diff options
author | Andrey Nazarov <skuller@skuller.net> | 2008-01-04 21:30:13 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2008-01-04 21:30:13 +0000 |
commit | 0f73c3d00f54ed960cf01d0cfe30734cda26586c (patch) | |
tree | ea0aa83116f9e12438997030146438b48eb2129d | |
parent | 672b1780a9f769ef51d08b7bb5b9cef179d059ba (diff) |
Added `--referer' and `--encoding' options to `mvdconnect' command.
-rw-r--r-- | source/mvd_client.c | 78 | ||||
-rw-r--r-- | source/mvd_local.h | 1 | ||||
-rw-r--r-- | source/sv_local.h | 7 |
3 files changed, 68 insertions, 18 deletions
diff --git a/source/mvd_client.c b/source/mvd_client.c index 40a1d31..a47f6a8 100644 --- a/source/mvd_client.c +++ b/source/mvd_client.c @@ -519,6 +519,22 @@ static void MVD_ReadDemo( mvd_t *mvd ) { } } +static htcoding_t MVD_FindCoding( const char *name ) { + if( !Q_stricmp( name, "identity" ) ) { + return HTTP_CODING_NONE; + } + if( !Q_stricmp( name, "gzip" ) ) { + return HTTP_CODING_GZIP; + } + if( !Q_stricmp( name, "x-gzip" ) ) { + return HTTP_CODING_GZIP; + } + if( !Q_stricmp( name, "deflate" ) ) { + return HTTP_CODING_DEFLATE; + } + return HTTP_CODING_UNKNOWN; +} + static qboolean MVD_ParseResponse( mvd_t *mvd ) { char key[MAX_TOKEN_CHARS]; char *p, *token; @@ -592,21 +608,7 @@ static qboolean MVD_ParseResponse( mvd_t *mvd ) { token = COM_SimpleParse( &line, NULL ); if( !strcmp( key, "content-type" ) ) { } else if( !strcmp( key, "content-encoding" ) ) { -#if USE_ZLIB - if( !Q_stricmp( token, "deflate" ) || - !Q_stricmp( token, "gzip" ) || - !Q_stricmp( token, "x-gzip" ) ) - { - if( inflateInit2( &mvd->z, 47 ) != Z_OK ) { - MVD_Dropf( mvd, "inflateInit2() failed: %s", mvd->z.msg ); - } - mvd->zbuf.data = MVD_Malloc( MAX_MSGLEN * 2 ); - mvd->zbuf.size = MAX_MSGLEN * 2; - } else -#endif - { - MVD_Dropf( mvd, "Unsupported content encoding: %s", token ); - } + mvd->contentCoding = MVD_FindCoding( token ); } else if( !strcmp( key, "content-length" ) ) { mvd->contentLength = atoi( token ); } else if( !strcmp( key, "transfer-encoding" ) ) { @@ -698,6 +700,24 @@ int MVD_Frame( void ) { MVD_Dropf( mvd, "HTTP request failed: %d %s", mvd->statusCode, mvd->statusText ); } + switch( mvd->contentCoding ) { + case HTTP_CODING_NONE: + break; +#if USE_ZLIB + case HTTP_CODING_GZIP: + case HTTP_CODING_DEFLATE: + if( inflateInit2( &mvd->z, 47 ) != Z_OK ) { + MVD_Dropf( mvd, "inflateInit2() failed: %s", mvd->z.msg ); + } + mvd->zbuf.data = MVD_Malloc( MAX_MSGLEN * 2 ); + mvd->zbuf.size = MAX_MSGLEN * 2; + break; +#endif + default: + MVD_Dropf( mvd, "Unsupported content encoding: %d", + mvd->contentCoding ); + break; + } Com_Printf( "[%s] Got response, awaiting gamestate...\n", mvd->name ); mvd->state = MVD_CHECKING; // fall through @@ -913,8 +933,10 @@ MVD_Connect_f void MVD_Connect_f( void ) { static const cmd_option_t options[] = { { "h", "help", "display this message" }, + { "e:number", "encoding", "assume encoding identified by <number>" }, { "i:number", "id", "specify remote stream ID as <number>" }, { "n:string", "name", "specify channel name as <string>" }, + { "r:string", "referer", "specify referer as <string> in HTTP request" }, { NULL } }; netadr_t adr; @@ -922,7 +944,8 @@ void MVD_Connect_f( void ) { char buffer[MAX_STRING_CHARS]; char resource[MAX_STRING_CHARS]; char credentials[MAX_STRING_CHARS]; - char *id = "", *name = NULL, *host, *p; + char *id = "", *name = NULL, *referer = NULL, *host, *p; + htcoding_t coding = HTTP_CODING_NONE; mvd_t *mvd; uint16 port; int c; @@ -936,14 +959,29 @@ void MVD_Connect_f( void ) { Com_Printf( "Full URI syntax: [http://][user:pass@]<host>[:port][/resource]\n" "If resource is given, default port is 80 and stream ID is ignored.\n" - "Otherwise, default port is %d and stream ID is undefined.\n", PORT_SERVER ); + "Otherwise, default port is %d and stream ID is undefined.\n\n" +#if USE_ZLIB + "Accepted content encodings: gzip, deflate.\n" +#endif + , PORT_SERVER ); return; + case 'e': + coding = MVD_FindCoding( cmd_optarg ); + if( coding == HTTP_CODING_UNKNOWN ) { + Com_Printf( "Unknown content encoding: %s.\n", cmd_optarg ); + Cmd_PrintHint(); + return; + } + break; case 'i': id = cmd_optarg; break; case 'n': name = cmd_optarg; break; + case 'r': + referer = cmd_optarg; + break; default: return; } @@ -1004,6 +1042,7 @@ void MVD_Connect_f( void ) { mvd = Z_ReservedAllocz( sizeof( *mvd ) ); mvd->id = mvd_chanid++; mvd->state = MVD_CONNECTING; + mvd->contentCoding = coding; mvd->stream = stream; mvd->stream.recv.data = Z_ReservedAlloc( MAX_MSGLEN * 2 ); mvd->stream.recv.size = MAX_MSGLEN * 2; @@ -1034,7 +1073,7 @@ void MVD_Connect_f( void ) { "GET /%s HTTP/1.0\r\n" "Host: %s\r\n" "User-Agent: " APPLICATION "/" VERSION "\r\n" -#ifdef USE_ZLIB +#if USE_ZLIB "Accept-Encoding: gzip, deflate\r\n" #endif "Accept: application/*\r\n", @@ -1043,6 +1082,9 @@ void MVD_Connect_f( void ) { Q_Encode64( buffer, credentials, sizeof( buffer ) ); MVD_HttpPrintf( mvd, "Authorization: Basic %s\r\n", buffer ); } + if( referer ) { + MVD_HttpPrintf( mvd, "Referer: %s\r\n", referer ); + } MVD_HttpPrintf( mvd, "\r\n" ); } diff --git a/source/mvd_local.h b/source/mvd_local.h index e75fdb1..becdd09 100644 --- a/source/mvd_local.h +++ b/source/mvd_local.h @@ -119,6 +119,7 @@ typedef struct mvd_s { char response[MAX_NET_STRING]; int responseLength; int contentLength; + htcoding_t contentCoding; int statusCode; char statusText[MAX_QPATH]; int msglen; diff --git a/source/sv_local.h b/source/sv_local.h index ad92847..bc50b1f 100644 --- a/source/sv_local.h +++ b/source/sv_local.h @@ -244,6 +244,13 @@ typedef enum { HTTP_METHOD_POST } htmethod_t; +typedef enum { + HTTP_CODING_NONE, + HTTP_CODING_GZIP, + HTTP_CODING_DEFLATE, + HTTP_CODING_UNKNOWN +} htcoding_t; + typedef struct { list_t entry; clstate_t state; |