]> git.ipfire.org Git - pakfire.git/commitdiff
httpclient: Add option to set a base URL
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 02:52:53 +0000 (02:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 02:52:53 +0000 (02:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/httpclient.c
src/libpakfire/include/pakfire/httpclient.h

index 30fb64d2b1a8f027a5a3c20a331d214b1a46d037..882b29d673e6ad854c6db70e1b1ca04e1bfcc858 100644 (file)
@@ -28,6 +28,7 @@
 #include <pakfire/httpclient.h>
 #include <pakfire/logging.h>
 #include <pakfire/progress.h>
+#include <pakfire/string.h>
 #include <pakfire/xfer.h>
 
 // The number of concurrent downloads
@@ -37,6 +38,9 @@ struct pakfire_httpclient {
        struct pakfire_ctx* ctx;
        int nrefs;
 
+       // Base URL
+       char baseurl[PATH_MAX];
+
        // Event Loop
        sd_event* loop;
        int still_running;
@@ -479,6 +483,17 @@ CURLSH* pakfire_httpclient_share(struct pakfire_httpclient* client) {
        return client->share;
 }
 
+const char* pakfire_httpclient_get_baseurl(struct pakfire_httpclient* client) {
+       if (*client->baseurl)
+               return client->baseurl;
+
+       return NULL;
+}
+
+int pakfire_httpclient_set_baseurl(struct pakfire_httpclient* client, const char* baseurl) {
+       return pakfire_string_set(client->baseurl, baseurl);
+}
+
 int pakfire_httpclient_create_xfer(struct pakfire_xfer** xfer,
                        struct pakfire_httpclient* client, const char* url) {
        return pakfire_xfer_create(xfer, client->ctx, client, url);
index 304cfe41b89da9ba7cfa910b8f03c44b449768c9..43a579724865d9a4470bef5a68af4259ab0d102c 100644 (file)
@@ -41,6 +41,9 @@ struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* d
 sd_event* pakfire_httpclient_loop(struct pakfire_httpclient* client);
 CURLSH* pakfire_httpclient_share(struct pakfire_httpclient* downloader);
 
+const char* pakfire_httpclient_get_baseurl(struct pakfire_httpclient* client);
+int pakfire_httpclient_set_baseurl(struct pakfire_httpclient* client, const char* baseurl);
+
 int pakfire_httpclient_create_xfer(struct pakfire_xfer** xfer,
        struct pakfire_httpclient* downloader, const char* url);