1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
10 #include "include/types.h"
12 #include "common/Formatter.h"
13 #include "common/ceph_json.h"
15 #include "rgw_common.h"
17 #define dout_subsys ceph_subsys_rgw
21 void dump_array(JSONObj *obj)
24 JSONObjIter iter = obj->find_first();
26 for (; !iter.end(); ++iter) {
28 cout << "data=" << o->get_data() << std::endl;
38 void decode_json(JSONObj *obj) {
39 JSONDecoder::decode_json("user", user, obj);
40 JSONDecoder::decode_json("access_key", access_key, obj);
41 JSONDecoder::decode_json("secret_key", secret_key, obj);
51 void decode_json(JSONObj *obj) {
52 JSONDecoder::decode_json("user_id", uid, obj);
53 JSONDecoder::decode_json("display_name", display_name, obj);
54 JSONDecoder::decode_json("max_buckets", max_buckets, obj);
55 JSONDecoder::decode_json("keys", keys, obj);
60 int main(int argc, char **argv) {
70 len = fread(buf, 1, sizeof(buf), stdin);
72 cerr << "read error" << std::endl;
77 bool ret = parser.parse(buf, len);
79 cerr << "parse error" << std::endl;
87 JSONObjIter iter = parser.find_first();
89 for (; !iter.end(); ++iter) {
91 cout << "is_object=" << obj->is_object() << std::endl;
92 cout << "is_array=" << obj->is_array() << std::endl;
93 cout << "name=" << obj->get_name() << std::endl;
94 cout << "data=" << obj->get_data() << std::endl;
97 iter = parser.find_first("conditions");
101 JSONObjIter iter2 = obj->find_first();
102 for (; !iter2.end(); ++iter2) {
103 JSONObj *child = *iter2;
104 cout << "is_object=" << child->is_object() << std::endl;
105 cout << "is_array=" << child->is_array() << std::endl;
106 if (child->is_array()) {
109 cout << "name=" << child->get_name() <<std::endl;
110 cout << "data=" << child->get_data() <<std::endl;
117 ui.decode_json(&parser);
118 } catch (JSONDecoder::err& e) {
119 cout << "failed to decode JSON input: " << e.message << std::endl;
123 JSONFormatter formatter(true);
125 formatter.open_object_section("user_info");
127 formatter.close_section();
129 formatter.flush(std::cout);
131 std::cout << std::endl;