diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-06-05 15:53:58 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-06-18 08:45:16 +0200 |
| commit | ef99f821022c35eec1f2a4feb1f0f348d340f9f3 (patch) | |
| tree | 5c966ebd217b4080533f7a19ae8ddb1dc4458585 | |
| parent | 359cfcb25276f6b28218495b6f6cce4e248fb6ab (diff) | |
| download | mullvadvpn-ef99f821022c35eec1f2a4feb1f0f348d340f9f3.tar.xz mullvadvpn-ef99f821022c35eec1f2a4feb1f0f348d340f9f3.zip | |
Bring back ClientSinkInfo member in WinDnsContext for use in dtor
| -rw-r--r-- | windows/windns/src/windns/windns.cpp | 10 | ||||
| -rw-r--r-- | windows/windns/src/windns/windnscontext.cpp | 35 | ||||
| -rw-r--r-- | windows/windns/src/windns/windnscontext.h | 12 |
3 files changed, 36 insertions, 21 deletions
diff --git a/windows/windns/src/windns/windns.cpp b/windows/windns/src/windns/windns.cpp index 728df4b173..66b7c94f7c 100644 --- a/windows/windns/src/windns/windns.cpp +++ b/windows/windns/src/windns/windns.cpp @@ -105,7 +105,7 @@ WinDns_Set( sinkInfo.errorSinkInfo = ErrorSinkInfo{ g_ErrorSink, g_ErrorContext }; sinkInfo.configSinkInfo = ConfigSinkInfo{ configSink, configContext }; - return g_Context->set(MakeStringArray(servers, numServers), sinkInfo); + g_Context->set(MakeStringArray(servers, numServers), sinkInfo); } catch (std::exception &err) { @@ -120,6 +120,8 @@ WinDns_Set( { return false; } + + return true; } WINDNS_LINKAGE @@ -130,12 +132,12 @@ WinDns_Reset( { if (nullptr == g_Context) { - return false; + return true; } try { - return g_Context->reset(); + g_Context->reset(); } catch (std::exception &err) { @@ -150,6 +152,8 @@ WinDns_Reset( { return false; } + + return true; } WINDNS_LINKAGE diff --git a/windows/windns/src/windns/windnscontext.cpp b/windows/windns/src/windns/windnscontext.cpp index 604e3e7aa4..efe975e54c 100644 --- a/windows/windns/src/windns/windnscontext.cpp +++ b/windows/windns/src/windns/windnscontext.cpp @@ -10,11 +10,31 @@ WinDnsContext::WinDnsContext() m_connection = std::make_shared<wmi::Connection>(wmi::Connection::Namespace::Cimv2); } -bool WinDnsContext::set(const std::vector<std::wstring> &servers, const ClientSinkInfo &sinkInfo) +WinDnsContext::~WinDnsContext() { + try + { + reset(); + } + catch (std::exception &err) + { + if (nullptr != m_sinkInfo.errorSinkInfo.sink) + { + m_sinkInfo.errorSinkInfo.sink(err.what(), m_sinkInfo.errorSinkInfo.context); + } + } + catch (...) + { + } +} + +void WinDnsContext::set(const std::vector<std::wstring> &servers, const ClientSinkInfo &sinkInfo) +{ + m_sinkInfo = sinkInfo; + if (nullptr == m_notification) { - m_configManager = std::make_shared<ConfigManager>(servers, sinkInfo.configSinkInfo); + m_configManager = std::make_shared<ConfigManager>(servers, m_sinkInfo.configSinkInfo); // // Register interface configuration monitoring. @@ -39,7 +59,7 @@ bool WinDnsContext::set(const std::vector<std::wstring> &servers, const ClientSi ConfigManager::Mutex mutex(*m_configManager); m_configManager->updateServers(servers); - m_configManager->updateConfigSink(sinkInfo.configSinkInfo); + m_configManager->updateConfigSink(m_sinkInfo.configSinkInfo); } // @@ -52,15 +72,13 @@ bool WinDnsContext::set(const std::vector<std::wstring> &servers, const ClientSi { nchelpers::SetDnsServers(nchelpers::GetInterfaceIndex(resultSet.result()), servers); } - - return true; } -bool WinDnsContext::reset() +void WinDnsContext::reset() { if (nullptr == m_notification) { - return true; + return; } m_notification->deactivate(); @@ -76,9 +94,6 @@ bool WinDnsContext::reset() m_configManager->processConfigs([&](const InterfaceConfig &config) { dnsReverter.revert(config); - return true; }); - - return true; } diff --git a/windows/windns/src/windns/windnscontext.h b/windows/windns/src/windns/windnscontext.h index 19e17550cf..89ff035fa9 100644 --- a/windows/windns/src/windns/windnscontext.h +++ b/windows/windns/src/windns/windnscontext.h @@ -14,19 +14,15 @@ class WinDnsContext public: WinDnsContext(); + ~WinDnsContext(); - // TODO: Review. - ~WinDnsContext() - { - reset(); - } - - bool set(const std::vector<std::wstring> &servers, const ClientSinkInfo &sinkInfo); - bool reset(); + void set(const std::vector<std::wstring> &servers, const ClientSinkInfo &sinkInfo); + void reset(); private: std::shared_ptr<wmi::Connection> m_connection; std::shared_ptr<ConfigManager> m_configManager; std::unique_ptr<wmi::Notification> m_notification; + ClientSinkInfo m_sinkInfo; }; |
