Changeset 57720 in vbox for trunk/src/VBox/Runtime/common/misc/http.cpp
- Timestamp:
- Sep 11, 2015 2:49:21 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/http.cpp
r57624 r57720 68 68 /** Whether to delete the CA on destruction. */ 69 69 bool fDeleteCaFile; 70 /** Set if we should use the system proxy settings for a URL. 71 * This means reconfiguring cURL for each request. */ 72 bool fUseSystemProxySettings; 70 73 /** Abort the current HTTP request if true. */ 71 74 bool volatile fAbort; … … 159 162 if (pThis) 160 163 { 161 pThis->u32Magic = RTHTTP_MAGIC; 162 pThis->pCurl = pCurl; 164 pThis->u32Magic = RTHTTP_MAGIC; 165 pThis->pCurl = pCurl; 166 pThis->fUseSystemProxySettings = true; 163 167 164 168 *phHttp = (RTHTTP)pThis; … … 261 265 else if (rc == VERR_ENV_VAR_NOT_FOUND) 262 266 rc = VINF_SUCCESS; 267 268 return rc; 269 } 270 271 272 static bool rtHttpUrlInNoProxyList(const char *pszUrl, const char *pszNoProxyList) 273 { 274 /** @todo implement me. */ 275 return false; 276 } 277 278 279 static int rtHttpConfigureProxyForUrl(PRTHTTPINTERNAL pThis, const char *pszUrl) 280 { 281 const char *pszProxy = NULL; 282 long uPort = 0; 283 const char *pszUser = NULL; 284 const char *pszPassword = NULL; 285 bool fNoProxy = true; 286 287 288 char szTmp[_1K]; 289 290 /* 291 * First we consult the "no_proxy" / "NO_PROXY" environment variable. 292 */ 293 const char *pszNoProxyVar; 294 size_t cchActual; 295 char *pszNoProxyFree = NULL; 296 char *pszNoProxy = szTmp; 297 int rc = RTEnvGetEx(RTENV_DEFAULT, pszNoProxyVar = "no_proxy", szTmp, sizeof(szTmp), &cchActual); 298 if (rc == VERR_ENV_VAR_NOT_FOUND) 299 rc = RTEnvGetEx(RTENV_DEFAULT, pszNoProxyVar = "NO_PROXY", szTmp, sizeof(szTmp), &cchActual); 300 if (rc == VERR_BUFFER_OVERFLOW) 301 { 302 pszNoProxyFree = pszNoProxy = (char *)RTMemTmpAlloc(cchActual + _1K); 303 AssertReturn(pszNoProxy, VERR_NO_TMP_MEMORY); 304 rc = RTEnvGetEx(RTENV_DEFAULT, pszNoProxyVar, pszNoProxy, cchActual + _1K, NULL); 305 } 306 AssertMsg(rc == VINF_SUCCESS || rc == VERR_ENV_VAR_NOT_FOUND, ("rc=%Rrc\n", rc)); 307 fNoProxy = rtHttpUrlInNoProxyList(pszUrl, pszNoProxy); 308 RTMemTmpFree(pszNoProxy); 309 if (!fNoProxy) 310 { 311 /* 312 * Get the schema specific specific env var, falling back on the 313 * generic all_proxy if not found. 314 */ 315 const char *apszEnvVars[4]; 316 unsigned cEnvVars = 0; 317 if (!RTStrNICmp(pszUrl, RT_STR_TUPLE("http:"))) 318 apszEnvVars[cEnvVars++] = "http_proxy"; /* Skip HTTP_PROXY because of cgi paranoia */ 319 else if (!RTStrNICmp(pszUrl, RT_STR_TUPLE("https:"))) 320 { 321 apszEnvVars[cEnvVars++] = "https_proxy"; 322 apszEnvVars[cEnvVars++] = "HTTPS_PROXY"; 323 } 324 else if (!RTStrNICmp(pszUrl, RT_STR_TUPLE("ftp:"))) 325 { 326 apszEnvVars[cEnvVars++] = "ftp_proxy"; 327 apszEnvVars[cEnvVars++] = "FTP_PROXY"; 328 } 329 else 330 AssertMsgFailedReturn(("Unknown/unsupported schema in URL: '%s'\n", pszUrl), VERR_NOT_SUPPORTED); 331 apszEnvVars[cEnvVars++] = "all_proxy"; 332 apszEnvVars[cEnvVars++] = "ALL_PROXY"; 333 334 for (uint32_t i = 0; i < cEnvVars; i++) 335 { 336 size_t cchValue; 337 rc = RTEnvGetEx(RTENV_DEFAULT, apszEnvVars[i], szTmp, sizeof(szTmp) - sizeof("http://"), &cchValue); 338 if (RT_SUCCESS(rc)) 339 { 340 if (!strstr(szTmp, "://")) 341 { 342 memmove(&szTmp[sizeof("http://") - 1], szTmp, cchValue + 1); 343 memcpy(szTmp, RT_STR_TUPLE("http://")); 344 } 345 /** @todo continue where using RTUriParse... */ 346 } 347 else 348 AssertMsg(rc == VERR_ENV_VAR_NOT_FOUND, ("%Rrc\n")); 349 } 350 351 #if 0 352 if (RT_SUCCESS(rc)) 353 { 354 int rcCurl; 355 if (!strncmp(szProxy, RT_STR_TUPLE("http://"))) 356 { 357 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_PROXY, &szProxy[sizeof("http://") - 1]); 358 if (CURL_FAILURE(rcCurl)) 359 return VERR_INVALID_PARAMETER; 360 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_PROXYPORT, 80); 361 if (CURL_FAILURE(rcCurl)) 362 return VERR_INVALID_PARAMETER; 363 } 364 else 365 { 366 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_PROXY, &szProxy[sizeof("http://") - 1]); 367 if (CURL_FAILURE(rcCurl)) 368 return VERR_INVALID_PARAMETER; 369 } 370 } 371 else if (rc == VERR_ENV_VAR_NOT_FOUND) 372 rc = VINF_SUCCESS; 373 #endif 374 } 263 375 264 376 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.