- Timestamp:
- Jul 4, 2013 5:27:05 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDHCPServer.cpp
r46658 r46960 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 map[u8OptId] = std::string(ValueUnion.psz); 300 301 } 302 break; // --end of value 303 178 304 default: 179 305 if (c > 0) … … 196 322 return errorSyntax(USAGE_DHCPSERVER, "You need to specify either --netname or --ifname to identify the DHCP server"); 197 323 198 if(enmCode != OP_REMOVE) 324 if( enmCode != OP_REMOVE 325 && GlobalDhcpOptions.size() == 0 326 && VmSlot2Options.size() == 0) 199 327 { 200 328 if(enable < 0 || pIp || pNetmask || pLowerIp || pUpperIp) … … 254 382 if (pIp || pNetmask || pLowerIp || pUpperIp) 255 383 { 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())); 257 389 if(FAILED(rc)) 258 390 return errorArgument("Failed to set configuration"); … … 262 394 { 263 395 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 } 264 429 } 265 430 }
Note:
See TracChangeset
for help on using the changeset viewer.