Changeset 85139 in vbox
- Timestamp:
- Jul 9, 2020 7:49:52 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/http.h
r85121 r85139 662 662 663 663 664 /** 665 * Supported proxy types. 666 */ 667 typedef enum { 668 RTHTTPPROXYTYPE_UNKNOWN, 669 RTHTTPPROXYTYPE_HTTP, 670 RTHTTPPROXYTYPE_HTTPS, 671 RTHTTPPROXYTYPE_SOCKS4, 672 RTHTTPPROXYTYPE_SOCKS5 673 } RTHTTPPROXYTYPE; 674 675 /** 676 * Proxy information structure. 677 */ 678 typedef struct { 679 /** Proxy host name (RTStrFree). */ 680 char *pszProxyHost; 681 /** Proxy port number (UINT32_MAX if not specified). */ 682 uint32_t uProxyPort; 683 /** The proxy type (RTHTTPPROXYTYPE_HTTP, RTHTTPPROXYTYPE_SOCKS5, ++). */ 684 RTHTTPPROXYTYPE enmProxyType; 685 /** Proxy username (RTStrFree). */ 686 char *pszProxyUsername; 687 /** Proxy password (RTStrFree). */ 688 char *pszProxyPassword; 689 } RTHTTPPROXYINFO; 690 /** A pointer to proxy information structure. */ 691 typedef RTHTTPPROXYINFO *PRTHTTPPROXYINFO; 692 693 /** 694 * Retrieve system proxy information for the specified URL. 695 * 696 * @returns IPRT status code. 697 * @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. 712 */ 713 RTR3DECL(int) RTHttpFreeProxyInfo(PRTHTTPPROXYINFO pProxyInfo); 714 664 715 /** @name thin wrappers for setting one or a few related curl options 665 716 * @remarks Temporary. Will not be included in the 7.0 release! -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloud.cpp
r84692 r85139 31 31 #include <iprt/uuid.h> 32 32 #include <iprt/file.h> 33 #include <iprt/http.h> 33 34 #include <VBox/log.h> 34 35 … … 2107 2108 } 2108 2109 2110 static bool getSystemProxyForUrl(const com::Utf8Str &strUrl, Bstr &strProxy) 2111 { 2112 RTHTTP hHttp; 2113 int rc = RTHttpCreate(&hHttp); 2114 if (RT_FAILURE(rc)) 2115 { 2116 LogRel(("OCI-NET: Failed to create HTTP context (rc=%d)\n", rc)); 2117 return false; 2118 } 2119 rc = RTHttpUseSystemProxySettings(hHttp); 2120 if (RT_FAILURE(rc)) 2121 { 2122 LogRel(("OCI-NET: Failed to use system proxy (rc=%d)\n", rc)); 2123 RTHttpDestroy(hHttp); 2124 return false; 2125 } 2126 2127 RTHTTPPROXYINFO proxy; 2128 RT_ZERO(proxy); 2129 rc = RTHttpGetProxyInfoForUrl(hHttp, strUrl.c_str(), &proxy); 2130 if (RT_FAILURE(rc)) 2131 { 2132 LogRel(("OCI-NET: Failed to get proxy for %s (rc=%d)\n", strUrl.c_str(), rc)); 2133 RTHttpDestroy(hHttp); 2134 return false; 2135 } 2136 const char *pcszProxyScheme = ""; 2137 switch (proxy.enmProxyType) 2138 { 2139 case RTHTTPPROXYTYPE_HTTP: 2140 pcszProxyScheme = "http://"; 2141 break; 2142 case RTHTTPPROXYTYPE_HTTPS: 2143 pcszProxyScheme = "https://"; 2144 break; 2145 case RTHTTPPROXYTYPE_SOCKS4: 2146 pcszProxyScheme = "socks4://"; 2147 break; 2148 case RTHTTPPROXYTYPE_SOCKS5: 2149 pcszProxyScheme = "socks://"; 2150 break; 2151 case RTHTTPPROXYTYPE_UNKNOWN: 2152 LogRel(("OCI-NET: Unknown proxy type. Using direct connecton.")); 2153 RTHttpDestroy(hHttp); 2154 return false; 2155 } 2156 strProxy = BstrFmt("%s%s:%d", pcszProxyScheme, proxy.pszProxyHost, proxy.uProxyPort); 2157 RTHttpFreeProxyInfo(&proxy); 2158 RTHttpDestroy(hHttp); 2159 return true; 2160 } 2161 2109 2162 static HRESULT createLocalGatewayImage(ComPtr<IVirtualBox> virtualBox, const Bstr& aGatewayIso, const Bstr& aGuestAdditionsIso, const Bstr& aProxy) 2110 2163 { … … 2125 2178 2126 2179 ComPtr<ISystemProperties> systemProperties; 2180 ProxyMode_T enmProxyMode; 2181 Bstr strProxy; 2127 2182 ComPtr<IMedium> hd; 2128 2183 Bstr defaultMachineFolder; … … 2131 2186 if (errorOccured(hrc, "Failed to obtain system properties.")) 2132 2187 return hrc; 2188 if (aProxy.isNotEmpty()) 2189 strProxy = aProxy; 2190 else 2191 { 2192 hrc = systemProperties->COMGETTER(ProxyMode)(&enmProxyMode); 2193 if (errorOccured(hrc, "Failed to obtain proxy mode.")) 2194 return hrc; 2195 switch (enmProxyMode) 2196 { 2197 case ProxyMode_NoProxy: 2198 strProxy.setNull(); 2199 break; 2200 case ProxyMode_Manual: 2201 hrc = systemProperties->COMGETTER(ProxyURL)(strProxy.asOutParam()); 2202 if (errorOccured(hrc, "Failed to obtain proxy URL.")) 2203 return hrc; 2204 break; 2205 case ProxyMode_System: 2206 if (!getSystemProxyForUrl("https://dl.fedoraproject.org", strProxy)) 2207 errorOccured(E_FAIL, "Failed to get system proxy for https://dl.fedoraproject.org. Will use direct connection."); 2208 break; 2209 default: /* To get rid of ProxyMode_32BitHack 'warning' */ 2210 RTAssertPanic(); 2211 break; 2212 } 2213 2214 } 2133 2215 hrc = systemProperties->COMGETTER(DefaultMachineFolder)(defaultMachineFolder.asOutParam()); 2134 2216 if (errorOccured(hrc, "Failed to obtain default machine folder.")) … … 2283 2365 return hrc; 2284 2366 2285 if ( aProxy.isNotEmpty())2286 { 2287 hrc = unattended->COMSETTER(Proxy)( aProxy.raw());2367 if (strProxy.isNotEmpty()) 2368 { 2369 hrc = unattended->COMSETTER(Proxy)(strProxy.raw()); 2288 2370 if (errorOccured(hrc, "Failed to set post install script template for the unattended installer.")) 2289 2371 return hrc; 2290 2372 } 2373 2291 2374 hrc = unattended->Prepare(); 2292 2375 if (errorOccured(hrc, "Failed to prepare unattended installation.")) -
trunk/src/VBox/Runtime/generic/http-curl.cpp
r85121 r85139 3547 3547 3548 3548 3549 RTR3DECL(int) RTHttpGetProxyInfoForUrl(RTHTTP hHttp, const char *pcszUrl, PRTHTTPPROXYINFO pProxy) 3550 { 3551 PRTHTTPINTERNAL pThis = hHttp; 3552 rtHttpResetState(pThis); 3553 int rc = rtHttpApplySettings(pThis, pcszUrl); 3554 if (RT_FAILURE(rc)) 3555 return rc; 3556 3557 switch (pThis->enmProxyType) 3558 { 3559 case CURLPROXY_HTTP: 3560 case CURLPROXY_HTTP_1_0: 3561 pProxy->enmProxyType = RTHTTPPROXYTYPE_HTTP; 3562 break; 3563 case CURLPROXY_HTTPS: 3564 pProxy->enmProxyType = RTHTTPPROXYTYPE_HTTPS; 3565 break; 3566 case CURLPROXY_SOCKS4: 3567 case CURLPROXY_SOCKS4A: 3568 pProxy->enmProxyType = RTHTTPPROXYTYPE_SOCKS4; 3569 break; 3570 case CURLPROXY_SOCKS5: 3571 case CURLPROXY_SOCKS5_HOSTNAME: 3572 pProxy->enmProxyType = RTHTTPPROXYTYPE_SOCKS5; 3573 break; 3574 default: 3575 pProxy->enmProxyType = RTHTTPPROXYTYPE_UNKNOWN; 3576 break; 3577 } 3578 if (pThis->pszProxyHost == NULL) 3579 return VERR_INTERNAL_ERROR; 3580 pProxy->pszProxyHost = RTStrDup(pThis->pszProxyHost); 3581 pProxy->uProxyPort = pThis->uProxyPort; 3582 pProxy->pszProxyUsername = NULL; 3583 pProxy->pszProxyPassword = NULL; 3584 3585 return VINF_SUCCESS; 3586 } 3587 3588 3589 RTR3DECL(int) RTHttpFreeProxyInfo(PRTHTTPPROXYINFO pProxy) 3590 { 3591 if (pProxy) 3592 { 3593 RTStrFree(pProxy->pszProxyHost); 3594 RTStrFree(pProxy->pszProxyUsername); 3595 RTStrFree(pProxy->pszProxyPassword); 3596 } 3597 return VINF_SUCCESS; 3598 } 3599 3600 3549 3601 RTR3DECL(int) RTHttpPerform(RTHTTP hHttp, const char *pszUrl, RTHTTPMETHOD enmMethod, void const *pvReqBody, size_t cbReqBody, 3550 3602 uint32_t *puHttpStatus, void **ppvHeaders, size_t *pcbHeaders, void **ppvBody, size_t *pcbBody)
Note:
See TracChangeset
for help on using the changeset viewer.