return -c;
}
-
-/*
- This function parses an API response
-*/
-static int pakfire_xfer_parse_api_response(struct pakfire_xfer* xfer,
- const char* buffer, const size_t length, struct json_object** object) {
- struct json_object* error = NULL;
- struct json_object* o = NULL;
- char* e = NULL;
- int r;
-
- // Check if we received any data
- if (!length) {
- DEBUG(xfer->ctx, "Received an empty response\n");
-
- // Reset the object
- if (object)
- *object = NULL;
-
- return 0;
- }
-
- // XXX Maybe fetch the parser's error message here?!
-
- // Parse the buffer
- r = pakfire_json_parse(&o, &e, buffer, length);
- if (r < 0) {
- ERROR(xfer->ctx, "Could not parse the response: %s\n", e);
- goto ERROR;
- }
-
- // Check if the response is a dictionary
- if (!json_object_is_type(o, json_type_object)) {
- ERROR(xfer->ctx, "The received object is not a JSON dict\n");
- r = -EBADMSG;
- goto ERROR;
- }
-
- // Fetch error
- r = json_object_object_get_ex(o, "error", &error);
- if (r) {
- r = pakfire_xfer_handle_api_error(xfer, error);
- goto ERROR;
- }
-
- // Return the object
- if (object)
- *object = json_object_get(o);
-
-ERROR:
- if (o)
- json_object_put(o);
- if (e)
- free(e);
-
- return r;
-}