From: Michael Tremer Date: Sat, 21 Jun 2025 17:29:24 +0000 (+0000) Subject: buildservice: Send all other API requests with a JSON payload X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51d51fee6d779bf5a5515b0be0e60179fb02c88f;p=people%2Fms%2Fpakfire.git buildservice: Send all other API requests with a JSON payload Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/buildservice.c b/src/pakfire/buildservice.c index d245fbb1..7f1ae677 100644 --- a/src/pakfire/buildservice.c +++ b/src/pakfire/buildservice.c @@ -393,6 +393,7 @@ ERROR: int pakfire_buildservice_build(struct pakfire_buildservice* service, const char* upload, const char* repo, const char** arches, int flags) { struct pakfire_xfer* xfer = NULL; + struct json_object* request = NULL; int r; // Create a new xfer @@ -405,37 +406,39 @@ int pakfire_buildservice_build(struct pakfire_buildservice* service, const char* if (r) goto ERROR; + // Create a new request object + r = pakfire_json_new_object(&request); + if (r < 0) + goto ERROR; + // Add the upload parameter - r = pakfire_xfer_add_param(xfer, "upload", "%s", upload); - if (r) + r = pakfire_json_add_string(request, "upload", upload); + if (r < 0) goto ERROR; // Add the repo parameter if (repo) { - r = pakfire_xfer_add_param(xfer, "repo", "%s", repo); - if (r) + r = pakfire_json_add_string(request, "repo", repo); + if (r < 0) goto ERROR; } // Add any arches if (arches) { - for (const char** arch = arches; *arch; arch++) { - r = pakfire_xfer_add_param(xfer, "arch", "%s", *arch); - if (r) - goto ERROR; - } + r = pakfire_json_add_string_array(request, "arches", (char**)arches); + if (r < 0) + goto ERROR; } // Disable tests? - if (flags & PAKFIRE_BUILDSERVICE_DISABLE_TESTS) { - r = pakfire_xfer_add_param(xfer, "disable_test_builds", "%s", "yes"); - if (r) - goto ERROR; - } + r = pakfire_json_add_boolean(request, "disable_test_builds", + flags & PAKFIRE_BUILDSERVICE_DISABLE_TESTS); + if (r < 0) + goto ERROR; // Send the request - r = pakfire_xfer_run_api_request(xfer, NULL, NULL); - if (r) + r = pakfire_xfer_run_api_request(xfer, request, NULL); + if (r < 0) goto ERROR; ERROR: @@ -832,6 +835,7 @@ ERROR: int pakfire_buildservice_create_repo(struct pakfire_buildservice* service, const char* distro, const char* name, const char* description, struct json_object** p) { struct pakfire_xfer* xfer = NULL; + struct json_object* request = NULL; struct json_object* response = NULL; int r; @@ -849,20 +853,25 @@ int pakfire_buildservice_create_repo(struct pakfire_buildservice* service, if (r) goto ERROR; + // Create the request + r = pakfire_json_new_object(&request); + if (r < 0) + goto ERROR; + // Set name - r = pakfire_xfer_add_param(xfer, "name", "%s", name); + r = pakfire_json_add_string(request, "name", name); if (r) goto ERROR; // Set description if (description) { - r = pakfire_xfer_add_param(xfer, "description", "%s", description); + r = pakfire_json_add_string(request, "description", description); if (r) goto ERROR; } // Send the request - r = pakfire_xfer_run_api_request(xfer, NULL, &response); + r = pakfire_xfer_run_api_request(xfer, request, &response); if (r) goto ERROR; @@ -873,6 +882,8 @@ int pakfire_buildservice_create_repo(struct pakfire_buildservice* service, ERROR: if (xfer) pakfire_xfer_unref(xfer); + if (request) + json_object_put(request); if (response) json_object_put(response);