From: Michael Tremer Date: Fri, 27 Jun 2025 14:01:00 +0000 (+0000) Subject: httpclient: Create its own type X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c3053e452939614d4dda043581645dbcb542b3d3;p=pakfire.git httpclient: Create its own type Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 64303dda..4ad67e4d 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -79,7 +79,7 @@ struct pakfire_client { sd_event* loop; // HTTP Client - struct pakfire_httpclient* httpclient; + pakfire_httpclient* httpclient; // URL char url[PATH_MAX]; diff --git a/src/pakfire/httpclient.c b/src/pakfire/httpclient.c index fd14bc0b..d3332bfc 100644 --- a/src/pakfire/httpclient.c +++ b/src/pakfire/httpclient.c @@ -36,7 +36,7 @@ // The number of concurrent downloads #define DEFAULT_MAX_PARALLEL 4 -struct pakfire_httpclient_xfer { +typedef struct pakfire_httpclient_xfer { TAILQ_ENTRY(pakfire_httpclient_xfer) nodes; struct pakfire_xfer* xfer; @@ -47,7 +47,7 @@ struct pakfire_httpclient_xfer { PAKFIRE_XFER_RUNNING, PAKFIRE_XFER_FINISHED, } status; -}; +} pakfire_httpclient_xfer; struct pakfire_httpclient { pakfire_ctx* ctx; @@ -93,13 +93,13 @@ struct pakfire_httpclient { unsigned int total_downloadsize; }; -static int pakfire_httpclient_has_flag(struct pakfire_httpclient* self, int flags) { +static int pakfire_httpclient_has_flag(pakfire_httpclient* self, int flags) { return self->flags & flags; } static int pakfire_httpclient_xfer_create( - struct pakfire_httpclient_xfer** x, struct pakfire_xfer* xfer) { - struct pakfire_httpclient_xfer* e = NULL; + pakfire_httpclient_xfer** x, struct pakfire_xfer* xfer) { + pakfire_httpclient_xfer* e = NULL; // Allocate some space e = calloc(1, sizeof(*e)); @@ -118,15 +118,15 @@ static int pakfire_httpclient_xfer_create( return 0; } -static void pakfire_httpclient_xfer_free(struct pakfire_httpclient_xfer* x) { +static void pakfire_httpclient_xfer_free(pakfire_httpclient_xfer* x) { if (x->xfer) pakfire_xfer_unref(x->xfer); free(x); } static size_t pakfire_httpclient_count_xfers( - struct pakfire_httpclient* self, const enum pakfire_httpclient_xfer_status status) { - struct pakfire_httpclient_xfer* e = NULL; + pakfire_httpclient* self, const enum pakfire_httpclient_xfer_status status) { + pakfire_httpclient_xfer* e = NULL; size_t counter = 0; TAILQ_FOREACH(e, &self->xfers, nodes) { @@ -137,19 +137,19 @@ static size_t pakfire_httpclient_count_xfers( return counter; } -static size_t pakfire_httpclient_num_running_xfers(struct pakfire_httpclient* self) { +static size_t pakfire_httpclient_num_running_xfers(pakfire_httpclient* self) { return pakfire_httpclient_count_xfers(self, PAKFIRE_XFER_RUNNING); } -static size_t pakfire_httpclient_num_queued_xfers(struct pakfire_httpclient* self) { +static size_t pakfire_httpclient_num_queued_xfers(pakfire_httpclient* self) { return pakfire_httpclient_count_xfers(self, PAKFIRE_XFER_QUEUED); } /* Returns the next queued xfer or NULL */ -static struct pakfire_httpclient_xfer* pakfire_httpclient_get_queued_xfer(struct pakfire_httpclient* self) { - struct pakfire_httpclient_xfer* e = NULL; +static pakfire_httpclient_xfer* pakfire_httpclient_get_queued_xfer(pakfire_httpclient* self) { + pakfire_httpclient_xfer* e = NULL; TAILQ_FOREACH(e, &self->xfers, nodes) { if (e->status == PAKFIRE_XFER_QUEUED) @@ -159,9 +159,9 @@ static struct pakfire_httpclient_xfer* pakfire_httpclient_get_queued_xfer(struct return NULL; } -static struct pakfire_httpclient_xfer* pakfire_httpclient_xfer_find( - struct pakfire_httpclient* self, struct pakfire_xfer* xfer) { - struct pakfire_httpclient_xfer* e = NULL; +static pakfire_httpclient_xfer* pakfire_httpclient_xfer_find( + pakfire_httpclient* self, struct pakfire_xfer* xfer) { + pakfire_httpclient_xfer* e = NULL; TAILQ_FOREACH(e, &self->xfers, nodes) { if (e->xfer == xfer) @@ -172,7 +172,7 @@ static struct pakfire_httpclient_xfer* pakfire_httpclient_xfer_find( } static int pakfire_httpclient_remove( - struct pakfire_httpclient* self, struct pakfire_httpclient_xfer* e) { + pakfire_httpclient* self, pakfire_httpclient_xfer* e) { int r; // Nothing to do if not running @@ -199,7 +199,7 @@ static int pakfire_httpclient_remove( } static int pakfire_httpclient_launch_one( - struct pakfire_httpclient* self, struct pakfire_httpclient_xfer* e) { + pakfire_httpclient* self, pakfire_httpclient_xfer* e) { int r; // Remove the handle if we ware launching again @@ -236,8 +236,8 @@ static int pakfire_httpclient_launch_one( return 0; } -static int pakfire_httpclient_launch(struct pakfire_httpclient* self) { - struct pakfire_httpclient_xfer* e = NULL; +static int pakfire_httpclient_launch(pakfire_httpclient* self) { + pakfire_httpclient_xfer* e = NULL; int r; while (pakfire_httpclient_num_running_xfers(self) < self->max_parallel) { @@ -255,8 +255,8 @@ static int pakfire_httpclient_launch(struct pakfire_httpclient* self) { return 0; } -static int pakfire_httpclient_check(struct pakfire_httpclient* self) { - struct pakfire_httpclient_xfer* e = NULL; +static int pakfire_httpclient_check(pakfire_httpclient* self) { + pakfire_httpclient_xfer* e = NULL; struct pakfire_xfer* xfer = NULL; int r; @@ -329,7 +329,7 @@ static int pakfire_httpclient_check(struct pakfire_httpclient* self) { } static int __pakfire_httpclient_timer(sd_event_source* s, uint64_t usec, void* data) { - struct pakfire_httpclient* self = data; + pakfire_httpclient* self = data; int r; DEBUG(self->ctx, "cURL timer fired\n"); @@ -347,7 +347,7 @@ static int __pakfire_httpclient_timer(sd_event_source* s, uint64_t usec, void* d } static int pakfire_httpclient_timer(CURLM* multi, long timeout_ms, void* data) { - struct pakfire_httpclient* self = data; + pakfire_httpclient* self = data; int r; // A negative value indicates that we should remove the timer @@ -383,7 +383,7 @@ static int pakfire_httpclient_timer(CURLM* multi, long timeout_ms, void* data) { } static int __pakfire_httpclient_socket(sd_event_source* s, int fd, uint32_t events, void* data) { - struct pakfire_httpclient* self = data; + pakfire_httpclient* self = data; int r; int action = 0; @@ -422,7 +422,7 @@ static int __pakfire_httpclient_socket(sd_event_source* s, int fd, uint32_t even } static int pakfire_httpclient_socket(CURL* e, curl_socket_t fd, int what, void* data, void* data2) { - struct pakfire_httpclient* self = data; + pakfire_httpclient* self = data; sd_event_source* s = data2; uint32_t events = 0; int r; @@ -485,7 +485,7 @@ ERROR: static int pakfire_httpclient_loop_exited(sd_event_source* event, void* data); static int pakfire_httpclient_loop_started(sd_event_source* event, void* data) { - struct pakfire_httpclient* self = data; + pakfire_httpclient* self = data; int r; // Start the progress @@ -511,7 +511,7 @@ static int pakfire_httpclient_loop_started(sd_event_source* event, void* data) { } static int pakfire_httpclient_loop_exited(sd_event_source* event, void* data) { - struct pakfire_httpclient* self = data; + pakfire_httpclient* self = data; int r; // Finish the progress @@ -537,7 +537,7 @@ static int pakfire_httpclient_loop_exited(sd_event_source* event, void* data) { &self->events.loop_started, pakfire_httpclient_loop_started, self); } -static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* self) { +static int pakfire_httpclient_setup_loop(pakfire_httpclient* self) { int r; // Fetch the context's loop @@ -566,7 +566,7 @@ static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* self) { return 0; } -static int pakfire_httpclient_setup_curl(struct pakfire_httpclient* self) { +static int pakfire_httpclient_setup_curl(pakfire_httpclient* self) { int r; // Initialize cURL @@ -646,7 +646,7 @@ static int pakfire_httpclient_setup_curl(struct pakfire_httpclient* self) { return 0; } -static int pakfire_httpclient_setup_progress(struct pakfire_httpclient* self, int flags) { +static int pakfire_httpclient_setup_progress(pakfire_httpclient* self, int flags) { int r; // Use some sensible defaults @@ -665,8 +665,8 @@ static int pakfire_httpclient_setup_progress(struct pakfire_httpclient* self, in return 0; } -static void pakfire_httpclient_free(struct pakfire_httpclient* self) { - struct pakfire_httpclient_xfer* e = NULL; +static void pakfire_httpclient_free(pakfire_httpclient* self) { + pakfire_httpclient_xfer* e = NULL; // Free any xfers that we still hold while (!TAILQ_EMPTY(&self->xfers)) { @@ -695,9 +695,9 @@ static void pakfire_httpclient_free(struct pakfire_httpclient* self) { free(self); } -int pakfire_httpclient_create(struct pakfire_httpclient** client, +int pakfire_httpclient_create(pakfire_httpclient** client, pakfire_ctx* ctx, int progress_flags) { - struct pakfire_httpclient* self = NULL; + pakfire_httpclient* self = NULL; int r; // Allocate a new object @@ -742,13 +742,13 @@ ERROR: return r; } -struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* self) { +pakfire_httpclient* pakfire_httpclient_ref(pakfire_httpclient* self) { ++self->nrefs; return self; } -struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* self) { +pakfire_httpclient* pakfire_httpclient_unref(pakfire_httpclient* self) { if (--self->nrefs > 0) return self; @@ -756,8 +756,8 @@ struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* s return NULL; } -int pakfire_httpclient_enqueue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer) { - struct pakfire_httpclient_xfer* e = NULL; +int pakfire_httpclient_enqueue(pakfire_httpclient* self, struct pakfire_xfer* xfer) { + pakfire_httpclient_xfer* e = NULL; int r; // Create a new object @@ -778,8 +778,8 @@ int pakfire_httpclient_enqueue(struct pakfire_httpclient* self, struct pakfire_x return 0; } -int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer) { - struct pakfire_httpclient_xfer* e = NULL; +int pakfire_httpclient_dequeue(pakfire_httpclient* self, struct pakfire_xfer* xfer) { + pakfire_httpclient_xfer* e = NULL; int r; // Find reference @@ -801,7 +801,7 @@ int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_x return 0; } -int pakfire_httpclient_run(struct pakfire_httpclient* self, const char* title) { +int pakfire_httpclient_run(pakfire_httpclient* self, const char* title) { int r = 0; // This function will start the event loop (usually used when we are running diff --git a/src/pakfire/httpclient.h b/src/pakfire/httpclient.h index 0fcce7a9..a0cf53c9 100644 --- a/src/pakfire/httpclient.h +++ b/src/pakfire/httpclient.h @@ -21,20 +21,20 @@ #ifndef PAKFIRE_HTTPCLIENT_H #define PAKFIRE_HTTPCLIENT_H -struct pakfire_httpclient; +typedef struct pakfire_httpclient pakfire_httpclient; #include #include -int pakfire_httpclient_create(struct pakfire_httpclient** client, +int pakfire_httpclient_create(pakfire_httpclient** client, pakfire_ctx* ctx, int progress_flags); -struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* self); -struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* self); +pakfire_httpclient* pakfire_httpclient_ref(pakfire_httpclient* self); +pakfire_httpclient* pakfire_httpclient_unref(pakfire_httpclient* self); -int pakfire_httpclient_enqueue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer); -int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer); +int pakfire_httpclient_enqueue(pakfire_httpclient* self, struct pakfire_xfer* xfer); +int pakfire_httpclient_dequeue(pakfire_httpclient* self, struct pakfire_xfer* xfer); -int pakfire_httpclient_run(struct pakfire_httpclient* self, const char* title); +int pakfire_httpclient_run(pakfire_httpclient* self, const char* title); #endif /* PAKFIRE_HTTPCLIENT_H */ diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index 78632aad..cb21e6c5 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -1923,7 +1923,7 @@ ERROR: } static int pakfire_transaction_download_package(struct pakfire_transaction* transaction, - struct pakfire_httpclient* httpclient, struct pakfire_package* pkg) { + pakfire_httpclient* httpclient, struct pakfire_package* pkg) { struct pakfire_repo* repo = NULL; struct pakfire_xfer* xfer = NULL; int r; @@ -1995,7 +1995,7 @@ static int pakfire_transaction_package_needs_download( } int pakfire_transaction_download(struct pakfire_transaction* transaction) { - struct pakfire_httpclient* httpclient = NULL; + pakfire_httpclient* httpclient = NULL; int r; // Initialize the HTTP client diff --git a/tests/libpakfire/httpclient.c b/tests/libpakfire/httpclient.c index a89cfd0b..0ab316f8 100644 --- a/tests/libpakfire/httpclient.c +++ b/tests/libpakfire/httpclient.c @@ -27,7 +27,7 @@ #define DOWNLOAD_URL "file://" ABS_TOP_SRCDIR "/tests/data/beep-1.3-2.ip3.x86_64.pfm" static int test_create(const struct test* t) { - struct pakfire_httpclient* client = NULL; + pakfire_httpclient* client = NULL; int r = EXIT_FAILURE; // Create a HTTP client diff --git a/tests/testsuite.h b/tests/testsuite.h index 38a497c5..a7123616 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -55,7 +55,7 @@ struct test { struct pakfire* pakfire; // HTTP Client - struct pakfire_httpclient* httpclient; + pakfire_httpclient* httpclient; }; struct testsuite {