]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add a test tool for json parser
authorYehuda Sadeh <yehuda@inktank.com>
Sat, 20 Oct 2012 00:27:53 +0000 (17:27 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 23 Oct 2012 17:43:09 +0000 (10:43 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/Makefile.am
src/rgw/rgw_jsonparser.cc [new file with mode: 0644]

index f90e07bb851e86687bc1f3a5149446039e6c5039..50feab6c15a3dc37f0ec526516f192b0105e053a 100644 (file)
@@ -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 (file)
index 0000000..7a1f11c
--- /dev/null
@@ -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);
+}
+