mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-07 14:11:52 +00:00
curl: Use a struct declaration instead of void pointers
We can declare the scruct in a header file and define it in a source file so we can avoid using void pointers for the handle. It's a better approach because compilers can trigger errors if we use a different type. Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
+9
-20
@@ -175,7 +175,7 @@ static void reevaluate_number_of_parallel_downloads(struct swupd_curl_parallel_h
|
||||
info("Curl - Reducing number of parallel downloads to %ld\n", h->max_xfer);
|
||||
}
|
||||
|
||||
void *swupd_curl_parallel_download_start(size_t max_xfer)
|
||||
struct swupd_curl_parallel_handle *swupd_curl_parallel_download_start(size_t max_xfer)
|
||||
{
|
||||
struct swupd_curl_parallel_handle *h = calloc(1, sizeof(struct swupd_curl_parallel_handle));
|
||||
ON_NULL_ABORT(h);
|
||||
@@ -211,30 +211,24 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void swupd_curl_parallel_download_set_callbacks(void *handle, swupd_curl_success_cb success_cb, swupd_curl_error_cb error_cb, swupd_curl_free_cb free_cb)
|
||||
void swupd_curl_parallel_download_set_callbacks(struct swupd_curl_parallel_handle *h, swupd_curl_success_cb success_cb, swupd_curl_error_cb error_cb, swupd_curl_free_cb free_cb)
|
||||
{
|
||||
struct swupd_curl_parallel_handle *h;
|
||||
|
||||
if (!handle) {
|
||||
if (!h) {
|
||||
error("Curl - Invalid parallel download handle\n");
|
||||
return;
|
||||
}
|
||||
h = handle;
|
||||
|
||||
h->success_cb = success_cb;
|
||||
h->error_cb = error_cb;
|
||||
h->free_cb = free_cb;
|
||||
}
|
||||
|
||||
void swupd_curl_parallel_download_set_progress_callbacks(void *handle, swupd_curl_progress_cb progress_cb, void *data)
|
||||
void swupd_curl_parallel_download_set_progress_callbacks(struct swupd_curl_parallel_handle *h, swupd_curl_progress_cb progress_cb, void *data)
|
||||
{
|
||||
struct swupd_curl_parallel_handle *h;
|
||||
|
||||
if (!handle) {
|
||||
if (!h) {
|
||||
error("Curl - Invalid parallel download handle\n");
|
||||
return;
|
||||
}
|
||||
h = handle;
|
||||
|
||||
h->progress_cb = progress_cb;
|
||||
h->data = data;
|
||||
@@ -505,16 +499,14 @@ out_bad:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int swupd_curl_parallel_download_enqueue(void *handle, const char *url, const char *filename, const char *hash, void *data)
|
||||
int swupd_curl_parallel_download_enqueue(struct swupd_curl_parallel_handle *h, const char *url, const char *filename, const char *hash, void *data)
|
||||
{
|
||||
struct swupd_curl_parallel_handle *h;
|
||||
struct multi_curl_file *file;
|
||||
|
||||
if (!handle) {
|
||||
if (!h) {
|
||||
error("Curl - Invalid parallel download handle\n");
|
||||
return -1;
|
||||
}
|
||||
h = handle;
|
||||
|
||||
file = calloc(1, sizeof(struct multi_curl_file));
|
||||
ON_NULL_ABORT(file);
|
||||
@@ -539,22 +531,19 @@ int swupd_curl_parallel_download_enqueue(void *handle, const char *url, const ch
|
||||
return process_download(h, file);
|
||||
}
|
||||
|
||||
int swupd_curl_parallel_download_end(void *handle, int *num_downloads)
|
||||
int swupd_curl_parallel_download_end(struct swupd_curl_parallel_handle *h, int *num_downloads)
|
||||
{
|
||||
struct swupd_curl_parallel_handle *h;
|
||||
struct multi_curl_file *file;
|
||||
int i, downloads = 0;
|
||||
struct list *l;
|
||||
bool retry = true;
|
||||
int ret = 0;
|
||||
|
||||
if (!handle) {
|
||||
if (!h) {
|
||||
error("Curl - Invalid parallel download handle\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
h = handle;
|
||||
|
||||
while (poll_fewer_than(h, 0, 0) == 0 && retry) {
|
||||
retry = false;
|
||||
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ static void download_mix_file(struct file *file)
|
||||
free_string(&filename);
|
||||
}
|
||||
|
||||
static void download_file(void *download_handle, struct file *file)
|
||||
static void download_file(struct swupd_curl_parallel_handle *download_handle, struct file *file)
|
||||
{
|
||||
char *url, *filename;
|
||||
|
||||
@@ -121,7 +121,7 @@ static double fullfile_query_total_download_size(struct list *files)
|
||||
*/
|
||||
int download_fullfiles(struct list *files, int *num_downloads)
|
||||
{
|
||||
void *download_handle;
|
||||
struct swupd_curl_parallel_handle *download_handle;
|
||||
struct list *iter;
|
||||
struct list *need_download = NULL;
|
||||
struct file *file;
|
||||
|
||||
+2
-2
@@ -113,7 +113,7 @@ static bool download_successful(void *data)
|
||||
return finalize_pack_download(pack_data->module, pack_data->newversion, pack_data->filename) == 0;
|
||||
}
|
||||
|
||||
static int download_pack(void *download_handle, int oldversion, int newversion, char *module, int is_mix)
|
||||
static int download_pack(struct swupd_curl_parallel_handle *download_handle, int oldversion, int newversion, char *module, int is_mix)
|
||||
{
|
||||
char *url = NULL;
|
||||
int err = -1;
|
||||
@@ -208,7 +208,7 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ
|
||||
int err;
|
||||
unsigned int list_length;
|
||||
unsigned int complete = 0;
|
||||
void *download_handle;
|
||||
struct swupd_curl_parallel_handle *download_handle;
|
||||
char *packs_size;
|
||||
|
||||
/* make a new list with only the bundles we actually need to download packs for */
|
||||
|
||||
+10
-5
@@ -30,6 +30,11 @@ enum download_status {
|
||||
DOWNLOAD_STATUS_ERROR,
|
||||
};
|
||||
|
||||
/*
|
||||
* Handle for swupd curl parallel functions.
|
||||
*/
|
||||
struct swupd_curl_parallel_handle;
|
||||
|
||||
/*
|
||||
* Callback to be called when a download is successful.
|
||||
*/
|
||||
@@ -92,7 +97,7 @@ int swupd_curl_get_file_memory(const char *url, struct curl_file_data *file_data
|
||||
*
|
||||
* Note: This function is non-blocking.
|
||||
*/
|
||||
void *swupd_curl_parallel_download_start(size_t max_xfer);
|
||||
struct swupd_curl_parallel_handle *swupd_curl_parallel_download_start(size_t max_xfer);
|
||||
|
||||
/*
|
||||
* Set parallel downloads callbacks.
|
||||
@@ -108,7 +113,7 @@ void *swupd_curl_parallel_download_start(size_t max_xfer);
|
||||
* to schedule a retry.
|
||||
* - free_cb(): Called when data is ready to be freed.
|
||||
*/
|
||||
void swupd_curl_parallel_download_set_callbacks(void *handle, swupd_curl_success_cb success_cb, swupd_curl_error_cb error_cb, swupd_curl_free_cb free_cb);
|
||||
void swupd_curl_parallel_download_set_callbacks(struct swupd_curl_parallel_handle *handle, swupd_curl_success_cb success_cb, swupd_curl_error_cb error_cb, swupd_curl_free_cb free_cb);
|
||||
|
||||
/*
|
||||
* Set parallel downloads progress callback
|
||||
@@ -118,7 +123,7 @@ void swupd_curl_parallel_download_set_callbacks(void *handle, swupd_curl_success
|
||||
* function prints the download progress, so it will always return 0.
|
||||
* - data: User data to be informed to progress_cb.
|
||||
*/
|
||||
void swupd_curl_parallel_download_set_progress_callbacks(void *handle, swupd_curl_progress_cb progress_cb, void *data);
|
||||
void swupd_curl_parallel_download_set_progress_callbacks(struct swupd_curl_parallel_handle *handle, swupd_curl_progress_cb progress_cb, void *data);
|
||||
|
||||
/*
|
||||
* Enqueue a file to be downloaded. If the number of current downloads is higher
|
||||
@@ -136,7 +141,7 @@ void swupd_curl_parallel_download_set_progress_callbacks(void *handle, swupd_cur
|
||||
*
|
||||
* Note: This function MAY be blocked.
|
||||
*/
|
||||
int swupd_curl_parallel_download_enqueue(void *handle, const char *url, const char *filename, const char *hash, void *data);
|
||||
int swupd_curl_parallel_download_enqueue(struct swupd_curl_parallel_handle *handle, const char *url, const char *filename, const char *hash, void *data);
|
||||
|
||||
/*
|
||||
* Finish all pending downloads and free memory allocated by parallel download
|
||||
@@ -149,7 +154,7 @@ int swupd_curl_parallel_download_enqueue(void *handle, const char *url, const ch
|
||||
*
|
||||
* Note: This function MAY be blocked.
|
||||
*/
|
||||
int swupd_curl_parallel_download_end(void *handle, int *num_downloads);
|
||||
int swupd_curl_parallel_download_end(struct swupd_curl_parallel_handle *handle, int *num_downloads);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user