]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_jsonparser.cc
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
20 void dump_array(JSONObj
*obj
)
23 JSONObjIter iter
= obj
->find_first();
25 for (; !iter
.end(); ++iter
) {
27 cout
<< "data=" << o
->get_data() << std::endl
;
37 void decode_json(JSONObj
*obj
) {
38 JSONDecoder::decode_json("user", user
, obj
);
39 JSONDecoder::decode_json("access_key", access_key
, obj
);
40 JSONDecoder::decode_json("secret_key", secret_key
, obj
);
50 void decode_json(JSONObj
*obj
) {
51 JSONDecoder::decode_json("user_id", uid
, obj
);
52 JSONDecoder::decode_json("display_name", display_name
, obj
);
53 JSONDecoder::decode_json("max_buckets", max_buckets
, obj
);
54 JSONDecoder::decode_json("keys", keys
, obj
);
59 int main(int argc
, char **argv
) {
69 len
= fread(buf
, 1, sizeof(buf
), stdin
);
71 cerr
<< "read error" << std::endl
;
76 bool ret
= parser
.parse(buf
, len
);
78 cerr
<< "parse error" << std::endl
;
86 JSONObjIter iter
= parser
.find_first();
88 for (; !iter
.end(); ++iter
) {
90 cout
<< "is_object=" << obj
->is_object() << std::endl
;
91 cout
<< "is_array=" << obj
->is_array() << std::endl
;
92 cout
<< "name=" << obj
->get_name() << std::endl
;
93 cout
<< "data=" << obj
->get_data() << std::endl
;
96 iter
= parser
.find_first("conditions");
100 JSONObjIter iter2
= obj
->find_first();
101 for (; !iter2
.end(); ++iter2
) {
102 JSONObj
*child
= *iter2
;
103 cout
<< "is_object=" << child
->is_object() << std::endl
;
104 cout
<< "is_array=" << child
->is_array() << std::endl
;
105 if (child
->is_array()) {
108 cout
<< "name=" << child
->get_name() <<std::endl
;
109 cout
<< "data=" << child
->get_data() <<std::endl
;
116 ui
.decode_json(&parser
);
117 } catch (JSONDecoder::err
& e
) {
118 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
122 JSONFormatter
formatter(true);
124 formatter
.open_object_section("user_info");
126 formatter
.close_section();
128 formatter
.flush(std::cout
);
130 std::cout
<< std::endl
;