From: divverent Date: Sun, 29 Aug 2010 18:33:06 +0000 (+0000) Subject: curl: strip user/pass from URLs on display X-Git-Tag: xonotic-v0.1.0preview~257 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=826a3660e4bcdea63651ecdc1a8ad7c8dc34a92a;p=xonotic%2Fdarkplaces.git curl: strip user/pass from URLs on display git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10429 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=a41cdf058486349769bcd97fe7ae60f0a3e3afcf --- diff --git a/libcurl.c b/libcurl.c index 0efac5e8..48f5bf35 100644 --- a/libcurl.c +++ b/libcurl.c @@ -534,6 +534,37 @@ static void Curl_EndDownload(downloadinfo *di, CurlStatus status, CURLcode error Z_Free(di); } +/* +==================== +CleanURL + +Returns a "cleaned up" URL for display (to strip login data) +==================== +*/ +static const char *CleanURL(const char *url) +{ + static char urlbuf[1024]; + const char *p, *q, *r; + + // if URL is of form anything://foo-without-slash@rest, replace by anything://rest + p = strstr(url, "://"); + if(p) + { + q = strchr(p + 3, '@'); + if(q) + { + r = strchr(p + 3, '/'); + if(!r || q < r) + { + dpsnprintf(urlbuf, sizeof(urlbuf), "%.*s%s", (int)(p - url + 3), url, q + 1); + return urlbuf; + } + } + } + + return url; +} + /* ==================== CheckPendingDownloads @@ -556,7 +587,7 @@ static void CheckPendingDownloads(void) { if(!di->buffer) { - Con_Printf("Downloading %s -> %s", di->url, di->filename); + Con_Printf("Downloading %s -> %s", CleanURL(di->url), di->filename); di->stream = FS_OpenRealFile(di->filename, "ab", false); if(!di->stream) @@ -574,7 +605,7 @@ static void CheckPendingDownloads(void) } else { - Con_DPrintf("Downloading %s -> memory\n", di->url); + Con_DPrintf("Downloading %s -> memory\n", CleanURL(di->url)); di->startpos = 0; } @@ -746,7 +777,7 @@ static qboolean Curl_Begin(const char *URL, double maxspeed, const char *name, q // 141.2.16.3 - - [17/Mar/2006:22:32:43 +0100] "GET /maps/tznex07.pk3 HTTP/1.1" 200 1077455 "dp://141.2.16.7:26000/" "Nexuiz Linux 22:07:43 Mar 17 2006" if(!name) - name = URL; + name = CleanURL(URL); if(!buf) { @@ -763,7 +794,7 @@ static qboolean Curl_Begin(const char *URL, double maxspeed, const char *name, q downloadinfo *di = Curl_Find(fn); if(di) { - Con_Printf("Can't download %s, already getting it from %s!\n", fn, di->url); + Con_Printf("Can't download %s, already getting it from %s!\n", fn, CleanURL(di->url)); // however, if it was not for this map yet... if(forthismap && !di->forthismap) @@ -1073,7 +1104,7 @@ static void Curl_Info_f(void) for(di = downloads; di; di = di->next) { double speed, percent; - Con_Printf(" %s -> %s ", di->url, di->filename); + Con_Printf(" %s -> %s ", CleanURL(di->url), di->filename); percent = 100.0 * Curl_GetDownloadAmount(di); speed = Curl_GetDownloadSpeed(di); if(percent >= 0) @@ -1136,10 +1167,6 @@ void Curl_Curl_f(void) return; } - for(i = 0; i != Cmd_Argc(); ++i) - Con_DPrintf("%s ", Cmd_Argv(i)); - Con_DPrint("\n"); - if(Cmd_Argc() < 2) { Con_Print("usage:\ncurl --info, curl --cancel [filename], curl url\n");