rgw_dencoder_src = rgw/rgw_dencoder.cc \
rgw/rgw_acl.cc \
rgw/rgw_common.cc \
- rgw/rgw_json.cc \
rgw/rgw_json_enc.cc
ceph_dencoder_SOURCES = test/encoding/ceph_dencoder.cc ${rgw_dencoder_src} perfglue/disabled_heap_profiler.cc
rgw/rgw_fcgi.cc \
rgw/rgw_xml.cc \
rgw/rgw_usage.cc \
- rgw/rgw_json.cc \
rgw/rgw_json_enc.cc \
rgw/rgw_user.cc \
rgw/rgw_tools.cc \
common/entity_name.cc \
common/ceph_crypto.cc \
common/ceph_crypto_cms.cc \
+ common/ceph_json.cc \
common/ipaddr.cc \
common/pick_address.cc \
include/addr_parsing.c \
common/config_opts.h\
common/ceph_crypto.h\
common/ceph_crypto_cms.h\
+ common/ceph_json.h\
common/utf8.h\
common/mime.h\
common/pick_address.h\
rgw/rgw_client_io.h\
rgw/rgw_fcgi.h\
rgw/rgw_xml.h\
- rgw/rgw_json.h\
rgw/rgw_cache.h\
rgw/rgw_common.h\
rgw/rgw_string.h\
--- /dev/null
+#include <iostream>
+#include <include/types.h>
+#include <errno.h>
+
+#include "common/ceph_json.h"
+
+// for testing DELETE ME
+#include <fstream>
+
+using namespace std;
+using namespace json_spirit;
+
+#define dout_subsys ceph_subsys_rgw
+
+JSONObjIter::JSONObjIter()
+{
+}
+
+JSONObjIter::~JSONObjIter()
+{
+}
+
+void JSONObjIter::set(const JSONObjIter::map_iter_t &_cur, const JSONObjIter::map_iter_t &_last)
+{
+ cur = _cur;
+ last = _last;
+}
+
+void JSONObjIter::operator++()
+{
+ if (cur != last)
+ ++cur;
+};
+
+JSONObj *JSONObjIter::operator*()
+{
+ return cur->second;
+};
+
+// does not work, FIXME
+ostream& operator<<(ostream& out, JSONObj& obj) {
+ out << obj.name << ": " << obj.data_string;
+ return out;
+}
+
+JSONObj::~JSONObj()
+{
+ multimap<string, JSONObj *>::iterator iter;
+ for (iter = children.begin(); iter != children.end(); ++iter) {
+ JSONObj *obj = iter->second;
+ delete obj;
+ }
+}
+
+
+void JSONObj::add_child(string el, JSONObj *obj)
+{
+ cout << "add_child: " << name << " <- " << el << std::endl;
+ children.insert(pair<string, JSONObj *>(el, obj));
+}
+
+bool JSONObj::get_attr(string name, string& attr)
+{
+ map<string, string>::iterator iter = attr_map.find(name);
+ if (iter == attr_map.end())
+ return false;
+ attr = iter->second;
+ return true;
+}
+
+JSONObjIter JSONObj::find(const string& name)
+{
+ JSONObjIter iter;
+ map<string, JSONObj *>::iterator first;
+ map<string, JSONObj *>::iterator last;
+ first = children.find(name);
+ if (first != children.end()) {
+ last = children.upper_bound(name);
+ iter.set(first, last);
+ }
+ return iter;
+}
+
+JSONObjIter JSONObj::find_first()
+{
+ JSONObjIter iter;
+ iter.set(children.begin(), children.end());
+ return iter;
+}
+
+JSONObjIter JSONObj::find_first(const string& name)
+{
+ JSONObjIter iter;
+ map<string, JSONObj *>::iterator first;
+ first = children.find(name);
+ iter.set(first, children.end());
+ return iter;
+}
+
+JSONObj *JSONObj::find_obj(const string& name)
+{
+ JSONObjIter iter = find(name);
+ if (iter.end())
+ return NULL;
+
+ return *iter;
+}
+
+bool JSONObj::get_data(const string& key, string *dest)
+{
+ JSONObj *obj = find_obj(key);
+ if (!obj)
+ return false;
+
+ *dest = obj->get_data();
+
+ return true;
+}
+
+/* accepts a JSON Array or JSON Object contained in
+ * a JSON Spirit Value, v, and creates a JSONObj for each
+ * child contained in v
+ */
+void JSONObj::handle_value(Value v)
+{
+ if (v.type() == obj_type) {
+ Object temp_obj = v.get_obj();
+ for (Object::size_type i = 0; i < temp_obj.size(); i++) {
+ Pair temp_pair = temp_obj[i];
+ string temp_name = temp_pair.name_;
+ Value temp_value = temp_pair.value_;
+ JSONObj *child = new JSONObj;
+ child->init(this, temp_value, temp_name);
+ add_child(temp_name, child);
+ }
+ } else if (v.type() == array_type) {
+ Array temp_array = v.get_array();
+ Value value;
+
+ for (unsigned j = 0; j < temp_array.size(); j++) {
+ Value cur = temp_array[j];
+ string temp_name;
+
+ JSONObj *child = new JSONObj;
+ child->init(this, cur, temp_name);
+ add_child(child->get_name(), child);
+ }
+ }
+}
+
+void JSONObj::init(JSONObj *p, Value v, string n)
+{
+ name = n;
+ parent = p;
+ data = v;
+
+ handle_value(v);
+ if (v.type() == str_type)
+ data_string = v.get_str();
+ else
+ data_string = write(v, raw_utf8);
+ attr_map.insert(pair<string,string>(name, data_string));
+}
+
+JSONObj *JSONObj::get_parent()
+{
+ return parent;
+}
+
+bool JSONObj::is_object()
+{
+ cout << data.type() << std::endl;
+ return (data.type() == obj_type);
+}
+
+bool JSONObj::is_array()
+{
+ return (data.type() == array_type);
+}
+
+vector<string> JSONObj::get_array_elements()
+{
+ vector<string> elements;
+ Array temp_array;
+
+ if (data.type() == array_type)
+ temp_array = data.get_array();
+
+ int array_size = temp_array.size();
+ if (array_size > 0)
+ for (int i = 0; i < array_size; i++) {
+ Value temp_value = temp_array[i];
+ string temp_string;
+ temp_string = write(temp_value, raw_utf8);
+ elements.push_back(temp_string);
+ }
+
+ return elements;
+}
+
+JSONParser::JSONParser() : buf_len(0), success(true)
+{
+}
+
+JSONParser::~JSONParser()
+{
+}
+
+
+
+void JSONParser::handle_data(const char *s, int len)
+{
+ json_buffer.append(s, len); // check for problems with null termination FIXME
+ buf_len += len;
+}
+
+// parse a supplied JSON fragment
+bool JSONParser::parse(const char *buf_, int len)
+{
+ string json_string = buf_;
+ // make a substring to len
+ json_string = json_string.substr(0, len);
+ success = read(json_string, data);
+ if (success)
+ handle_value(data);
+ else
+ set_failure();
+
+ return success;
+}
+
+// parse the internal json_buffer up to len
+bool JSONParser::parse(int len)
+{
+ string json_string = json_buffer.substr(0, len);
+ success = read(json_string, data);
+ if (success)
+ handle_value(data);
+ else
+ set_failure();
+
+ return success;
+}
+
+// parse the complete internal json_buffer
+bool JSONParser::parse()
+{
+ success = read(json_buffer, data);
+ if (success)
+ handle_value(data);
+ else
+ set_failure();
+
+ return success;
+}
+
+// parse a supplied ifstream, for testing. DELETE ME
+bool JSONParser::parse(const char *file_name)
+{
+ ifstream is(file_name);
+ success = read(is, data);
+ if (success)
+ handle_value(data);
+ else
+ set_failure();
+
+ return success;
+}
+
+
+void decode_json_obj(long& val, JSONObj *obj)
+{
+ string s = obj->get_data();
+ const char *start = s.c_str();
+ char *p;
+
+ errno = 0;
+ val = strtol(start, &p, 10);
+
+ /* Check for various possible errors */
+
+ if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
+ (errno != 0 && val == 0)) {
+ throw JSONDecoder::err("failed to parse number");
+ }
+
+ if (p == start) {
+ throw JSONDecoder::err("failed to parse number");
+ }
+
+ while (*p != '\0') {
+ if (!isspace(*p)) {
+ throw JSONDecoder::err("failed to parse number");
+ }
+ p++;
+ }
+}
+
+void decode_json_obj(unsigned long& val, JSONObj *obj)
+{
+ string s = obj->get_data();
+ const char *start = s.c_str();
+ char *p;
+
+ errno = 0;
+ val = strtoul(start, &p, 10);
+
+ /* Check for various possible errors */
+
+ if ((errno == ERANGE && val == ULONG_MAX) ||
+ (errno != 0 && val == 0)) {
+ throw JSONDecoder::err("failed to number");
+ }
+
+ if (p == start) {
+ throw JSONDecoder::err("failed to parse number");
+ }
+
+ while (*p != '\0') {
+ if (!isspace(*p)) {
+ throw JSONDecoder::err("failed to parse number");
+ }
+ p++;
+ }
+}
+
+void decode_json_obj(int& val, JSONObj *obj)
+{
+ long l;
+ decode_json_obj(l, obj);
+#if LONG_MAX > INT_MAX
+ if (l > INT_MAX || l < INT_MIN) {
+ throw JSONDecoder::err("integer out of range");
+ }
+#endif
+
+ val = (int)l;
+}
+
+void decode_json_obj(unsigned& val, JSONObj *obj)
+{
+ unsigned long l;
+ decode_json_obj(l, obj);
+#if ULONG_MAX > UINT_MAX
+ if (l > UINT_MAX) {
+ throw JSONDecoder::err("unsigned integer out of range");
+ }
+#endif
+
+ val = (unsigned)l;
+}
+
+void decode_json_obj(bool& val, JSONObj *obj)
+{
+ string s = obj->get_data();
+ if (strcasecmp(s.c_str(), "true") == 0) {
+ val = true;
+ return;
+ }
+ if (strcasecmp(s.c_str(), "false") == 0) {
+ val = true;
+ return;
+ }
+ int i;
+ decode_json_obj(i, obj);
+ val = (bool)i;
+}
+
--- /dev/null
+#ifndef CEPH_JSON_H
+#define CEPH_JSON_H
+
+#include <iostream>
+#include <include/types.h>
+
+#include "json_spirit/json_spirit.h"
+
+
+using namespace json_spirit;
+
+
+class JSONObj;
+
+class JSONObjIter {
+ typedef map<string, JSONObj *>::iterator map_iter_t;
+ map_iter_t cur;
+ map_iter_t last;
+
+public:
+ JSONObjIter();
+ ~JSONObjIter();
+ void set(const JSONObjIter::map_iter_t &_cur, const JSONObjIter::map_iter_t &_end);
+
+ void operator++();
+ JSONObj *operator*();
+
+ bool end() {
+ return (cur == last);
+ }
+};
+
+class JSONObj
+{
+ JSONObj *parent;
+protected:
+ string name; // corresponds to obj_type in XMLObj
+ Value data;
+ string data_string;
+ multimap<string, JSONObj *> children;
+ map<string, string> attr_map;
+ void handle_value(Value v);
+
+public:
+
+ JSONObj() : parent(NULL){};
+
+ virtual ~JSONObj();
+
+ void init(JSONObj *p, Value v, string n);
+
+ string& get_name() { return name; }
+ string& get_data() { return data_string; }
+ bool get_data(const string& key, string *dest);
+ JSONObj *get_parent();
+ void add_child(string el, JSONObj *child);
+ bool get_attr(string name, string& attr);
+ JSONObjIter find(const string& name);
+ JSONObjIter find_first();
+ JSONObjIter find_first(const string& name);
+ JSONObj *find_obj(const string& name);
+
+ friend ostream& operator<<(ostream& out, JSONObj& obj); // does not work, FIXME
+
+ bool is_array();
+ bool is_object();
+ vector<string> get_array_elements();
+};
+
+class JSONParser : public JSONObj
+{
+ int buf_len;
+ string json_buffer;
+ bool success;
+public:
+ JSONParser();
+ virtual ~JSONParser();
+ void handle_data(const char *s, int len);
+
+ bool parse(const char *buf_, int len);
+ bool parse(int len);
+ bool parse();
+ bool parse(const char *file_name);
+
+ const char *get_json() { return json_buffer.c_str(); }
+ void set_failure() { success = false; }
+};
+
+
+class JSONDecoder {
+public:
+ struct err {
+ string message;
+
+ err(const string& m) : message(m) {}
+ };
+
+ JSONParser parser;
+
+ JSONDecoder(bufferlist& bl) {
+ if (!parser.parse(bl.c_str(), bl.length())) {
+ cout << "JSONDecoder::err()" << std::endl;
+ throw JSONDecoder::err("failed to parse JSON input");
+ }
+ }
+
+ template<class T>
+ static bool decode_json(const string& name, T& val, JSONObj *obj, bool mandatory = false);
+
+ template<class T>
+ static void decode_json(const string& name, T& val, T& default_val, JSONObj *obj);
+};
+
+template<class T>
+void decode_json_obj(T& val, JSONObj *obj)
+{
+ val.decode_json(obj);
+}
+
+static inline void decode_json_obj(string& val, JSONObj *obj)
+{
+ val = obj->get_data();
+}
+
+void decode_json_obj(unsigned long& val, JSONObj *obj);
+void decode_json_obj(long& val, JSONObj *obj);
+void decode_json_obj(unsigned& val, JSONObj *obj);
+void decode_json_obj(int& val, JSONObj *obj);
+void decode_json_obj(bool& val, JSONObj *obj);
+
+template<class T>
+void decode_json_obj(list<T>& l, JSONObj *obj)
+{
+ JSONObjIter iter = obj->find_first();
+
+ for (; !iter.end(); ++iter) {
+ T val;
+ JSONObj *o = *iter;
+ decode_json_obj(val, o);
+ l.push_back(val);
+ }
+}
+
+template<class T>
+bool JSONDecoder::decode_json(const string& name, T& val, JSONObj *obj, bool mandatory)
+{
+ JSONObjIter iter = obj->find_first(name);
+ if (iter.end()) {
+ if (mandatory) {
+ string s = "missing mandatory field " + name;
+ throw err(s);
+ }
+ return false;
+ }
+
+ try {
+ decode_json_obj(val, *iter);
+ } catch (err& e) {
+ string s = name + ": ";
+ s.append(e.message);
+ throw err(s);
+ }
+
+ return true;
+}
+
+template<class T>
+void JSONDecoder::decode_json(const string& name, T& val, T& default_val, JSONObj *obj)
+{
+ JSONObjIter iter = obj->find_first(name);
+ if (iter.end()) {
+ val = default_val;
+ return;
+ }
+
+ try {
+ decode_json_obj(val, *iter);
+ } catch (err& e) {
+ val = default_val;
+ string s = name + ": ";
+ s.append(e.message);
+ throw err(s);
+ }
+}
+
+#endif
#include <errno.h>
#include "json_spirit/json_spirit.h"
+#include "common/ceph_json.h"
#include "rgw_common.h"
#include "rgw_acl.h"
#include "rgw_string.h"
-#include "rgw_json.h"
#include "common/ceph_crypto.h"
#include "common/armor.h"
+++ /dev/null
-#include <iostream>
-#include <include/types.h>
-
-#include "rgw_json.h"
-#include "rgw_common.h"
-
-// for testing DELETE ME
-#include <fstream>
-
-using namespace std;
-using namespace json_spirit;
-
-#define dout_subsys ceph_subsys_rgw
-
-JSONObjIter::JSONObjIter()
-{
-}
-
-JSONObjIter::~JSONObjIter()
-{
-}
-
-void JSONObjIter::set(const JSONObjIter::map_iter_t &_cur, const JSONObjIter::map_iter_t &_last)
-{
- cur = _cur;
- last = _last;
-}
-
-void JSONObjIter::operator++()
-{
- if (cur != last)
- ++cur;
-};
-
-JSONObj *JSONObjIter::operator*()
-{
- return cur->second;
-};
-
-// does not work, FIXME
-ostream& operator<<(ostream& out, JSONObj& obj) {
- out << obj.name << ": " << obj.data_string;
- return out;
-}
-
-JSONObj::~JSONObj()
-{
- multimap<string, JSONObj *>::iterator iter;
- for (iter = children.begin(); iter != children.end(); ++iter) {
- JSONObj *obj = iter->second;
- delete obj;
- }
-}
-
-
-void JSONObj::add_child(string el, JSONObj *obj)
-{
- cout << "add_child: " << name << " <- " << el << std::endl;
- children.insert(pair<string, JSONObj *>(el, obj));
-}
-
-bool JSONObj::get_attr(string name, string& attr)
-{
- map<string, string>::iterator iter = attr_map.find(name);
- if (iter == attr_map.end())
- return false;
- attr = iter->second;
- return true;
-}
-
-JSONObjIter JSONObj::find(const string& name)
-{
- JSONObjIter iter;
- map<string, JSONObj *>::iterator first;
- map<string, JSONObj *>::iterator last;
- first = children.find(name);
- if (first != children.end()) {
- last = children.upper_bound(name);
- iter.set(first, last);
- }
- return iter;
-}
-
-JSONObjIter JSONObj::find_first()
-{
- JSONObjIter iter;
- iter.set(children.begin(), children.end());
- return iter;
-}
-
-JSONObjIter JSONObj::find_first(const string& name)
-{
- JSONObjIter iter;
- map<string, JSONObj *>::iterator first;
- first = children.find(name);
- iter.set(first, children.end());
- return iter;
-}
-
-JSONObj *JSONObj::find_obj(const string& name)
-{
- JSONObjIter iter = find(name);
- if (iter.end())
- return NULL;
-
- return *iter;
-}
-
-bool JSONObj::get_data(const string& key, string *dest)
-{
- JSONObj *obj = find_obj(key);
- if (!obj)
- return false;
-
- *dest = obj->get_data();
-
- return true;
-}
-
-/* accepts a JSON Array or JSON Object contained in
- * a JSON Spirit Value, v, and creates a JSONObj for each
- * child contained in v
- */
-void JSONObj::handle_value(Value v)
-{
- if (v.type() == obj_type) {
- Object temp_obj = v.get_obj();
- for (Object::size_type i = 0; i < temp_obj.size(); i++) {
- Pair temp_pair = temp_obj[i];
- string temp_name = temp_pair.name_;
- Value temp_value = temp_pair.value_;
- JSONObj *child = new JSONObj;
- child->init(this, temp_value, temp_name);
- add_child(temp_name, child);
- }
- } else if (v.type() == array_type) {
- Array temp_array = v.get_array();
- Value value;
-
- for (unsigned j = 0; j < temp_array.size(); j++) {
- Value cur = temp_array[j];
- string temp_name;
-
- JSONObj *child = new JSONObj;
- child->init(this, cur, temp_name);
- add_child(child->get_name(), child);
- }
- }
-}
-
-void JSONObj::init(JSONObj *p, Value v, string n)
-{
- name = n;
- parent = p;
- data = v;
-
- handle_value(v);
- if (v.type() == str_type)
- data_string = v.get_str();
- else
- data_string = write(v, raw_utf8);
- attr_map.insert(pair<string,string>(name, data_string));
-}
-
-JSONObj *JSONObj::get_parent()
-{
- return parent;
-}
-
-bool JSONObj::is_object()
-{
- cout << data.type() << std::endl;
- return (data.type() == obj_type);
-}
-
-bool JSONObj::is_array()
-{
- return (data.type() == array_type);
-}
-
-vector<string> JSONObj::get_array_elements()
-{
- vector<string> elements;
- Array temp_array;
-
- if (data.type() == array_type)
- temp_array = data.get_array();
-
- int array_size = temp_array.size();
- if (array_size > 0)
- for (int i = 0; i < array_size; i++) {
- Value temp_value = temp_array[i];
- string temp_string;
- temp_string = write(temp_value, raw_utf8);
- elements.push_back(temp_string);
- }
-
- return elements;
-}
-
-RGWJSONParser::RGWJSONParser() : buf_len(0), success(true)
-{
-}
-
-RGWJSONParser::~RGWJSONParser()
-{
-}
-
-
-
-void RGWJSONParser::handle_data(const char *s, int len)
-{
- json_buffer.append(s, len); // check for problems with null termination FIXME
- buf_len += len;
-}
-
-// parse a supplied JSON fragment
-bool RGWJSONParser::parse(const char *buf_, int len)
-{
- string json_string = buf_;
- // make a substring to len
- json_string = json_string.substr(0, len);
- success = read(json_string, data);
- if (success)
- handle_value(data);
- else
- set_failure();
-
- return success;
-}
-
-// parse the internal json_buffer up to len
-bool RGWJSONParser::parse(int len)
-{
- string json_string = json_buffer.substr(0, len);
- success = read(json_string, data);
- if (success)
- handle_value(data);
- else
- set_failure();
-
- return success;
-}
-
-// parse the complete internal json_buffer
-bool RGWJSONParser::parse()
-{
- success = read(json_buffer, data);
- if (success)
- handle_value(data);
- else
- set_failure();
-
- return success;
-}
-
-// parse a supplied ifstream, for testing. DELETE ME
-bool RGWJSONParser::parse(const char *file_name)
-{
- ifstream is(file_name);
- success = read(is, data);
- if (success)
- handle_value(data);
- else
- set_failure();
-
- return success;
-}
-
-
-void decode_json_obj(long& val, JSONObj *obj)
-{
- string s = obj->get_data();
- const char *start = s.c_str();
- char *p;
-
- errno = 0;
- val = strtol(start, &p, 10);
-
- /* Check for various possible errors */
-
- if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
- (errno != 0 && val == 0)) {
- throw JSONDecoder::err("failed to parse number");
- }
-
- if (p == start) {
- throw JSONDecoder::err("failed to parse number");
- }
-
- while (*p != '\0') {
- if (!isspace(*p)) {
- throw JSONDecoder::err("failed to parse number");
- }
- p++;
- }
-}
-
-void decode_json_obj(unsigned long& val, JSONObj *obj)
-{
- string s = obj->get_data();
- const char *start = s.c_str();
- char *p;
-
- errno = 0;
- val = strtoul(start, &p, 10);
-
- /* Check for various possible errors */
-
- if ((errno == ERANGE && val == ULONG_MAX) ||
- (errno != 0 && val == 0)) {
- throw JSONDecoder::err("failed to number");
- }
-
- if (p == start) {
- throw JSONDecoder::err("failed to parse number");
- }
-
- while (*p != '\0') {
- if (!isspace(*p)) {
- throw JSONDecoder::err("failed to parse number");
- }
- p++;
- }
-}
-
-void decode_json_obj(int& val, JSONObj *obj)
-{
- long l;
- decode_json_obj(l, obj);
-#if LONG_MAX > INT_MAX
- if (l > INT_MAX || l < INT_MIN) {
- throw JSONDecoder::err("integer out of range");
- }
-#endif
-
- val = (int)l;
-}
-
-void decode_json_obj(unsigned& val, JSONObj *obj)
-{
- unsigned long l;
- decode_json_obj(l, obj);
-#if ULONG_MAX > UINT_MAX
- if (l > UINT_MAX) {
- throw JSONDecoder::err("unsigned integer out of range");
- }
-#endif
-
- val = (unsigned)l;
-}
-
-void decode_json_obj(bool& val, JSONObj *obj)
-{
- string s = obj->get_data();
- if (strcasecmp(s.c_str(), "true") == 0) {
- val = true;
- return;
- }
- if (strcasecmp(s.c_str(), "false") == 0) {
- val = true;
- return;
- }
- int i;
- decode_json_obj(i, obj);
- val = (bool)i;
-}
-
+++ /dev/null
-#ifndef RGW_JSON_H
-#define RGW_JSON_H
-
-#include <iostream>
-#include <include/types.h>
-
-#include "json_spirit/json_spirit.h"
-
-
-using namespace json_spirit;
-
-
-class JSONObj;
-
-class JSONObjIter {
- typedef map<string, JSONObj *>::iterator map_iter_t;
- map_iter_t cur;
- map_iter_t last;
-
-public:
- JSONObjIter();
- ~JSONObjIter();
- void set(const JSONObjIter::map_iter_t &_cur, const JSONObjIter::map_iter_t &_end);
-
- void operator++();
- JSONObj *operator*();
-
- bool end() {
- return (cur == last);
- }
-};
-
-class JSONObj
-{
- JSONObj *parent;
-protected:
- string name; // corresponds to obj_type in XMLObj
- Value data;
- string data_string;
- multimap<string, JSONObj *> children;
- map<string, string> attr_map;
- void handle_value(Value v);
-
-public:
-
- JSONObj() : parent(NULL){};
-
- virtual ~JSONObj();
-
- void init(JSONObj *p, Value v, string n);
-
- string& get_name() { return name; }
- string& get_data() { return data_string; }
- bool get_data(const string& key, string *dest);
- JSONObj *get_parent();
- void add_child(string el, JSONObj *child);
- bool get_attr(string name, string& attr);
- JSONObjIter find(const string& name);
- JSONObjIter find_first();
- JSONObjIter find_first(const string& name);
- JSONObj *find_obj(const string& name);
-
- friend ostream& operator<<(ostream& out, JSONObj& obj); // does not work, FIXME
-
- bool is_array();
- bool is_object();
- vector<string> get_array_elements();
-};
-
-class RGWJSONParser : public JSONObj
-{
- int buf_len;
- string json_buffer;
- bool success;
-public:
- RGWJSONParser();
- virtual ~RGWJSONParser();
- void handle_data(const char *s, int len);
-
- bool parse(const char *buf_, int len);
- bool parse(int len);
- bool parse();
- bool parse(const char *file_name);
-
- const char *get_json() { return json_buffer.c_str(); }
- void set_failure() { success = false; }
-};
-
-
-class JSONDecoder {
-public:
- struct err {
- string message;
-
- err(const string& m) : message(m) {}
- };
-
- RGWJSONParser parser;
-
- JSONDecoder(bufferlist& bl) {
- if (!parser.parse(bl.c_str(), bl.length())) {
- cout << "JSONDecoder::err()" << std::endl;
- throw JSONDecoder::err("failed to parse JSON input");
- }
- }
-
- template<class T>
- static bool decode_json(const string& name, T& val, JSONObj *obj, bool mandatory = false);
-
- template<class T>
- static void decode_json(const string& name, T& val, T& default_val, JSONObj *obj);
-};
-
-template<class T>
-void decode_json_obj(T& val, JSONObj *obj)
-{
- val.decode_json(obj);
-}
-
-static inline void decode_json_obj(string& val, JSONObj *obj)
-{
- val = obj->get_data();
-}
-
-void decode_json_obj(unsigned long& val, JSONObj *obj);
-void decode_json_obj(long& val, JSONObj *obj);
-void decode_json_obj(unsigned& val, JSONObj *obj);
-void decode_json_obj(int& val, JSONObj *obj);
-void decode_json_obj(bool& val, JSONObj *obj);
-
-template<class T>
-void decode_json_obj(list<T>& l, JSONObj *obj)
-{
- JSONObjIter iter = obj->find_first();
-
- for (; !iter.end(); ++iter) {
- T val;
- JSONObj *o = *iter;
- decode_json_obj(val, o);
- l.push_back(val);
- }
-}
-
-template<class T>
-bool JSONDecoder::decode_json(const string& name, T& val, JSONObj *obj, bool mandatory)
-{
- JSONObjIter iter = obj->find_first(name);
- if (iter.end()) {
- if (mandatory) {
- string s = "missing mandatory field " + name;
- throw err(s);
- }
- return false;
- }
-
- try {
- decode_json_obj(val, *iter);
- } catch (err& e) {
- string s = name + ": ";
- s.append(e.message);
- throw err(s);
- }
-
- return true;
-}
-
-template<class T>
-void JSONDecoder::decode_json(const string& name, T& val, T& default_val, JSONObj *obj)
-{
- JSONObjIter iter = obj->find_first(name);
- if (iter.end()) {
- val = default_val;
- return;
- }
-
- try {
- decode_json_obj(val, *iter);
- } catch (err& e) {
- val = default_val;
- string s = name + ": ";
- s.append(e.message);
- throw err(s);
- }
-}
-
-#endif
#include "include/types.h"
#include "common/Formatter.h"
+#include "common/ceph_json.h"
-#include "rgw_json.h"
#include "rgw_common.h"
#define dout_subsys ceph_subsys_rgw
int main(int argc, char **argv) {
- RGWJSONParser parser;
+ JSONParser parser;
char buf[1024];
bufferlist bl;
#include <errno.h>
+#include "common/ceph_json.h"
#include "rgw_policy_s3.h"
-#include "rgw_json.h"
#include "rgw_common.h"
int RGWPolicy::from_json(bufferlist& bl, string& err_msg)
{
- RGWJSONParser parser;
+ JSONParser parser;
if (!parser.parse(bl.c_str(), bl.length())) {
err_msg = "Malformed JSON";
#include <stdlib.h>
#include <unistd.h>
-#include "rgw_json.h"
+#include "common/ceph_json.h"
#include "rgw_common.h"
#include "rgw_swift.h"
#include "rgw_swift_auth.h"
int KeystoneToken::parse(CephContext *cct, bufferlist& bl)
{
- RGWJSONParser parser;
+ JSONParser parser;
if (!parser.parse(bl.c_str(), bl.length())) {
ldout(cct, 0) << "malformed json" << dendl;
ldout(cct, 10) << "request returned " << bl.c_str() << dendl;
- RGWJSONParser parser;
+ JSONParser parser;
if (!parser.parse(bl.c_str(), bl.length())) {
ldout(cct, 0) << "malformed json" << dendl;
ldout(cct, 10) << "ceph_decode_cms: decoded: " << json.c_str() << dendl;
- RGWJSONParser list_parser;
+ JSONParser list_parser;
if (!list_parser.parse(json.c_str(), json.length())) {
ldout(cct, 0) << "malformed json" << dendl;
return -EINVAL;