From 5ffcee110cb1676bb6cd53541e541c784cf4c2ab Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 20 Apr 2025 14:11:43 +0000 Subject: [PATCH] jobs: Stream logs as base64-encoded data 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 --- src/pakfire/job.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pakfire/job.c b/src/pakfire/job.c index 7dc7dc7e..bc3c7ccb 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -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; } -- 2.39.5