From: Michael Tremer Date: Tue, 17 Oct 2023 09:52:42 +0000 (+0000) Subject: buildservice: Fetch URL from configuration X-Git-Tag: 0.9.30~1465 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d2cc9e6881aa2b2e5f7e57026237d92421cf8af;p=pakfire.git buildservice: Fetch URL from configuration Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/buildservice.c b/src/libpakfire/buildservice.c index a26076ee7..1f4d146fb 100644 --- a/src/libpakfire/buildservice.c +++ b/src/libpakfire/buildservice.c @@ -19,17 +19,55 @@ #############################################################################*/ #include +#include #include #include +#include #include +#include #include +#include 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(