Changeset 18208 in vbox for trunk/src/VBox/Main
- Timestamp:
- Mar 24, 2009 5:01:32 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 7 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl2.cpp
r18068 r18208 84 84 # include <netif.h> 85 85 #endif 86 87 #include "DHCPServerRunner.h" 86 88 87 89 #include <VBox/param.h> … … 1307 1309 NetworkAttachmentType_T networkAttachment; 1308 1310 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H(); 1309 Bstr networkName ;1311 Bstr networkName, trunkName, trunkType; 1310 1312 switch (networkAttachment) 1311 1313 { … … 1353 1355 { 1354 1356 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK(); 1355 networkName = Bstr(psz); 1357 /* NAT uses its own DHCP implementation */ 1358 //networkName = Bstr(psz); 1356 1359 } 1357 1360 … … 1498 1501 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK(); 1499 1502 networkName = Bstr(szNetwork); 1503 trunkName = Bstr(pszTrunk); 1504 trunkType = Bstr(TRUNKTYPE_NETFLT); 1500 1505 1501 1506 # if defined(RT_OS_DARWIN) … … 1715 1720 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK(); 1716 1721 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK(); 1722 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK(); 1717 1723 networkName = Bstr(psz); 1724 trunkType = Bstr(TRUNKTYPE_WHATEVER); 1718 1725 } 1719 1726 STR_FREE(); … … 1791 1798 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK(); 1792 1799 networkName = Bstr(szNetwork); 1800 trunkName = Bstr(pszTrunk); 1801 trunkType = TRUNKTYPE_NETADP; 1793 1802 #elif defined(RT_OS_DARWIN) 1794 1803 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK(); … … 1796 1805 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK(); 1797 1806 networkName = Bstr("HostInterfaceNetworking-vboxnet0"); 1807 trunkName = Bstr("vboxnet0"); 1808 trunkType = TRUNKTYPE_NETADP; 1798 1809 #else 1799 1810 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK(); … … 1801 1812 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK(); 1802 1813 networkName = Bstr("HostInterfaceNetworking-vboxnet0"); 1814 trunkName = Bstr("vboxnet0"); 1815 trunkType = TRUNKTYPE_NETFLT; 1803 1816 #endif 1804 1817 #if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) … … 1851 1864 if(!networkName.isNull()) 1852 1865 { 1866 /* 1867 * Until we implement service reference counters DHCP Server will be stopped 1868 * by DHCPServerRunner destructor. 1869 */ 1853 1870 ComPtr<IDHCPServer> dhcpServer; 1854 1871 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.mutableRaw(), dhcpServer.asOutParam()); … … 1863 1880 H(); 1864 1881 } 1865 1882 1866 1883 if(bEnabled) 1867 { 1868 Bstr ip, mask, lowerIp, upperIp; 1869 1870 hrc = dhcpServer->COMGETTER(IPAddress)(ip.asOutParam()); 1871 if(FAILED(hrc)) 1872 { 1873 LogRel(("DHCP svr: COMGETTER(IPAddress) failed, hrc (0x%x)", hrc)); 1874 H(); 1875 } 1876 1877 hrc = dhcpServer->COMGETTER(NetworkMask)(mask.asOutParam()); 1878 if(FAILED(hrc)) 1879 { 1880 LogRel(("DHCP svr: COMGETTER(NetworkMask) failed, hrc (0x%x)", hrc)); 1881 H(); 1882 } 1883 1884 hrc = dhcpServer->COMGETTER(LowerIP)(lowerIp.asOutParam()); 1885 if(FAILED(hrc)) 1886 { 1887 LogRel(("DHCP svr: COMGETTER(LowerIP) failed, hrc (0x%x)", hrc)); 1888 H(); 1889 } 1890 1891 hrc = dhcpServer->COMGETTER(UpperIP)(upperIp.asOutParam()); 1892 if(FAILED(hrc)) 1893 { 1894 LogRel(("DHCP svr: COMGETTER(UpperIP) failed, hrc (0x%x)", hrc)); 1895 H(); 1896 } 1897 1898 char strMAC[13]; 1899 Guid guid; 1900 guid.create(); 1901 RTStrPrintf (strMAC, sizeof(strMAC), "080027%02X%02X%02X", 1902 guid.ptr()->au8[0], guid.ptr()->au8[1], guid.ptr()->au8[2]); 1903 1904 rc = CFGMR3InsertString(pCfg, "DhcpIPAddress", Utf8Str(ip).raw()); RC_CHECK(); 1905 rc = CFGMR3InsertString(pCfg, "DhcpNetworkMask", Utf8Str(mask).raw()); RC_CHECK(); 1906 rc = CFGMR3InsertString(pCfg, "DhcpLowerIP", Utf8Str(lowerIp).raw()); RC_CHECK(); 1907 rc = CFGMR3InsertString(pCfg, "DhcpUpperIP", Utf8Str(upperIp).raw()); RC_CHECK(); 1908 rc = CFGMR3InsertString(pCfg, "DhcpMacAddress", strMAC); RC_CHECK(); 1909 } 1884 hrc = dhcpServer->Start(networkName, trunkName, trunkType); 1910 1885 } 1911 1886 else -
trunk/src/VBox/Main/DHCPServerImpl.cpp
r18023 r18208 22 22 */ 23 23 24 #include "DHCPServerRunner.h" 24 25 #include "DHCPServerImpl.h" 25 26 #include "Logging.h" … … 240 241 return mVirtualBox->saveSettings(); 241 242 } 243 244 STDMETHODIMP DHCPServer::Start (IN_BSTR aNetworkName, IN_BSTR aTrunkName, IN_BSTR aTrunkType) 245 { 246 /* Silently ignore attepmts to run disabled servers. */ 247 if (!m.enabled) 248 return S_OK; 249 250 m.dhcp.setOption(DHCPCFG_NETNAME, Utf8Str(aNetworkName)); 251 Bstr tmp(aTrunkName); 252 if (!tmp.isEmpty()) 253 m.dhcp.setOption(DHCPCFG_TRUNKNAME, Utf8Str(tmp)); 254 m.dhcp.setOption(DHCPCFG_TRUNKTYPE, Utf8Str(aTrunkType)); 255 //temporary hack for testing 256 // DHCPCFG_NAME 257 char strMAC[13]; 258 Guid guid; 259 guid.create(); 260 RTStrPrintf (strMAC, sizeof(strMAC), "080027%02X%02X%02X", 261 guid.ptr()->au8[0], guid.ptr()->au8[1], guid.ptr()->au8[2]); 262 m.dhcp.setOption(DHCPCFG_MACADDRESS, strMAC); 263 m.dhcp.setOption(DHCPCFG_IPADDRESS, Utf8Str(m.IPAddress)); 264 // DHCPCFG_LEASEDB, 265 // DHCPCFG_VERBOSE, 266 // DHCPCFG_GATEWAY, 267 m.dhcp.setOption(DHCPCFG_LOWERIP, Utf8Str(m.lowerIP)); 268 m.dhcp.setOption(DHCPCFG_UPPERIP, Utf8Str(m.upperIP)); 269 m.dhcp.setOption(DHCPCFG_NETMASK, Utf8Str(m.networkMask)); 270 271 // DHCPCFG_HELP, 272 // DHCPCFG_VERSION, 273 // DHCPCFG_NOTOPT_MAXVAL 274 m.dhcp.setOption(DHCPCFG_BEGINCONFIG, ""); 275 276 return RT_FAILURE(m.dhcp.start()) ? E_FAIL : S_OK; 277 //m.dhcp.detachFromServer(); /* need to do this to avoid server shutdown on runner destruction */ 278 } 279 280 STDMETHODIMP DHCPServer::Stop (void) 281 { 282 return RT_FAILURE(m.dhcp.stop()) ? E_FAIL : S_OK; 283 } -
trunk/src/VBox/Main/Makefile.kmk
r18023 r18208 280 280 HostNetworkInterfaceImpl.cpp \ 281 281 DHCPServerImpl.cpp \ 282 DHCPServerRunner.cpp \ 282 283 GuestOSTypeImpl.cpp \ 283 284 NetworkAdapterImpl.cpp \ -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r18177 r18208 62 62 #include "GuestOSTypeImpl.h" 63 63 #include "Version.h" 64 #include "DHCPServerRunner.h" 64 65 #include "DHCPServerImpl.h" 65 66 -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r18197 r18208 1232 1232 <interface 1233 1233 name="IDHCPServer" extends="$unknown" 1234 uuid=" fab58256-c76e-4ddd-8029-18343e5b0069"1234 uuid="6cfe387c-74fb-4ca7-bff6-973bec8af7a3" 1235 1235 wsmap="managed" 1236 1236 > … … 1305 1305 </desc> 1306 1306 </param> 1307 </method> 1308 1309 <method name="start"> 1310 <desc> 1311 Starts DHCP server process. 1312 <result name="E_FAIL"> 1313 Failed to start the process. 1314 </result> 1315 </desc> 1316 <param name="networkName" type="wstring" dir="in"> 1317 <desc> 1318 Name of internal network DHCP server should attach to. 1319 </desc> 1320 </param> 1321 <param name="trunkName" type="wstring" dir="in"> 1322 <desc> 1323 Name of internal network trunk. 1324 </desc> 1325 </param> 1326 <param name="trunkType" type="wstring" dir="in"> 1327 <desc> 1328 Type of internal network trunk. 1329 </desc> 1330 </param> 1331 </method> 1332 1333 <method name="stop"> 1334 <desc> 1335 Stops DHCP server process. 1336 <result name="E_FAIL"> 1337 Failed to stop the process. 1338 </result> 1339 </desc> 1307 1340 </method> 1308 1341 </interface> -
trunk/src/VBox/Main/include/DHCPServerImpl.h
r18023 r18208 77 77 STDMETHOD(SetConfiguration) (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aFromIPAddress, IN_BSTR aToIPAddress); 78 78 79 STDMETHOD(Start) (IN_BSTR aNetworkName, IN_BSTR aTrunkName, IN_BSTR aTrunkType); 80 STDMETHOD(Stop) (); 81 79 82 // for VirtualBoxSupportErrorInfoImpl 80 83 static const wchar_t *getComponentName() { return L"DHCPServer"; } … … 95 98 Bstr upperIP; 96 99 BOOL enabled; 100 101 DHCPServerRunner dhcp; 97 102 } m; 98 103 -
trunk/src/VBox/Main/include/DHCPServerRunner.h
r18169 r18208 1 /* $Id : DHCPServerRunner.h 44622 2009-03-17 13:48:59Z misha$ */1 /* $Id$ */ 2 2 /** @file 3 3 * VirtualBox Main - interface for VBox DHCP server … … 23 23 #include <iprt/string.h> 24 24 #include <iprt/mem.h> 25 //#include <VBox/com/string.h>25 #include <VBox/com/string.h> 26 26 27 //using namespace com;28 27 typedef enum 29 28 { … … 50 49 #define TRUNKTYPE_NETADP "netadp" 51 50 #define TRUNKTYPE_SRVNAT "srvnat" 52 53 class Utf8Str54 {55 public:56 57 enum CaseSensitivity58 {59 CaseSensitive,60 CaseInsensitive61 };62 63 typedef char *String;64 typedef const char *ConstString;65 66 Utf8Str () : str (NULL) {}67 68 Utf8Str (const Utf8Str &that) : str (NULL) { raw_copy (str, that.str); }69 Utf8Str (const char *that) : str (NULL) { raw_copy (str, that); }70 71 /** Shortcut that calls #alloc(aSize) right after object creation. */72 Utf8Str (size_t aSize) : str (NULL) { alloc(aSize); }73 74 virtual ~Utf8Str () { setNull(); }75 76 Utf8Str &operator = (const Utf8Str &that) { safe_assign (that.str); return *this; }77 Utf8Str &operator = (const char *that) { safe_assign (that); return *this; }78 79 Utf8Str &setNull()80 {81 if (str)82 {83 ::RTStrFree (str);84 str = NULL;85 }86 return *this;87 }88 89 Utf8Str &setNullIfEmpty()90 {91 if (str && *str == 0)92 {93 ::RTStrFree (str);94 str = NULL;95 }96 return *this;97 }98 99 /**100 * Allocates memory for a string capable to store \a aSize - 1 bytes (not characters!);101 * in other words, aSize includes the terminating zero character. If \a aSize102 * is zero, or if a memory allocation error occurs, this object will become null.103 */104 Utf8Str &alloc (size_t aSize)105 {106 setNull();107 if (aSize)108 {109 #if !defined (VBOX_WITH_XPCOM)110 str = (char *) ::RTMemTmpAlloc (aSize);111 #else112 str = (char *) nsMemory::Alloc (aSize);113 #endif114 if (str)115 str [0] = 0;116 }117 return *this;118 }119 120 void append(const Utf8Str &that)121 {122 size_t cbThis = length();123 size_t cbThat = that.length();124 125 if (cbThat)126 {127 size_t cbBoth = cbThis + cbThat + 1;128 129 // @todo optimize with realloc() once the memory management is fixed130 char *pszTemp;131 pszTemp = (char*)::RTMemTmpAlloc(cbBoth);132 if (str)133 {134 memcpy(pszTemp, str, cbThis);135 setNull();136 }137 if (that.str)138 memcpy(pszTemp + cbThis, that.str, cbThat);139 pszTemp[cbThis + cbThat] = '\0';140 141 str = pszTemp;142 }143 }144 145 int compare (const char *pcsz, CaseSensitivity cs = CaseSensitive) const146 {147 if (str == pcsz)148 return 0;149 if (str == NULL)150 return -1;151 if (pcsz == NULL)152 return 1;153 154 if (cs == CaseSensitive)155 return ::RTStrCmp(str, pcsz);156 else157 return ::RTStrICmp(str, pcsz);158 }159 160 int compare (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const161 {162 return compare (that.str, cs);163 }164 165 bool operator == (const Utf8Str &that) const { return !compare (that); }166 bool operator != (const Utf8Str &that) const { return !!compare (that); }167 bool operator == (const char *that) const { return !compare (that); }168 bool operator != (const char *that) const { return !!compare (that); }169 bool operator < (const Utf8Str &that) const { return compare (that) < 0; }170 bool operator < (const char *that) const { return compare (that) < 0; }171 172 bool endsWith (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const173 {174 if (isNull() || that.isNull())175 return false;176 177 if (length() < that.length())178 return false;179 180 int l = length() - that.length();181 if (cs == CaseSensitive)182 return ::RTStrCmp(&str[l], that.str) == 0;183 else184 return ::RTStrICmp(&str[l], that.str) == 0;185 }186 187 bool startsWith (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const188 {189 if (isNull() || that.isNull())190 return false;191 192 if (length() < that.length())193 return false;194 195 if (cs == CaseSensitive)196 return ::RTStrNCmp(str, that.str, that.length()) == 0;197 else198 return ::RTStrNICmp(str, that.str, that.length()) == 0;199 }200 201 bool isNull() const { return str == NULL; }202 operator bool() const { return !isNull(); }203 204 bool isEmpty() const { return isNull() || *str == 0; }205 206 size_t length() const { return isNull() ? 0 : ::strlen (str); }207 208 /** Intended to to pass instances as input (|char *|) parameters to methods. */209 operator const char *() const { return str; }210 211 /** The same as operator const char *(), but for situations where the compiler212 cannot typecast implicitly (for example, in printf() argument list). */213 const char *raw() const { return str; }214 215 /** The same as operator const char *(), but for situations where the compiler216 cannot typecast implicitly (for example, in printf() argument list). */217 const char *c_str() const { return str; }218 219 /**220 * Returns a non-const raw pointer that allows to modify the string directly.221 * @warning222 * Be sure not to modify data beyond the allocated memory! The223 * guaranteed size of the allocated memory is at least #length()224 * bytes after creation and after every assignment operation.225 */226 char *mutableRaw() { return str; }227 228 /**229 * Intended to assign instances to |char *| out parameters from within the230 * interface method. Transfers the ownership of the duplicated string to the231 * caller.232 */233 const Utf8Str &cloneTo (char **pstr) const234 {235 if (pstr)236 {237 *pstr = NULL;238 raw_copy (*pstr, str);239 }240 return *this;241 }242 243 /**244 * Intended to assign instances to |char *| out parameters from within the245 * interface method. Transfers the ownership of the original string to the246 * caller and resets the instance to null.247 *248 * As opposed to cloneTo(), this method doesn't create a copy of the249 * string.250 */251 Utf8Str &detachTo (char **pstr)252 {253 *pstr = str;254 str = NULL;255 return *this;256 }257 258 static const size_t npos;259 260 /**261 * Intended to pass instances as out (|char **|) parameters to methods.262 * Takes the ownership of the returned data.263 */264 char **asOutParam() { setNull(); return &str; }265 266 /**267 * Static immutable null object. May be used for comparison purposes.268 */269 static const Utf8Str Null;270 271 protected:272 273 void safe_assign (const char *s)274 {275 if (str != s)276 {277 setNull();278 raw_copy (str, s);279 }280 }281 282 inline static void raw_copy (char *&ls, const char *rs)283 {284 if (rs)285 //#if !defined (VBOX_WITH_XPCOM)286 ::RTStrDupEx (&ls, rs);287 //#else288 // ls = (char *) nsMemory::Clone (rs, strlen (rs) + 1);289 //#endif290 }291 292 char *str;293 294 };295 51 296 52 class DHCPServerRunner … … 328 84 void detachFromServer(); 329 85 private: 330 Utf8Str mOptions[DHCPCFG_NOTOPT_MAXVAL];86 com::Utf8Str mOptions[DHCPCFG_NOTOPT_MAXVAL]; 331 87 RTPROCESS mProcess; 332 88 }; -
trunk/src/VBox/Main/xpcom/server.cpp
r18023 r18208 111 111 #include <ParallelPortImpl.h> 112 112 #include <USBControllerImpl.h> 113 #include "DHCPServerRunner.h" 113 114 #include "DHCPServerImpl.h" 114 115 #ifdef VBOX_WITH_USB
Note:
See TracChangeset
for help on using the changeset viewer.