Change krbCred member to reauthCred to better clarify purpose
[moonshot.git] / mech_eap / util_json.h
index 639e7b0..e2c5e29 100644 (file)
@@ -31,7 +31,7 @@
  */
 
 /*
- * JSON object wrapper with toll-free DDF bridging.
+ * JSON object wrapper with not-entirely-toll-free DDF bridging.
  */
 
 #ifndef _UTIL_JSON_H_
 
 using namespace shibsp;
 
-namespace gss_eap {
+namespace gss_eap_util {
     class JSONObject;
 
+    class JSONException : public std::exception {
+    public:
+        JSONException(json_t *obj = NULL, json_type type = JSON_NULL);
+
+        ~JSONException(void) throw() {
+            json_decref(m_obj);
+        }
+
+        virtual const char *what(void) const throw() {
+            return m_reason.c_str();
+        }
+
+    private:
+        json_t *m_obj;
+        json_type m_type;
+        std::string m_reason;
+    };
+
     class JSONIterator {
     public:
         JSONIterator(const JSONObject &obj);
@@ -70,15 +88,15 @@ namespace gss_eap {
         static JSONObject object(void);
         static JSONObject array(void);
         static JSONObject null(void);
+        static JSONObject ddf(DDF &value);
 
         char *dump(size_t flags = 0) const;
-        void dump(FILE *fp, size_t flags = 0) const;
+        void dump(FILE *fp, size_t flags = JSON_INDENT(4)) const;
 
         json_type type(void) const { return json_typeof(m_obj); }
         size_t size(void) const;
 
         JSONObject(void);
-        JSONObject(DDF &value);
         JSONObject(const char *value);
         JSONObject(json_int_t value);
         JSONObject(double value);
@@ -105,9 +123,16 @@ namespace gss_eap {
         json_int_t integer(void) const;
         double real(void) const;
         double number(void) const;
-        bool isnull(void) const;
         DDF ddf(void) const;
 
+        bool isObject(void) const;
+        bool isArray(void) const;
+        bool isString(void) const;
+        bool isInteger(void) const;
+        bool isNumber(void) const;
+        bool isBoolean(void) const;
+        bool isNull(void) const;
+
         ~JSONObject(void)
         {
             if (m_obj != NULL)
@@ -130,7 +155,7 @@ namespace gss_eap {
         friend class JSONIterator;
 
         json_t *get(void) const {
-            return m_obj ? json_incref(m_obj) : json_null();
+            return json_incref(m_obj);
         }
 
         void set(json_t *obj) {
@@ -140,11 +165,10 @@ namespace gss_eap {
             }
         }
 
-        JSONObject(json_t *obj, bool retain);
+        JSONObject(json_t *obj, bool retain = true);
 
         json_t *m_obj;
     };
-
 }
 
 #endif /* __cplusplus */