]> git.ipfire.org Git - pakfire.git/commitdiff
jobs: Stream logs as base64-encoded data
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 20 Apr 2025 14:11:43 +0000 (14:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 20 Apr 2025 14:11:43 +0000 (14:11 +0000)
There should not be anything else but ASCII or Unicode characters here,
but we can never be too sure. Therefore we will encode all data as
base64 to keep the protocol somewhat extensible.

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

index 7dc7dc7e6c19e84b3193567e290804298329515b..bc3c7ccbba12dbc5362ad12e4f43df37688bb1d0 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <systemd/sd-event.h>
 
+#include <pakfire/base64.h>
 #include <pakfire/build.h>
 #include <pakfire/config.h>
 #include <pakfire/constants.h>
@@ -760,9 +761,17 @@ static int pakfire_job_send_log_line(struct pakfire_job* job,
                const struct timeval* timestamp, int priority, const char* line, size_t length) {
        struct json_object* message = NULL;
        struct json_object* data = NULL;
+       char* base64 = NULL;
        char buffer[64];
        int r;
 
+       // Encode the line to base64
+       r = pakfire_b64encode(&base64, (const unsigned char*)line, length);
+       if (r < 0) {
+               ERROR(job->ctx, "Failed to encode the log line: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
        // Create a new JSON object
        data = json_object_new_object();
        if (!data) {
@@ -787,7 +796,7 @@ static int pakfire_job_send_log_line(struct pakfire_job* job,
                goto ERROR;
 
        // Add the line
-       r = pakfire_json_add_stringn(data, "line", line, length);
+       r = pakfire_json_add_string(data, "line", base64);
        if (r)
                goto ERROR;
 
@@ -825,6 +834,8 @@ ERROR:
                json_object_put(message);
        if (data)
                json_object_put(data);
+       if (base64)
+               free(base64);
 
        return r;
 }