return -ENOENT;
}
+struct Formattable {
+ enum Type {
+ FMT_NONE,
+ FMT_STRING,
+ FMT_ARRAY,
+ FMT_OBJ,
+ } type{FMT_NONE};
+ string str;
+ vector<Formattable> arr;
+ map<string, Formattable> obj;
+
+ void decode_json(JSONObj *jo) {
+ if (jo->is_array()) {
+ type = Formattable::FMT_ARRAY;
+ decode_json_obj(arr, jo);
+ } else if (jo->is_object()) {
+ type = Formattable::FMT_OBJ;
+ auto iter = jo->find_first();
+ while (!iter.end()) {
+ JSONObj *field;
+ decode_json_obj(obj[field->get_name()], field);
+ }
+ } else {
+ type = Formattable::FMT_STRING;
+ decode_json_obj(str, jo);
+ }
+ }
+
+ const string& val() const {
+ return str;
+ }
+
+ const vector<Formattable>& array() const {
+ return arr;
+ }
+
+ const Formattable& operator[](const string& name) const;
+};
+
+static Formattable default_formattable;
+
+const Formattable& Formattable::operator[](const string& name) const {
+ auto i = obj.find(name);
+ if (i == obj.end()) {
+ return default_formattable;
+ }
+ return i->second;
+}
+
+void encode_json(const char *name, const Formattable& v, Formatter *f)
+{
+ switch (v.type) {
+ case Formattable::FMT_STRING:
+ encode_json(name, v.str, f);
+ break;
+ case Formattable::FMT_ARRAY:
+ encode_json(name, v.arr, f);
+ break;
+ case Formattable::FMT_OBJ:
+ f->open_object_section(name);
+ for (auto iter : v.obj) {
+ encode_json(iter.first.c_str(), iter.second, f);
+ }
+ f->close_section();
+ break;
+ case Formattable::FMT_NONE:
+ break;
+ }
+}
+
+
#ifdef BUILDING_FOR_EMBEDDED
extern "C" int cephd_rgw_admin(int argc, const char **argv)
#else