Changeset 47021 in vbox
- Timestamp:
- Jul 6, 2013 5:49:56 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 87052
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDHCPServer.cpp
r46969 r47021 40 40 #include "VBoxManage.h" 41 41 42 #include <string> 43 #include <vector> 44 #include <map> 45 42 46 #ifndef VBOX_ONLY_DOCS 43 47 using namespace com; … … 49 53 OP_MODIFY 50 54 } OPCODE; 55 56 typedef std::map<DhcpOpt_T, std::string> DhcpOptMap; 57 typedef DhcpOptMap::iterator DhcpOptIterator; 58 typedef DhcpOptMap::value_type DhcpOptValuePair; 59 60 struct VmNameSlotKey; 61 typedef struct VmNameSlotKey VmNameSlotKey; 62 63 struct 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 81 typedef std::map<VmNameSlotKey, DhcpOptMap> VmSlot2OptionsM; 82 typedef VmSlot2OptionsM::iterator VmSlot2OptionsIterator; 83 typedef VmSlot2OptionsM::value_type VmSlot2OptionsPair; 84 85 typedef std::vector<VmNameSlotKey> VmConfigs; 51 86 52 87 static const RTGETOPTDEF g_aDHCPIPOptions[] … … 72 107 { "-enable", 'e', RTGETOPT_REQ_NOTHING }, // deprecated 73 108 { "--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 75 116 }; 76 117 … … 82 123 int index = iStart; 83 124 HRESULT rc; 84 125 bool fOptionsRead = false; 126 bool fVmOptionRead = false; 127 128 const char *pszVmName = NULL; 85 129 const char *pNetName = NULL; 86 130 const char *pIfName = NULL; … … 89 133 const char * pLowerIp = NULL; 90 134 const char * pUpperIp = NULL; 135 136 uint8_t u8OptId = -1; 137 uint8_t u8Slot = -1; 138 91 139 int enable = -1; 140 141 DhcpOptMap GlobalDhcpOptions; 142 VmSlot2OptionsM VmSlot2Options; 143 VmConfigs VmConfigs2Delete; 92 144 93 145 int c; … … 176 228 return errorSyntax(USAGE_DHCPSERVER, "unhandled parameter: %s", ValueUnion.psz); 177 229 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 std::string strVal = ValueUnion.psz; 300 map.insert(DhcpOptValuePair((DhcpOpt_T)u8OptId, strVal)); 301 302 } 303 break; // --end of value 304 178 305 default: 179 306 if (c > 0) … … 196 323 return errorSyntax(USAGE_DHCPSERVER, "You need to specify either --netname or --ifname to identify the DHCP server"); 197 324 198 if(enmCode != OP_REMOVE) 325 if( enmCode != OP_REMOVE 326 && GlobalDhcpOptions.size() == 0 327 && VmSlot2Options.size() == 0) 199 328 { 200 329 if(enable < 0 || pIp || pNetmask || pLowerIp || pUpperIp) … … 254 383 if (pIp || pNetmask || pLowerIp || pUpperIp) 255 384 { 256 CHECK_ERROR(svr, SetConfiguration (Bstr(pIp).mutableRaw(), Bstr(pNetmask).mutableRaw(), Bstr(pLowerIp).mutableRaw(), Bstr(pUpperIp).mutableRaw())); 385 CHECK_ERROR(svr, SetConfiguration ( 386 Bstr(pIp).mutableRaw(), 387 Bstr(pNetmask).mutableRaw(), 388 Bstr(pLowerIp).mutableRaw(), 389 Bstr(pUpperIp).mutableRaw())); 257 390 if(FAILED(rc)) 258 391 return errorArgument("Failed to set configuration"); … … 262 395 { 263 396 CHECK_ERROR(svr, COMSETTER(Enabled) ((BOOL)enable)); 397 } 398 399 /* option processing */ 400 DhcpOptIterator itOpt; 401 VmSlot2OptionsIterator it; 402 403 /* Global Options */ 404 for(itOpt = GlobalDhcpOptions.begin(); 405 itOpt != GlobalDhcpOptions.end(); 406 ++itOpt) 407 { 408 CHECK_ERROR(svr, 409 AddGlobalOption( 410 itOpt->first, 411 com::Bstr(itOpt->second.c_str()).raw())); 412 } 413 414 /* heh, vm slot options. */ 415 416 for (it = VmSlot2Options.begin(); 417 it != VmSlot2Options.end(); 418 ++it) 419 { 420 for(itOpt = it->second.begin(); 421 itOpt != it->second.end(); 422 ++itOpt) 423 { 424 CHECK_ERROR(svr, 425 AddVmSlotOption(Bstr(it->first.VmName.c_str()).raw(), 426 it->first.u8Slot, 427 itOpt->first, 428 com::Bstr(itOpt->second.c_str()).raw())); 429 } 264 430 } 265 431 }
Note:
See TracChangeset
for help on using the changeset viewer.