VirtualBox

Changeset 46960 in vbox for trunk


Ignore:
Timestamp:
Jul 4, 2013 5:27:05 AM (12 years ago)
Author:
vboxsync
Message:

Frontend/VBoxManage: new configuration options for dhcp server.

vm - name of virtual machine
slot - number of slot
id - id of dhcp option
value - value of dhcp option.

File:
1 edited

Legend:

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

    r46658 r46960  
    4040#include "VBoxManage.h"
    4141
     42#include <string>
     43#include <vector>
     44#include <map>
     45
    4246#ifndef VBOX_ONLY_DOCS
    4347using namespace com;
     
    4953    OP_MODIFY
    5054} OPCODE;
     55
     56typedef std::map<DhcpOpt_T, std::string> DhcpOptMap;
     57typedef DhcpOptMap::iterator DhcpOptIterator;
     58typedef DhcpOptMap::value_type DhcpOptValuePair;
     59
     60struct VmNameSlotKey;
     61typedef struct VmNameSlotKey VmNameSlotKey;
     62
     63struct VmNameSlotKey
     64{
     65    std::string VmName;
     66    uint8_t u8Slot;
     67
     68    VmNameSlotKey(std::string aVmName, uint8_t aSlot) :
     69      VmName(aVmName),
     70      u8Slot(aSlot) {}
     71
     72    bool operator< (const VmNameSlotKey& that) const
     73    {
     74        if (VmName == that.VmName)
     75            return u8Slot < that.u8Slot;
     76        else
     77            return VmName < that.VmName;
     78    }
     79};
     80
     81typedef std::map<VmNameSlotKey, DhcpOptMap> VmSlot2OptionsM;
     82typedef VmSlot2OptionsM::iterator VmSlot2OptionsIterator;
     83typedef VmSlot2OptionsM::value_type VmSlot2OptionsPair;
     84
     85typedef std::vector<VmNameSlotKey> VmConfigs;
    5186
    5287static const RTGETOPTDEF g_aDHCPIPOptions[]
     
    72107        { "-enable",            'e', RTGETOPT_REQ_NOTHING },    // deprecated
    73108        { "--disable",          'd', RTGETOPT_REQ_NOTHING },
    74         { "-disable",           'd', RTGETOPT_REQ_NOTHING }     // deprecated
     109        { "-disable",           'd', RTGETOPT_REQ_NOTHING },     // deprecated
     110        { "--options",          'o', RTGETOPT_REQ_NOTHING },     
     111        {"--vm",                'n', RTGETOPT_REQ_STRING}, /* only with -o */
     112        {"--slot",              's', RTGETOPT_REQ_UINT8}, /* only with -o and -n */
     113        {"--id",                'i', RTGETOPT_REQ_UINT8}, /* only with -o */
     114        {"--value",             'p', RTGETOPT_REQ_STRING} /* only with -i */
     115
    75116      };
    76117
     
    82123    int index = iStart;
    83124    HRESULT rc;
    84 
     125    bool fOptionsRead = false;
     126    bool fVmOptionRead = false;
     127
     128    const char *pszVmName = NULL;
    85129    const char *pNetName = NULL;
    86130    const char *pIfName = NULL;
     
    89133    const char * pLowerIp = NULL;
    90134    const char * pUpperIp = NULL;
     135
     136    uint8_t u8OptId = -1;
     137    uint8_t u8Slot = -1;
     138
    91139    int enable = -1;
     140
     141    DhcpOptMap GlobalDhcpOptions;
     142    VmSlot2OptionsM VmSlot2Options;
     143    VmConfigs       VmConfigs2Delete;
    92144
    93145    int c;
     
    176228                return errorSyntax(USAGE_DHCPSERVER, "unhandled parameter: %s", ValueUnion.psz);
    177229            break;
     230
     231            case 'o': // --options
     232                {
     233        // {"--vm",                'n', RTGETOPT_REQ_STRING}, /* only with -o */
     234        // {"--slot",              's', RTGETOPT_REQ_UINT8}, /* only with -o and -n*/
     235        // {"--id",                'i', RTGETOPT_REQ_UINT8}, /* only with -o */
     236        // {"--value",             'p', RTGETOPT_REQ_STRING} /* only with -i */
     237                    if (fOptionsRead)
     238                        return errorSyntax(USAGE_DHCPSERVER,
     239                                           "previos option edition  wasn't finished");
     240                    fOptionsRead = true;
     241                    fVmOptionRead = false; /* we want specify new global or vm option*/
     242                    u8Slot = (uint8_t)~0;
     243                    u8OptId = (uint8_t)~0;
     244                    pszVmName = NULL;
     245                } /* end of --options  */
     246                break;
     247
     248            case 'n': // --vm-name
     249                {
     250                    if (fVmOptionRead)
     251                        return errorSyntax(USAGE_DHCPSERVER,
     252                                           "previous vm option edition wasn't finished");
     253                    else
     254                        fVmOptionRead = true;
     255                    u8Slot = (uint8_t)~0; /* clear slor */
     256                    pszVmName = RTStrDup(ValueUnion.psz);
     257                }
     258                break; /* end of --vm-name */
     259
     260            case 's': // --slot
     261                {
     262                    if (!fVmOptionRead)
     263                        return errorSyntax(USAGE_DHCPSERVER,
     264                                           "vm name wasn't specified");
     265                   
     266                    u8Slot = ValueUnion.u8;
     267                }
     268                break; /* end of --slot */
     269
     270            case 'i': // --id
     271                {
     272                    if (!fOptionsRead)
     273                        return errorSyntax(USAGE_DHCPSERVER,
     274                                           "-o wasn't found");
     275
     276                    u8OptId = ValueUnion.u8;
     277                }
     278                break; /* end of --id */
     279
     280            case 'p': // --value
     281                {
     282                    if (!fOptionsRead)
     283                        return errorSyntax(USAGE_DHCPSERVER,
     284                                           "-o wasn't found");
     285                   
     286                    if (u8OptId == (uint8_t)~0)
     287                        return errorSyntax(USAGE_DHCPSERVER,
     288                                           "--id wasn't found");
     289                    if (   fVmOptionRead
     290                        && u8Slot == (uint8_t)~0)
     291                        return errorSyntax(USAGE_DHCPSERVER,
     292                                           "--slot wasn't found");
     293                   
     294                    DhcpOptMap& map = (fVmOptionRead ?
     295                                       VmSlot2Options[
     296                                         VmNameSlotKey::VmNameSlotKey(pszVmName,
     297                                                                      u8Slot)]
     298                                       : GlobalDhcpOptions);
     299                    map[u8OptId] = std::string(ValueUnion.psz);
     300
     301                }
     302                break; // --end of value
     303
    178304            default:
    179305                if (c > 0)
     
    196322        return errorSyntax(USAGE_DHCPSERVER, "You need to specify either --netname or --ifname to identify the DHCP server");
    197323
    198     if(enmCode != OP_REMOVE)
     324    if(   enmCode != OP_REMOVE
     325       && GlobalDhcpOptions.size() == 0
     326       && VmSlot2Options.size() == 0)
    199327    {
    200328        if(enable < 0 || pIp || pNetmask || pLowerIp || pUpperIp)
     
    254382        if (pIp || pNetmask || pLowerIp || pUpperIp)
    255383        {
    256             CHECK_ERROR(svr, SetConfiguration (Bstr(pIp).mutableRaw(), Bstr(pNetmask).mutableRaw(), Bstr(pLowerIp).mutableRaw(), Bstr(pUpperIp).mutableRaw()));
     384            CHECK_ERROR(svr, SetConfiguration (
     385                          Bstr(pIp).mutableRaw(),
     386                          Bstr(pNetmask).mutableRaw(),
     387                          Bstr(pLowerIp).mutableRaw(),
     388                          Bstr(pUpperIp).mutableRaw()));
    257389            if(FAILED(rc))
    258390                return errorArgument("Failed to set configuration");
     
    262394        {
    263395            CHECK_ERROR(svr, COMSETTER(Enabled) ((BOOL)enable));
     396        }
     397
     398        /* option processing */
     399        DhcpOptIterator itOpt;
     400        VmSlot2OptionsIterator it;
     401       
     402        /* Global Options */
     403        for(itOpt = GlobalDhcpOptions.begin();
     404            itOpt != GlobalDhcpOptions.end();
     405            ++itOpt)
     406        {
     407            CHECK_ERROR(svr,
     408                        AddGlobalOption(
     409                          itOpt->first,
     410                          com::Bstr(itOpt->second.c_str()).raw()));
     411        }
     412
     413        /* heh, vm slot options. */
     414
     415        for (it = VmSlot2Options.begin();
     416             it != VmSlot2Options.end();
     417             ++it)
     418        {
     419            for(itOpt = it->second.begin();
     420                itOpt != it->second.end();
     421                ++itOpt)
     422            {
     423                CHECK_ERROR(svr,
     424                            AddVmSlotOption(Bstr(it->first.VmName.c_str()).raw(),
     425                                            it->first.u8Slot,
     426                                            itOpt->first,
     427                                            com::Bstr(itOpt->second.c_str()).raw()));
     428            }
    264429        }
    265430    }
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