summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2012-10-19 17:27:53 -0700
committerYehuda Sadeh <yehuda@inktank.com>2012-10-23 10:43:09 -0700
commit81f257d5839c63aaab33e4070f1e9597b3240890 (patch)
treea9a054e8d7eb8aee717fc04f963eca70ec9ec348
parentc2b702fac73c5a1de72cce7c694fbdac96d71e1f (diff)
downloadceph-81f257d5839c63aaab33e4070f1e9597b3240890.tar.gz
rgw: add a test tool for json parser
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/Makefile.am5
-rw-r--r--src/rgw/rgw_jsonparser.cc80
2 files changed, 85 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f90e07bb851..50feab6c15a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -360,6 +360,11 @@ rgw_multiparser_CXXFLAGS = ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS}
rgw_multiparser_LDADD = $(my_radosgw_ldadd)
bin_DEBUGPROGRAMS += rgw_multiparser
+rgw_jsonparser_SOURCES = rgw/rgw_jsonparser.cc
+rgw_jsonparser_CXXFLAGS = ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS}
+rgw_jsonparser_LDADD = $(my_radosgw_ldadd)
+bin_DEBUGPROGRAMS += rgw_jsonparser
+
endif
# librbd
diff --git a/src/rgw/rgw_jsonparser.cc b/src/rgw/rgw_jsonparser.cc
new file mode 100644
index 00000000000..7a1f11c325e
--- /dev/null
+++ b/src/rgw/rgw_jsonparser.cc
@@ -0,0 +1,80 @@
+#include <string.h>
+
+#include <iostream>
+#include <map>
+
+#include "include/types.h"
+
+#include "rgw_json.h"
+
+#define dout_subsys ceph_subsys_rgw
+
+using namespace std;
+
+void dump_array(JSONObj *obj)
+{
+
+ JSONObjIter iter = obj->find_first();
+
+ for (; !iter.end(); ++iter) {
+ JSONObj *o = *iter;
+ cout << "data=" << o->get_data() << endl;
+ }
+
+}
+
+int main(int argc, char **argv) {
+ RGWJSONParser parser;
+
+ char buf[1024];
+
+ for (;;) {
+ int done;
+ int len;
+
+ len = fread(buf, 1, sizeof(buf), stdin);
+ if (ferror(stdin)) {
+ cerr << "read error" << std::endl;
+ exit(-1);
+ }
+ done = feof(stdin);
+
+ bool ret = parser.parse(buf, len);
+ if (!ret)
+ cerr << "parse error" << std::endl;
+
+ if (done)
+ 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;
+ }
+
+ iter = parser.find_first("conditions");
+ if (!iter.end()) {
+ JSONObj *obj = *iter;
+
+ 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;
+ if (child->is_array()) {
+ dump_array(child);
+ }
+ cout << "name=" << child->get_name() << endl;
+ cout << "data=" << child->get_data() << endl;
+ }
+ }
+
+
+ exit(0);
+}
+