VirtualBox

Changeset 74431 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Sep 24, 2018 9:16:17 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125272
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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.

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