Changeset 105726 in vbox for trunk/src/VBox/Main/src-client
- Timestamp:
- Aug 19, 2024 2:05:15 PM (7 months ago)
- svn:sync-xref-src-repo-rev:
- 164430
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r105605 r105726 4512 4512 4513 4513 4514 /* 4514 /** Helper that converts a BSTR safe array into a C-string array. */ 4515 static char **bstrSafeArrayToC(SafeArray<BSTR> const &a_rStrings, size_t *pcEntries) RT_NOEXCEPT 4516 { 4517 if (pcEntries) 4518 *pcEntries = 0; 4519 4520 /* 4521 * The array is NULL terminated. 4522 */ 4523 const size_t cStrings = a_rStrings.size(); 4524 char **papszRet = (char **)RTMemAllocZ((cStrings + 1) * sizeof(papszRet[0])); 4525 AssertReturn(papszRet, NULL); 4526 4527 /* 4528 * The individual strings. 4529 */ 4530 for (size_t i = 0; i < cStrings; i++) 4531 { 4532 int vrc = RTUtf16ToUtf8Ex((PCRTUTF16)a_rStrings[i], RTSTR_MAX, &papszRet[i], 0, NULL); 4533 AssertRC(vrc); 4534 if (RT_FAILURE(vrc)) 4535 { 4536 while (i-- > 0) 4537 { 4538 RTStrFree(papszRet[i]); 4539 papszRet[i] = NULL; 4540 } 4541 return NULL; 4542 } 4543 4544 } 4545 if (pcEntries) 4546 *pcEntries = cStrings; 4547 return papszRet; 4548 } 4549 4550 4551 /** 4515 4552 * IHostNameResolutionConfigurationChangeEvent 4516 4553 * … … 4520 4557 HRESULT Console::i_onNATDnsChanged() 4521 4558 { 4522 HRESULT hrc;4523 4524 4559 AutoCaller autoCaller(this); 4525 4560 AssertComRCReturnRC(autoCaller.hrc()); 4526 4561 4527 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 4528 4529 #if 0 /* XXX: We don't yet pass this down to pfnNotifyDnsChanged */ 4530 ComPtr<IVirtualBox> pVirtualBox; 4531 hrc = mMachine->COMGETTER(Parent)(pVirtualBox.asOutParam()); 4562 /* We wrap PDMINETWORKNATDNSCONFIG to simplify freeing memory allocations 4563 in it (exceptions, AssertReturn, regular returns). */ 4564 struct DnsConfigCleanupWrapper 4565 { 4566 PDMINETWORKNATDNSCONFIG Core; 4567 4568 DnsConfigCleanupWrapper() 4569 { 4570 Core.szDomainName[0] = '\0'; 4571 Core.cNameServers = 0; 4572 Core.papszNameServers = NULL; 4573 Core.cSearchDomains = 0; 4574 Core.papszSearchDomains = NULL; 4575 } 4576 4577 void freeStrArray(char **papsz) 4578 { 4579 if (papsz) 4580 { 4581 for (size_t i = 0; papsz[i] != NULL; i++) 4582 RTStrFree(papsz[i]); 4583 RTMemFree(papsz); 4584 } 4585 } 4586 4587 ~DnsConfigCleanupWrapper() 4588 { 4589 freeStrArray((char **)Core.papszNameServers); 4590 Core.papszNameServers = NULL; 4591 freeStrArray((char **)Core.papszSearchDomains); 4592 Core.papszSearchDomains = NULL; 4593 } 4594 } DnsConfig; 4595 4596 4597 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /** @todo r=bird: Why a write lock? */ 4598 4599 ComPtr<IVirtualBox> ptrVirtualBox; 4600 HRESULT hrc = mMachine->COMGETTER(Parent)(ptrVirtualBox.asOutParam()); 4532 4601 if (FAILED(hrc)) 4533 4602 return S_OK; 4534 4603 4535 ComPtr<IHost> p Host;4536 hrc = p VirtualBox->COMGETTER(Host)(pHost.asOutParam());4604 ComPtr<IHost> ptrHost; 4605 hrc = ptrVirtualBox->COMGETTER(Host)(ptrHost.asOutParam()); 4537 4606 if (FAILED(hrc)) 4538 4607 return S_OK; 4539 4608 4540 SafeArray<BSTR> aNameServers; 4541 hrc = pHost->COMGETTER(NameServers)(ComSafeArrayAsOutParam(aNameServers)); 4542 if (FAILED(hrc)) 4543 return S_OK; 4544 4545 const size_t cNameServers = aNameServers.size(); 4546 Log(("DNS change - %zu nameservers\n", cNameServers)); 4547 4548 for (size_t i = 0; i < cNameServers; ++i) 4549 { 4550 com::Utf8Str strNameServer(aNameServers[i]); 4551 Log(("- nameserver[%zu] = \"%s\"\n", i, strNameServer.c_str())); 4552 } 4553 4554 com::Bstr domain; 4555 pHost->COMGETTER(DomainName)(domain.asOutParam()); 4556 Log(("domain name = \"%s\"\n", com::Utf8Str(domain).c_str())); 4557 #endif /* 0 */ 4558 4559 ComPtr<IPlatform> pPlatform; 4560 hrc = mMachine->COMGETTER(Platform)(pPlatform.asOutParam()); 4609 /* Domain name: */ 4610 { 4611 com::Bstr bstrDomain; 4612 ptrHost->COMGETTER(DomainName)(bstrDomain.asOutParam()); 4613 com::Utf8Str const strDomainName(bstrDomain); 4614 int vrc = RTStrCopy(DnsConfig.Core.szDomainName, sizeof(DnsConfig.Core.szDomainName), strDomainName.c_str()); 4615 AssertRC(vrc); 4616 } 4617 Log(("domain name = \"%s\"\n", DnsConfig.Core.szDomainName)); 4618 4619 /* Name servers: */ 4620 { 4621 SafeArray<BSTR> nameServers; 4622 hrc = ptrHost->COMGETTER(NameServers)(ComSafeArrayAsOutParam(nameServers)); 4623 if (FAILED(hrc)) 4624 return S_OK; 4625 DnsConfig.Core.papszNameServers = bstrSafeArrayToC(nameServers, &DnsConfig.Core.cNameServers); 4626 if (!DnsConfig.Core.papszNameServers) 4627 return E_OUTOFMEMORY; 4628 } 4629 Log(("DNS change - %zu nameservers\n", DnsConfig.Core.cNameServers)); 4630 for (size_t i = 0; i < DnsConfig.Core.cNameServers; i++) 4631 Log(("- papszNameServers[%zu] = \"%s\"\n", i, DnsConfig.Core.papszNameServers[i])); 4632 4633 /* Search domains: */ 4634 { 4635 SafeArray<BSTR> searchDomains; 4636 hrc = ptrHost->COMGETTER(SearchStrings)(ComSafeArrayAsOutParam(searchDomains)); 4637 if (FAILED(hrc)) 4638 return S_OK; 4639 DnsConfig.Core.papszSearchDomains = bstrSafeArrayToC(searchDomains, &DnsConfig.Core.cSearchDomains); 4640 if (!DnsConfig.Core.papszSearchDomains) 4641 return E_OUTOFMEMORY; 4642 } 4643 Log(("Search Domain change - %u domains\n", DnsConfig.Core.cSearchDomains)); 4644 for (size_t i = 0; i < DnsConfig.Core.cSearchDomains; i++) 4645 Log(("- papszSearchDomain[%zu] = \"%s\"\n", i, DnsConfig.Core.papszSearchDomains[i])); 4646 4647 /* 4648 * Notify all the NAT drivers. 4649 */ 4650 /** @todo r=bird: This is the worst way of "enumerating" network devices 4651 * ever conceived. */ 4652 ComPtr<IPlatform> ptrPlatform; 4653 hrc = mMachine->COMGETTER(Platform)(ptrPlatform.asOutParam()); 4561 4654 AssertComRCReturn(hrc, hrc); 4562 4655 4563 4656 ChipsetType_T enmChipsetType; 4564 hrc = p Platform->COMGETTER(ChipsetType)(&enmChipsetType);4657 hrc = ptrPlatform->COMGETTER(ChipsetType)(&enmChipsetType); 4565 4658 AssertComRCReturn(hrc, hrc); 4566 4659 … … 4570 4663 ULONG const ulInstanceMax = PlatformProperties::s_getMaxNetworkAdapters(enmChipsetType); 4571 4664 4572 notifyNatDnsChange(ptrVM.rawUVM(), ptrVM.vtable(), "pcnet", ulInstanceMax );4573 notifyNatDnsChange(ptrVM.rawUVM(), ptrVM.vtable(), "e1000", ulInstanceMax );4574 notifyNatDnsChange(ptrVM.rawUVM(), ptrVM.vtable(), "virtio-net", ulInstanceMax );4665 notifyNatDnsChange(ptrVM.rawUVM(), ptrVM.vtable(), "pcnet", ulInstanceMax, &DnsConfig.Core); 4666 notifyNatDnsChange(ptrVM.rawUVM(), ptrVM.vtable(), "e1000", ulInstanceMax, &DnsConfig.Core); 4667 notifyNatDnsChange(ptrVM.rawUVM(), ptrVM.vtable(), "virtio-net", ulInstanceMax, &DnsConfig.Core); 4575 4668 } 4576 4669 … … 4579 4672 4580 4673 4581 /* 4674 /** 4582 4675 * This routine walks over all network device instances, checking if 4583 4676 * device instance has DrvNAT attachment and triggering DrvNAT DNS 4584 4677 * change callback. 4585 4678 */ 4586 void Console::notifyNatDnsChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, ULONG ulInstanceMax) 4679 void Console::notifyNatDnsChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, ULONG ulInstanceMax, 4680 PCPDMINETWORKNATDNSCONFIG pDnsConfig) 4587 4681 { 4588 4682 Log(("notifyNatDnsChange: looking for DrvNAT attachment on %s device instances\n", pszDevice)); … … 4600 4694 pNetNatCfg = (PPDMINETWORKNATCONFIG)pBase->pfnQueryInterface(pBase, PDMINETWORKNATCONFIG_IID); 4601 4695 if (pNetNatCfg && pNetNatCfg->pfnNotifyDnsChanged) 4602 pNetNatCfg->pfnNotifyDnsChanged(pNetNatCfg );4696 pNetNatCfg->pfnNotifyDnsChanged(pNetNatCfg, pDnsConfig); 4603 4697 } 4604 4698 }
Note:
See TracChangeset
for help on using the changeset viewer.