From: Michael Tremer Date: Fri, 27 Jun 2025 08:40:39 +0000 (+0000) Subject: xfer: Remove convenience function to run synchronous API requests X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55b5e8337d966d549c1f274e3b9fe7cf7705e6e6;p=pakfire.git xfer: Remove convenience function to run synchronous API requests Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/xfer.c b/src/pakfire/xfer.c index 9419062f..1b4136e2 100644 --- a/src/pakfire/xfer.c +++ b/src/pakfire/xfer.c @@ -1920,70 +1920,3 @@ ERROR: return r; } - -static pakfire_xfer_error_code_t pakfire_xfer_run_api_request_once( - struct pakfire_xfer* xfer, struct json_object** response) { - char* buffer = NULL; - size_t length = 0; - int r; - - // Write the response to the buffer - r = pakfire_xfer_set_output_buffer(xfer, &buffer, &length); - if (r) - goto ERROR; - - // Run the xfer - r = pakfire_xfer_run(xfer, PAKFIRE_XFER_NO_PROGRESS); - if (r) - goto ERROR; - - // Parse the response - r = pakfire_xfer_parse_api_response(xfer, buffer, length, response); - if (r) { - ERROR(xfer->ctx, "Could not parse the API response: %s\n", strerror(-r)); - goto ERROR; - } - -ERROR: - // Reset the output stream - pakfire_xfer_reset_output(xfer); - - if (buffer) - free(buffer); - - return r; -} - -/* - This function sends a request and automatically parses the response. - The response might optionally be returned if response is not NULL. -*/ -pakfire_xfer_error_code_t pakfire_xfer_run_api_request( - struct pakfire_xfer* xfer, struct json_object* request, struct json_object** response) { - pakfire_xfer_error_code_t r; - - // Set the request body - if (request) { - r = pakfire_xfer_set_json_payload(xfer, request); - if (r < 0) - return r; - } - - // Loop indefinitely... - for (;;) { - r = pakfire_xfer_run_api_request_once(xfer, response); - switch (r) { - // Try again after five seconds for recoverable errors - case PAKFIRE_XFER_DNS_ERROR: - case PAKFIRE_XFER_TRANSPORT_ERROR: - case PAKFIRE_XFER_TIMEOUT: - usleep(5000000); - break; - - default: - return r; - } - } - - return 0; -} diff --git a/src/pakfire/xfer.h b/src/pakfire/xfer.h index 06d3460d..855b38bc 100644 --- a/src/pakfire/xfer.h +++ b/src/pakfire/xfer.h @@ -140,8 +140,6 @@ int pakfire_xfer_prepare(struct pakfire_xfer* xfer, struct pakfire_progress* pro pakfire_xfer_error_code_t pakfire_xfer_done(struct pakfire_xfer* xfer, sd_event* loop, int code); pakfire_xfer_error_code_t pakfire_xfer_run(struct pakfire_xfer* xfer, int flags); -pakfire_xfer_error_code_t pakfire_xfer_run_api_request( - struct pakfire_xfer* xfer, struct json_object* request, struct json_object** response); // WebSocket typedef int (*pakfire_xfer_open_callback)(struct pakfire_xfer* xfer, void* data);