- Timestamp:
- Aug 8, 2020 2:06:23 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/http.h
r85139 r85650 665 665 * Supported proxy types. 666 666 */ 667 typedef enum { 668 RTHTTPPROXYTYPE_UNKNOWN, 667 typedef enum RTHTTPPROXYTYPE 668 { 669 RTHTTPPROXYTYPE_INVALID = 0, 670 RTHTTPPROXYTYPE_NOPROXY, 669 671 RTHTTPPROXYTYPE_HTTP, 670 672 RTHTTPPROXYTYPE_HTTPS, 671 673 RTHTTPPROXYTYPE_SOCKS4, 672 RTHTTPPROXYTYPE_SOCKS5 674 RTHTTPPROXYTYPE_SOCKS5, 675 RTHTTPPROXYTYPE_UNKNOWN, 676 RTHTTPPROXYTYPE_END, 677 RTHTTPPROXYTYPE_32BIT_HACK = 0x7fffffff 673 678 } RTHTTPPROXYTYPE; 674 679 675 680 /** 676 * Proxy information structure. 677 */ 678 typedef struct { 679 /** Proxy host name (RTStrFree). */ 681 * Proxy information returned by RTHttpQueryProxyInfoForUrl. 682 */ 683 typedef struct RTHTTPPROXYINFO 684 { 685 /** Proxy host name. */ 680 686 char *pszProxyHost; 681 687 /** Proxy port number (UINT32_MAX if not specified). */ … … 683 689 /** The proxy type (RTHTTPPROXYTYPE_HTTP, RTHTTPPROXYTYPE_SOCKS5, ++). */ 684 690 RTHTTPPROXYTYPE enmProxyType; 685 /** Proxy username (RTStrFree). */691 /** Proxy username. */ 686 692 char *pszProxyUsername; 687 /** Proxy password (RTStrFree). */693 /** Proxy password. */ 688 694 char *pszProxyPassword; 689 695 } RTHTTPPROXYINFO; … … 696 702 * @returns IPRT status code. 697 703 * @param hHttp The HTTP client handle. 698 * @param pcszUrl The URL that needs to be accessed via proxy. 699 * @param pProxyInfo A pointer to the structure where the proxy information to be stored. 700 * 701 * @note This function allocates memory that must be released by RTHttpFreeProxyInfo. 702 */ 703 RTR3DECL(int) RTHttpGetProxyInfoForUrl(RTHTTP hHttp, const char *pcszUrl, PRTHTTPPROXYINFO pProxyInfo); 704 705 /** 706 * Release memory used for storing proxy information. 707 * 708 * @returns IPRT status code. 709 * @param pProxyInfo A pointer to the proxy structure being released. 710 * 711 * @note This function releases memory that has been allocated by RTHttpGetProxyInfoForUrl. 704 * @param pszUrl The URL that needs to be accessed via proxy. 705 * @param pProxyInfo Where to return the proxy information. This must be 706 * freed up by calling RTHttpFreeProxyInfo() when done. 707 */ 708 RTR3DECL(int) RTHttpQueryProxyInfoForUrl(RTHTTP hHttp, const char *pszUrl, PRTHTTPPROXYINFO pProxyInfo); 709 710 /** 711 * Counter part to RTHttpQueryProxyInfoForUrl that releases any memory returned 712 * in the proxy info structure. 713 * 714 * @returns IPRT status code. 715 * @param pProxyInfo Pointer to proxy info returned by a successful 716 * RTHttpQueryProxyInfoForUrl() call. 712 717 */ 713 718 RTR3DECL(int) RTHttpFreeProxyInfo(PRTHTTPPROXYINFO pProxyInfo); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloud.cpp
r85359 r85650 2108 2108 } 2109 2109 2110 static bool getSystemProxyForUrl(const com::Utf8Str &strUrl, Bstr &strProxy) 2111 { 2110 /** 2111 * @returns COM status code. 2112 * @retval S_OK if url needs proxy. 2113 * @retval S_FALSE if noproxy for the URL. 2114 */ 2115 static HRESULT getSystemProxyForUrl(const com::Utf8Str &strUrl, Bstr &strProxy) 2116 { 2117 /** @todo r=bird: LogRel is pointless here. */ 2112 2118 #ifndef VBOX_WITH_PROXY_INFO 2113 2119 RT_NOREF(strUrl, strProxy); 2114 2120 LogRel(("CLOUD-NET: Proxy support is disabled. Using direct connection.\n")); 2115 return false;2121 return S_FALSE; 2116 2122 #else /* VBOX_WITH_PROXY_INFO */ 2117 RTHTTP hHttp; 2123 HRESULT hrc = E_FAIL; 2124 RTHTTP hHttp; 2118 2125 int rc = RTHttpCreate(&hHttp); 2119 if (RT_FAILURE(rc)) 2120 { 2121 LogRel(("CLOUD-NET: Failed to create HTTP context (rc=%d)\n", rc)); 2122 return false; 2123 } 2124 rc = RTHttpUseSystemProxySettings(hHttp); 2125 if (RT_FAILURE(rc)) 2126 { 2127 LogRel(("CLOUD-NET: Failed to use system proxy (rc=%d)\n", rc)); 2126 if (RT_SUCCESS(rc)) 2127 { 2128 rc = RTHttpUseSystemProxySettings(hHttp); 2129 if (RT_SUCCESS(rc)) 2130 { 2131 RTHTTPPROXYINFO proxy; 2132 rc = RTHttpQueryProxyInfoForUrl(hHttp, strUrl.c_str(), &proxy); 2133 if (RT_SUCCESS(rc)) 2134 { 2135 const char *pcszProxyScheme = ""; 2136 switch (proxy.enmProxyType) 2137 { 2138 case RTHTTPPROXYTYPE_NOPROXY: 2139 pcszProxyScheme = NULL; 2140 hrc = S_FALSE; 2141 break; 2142 case RTHTTPPROXYTYPE_HTTP: 2143 pcszProxyScheme = "http://"; 2144 break; 2145 case RTHTTPPROXYTYPE_HTTPS: 2146 pcszProxyScheme = "https://"; 2147 break; 2148 case RTHTTPPROXYTYPE_SOCKS4: 2149 pcszProxyScheme = "socks4://"; 2150 break; 2151 case RTHTTPPROXYTYPE_SOCKS5: 2152 pcszProxyScheme = "socks://"; 2153 break; 2154 case RTHTTPPROXYTYPE_INVALID: 2155 case RTHTTPPROXYTYPE_UNKNOWN: 2156 case RTHTTPPROXYTYPE_END: 2157 case RTHTTPPROXYTYPE_32BIT_HACK: 2158 break; 2159 } 2160 if (pcszProxyScheme && *pcszProxyScheme != '\0') 2161 { 2162 if (proxy.pszProxyUsername || proxy.pszProxyPassword) 2163 LogRel(("CLOUD-NET: Warning! Code doesn't yet handle proxy user or password. Sorry.\n")); 2164 if (proxy.uProxyPort != UINT32_MAX) 2165 strProxy.printf("%s%s:%d", pcszProxyScheme, proxy.pszProxyHost, proxy.uProxyPort); 2166 else 2167 strProxy.printf("%s%s", pcszProxyScheme, proxy.pszProxyHost); 2168 hrc = S_OK; 2169 } 2170 else if (pcszProxyScheme) 2171 { 2172 LogRel(("CLOUD-NET: Unknown proxy type %d. Using direct connection.\n", proxy.enmProxyType)); 2173 AssertFailed(); 2174 } 2175 RTHttpFreeProxyInfo(&proxy); 2176 } 2177 else 2178 LogRel(("CLOUD-NET: Failed to get proxy for %s (rc=%Rrc)\n", strUrl.c_str(), rc)); 2179 } 2180 else 2181 LogRel(("CLOUD-NET: Failed to use system proxy (rc=%Rrc)\n", rc)); 2128 2182 RTHttpDestroy(hHttp); 2129 return false; 2130 } 2131 2132 RTHTTPPROXYINFO proxy; 2133 RT_ZERO(proxy); 2134 rc = RTHttpGetProxyInfoForUrl(hHttp, strUrl.c_str(), &proxy); 2135 if (RT_FAILURE(rc)) 2136 { 2137 LogRel(("CLOUD-NET: Failed to get proxy for %s (rc=%d)\n", strUrl.c_str(), rc)); 2138 RTHttpDestroy(hHttp); 2139 return false; 2140 } 2141 const char *pcszProxyScheme = ""; 2142 switch (proxy.enmProxyType) 2143 { 2144 case RTHTTPPROXYTYPE_HTTP: 2145 pcszProxyScheme = "http://"; 2146 break; 2147 case RTHTTPPROXYTYPE_HTTPS: 2148 pcszProxyScheme = "https://"; 2149 break; 2150 case RTHTTPPROXYTYPE_SOCKS4: 2151 pcszProxyScheme = "socks4://"; 2152 break; 2153 case RTHTTPPROXYTYPE_SOCKS5: 2154 pcszProxyScheme = "socks://"; 2155 break; 2156 case RTHTTPPROXYTYPE_UNKNOWN: 2157 LogRel(("CLOUD-NET: Unknown proxy type. Using direct connecton.")); 2158 RTHttpDestroy(hHttp); 2159 return false; 2160 } 2161 strProxy = BstrFmt("%s%s:%d", pcszProxyScheme, proxy.pszProxyHost, proxy.uProxyPort); 2162 RTHttpFreeProxyInfo(&proxy); 2163 RTHttpDestroy(hHttp); 2164 return true; 2183 } 2184 else 2185 LogRel(("CLOUD-NET: Failed to create HTTP context (rc=%Rrc)\n", rc)); 2186 return hrc; 2165 2187 #endif /* VBOX_WITH_PROXY_INFO */ 2166 2188 } … … 2210 2232 break; 2211 2233 case ProxyMode_System: 2212 if (!getSystemProxyForUrl("https://dl.fedoraproject.org", strProxy)) 2213 errorOccured(E_FAIL, "Failed to get system proxy for https://dl.fedoraproject.org. Will use direct connection."); 2234 hrc = getSystemProxyForUrl("https://dl.fedoraproject.org", strProxy); 2235 if (FAILED(hrc)) 2236 errorOccured(hrc, "Failed to get system proxy for https://dl.fedoraproject.org. Will use direct connection."); 2214 2237 break; 2215 2238 default: /* To get rid of ProxyMode_32BitHack 'warning' */ 2216 RTAssertPanic();2239 AssertFailed(); 2217 2240 break; 2218 2241 } -
trunk/src/VBox/Main/src-client/CloudGateway.cpp
r85359 r85650 545 545 if (RT_FAILURE(rc)) 546 546 { 547 LogRel(("CLOUD-NET: Failed to create HTTP context (rc=% d)\n", rc));547 LogRel(("CLOUD-NET: Failed to create HTTP context (rc=%Rrc)\n", rc)); 548 548 return false; 549 549 } … … 551 551 if (RT_FAILURE(rc)) 552 552 { 553 LogRel(("CLOUD-NET: Failed to use system proxy (rc=% d)\n", rc));553 LogRel(("CLOUD-NET: Failed to use system proxy (rc=%Rrc)\n", rc)); 554 554 RTHttpDestroy(hHttp); 555 555 return false; … … 557 557 558 558 RTHTTPPROXYINFO proxy; 559 RT_ZERO(proxy); 560 rc = RTHttpGetProxyInfoForUrl(hHttp, ("http://" + strIpAddr).c_str(), &proxy); 559 rc = RTHttpQueryProxyInfoForUrl(hHttp, ("http://" + strIpAddr).c_str(), &proxy); 561 560 if (RT_FAILURE(rc)) 562 561 { 563 LogRel(("CLOUD-NET: Failed to get proxy for %s (rc=% d)\n", strIpAddr.c_str(), rc));562 LogRel(("CLOUD-NET: Failed to get proxy for %s (rc=%Rrc)\n", strIpAddr.c_str(), rc)); 564 563 RTHttpDestroy(hHttp); 565 564 return false; … … 567 566 switch (proxy.enmProxyType) 568 567 { 568 case RTHTTPPROXYTYPE_NOPROXY: 569 RTHttpFreeProxyInfo(&proxy); 570 RTHttpDestroy(hHttp); 571 return false; 569 572 case RTHTTPPROXYTYPE_HTTP: 570 573 strProxyType = "HTTP"; … … 580 583 break; 581 584 case RTHTTPPROXYTYPE_UNKNOWN: 582 LogRel(("CLOUD-NET: Unknown proxy type.")); 585 case RTHTTPPROXYTYPE_INVALID: 586 case RTHTTPPROXYTYPE_END: 587 case RTHTTPPROXYTYPE_32BIT_HACK: 583 588 break; 584 589 } 590 AssertStmt(strProxyType.isNotEmpty(), LogRel(("CLOUD-NET: Unknown proxy type: %d\n", proxy.enmProxyType))); 585 591 strProxyHost = proxy.pszProxyHost; 586 strProxyPort = BstrFmt("%d", proxy.uProxyPort); 592 if (proxy.uProxyPort != UINT32_MAX) 593 strProxyPort.printf("%d", proxy.uProxyPort); 587 594 RTHttpFreeProxyInfo(&proxy); 588 595 RTHttpDestroy(hHttp); -
trunk/src/VBox/Runtime/generic/http-curl.cpp
r85646 r85650 3556 3556 3557 3557 3558 RTR3DECL(int) RTHttpGetProxyInfoForUrl(RTHTTP hHttp, const char *pcszUrl, PRTHTTPPROXYINFO pProxy) 3559 { 3560 PRTHTTPINTERNAL pThis = hHttp; 3558 RTR3DECL(int) RTHttpQueryProxyInfoForUrl(RTHTTP hHttp, const char *pszUrl, PRTHTTPPROXYINFO pProxy) 3559 { 3560 /* 3561 * Validate input and clear output. 3562 */ 3563 Log(("RTHttpQueryProxyInfoForUrl: hHttp=%p pszUrl=%s pProxy=%s\n", hHttp, pszUrl, pProxy)); 3564 RT_ZERO(*pProxy); 3565 pProxy->uProxyPort = UINT32_MAX; 3566 3567 PRTHTTPINTERNAL pThis = hHttp; 3568 RTHTTP_VALID_RETURN(pThis); 3569 3570 /* 3571 * Set up the proxy for the URL. 3572 */ 3561 3573 rtHttpResetState(pThis); 3562 int rc = rtHttpApplySettings(pThis, pcszUrl); 3563 if (RT_FAILURE(rc)) 3564 return rc; 3565 3566 switch (pThis->enmProxyType) 3567 { 3568 case CURLPROXY_HTTP: 3569 case CURLPROXY_HTTP_1_0: 3570 pProxy->enmProxyType = RTHTTPPROXYTYPE_HTTP; 3571 break; 3574 /** @todo this does a bit too much (we don't need to set up SSL for instance). */ 3575 int rc = rtHttpApplySettings(pThis, pszUrl); 3576 if (RT_SUCCESS(rc)) 3577 { 3578 /* 3579 * Copy out the result. 3580 */ 3581 if (pThis->fNoProxy) 3582 pProxy->enmProxyType = RTHTTPPROXYTYPE_NOPROXY; 3583 else 3584 { 3585 switch (pThis->enmProxyType) 3586 { 3587 case CURLPROXY_HTTP: 3588 #ifdef CURL_AT_LEAST_VERSION 3589 # if CURL_AT_LEAST_VERSION(7,19,4) 3590 case CURLPROXY_HTTP_1_0: 3591 # endif 3592 #endif 3593 pProxy->enmProxyType = RTHTTPPROXYTYPE_HTTP; 3594 break; 3572 3595 #ifdef CURL_AT_LEAST_VERSION 3573 3596 # if CURL_AT_LEAST_VERSION(7,52,0) 3574 case CURLPROXY_HTTPS:3575 pProxy->enmProxyType = RTHTTPPROXYTYPE_HTTPS;3576 break;3597 case CURLPROXY_HTTPS: 3598 pProxy->enmProxyType = RTHTTPPROXYTYPE_HTTPS; 3599 break; 3577 3600 # endif 3578 3601 #endif 3579 case CURLPROXY_SOCKS4: 3580 case CURLPROXY_SOCKS4A: 3581 pProxy->enmProxyType = RTHTTPPROXYTYPE_SOCKS4; 3582 break; 3583 case CURLPROXY_SOCKS5: 3584 case CURLPROXY_SOCKS5_HOSTNAME: 3585 pProxy->enmProxyType = RTHTTPPROXYTYPE_SOCKS5; 3586 break; 3587 default: 3588 pProxy->enmProxyType = RTHTTPPROXYTYPE_UNKNOWN; 3589 break; 3590 } 3591 if (pThis->pszProxyHost == NULL) 3592 return VERR_INTERNAL_ERROR; 3593 pProxy->pszProxyHost = RTStrDup(pThis->pszProxyHost); 3594 pProxy->uProxyPort = pThis->uProxyPort; 3595 pProxy->pszProxyUsername = NULL; 3596 pProxy->pszProxyPassword = NULL; 3597 3598 return VINF_SUCCESS; 3602 case CURLPROXY_SOCKS4: 3603 case CURLPROXY_SOCKS4A: 3604 pProxy->enmProxyType = RTHTTPPROXYTYPE_SOCKS4; 3605 break; 3606 case CURLPROXY_SOCKS5: 3607 case CURLPROXY_SOCKS5_HOSTNAME: 3608 pProxy->enmProxyType = RTHTTPPROXYTYPE_SOCKS5; 3609 break; 3610 default: 3611 AssertFailed(); 3612 pProxy->enmProxyType = RTHTTPPROXYTYPE_UNKNOWN; 3613 break; 3614 } 3615 pProxy->uProxyPort = pThis->uProxyPort; 3616 if (pThis->pszProxyHost != NULL) 3617 { 3618 rc = RTStrDupEx(&pProxy->pszProxyHost, pThis->pszProxyHost); 3619 if (pThis->pszProxyUsername && RT_SUCCESS(rc)) 3620 rc = RTStrDupEx(&pProxy->pszProxyUsername, pThis->pszProxyUsername); 3621 if (pThis->pszProxyPassword && RT_SUCCESS(rc)) 3622 rc = RTStrDupEx(&pProxy->pszProxyPassword, pThis->pszProxyPassword); 3623 if (RT_FAILURE(rc)) 3624 RTHttpFreeProxyInfo(pProxy); 3625 } 3626 else 3627 { 3628 AssertFailed(); 3629 rc = VERR_INTERNAL_ERROR; 3630 } 3631 } 3632 } 3633 return rc; 3599 3634 } 3600 3635 … … 3607 3642 RTStrFree(pProxy->pszProxyUsername); 3608 3643 RTStrFree(pProxy->pszProxyPassword); 3644 pProxy->pszProxyHost = NULL; 3645 pProxy->pszProxyUsername = NULL; 3646 pProxy->pszProxyPassword = NULL; 3647 pProxy->enmProxyType = RTHTTPPROXYTYPE_INVALID; 3648 pProxy->uProxyPort = UINT32_MAX; 3609 3649 } 3610 3650 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.