]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Pass the HTTP status code to the response callback
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 08:56:10 +0000 (08:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 08:56:10 +0000 (08:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/upload_list.c
src/pakfire/client.c
src/pakfire/xfer.c
src/pakfire/xfer.h

index caf8bbcb8ee3c58c1d1356461e066fb25f51f0b7..0e35fbc8204f4fc59281ab813a8dce1aca19bfe8 100644 (file)
@@ -30,7 +30,7 @@
 static const char* doc = "Lists all uploads";
 
 static int list_callback(struct pakfire_xfer* xfer,
-               pakfire_xfer_error_code_t code, struct json_object* response, void* data) {
+               pakfire_xfer_error_code_t code, int status, struct json_object* response, void* data) {
        // XXX For now, just dump the entire JSON object
        return cli_dump_json(response);
 }
index c182c38a146e64160ac3d9213d07ed103fe1e2b6..3ac3dda4ba004ca9ed86eaf2293538918dc08cc2 100644 (file)
@@ -167,7 +167,7 @@ static int pakfire_client_ready(struct pakfire_client* self) {
 }
 
 static int pakfire_client_auth_response(struct pakfire_xfer* xfer,
-       pakfire_xfer_error_code_t code, json_object* response, void* data);
+       pakfire_xfer_error_code_t code, int status, json_object* response, void* data);
 
 static int pakfire_client_auth_required(struct pakfire_client* self);
 
@@ -649,7 +649,7 @@ static int pakfire_client_auth_successful(
 }
 
 static int pakfire_client_auth_response(struct pakfire_xfer* xfer,
-               pakfire_xfer_error_code_t code, json_object* response, void* data) {
+               pakfire_xfer_error_code_t code, int status, json_object* response, void* data) {
        struct pakfire_client* client = data;
 
        switch (code) {
@@ -893,7 +893,7 @@ static void pakfire_client_build_free(struct pakfire_client_build* self) {
 }
 
 static int pakfire_client_build_response(struct pakfire_xfer* xfer,
-               pakfire_xfer_error_code_t status, struct json_object* response, void* data) {
+               pakfire_xfer_error_code_t code, int status, struct json_object* response, void* data) {
        struct pakfire_client_build* build = data;
        const char* uuid = NULL;
        int r = 0;
@@ -906,7 +906,7 @@ static int pakfire_client_build_response(struct pakfire_xfer* xfer,
                        goto ERROR;
 
                // Call the callback
-               r = build->callback(build->client, status, uuid, build->data);
+               r = build->callback(build->client, code, uuid, build->data);
        }
 
 ERROR:
@@ -1095,8 +1095,8 @@ ERROR:
 }
 
 static int pakfire_upload_payload_callback(struct pakfire_xfer* xfer,
-               pakfire_xfer_error_code_t code, struct json_object* response, void* data) {
-       pakfire_client_upload_status status = PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL;
+               pakfire_xfer_error_code_t code, int status, struct json_object* response, void* data) {
+       pakfire_client_upload_status s = PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL;
        struct pakfire_client_upload* upload = data;
        int r = 0;
 
@@ -1106,13 +1106,13 @@ static int pakfire_upload_payload_callback(struct pakfire_xfer* xfer,
                        break;
 
                default:
-                       status = PAKFIRE_CLIENT_UPLOAD_ERROR;
+                       s = PAKFIRE_CLIENT_UPLOAD_ERROR;
                        break;
        }
 
        // Call the callback (if any)
        if (upload->callback)
-               r = upload->callback(upload->client, status, upload->path, upload->uuid, upload->data);
+               r = upload->callback(upload->client, s, upload->path, upload->uuid, upload->data);
 
        // Free the upload
        pakfire_client_upload_free(upload);
@@ -1163,7 +1163,7 @@ ERROR:
 }
 
 static int pakfire_client_upload_response(struct pakfire_xfer* xfer,
-               pakfire_xfer_error_code_t code, struct json_object* response, void* data) {
+               pakfire_xfer_error_code_t code, int status, struct json_object* response, void* data) {
        struct pakfire_client_upload* self = data;
        const char* uuid = NULL;
        int r;
index f024ad983a5bb7a81afb09151feeca8e2e0bb220..dc56c11937229ce9173fb2b6eddefd4b21ff2fec 100644 (file)
@@ -934,7 +934,7 @@ ERROR:
        return r;
 }
 
-static int pakfire_xfer_call_response_callback(struct pakfire_xfer* self, pakfire_xfer_error_code_t code) {
+static int pakfire_xfer_call_response_callback(struct pakfire_xfer* self, pakfire_xfer_error_code_t code, int status) {
        struct json_object* response = NULL;
        char* error = NULL;
        int r;
@@ -956,7 +956,7 @@ static int pakfire_xfer_call_response_callback(struct pakfire_xfer* self, pakfir
        }
 
        // Run the callback
-       r = self->callbacks.response(self, code, response, self->callbacks.data);
+       r = self->callbacks.response(self, code, status, response, self->callbacks.data);
 
 ERROR:
        if (response)
@@ -967,7 +967,7 @@ ERROR:
        return r;
 }
 
-static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {
+static int pakfire_xfer_fail(struct pakfire_xfer* xfer, pakfire_xfer_error_code_t code, int status) {
        int r;
 
        // Drop the hasher
@@ -1023,7 +1023,7 @@ static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {
 
        // Call the response callback
        if (xfer->callbacks.response) {
-               r = pakfire_xfer_call_response_callback(xfer, code);
+               r = pakfire_xfer_call_response_callback(xfer, code, status);
                if (r < 0)
                        return r;
        }
@@ -1096,7 +1096,7 @@ static int pakfire_xfer_socket_recv(struct pakfire_xfer* xfer) {
 
                        // We seem to have lost the connection
                        case CURLE_GOT_NOTHING:
-                               return pakfire_xfer_fail(xfer, PAKFIRE_XFER_TRANSPORT_ERROR);
+                               return pakfire_xfer_fail(xfer, PAKFIRE_XFER_TRANSPORT_ERROR, 599);
 
                        default:
                                ERROR(xfer->ctx, "Could not read from WebSocket: %s\n", curl_easy_strerror(r));
@@ -1258,7 +1258,7 @@ static int pakfire_xfer_verify(struct pakfire_xfer* self) {
                        pakfire_hashes_dump(self->ctx, &computed_hashes, LOG_ERR);
 
                        // Consider the download failed
-                       return pakfire_xfer_fail(self, PAKFIRE_XFER_DIGEST_MISMATCH);
+                       return pakfire_xfer_fail(self, PAKFIRE_XFER_DIGEST_MISMATCH, 599);
 
                // Errors
                default:
@@ -1267,7 +1267,7 @@ static int pakfire_xfer_verify(struct pakfire_xfer* self) {
        }
 }
 
-static int pakfire_xfer_save(struct pakfire_xfer* xfer) {
+static int pakfire_xfer_save(struct pakfire_xfer* xfer, int status) {
        int fd = -EBADF;
        int r;
 
@@ -1277,7 +1277,7 @@ static int pakfire_xfer_save(struct pakfire_xfer* xfer) {
 
        // Call the output callback if configured
        if (xfer->callbacks.response)
-               return pakfire_xfer_call_response_callback(xfer, PAKFIRE_XFER_OK);
+               return pakfire_xfer_call_response_callback(xfer, PAKFIRE_XFER_OK, status);
 
        // Nothing to do if path isn't set
        if (!*xfer->path)
@@ -1326,9 +1326,9 @@ pakfire_xfer_error_code_t pakfire_xfer_done(
        CURL* h = xfer->handle;
        int r;
        const char* scheme = NULL;
-       long response_code;
        long http_version;
        double total_time;
+       long status = 0;
 
        curl_off_t download_size = 0;
        curl_off_t download_speed = 0;
@@ -1356,9 +1356,9 @@ pakfire_xfer_error_code_t pakfire_xfer_done(
                DEBUG(xfer->ctx, "  Effective URL: %s\n", xfer->effective_url);
 
        // Response code
-       curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &response_code);
-       if (response_code)
-               DEBUG(xfer->ctx, "  Response code: %ld\n", response_code);
+       curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &status);
+       if (status)
+               DEBUG(xfer->ctx, "  Status Code: %ld\n", status);
 
        // HTTP Version
        curl_easy_getinfo(h, CURLINFO_HTTP_VERSION, &http_version);
@@ -1411,7 +1411,7 @@ pakfire_xfer_error_code_t pakfire_xfer_done(
                                        return r;
 
                                // Save the payload
-                               r = pakfire_xfer_save(xfer);
+                               r = pakfire_xfer_save(xfer, status);
                                if (r < 0)
                                        return r;
                                break;
@@ -1419,7 +1419,7 @@ pakfire_xfer_error_code_t pakfire_xfer_done(
                        case PAKFIRE_XFER_UPLOAD:
                                // Call the output callback if configured
                                if (xfer->callbacks.response) {
-                                       r = pakfire_xfer_call_response_callback(xfer, PAKFIRE_XFER_OK);
+                                       r = pakfire_xfer_call_response_callback(xfer, PAKFIRE_XFER_OK, status);
                                        if (r < 0)
                                                return r;
                                }
@@ -1439,7 +1439,7 @@ pakfire_xfer_error_code_t pakfire_xfer_done(
                code = pakfire_xfer_code(code, code);
 
                // Report that something went wrong
-               r = pakfire_xfer_fail(xfer, code);
+               r = pakfire_xfer_fail(xfer, code, status);
                if (r < 0)
                        return r;
        }
index 855b38bce2ab87c0eb63098dc961e036cd39f2a4..c9809390dcc73712a6e535cbdfcbcd96c3de8bbb 100644 (file)
@@ -128,7 +128,7 @@ int pakfire_xfer_set_output_buffer(struct pakfire_xfer* xfer, char** buffer, siz
 int pakfire_xfer_set_output_path(struct pakfire_xfer* xfer, const char* path);
 
 typedef int (*pakfire_xfer_response_callback)(struct pakfire_xfer* xfer,
-       pakfire_xfer_error_code_t status, json_object* response, void* data);
+       pakfire_xfer_error_code_t error, int code, struct json_object* response, void* data);
 
 int pakfire_xfer_set_response_callback(struct pakfire_xfer* xfer,
        pakfire_xfer_response_callback callback, void* data);