diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-05-25 11:22:01 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-05-25 11:22:01 +0200 |
| commit | 32e1bd67dd67652c89762a327e44ba3d47780c48 (patch) | |
| tree | f0ae4de1b7d5703a500209f876d35530f3dcb9fc /wfpctl/src/extras/cli/modules | |
| parent | 835342bcd9ccffc092825b1c96077f6af1eb9878 (diff) | |
| download | mullvadvpn-32e1bd67dd67652c89762a327e44ba3d47780c48.tar.xz mullvadvpn-32e1bd67dd67652c89762a327e44ba3d47780c48.zip | |
Move wfpctl -> windows/winfw
Diffstat (limited to 'wfpctl/src/extras/cli/modules')
| -rw-r--r-- | wfpctl/src/extras/cli/modules/imodule.h | 19 | ||||
| -rw-r--r-- | wfpctl/src/extras/cli/modules/list.h | 33 | ||||
| -rw-r--r-- | wfpctl/src/extras/cli/modules/module.cpp | 70 | ||||
| -rw-r--r-- | wfpctl/src/extras/cli/modules/module.h | 50 | ||||
| -rw-r--r-- | wfpctl/src/extras/cli/modules/monitor.h | 21 | ||||
| -rw-r--r-- | wfpctl/src/extras/cli/modules/wfpctl.h | 25 |
6 files changed, 0 insertions, 218 deletions
diff --git a/wfpctl/src/extras/cli/modules/imodule.h b/wfpctl/src/extras/cli/modules/imodule.h deleted file mode 100644 index 82221f284f..0000000000 --- a/wfpctl/src/extras/cli/modules/imodule.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "cli/propertylist.h" -#include <string> -#include <vector> - -namespace modules -{ - -struct IModule -{ - virtual std::wstring name() = 0; - virtual std::wstring description() = 0; - virtual PropertyList commands() = 0; - - virtual void handleRequest(const std::vector<std::wstring> &request) = 0; -}; - -} diff --git a/wfpctl/src/extras/cli/modules/list.h b/wfpctl/src/extras/cli/modules/list.h deleted file mode 100644 index 23751c2a26..0000000000 --- a/wfpctl/src/extras/cli/modules/list.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "module.h" -#include "cli/util.h" -#include "cli/commands/list/sessions.h" -#include "cli/commands/list/providers.h" -#include "cli/commands/list/events.h" -#include "cli/commands/list/filters.h" -#include "cli/commands/list/layers.h" -#include "cli/commands/list/providercontexts.h" -#include "cli/commands/list/sublayers.h" - -namespace modules -{ - -class List : public Module -{ -public: - - List(MessageSink messageSink) - : Module(L"list", L"List various objects in the WFP universe.") - { - addCommand(std::make_unique<commands::list::Sessions>(messageSink)); - addCommand(std::make_unique<commands::list::Providers>(messageSink)); - addCommand(std::make_unique<commands::list::Events>(messageSink)); - addCommand(std::make_unique<commands::list::Filters>(messageSink)); - addCommand(std::make_unique<commands::list::Layers>(messageSink)); - addCommand(std::make_unique<commands::list::ProviderContexts>(messageSink)); - addCommand(std::make_unique<commands::list::Sublayers>(messageSink)); - } -}; - -} diff --git a/wfpctl/src/extras/cli/modules/module.cpp b/wfpctl/src/extras/cli/modules/module.cpp deleted file mode 100644 index f66ae5a084..0000000000 --- a/wfpctl/src/extras/cli/modules/module.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "stdafx.h" -#include "module.h" -#include "cli/util.h" -#include "libcommon/string.h" -#include <sstream> -#include <utility> - -namespace modules -{ - -PropertyList Module::commands() -{ - PropertyList c; - - for (auto &command : m_commands) - { - c.add(common::string::Lower(command.second->name()), command.second->description()); - } - - return c; -} - -void Module::handleRequest(const std::vector<std::wstring> &request) -{ - // - // The request has the form of: - // - // [0] command - // [1] arg1 - // [2] arg2 - // ... - // - - if (request.empty()) - { - std::wstringstream ss; - - ss << L"Command missing. Try 'help " << m_name << "'."; - - throw std::runtime_error(common::string::ToAnsi(ss.str())); - } - - auto wanted = common::string::Lower(request[0]); - auto found = m_commands.find(wanted); - - if (found == m_commands.end()) - { - std::wstringstream ss; - - ss << L"Module '" << m_name << "' doesn't support the command '" << request[0] << "'."; - - throw std::runtime_error(common::string::ToAnsi(ss.str())); - } - - auto args = request; - - args.erase(args.begin()); - - found->second->handleRequest(args); -} - -void Module::addCommand(std::unique_ptr<commands::ICommand> command) -{ - m_commands.insert(std::make_pair( - common::string::Lower(command->name()), - std::move(command) - )); -} - -} diff --git a/wfpctl/src/extras/cli/modules/module.h b/wfpctl/src/extras/cli/modules/module.h deleted file mode 100644 index 45587ab7e5..0000000000 --- a/wfpctl/src/extras/cli/modules/module.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "imodule.h" -#include "cli/commands/icommand.h" -#include <map> -#include <memory> - -namespace modules -{ - -class Module : public IModule -{ -public: - - Module(const std::wstring &name, const std::wstring &description) - : m_name(name) - , m_description(description) - { - } - - std::wstring name() override - { - return m_name; - } - - std::wstring description() override - { - return m_description; - } - - // Collect name and description from commands. - PropertyList commands() override; - - // Identify requested command and dispatch to it. - void handleRequest(const std::vector<std::wstring> &request) override; - - void addCommand(std::unique_ptr<commands::ICommand> command); - -private: - - Module(const Module &); - Module &operator=(const Module &); - - std::wstring m_name; - std::wstring m_description; - - std::map<std::wstring, std::unique_ptr<commands::ICommand> > m_commands; -}; - -} diff --git a/wfpctl/src/extras/cli/modules/monitor.h b/wfpctl/src/extras/cli/modules/monitor.h deleted file mode 100644 index e227192e82..0000000000 --- a/wfpctl/src/extras/cli/modules/monitor.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "module.h" -#include "cli/util.h" -#include "cli/commands/monitor/m_events.h" - -namespace modules -{ - -class Monitor : public Module -{ -public: - - Monitor(MessageSink messageSink) - : Module(L"monitor", L"Real-time monitoring of events and object creation/deletion in WFP.") - { - addCommand(std::make_unique<commands::monitor::Events>(messageSink)); - } -}; - -} diff --git a/wfpctl/src/extras/cli/modules/wfpctl.h b/wfpctl/src/extras/cli/modules/wfpctl.h deleted file mode 100644 index b690454e19..0000000000 --- a/wfpctl/src/extras/cli/modules/wfpctl.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "module.h" -#include "cli/util.h" -#include "cli/commands/wfpctl/init.h" -#include "cli/commands/wfpctl/deinit.h" -#include "cli/commands/wfpctl/policy.h" - -namespace modules -{ - -class Wfpctl : public Module -{ -public: - - Wfpctl(MessageSink messageSink) - : Module(L"wfpctl", L"Exercise functionality provided by \"wfpctl.dll\".") - { - addCommand(std::make_unique<commands::wfpctl::Init>(messageSink)); - addCommand(std::make_unique<commands::wfpctl::Deinit>(messageSink)); - addCommand(std::make_unique<commands::wfpctl::Policy>(messageSink)); - } -}; - -} |
