From: Michael Tremer Date: Fri, 10 Jul 2026 11:13:03 +0000 (+0000) Subject: request: Handle request responses X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c9e9a44d7ea8c0aeb1c01685a0a45af877c3fed;p=telemetry.git request: Handle request responses Signed-off-by: Michael Tremer --- diff --git a/src/daemon/request.c b/src/daemon/request.c index a1f5809..7072fe6 100644 --- a/src/daemon/request.c +++ b/src/daemon/request.c @@ -304,5 +304,86 @@ int td_request_launch(td_request* self) { } int td_request_done(td_request* self, int code) { - return 0; + char* effective_url = NULL; + td_file* file = NULL; + double total_time; + int status; + int r; + + curl_off_t download_size = 0; + curl_off_t download_speed = 0; + + // Log the result + DEBUG(self->ctx, "cURL xfer done: %d - %s\n", code, curl_easy_strerror(code)); + if (*self->error) + DEBUG(self->ctx, " Error: %s\n", self->error); + + // Effective URL + r = curl_easy_getinfo(self->handle, CURLINFO_EFFECTIVE_URL, &effective_url); + if (r) + goto ERROR; + + if (effective_url) + DEBUG(self->ctx, " Effective URL: %s\n", effective_url); + + // Response code + r = curl_easy_getinfo(self->handle, CURLINFO_RESPONSE_CODE, &status); + if (r) + goto ERROR; + + if (status) + DEBUG(self->ctx, " Status Code: %ld\n", status); + + // Total Time + r = curl_easy_getinfo(self->handle, CURLINFO_TOTAL_TIME, &total_time); + if (r) + goto ERROR; + + DEBUG(self->ctx, " Total Time: %.2fms\n", total_time * 1000.0); + + // Download Size + r = curl_easy_getinfo(self->handle, CURLINFO_SIZE_DOWNLOAD_T, &download_size); + if (r) + goto ERROR; + + if (download_size) + DEBUG(self->ctx, " Download Size: %ld bytes\n", download_size); + + // Download Speed + r = curl_easy_getinfo(self->handle, CURLINFO_SPEED_DOWNLOAD_T, &download_speed); + if (r) + goto ERROR; + + if (download_speed) + DEBUG(self->ctx, " Download Speed: %ld bps\n", download_speed); + + // Make the output buffer to a file object + r = td_file_open_buffer(&file, self->ctx, self->buffer); + if (r < 0) + goto ERROR; + + // Call any callbacks + switch (code) { + // Success + case 0: + if (self->callbacks.on_success) { + r = self->callbacks.on_success(self->ctx, + file, self->callbacks.on_success_data); + } + break; + + // Failure + default: + if (self->callbacks.on_failure) { + r = self->callbacks.on_failure(self->ctx, + code, file, self->callbacks.on_failure_data); + } + break; + } + +ERROR: + if (file) + td_file_unref(file); + + return r; }