Changeset 75819 in vbox
- Timestamp:
- Nov 29, 2018 4:16:40 PM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDHCPServer.cpp
r75648 r75819 60 60 typedef DhcpOpts::iterator DhcpOptIterator; 61 61 62 typedef std::vector<DhcpOpt_T> DhcpOptIds; 63 typedef DhcpOptIds::iterator DhcpOptIdIterator; 64 62 65 struct VmNameSlotKey 63 66 { … … 82 85 typedef VmSlot2OptionsM::iterator VmSlot2OptionsIterator; 83 86 typedef VmSlot2OptionsM::value_type VmSlot2OptionsPair; 87 88 typedef std::map<VmNameSlotKey, DhcpOptIds> VmSlot2OptionIdsM; 89 typedef VmSlot2OptionIdsM::iterator VmSlot2OptionIdsIterator; 84 90 85 91 typedef std::vector<VmNameSlotKey> VmConfigs; … … 112 118 { "--slot", 's', RTGETOPT_REQ_UINT8}, /* only with -o and -n */ 113 119 { "--id", 'i', RTGETOPT_REQ_UINT8}, /* only with -o */ 114 { "--value", 'p', RTGETOPT_REQ_STRING} /* only with -i */ 120 { "--value", 'p', RTGETOPT_REQ_STRING}, /* only with -i */ 121 { "--remove", 'r', RTGETOPT_REQ_NOTHING} /* only with -i */ 115 122 }; 116 123 … … 138 145 int enable = -1; 139 146 140 DhcpOpts GlobalDhcpOptions; 141 VmSlot2OptionsM VmSlot2Options; 142 VmConfigs VmConfigs2Delete; 147 DhcpOpts GlobalDhcpOptions; 148 DhcpOptIds GlobalDhcpOptions2Delete; 149 VmSlot2OptionsM VmSlot2Options; 150 VmSlot2OptionIdsM VmSlot2Options2Delete; 151 VmConfigs VmConfigs2Delete; 143 152 144 153 int c; … … 299 308 break; // --end of value 300 309 310 case 'r': /* --remove */ 311 { 312 if (!fOptionsRead) 313 return errorSyntax(USAGE_DHCPSERVER, 314 "-o wasn't found"); 315 316 if (u8OptId == (uint8_t)~0) 317 return errorSyntax(USAGE_DHCPSERVER, 318 "--id wasn't found"); 319 if ( fVmOptionRead 320 && u8Slot == (uint8_t)~0) 321 return errorSyntax(USAGE_DHCPSERVER, 322 "--slot wasn't found"); 323 324 DhcpOptIds &optIds = fVmOptionRead ? VmSlot2Options2Delete[VmNameSlotKey(pszVmName, u8Slot)] 325 : GlobalDhcpOptions2Delete; 326 optIds.push_back((DhcpOpt_T)u8OptId); 327 } 328 break; /* --end of remove */ 329 301 330 default: 302 331 if (c > 0) … … 322 351 && enmCode != OP_RESTART 323 352 && GlobalDhcpOptions.empty() 324 && VmSlot2Options.empty()) 353 && VmSlot2Options.empty() 354 && GlobalDhcpOptions2Delete.empty() 355 && VmSlot2Options2Delete.empty()) 325 356 { 326 357 if(enable < 0 || pIp || pNetmask || pLowerIp || pUpperIp) … … 404 435 { 405 436 CHECK_ERROR(svr, COMSETTER(Enabled) ((BOOL)enable)); 437 } 438 439 /* remove specified options */ 440 DhcpOptIdIterator itOptId; 441 for (itOptId = GlobalDhcpOptions2Delete.begin(); 442 itOptId != GlobalDhcpOptions2Delete.end(); 443 ++itOptId) 444 { 445 CHECK_ERROR(svr, RemoveGlobalOption(*itOptId)); 446 } 447 VmSlot2OptionIdsIterator itIdVector; 448 for (itIdVector = VmSlot2Options2Delete.begin(); 449 itIdVector != VmSlot2Options2Delete.end(); 450 ++itIdVector) 451 { 452 for(itOptId = itIdVector->second.begin(); 453 itOptId != itIdVector->second.end(); 454 ++itOptId) 455 { 456 CHECK_ERROR(svr, 457 RemoveVmSlotOption(Bstr(itIdVector->first.VmName.c_str()).raw(), 458 itIdVector->first.u8Slot, 459 *itOptId)); 460 } 406 461 } 407 462 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r75365 r75819 1210 1210 " --lowerip <lower_ip>\n" 1211 1211 " --upperip <upper_ip>]\n" 1212 " [--enable | --disable]\n\n" 1212 " [--enable | --disable]\n" 1213 " [--options [--vm <name> --slot <number>]\n" 1214 " --id <number> [--value <string> | --remove]]\n" 1215 " (multiple options allowed after --options)\n\n" 1213 1216 "%s dhcpserver %s remove --netname <network_name> |\n" 1214 1217 #if defined(VBOX_WITH_NETFLT) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r74432 r75819 778 778 779 779 /** 780 * Helper function for querying and displaying DHCP option for an adapter. 781 * 782 * @returns See produceList. 783 * @param pSrv Smart pointer to IDHCPServer. 784 * @param vmSlot String identifying the adapter, like '[vmname]:slot' 785 */ 786 static HRESULT listVmSlotDhcpOptions(const ComPtr<IDHCPServer> pSrv, const Utf8Str& vmSlot) 787 { 788 RTCList<RTCString> lstParts = vmSlot.split(":"); 789 if (lstParts.size() < 2) 790 return E_INVALIDARG; 791 if (lstParts[0].length() < 2 || !lstParts[0].startsWith("[") || !lstParts[0].endsWith("]")) 792 return E_INVALIDARG; 793 Bstr vmName(lstParts[0].substr(1, lstParts[0].length()-2)); 794 ULONG uSlot = lstParts[1].toUInt32(); 795 com::SafeArray<BSTR> options; 796 CHECK_ERROR2I_RET(pSrv, GetVmSlotOptions(vmName.raw(), uSlot, ComSafeArrayAsOutParam(options)), hrcCheck); 797 if (options.size()) 798 RTPrintf("Options for slot #%d of '%ls':\n", uSlot, vmName.raw()); 799 for (size_t i = 0; i < options.size(); ++i) 800 { 801 RTPrintf(" %ls\n", options[i]); 802 } 803 return S_OK; 804 } 805 806 807 /** 808 * List DHCP servers. 809 * 810 * @returns See produceList. 811 * @param pVirtualBox Reference to the IVirtualBox smart pointer. 812 */ 813 static HRESULT listDhcpServers(const ComPtr<IVirtualBox> &pVirtualBox) 814 { 815 HRESULT rc = S_OK; 816 com::SafeIfaceArray<IDHCPServer> svrs; 817 CHECK_ERROR_RET(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)), rc); 818 for (size_t i = 0; i < svrs.size(); ++i) 819 { 820 ComPtr<IDHCPServer> svr = svrs[i]; 821 Bstr netName; 822 svr->COMGETTER(NetworkName)(netName.asOutParam()); 823 RTPrintf("NetworkName: %ls\n", netName.raw()); 824 Bstr ip; 825 svr->COMGETTER(IPAddress)(ip.asOutParam()); 826 RTPrintf("IP: %ls\n", ip.raw()); 827 Bstr netmask; 828 svr->COMGETTER(NetworkMask)(netmask.asOutParam()); 829 RTPrintf("NetworkMask: %ls\n", netmask.raw()); 830 Bstr lowerIp; 831 svr->COMGETTER(LowerIP)(lowerIp.asOutParam()); 832 RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw()); 833 Bstr upperIp; 834 svr->COMGETTER(UpperIP)(upperIp.asOutParam()); 835 RTPrintf("upperIPAddress: %ls\n", upperIp.raw()); 836 BOOL fEnabled; 837 svr->COMGETTER(Enabled)(&fEnabled); 838 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No"); 839 com::SafeArray<BSTR> globalOptions; 840 CHECK_ERROR_BREAK(svr, COMGETTER(GlobalOptions)(ComSafeArrayAsOutParam(globalOptions))); 841 if (globalOptions.size()) 842 { 843 RTPrintf("Global options:\n"); 844 for (size_t j = 0; j < globalOptions.size(); ++j) 845 RTPrintf(" %ls\n", globalOptions[j]); 846 } 847 com::SafeArray<BSTR> vmConfigs; 848 CHECK_ERROR_BREAK(svr, COMGETTER(VmConfigs)(ComSafeArrayAsOutParam(vmConfigs))); 849 for (size_t j = 0; j < vmConfigs.size(); ++j) 850 { 851 rc = listVmSlotDhcpOptions(svr, vmConfigs[j]); 852 if (FAILED(rc)) 853 break; 854 } 855 RTPrintf("\n"); 856 } 857 858 return rc; 859 } 860 861 /** 780 862 * List extension packs. 781 863 * … … 1302 1384 1303 1385 case kListDhcpServers: 1304 { 1305 com::SafeIfaceArray<IDHCPServer> svrs; 1306 CHECK_ERROR(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs))); 1307 for (size_t i = 0; i < svrs.size(); ++i) 1308 { 1309 ComPtr<IDHCPServer> svr = svrs[i]; 1310 Bstr netName; 1311 svr->COMGETTER(NetworkName)(netName.asOutParam()); 1312 RTPrintf("NetworkName: %ls\n", netName.raw()); 1313 Bstr ip; 1314 svr->COMGETTER(IPAddress)(ip.asOutParam()); 1315 RTPrintf("IP: %ls\n", ip.raw()); 1316 Bstr netmask; 1317 svr->COMGETTER(NetworkMask)(netmask.asOutParam()); 1318 RTPrintf("NetworkMask: %ls\n", netmask.raw()); 1319 Bstr lowerIp; 1320 svr->COMGETTER(LowerIP)(lowerIp.asOutParam()); 1321 RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw()); 1322 Bstr upperIp; 1323 svr->COMGETTER(UpperIP)(upperIp.asOutParam()); 1324 RTPrintf("upperIPAddress: %ls\n", upperIp.raw()); 1325 BOOL fEnabled; 1326 svr->COMGETTER(Enabled)(&fEnabled); 1327 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No"); 1328 RTPrintf("\n"); 1329 } 1330 break; 1331 } 1386 rc = listDhcpServers(pVirtualBox); 1387 break; 1332 1388 1333 1389 case kListExtPacks: -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r75817 r75819 1791 1791 <interface 1792 1792 name="IDHCPServer" extends="$unknown" 1793 uuid=" 197717d2-a742-4966-a529-d1467e903feb"1793 uuid="ea2d467f-b6c2-4b9a-8eb5-6e2f275dd72e" 1794 1794 wsmap="managed" 1795 1795 reservedMethods="2" reservedAttributes="6" … … 1842 1842 <param name="option" type="DhcpOpt" dir="in"/> 1843 1843 <param name="value" type="wstring" dir="in" /> 1844 </method> 1845 1846 <method name="removeGlobalOption"> 1847 <desc> 1848 removes the specified option 1849 <result name="E_INVALIDARG"> 1850 invalid option id supplied 1851 </result> 1852 </desc> 1853 <param name="option" type="DhcpOpt" dir="in"/> 1854 </method> 1855 1856 <method name="removeGlobalOptions"> 1857 <desc> 1858 removes all global options 1859 <result name="E_FAIL"> 1860 failed to remove global options 1861 </result> 1862 </desc> 1844 1863 </method> 1845 1864 … … 1877 1896 </method> 1878 1897 1898 <method name="removeVmSlotOption"> 1899 <desc> 1900 removes the specified option 1901 <result name="E_INVALIDARG"> 1902 invalid VM, slot, or option id supplied 1903 </result> 1904 </desc> 1905 <param name="vmname" type="wstring" dir="in"/> 1906 <param name="slot" type="long" dir="in"/> 1907 <param name="option" type="DhcpOpt" dir="in"/> 1908 </method> 1909 1879 1910 <method name="removeVmSlotOptions"> 1911 <desc> 1912 removes all option for the specified adapter 1913 <result name="E_INVALIDARG"> 1914 invalid VM or slot supplied 1915 </result> 1916 </desc> 1880 1917 <param name="vmname" type="wstring" dir="in"/> 1881 1918 <param name="slot" type="long" dir="in"/> -
trunk/src/VBox/Main/include/DHCPServerImpl.h
r75648 r75819 116 116 HRESULT addGlobalOption(DhcpOpt_T aOption, 117 117 const com::Utf8Str &aValue); 118 HRESULT removeGlobalOption(DhcpOpt_T aOption); 119 HRESULT removeGlobalOptions(); 118 120 HRESULT addVmSlotOption(const com::Utf8Str &aVmName, 119 121 LONG aSlot, 120 122 DhcpOpt_T aOption, 121 123 const com::Utf8Str &aValue); 124 HRESULT removeVmSlotOption(const com::Utf8Str &aVmName, 125 LONG aSlot, 126 DhcpOpt_T aOption); 122 127 HRESULT removeVmSlotOptions(const com::Utf8Str &aVmName, 123 128 LONG aSlot); -
trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
r75648 r75819 478 478 479 479 480 HRESULT DHCPServer::removeGlobalOption(DhcpOpt_T aOption) 481 { 482 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 483 484 settings::DhcpOptionMap::size_type cErased = m->GlobalDhcpOptions.erase(aOption); 485 if (!cErased) 486 return E_INVALIDARG; 487 488 alock.release(); 489 490 AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS); 491 return mVirtualBox->i_saveSettings(); 492 } 493 494 495 HRESULT DHCPServer::removeGlobalOptions() 496 { 497 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 498 m->GlobalDhcpOptions.clear(); 499 500 alock.release(); 501 502 AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS); 503 return mVirtualBox->i_saveSettings(); 504 } 505 506 480 507 HRESULT DHCPServer::getGlobalOptions(std::vector<com::Utf8Str> &aValues) 481 508 { … … 520 547 int rc = addOption(map, aOption, aValue); 521 548 if (!RT_SUCCESS(rc)) 549 return E_INVALIDARG; 550 551 alock.release(); 552 553 AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS); 554 return mVirtualBox->i_saveSettings(); 555 } 556 557 558 HRESULT DHCPServer::removeVmSlotOption(const com::Utf8Str &aVmName, LONG aSlot, DhcpOpt_T aOption) 559 { 560 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 561 settings::DhcpOptionMap &map = i_findOptMapByVmNameSlot(aVmName, aSlot); 562 settings::DhcpOptionMap::size_type cErased = map.erase(aOption); 563 if (!cErased) 522 564 return E_INVALIDARG; 523 565
Note:
See TracChangeset
for help on using the changeset viewer.