]> git.ipfire.org Git - pakfire.git/commitdiff
buildservice: Send all other API requests with a JSON payload
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 17:29:24 +0000 (17:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 17:29:24 +0000 (17:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/buildservice.c

index d245fbb14025745cb52f0d419f451f56ad700573..7f1ae67717dc02b23a006a17138bce69e308e3a1 100644 (file)
@@ -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);