diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-01-20 19:03:48 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-01-20 19:03:48 +0100 |
| commit | feaff7f3e7585f073b241eb87e31740b138dc714 (patch) | |
| tree | 67353ac90f69ea7bf810c0c7b341f8f77867be4a /windows | |
| parent | b746ee3c93454482d02fb8f64393350a79587b99 (diff) | |
| parent | a64020b195a83b0960fe79ff11904c4f35348ec8 (diff) | |
| download | mullvadvpn-feaff7f3e7585f073b241eb87e31740b138dc714.tar.xz mullvadvpn-feaff7f3e7585f073b241eb87e31740b138dc714.zip | |
Merge branch 'win-refactor'
Diffstat (limited to 'windows')
| -rw-r--r-- | windows/libshared/src/libshared/logging/logsinkadapter.cpp | 32 | ||||
| m--------- | windows/libwfp | 0 | ||||
| -rw-r--r-- | windows/nsis-plugins/src/cleanup/cleaningops.cpp | 2 | ||||
| -rw-r--r-- | windows/nsis-plugins/src/driverlogic/driverlogic.cpp | 15 | ||||
| -rw-r--r-- | windows/nsis-plugins/src/tray/tray.cpp | 2 | ||||
| -rw-r--r-- | windows/windns/src/windns/netsh.cpp | 16 | ||||
| -rw-r--r-- | windows/windns/src/windns/netsh.h | 4 | ||||
| m--------- | windows/windows-libraries | 0 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.cpp | 25 | ||||
| -rw-r--r-- | windows/winutil/src/winutil/winutil.cpp | 15 |
10 files changed, 34 insertions, 77 deletions
diff --git a/windows/libshared/src/libshared/logging/logsinkadapter.cpp b/windows/libshared/src/libshared/logging/logsinkadapter.cpp index f506aba096..03244cb423 100644 --- a/windows/libshared/src/libshared/logging/logsinkadapter.cpp +++ b/windows/libshared/src/libshared/logging/logsinkadapter.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include <libcommon/valuemapper.h> #include "logsinkadapter.h" namespace shared::logging @@ -19,30 +20,15 @@ common::logging::LogTarget LogSinkAdapter::MakeAdapter(MullvadLogSink target, vo return; } - // - // TODO: Replace manual mapping with ValueMapper once the updated - // ValueMapper reaches libcommon. - // + const std::optional<MULLVAD_LOG_LEVEL> translatedLevel = common::ValueMapper::TryMap<>(level, { + std::make_pair(common::logging::LogLevel::Warning, MULLVAD_LOG_LEVEL_WARNING), + std::make_pair(common::logging::LogLevel::Info, MULLVAD_LOG_LEVEL_INFO), + std::make_pair(common::logging::LogLevel::Trace, MULLVAD_LOG_LEVEL_TRACE), + std::make_pair(common::logging::LogLevel::Debug, MULLVAD_LOG_LEVEL_DEBUG), + std::make_pair(common::logging::LogLevel::Error, MULLVAD_LOG_LEVEL_ERROR), + }); - const MULLVAD_LOG_LEVEL translatedLevel = [level]() - { - switch (level) - { - case common::logging::LogLevel::Warning: - return MULLVAD_LOG_LEVEL_WARNING; - case common::logging::LogLevel::Info: - return MULLVAD_LOG_LEVEL_INFO; - case common::logging::LogLevel::Trace: - return MULLVAD_LOG_LEVEL_TRACE; - case common::logging::LogLevel::Debug: - return MULLVAD_LOG_LEVEL_DEBUG; - case common::logging::LogLevel::Error: - default: - return MULLVAD_LOG_LEVEL_ERROR; - } - }(); - - target(translatedLevel, msg, context); + target(translatedLevel.value_or(MULLVAD_LOG_LEVEL_ERROR), msg, context); }; } diff --git a/windows/libwfp b/windows/libwfp -Subproject 0b711f0379b680d4b128cb35180b223964ff605 +Subproject 70dde60aa45029b825658cad6e0159bba44b0bd diff --git a/windows/nsis-plugins/src/cleanup/cleaningops.cpp b/windows/nsis-plugins/src/cleanup/cleaningops.cpp index 671ff3c73d..88cf20ad55 100644 --- a/windows/nsis-plugins/src/cleanup/cleaningops.cpp +++ b/windows/nsis-plugins/src/cleanup/cleaningops.cpp @@ -5,7 +5,7 @@ #include <libcommon/string.h> #include <libcommon/memory.h> #include <libcommon/security.h> -#include <libcommon/process.h> +#include <libcommon/process/process.h> #include <filesystem> #include <utility> #include <functional> diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.cpp b/windows/nsis-plugins/src/driverlogic/driverlogic.cpp index e57b08327b..d82cde2f4d 100644 --- a/windows/nsis-plugins/src/driverlogic/driverlogic.cpp +++ b/windows/nsis-plugins/src/driverlogic/driverlogic.cpp @@ -127,16 +127,11 @@ void __declspec(dllexport) NSISCALL EstablishBaseline try { - using value_type = common::ValueMapper<Context::BaselineStatus, EstablishBaselineStatus>::value_type; - - const common::ValueMapper<Context::BaselineStatus, EstablishBaselineStatus> mapper = - { - value_type(Context::BaselineStatus::NO_TAP_ADAPTERS_PRESENT, EstablishBaselineStatus::NO_TAP_ADAPTERS_PRESENT), - value_type(Context::BaselineStatus::SOME_TAP_ADAPTERS_PRESENT, EstablishBaselineStatus::SOME_TAP_ADAPTERS_PRESENT), - value_type(Context::BaselineStatus::MULLVAD_ADAPTER_PRESENT, EstablishBaselineStatus::MULLVAD_ADAPTER_PRESENT) - }; - - const auto status = mapper.map(g_context->establishBaseline()); + const auto status = common::ValueMapper::Map(g_context->establishBaseline(), { + std::make_pair(Context::BaselineStatus::NO_TAP_ADAPTERS_PRESENT, EstablishBaselineStatus::NO_TAP_ADAPTERS_PRESENT), + std::make_pair(Context::BaselineStatus::SOME_TAP_ADAPTERS_PRESENT, EstablishBaselineStatus::SOME_TAP_ADAPTERS_PRESENT), + std::make_pair(Context::BaselineStatus::MULLVAD_ADAPTER_PRESENT, EstablishBaselineStatus::MULLVAD_ADAPTER_PRESENT) + }); pushstring(L""); pushint(status); diff --git a/windows/nsis-plugins/src/tray/tray.cpp b/windows/nsis-plugins/src/tray/tray.cpp index dc5c02ea91..e86162e0fa 100644 --- a/windows/nsis-plugins/src/tray/tray.cpp +++ b/windows/nsis-plugins/src/tray/tray.cpp @@ -9,7 +9,7 @@ #include <libcommon/registry/registry.h> #include <libcommon/resourcedata.h> #include <libcommon/filesystem.h> -#include <libcommon/process.h> +#include <libcommon/process/process.h> #include <libcommon/security.h> #include <nsis/pluginapi.h> #include <stdexcept> diff --git a/windows/windns/src/windns/netsh.cpp b/windows/windns/src/windns/netsh.cpp index d8354e4e0b..8129c4b207 100644 --- a/windows/windns/src/windns/netsh.cpp +++ b/windows/windns/src/windns/netsh.cpp @@ -11,7 +11,7 @@ namespace { -__declspec(noreturn) void ThrowWithDetails(std::string &&error, common::ApplicationRunner &netsh) +__declspec(noreturn) void ThrowWithDetails(std::string &&error, common::process::ApplicationRunner &netsh) { std::string details("Failed to capture output from 'netsh'"); @@ -65,7 +65,7 @@ void NetSh::setIpv4StaticDns(uint32_t interfaceIndex, << nameServers[0] << L" validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); + auto netsh = common::process::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); validateShellOut(*netsh, timeout); } @@ -86,7 +86,7 @@ void NetSh::setIpv4StaticDns(uint32_t interfaceIndex, << i + 1 << L" validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); + auto netsh = common::process::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); validateShellOut(*netsh, timeout); } @@ -106,7 +106,7 @@ void NetSh::setIpv4DhcpDns(uint32_t interfaceIndex, uint32_t timeout) << interfaceIndex << L" source=dhcp"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); + auto netsh = common::process::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); validateShellOut(*netsh, timeout); } @@ -137,7 +137,7 @@ void NetSh::setIpv6StaticDns(uint32_t interfaceIndex, << nameServers[0] << L" validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); + auto netsh = common::process::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); validateShellOut(*netsh, timeout); } @@ -158,7 +158,7 @@ void NetSh::setIpv6StaticDns(uint32_t interfaceIndex, << i + 1 << L" validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); + auto netsh = common::process::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); validateShellOut(*netsh, timeout); } @@ -178,12 +178,12 @@ void NetSh::setIpv6DhcpDns(uint32_t interfaceIndex, uint32_t timeout) << interfaceIndex << L" source=dhcp"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); + auto netsh = common::process::ApplicationRunner::StartWithoutConsole(m_netShPath, ss.str()); validateShellOut(*netsh, timeout); } -void NetSh::validateShellOut(common::ApplicationRunner &netsh, uint32_t timeout) +void NetSh::validateShellOut(common::process::ApplicationRunner &netsh, uint32_t timeout) { const uint32_t actualTimeout = (0 == timeout ? 10000 : timeout); diff --git a/windows/windns/src/windns/netsh.h b/windows/windns/src/windns/netsh.h index 3b0b2b0251..732a151a65 100644 --- a/windows/windns/src/windns/netsh.h +++ b/windows/windns/src/windns/netsh.h @@ -1,7 +1,7 @@ #pragma once #include <libcommon/logging/ilogsink.h> -#include <libcommon/applicationrunner.h> +#include <libcommon/process/applicationrunner.h> #include <string> #include <vector> #include <cstdint> @@ -29,5 +29,5 @@ private: std::shared_ptr<common::logging::ILogSink> m_logSink; std::wstring m_netShPath; - void validateShellOut(common::ApplicationRunner &netsh, uint32_t timeout); + void validateShellOut(common::process::ApplicationRunner &netsh, uint32_t timeout); }; diff --git a/windows/windows-libraries b/windows/windows-libraries -Subproject a1a8fa847b29d828c45127d285ad506d1c38639 +Subproject 95ef76dc8700fd9369bd7b8f507b103ceaefd3c diff --git a/windows/winnet/src/winnet/winnet.cpp b/windows/winnet/src/winnet/winnet.cpp index 3c8f133d57..55bfca5b39 100644 --- a/windows/winnet/src/winnet/winnet.cpp +++ b/windows/winnet/src/winnet/winnet.cpp @@ -7,6 +7,7 @@ #include <libshared/logging/unwind.h>
#include <libshared/network/interfaceutils.h>
#include <libcommon/error.h>
+#include <libcommon/valuemapper.h>
#include <libcommon/network.h>
#include <cstdint>
#include <stdexcept>
@@ -522,26 +523,6 @@ WinNet_DeleteRoute( }
}
-//
-// TODO: Move to libcommon.
-//
-struct ValueMapper
-{
- template<typename T, typename U, std::size_t S>
- static U map(T t, const std::pair<T, U> (&dictionary)[S])
- {
- for (const auto &entry : dictionary)
- {
- if (t == entry.first)
- {
- return entry.second;
- }
- }
-
- throw std::runtime_error("Could not map between values");
- }
-};
-
extern "C"
WINNET_LINKAGE
bool
@@ -577,7 +558,7 @@ WinNet_RegisterDefaultRouteChangedCallback( { from_t::Removed, WINNET_DEFAULT_ROUTE_CHANGED_EVENT_TYPE_REMOVED }
};
- const auto translatedEventType = ValueMapper::map<>(eventType, eventTypeMap);
+ const auto translatedEventType = common::ValueMapper::Map<>(eventType, eventTypeMap);
//
// Translate the family type.
@@ -589,7 +570,7 @@ WinNet_RegisterDefaultRouteChangedCallback( { static_cast<ADDRESS_FAMILY>(AF_INET6), WINNET_IP_FAMILY_V6 }
};
- const auto translatedFamily = ValueMapper::map<>(family, familyMap);
+ const auto translatedFamily = common::ValueMapper::Map<>(family, familyMap);
//
// Determine which LUID to forward.
diff --git a/windows/winutil/src/winutil/winutil.cpp b/windows/winutil/src/winutil/winutil.cpp index 4ea0ac27e3..b5b809a216 100644 --- a/windows/winutil/src/winutil/winutil.cpp +++ b/windows/winutil/src/winutil/winutil.cpp @@ -16,16 +16,11 @@ WinUtil_MigrateAfterWindowsUpdate( { try { - using value_type = common::ValueMapper<migration::MigrationStatus, WINUTIL_MIGRATION_STATUS>::value_type; - - const common::ValueMapper<migration::MigrationStatus, WINUTIL_MIGRATION_STATUS> mapper = - { - value_type(migration::MigrationStatus::Success, WINUTIL_MIGRATION_STATUS_SUCCESS), - value_type(migration::MigrationStatus::Aborted, WINUTIL_MIGRATION_STATUS_ABORTED), - value_type(migration::MigrationStatus::NothingToMigrate, WINUTIL_MIGRATION_STATUS_NOTHING_TO_MIGRATE), - }; - - return mapper.map(migration::MigrateAfterWindowsUpdate()); + return common::ValueMapper::Map(migration::MigrateAfterWindowsUpdate(), { + std::make_pair(migration::MigrationStatus::Success, WINUTIL_MIGRATION_STATUS_SUCCESS), + std::make_pair(migration::MigrationStatus::Aborted, WINUTIL_MIGRATION_STATUS_ABORTED), + std::make_pair(migration::MigrationStatus::NothingToMigrate, WINUTIL_MIGRATION_STATUS_NOTHING_TO_MIGRATE), + }); } catch (const std::exception &err) { |
