Changeset 94756 in vbox for trunk/src/VBox/Main/src-server/UpdateAgentImpl.cpp
- Timestamp:
- Apr 29, 2022 8:55:44 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/UpdateAgentImpl.cpp
r94737 r94756 43 43 #include "VirtualBoxImpl.h" 44 44 #include "VBoxEvents.h" 45 #include "SystemPropertiesImpl.h" 45 46 #include "ThreadTask.h" 46 47 #include "VirtualBoxImpl.h" … … 265 266 } 266 267 268 /** 269 * Returns the proxy mode as a string. 270 * 271 * @returns Proxy mode as string. 272 * @param enmMode Proxy mode to return as string. 273 */ 274 /* static */ 275 const char *UpdateAgentBase::i_proxyModeToStr(ProxyMode_T enmMode) 276 { 277 switch (enmMode) 278 { 279 case ProxyMode_System: return "System"; 280 case ProxyMode_Manual: return "Manual"; 281 case ProxyMode_NoProxy: return "None"; 282 default: break; 283 } 284 285 AssertFailed(); 286 return "<Invalid>"; 287 } 288 267 289 268 290 /********************************************************************************************************************************* … … 296 318 HRESULT hr = unconst(m_EventSource).createObject(); 297 319 if (SUCCEEDED(hr)) 320 { 298 321 hr = m_EventSource->init(); 322 if (SUCCEEDED(hr)) 323 mData.m_fUseOwnProxy = false; 324 } 299 325 300 326 return hr; … … 522 548 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 523 549 524 *aMode = m->enmProxyMode; 525 526 return S_OK; 550 return i_getProxyMode(aMode); 527 551 } 528 552 … … 532 556 533 557 m->enmProxyMode = aMode; 558 mData.m_fUseOwnProxy = true; 534 559 535 560 return i_commitSettings(alock); … … 540 565 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 541 566 542 aAddress = m->strProxyUrl; 543 544 return S_OK; 567 return i_getProxyURL(aAddress); 545 568 } 546 569 … … 550 573 551 574 m->strProxyUrl = aAddress; 575 mData.m_fUseOwnProxy = true; 552 576 553 577 return i_commitSettings(alock); … … 677 701 data = *m; 678 702 703 /* Cancel out eventually set proxy settings if those were not explicitly set. 704 * This way the ISystemProperties proxy settings will be used then. */ 705 if (!mData.m_fUseOwnProxy) 706 { 707 data.strProxyUrl = ""; 708 data.enmProxyMode = ProxyMode_System; 709 } 710 679 711 return S_OK; 680 712 } … … 731 763 AutoWriteLock vboxLock(m_VirtualBox COMMA_LOCKVAL_SRC_POS); 732 764 return m_VirtualBox->i_saveSettings(); 765 } 766 767 /** 768 * Returns the proxy mode to use. 769 * 770 * @returns HRESULT 771 * @param aMode Where to return the proxy mode. 772 */ 773 HRESULT UpdateAgent::i_getProxyMode(ProxyMode_T *aMode) 774 { 775 HRESULT hrc; 776 777 if (!mData.m_fUseOwnProxy) /* If not explicitly set, use the ISystemProperties proxy settings. */ 778 { 779 ComPtr<ISystemProperties> pSystemProperties; 780 hrc = m_VirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam()); 781 if (SUCCEEDED(hrc)) 782 hrc = pSystemProperties->COMGETTER(ProxyMode)(aMode); 783 } 784 else 785 { 786 *aMode = m->enmProxyMode; 787 hrc = S_OK; 788 } 789 790 return hrc; 791 } 792 793 /** 794 * Returns the proxy URL to use. 795 * 796 * @returns HRESULT 797 * @param aUrl Where to return the proxy URL to use. 798 */ 799 HRESULT UpdateAgent::i_getProxyURL(com::Utf8Str &aUrl) 800 { 801 HRESULT hrc; 802 803 if (!mData.m_fUseOwnProxy) /* If not explicitly set, use the ISystemProperties proxy settings. */ 804 { 805 ComPtr<ISystemProperties> pSystemProperties; 806 hrc = m_VirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam()); 807 if (SUCCEEDED(hrc)) 808 { 809 com::Bstr bstrVal; 810 hrc = pSystemProperties->COMGETTER(ProxyURL)(bstrVal.asOutParam()); 811 if (SUCCEEDED(hrc)) 812 aUrl = bstrVal; 813 } 814 } 815 else 816 { 817 aUrl = m->strProxyUrl; 818 hrc = S_OK; 819 } 820 821 return hrc; 822 } 823 824 /** 825 * Configures a HTTP client's proxy. 826 * 827 * @returns HRESULT 828 * @param hHttp HTTP client to configure proxy for. 829 */ 830 HRESULT UpdateAgent::i_configureProxy(RTHTTP hHttp) 831 { 832 HRESULT rc; 833 834 ProxyMode_T enmProxyMode; 835 rc = i_getProxyMode(&enmProxyMode); 836 ComAssertComRCRetRC(rc); 837 Utf8Str strProxyUrl; 838 rc = i_getProxyURL(strProxyUrl); 839 ComAssertComRCRetRC(rc); 840 841 if (enmProxyMode == ProxyMode_Manual) 842 { 843 int vrc = RTHttpSetProxyByUrl(hHttp, strProxyUrl.c_str()); 844 if (RT_FAILURE(vrc)) 845 return i_reportError(vrc, tr("RTHttpSetProxyByUrl() failed: %Rrc"), vrc); 846 } 847 else if (enmProxyMode == ProxyMode_System) 848 { 849 int vrc = RTHttpUseSystemProxySettings(hHttp); 850 if (RT_FAILURE(vrc)) 851 return i_reportError(vrc, tr("RTHttpUseSystemProxySettings() failed: %Rrc"), vrc); 852 } 853 else 854 Assert(enmProxyMode == ProxyMode_NoProxy); 855 856 LogRel2(("Update agent (%s): Using proxy mode = '%s', URL = '%s'\n", 857 mData.m_strName.c_str(), UpdateAgentBase::i_proxyModeToStr(enmProxyMode), strProxyUrl.c_str())); 858 859 return S_OK; 733 860 } 734 861 … … 978 1105 HRESULT HostUpdateAgent::i_checkForUpdateInner(RTHTTP hHttp, Utf8Str const &strUrl, Utf8Str const &strUserAgent) 979 1106 { 1107 /* 1108 * Configure the proxy (if any). 1109 */ 1110 HRESULT rc = i_configureProxy(hHttp); 1111 if (FAILED(rc)) 1112 return rc; 1113 980 1114 /** @todo Are there any other headers needed to be added first via RTHttpSetHeaders()? */ 981 1115 int vrc = RTHttpAddHeader(hHttp, "User-Agent", strUserAgent.c_str(), strUserAgent.length(), RTHTTPADDHDR_F_BACK); 982 1116 if (RT_FAILURE(vrc)) 983 1117 return i_reportError(vrc, tr("RTHttpAddHeader() failed: %Rrc (user agent)"), vrc); 984 985 /*986 * Configure proxying.987 */988 if (m->enmProxyMode == ProxyMode_Manual)989 {990 vrc = RTHttpSetProxyByUrl(hHttp, m->strProxyUrl.c_str());991 if (RT_FAILURE(vrc))992 return i_reportError(vrc, tr("RTHttpSetProxyByUrl() failed: %Rrc"), vrc);993 }994 else if (m->enmProxyMode == ProxyMode_System)995 {996 vrc = RTHttpUseSystemProxySettings(hHttp);997 if (RT_FAILURE(vrc))998 return i_reportError(vrc, tr("RTHttpUseSystemProxySettings() failed: %Rrc"), vrc);999 }1000 else1001 Assert(m->enmProxyMode == ProxyMode_NoProxy);1002 1118 1003 1119 /* … … 1035 1151 size_t const cchWord1 = (size_t)(pchResponse - pchWord1); 1036 1152 1037 HRESULT rc;1038 1039 1153 /* Decode the two word: */ 1040 1154 static char const s_szUpToDate[] = "UPTODATE";
Note:
See TracChangeset
for help on using the changeset viewer.