Quake II RTX doxygen
1.0 dev
|
|
#include "client.h"
#include <curl/curl.h>
Go to the source code of this file.
|
static int | progress_func (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) |
|
static size_t | recv_func (void *ptr, size_t size, size_t nmemb, void *stream) |
|
static void | escape_path (const char *path, char *escaped) |
|
static const char * | http_strerror (int response) |
|
static const char * | http_gamedir (void) |
|
static void | start_download (dlqueue_t *entry, dlhandle_t *dl) |
|
void | HTTP_CleanupDownloads (void) |
|
void | HTTP_Init (void) |
|
void | HTTP_Shutdown (void) |
|
void | HTTP_SetServer (const char *url) |
|
qerror_t | HTTP_QueueDownload (const char *path, dltype_t type) |
|
static void | check_and_queue_download (char *path) |
|
static void | parse_file_list (dlhandle_t *dl) |
|
static void | rescan_queue (void) |
|
static void | abort_downloads (void) |
|
static dlhandle_t * | find_handle (CURL *curl) |
|
static qboolean | finish_download (void) |
|
static dlhandle_t * | get_free_handle (void) |
|
static void | start_next_download (void) |
|
void | HTTP_RunDownloads (void) |
|
◆ MAX_DLSIZE
#define MAX_DLSIZE 0x100000 |
◆ MIN_DLSIZE
#define MIN_DLSIZE 0x8000 |
◆ abort_downloads()
◆ check_and_queue_download()
static void check_and_queue_download |
( |
char * |
path | ) |
|
|
static |
Definition at line 579 of file http.c.
588 if (len >= MAX_QPATH)
591 ext = strrchr(path,
'.');
601 if (!strcmp(
ext,
"pak") || !strcmp(
ext,
"pkz")) {
602 Com_Printf(
"[HTTP] Filelist is requesting a .%s file '%s'\n",
ext, path);
607 Com_WPrintf(
"[HTTP] Illegal file type '%s' in filelist.\n", path);
612 if (path[0] ==
'@') {
613 if (type == DL_PAK) {
614 Com_WPrintf(
"[HTTP] '@' prefix used on a pak file '%s' in filelist.\n", path);
617 flags = FS_PATH_GAME;
620 }
else if (type == DL_PAK) {
622 flags = FS_PATH_GAME | FS_TYPE_REAL;
633 if (valid == PATH_INVALID ||
634 !Q_ispath(path[0]) ||
635 !Q_ispath(path[len - 1]) ||
636 strstr(path,
"..") ||
637 (type ==
DL_OTHER && !strchr(path,
'/')) ||
638 (type == DL_PAK && strchr(path,
'/'))) {
639 Com_WPrintf(
"[HTTP] Illegal path '%s' in filelist.\n", path);
643 if (FS_FileExistsEx(path, flags))
646 if (valid == PATH_MIXED_CASE)
Referenced by parse_file_list().
◆ escape_path()
static void escape_path |
( |
const char * |
path, |
|
|
char * |
escaped |
|
) |
| |
|
static |
Definition at line 152 of file http.c.
154 static const char allowed[] =
";/?:@&=+$,[]-_.!~*'()";
161 if (!Q_isalnum(
c) && !strchr(allowed,
c)) {
162 sprintf(p,
"%%%02x",
c);
Referenced by start_download().
◆ find_handle()
Definition at line 723 of file http.c.
728 for (i = 0; i < 4; i++) {
730 if (dl->
curl == curl) {
735 Com_Error(ERR_FATAL,
"CURL handle not found for CURLMSG_DONE");
Referenced by finish_download().
◆ finish_download()
static qboolean finish_download |
( |
void |
| ) |
|
|
static |
Definition at line 741 of file http.c.
750 char size[16], speed[16];
751 char temp[MAX_OSPATH];
752 qboolean fatal_error = qfalse;
761 if (
msg->msg != CURLMSG_DONE)
764 curl =
msg->easy_handle;
779 result =
msg->data.result;
783 case CURLE_HTTP_RETURNED_ERROR:
785 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
786 if (result == CURLE_OK && response == 200) {
806 case CURLE_COULDNT_RESOLVE_HOST:
807 case CURLE_COULDNT_CONNECT:
808 case CURLE_COULDNT_RESOLVE_PROXY:
810 err = curl_easy_strerror(result);
816 err = curl_easy_strerror(result);
817 level = PRINT_WARNING;
824 "[HTTP] %s [%s] [%d remaining file%s]\n",
847 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &sec);
848 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &bytes);
860 Com_Printf(
"[HTTP] %s [%s, %s/sec] [%d remaining file%s]\n",
868 if (rename(dl->
path, temp))
869 Com_EPrintf(
"[HTTP] Failed to rename '%s' to '%s': %s\n",
878 }
else if (!fatal_error) {
881 }
while (msgs_in_queue > 0);
Referenced by HTTP_RunDownloads().
◆ get_free_handle()
◆ HTTP_CleanupDownloads()
◆ http_gamedir()
static const char* http_gamedir |
( |
void |
| ) |
|
|
static |
◆ HTTP_Init()
Definition at line 436 of file http.c.
446 cl_http_debug =
Cvar_Get(
"cl_http_debug",
"0", 0);
450 cl_http_blocking_timeout =
Cvar_Get(
"cl_http_blocking_timeout",
"15", 0);
453 curl_global_init(CURL_GLOBAL_NOTHING);
455 Com_DPrintf(
"%s initialized.\n", curl_version());
Referenced by CL_Init().
◆ HTTP_QueueDownload()
qerror_t HTTP_QueueDownload |
( |
const char * |
path, |
|
|
dltype_t |
type |
|
) |
| |
Definition at line 530 of file http.c.
534 char temp[MAX_QPATH];
549 return Q_ERR_SUCCESS;
554 if (len <
sizeof(temp))
567 if (len > 4 && !Q_stricmp(path + len - 4,
".bsp")) {
569 if (len <
sizeof(temp) - 5) {
570 memcpy(temp + len - 4,
".filelist", 10);
575 return Q_ERR_SUCCESS;
Referenced by check_file_len().
◆ HTTP_RunDownloads()
Definition at line 941 of file http.c.
952 ret = curl_multi_perform(
curl_multi, &new_count);
959 }
while (ret == CURLM_CALL_MULTI_PERFORM);
961 if (ret != CURLM_OK) {
962 Com_EPrintf(
"[HTTP] Error running downloads: %s.\n",
963 curl_multi_strerror(ret));
Referenced by CL_ProcessEvents().
◆ HTTP_SetServer()
void HTTP_SetServer |
( |
const char * |
url | ) |
|
Definition at line 477 of file http.c.
480 Com_EPrintf(
"[HTTP] Set server without cleanup?\n");
508 if (strncmp(url,
"http://", 7)) {
509 Com_Printf(
"[HTTP] Ignoring download server URL with non-HTTP schema.\n");
Referenced by CL_ConnectionlessPacket().
◆ HTTP_Shutdown()
◆ http_strerror()
static const char* http_strerror |
( |
int |
response | ) |
|
|
static |
Definition at line 172 of file http.c.
174 static char buffer[32];
181 return "401 Unauthorized";
183 return "403 Forbidden";
185 return "404 Not Found";
187 return "500 Internal Server Error";
189 return "503 Service Unavailable";
192 if (response < 100 || response >= 600) {
193 Q_snprintf(buffer,
sizeof(buffer),
"%d <bad code>", response);
198 if (response < 200) {
199 Q_snprintf(buffer,
sizeof(buffer),
"%d Informational", response);
200 }
else if (response < 300) {
201 Q_snprintf(buffer,
sizeof(buffer),
"%d Success", response);
202 }
else if (response < 400) {
203 Q_snprintf(buffer,
sizeof(buffer),
"%d Redirection", response);
204 }
else if (response < 500) {
205 Q_snprintf(buffer,
sizeof(buffer),
"%d Client Error", response);
207 Q_snprintf(buffer,
sizeof(buffer),
"%d Server Error", response);
Referenced by finish_download().
◆ parse_file_list()
Definition at line 656 of file http.c.
667 p = strchr(list,
'\n');
669 if (p > list && *(p - 1) ==
'\r')
Referenced by finish_download().
◆ progress_func()
static int progress_func |
( |
void * |
clientp, |
|
|
double |
dltotal, |
|
|
double |
dlnow, |
|
|
double |
ultotal, |
|
|
double |
ulnow |
|
) |
| |
|
static |
◆ recv_func()
static size_t recv_func |
( |
void * |
ptr, |
|
|
size_t |
size, |
|
|
size_t |
nmemb, |
|
|
void * |
stream |
|
) |
| |
|
static |
Definition at line 96 of file http.c.
99 size_t new_size, bytes;
104 if (size > SIZE_MAX / nmemb)
110 bytes = size * nmemb;
116 if (new_size > dl->
size) {
128 Com_DPrintf(
"[HTTP] Oversize file while trying to download '%s'\n", dl->
url);
Referenced by start_download().
◆ rescan_queue()
◆ start_download()
Definition at line 223 of file http.c.
226 char temp[MAX_QPATH];
227 char escaped[MAX_QPATH * 4];
233 if (entry->
type == DL_LIST) {
240 if (len >=
sizeof(dl->
path)) {
241 Com_EPrintf(
"[HTTP] Refusing oversize temporary file path.\n");
247 if (len >=
sizeof(temp)) {
248 Com_EPrintf(
"[HTTP] Refusing oversize server file path.\n");
262 Com_EPrintf(
"[HTTP] Couldn't open '%s' for writing: %s\n", dl->
path, strerror(errno));
268 if (len >=
sizeof(dl->
url)) {
269 Com_EPrintf(
"[HTTP] Refusing oversize download URL.\n");
278 dl->
curl = curl_easy_init();
280 curl_easy_setopt(dl->
curl, CURLOPT_ENCODING,
"");
282 if (cl_http_debug->integer) {
283 curl_easy_setopt(dl->
curl, CURLOPT_DEBUGFUNCTION, debug_func);
284 curl_easy_setopt(dl->
curl, CURLOPT_VERBOSE, 1);
287 curl_easy_setopt(dl->
curl, CURLOPT_NOPROGRESS, 0);
289 curl_easy_setopt(dl->
curl, CURLOPT_WRITEDATA, dl->
file);
290 curl_easy_setopt(dl->
curl, CURLOPT_WRITEFUNCTION, NULL);
292 curl_easy_setopt(dl->
curl, CURLOPT_WRITEDATA, dl);
293 curl_easy_setopt(dl->
curl, CURLOPT_WRITEFUNCTION,
recv_func);
295 curl_easy_setopt(dl->
curl, CURLOPT_FAILONERROR, 1);
297 curl_easy_setopt(dl->
curl, CURLOPT_FOLLOWLOCATION, 1);
298 curl_easy_setopt(dl->
curl, CURLOPT_MAXREDIRS, 5);
300 curl_easy_setopt(dl->
curl, CURLOPT_PROGRESSDATA, dl);
303 curl_easy_setopt(dl->
curl, CURLOPT_URL, dl->
url);
306 if (ret != CURLM_OK) {
307 Com_EPrintf(
"[HTTP] Failed to add download handle: %s\n",
308 curl_multi_strerror(ret));
317 Com_DPrintf(
"[HTTP] Fetching %s...\n", dl->
url);
Referenced by start_next_download().
◆ start_next_download()
static void start_next_download |
( |
void |
| ) |
|
|
static |
◆ cl_http_default_url
cvar_t* cl_http_default_url |
|
static |
◆ cl_http_downloads
cvar_t* cl_http_downloads |
|
static |
◆ cl_http_filelists
cvar_t* cl_http_filelists |
|
static |
◆ cl_http_max_connections
cvar_t* cl_http_max_connections |
|
static |
◆ cl_http_proxy
◆ curl_handles
◆ curl_initialized
qboolean curl_initialized |
|
static |
◆ curl_multi
◆ download_default_repo
qboolean download_default_repo |
|
static |
◆ download_handles
◆ download_referer
char download_referer[32] |
|
static |
◆ download_server
char download_server[512] |
|
static |
static void parse_file_list(dlhandle_t *dl)
static cvar_t * cl_http_downloads
char * NET_AdrToString(const netadr_t *a)
size_t Q_snprintf(char *dest, size_t size, const char *fmt,...)
size_t Com_FormatSizeLong(char *dest, size_t destsize, off_t bytes)
qboolean CL_CheckDownloadExtension(const char *ext)
qboolean CL_IgnoreDownload(const char *path)
static void start_download(dlqueue_t *entry, dlhandle_t *dl)
static qboolean curl_initialized
void HTTP_CleanupDownloads(void)
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
const char * Q_ErrorString(qerror_t error)
static qboolean finish_download(void)
static cvar_t * cl_http_max_connections
static const char * http_strerror(int response)
static void start_next_download(void)
static size_t recv_func(void *ptr, size_t size, size_t nmemb, void *stream)
static void check_and_queue_download(char *path)
void CL_FinishDownload(dlqueue_t *q)
int FS_ValidatePath(const char *s)
static void rescan_queue(void)
static const char * http_gamedir(void)
static char download_server[512]
void Com_Error(error_type_t type, const char *fmt,...)
static char download_referer[32]
static cvar_t * cl_http_filelists
static dlhandle_t * get_free_handle(void)
static qboolean download_default_repo
static dlhandle_t * find_handle(CURL *curl)
static void escape_path(const char *path, char *escaped)
size_t Q_strlcpy(char *dst, const char *src, size_t size)
void Com_LPrintf(print_type_t type, const char *fmt,...)
void CL_StartNextDownload(void)
void CL_RestartFilesystem(qboolean total)
void CL_RequestNextDownload(void)
struct client_static_s::@2 download
static CURLM * curl_multi
static cvar_t * cl_http_default_url
static int progress_func(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
static void abort_downloads(void)
void CL_ClientCommand(const char *string)
qerror_t FS_CreatePath(char *path)
qerror_t CL_QueueDownload(const char *path, dltype_t type)
CONST PIXELFORMATDESCRIPTOR int
static cvar_t * cl_http_proxy
void * Z_Realloc(void *ptr, size_t size)
char fs_gamedir[MAX_OSPATH]
static dlhandle_t download_handles[4]
size_t FS_NormalizePath(char *out, const char *in)