summaryrefslogtreecommitdiff
path: root/src/rgw/rgw_jsonparser.cc
blob: 7a1f11c325efe076131abbaaf41a6a5c1c773f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
}