summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-02-06 12:36:56 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-03-22 11:23:07 -0700
commit53ba6c2d0f6d165d9ba731dd838f7f0ce8e9e218 (patch)
treef724d3724ad9bfc0ea8cfd807b6515e4c9b2b0fe
parentda33701318c42a2436bb0318b63b720ff52ae057 (diff)
downloadceph-53ba6c2d0f6d165d9ba731dd838f7f0ce8e9e218.tar.gz
rgw: rgw_jsonparser changes
Now testing json_decode functionality. Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_jsonparser.cc72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/rgw/rgw_jsonparser.cc b/src/rgw/rgw_jsonparser.cc
index 7a1f11c325e..820cc6216b6 100644
--- a/src/rgw/rgw_jsonparser.cc
+++ b/src/rgw/rgw_jsonparser.cc
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <string.h>
#include <iostream>
@@ -5,7 +6,10 @@
#include "include/types.h"
+#include "common/Formatter.h"
+
#include "rgw_json.h"
+#include "rgw_common.h"
#define dout_subsys ceph_subsys_rgw
@@ -18,15 +22,43 @@ void dump_array(JSONObj *obj)
for (; !iter.end(); ++iter) {
JSONObj *o = *iter;
- cout << "data=" << o->get_data() << endl;
+ cout << "data=" << o->get_data() << std::endl;
}
}
+struct Key {
+ string user;
+ string access_key;
+ string secret_key;
+
+ void decode_json(JSONObj *obj) {
+ JSONDecoder::decode_json("user", user, obj);
+ JSONDecoder::decode_json("access_key", access_key, obj);
+ JSONDecoder::decode_json("secret_key", secret_key, obj);
+ }
+};
+
+struct UserInfo {
+ string uid;
+ string display_name;
+ int max_buckets;
+ list<Key> keys;
+
+ void decode_json(JSONObj *obj) {
+ JSONDecoder::decode_json("user_id", uid, obj);
+ JSONDecoder::decode_json("display_name", display_name, obj);
+ JSONDecoder::decode_json("max_buckets", max_buckets, obj);
+ JSONDecoder::decode_json("keys", keys, obj);
+ }
+};
+
+
int main(int argc, char **argv) {
RGWJSONParser parser;
char buf[1024];
+ bufferlist bl;
for (;;) {
int done;
@@ -43,18 +75,20 @@ int main(int argc, char **argv) {
if (!ret)
cerr << "parse error" << std::endl;
- if (done)
+ if (done) {
+ bl.append(buf, len);
break;
+ }
}
JSONObjIter iter = parser.find_first();
for (; !iter.end(); ++iter) {
JSONObj *obj = *iter;
- cout << "is_object=" << obj->is_object() << endl;
- cout << "is_array=" << obj->is_array() << endl;
- cout << "name=" << obj->get_name() << endl;
- cout << "data=" << obj->get_data() << endl;
+ cout << "is_object=" << obj->is_object() << std::endl;
+ cout << "is_array=" << obj->is_array() << std::endl;
+ cout << "name=" << obj->get_name() << std::endl;
+ cout << "data=" << obj->get_data() << std::endl;
}
iter = parser.find_first("conditions");
@@ -64,17 +98,33 @@ int main(int argc, char **argv) {
JSONObjIter iter2 = obj->find_first();
for (; !iter2.end(); ++iter2) {
JSONObj *child = *iter2;
- cout << "is_object=" << child->is_object() << endl;
- cout << "is_array=" << child->is_array() << endl;
+ cout << "is_object=" << child->is_object() << std::endl;
+ cout << "is_array=" << child->is_array() << std::endl;
if (child->is_array()) {
dump_array(child);
}
- cout << "name=" << child->get_name() << endl;
- cout << "data=" << child->get_data() << endl;
+ cout << "name=" << child->get_name() <<std::endl;
+ cout << "data=" << child->get_data() <<std::endl;
}
}
+ RGWUserInfo ui;
+
+ try {
+ ui.decode_json(&parser);
+ } catch (JSONDecoder::err& e) {
+ cout << "failed to decode JSON input: " << e.message << std::endl;
+ exit(1);
+ }
+
+ JSONFormatter formatter(true);
+
+ formatter.open_object_section("user_info");
+ ui.dump(&formatter);
+ formatter.close_section();
+
+ formatter.flush(std::cout);
- exit(0);
+ std::cout << std::endl;
}