From: Michael Tremer Date: Sat, 21 Jun 2025 16:24:06 +0000 (+0000) Subject: xfer: Add a function to add a JSON request body X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ffaf116305d27a4a98249000c8bdcff9e559cbf;p=pakfire.git xfer: Add a function to add a JSON request body Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/xfer.c b/src/pakfire/xfer.c index 21d9c10c..0c018e62 100644 --- a/src/pakfire/xfer.c +++ b/src/pakfire/xfer.c @@ -706,6 +706,18 @@ int pakfire_xfer_set_payload(struct pakfire_xfer* self, const char* payload) { return 0; } +int pakfire_xfer_set_json_payload(struct pakfire_xfer* self, struct json_object* json) { + const char* s = NULL; + + // Convert the payload to string + s = pakfire_json_to_string(json); + if (!s) + return -EINVAL; + + // Set the payload + return pakfire_xfer_set_payload(self, s); +} + static void pakfire_xfer_reset_output(struct pakfire_xfer* xfer) { if (xfer->fin) { fclose(xfer->fin); diff --git a/src/pakfire/xfer.h b/src/pakfire/xfer.h index 1dd2d167..aaf5e0b9 100644 --- a/src/pakfire/xfer.h +++ b/src/pakfire/xfer.h @@ -120,7 +120,9 @@ int pakfire_xfer_add_query(struct pakfire_xfer* xfer, int pakfire_xfer_add_param(struct pakfire_xfer* xfer, const char* key, const char* format, ...) __attribute__((format(printf, 3, 4))); +// Payload int pakfire_xfer_set_payload(struct pakfire_xfer* self, const char* payload); +int pakfire_xfer_set_json_payload(struct pakfire_xfer* self, struct json_object* json); // Output int pakfire_xfer_set_output(struct pakfire_xfer* xfer, FILE* f);