Changeset 57727 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Sep 12, 2015 12:44:44 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/http.cpp
r57726 r57727 35 35 #include <iprt/assert.h> 36 36 #include <iprt/crypto/store.h> 37 #include <iprt/ctype.h> 37 38 #include <iprt/env.h> 38 39 #include <iprt/err.h> … … 226 227 RTStrFree(pThis->pszRedirLocation); 227 228 229 RTStrFree(pThis->pszProxyHost); 230 RTStrFree(pThis->pszProxyUsername); 231 RTMemWipeThoroughly(pThis->pszProxyPassword, strlen(pThis->pszProxyPassword), 2); 232 RTStrFree(pThis->pszProxyPassword); 233 228 234 RTMemFree(pThis); 229 235 … … 276 282 * @param pThis The HTTP client instance. 277 283 * @param enmProxyType The proxy type. 278 * @param pszHost The proxy host name. If NULL, the proxying will be 279 * disabled. 284 * @param pszHost The proxy host name. 280 285 * @param uPort The proxy port number. 281 286 * @param pszUsername The proxy username, or NULL if none. … … 286 291 { 287 292 int rcCurl; 293 AssertReturn(pszHost, VERR_INVALID_PARAMETER); 294 295 if (pThis->fNoProxy) 296 { 297 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_NOPROXY, (const char *)NULL); 298 AssertMsgReturn(rcCurl == CURLE_OK, ("CURLOPT_NOPROXY=NULL: %d (%#x)\n", rcCurl, rcCurl), 299 VERR_HTTP_CURL_PROXY_CONFIG); 300 pThis->fNoProxy = false; 301 } 288 302 289 303 if (enmProxyType != pThis->enmProxyType) … … 396 410 pThis->pszProxyHost = NULL; 397 411 } 412 413 /* No proxy for everything! */ 414 AssertReturn(curl_easy_setopt(pThis->pCurl, CURLOPT_NOPROXY, "*") == CURLE_OK, CURLOPT_PROXY); 415 pThis->fNoProxy = true; 416 398 417 return VINF_SUCCESS; 399 418 } 400 419 401 420 402 static bool rtHttpUrlInNoProxyList(const char *pszUrl, const char *pszNoProxyList) 403 { 404 /** @todo implement me. */ 405 return false; 406 } 407 421 /** 422 * See if the host name of the URL is included in the stripped no_proxy list. 423 * 424 * The no_proxy list is a colon or space separated list of domain names for 425 * which there should be no proxying. Given "no_proxy=oracle.com" neither the 426 * URL "http://www.oracle.com" nor "http://oracle.com" will not be proxied, but 427 * "http://notoracle.com" will be. 428 * 429 * @returns true if the URL is in the no_proxy list, otherwise false. 430 * @param pszUrl The URL. 431 * @param pszNoProxyList The stripped no_proxy list. 432 */ 433 static bool rtHttpUrlInNoProxyList(const char *pszUrl, const char *pszNoProxyList) 434 { 435 /* 436 * Check for just '*', diabling proxying for everything. 437 * (Caller stripped pszNoProxyList.) 438 */ 439 if (*pszNoProxyList == '*' && pszNoProxyList[1] == '\0') 440 return true; 441 442 /* 443 * Empty list? (Caller stripped it, remember). 444 */ 445 if (!*pszNoProxyList) 446 return false; 447 448 /* 449 * We now need to parse the URL and extract the host name. 450 */ 451 RTURIPARSED Parsed; 452 int rc = RTUriParse(pszUrl, &Parsed); 453 AssertRCReturn(rc, false); 454 char *pszHost = RTUriParsedAuthorityHost(pszUrl, &Parsed); 455 if (!pszHost) /* Don't assert, in case of file:///xxx or similar blunder. */ 456 return false; 457 458 bool fRet = false; 459 size_t const cchHost = strlen(pszHost); 460 if (cchHost) 461 { 462 /* 463 * The list is comma or space separated, walk it and match host names. 464 */ 465 while (*pszNoProxyList != '\0') 466 { 467 /* Strip leading slashes, commas and dots. */ 468 char ch; 469 while ( (ch = *pszNoProxyList) == ',' 470 || ch == '.' 471 || RT_C_IS_SPACE(ch)) 472 pszNoProxyList++; 473 474 /* Find the end. */ 475 size_t cch = RTStrOffCharOrTerm(pszNoProxyList, ','); 476 size_t offNext = RTStrOffCharOrTerm(pszNoProxyList, ' '); 477 cch = RT_MIN(cch, offNext); 478 offNext = cch; 479 480 /* Trip trailing spaces, well tabs and stuff. */ 481 while (cch > 0 && RT_C_IS_SPACE(pszNoProxyList[cch - 1])) 482 cch--; 483 484 /* Do the matching, if we have anything to work with. */ 485 if (cch > 0) 486 { 487 if ( ( cch == cchHost 488 && RTStrNICmp(pszNoProxyList, pszHost, cch) == 0) 489 || ( cch < cchHost 490 && pszHost[cchHost - cch - 1] == '.' 491 && RTStrNICmp(pszNoProxyList, &pszHost[cchHost - cch], cch) == 0) ) 492 { 493 fRet = true; 494 break; 495 } 496 } 497 498 /* Next. */ 499 pszNoProxyList += offNext; 500 } 501 } 502 503 RTStrFree(pszHost); 504 return fRet; 505 } 408 506 409 507 … … 437 535 } 438 536 AssertMsg(rc == VINF_SUCCESS || rc == VERR_ENV_VAR_NOT_FOUND, ("rc=%Rrc\n", rc)); 439 bool fNoProxy = rtHttpUrlInNoProxyList(pszUrl, pszNoProxy);537 bool fNoProxy = rtHttpUrlInNoProxyList(pszUrl, RTStrStrip(pszNoProxy)); 440 538 RTMemTmpFree(pszNoProxyFree); 441 539 if (!fNoProxy)
Note:
See TracChangeset
for help on using the changeset viewer.