]> git.ipfire.org Git - collecty.git/commitdiff
source: Add a default request handler
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 11:35:50 +0000 (11:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 11:35:50 +0000 (11:35 +0000)
This function catches basic cURL errors (e.g. host unreachable, etc) so
that we will throttle sending requests at some point.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index c9e4617784653bfa38fb2f84e1b18d4ea2111b61..6108cfcfc888af38ea86e377524f138008fec735 100644 (file)
@@ -640,6 +640,41 @@ ERROR:
        return r;
 }
 
+static int td_source_request_failed(td_ctx* ctx, int code, td_file* file, void* data) {
+       td_source* self = data;
+       int r;
+
+       switch (code) {
+               case CURLE_OK:
+                       r = 0;
+                       break;
+
+               // For unrecoverable errors, we will disable the source straight away
+               case CURLE_UNSUPPORTED_PROTOCOL:
+               case CURLE_NOT_BUILT_IN:
+               case CURLE_RANGE_ERROR:
+                       return td_source_disable(self);
+
+               // Invalid requests
+               case CURLE_URL_MALFORMAT:
+                       r = -EINVAL;
+                       break;
+
+               // Failed to connect
+               case CURLE_COULDNT_CONNECT:
+                       r = -ECONNREFUSED;
+                       break;
+
+               // Handle anything else that is unknown
+               default:
+                       r = -EINVAL;
+                       break;
+       }
+
+       // Run the error detection
+       return td_source_error_detection(self, r, 0);
+}
+
 int td_source_create_request(td_source* self, td_request** request) {
        td_client* client = NULL;
        int r;
@@ -654,6 +689,9 @@ int td_source_create_request(td_source* self, td_request** request) {
        if (r < 0)
                goto ERROR;
 
+       // Set the failure callback
+       td_request_on_failure(*request, td_source_request_failed, self);
+
 ERROR:
        if (client)
                td_client_unref(client);