(task_http) Cleanups

This commit is contained in:
libretroadmin 2022-07-09 01:24:59 +02:00
parent fa9e56d824
commit 460ca09c87
1 changed files with 31 additions and 54 deletions

View File

@ -94,9 +94,7 @@ static int cb_http_conn_default(void *data_, size_t len)
if (!network_init())
return -1;
http->handle = net_http_new(http->connection.handle);
if (!http->handle)
if (!(http->handle = net_http_new(http->connection.handle)))
{
http->error = true;
return -1;
@ -191,9 +189,7 @@ task_finished:
free(tmp);
if (task_get_cancelled(task))
{
task_set_error(task, strdup("Task cancelled."));
}
else
{
data = (http_transfer_data_t*)malloc(sizeof(*data));
@ -238,24 +234,15 @@ static void task_http_transfer_cleanup(retro_task_t *task)
static bool task_http_finder(retro_task_t *task, void *user_data)
{
http_handle_t *http = NULL;
if (!task || (task->handler != task_http_transfer_handler))
return false;
if (!user_data)
return false;
http = (http_handle_t*)task->state;
if (!http)
return false;
if (task && (task->handler == task_http_transfer_handler) && user_data)
if ((http = (http_handle_t*)task->state))
return string_is_equal(http->connection_url, (const char*)user_data);
return false;
}
static bool task_http_retriever(retro_task_t *task, void *data)
{
http_transfer_info_t *info = (http_transfer_info_t*)data;
/* Extract HTTP handle and return already if invalid */
http_handle_t *http = (http_handle_t *)task->state;
if (!http)
@ -310,9 +297,7 @@ static void* task_push_http_transfer_generic(
}
}
http = (http_handle_t*)malloc(sizeof(*http));
if (!http)
if (!(http = (http_handle_t*)malloc(sizeof(*http))))
goto error;
http->connection.handle = conn;
@ -330,9 +315,8 @@ static void* task_push_http_transfer_generic(
strlcpy(http->connection_url, url, sizeof(http->connection_url));
http->status = HTTP_STATUS_CONNECTION_TRANSFER;
t = task_init();
if (!t)
if (!(t = task_init()))
goto error;
t->handler = task_http_transfer_handler;
@ -361,12 +345,11 @@ void* task_push_http_transfer(const char *url, bool mute,
const char *type,
retro_task_callback_t cb, void *user_data)
{
if (string_is_empty(url))
return NULL;
if (!string_is_empty(url))
return task_push_http_transfer_generic(
net_http_connection_new(url, "GET", NULL),
url, mute, type, cb, user_data);
return NULL;
}
void* task_push_http_transfer_file(const char* url, bool mute,
@ -380,11 +363,9 @@ void* task_push_http_transfer_file(const char* url, bool mute,
if (string_is_empty(url))
return NULL;
t = (retro_task_t*)task_push_http_transfer_generic(
if (!(t = (retro_task_t*)task_push_http_transfer_generic(
net_http_connection_new(url, "GET", NULL),
url, mute, type, cb, transfer_data);
if (!t)
url, mute, type, cb, transfer_data)))
return NULL;
if (transfer_data)
@ -414,11 +395,10 @@ void* task_push_http_transfer_with_user_agent(const char *url, bool mute,
if (string_is_empty(url))
return NULL;
conn = net_http_connection_new(url, "GET", NULL);
if (!conn)
if (!(conn = net_http_connection_new(url, "GET", NULL)))
return NULL;
if (user_agent != NULL)
if (user_agent)
net_http_connection_set_user_agent(conn, user_agent);
/* assert: task_push_http_transfer_generic will free conn on failure */
@ -434,11 +414,10 @@ void* task_push_http_transfer_with_headers(const char *url, bool mute,
if (string_is_empty(url))
return NULL;
conn = net_http_connection_new(url, "GET", NULL);
if (!conn)
if (!(conn = net_http_connection_new(url, "GET", NULL)))
return NULL;
if (headers != NULL)
if (headers)
net_http_connection_set_headers(conn, headers);
/* assert: task_push_http_transfer_generic will free conn on failure */
@ -449,11 +428,11 @@ void* task_push_http_post_transfer(const char *url,
const char *post_data, bool mute,
const char *type, retro_task_callback_t cb, void *user_data)
{
if (string_is_empty(url))
return NULL;
if (!string_is_empty(url))
return task_push_http_transfer_generic(
net_http_connection_new(url, "POST", post_data),
url, mute, type, cb, user_data);
return NULL;
}
void* task_push_http_post_transfer_with_user_agent(const char *url,
@ -466,11 +445,10 @@ void* task_push_http_post_transfer_with_user_agent(const char *url,
if (string_is_empty(url))
return NULL;
conn = net_http_connection_new(url, "POST", post_data);
if (!conn)
if (!(conn = net_http_connection_new(url, "POST", post_data)))
return NULL;
if (user_agent != NULL)
if (user_agent)
net_http_connection_set_user_agent(conn, user_agent);
/* assert: task_push_http_transfer_generic will free conn on failure */
@ -487,11 +465,10 @@ void* task_push_http_post_transfer_with_headers(const char *url,
if (string_is_empty(url))
return NULL;
conn = net_http_connection_new(url, "POST", post_data);
if (!conn)
if (!(conn = net_http_connection_new(url, "POST", post_data)))
return NULL;
if (headers != NULL)
if (headers)
net_http_connection_set_headers(conn, headers);
/* assert: task_push_http_transfer_generic will free conn on failure */