+ DDF ddf(NULL);
+
+ switch (json_typeof(json)) {
+ case JSON_OBJECT: {
+ void *iter = json_object_iter(json);
+
+ while (iter != NULL) {
+ const char *key = json_object_iter_key(iter);
+ json_t *value = json_object_iter_value(iter);
+ ddf.add(jsonToDdf(value).name(key));
+ iter = json_object_iter_next(json, iter);
+ }
+ break;
+ }
+ case JSON_ARRAY: {
+ size_t i;
+
+ for (i = 0; i < json_array_size(json); i++) {
+ DDF value = jsonToDdf(json_array_get(json, i));
+ ddf.add(value);
+ }
+ break;
+ }
+ case JSON_STRING:
+ ddf.string(json_string_value(json));
+ break;
+ case JSON_INTEGER:
+ ddf.integer(json_integer_value(json));
+ break;
+ case JSON_REAL:
+ ddf.floating(json_real_value(json));
+ break;
+ case JSON_TRUE:
+ ddf.integer(1L);
+ break;
+ case JSON_FALSE:
+ ddf.integer(0L);
+ break;
+ case JSON_NULL:
+ break;
+ }
+
+ return ddf;
+}
+
+json_t *
+gss_eap_shib_attr_provider::jsonRepresentation(void) const
+{
+ json_t *obj, *attrs;
+
+ obj = json_object();
+ if (obj == NULL)
+ throw new std::bad_alloc;
+
+ /* FIXME check json_object_set_new return value */
+ json_object_set_new(obj, "authenticated", json_integer(m_authenticated));
+
+ attrs = json_array();
+ if (attrs == NULL) {
+ json_decref(obj);
+ throw new std::bad_alloc;
+ }
+
+ for (vector<Attribute*>::const_iterator a = m_attributes.begin();
+ a != m_attributes.end(); ++a) {
+ DDF attr = (*a)->marshall();
+ /* FIXME check json_array_append_new return value */
+ json_array_append_new(attrs, ddfToJson(attr));
+ }
+
+ json_object_set_new(obj, "attributes", attrs);
+
+ return obj;