- json_object_put(apps->prvarr);
- json_object_put(apps->pubarr);
- json_object_put(apps->pubobj);
- json_object_put(apps->prvobj);
+ json_object_put(apps->publics.all);
+ json_object_put(apps->publics.visibles);
+ json_object_put(apps->publics.byname);
+ json_object_put(apps->privates.all);
+ json_object_put(apps->privates.visibles);
+ json_object_put(apps->privates.byname);
+}
+
+/*
+ * Append the field 'data' to the field 'name' of the 'object'.
+ * When a second append is done to one field, it is automatically
+ * transformed to an array.
+ * Return 0 in case of success or -1 in case of error.
+ */
+static int append_field(
+ struct json_object *object,
+ const char *name,
+ struct json_object *data
+)
+{
+ struct json_object *item, *array;
+
+ if (!json_object_object_get_ex(object, name, &item))
+ json_object_object_add(object, name, data);
+ else {
+ if (json_object_is_type(item, json_type_array))
+ array = item;
+ else {
+ array = json_object_new_array();
+ if (!array)
+ goto error;
+ json_object_array_add(array, json_object_get(item));
+ json_object_object_add(object, name, array);
+ }
+ json_object_array_add(array, data);
+ }
+ return 0;
+ error:
+ json_object_put(data);
+ errno = ENOMEM;
+ return -1;