cl_http.c File Reference

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"
Include dependency graph for cl_http.c:

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_tCL_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_tcl_http_downloads
static cvar_tcl_http_filelists
static cvar_tcl_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

Detailed Description

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.

Author:
R1CH
See also:
CL_ConnectionlessPacket
SVC_DirectConnect

Definition in file cl_http.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
HTTPDL_ABORT_NONE 
HTTPDL_ABORT_SOFT 
HTTPDL_ABORT_HARD 

Definition at line 42 of file cl_http.c.


Function Documentation

void CL_CancelHTTPDownloads ( qboolean  permKill  ) 
static void CL_CheckAndQueueDownload ( char *  path  )  [static]

Validate a path supplied by a filelist.

Parameters:
[in,out] path Pointer to file (path) to download (high bits will be stripped).
See also:
CL_QueueHTTPDownload
CL_ParseFileList

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  ) 
Returns:
true if the file exists, otherwise it attempts to start a download via curl
See also:
CL_CheckAndQueueDownload
CL_RequestNextDownload

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.

References i, and len.

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.

Todo:
technically i shouldn't need to do this as curl will auto reuse the existing handle when you change the URL. however, the handleCount goes all weird when reusing a download slot in this way. if you can figure out why, please let me know.

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  ) 
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.

See also:
CL_Frame

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  ) 
static void CL_StartHTTPDownload ( dlqueue_t entry,
dlhandle_t dl 
) [static]
static void CL_StartNextHTTPDownload ( void   )  [static]
void HTTP_InitStartup ( void   ) 

Definition at line 829 of file cl_http.c.

References Cvar_Get().

Referenced by CL_InitLocal().

static qboolean isvalidchar ( int  c  )  [inline, static]

Definition at line 68 of file cl_http.c.

References qfalse, and qtrue.

Referenced by CL_CheckAndQueueDownload().

static void StripHighBits ( char *  string  )  [static]

Definition at line 54 of file cl_http.c.

Referenced by CL_CheckAndQueueDownload().


Variable Documentation

int abortDownloads = HTTPDL_ABORT_NONE [static]

Definition at line 38 of file cl_http.c.

Definition at line 39 of file cl_http.c.

Definition at line 40 of file cl_http.c.

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]
CURLM* multi = NULL [static]
int pendingCount = 0 [static]

Generated by  doxygen 1.6.2