From: divverent Date: Tue, 3 Jan 2012 12:00:40 +0000 (+0000) Subject: allow control over User-Agent: X-Git-Tag: xonotic-v0.6.0~91 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b39f698999d7954c0e720b2dc3499d521a540eb5;p=xonotic%2Fdarkplaces.git allow control over User-Agent: cl_curl_useragent 0 turns it off -DHTTP_USER_AGENT="Foo" overrides the engineversion part cl_curl_useragent_append bar appends stuff ("Foo bar") git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11630 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=c63a96d0455acb22993ca01751d99f509e861461 --- diff --git a/libcurl.c b/libcurl.c index 637a649d..3baa91b4 100644 --- a/libcurl.c +++ b/libcurl.c @@ -9,6 +9,8 @@ static cvar_t sv_curl_defaulturl = {CVAR_SAVE, "sv_curl_defaulturl","", "default static cvar_t sv_curl_serverpackages = {CVAR_SAVE, "sv_curl_serverpackages","", "list of required files for the clients, separated by spaces"}; static cvar_t sv_curl_maxspeed = {CVAR_SAVE, "sv_curl_maxspeed","0", "maximum download speed for clients downloading from sv_curl_defaulturl (KiB/s)"}; static cvar_t cl_curl_enabled = {CVAR_SAVE, "cl_curl_enabled","1", "whether client's download support is enabled"}; +static cvar_t cl_curl_useragent = {0, "cl_curl_useragent","1", "send the User-Agent string (note: turning this off may break stuff)"}; +static cvar_t cl_curl_useragent_append = {0, "cl_curl_useragent_append","", "a string to append to the User-Agent string (useful for name and version number of your mod)"}; /* ================================================================= @@ -637,7 +639,27 @@ static void CheckPendingDownloads(void) di->curle = qcurl_easy_init(); di->slist = NULL; qcurl_easy_setopt(di->curle, CURLOPT_URL, di->url); - qcurl_easy_setopt(di->curle, CURLOPT_USERAGENT, engineversion); + if(cl_curl_useragent.integer) + { + const char *ua +#ifdef HTTP_USER_AGENT + = HTTP_USER_AGENT; +#else + = engineversion; +#endif + if(!ua) + ua = ""; + if(*cl_curl_useragent_append.string) + ua = va(vabuf, sizeof(vabuf), "%s%s%s", + ua, + (ua[0] && ua[strlen(ua)-1] != ' ') + ? " " + : "", + cl_curl_useragent_append.string); + qcurl_easy_setopt(di->curle, CURLOPT_USERAGENT, ua); + } + else + qcurl_easy_setopt(di->curle, CURLOPT_USERAGENT, ""); qcurl_easy_setopt(di->curle, CURLOPT_REFERER, di->referer); qcurl_easy_setopt(di->curle, CURLOPT_RESUME_FROM, (long) di->startpos); qcurl_easy_setopt(di->curle, CURLOPT_FOLLOWLOCATION, 1); @@ -1395,6 +1417,8 @@ void Curl_Init_Commands(void) Cvar_RegisterVariable (&sv_curl_defaulturl); Cvar_RegisterVariable (&sv_curl_serverpackages); Cvar_RegisterVariable (&sv_curl_maxspeed); + Cvar_RegisterVariable (&cl_curl_useragent); + Cvar_RegisterVariable (&cl_curl_useragent_append); Cmd_AddCommand ("curl", Curl_Curl_f, "download data from an URL and add to search path"); //Cmd_AddCommand ("curlcat", Curl_CurlCat_f, "display data from an URL (debugging command)"); }