VirtualBox

Ignore:
Timestamp:
Apr 29, 2022 8:55:44 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151138
Message:

Main/VBoxManage/Update check: More code + docs for proxy settings handling. bugref:7983

File:
1 edited

Legend:

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

    r94685 r94756  
    4141using namespace com;    // SafeArray
    4242
     43
     44/**
     45 * Returns the proxy mode as a string.
     46 *
     47 * @returns Proxy mode as string.
     48 * @param   enmMode             Proxy mode to return as string.
     49 */
     50static const char *proxyModeToStr(ProxyMode_T enmMode)
     51{
     52    switch (enmMode)
     53    {
     54        case ProxyMode_System:  return "System";
     55        case ProxyMode_Manual:  return "Manual";
     56        case ProxyMode_NoProxy: return "None";
     57        default:                break;
     58    }
     59
     60    AssertFailed();
     61    return "<Invalid>";
     62}
     63
    4364static RTEXITCODE doUpdateList(int argc, char **argv, ComPtr<IUpdateAgent> pUpdateAgent)
    4465{
     
    92113    CHECK_ERROR2I_RET(pUpdateAgent, COMGETTER(CheckFrequency)(&uCheckFreqSeconds), RTEXITCODE_FAILURE);
    93114
    94     ULONG const uCheckFreqDays = uCheckFreqSeconds / RT_SEC_1DAY;
    95 
    96     if (fMachineReadable)
    97         outputMachineReadableULong("frequency", &uCheckFreqSeconds);
     115    ULONG uCheckFreqDays = uCheckFreqSeconds / RT_SEC_1DAY;
     116
     117    if (fMachineReadable)
     118        outputMachineReadableULong("frequency-days", &uCheckFreqDays);
    98119    else if (uCheckFreqDays == 0)
    99         RTPrintf(UpdateCheck::tr("Frequency:              never\n")); /** @todo r=bird: Two inconsistencies here. HostUpdateImpl.cpp code will indicate the need for updating if no last-check-date.  modifysettings cannot set it to zero (I added the error message, you just skipped setting it originally). */
     120        RTPrintf(UpdateCheck::tr("Frequency:              Never\n"));
    100121    else if (uCheckFreqDays == 1)
    101         RTPrintf(UpdateCheck::tr("Frequency:              every day\n"));
    102     else
    103         RTPrintf(UpdateCheck::tr("Frequency:              every %u days\n"), uCheckFreqDays);
     122        RTPrintf(UpdateCheck::tr("Frequency:              Every day\n"));
     123    else
     124        RTPrintf(UpdateCheck::tr("Frequency:              Every %u days\n"), uCheckFreqDays);
    104125
    105126    UpdateChannel_T enmUpdateChannel;
     
    132153        RTPrintf(UpdateCheck::tr("Channel:                %s\n"), psz);
    133154
    134     Bstr bstrLastCheckDate;
    135     CHECK_ERROR2I_RET(pUpdateAgent, COMGETTER(LastCheckDate)(bstrLastCheckDate.asOutParam()),
     155    Bstr bstrVal;
     156    CHECK_ERROR2I_RET(pUpdateAgent, COMGETTER(LastCheckDate)(bstrVal.asOutParam()),
    136157                      RTEXITCODE_FAILURE);
    137158    if (fMachineReadable)
    138         outputMachineReadableString("last-check-date", &bstrLastCheckDate);
    139     else if (bstrLastCheckDate.isNotEmpty())
    140         RTPrintf(UpdateCheck::tr("Last Check Date:        %ls\n"), bstrLastCheckDate.raw());
     159        outputMachineReadableString("last-check-date", &bstrVal);
     160    else if (bstrVal.isNotEmpty())
     161        RTPrintf(UpdateCheck::tr("Last Check Date:        %ls\n"), bstrVal.raw());
     162
     163    CHECK_ERROR2I_RET(pUpdateAgent, COMGETTER(RepositoryURL)(bstrVal.asOutParam()), RTEXITCODE_FAILURE);
     164    if (fMachineReadable)
     165        outputMachineReadableString("repo-url", &bstrVal);
     166    else
     167        RTPrintf(UpdateCheck::tr("Repository:             %ls\n"), bstrVal.raw());
     168
     169    ProxyMode_T enmProxyMode;
     170    CHECK_ERROR2I_RET(pUpdateAgent, COMGETTER(ProxyMode)(&enmProxyMode), RTEXITCODE_FAILURE);
     171    if (fMachineReadable)
     172        outputMachineReadableString("proxy-mode", proxyModeToStr(enmProxyMode));
     173    else
     174        RTPrintf(UpdateCheck::tr("Proxy mode:             %s\n"), proxyModeToStr(enmProxyMode));
     175    CHECK_ERROR2I_RET(pUpdateAgent, COMGETTER(ProxyURL)(bstrVal.asOutParam()), RTEXITCODE_FAILURE);
     176    if (fMachineReadable)
     177        outputMachineReadableString("proxy-url", &bstrVal);
     178    else
     179        RTPrintf(UpdateCheck::tr("Proxy URL:              %ls\n"), bstrVal.raw());
    141180
    142181    return RTEXITCODE_SUCCESS;
     
    148187     * Parse options.
    149188     */
     189    enum GETOPTDEF_UPDATEMODIFY
     190    {
     191        GETOPTDEF_UPDATEMODIFY_PROXY_MODE = 2000,
     192        GETOPTDEF_UPDATEMODIFY_PROXY_URL
     193    };
    150194    static const RTGETOPTDEF s_aOptions[] =
    151195    {
    152         { "--enable",        'e', RTGETOPT_REQ_NOTHING },
    153         { "--disable",       'd', RTGETOPT_REQ_NOTHING },
    154         { "--channel",       'c', RTGETOPT_REQ_STRING },
    155         { "--frequency",     'f', RTGETOPT_REQ_UINT32 },
     196        { "--enable",        'e',                                   RTGETOPT_REQ_NOTHING },
     197        { "--disable",       'd',                                   RTGETOPT_REQ_NOTHING },
     198        { "--channel",       'c',                                   RTGETOPT_REQ_STRING  },
     199        { "--frequency",     'f',                                   RTGETOPT_REQ_UINT32  },
     200        { "--proxy-mode",    GETOPTDEF_UPDATEMODIFY_PROXY_MODE,     RTGETOPT_REQ_STRING  },
     201        { "--proxy-url",     GETOPTDEF_UPDATEMODIFY_PROXY_URL,      RTGETOPT_REQ_STRING  }
    156202    };
    157203
     
    160206    AssertRCReturn(vrc, RTEXITCODE_INIT);
    161207
    162     int                         fEnabled       = -1; /* tristate: -1 (not modified), false, true */
    163     UpdateChannel_T const       enmChannelNil  = (UpdateChannel_T)-999;
    164     UpdateChannel_T             enmChannel     = enmChannelNil;
     208    int                         fEnabled       = -1;               /* Tristate: -1 (not modified), false, true. */
     209    UpdateChannel_T             enmChannel     = (UpdateChannel_T)-1;
    165210    uint32_t                    cFrequencyDays = 0;
     211    ProxyMode_T                 enmProxyMode   = (ProxyMode_T)-1; /* Default  if not modified, or ProxyMode_T values. */
     212    Bstr                        strProxyURL    = "unmodified";    /* Default if not modified, so that empty values also can be set (clears proxy). */
    166213
    167214    int c;
     
    188235                    enmChannel = UpdateChannel_All;
    189236                else
    190                     return errorArgument(UpdateCheck::tr("Unknown channel specified: '%s'"), ValueUnion.psz);
     237                    return errorArgument(UpdateCheck::tr("Invalid channel specified: '%s'"), ValueUnion.psz);
    191238                break;
    192239
     
    197244                break;
    198245
    199             /** @todo Add more options like proxy + repo handling etc. */
     246            case GETOPTDEF_UPDATEMODIFY_PROXY_MODE:
     247                if (!RTStrICmp(ValueUnion.psz, "system"))
     248                    enmProxyMode = ProxyMode_System;
     249                else if (   !RTStrICmp(ValueUnion.psz, "none")
     250                         || !RTStrICmp(ValueUnion.psz, "disabled")
     251                         || !RTStrICmp(ValueUnion.psz, "off"))
     252                    enmProxyMode = ProxyMode_NoProxy;
     253                else if (!RTStrICmp(ValueUnion.psz, "manual"))
     254                    enmProxyMode = ProxyMode_Manual;
     255                else
     256                    return errorArgument(UpdateCheck::tr("Invalid proxy mode specified: '%s'"), ValueUnion.psz);
     257                break;
     258
     259            case GETOPTDEF_UPDATEMODIFY_PROXY_URL:
     260                strProxyURL = ValueUnion.psz;
     261                break;
     262
     263            /** @todo Add more options like repo handling etc. */
    200264
    201265            default:
     
    205269
    206270    if (   fEnabled       == -1
    207         && enmChannel     == enmChannelNil
    208         && cFrequencyDays == 0)
     271        && enmChannel     == (UpdateChannel_T)-1
     272        && cFrequencyDays == 0
     273        && enmProxyMode   == (ProxyMode_T)-1
     274        && strProxyURL    == "unmodified")
    209275        return errorSyntax(UpdateCheck::tr("No change requested"));
    210276
     
    212278     * Make the changes.
    213279     */
    214     if (enmChannel != enmChannelNil)
     280    if (enmChannel != (UpdateChannel_T)-1)
    215281    {
    216282        CHECK_ERROR2I_RET(pUpdateAgent, COMSETTER(Channel)(enmChannel), RTEXITCODE_FAILURE);
     
    223289    {
    224290        CHECK_ERROR2I_RET(pUpdateAgent, COMSETTER(CheckFrequency)(cFrequencyDays * RT_SEC_1DAY), RTEXITCODE_FAILURE);
     291    }
     292    if (enmProxyMode != (ProxyMode_T)-1)
     293    {
     294        CHECK_ERROR2I_RET(pUpdateAgent, COMSETTER(ProxyMode)(enmProxyMode), RTEXITCODE_FAILURE);
     295    }
     296    if (strProxyURL.compare("unmodified") != 0)
     297    {
     298        CHECK_ERROR2I_RET(pUpdateAgent, COMSETTER(ProxyURL)(strProxyURL.raw()), RTEXITCODE_FAILURE);
    225299    }
    226300    return RTEXITCODE_SUCCESS;
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