]> git.ipfire.org Git - pakfire.git/commitdiff
buildservice: Fetch URL from configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 09:52:42 +0000 (09:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 09:52:42 +0000 (09:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/buildservice.c

index a26076ee7aff2b8c126b42a925b44c5d4e5b7011..1f4d146fbb667e15a6adbf426b9cff7ebde7afc7 100644 (file)
 #############################################################################*/
 
 #include <errno.h>
+#include <limits.h>
 #include <stdlib.h>
 
 #include <pakfire/buildservice.h>
+#include <pakfire/config.h>
 #include <pakfire/ctx.h>
+#include <pakfire/logging.h>
 #include <pakfire/private.h>
+#include <pakfire/string.h>
 
 struct pakfire_buildservice {
        struct pakfire_ctx* ctx;
        int nrefs;
+
+       char url[PATH_MAX];
 };
 
+static int pakfire_buildservice_setup(struct pakfire_buildservice* service) {
+       struct pakfire_config* config = NULL;
+       const char* url = NULL;
+       int r;
+
+       // Fetch the configuration
+       config = pakfire_ctx_get_config(service->ctx);
+       if (!config) {
+               r = 1;
+               goto ERROR;
+       }
+
+       // Fetch the URL
+       url = pakfire_config_get(config, "client", "url", NULL);
+       if (!url) {
+               CTX_ERROR(service->ctx, "Build Service URL is not configured\n");
+               r = 1;
+               goto ERROR;
+       }
+
+       // Store the URL
+       r = pakfire_string_set(service->url, url);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (config)
+               pakfire_config_unref(config);
+
+       return r;
+}
+
 static void pakfire_buildservice_free(struct pakfire_buildservice* service) {
        if (service->ctx)
                pakfire_ctx_unref(service->ctx);
@@ -40,6 +78,7 @@ static void pakfire_buildservice_free(struct pakfire_buildservice* service) {
 PAKFIRE_EXPORT int pakfire_buildservice_create(
                struct pakfire_buildservice** service, struct pakfire_ctx* ctx) {
        struct pakfire_buildservice* s = NULL;
+       int r;
 
        // Allocate some memory
        s = calloc(1, sizeof(*s));
@@ -52,10 +91,20 @@ PAKFIRE_EXPORT int pakfire_buildservice_create(
        // Initialize the reference counter
        s->nrefs = 1;
 
+       // Setup everything
+       r = pakfire_buildservice_setup(s);
+       if (r)
+               goto ERROR;
+
        // Return the pointer
        *service = s;
 
        return 0;
+
+ERROR:
+       pakfire_buildservice_free(s);
+
+       return r;
 }
 
 PAKFIRE_EXPORT struct pakfire_buildservice* pakfire_buildservice_ref(