2015-05-05 15:36:58 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-05-05 15:36:58 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-05-09 18:10:58 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-05-05 15:36:58 +00:00
|
|
|
#include <net/net_http.h>
|
2016-01-20 03:07:24 +00:00
|
|
|
#include <string/stdstring.h>
|
2015-05-05 16:34:48 +00:00
|
|
|
#include <compat/strl.h>
|
2015-06-08 09:10:12 +00:00
|
|
|
#include <file/file_path.h>
|
2015-06-28 17:10:36 +00:00
|
|
|
#include <net/net_compat.h>
|
2017-06-28 02:41:38 +00:00
|
|
|
#include <retro_timers.h>
|
2024-09-09 03:47:32 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-05-05 15:36:58 +00:00
|
|
|
|
2019-05-22 07:55:10 +00:00
|
|
|
#ifdef RARCH_INTERNAL
|
2018-01-01 07:08:09 +00:00
|
|
|
#include "../gfx/video_display_server.h"
|
2019-05-22 07:55:10 +00:00
|
|
|
#endif
|
2019-01-20 01:17:43 +00:00
|
|
|
#include "task_file_transfer.h"
|
2016-02-09 16:12:39 +00:00
|
|
|
#include "tasks_internal.h"
|
2015-05-05 15:36:58 +00:00
|
|
|
|
2015-07-08 19:35:24 +00:00
|
|
|
enum http_status_enum
|
|
|
|
{
|
2017-05-20 12:02:16 +00:00
|
|
|
HTTP_STATUS_CONNECTION_TRANSFER = 0,
|
2015-07-08 19:35:24 +00:00
|
|
|
HTTP_STATUS_CONNECTION_TRANSFER_PARSE,
|
|
|
|
HTTP_STATUS_TRANSFER,
|
|
|
|
HTTP_STATUS_TRANSFER_PARSE,
|
|
|
|
HTTP_STATUS_TRANSFER_PARSE_FREE
|
|
|
|
};
|
|
|
|
|
2017-05-13 16:10:26 +00:00
|
|
|
struct http_transfer_info
|
2016-05-18 22:04:38 +00:00
|
|
|
{
|
|
|
|
int progress;
|
2024-09-09 03:47:32 +00:00
|
|
|
char url[NAME_MAX_LENGTH];
|
2017-05-13 16:10:26 +00:00
|
|
|
};
|
2016-05-18 22:04:38 +00:00
|
|
|
|
2017-05-13 16:10:26 +00:00
|
|
|
struct http_handle
|
2015-07-08 19:35:24 +00:00
|
|
|
{
|
2020-08-14 16:51:50 +00:00
|
|
|
struct http_t *handle;
|
|
|
|
transfer_cb_t cb;
|
2015-07-08 19:35:24 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct http_connection_t *handle;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
} connection;
|
|
|
|
unsigned status;
|
2015-11-25 02:12:31 +00:00
|
|
|
bool error;
|
2024-09-09 03:47:32 +00:00
|
|
|
char connection_elem[NAME_MAX_LENGTH];
|
|
|
|
char connection_url[NAME_MAX_LENGTH];
|
2017-05-13 16:10:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct http_transfer_info http_transfer_info_t;
|
|
|
|
typedef struct http_handle http_handle_t;
|
2015-07-08 19:35:24 +00:00
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_http_con_iterate_transfer(http_handle_t *http)
|
2015-05-05 15:36:58 +00:00
|
|
|
{
|
|
|
|
if (!net_http_connection_iterate(http->connection.handle))
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_http_conn_iterate_transfer_parse(
|
2016-02-03 16:41:04 +00:00
|
|
|
http_handle_t *http)
|
2015-05-05 15:36:58 +00:00
|
|
|
{
|
|
|
|
if (net_http_connection_done(http->connection.handle))
|
|
|
|
{
|
|
|
|
if (http->connection.handle && http->connection.cb)
|
|
|
|
http->connection.cb(http, 0);
|
|
|
|
}
|
2017-12-12 07:55:31 +00:00
|
|
|
|
2015-05-05 15:36:58 +00:00
|
|
|
net_http_connection_free(http->connection.handle);
|
|
|
|
|
|
|
|
http->connection.handle = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cb_http_conn_default(void *data_, size_t len)
|
|
|
|
{
|
|
|
|
http_handle_t *http = (http_handle_t*)data_;
|
|
|
|
|
|
|
|
if (!http)
|
|
|
|
return -1;
|
|
|
|
|
2015-06-28 17:10:36 +00:00
|
|
|
if (!network_init())
|
|
|
|
return -1;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(http->handle = net_http_new(http->connection.handle)))
|
2015-05-05 15:36:58 +00:00
|
|
|
{
|
2015-11-25 02:12:31 +00:00
|
|
|
http->error = true;
|
2015-05-05 15:36:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
http->cb = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-13 08:19:53 +00:00
|
|
|
* task_http_iterate_transfer:
|
2015-05-05 15:36:58 +00:00
|
|
|
*
|
|
|
|
* Resumes HTTP transfer update.
|
|
|
|
*
|
|
|
|
* Returns: 0 when finished, -1 when we should continue
|
|
|
|
* with the transfer on the next frame.
|
|
|
|
**/
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_http_iterate_transfer(retro_task_t *task)
|
2015-05-05 15:36:58 +00:00
|
|
|
{
|
2015-11-30 12:17:46 +00:00
|
|
|
http_handle_t *http = (http_handle_t*)task->state;
|
2015-07-01 17:40:50 +00:00
|
|
|
size_t pos = 0, tot = 0;
|
|
|
|
|
2016-10-09 17:33:19 +00:00
|
|
|
/* FIXME: This wouldn't be needed if we could wait for a timeout */
|
2017-01-03 17:26:52 +00:00
|
|
|
if (task_queue_is_threaded())
|
2016-10-09 17:33:19 +00:00
|
|
|
retro_sleep(1);
|
|
|
|
|
2015-07-01 17:40:50 +00:00
|
|
|
if (!net_http_update(http->handle, &pos, &tot))
|
|
|
|
{
|
2020-01-23 00:42:55 +00:00
|
|
|
if (tot == 0)
|
|
|
|
task_set_progress(task, -1);
|
|
|
|
else if (pos < (((size_t)-1) / 100))
|
|
|
|
/* prefer multiply then divide for more accurate results */
|
|
|
|
task_set_progress(task, (signed)(pos * 100 / tot));
|
|
|
|
else
|
|
|
|
/* but invert the logic if it would cause an overflow */
|
2021-07-18 04:47:25 +00:00
|
|
|
task_set_progress(task, MIN((signed)pos / (tot / 100), 100));
|
2015-07-01 17:40:50 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-05-05 15:36:58 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
static void task_http_transfer_handler(retro_task_t *task)
|
2015-05-05 15:36:58 +00:00
|
|
|
{
|
2016-05-13 08:28:44 +00:00
|
|
|
http_transfer_data_t *data = NULL;
|
|
|
|
http_handle_t *http = (http_handle_t*)task->state;
|
2015-05-05 15:36:58 +00:00
|
|
|
|
2016-12-29 05:50:18 +00:00
|
|
|
if (task_get_cancelled(task))
|
2016-05-05 18:32:36 +00:00
|
|
|
goto task_finished;
|
|
|
|
|
2015-05-05 15:36:58 +00:00
|
|
|
switch (http->status)
|
|
|
|
{
|
|
|
|
case HTTP_STATUS_CONNECTION_TRANSFER_PARSE:
|
2016-05-13 08:19:53 +00:00
|
|
|
task_http_conn_iterate_transfer_parse(http);
|
2015-05-05 15:36:58 +00:00
|
|
|
http->status = HTTP_STATUS_TRANSFER;
|
|
|
|
break;
|
|
|
|
case HTTP_STATUS_CONNECTION_TRANSFER:
|
2016-05-13 08:19:53 +00:00
|
|
|
if (!task_http_con_iterate_transfer(http))
|
2015-05-05 15:36:58 +00:00
|
|
|
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
|
|
|
break;
|
|
|
|
case HTTP_STATUS_TRANSFER:
|
2016-05-13 08:19:53 +00:00
|
|
|
if (!task_http_iterate_transfer(task))
|
2015-11-24 01:30:57 +00:00
|
|
|
goto task_finished;
|
2015-05-05 15:36:58 +00:00
|
|
|
break;
|
2015-11-24 01:30:57 +00:00
|
|
|
case HTTP_STATUS_TRANSFER_PARSE:
|
2015-11-23 14:13:26 +00:00
|
|
|
goto task_finished;
|
2015-05-05 15:36:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-07-08 19:18:34 +00:00
|
|
|
|
2016-05-05 18:32:36 +00:00
|
|
|
if (http->error)
|
2015-11-25 01:17:38 +00:00
|
|
|
goto task_finished;
|
|
|
|
|
2015-11-23 14:13:26 +00:00
|
|
|
return;
|
|
|
|
task_finished:
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_finished(task, true);
|
2015-07-08 19:35:24 +00:00
|
|
|
|
2015-11-23 14:13:26 +00:00
|
|
|
if (http->handle)
|
|
|
|
{
|
2015-11-24 01:30:57 +00:00
|
|
|
size_t len = 0;
|
|
|
|
char *tmp = (char*)net_http_data(http->handle, &len, false);
|
2023-08-04 07:20:50 +00:00
|
|
|
struct string_list *headers = net_http_headers(http->handle);
|
2015-11-24 01:30:57 +00:00
|
|
|
|
|
|
|
if (tmp && http->cb)
|
|
|
|
http->cb(tmp, len);
|
|
|
|
|
2023-07-29 02:59:44 +00:00
|
|
|
if (!tmp)
|
2015-11-24 01:30:57 +00:00
|
|
|
tmp = (char*)net_http_data(http->handle, &len, true);
|
|
|
|
|
2023-07-29 02:59:44 +00:00
|
|
|
if (task_get_cancelled(task))
|
|
|
|
{
|
2015-11-24 01:30:57 +00:00
|
|
|
if (tmp)
|
|
|
|
free(tmp);
|
2023-08-04 07:20:50 +00:00
|
|
|
string_list_free(headers);
|
2015-11-24 01:30:57 +00:00
|
|
|
|
2023-07-29 02:59:44 +00:00
|
|
|
task_set_error(task,
|
|
|
|
strldup("Task cancelled.", sizeof("Task cancelled.")));
|
2015-11-24 01:30:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-04 07:20:50 +00:00
|
|
|
data = (http_transfer_data_t*)malloc(sizeof(*data));
|
|
|
|
data->data = tmp;
|
|
|
|
data->headers = headers;
|
|
|
|
data->len = len;
|
|
|
|
data->status = net_http_status(http->handle);
|
2015-07-08 19:18:34 +00:00
|
|
|
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_data(task, data);
|
2023-07-29 02:59:44 +00:00
|
|
|
|
|
|
|
if (!task->mute && net_http_error(http->handle))
|
|
|
|
task_set_error(task, strldup("Download failed.",
|
|
|
|
sizeof("Download failed.")));
|
2015-11-24 01:30:57 +00:00
|
|
|
}
|
2015-07-08 19:35:24 +00:00
|
|
|
|
2015-11-23 14:13:26 +00:00
|
|
|
net_http_delete(http->handle);
|
2015-11-25 02:12:31 +00:00
|
|
|
} else if (http->error)
|
2022-08-25 14:31:54 +00:00
|
|
|
task_set_error(task, strldup("Internal error.",
|
|
|
|
sizeof("Internal error.")));
|
2015-07-08 19:35:24 +00:00
|
|
|
|
2015-11-23 14:13:26 +00:00
|
|
|
free(http);
|
2015-07-08 19:35:24 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 01:42:25 +00:00
|
|
|
static void task_http_transfer_cleanup(retro_task_t *task)
|
|
|
|
{
|
2021-03-22 14:01:57 +00:00
|
|
|
http_transfer_data_t* data = (http_transfer_data_t*)task_get_data(task);
|
2021-03-16 01:42:25 +00:00
|
|
|
if (data)
|
|
|
|
{
|
2023-08-04 07:20:50 +00:00
|
|
|
string_list_free(data->headers);
|
2021-03-16 01:42:25 +00:00
|
|
|
if (data->data)
|
|
|
|
free(data->data);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
static bool task_http_finder(retro_task_t *task, void *user_data)
|
2015-11-30 14:36:53 +00:00
|
|
|
{
|
2016-05-13 08:28:44 +00:00
|
|
|
http_handle_t *http = NULL;
|
2022-07-08 23:24:59 +00:00
|
|
|
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;
|
2015-11-30 14:36:53 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
static bool task_http_retriever(retro_task_t *task, void *data)
|
2016-05-05 04:11:28 +00:00
|
|
|
{
|
2016-05-08 02:04:50 +00:00
|
|
|
http_transfer_info_t *info = (http_transfer_info_t*)data;
|
2016-05-06 04:31:25 +00:00
|
|
|
/* Extract HTTP handle and return already if invalid */
|
2016-05-08 02:04:50 +00:00
|
|
|
http_handle_t *http = (http_handle_t *)task->state;
|
2016-05-05 04:11:28 +00:00
|
|
|
if (!http)
|
|
|
|
return false;
|
|
|
|
|
2016-05-06 04:31:25 +00:00
|
|
|
/* Fill HTTP info link */
|
2020-08-14 16:51:50 +00:00
|
|
|
strlcpy(info->url, http->connection_url, sizeof(info->url));
|
2016-12-29 05:50:18 +00:00
|
|
|
info->progress = task_get_progress(task);
|
2016-05-06 04:31:25 +00:00
|
|
|
return true;
|
2016-05-05 04:11:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 07:08:09 +00:00
|
|
|
static void http_transfer_progress_cb(retro_task_t *task)
|
|
|
|
{
|
2019-05-22 07:55:10 +00:00
|
|
|
#ifdef RARCH_INTERNAL
|
|
|
|
if (task)
|
|
|
|
video_display_server_set_window_progress(task->progress, task->finished);
|
|
|
|
#endif
|
2018-01-01 07:08:09 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
static void *task_push_http_transfer_generic(
|
2017-05-09 18:10:58 +00:00
|
|
|
struct http_connection_t *conn,
|
|
|
|
const char *url, bool mute, const char *type,
|
2016-02-09 16:47:04 +00:00
|
|
|
retro_task_callback_t cb, void *user_data)
|
2015-07-08 19:35:24 +00:00
|
|
|
{
|
2019-05-22 07:55:10 +00:00
|
|
|
retro_task_t *t = NULL;
|
|
|
|
http_handle_t *http = NULL;
|
2021-07-28 03:02:14 +00:00
|
|
|
const char *method = NULL;
|
2015-07-08 19:35:24 +00:00
|
|
|
|
2021-07-24 04:04:42 +00:00
|
|
|
if (!conn)
|
|
|
|
return NULL;
|
2016-01-28 08:57:55 +00:00
|
|
|
|
2021-07-28 03:02:14 +00:00
|
|
|
method = net_http_connection_method(conn);
|
|
|
|
if (method && (method[0] == 'P' || method[0] == 'p'))
|
2019-09-30 03:09:08 +00:00
|
|
|
{
|
2021-07-24 04:04:42 +00:00
|
|
|
/* POST requests usually mutate the server, so assume multiple calls are
|
|
|
|
* intended, even if they're duplicated. Additionally, they may differ
|
|
|
|
* only by the POST data, and task_http_finder doesn't look at that, so
|
|
|
|
* unique requests could be misclassified as duplicates.
|
|
|
|
*/
|
2019-09-30 03:09:08 +00:00
|
|
|
}
|
2021-07-24 04:04:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
task_finder_data_t find_data;
|
2022-07-08 23:24:59 +00:00
|
|
|
find_data.func = task_http_finder;
|
2021-07-24 04:04:42 +00:00
|
|
|
find_data.userdata = (void*)url;
|
2015-11-30 14:36:53 +00:00
|
|
|
|
2021-07-24 04:04:42 +00:00
|
|
|
/* Concurrent download of the same file is not allowed */
|
|
|
|
if (task_queue_find(&find_data))
|
|
|
|
{
|
|
|
|
net_http_connection_free(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-11-23 14:13:26 +00:00
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(http = (http_handle_t*)malloc(sizeof(*http))))
|
2016-01-21 02:22:17 +00:00
|
|
|
goto error;
|
2016-01-21 02:19:14 +00:00
|
|
|
|
2020-06-27 14:36:08 +00:00
|
|
|
http->connection.handle = conn;
|
|
|
|
http->connection.cb = &cb_http_conn_default;
|
2020-08-14 16:51:50 +00:00
|
|
|
http->connection_elem[0] = '\0';
|
|
|
|
http->connection_url[0] = '\0';
|
2020-06-27 14:36:08 +00:00
|
|
|
http->handle = NULL;
|
|
|
|
http->cb = NULL;
|
|
|
|
http->status = 0;
|
|
|
|
http->error = false;
|
2015-11-23 14:13:26 +00:00
|
|
|
|
|
|
|
if (type)
|
2020-08-14 16:51:50 +00:00
|
|
|
strlcpy(http->connection_elem, type, sizeof(http->connection_elem));
|
2015-11-23 14:13:26 +00:00
|
|
|
|
2020-08-14 16:51:50 +00:00
|
|
|
strlcpy(http->connection_url, url, sizeof(http->connection_url));
|
2016-05-04 23:48:08 +00:00
|
|
|
|
2016-01-21 02:22:17 +00:00
|
|
|
http->status = HTTP_STATUS_CONNECTION_TRANSFER;
|
2016-01-21 02:19:14 +00:00
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(t = task_init()))
|
2016-01-21 02:22:17 +00:00
|
|
|
goto error;
|
2016-01-21 02:19:14 +00:00
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
t->handler = task_http_transfer_handler;
|
2016-01-21 02:22:17 +00:00
|
|
|
t->state = http;
|
2016-05-27 03:06:03 +00:00
|
|
|
t->mute = mute;
|
2016-01-21 02:22:17 +00:00
|
|
|
t->callback = cb;
|
2018-01-01 07:08:09 +00:00
|
|
|
t->progress_cb = http_transfer_progress_cb;
|
2021-03-16 01:42:25 +00:00
|
|
|
t->cleanup = task_http_transfer_cleanup;
|
2016-01-21 02:22:17 +00:00
|
|
|
t->user_data = user_data;
|
|
|
|
t->progress = -1;
|
2015-11-30 12:17:46 +00:00
|
|
|
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_push(t);
|
2015-11-23 14:13:26 +00:00
|
|
|
|
2016-05-05 18:32:36 +00:00
|
|
|
return t;
|
2016-01-21 02:22:17 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (conn)
|
|
|
|
net_http_connection_free(conn);
|
|
|
|
if (http)
|
|
|
|
free(http);
|
|
|
|
|
2016-05-05 18:32:36 +00:00
|
|
|
return NULL;
|
2015-07-08 19:35:24 +00:00
|
|
|
}
|
2016-05-05 04:11:28 +00:00
|
|
|
|
2017-05-09 18:10:58 +00:00
|
|
|
void* task_push_http_transfer(const char *url, bool mute,
|
|
|
|
const char *type,
|
2018-03-16 02:16:49 +00:00
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
2022-07-08 23:24:59 +00:00
|
|
|
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;
|
2018-03-16 02:16:49 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 07:20:50 +00:00
|
|
|
void *task_push_webdav_stat(const char *url, bool mute, const char *headers,
|
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t *conn;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(conn = net_http_connection_new(url, "OPTIONS", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (headers)
|
|
|
|
net_http_connection_set_headers(conn, headers);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, NULL, cb, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* task_push_webdav_mkdir(const char *url, bool mute,
|
|
|
|
const char *headers,
|
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t *conn;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(conn = net_http_connection_new(url, "MKCOL", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (headers)
|
|
|
|
net_http_connection_set_headers(conn, headers);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, NULL, cb, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* task_push_webdav_put(const char *url,
|
|
|
|
const void *put_data, size_t len, bool mute,
|
|
|
|
const char *headers, retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t *conn;
|
|
|
|
char expect[1024];
|
|
|
|
size_t _len;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(conn = net_http_connection_new(url, "PUT", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_len = strlcpy(expect, "Expect: 100-continue\r\n", sizeof(expect));
|
|
|
|
if (headers)
|
|
|
|
{
|
|
|
|
strlcpy(expect + _len, headers, sizeof(expect) - _len);
|
|
|
|
net_http_connection_set_headers(conn, expect);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (put_data)
|
|
|
|
net_http_connection_set_content(conn, NULL, len, put_data);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, NULL, cb, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* task_push_webdav_delete(const char *url, bool mute,
|
|
|
|
const char *headers,
|
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t *conn;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(conn = net_http_connection_new(url, "DELETE", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (headers)
|
|
|
|
net_http_connection_set_headers(conn, headers);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, NULL, cb, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *task_push_webdav_move(const char *url,
|
|
|
|
const char *dest, bool mute, const char *headers,
|
|
|
|
retro_task_callback_t cb, void *userdata)
|
|
|
|
{
|
|
|
|
struct http_connection_t *conn;
|
|
|
|
char dest_header[PATH_MAX_LENGTH + 512];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(conn = net_http_connection_new(url, "MOVE", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
len = strlcpy(dest_header, "Destination: ", sizeof(dest_header));
|
|
|
|
len += strlcpy(dest_header + len, dest, sizeof(dest_header) - len);
|
|
|
|
len += strlcpy(dest_header + len, "\r\n", sizeof(dest_header) - len);
|
|
|
|
|
|
|
|
if (headers)
|
|
|
|
strlcpy(dest_header + len, headers, sizeof(dest_header) - len);
|
|
|
|
|
|
|
|
net_http_connection_set_headers(conn, dest_header);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, NULL, cb, userdata);
|
|
|
|
}
|
|
|
|
|
2020-01-18 02:48:40 +00:00
|
|
|
void* task_push_http_transfer_file(const char* url, bool mute,
|
|
|
|
const char* type,
|
|
|
|
retro_task_callback_t cb, file_transfer_t* transfer_data)
|
|
|
|
{
|
2022-08-04 01:44:19 +00:00
|
|
|
size_t len;
|
2024-09-09 03:47:32 +00:00
|
|
|
const char *s = NULL;
|
|
|
|
char tmp[NAME_MAX_LENGTH] = "";
|
|
|
|
retro_task_t *t = NULL;
|
2020-01-18 02:48:40 +00:00
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(t = (retro_task_t*)task_push_http_transfer_generic(
|
2020-01-18 02:48:40 +00:00
|
|
|
net_http_connection_new(url, "GET", NULL),
|
2022-07-08 23:24:59 +00:00
|
|
|
url, mute, type, cb, transfer_data)))
|
2020-01-18 02:48:40 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (transfer_data)
|
2022-08-04 01:44:19 +00:00
|
|
|
s = transfer_data->path;
|
2020-01-18 02:48:40 +00:00
|
|
|
else
|
2022-08-04 01:44:19 +00:00
|
|
|
s = url;
|
2020-01-18 02:48:40 +00:00
|
|
|
|
2022-08-04 01:44:19 +00:00
|
|
|
len = strlcpy(tmp, msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp));
|
2023-06-20 14:33:55 +00:00
|
|
|
tmp[ len] = ' ';
|
|
|
|
tmp[++len] = '\0';
|
2020-01-18 02:48:40 +00:00
|
|
|
|
2020-06-25 12:38:06 +00:00
|
|
|
if (string_ends_with_size(s, ".index",
|
|
|
|
strlen(s), STRLEN_CONST(".index")))
|
2023-06-18 10:06:12 +00:00
|
|
|
s = msg_hash_to_str(MSG_INDEX_FILE);
|
|
|
|
|
2023-06-18 17:24:58 +00:00
|
|
|
strlcpy(tmp + len, s, sizeof(tmp) - len);
|
2020-01-18 02:48:40 +00:00
|
|
|
|
|
|
|
t->title = strdup(tmp);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2019-09-30 03:09:08 +00:00
|
|
|
void* task_push_http_transfer_with_user_agent(const char *url, bool mute,
|
2021-12-09 04:52:42 +00:00
|
|
|
const char *type, const char *user_agent,
|
2019-09-30 03:09:08 +00:00
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
2021-12-09 04:52:42 +00:00
|
|
|
struct http_connection_t *conn;
|
2019-09-30 03:09:08 +00:00
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(conn = net_http_connection_new(url, "GET", NULL)))
|
2019-09-30 03:09:08 +00:00
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (user_agent)
|
2019-09-30 03:09:08 +00:00
|
|
|
net_http_connection_set_user_agent(conn, user_agent);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, type, cb, user_data);
|
|
|
|
}
|
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
void* task_push_http_transfer_with_headers(const char *url, bool mute,
|
|
|
|
const char *type, const char *headers,
|
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t *conn;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(conn = net_http_connection_new(url, "GET", NULL)))
|
2021-12-09 04:52:42 +00:00
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (headers)
|
2021-12-09 04:52:42 +00:00
|
|
|
net_http_connection_set_headers(conn, headers);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, type, cb, user_data);
|
|
|
|
}
|
|
|
|
|
2017-05-09 18:10:58 +00:00
|
|
|
void* task_push_http_post_transfer(const char *url,
|
|
|
|
const char *post_data, bool mute,
|
2017-03-02 22:36:25 +00:00
|
|
|
const char *type, retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
2022-07-08 23:24:59 +00:00
|
|
|
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;
|
2017-03-02 22:36:25 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 03:12:49 +00:00
|
|
|
void* task_push_http_post_transfer_with_user_agent(const char *url,
|
|
|
|
const char *post_data, bool mute,
|
2021-12-09 04:52:42 +00:00
|
|
|
const char *type, const char *user_agent,
|
2020-02-15 03:12:49 +00:00
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t* conn;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(conn = net_http_connection_new(url, "POST", post_data)))
|
2020-02-15 03:12:49 +00:00
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (user_agent)
|
2020-02-15 03:12:49 +00:00
|
|
|
net_http_connection_set_user_agent(conn, user_agent);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, type, cb, user_data);
|
|
|
|
}
|
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
void* task_push_http_post_transfer_with_headers(const char *url,
|
|
|
|
const char *post_data, bool mute,
|
|
|
|
const char *type, const char *headers,
|
|
|
|
retro_task_callback_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct http_connection_t* conn;
|
|
|
|
|
|
|
|
if (string_is_empty(url))
|
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (!(conn = net_http_connection_new(url, "POST", post_data)))
|
2021-12-09 04:52:42 +00:00
|
|
|
return NULL;
|
|
|
|
|
2022-07-08 23:24:59 +00:00
|
|
|
if (headers)
|
2021-12-09 04:52:42 +00:00
|
|
|
net_http_connection_set_headers(conn, headers);
|
|
|
|
|
|
|
|
return task_push_http_transfer_generic(conn, url, mute, type, cb, user_data);
|
|
|
|
}
|
|
|
|
|
2016-05-06 04:31:25 +00:00
|
|
|
task_retriever_info_t *http_task_get_transfer_list(void)
|
2016-05-05 04:11:28 +00:00
|
|
|
{
|
2016-05-06 04:31:25 +00:00
|
|
|
task_retriever_data_t retrieve_data;
|
2016-05-05 04:11:28 +00:00
|
|
|
|
2016-05-06 04:31:25 +00:00
|
|
|
/* Fill retrieve data */
|
2016-05-27 16:14:47 +00:00
|
|
|
retrieve_data.handler = task_http_transfer_handler;
|
2016-05-06 04:31:25 +00:00
|
|
|
retrieve_data.element_size = sizeof(http_transfer_info_t);
|
2016-05-27 16:14:47 +00:00
|
|
|
retrieve_data.func = task_http_retriever;
|
2016-05-05 04:11:28 +00:00
|
|
|
|
|
|
|
/* Build list of current HTTP transfers and return it */
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_retrieve(&retrieve_data);
|
|
|
|
|
2016-05-06 04:31:25 +00:00
|
|
|
return retrieve_data.list;
|
2016-05-05 04:11:28 +00:00
|
|
|
}
|