HTTP downloading is used if the server provides a content server URL in the connect message. Any missing content the client needs will then use the HTTP server. CURL is used to enable multiple files to be downloaded in parallel to improve performance on high latency links when small files such as textures are needed. Since CURL natively supports gzip content encoding, any files on the HTTP server should ideally be gzipped to conserve bandwidth. More...
#include "client.h"
#include "cl_http.h"
#include "battlescape/cl_parse.h"
Go to the source code of this file.
Enumerations | |
enum | { HTTPDL_ABORT_NONE, HTTPDL_ABORT_SOFT, HTTPDL_ABORT_HARD } |
Functions | |
static void | StripHighBits (char *string) |
static qboolean | isvalidchar (int c) |
static int | CL_HTTP_Progress (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) |
libcurl callback to update progress info. Mainly just used as a way to cancel the transfer if required. | |
static void | CL_EscapeHTTPPath (const char *filePath, char *escaped) |
Properly escapes a path with HTTP encoding. libcurl's function seems to treat '/' and such as illegal chars and encodes almost the entire URL... | |
static void | CL_StartHTTPDownload (dlqueue_t *entry, dlhandle_t *dl) |
Actually starts a download by adding it to the curl multi handle. | |
void | CL_SetHTTPServer (const char *URL) |
A new server is specified, so we nuke all our state. | |
void | CL_ResetPrecacheCheck (void) |
void | CL_CancelHTTPDownloads (qboolean permKill) |
Cancel all downloads and nuke the queue. | |
static dlhandle_t * | CL_GetFreeDLHandle (void) |
Find a free download handle to start another queue entry on. | |
qboolean | CL_QueueHTTPDownload (const char *ufoPath) |
Called from the precache check to queue a download. | |
qboolean | CL_PendingHTTPDownloads (void) |
See if we're still busy with some downloads. Called by precacher just before it loads the map since we could be downloading the map. If we're busy still, it'll wait and CL_FinishHTTPDownload will pick up from where it left. | |
qboolean | CL_CheckOrDownloadFile (const char *filename) |
static void | CL_CheckAndQueueDownload (char *path) |
Validate a path supplied by a filelist. | |
static void | CL_ParseFileList (dlhandle_t *dl) |
A filelist is in memory, scan and validate it and queue up the files. | |
static void | CL_ReVerifyHTTPQueue (void) |
A pk3 file just downloaded, let's see if we can remove some stuff from the queue which is in the .pk3. | |
void | CL_HTTP_Cleanup (void) |
UFO is exiting or we're changing servers. Clean up. | |
static void | CL_FinishHTTPDownload (void) |
A download finished, find out what it was, whether there were any errors and if so, how severe. If none, rename file and other such stuff. | |
static void | CL_StartNextHTTPDownload (void) |
Start another HTTP download if possible. | |
void | CL_RunHTTPDownloads (void) |
This calls curl_multi_perform do actually do stuff. Called every frame while connecting to minimise latency. Also starts new downloads if we're not doing the maximum already. | |
void | HTTP_InitStartup (void) |
Variables | |
static cvar_t * | cl_http_downloads |
static cvar_t * | cl_http_filelists |
static cvar_t * | cl_http_max_connections |
static CURLM * | multi = NULL |
static int | handleCount = 0 |
static int | pendingCount = 0 |
static int | abortDownloads = HTTPDL_ABORT_NONE |
static qboolean | downloadingPK3 = qfalse |
HTTP downloading is used if the server provides a content server URL in the connect message. Any missing content the client needs will then use the HTTP server. CURL is used to enable multiple files to be downloaded in parallel to improve performance on high latency links when small files such as textures are needed. Since CURL natively supports gzip content encoding, any files on the HTTP server should ideally be gzipped to conserve bandwidth.
Definition in file cl_http.c.
anonymous enum |
void CL_CancelHTTPDownloads | ( | qboolean | permKill | ) |
Cancel all downloads and nuke the queue.
Definition at line 265 of file cl_http.c.
References abortDownloads, cls, DLQ_STATE_DONE, DLQ_STATE_NOT_STARTED, client_static_s::downloadQueue, client_static_s::downloadServer, handleCount, HTTPDL_ABORT_HARD, HTTPDL_ABORT_SOFT, dlqueue_s::next, pendingCount, and dlqueue_s::state.
Referenced by CL_FinishHTTPDownload(), and CL_RunHTTPDownloads().
static void CL_CheckAndQueueDownload | ( | char * | path | ) | [static] |
Validate a path supplied by a filelist.
[in,out] | path | Pointer to file (path) to download (high bits will be stripped). |
Definition at line 419 of file cl_http.c.
References CL_CheckOrDownloadFile(), CL_QueueHTTPDownload(), cls, Com_GetExtension(), Com_Printf(), Com_sprintf(), client_static_s::downloadQueue, f, FS_CheckFile(), FS_Gamedir(), isvalidchar(), MAX_OSPATH, MAX_QPATH, dlqueue_s::next, qfalse, qtrue, and StripHighBits().
Referenced by CL_ParseFileList().
qboolean CL_CheckOrDownloadFile | ( | const char * | filename | ) |
Definition at line 369 of file cl_http.c.
References CL_QueueHTTPDownload(), Com_Printf(), FS_LoadFile(), MAX_OSPATH, Q_strncpyz(), qfalse, and qtrue.
Referenced by CL_CheckAndQueueDownload(), CL_DownloadMap(), and CL_DownloadUMPMap().
static void CL_EscapeHTTPPath | ( | const char * | filePath, | |
char * | escaped | |||
) | [static] |
Properly escapes a path with HTTP encoding. libcurl's function seems to treat '/' and such as illegal chars and encodes almost the entire URL...
Definition at line 106 of file cl_http.c.
Referenced by CL_StartHTTPDownload().
static void CL_FinishHTTPDownload | ( | void | ) | [static] |
A download finished, find out what it was, whether there were any errors and if so, how severe. If none, rename file and other such stuff.
Definition at line 601 of file cl_http.c.
References abortDownloads, ca_connected, CL_CancelHTTPDownloads(), CL_ParseFileList(), CL_PendingHTTPDownloads(), CL_RequestNextDownload(), CL_ReVerifyHTTPQueue(), cls, Com_Error(), Com_GetExtension(), Com_Printf(), Com_sprintf(), dlhandle_s::curl, DLQ_STATE_DONE, downloadingPK3, client_static_s::downloadName, client_static_s::downloadPosition, client_static_s::downloadServer, ERR_DROP, dlhandle_s::file, dlhandle_s::filePath, FS_Gamedir(), FS_RemoveFile(), FS_RenameFile(), FS_RestartFilesystem(), handleCount, HTTPDL_ABORT_HARD, HTTPDL_ABORT_NONE, HTTPDL_ABORT_SOFT, client_static_s::HTTPHandles, i, MAX_OSPATH, multi, pendingCount, qfalse, qtrue, dlhandle_s::queueEntry, client_static_s::state, dlqueue_s::state, and dlqueue_s::ufoPath.
Referenced by CL_RunHTTPDownloads().
static dlhandle_t* CL_GetFreeDLHandle | ( | void | ) | [static] |
Find a free download handle to start another queue entry on.
Definition at line 291 of file cl_http.c.
References cls, DLQ_STATE_DONE, client_static_s::HTTPHandles, i, dlhandle_s::queueEntry, and dlqueue_s::state.
Referenced by CL_StartNextHTTPDownload().
void CL_HTTP_Cleanup | ( | void | ) |
UFO is exiting or we're changing servers. Clean up.
Definition at line 565 of file cl_http.c.
References cls, dlhandle_s::curl, dlhandle_s::file, dlhandle_s::filePath, client_static_s::HTTPHandles, i, Mem_Free, multi, and dlhandle_s::tempBuffer.
Referenced by CL_SetHTTPServer(), and CL_Shutdown().
static int CL_HTTP_Progress | ( | void * | clientp, | |
double | dltotal, | |||
double | dlnow, | |||
double | ultotal, | |||
double | ulnow | |||
) | [static] |
libcurl callback to update progress info. Mainly just used as a way to cancel the transfer if required.
Definition at line 79 of file cl_http.c.
References abortDownloads, cls, client_static_s::downloadName, client_static_s::downloadPercent, client_static_s::downloadPosition, int(), dlhandle_s::position, Q_strncpyz(), dlhandle_s::queueEntry, and dlqueue_s::ufoPath.
Referenced by CL_StartHTTPDownload().
static void CL_ParseFileList | ( | dlhandle_t * | dl | ) | [static] |
A filelist is in memory, scan and validate it and queue up the files.
Definition at line 514 of file cl_http.c.
References CL_CheckAndQueueDownload(), cvar_s::integer, Mem_Free, and dlhandle_s::tempBuffer.
Referenced by CL_FinishHTTPDownload().
qboolean CL_PendingHTTPDownloads | ( | void | ) |
See if we're still busy with some downloads. Called by precacher just before it loads the map since we could be downloading the map. If we're busy still, it'll wait and CL_FinishHTTPDownload will pick up from where it left.
Definition at line 356 of file cl_http.c.
References cls, client_static_s::downloadServer, handleCount, pendingCount, and qfalse.
Referenced by CL_CanMultiplayerStart(), and CL_FinishHTTPDownload().
qboolean CL_QueueHTTPDownload | ( | const char * | ufoPath | ) |
Called from the precache check to queue a download.
Definition at line 308 of file cl_http.c.
References abortDownloads, BASEDIRNAME, CL_QueueHTTPDownload(), cls, Com_GetExtension(), Com_sprintf(), DLQ_STATE_NOT_STARTED, client_static_s::downloadQueue, client_static_s::downloadServer, cvar_s::integer, len, MAX_OSPATH, Mem_Alloc, dlqueue_s::next, pendingCount, Q_strcasecmp, Q_strncpyz(), qfalse, qtrue, dlqueue_s::state, and dlqueue_s::ufoPath.
Referenced by CL_CheckAndQueueDownload(), CL_CheckOrDownloadFile(), and CL_QueueHTTPDownload().
void CL_ResetPrecacheCheck | ( | void | ) |
static void CL_ReVerifyHTTPQueue | ( | void | ) | [static] |
A pk3 file just downloaded, let's see if we can remove some stuff from the queue which is in the .pk3.
Definition at line 545 of file cl_http.c.
References cls, DLQ_STATE_DONE, DLQ_STATE_NOT_STARTED, client_static_s::downloadQueue, FS_LoadFile(), dlqueue_s::next, pendingCount, dlqueue_s::state, and dlqueue_s::ufoPath.
Referenced by CL_FinishHTTPDownload().
void CL_RunHTTPDownloads | ( | void | ) |
This calls curl_multi_perform do actually do stuff. Called every frame while connecting to minimise latency. Also starts new downloads if we're not doing the maximum already.
Definition at line 793 of file cl_http.c.
References abortDownloads, CL_CancelHTTPDownloads(), CL_FinishHTTPDownload(), CL_StartNextHTTPDownload(), cls, Com_Printf(), downloadingPK3, client_static_s::downloadServer, handleCount, HTTPDL_ABORT_NONE, multi, pendingCount, and qtrue.
Referenced by CL_Frame().
void CL_SetHTTPServer | ( | const char * | URL | ) |
A new server is specified, so we nuke all our state.
Definition at line 225 of file cl_http.c.
References abortDownloads, CL_HTTP_Cleanup(), cls, Com_Error(), client_static_s::downloadQueue, client_static_s::downloadServer, ERR_DROP, handleCount, HTTPDL_ABORT_NONE, Mem_Free, multi, dlqueue_s::next, pendingCount, and Q_strncpyz().
Referenced by CL_ConnectionlessPacket().
static void CL_StartHTTPDownload | ( | dlqueue_t * | entry, | |
dlhandle_t * | dl | |||
) | [static] |
Actually starts a download by adding it to the curl multi handle.
Definition at line 144 of file cl_http.c.
References BASEDIRNAME, CL_EscapeHTTPPath(), CL_HTTP_Progress(), cls, Com_GetExtension(), Com_Printf(), Com_sprintf(), dlhandle_s::curl, Cvar_GetString(), DLQ_STATE_DONE, DLQ_STATE_RUNNING, client_static_s::downloadReferer, client_static_s::downloadServer, dlhandle_s::file, dlhandle_s::filePath, dlhandle_s::fileSize, FS_CreatePath(), FS_Gamedir(), handleCount, HTTP_Header(), http_proxy, HTTP_Recv(), MAX_OSPATH, MAX_QPATH, multi, dlhandle_s::position, dlhandle_s::queueEntry, dlhandle_s::speed, dlqueue_s::state, cvar_s::string, dlhandle_s::tempBuffer, dlqueue_s::ufoPath, and dlhandle_s::URL.
Referenced by CL_StartNextHTTPDownload().
static void CL_StartNextHTTPDownload | ( | void | ) | [static] |
Start another HTTP download if possible.
Definition at line 763 of file cl_http.c.
References CL_GetFreeDLHandle(), CL_StartHTTPDownload(), cls, DLQ_STATE_NOT_STARTED, downloadingPK3, client_static_s::downloadQueue, len, dlqueue_s::next, Q_strcasecmp, qtrue, dlqueue_s::state, and dlqueue_s::ufoPath.
Referenced by CL_RunHTTPDownloads().
void HTTP_InitStartup | ( | void | ) |
static qboolean isvalidchar | ( | int | c | ) | [inline, static] |
Definition at line 68 of file cl_http.c.
Referenced by CL_CheckAndQueueDownload().
static void StripHighBits | ( | char * | string | ) | [static] |
Definition at line 54 of file cl_http.c.
Referenced by CL_CheckAndQueueDownload().
int abortDownloads = HTTPDL_ABORT_NONE [static] |
Definition at line 51 of file cl_http.c.
Referenced by CL_CancelHTTPDownloads(), CL_FinishHTTPDownload(), CL_HTTP_Progress(), CL_QueueHTTPDownload(), CL_RunHTTPDownloads(), and CL_SetHTTPServer().
cvar_t* cl_http_downloads [static] |
cvar_t* cl_http_filelists [static] |
cvar_t* cl_http_max_connections [static] |
qboolean downloadingPK3 = qfalse [static] |
Definition at line 52 of file cl_http.c.
Referenced by CL_FinishHTTPDownload(), CL_RunHTTPDownloads(), and CL_StartNextHTTPDownload().
int handleCount = 0 [static] |
Definition at line 49 of file cl_http.c.
Referenced by CL_CancelHTTPDownloads(), CL_FinishHTTPDownload(), CL_PendingHTTPDownloads(), CL_RunHTTPDownloads(), CL_SetHTTPServer(), and CL_StartHTTPDownload().
CURLM* multi = NULL [static] |
Definition at line 48 of file cl_http.c.
Referenced by CL_FinishHTTPDownload(), CL_HTTP_Cleanup(), CL_RunHTTPDownloads(), CL_SetHTTPServer(), and CL_StartHTTPDownload().
int pendingCount = 0 [static] |
Definition at line 50 of file cl_http.c.
Referenced by CL_CancelHTTPDownloads(), CL_FinishHTTPDownload(), CL_PendingHTTPDownloads(), CL_QueueHTTPDownload(), CL_ReVerifyHTTPQueue(), CL_RunHTTPDownloads(), and CL_SetHTTPServer().