VirtualBox

Changeset 74431 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 24, 2018 9:16:17 AM (6 years ago)
Author:
vboxsync
Message:

Main,GUI,VBoxManage: Provide API for proxy settings that picks up the current GUI settings and converts it to SystemProperties XML attributes. Adjusted GUI to use it. Updated VBoxMangage system properties handling accordingly. bugref:9249

Location:
trunk/src/VBox
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r74003 r74431  
    10581058                     "                            defaultfrontend default|<name>\n"
    10591059                     "                            logginglevel <log setting>\n"
     1060                     "                            proxymode system|noproxy|manual\n"
     1061                     "                            proxyurl <url>\n"
    10601062                     "\n", SEP);
    10611063
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp

    r73716 r74431  
    623623{
    624624    ComPtr<ISystemProperties> systemProperties;
    625     pVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
     625    CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()), hrcCheck);
    626626
    627627    Bstr str;
     
    758758    systemProperties->COMGETTER(LoggingLevel)(str.asOutParam());
    759759    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());
    760772    return S_OK;
    761773}
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r73740 r74431  
    10461046            bstrLoggingLevel.setNull();
    10471047        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()));
    10481066    }
    10491067    else
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxUtils.h

    r71630 r74431  
    6262
    6363
    64 /** Simple class,
    65   * containing functionality to (de)serialize proxy settings. */
    66 class UIProxyManager
    67 {
    68 public:
    69 
    70     /** Proxy states. */
    71     enum ProxyState
    72     {
    73         ProxyState_Disabled,
    74         ProxyState_Enabled,
    75         ProxyState_Auto
    76     };
    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() const
    107     {
    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.0
    173         states["proxyEnabled"]  = ProxyState_Enabled;  // Old since VBox 4.1
    174         states["ProxyEnabled"]  = ProxyState_Enabled;  // New since VBox 5.0
    175         /* 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 
    19564#endif /* !___VBoxUtils_h___ */
    19665
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r71466 r74431  
    3535#  include "VBoxGlobal.h"
    3636#  include "VBoxUtils.h"
     37#  include "CSystemProperties.h"
    3738# else /* VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS */
    3839#  include <VBox/log.h>
     
    384385
    385386#ifndef VBOX_GUI_IN_TST_SSL_CERT_DOWNLOADS
    386     /* Get the proxy-manager: */
    387     UIProxyManager proxyManager(gEDataManager->proxySettings());
    388 
    389387    /* If the specific proxy settings are enabled, we'll use them
    390388     * 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:
    399400            return VINF_SUCCESS;
    400401        default:
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsProxy.cpp

    r72664 r74431  
    3030# include "UIMessageCenter.h"
    3131# include "VBoxUtils.h"
     32# include "VBoxGlobal.h"
     33# include "CSystemProperties.h"
    3234
    3335#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3941    /** Constructs data. */
    4042    UIDataSettingsGlobalProxy()
    41         : m_enmProxyState(UIProxyManager::ProxyState_Auto)
     43        : m_enmProxyMode(KProxyMode_System)
    4244        , m_strProxyHost(QString())
    4345        , m_strProxyPort(QString())
     
    4850    {
    4951        return true
    50                && (m_enmProxyState == other.m_enmProxyState)
     52               && (m_enmProxyMode == other.m_enmProxyMode)
    5153               && (m_strProxyHost == other.m_strProxyHost)
    5254               && (m_strProxyPort == other.m_strProxyPort)
     
    5961    bool operator!=(const UIDataSettingsGlobalProxy &other) const { return !equal(other); }
    6062
    61     /** Holds the proxy state. */
    62     UIProxyManager::ProxyState m_enmProxyState;
     63    /** Holds the proxy mode. */
     64    KProxyMode m_enmProxyMode;
    6365    /** Holds the proxy host. */
    6466    QString m_strProxyHost;
     
    9395
    9496    /* 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    }
    99114
    100115    /* Cache old proxy data: */
     
    111126
    112127    /* 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) */
    118134    }
    119135    m_pHostEditor->setText(oldProxyData.m_strProxyHost);
     
    131147
    132148    /* 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;
    136151    newProxyData.m_strProxyHost = m_pHostEditor->text();
    137152    newProxyData.m_strProxyPort = m_pPortEditor->text();
     
    266281
    267282        /* 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        }
    273306    }
    274307    /* Return result: */
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r74186 r74431  
    99129912  -->
    99139913
     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
    99149927  <interface
    99159928    name="ISystemProperties"
    99169929    extends="$unknown"
    9917     uuid="0eb668d2-495e-5a36-8890-29999b5f030c"
     9930    uuid="d55176e5-6730-4e9e-fc1f-a59b1f44f78f"
    99189931    wsmap="managed"
    99199932    reservedMethods="4" reservedAttributes="16"
     
    1022610239        Supported bitmap formats which can be used with takeScreenShot
    1022710240        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.
    1022810266      </desc>
    1022910267    </attribute>
  • trunk/src/VBox/Main/include/SystemPropertiesImpl.h

    r69500 r74431  
    106106    HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
    107107    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);
    108112
    109113    // wrapped ISystemProperties methods
  • trunk/src/VBox/Main/src-server/SystemPropertiesImpl.cpp

    r73003 r74431  
    3434#include <iprt/path.h>
    3535#include <iprt/string.h>
     36#include <iprt/uri.h>
    3637#include <iprt/cpp/utils.h>
    3738
     
    9798    i_setDefaultVRDEExtPack(Utf8Str::Empty);
    9899
    99     m->ulLogHistoryCount = 3;
     100    m->uLogHistoryCount = 3;
    100101
    101102
     
    873874    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    874875
    875     *count = m->ulLogHistoryCount;
     876    *count = m->uLogHistoryCount;
    876877
    877878    return S_OK;
     
    882883{
    883884    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    884     m->ulLogHistoryCount = count;
     885    m->uLogHistoryCount = count;
    885886    alock.release();
    886887
     
    986987}
    987988
     989HRESULT 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
     998HRESULT 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
     1020HRESULT SystemProperties::getProxyURL(com::Utf8Str &aProxyURL)
     1021{
     1022    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     1023    aProxyURL = m->strProxyUrl;
     1024    return S_OK;
     1025}
     1026
     1027HRESULT 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
    9881074// public methods only for internal purposes
    9891075/////////////////////////////////////////////////////////////////////////////
     
    10141100    if (FAILED(rc)) return rc;
    10151101
    1016     m->ulLogHistoryCount = data.ulLogHistoryCount;
     1102    m->uLogHistoryCount  = data.uLogHistoryCount;
    10171103    m->fExclusiveHwVirt  = data.fExclusiveHwVirt;
     1104    m->uProxyMode        = data.uProxyMode;
     1105    m->strProxyUrl       = data.strProxyUrl;
    10181106
    10191107    rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
     
    13561444    return S_OK;
    13571445}
     1446
  • trunk/src/VBox/Main/xml/Settings.cpp

    r73768 r74431  
    7979#include <iprt/ldr.h>
    8080#include <iprt/base64.h>
     81#include <iprt/uri.h>
    8182#include <iprt/cpp/lock.h>
    8283
     
    15791580 * Constructor. Needs to set sane defaults which stand the test of time.
    15801581 */
    1581 SystemProperties::SystemProperties() :
    1582     ulLogHistoryCount(3),
    1583     fExclusiveHwVirt(true)
     1582SystemProperties::SystemProperties()
     1583    : uLogHistoryCount(3)
     1584    , uProxyMode(ProxyMode_System)
     1585    , fExclusiveHwVirt(true)
    15841586{
    15851587#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
     
    18671869
    18681870/**
     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 */
     1878bool 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/**
    18691956 * Constructor.
    18701957 *
     
    18881975        xml::NodesLoop nlRootChildren(*m->pelmRoot);
    18891976        const xml::ElementNode *pelmRootChild;
     1977        bool fCopyProxySettingsFromExtraData = false;
    18901978        while ((pelmRootChild = nlRootChildren.forAllNodes()))
    18911979        {
     
    19061994                        pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
    19071995                        pelmGlobalChild->getAttributeValue("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
    1908                         pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.ulLogHistoryCount);
     1996                        pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.uLogHistoryCount);
    19091997                        pelmGlobalChild->getAttributeValue("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
    19101998                        pelmGlobalChild->getAttributeValue("defaultFrontend", systemProperties.strDefaultFrontend);
    19111999                        pelmGlobalChild->getAttributeValue("exclusiveHwVirt", systemProperties.fExclusiveHwVirt);
     2000                        if (!pelmGlobalChild->getAttributeValue("proxyMode", systemProperties.uProxyMode))
     2001                            fCopyProxySettingsFromExtraData = true;
     2002                        pelmGlobalChild->getAttributeValue("proxyUrl", systemProperties.strProxyUrl);
    19122003                    }
    19132004                    else if (pelmGlobalChild->nameEquals("ExtraData"))
     
    19412032        }
    19422033
     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
    19432042        clearDocument();
    19442043    }
     
    21412240    if (systemProperties.strDefaultVRDEExtPack.length())
    21422241        pelmSysProps->setAttribute("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
    2143     pelmSysProps->setAttribute("LogHistoryCount", systemProperties.ulLogHistoryCount);
     2242    pelmSysProps->setAttribute("LogHistoryCount", systemProperties.uLogHistoryCount);
    21442243    if (systemProperties.strAutostartDatabasePath.length())
    21452244        pelmSysProps->setAttribute("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
    21462245    if (systemProperties.strDefaultFrontend.length())
    21472246        pelmSysProps->setAttribute("defaultFrontend", systemProperties.strDefaultFrontend);
     2247    if (systemProperties.strProxyUrl.length())
     2248        pelmSysProps->setAttribute("proxyUrl", systemProperties.strProxyUrl);
     2249    pelmSysProps->setAttribute("proxyMode", systemProperties.uProxyMode);
    21482250    pelmSysProps->setAttribute("exclusiveHwVirt", systemProperties.fExclusiveHwVirt);
    21492251
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette