Changeset 74431 in vbox for trunk/src/VBox
- Timestamp:
- Sep 24, 2018 9:16:17 AM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r74003 r74431 1058 1058 " defaultfrontend default|<name>\n" 1059 1059 " logginglevel <log setting>\n" 1060 " proxymode system|noproxy|manual\n" 1061 " proxyurl <url>\n" 1060 1062 "\n", SEP); 1061 1063 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r73716 r74431 623 623 { 624 624 ComPtr<ISystemProperties> systemProperties; 625 pVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());625 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()), hrcCheck); 626 626 627 627 Bstr str; … … 758 758 systemProperties->COMGETTER(LoggingLevel)(str.asOutParam()); 759 759 RTPrintf("Logging Level: %ls\n", str.raw()); 760 ProxyMode_T enmProxyMode = (ProxyMode_T)42; 761 systemProperties->COMGETTER(ProxyMode)(&enmProxyMode); 762 psz = "Unknown"; 763 switch (enmProxyMode) 764 { 765 case ProxyMode_System: psz = "System"; break; 766 case ProxyMode_NoProxy: psz = "NoProxy"; break; 767 case ProxyMode_Manual: psz = "Manual"; break; 768 } 769 RTPrintf("Proxy Mode: %s\n", psz); 770 systemProperties->COMGETTER(ProxyURL)(str.asOutParam()); 771 RTPrintf("Proxy URL: %ls\n", str.raw()); 760 772 return S_OK; 761 773 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r73740 r74431 1046 1046 bstrLoggingLevel.setNull(); 1047 1047 CHECK_ERROR(systemProperties, COMSETTER(LoggingLevel)(bstrLoggingLevel.raw())); 1048 } 1049 else if (!strcmp(a->argv[0], "proxymode")) 1050 { 1051 ProxyMode_T enmProxyMode; 1052 if (!RTStrICmpAscii(a->argv[1], "system")) 1053 enmProxyMode = ProxyMode_System; 1054 else if (!RTStrICmpAscii(a->argv[1], "noproxy")) 1055 enmProxyMode = ProxyMode_NoProxy; 1056 else if (!RTStrICmpAscii(a->argv[1], "manual")) 1057 enmProxyMode = ProxyMode_Manual; 1058 else 1059 return errorArgument("Unknown proxy mode: '%s'", a->argv[1]); 1060 CHECK_ERROR(systemProperties, COMSETTER(ProxyMode)(enmProxyMode)); 1061 } 1062 else if (!strcmp(a->argv[0], "proxyurl")) 1063 { 1064 Bstr bstrProxyUrl(a->argv[1]); 1065 CHECK_ERROR(systemProperties, COMSETTER(ProxyURL)(bstrProxyUrl.raw())); 1048 1066 } 1049 1067 else -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxUtils.h
r71630 r74431 62 62 63 63 64 /** Simple class,65 * containing functionality to (de)serialize proxy settings. */66 class UIProxyManager67 {68 public:69 70 /** Proxy states. */71 enum ProxyState72 {73 ProxyState_Disabled,74 ProxyState_Enabled,75 ProxyState_Auto76 };77 78 /** Constructs proxy-manager which parses @a strProxySettings. */79 UIProxyManager(const QString &strProxySettings = QString())80 : m_enmProxyState(ProxyState_Auto)81 , m_fAuthEnabled(false)82 {83 /* Parse proxy settings: */84 if (strProxySettings.isEmpty())85 return;86 QStringList proxySettings = strProxySettings.split(",");87 88 /* Parse proxy state, host and port: */89 if (proxySettings.size() > 0)90 m_enmProxyState = proxyStateFromString(proxySettings[0]);91 if (proxySettings.size() > 1)92 m_strProxyHost = proxySettings[1];93 if (proxySettings.size() > 2)94 m_strProxyPort = proxySettings[2];95 96 /* Parse whether proxy auth enabled and has login/password: */97 if (proxySettings.size() > 3)98 m_fAuthEnabled = proxySettings[3] == "authEnabled";99 if (proxySettings.size() > 4)100 m_strAuthLogin = proxySettings[4];101 if (proxySettings.size() > 5)102 m_strAuthPassword = proxySettings[5];103 }104 105 /** Serializes proxy settings. */106 QString toString() const107 {108 /* Serialize settings: */109 QString strResult;110 if (m_enmProxyState != ProxyState_Auto || !m_strProxyHost.isEmpty() || !m_strProxyPort.isEmpty() ||111 m_fAuthEnabled || !m_strAuthLogin.isEmpty() || !m_strAuthPassword.isEmpty())112 {113 QStringList proxySettings;114 proxySettings << proxyStateToString(m_enmProxyState);115 proxySettings << m_strProxyHost;116 proxySettings << m_strProxyPort;117 proxySettings << QString(m_fAuthEnabled ? "authEnabled" : "authDisabled");118 proxySettings << m_strAuthLogin;119 proxySettings << m_strAuthPassword;120 strResult = proxySettings.join(",");121 }122 return strResult;123 }124 125 /** Returns the proxy state. */126 ProxyState proxyState() const { return m_enmProxyState; }127 /** Returns the proxy host. */128 const QString &proxyHost() const { return m_strProxyHost; }129 /** Returns the proxy port. */130 const QString &proxyPort() const { return m_strProxyPort; }131 132 /** Returns whether the proxy auth is enabled. */133 bool authEnabled() const { return m_fAuthEnabled; }134 /** Returns the proxy auth login. */135 const QString &authLogin() const { return m_strAuthLogin; }136 /** Returns the proxy auth password. */137 const QString &authPassword() const { return m_strAuthPassword; }138 139 /** Defines the proxy @a enmState. */140 void setProxyState(ProxyState enmState) { m_enmProxyState = enmState; }141 /** Defines the proxy @a strHost. */142 void setProxyHost(const QString &strHost) { m_strProxyHost = strHost; }143 /** Defines the proxy @a strPort. */144 void setProxyPort(const QString &strPort) { m_strProxyPort = strPort; }145 146 /** Defines whether the proxy auth is @a fEnabled. */147 void setAuthEnabled(bool fEnabled) { m_fAuthEnabled = fEnabled; }148 /** Defines the proxy auth @a strLogin. */149 void setAuthLogin(const QString &strLogin) { m_strAuthLogin = strLogin; }150 /** Defines the proxy auth @a strPassword. */151 void setAuthPassword(const QString &strPassword) { m_strAuthPassword = strPassword; }152 153 private:154 155 /** Converts passed @a enmState to corresponding #QString. */156 static QString proxyStateToString(ProxyState enmState)157 {158 switch (enmState)159 {160 case ProxyState_Disabled: return QString("ProxyDisabled");161 case ProxyState_Enabled: return QString("ProxyEnabled");162 case ProxyState_Auto: break;163 }164 return QString("ProxyAuto");165 }166 167 /** Converts passed @a strState to corresponding #ProxyState. */168 static ProxyState proxyStateFromString(const QString &strState)169 {170 /* Compose the map of known states: */171 QMap<QString, ProxyState> states;172 states["ProxyDisabled"] = ProxyState_Disabled; // New since VBox 5.0173 states["proxyEnabled"] = ProxyState_Enabled; // Old since VBox 4.1174 states["ProxyEnabled"] = ProxyState_Enabled; // New since VBox 5.0175 /* Return one of registered or 'Auto' by default: */176 return states.value(strState, ProxyState_Auto);177 }178 179 /** Holds the proxy state. */180 ProxyState m_enmProxyState;181 /** Holds the proxy host. */182 QString m_strProxyHost;183 /** Holds the proxy port. */184 QString m_strProxyPort;185 186 /** Holds whether the proxy auth is enabled. */187 bool m_fAuthEnabled;188 /** Holds the proxy auth login. */189 QString m_strAuthLogin;190 /** Holds the proxy auth password. */191 QString m_strAuthPassword;192 };193 194 195 64 #endif /* !___VBoxUtils_h___ */ 196 65 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp
r71466 r74431 35 35 # include "VBoxGlobal.h" 36 36 # include "VBoxUtils.h" 37 # include "CSystemProperties.h" 37 38 # else /* VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS */ 38 39 # include <VBox/log.h> … … 384 385 385 386 #ifndef VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS 386 /* Get the proxy-manager: */387 UIProxyManager proxyManager(gEDataManager->proxySettings());388 389 387 /* If the specific proxy settings are enabled, we'll use them 390 388 * unless user disabled that functionality manually. */ 391 switch (proxyManager.proxyState()) 392 { 393 case UIProxyManager::ProxyState_Enabled: 394 return RTHttpSetProxy(m_hHttp, 395 proxyManager.proxyHost().toUtf8().constData(), 396 proxyManager.proxyPort().toUInt(), 397 NULL /* pszProxyUser */, NULL /* pszProxyPwd */); 398 case UIProxyManager::ProxyState_Disabled: 389 CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties(); 390 KProxyMode enmProxyMode = properties.GetProxyMode(); 391 AssertReturn(properties.isOk(), VERR_INTERNAL_ERROR_3); 392 switch (enmProxyMode) 393 { 394 case KProxyMode_Manual: 395 { 396 QString strProxyURL = properties.GetProxyURL(); 397 return RTHttpSetProxyByUrl(m_hHttp, strProxyURL.toUtf8().constData()); 398 } 399 case KProxyMode_NoProxy: 399 400 return VINF_SUCCESS; 400 401 default: -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsProxy.cpp
r72664 r74431 30 30 # include "UIMessageCenter.h" 31 31 # include "VBoxUtils.h" 32 # include "VBoxGlobal.h" 33 # include "CSystemProperties.h" 32 34 33 35 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 39 41 /** Constructs data. */ 40 42 UIDataSettingsGlobalProxy() 41 : m_enmProxy State(UIProxyManager::ProxyState_Auto)43 : m_enmProxyMode(KProxyMode_System) 42 44 , m_strProxyHost(QString()) 43 45 , m_strProxyPort(QString()) … … 48 50 { 49 51 return true 50 && (m_enmProxy State == other.m_enmProxyState)52 && (m_enmProxyMode == other.m_enmProxyMode) 51 53 && (m_strProxyHost == other.m_strProxyHost) 52 54 && (m_strProxyPort == other.m_strProxyPort) … … 59 61 bool operator!=(const UIDataSettingsGlobalProxy &other) const { return !equal(other); } 60 62 61 /** Holds the proxy state. */62 UIProxyManager::ProxyState m_enmProxyState;63 /** Holds the proxy mode. */ 64 KProxyMode m_enmProxyMode; 63 65 /** Holds the proxy host. */ 64 66 QString m_strProxyHost; … … 93 95 94 96 /* Gather old proxy data: */ 95 UIProxyManager proxyManager(gEDataManager->proxySettings()); 96 oldProxyData.m_enmProxyState = proxyManager.proxyState(); 97 oldProxyData.m_strProxyHost = proxyManager.proxyHost(); 98 oldProxyData.m_strProxyPort = proxyManager.proxyPort(); 97 CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties(); 98 if (properties.isNotNull()) 99 { 100 oldProxyData.m_enmProxyMode = properties.GetProxyMode(); 101 oldProxyData.m_strProxyHost = properties.GetProxyURL(); 102 oldProxyData.m_strProxyPort = ""; 103 if (!oldProxyData.m_strProxyHost.isEmpty()) 104 { 105 QUrl url(oldProxyData.m_strProxyHost); 106 if (url.port() != -1) 107 { 108 oldProxyData.m_strProxyPort = QString::number(url.port()); 109 url.setPort(-1); 110 oldProxyData.m_strProxyHost = url.url(); 111 } 112 } 113 } 99 114 100 115 /* Cache old proxy data: */ … … 111 126 112 127 /* Load old proxy data from the cache: */ 113 switch (oldProxyData.m_enmProxyState) 114 { 115 case UIProxyManager::ProxyState_Auto: m_pRadioProxyAuto->setChecked(true); break; 116 case UIProxyManager::ProxyState_Disabled: m_pRadioProxyDisabled->setChecked(true); break; 117 case UIProxyManager::ProxyState_Enabled: m_pRadioProxyEnabled->setChecked(true); break; 128 switch (oldProxyData.m_enmProxyMode) 129 { 130 case KProxyMode_System: m_pRadioProxyAuto->setChecked(true); break; 131 case KProxyMode_NoProxy: m_pRadioProxyDisabled->setChecked(true); break; 132 case KProxyMode_Manual: m_pRadioProxyEnabled->setChecked(true); break; 133 case KProxyMode_Max: break; /* (compiler warnings) */ 118 134 } 119 135 m_pHostEditor->setText(oldProxyData.m_strProxyHost); … … 131 147 132 148 /* Gather new proxy data: */ 133 newProxyData.m_enmProxyState = m_pRadioProxyEnabled->isChecked() ? UIProxyManager::ProxyState_Enabled : 134 m_pRadioProxyDisabled->isChecked() ? UIProxyManager::ProxyState_Disabled : 135 UIProxyManager::ProxyState_Auto; 149 newProxyData.m_enmProxyMode = m_pRadioProxyEnabled->isChecked() ? KProxyMode_Manual 150 : m_pRadioProxyDisabled->isChecked() ? KProxyMode_NoProxy : KProxyMode_System; 136 151 newProxyData.m_strProxyHost = m_pHostEditor->text(); 137 152 newProxyData.m_strProxyPort = m_pPortEditor->text(); … … 266 281 267 282 /* Save new proxy data from the cache: */ 268 UIProxyManager proxyManager; 269 proxyManager.setProxyState(newProxyData.m_enmProxyState); 270 proxyManager.setProxyHost(newProxyData.m_strProxyHost); 271 proxyManager.setProxyPort(newProxyData.m_strProxyPort); 272 gEDataManager->setProxySettings(proxyManager.toString()); 283 CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties(); 284 if (properties.isNull()) 285 fSuccess = false; 286 else 287 { 288 properties.SetProxyMode(newProxyData.m_enmProxyMode); 289 fSuccess &= properties.isOk(); 290 291 if (newProxyData.m_strProxyPort.isEmpty()) 292 properties.SetProxyURL(newProxyData.m_strProxyHost); 293 else 294 { 295 QUrl url(newProxyData.m_strProxyHost); 296 if (url.port() == -1) 297 url.setPort(newProxyData.m_strProxyPort.toUInt()); 298 properties.SetProxyURL(url.url()); 299 } 300 fSuccess &= properties.isOk(); 301 302 /* Drop the old extra data setting if still around: */ 303 if (fSuccess && !gEDataManager->proxySettings().isEmpty()) 304 gEDataManager->setProxySettings(QString()); 305 } 273 306 } 274 307 /* Return result: */ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r74186 r74431 9912 9912 --> 9913 9913 9914 <enum name="ProxyMode" uuid="885264b3-b517-40fc-ce46-36e3bae895a4"> 9915 <desc> Proxy setting: System (default), NoProxy and Manual. <link to="ISystemProperties::proxyMode"/></desc> 9916 <const name="System" value="0"> 9917 <desc>Use the system proxy settings as far as possible.</desc> 9918 </const> 9919 <const name="NoProxy" value="1"> 9920 <desc>Direct connection to the Internet.</desc> 9921 </const> 9922 <const name="Manual" value="2"> 9923 <desc>Use the manual proxy from <link to="ISystemProperties::proxyURL"/>.</desc> 9924 </const> 9925 </enum> 9926 9914 9927 <interface 9915 9928 name="ISystemProperties" 9916 9929 extends="$unknown" 9917 uuid=" 0eb668d2-495e-5a36-8890-29999b5f030c"9930 uuid="d55176e5-6730-4e9e-fc1f-a59b1f44f78f" 9918 9931 wsmap="managed" 9919 9932 reservedMethods="4" reservedAttributes="16" … … 10226 10239 Supported bitmap formats which can be used with takeScreenShot 10227 10240 and takeScreenShotToArray methods. 10241 </desc> 10242 </attribute> 10243 10244 <attribute name="proxyMode" type="ProxyMode" readonly="no"> 10245 <desc> The proxy mode setting: System, NoProxy or Manual.</desc> 10246 </attribute> 10247 <attribute name="proxyURL" type="wstring" readonly="no"> 10248 <desc> 10249 Proxy server URL for the <link to="ProxyMode::Manual" /> proxy mode. 10250 10251 The format is: [{type}"://"][{userid}[@{password}]:]{server}[":"{port}] 10252 10253 Valid types are: http (default), https, socks4, socks4a, socks5, socks5h and direct. 10254 Please note that these are proxy types defining how the proxy operates rather than 10255 how to proxy any similarly named protocol (i.e. don't confuse a http-proxy with 10256 proxying the http protocol, as a http-proxy usually can proxy https and other protocols too). 10257 10258 The port number defaults to 80 for http, 443 for https and 1080 for the socks ones. 10259 10260 <note>The password is currently stored as plain text! Use the <link to="ProxyMode::System" /> 10261 mode if you consider the proxy password to be sensitive.</note> 10262 10263 An empty string will cause the behavior to be identical to <link to="ProxyMode::System" />. 10264 For compatibility with libproxy, an URL starting with "direct://" will cause 10265 <link to="ProxyMode::NoProxy" /> behavior. 10228 10266 </desc> 10229 10267 </attribute> -
trunk/src/VBox/Main/include/SystemPropertiesImpl.h
r69500 r74431 106 106 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend); 107 107 HRESULT getScreenShotFormats(std::vector<BitmapFormat_T> &aScreenShotFormats); 108 HRESULT getProxyMode(ProxyMode_T *pProxyMode); 109 HRESULT setProxyMode(ProxyMode_T aProxyMode); 110 HRESULT getProxyURL(com::Utf8Str &aProxyURL); 111 HRESULT setProxyURL(const com::Utf8Str &aProxyURL); 108 112 109 113 // wrapped ISystemProperties methods -
trunk/src/VBox/Main/src-server/SystemPropertiesImpl.cpp
r73003 r74431 34 34 #include <iprt/path.h> 35 35 #include <iprt/string.h> 36 #include <iprt/uri.h> 36 37 #include <iprt/cpp/utils.h> 37 38 … … 97 98 i_setDefaultVRDEExtPack(Utf8Str::Empty); 98 99 99 m->u lLogHistoryCount = 3;100 m->uLogHistoryCount = 3; 100 101 101 102 … … 873 874 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 874 875 875 *count = m->u lLogHistoryCount;876 *count = m->uLogHistoryCount; 876 877 877 878 return S_OK; … … 882 883 { 883 884 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 884 m->u lLogHistoryCount = count;885 m->uLogHistoryCount = count; 885 886 alock.release(); 886 887 … … 986 987 } 987 988 989 HRESULT SystemProperties::getProxyMode(ProxyMode_T *pProxyMode) 990 { 991 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 992 ProxyMode_T enmMode = *pProxyMode = (ProxyMode_T)m->uProxyMode; 993 AssertMsgReturn(enmMode == ProxyMode_System || enmMode == ProxyMode_NoProxy || enmMode == ProxyMode_Manual, 994 ("enmMode=%d\n", enmMode), E_UNEXPECTED); 995 return S_OK; 996 } 997 998 HRESULT SystemProperties::setProxyMode(ProxyMode_T aProxyMode) 999 { 1000 /* Validate input. */ 1001 switch (aProxyMode) 1002 { 1003 case ProxyMode_System: 1004 case ProxyMode_NoProxy: 1005 case ProxyMode_Manual: 1006 break; 1007 default: 1008 return setError(E_INVALIDARG, tr("Invalid ProxyMode value: %d"), (int)aProxyMode); 1009 } 1010 1011 /* Set and write out settings. */ 1012 { 1013 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1014 m->uProxyMode = aProxyMode; 1015 } 1016 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */ 1017 return mParent->i_saveSettings(); 1018 } 1019 1020 HRESULT SystemProperties::getProxyURL(com::Utf8Str &aProxyURL) 1021 { 1022 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1023 aProxyURL = m->strProxyUrl; 1024 return S_OK; 1025 } 1026 1027 HRESULT SystemProperties::setProxyURL(const com::Utf8Str &aProxyURL) 1028 { 1029 /* 1030 * Validate input. 1031 */ 1032 Utf8Str const *pStrProxyUrl = &aProxyURL; 1033 Utf8Str strTmp; 1034 if (pStrProxyUrl->isNotEmpty()) 1035 { 1036 /* RTUriParse requires a scheme, so append 'http://' if none seems present: */ 1037 if (pStrProxyUrl->find("://") == RTCString::npos) 1038 { 1039 strTmp.printf("http://%s", aProxyURL.c_str()); 1040 pStrProxyUrl = &strTmp; 1041 } 1042 1043 /* Use RTUriParse to check the format. There must be a hostname, but nothing 1044 can follow it and the port. */ 1045 RTURIPARSED Parsed; 1046 int vrc = RTUriParse(pStrProxyUrl->c_str(), &Parsed); 1047 if (RT_FAILURE(vrc)) 1048 return setErrorBoth(E_INVALIDARG, vrc, tr("Failed to parse proxy URL: %Rrc"), vrc); 1049 if ( Parsed.cchAuthorityHost == 0 1050 && !RTUriIsSchemeMatch(pStrProxyUrl->c_str(), "direct")) 1051 return setError(E_INVALIDARG, tr("Proxy URL must include a hostname")); 1052 if (Parsed.cchPath > 0) 1053 return setError(E_INVALIDARG, tr("Proxy URL must not include a path component (%.*s)"), 1054 Parsed.cchPath, pStrProxyUrl->c_str() + Parsed.offPath); 1055 if (Parsed.cchQuery > 0) 1056 return setError(E_INVALIDARG, tr("Proxy URL must not include a query component (?%.*s)"), 1057 Parsed.cchQuery, pStrProxyUrl->c_str() + Parsed.offQuery); 1058 if (Parsed.cchFragment > 0) 1059 return setError(E_INVALIDARG, tr("Proxy URL must not include a fragment component (#%.*s)"), 1060 Parsed.cchFragment, pStrProxyUrl->c_str() + Parsed.offFragment); 1061 } 1062 1063 /* 1064 * Set and write out settings. 1065 */ 1066 { 1067 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1068 m->strProxyUrl = *pStrProxyUrl; 1069 } 1070 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */ 1071 return mParent->i_saveSettings(); 1072 } 1073 988 1074 // public methods only for internal purposes 989 1075 ///////////////////////////////////////////////////////////////////////////// … … 1014 1100 if (FAILED(rc)) return rc; 1015 1101 1016 m->u lLogHistoryCount = data.ulLogHistoryCount;1102 m->uLogHistoryCount = data.uLogHistoryCount; 1017 1103 m->fExclusiveHwVirt = data.fExclusiveHwVirt; 1104 m->uProxyMode = data.uProxyMode; 1105 m->strProxyUrl = data.strProxyUrl; 1018 1106 1019 1107 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath); … … 1356 1444 return S_OK; 1357 1445 } 1446 -
trunk/src/VBox/Main/xml/Settings.cpp
r73768 r74431 79 79 #include <iprt/ldr.h> 80 80 #include <iprt/base64.h> 81 #include <iprt/uri.h> 81 82 #include <iprt/cpp/lock.h> 82 83 … … 1579 1580 * Constructor. Needs to set sane defaults which stand the test of time. 1580 1581 */ 1581 SystemProperties::SystemProperties() : 1582 ulLogHistoryCount(3), 1583 fExclusiveHwVirt(true) 1582 SystemProperties::SystemProperties() 1583 : uLogHistoryCount(3) 1584 , uProxyMode(ProxyMode_System) 1585 , fExclusiveHwVirt(true) 1584 1586 { 1585 1587 #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) … … 1867 1869 1868 1870 /** 1871 * Converts old style Proxy settings from ExtraData/UI section. 1872 * 1873 * Saves proxy settings directly to systemProperties structure. 1874 * 1875 * @returns true if conversion was successfull, false if not. 1876 * @param strUIProxySettings The GUI settings string to convert. 1877 */ 1878 bool MainConfigFile::convertGuiProxySettings(const com::Utf8Str &strUIProxySettings) 1879 { 1880 /* 1881 * Possible variants: 1882 * - "ProxyAuto,proxyserver.url,1080,authDisabled,," 1883 * - "ProxyDisabled,proxyserver.url,1080,authDisabled,," 1884 * - "ProxyEnabled,proxyserver.url,1080,authDisabled,," 1885 * 1886 * Note! We only need to bother with the first three fields as the last 1887 * three was never really used or ever actually passed to the HTTP 1888 * client code. 1889 */ 1890 /* First field: The proxy mode. */ 1891 const char *psz = RTStrStripL(strUIProxySettings.c_str()); 1892 static const struct { const char *psz; size_t cch; ProxyMode_T enmMode; } s_aModes[] = 1893 { 1894 { RT_STR_TUPLE("ProxyAuto"), ProxyMode_System }, 1895 { RT_STR_TUPLE("ProxyDisabled"), ProxyMode_NoProxy }, 1896 { RT_STR_TUPLE("ProxyEnabled"), ProxyMode_Manual }, 1897 }; 1898 for (size_t i = 0; i < RT_ELEMENTS(s_aModes); i++) 1899 if (RTStrNICmpAscii(psz, s_aModes[i].psz, s_aModes[i].cch) == 0) 1900 { 1901 systemProperties.uProxyMode = s_aModes[i].enmMode; 1902 psz = RTStrStripL(psz + s_aModes[i].cch); 1903 if (*psz == ',') 1904 { 1905 /* Second field: The proxy host, possibly fully fledged proxy URL. */ 1906 psz = RTStrStripL(psz + 1); 1907 if (*psz != '\0' && *psz != ',') 1908 { 1909 const char *pszEnd = strchr(psz, ','); 1910 size_t cchHost = pszEnd ? pszEnd - psz : strlen(psz); 1911 while (cchHost > 0 && RT_C_IS_SPACE(psz[cchHost - 1])) 1912 cchHost--; 1913 systemProperties.strProxyUrl.assign(psz, cchHost); 1914 if (systemProperties.strProxyUrl.find("://") == RTCString::npos) 1915 systemProperties.strProxyUrl.replace(0, 0, "http://"); 1916 1917 /* Third field: The proxy port. Defaulted to 1080 for all proxies. 1918 The new settings has type specific default ports. */ 1919 uint16_t uPort = 1080; 1920 if (pszEnd) 1921 { 1922 int rc = RTStrToUInt16Ex(RTStrStripL(pszEnd + 1), NULL, 10, &uPort); 1923 if (RT_FAILURE(rc)) 1924 uPort = 1080; 1925 } 1926 RTURIPARSED Parsed; 1927 int rc = RTUriParse(systemProperties.strProxyUrl.c_str(), &Parsed); 1928 if (RT_SUCCESS(rc)) 1929 { 1930 if (Parsed.uAuthorityPort == UINT32_MAX) 1931 systemProperties.strProxyUrl.appendPrintf(systemProperties.strProxyUrl.endsWith(":") 1932 ? "%u" : ":%u", uPort); 1933 } 1934 else 1935 { 1936 LogRelFunc(("Dropping invalid proxy URL for %u: %s\n", 1937 systemProperties.uProxyMode, systemProperties.strProxyUrl.c_str())); 1938 systemProperties.strProxyUrl.setNull(); 1939 } 1940 } 1941 /* else: don't bother with the rest if we haven't got a host. */ 1942 } 1943 if ( systemProperties.strProxyUrl.isEmpty() 1944 && systemProperties.uProxyMode == ProxyMode_Manual) 1945 { 1946 systemProperties.uProxyMode = ProxyMode_System; 1947 return false; 1948 } 1949 return true; 1950 } 1951 LogRelFunc(("Unknown proxy type: %s\n", psz)); 1952 return false; 1953 } 1954 1955 /** 1869 1956 * Constructor. 1870 1957 * … … 1888 1975 xml::NodesLoop nlRootChildren(*m->pelmRoot); 1889 1976 const xml::ElementNode *pelmRootChild; 1977 bool fCopyProxySettingsFromExtraData = false; 1890 1978 while ((pelmRootChild = nlRootChildren.forAllNodes())) 1891 1979 { … … 1906 1994 pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary); 1907 1995 pelmGlobalChild->getAttributeValue("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack); 1908 pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.u lLogHistoryCount);1996 pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.uLogHistoryCount); 1909 1997 pelmGlobalChild->getAttributeValue("autostartDatabasePath", systemProperties.strAutostartDatabasePath); 1910 1998 pelmGlobalChild->getAttributeValue("defaultFrontend", systemProperties.strDefaultFrontend); 1911 1999 pelmGlobalChild->getAttributeValue("exclusiveHwVirt", systemProperties.fExclusiveHwVirt); 2000 if (!pelmGlobalChild->getAttributeValue("proxyMode", systemProperties.uProxyMode)) 2001 fCopyProxySettingsFromExtraData = true; 2002 pelmGlobalChild->getAttributeValue("proxyUrl", systemProperties.strProxyUrl); 1912 2003 } 1913 2004 else if (pelmGlobalChild->nameEquals("ExtraData")) … … 1941 2032 } 1942 2033 2034 if (fCopyProxySettingsFromExtraData) 2035 for (StringsMap::const_iterator it = mapExtraDataItems.begin(); it != mapExtraDataItems.end(); ++it) 2036 if (it->first.equals("GUI/ProxySettings")) 2037 { 2038 convertGuiProxySettings(it->second); 2039 break; 2040 } 2041 1943 2042 clearDocument(); 1944 2043 } … … 2141 2240 if (systemProperties.strDefaultVRDEExtPack.length()) 2142 2241 pelmSysProps->setAttribute("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack); 2143 pelmSysProps->setAttribute("LogHistoryCount", systemProperties.u lLogHistoryCount);2242 pelmSysProps->setAttribute("LogHistoryCount", systemProperties.uLogHistoryCount); 2144 2243 if (systemProperties.strAutostartDatabasePath.length()) 2145 2244 pelmSysProps->setAttribute("autostartDatabasePath", systemProperties.strAutostartDatabasePath); 2146 2245 if (systemProperties.strDefaultFrontend.length()) 2147 2246 pelmSysProps->setAttribute("defaultFrontend", systemProperties.strDefaultFrontend); 2247 if (systemProperties.strProxyUrl.length()) 2248 pelmSysProps->setAttribute("proxyUrl", systemProperties.strProxyUrl); 2249 pelmSysProps->setAttribute("proxyMode", systemProperties.uProxyMode); 2148 2250 pelmSysProps->setAttribute("exclusiveHwVirt", systemProperties.fExclusiveHwVirt); 2149 2251
Note:
See TracChangeset
for help on using the changeset viewer.