return json_object_object_add(json, name, object);
}
-int pakfire_json_get_int64(struct json_object* json, const char* key, int64_t* value) {
+static int __pakfire_json_get_object(struct json_object* json,
+ const char* key, const json_type type, struct json_object** o) {
struct json_object* object = NULL;
int r;
return -ENOMSG;
// Check if this is an integer
- r = json_object_is_type(object, json_type_int);
+ r = json_object_is_type(object, type);
if (!r)
return -ENOMSG;
+ // Return the pointer
+ *o = object;
+
+ return 0;
+}
+
+int pakfire_json_get_string(struct json_object* json, const char* key, const char** value) {
+ struct json_object* object = NULL;
+ int r;
+
+ // Fetch the object
+ r = __pakfire_json_get_object(json, key, json_type_string, &object);
+ if (r < 0)
+ return r;
+
+ // Return the value
+ *value = json_object_get_string(object);
+
+ return 0;
+}
+
+int pakfire_json_get_int64(struct json_object* json, const char* key, int64_t* value) {
+ struct json_object* object = NULL;
+ int r;
+
+ // Fetch the object
+ r = __pakfire_json_get_object(json, key, json_type_int, &object);
+ if (r < 0)
+ return r;
+
// Return the value
*value = json_object_get_int64(object);
return 0;
}
+
+int pakfire_json_get_object(struct json_object* json, const char* key, struct json_object** object) {
+ return __pakfire_json_get_object(json, key, json_type_object, object);
+}
+
+int pakfire_json_get_array(struct json_object* json, const char* key, struct json_object** array) {
+ return __pakfire_json_get_object(json, key, json_type_array, array);
+}
int pakfire_json_add_object(struct json_object* json, const char* name, struct json_object** o);
int pakfire_json_add_array(struct json_object* json, const char* name, struct json_object** array);
+int pakfire_json_get_string(struct json_object* json, const char* key, const char** value);
int pakfire_json_get_int64(struct json_object* json, const char* key, int64_t* value);
+int pakfire_json_get_object(struct json_object* json, const char* key, struct json_object** object);
+int pakfire_json_get_array(struct json_object* json, const char* key, struct json_object** array);
#endif /* PAKFIRE_JSON_H */