From 942b22b2ef5ba188ea077dd545c5f240a043cf6f Mon Sep 17 00:00:00 2001 From: eportnov Date: Tue, 13 Sep 2022 17:30:47 +0300 Subject: add new interfaces --- src/converter/file.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++ src/converter/file.hpp | 30 ++++++++++++++++ src/converter/full.cpp | 17 +++++++++ src/converter/full.hpp | 23 ++++++++++++ src/converter/settings.cpp | 65 ++++++++++++++++++++++++++++++++++ src/converter/settings.hpp | 28 +++++++++++++++ src/converter/string.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++ src/converter/string.hpp | 31 +++++++++++++++++ 8 files changed, 363 insertions(+) create mode 100644 src/converter/file.cpp create mode 100644 src/converter/file.hpp create mode 100644 src/converter/full.cpp create mode 100644 src/converter/full.hpp create mode 100644 src/converter/settings.cpp create mode 100644 src/converter/settings.hpp create mode 100644 src/converter/string.cpp create mode 100644 src/converter/string.hpp (limited to 'src/converter') diff --git a/src/converter/file.cpp b/src/converter/file.cpp new file mode 100644 index 0000000..203cca9 --- /dev/null +++ b/src/converter/file.cpp @@ -0,0 +1,87 @@ +#include "file.hpp" + +namespace smtp::converter +{ + manage::SettingsFields File::Convert( manage::SettingsFileDataType const& from ) const + { + manage::SettingsFields result; + + ApplyAuth( result, from ); + ApplySsl( result, from ); + ApplyUsername( result, from ); + ApplyPassword( result, from ); + ApplyHost( result, from ); + ApplyPort( result, from ); + + return result; + } + + void File::ApplyAuth( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "need_auth"; + + ApplyBool(from, FIELD, result.is_need_auth); + } + + void File::ApplySsl( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "need_ssl"; + + ApplyBool(from, FIELD, result.is_need_ssl); + } + + void File::ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const + { + static const std::string TRUE_AS_STRING = "true"; + static const std::string FALSE_AS_STRING = "false"; + + auto find = from.find( search_field ); + if( find == from.end() ) + { + return; + } + if( find->second != TRUE_AS_STRING && find->second != FALSE_AS_STRING ) + { + return; + } + field = ( find->second == TRUE_AS_STRING ) ? true : false; + } + + void File::ApplyUsername( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "username"; + + ApplyString( from, FIELD, result.username ); + } + + void File::ApplyPassword( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "password"; + + ApplyString( from, FIELD, result.password ); + } + + void File::ApplyHost( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "host"; + + ApplyString( from, FIELD, result.host ); + } + + void File::ApplyPort( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "port"; + + ApplyString(from, FIELD, result.port); + } + + void File::ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const + { + auto find = from.find( search_field ); + if( find == from.end() ) + { + return; + } + field = find->second; + } +} diff --git a/src/converter/file.hpp b/src/converter/file.hpp new file mode 100644 index 0000000..64ef152 --- /dev/null +++ b/src/converter/file.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include "managment/general.hpp" + +namespace smtp::converter +{ + class File + { + public: + File() = default; + ~File() = default; + + manage::SettingsFields Convert( manage::SettingsFileDataType const& from ) const; + private: + void ApplyAuth( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplySsl( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const; + + void ApplyUsername( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyPassword( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyHost( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyPort( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const; + }; +} + + diff --git a/src/converter/full.cpp b/src/converter/full.cpp new file mode 100644 index 0000000..91a9816 --- /dev/null +++ b/src/converter/full.cpp @@ -0,0 +1,17 @@ +#include "full.hpp" +#include "file.hpp" +#include "settings.hpp" + +namespace smtp::converter +{ + manage::SettingsFields Full::Convert( manage::SettingsFileDataType const& from ) const + { + return File{}.Convert( from ); + } + + std::unordered_map Full::Convert( manage::SettingsFields const& from ) const + { + return Settings{}.Convert( from ); + + } +} diff --git a/src/converter/full.hpp b/src/converter/full.hpp new file mode 100644 index 0000000..7025324 --- /dev/null +++ b/src/converter/full.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "managment/general.hpp" + +namespace smtp::converter +{ + class Full + { + public: + Full() = default; + ~Full() = default; + + manage::SettingsFields Convert( std::unordered_map const& from ) const; + std::unordered_map Convert( manage::SettingsFields const& from ) const; + private: + + }; +} + + diff --git a/src/converter/settings.cpp b/src/converter/settings.cpp new file mode 100644 index 0000000..7aa2106 --- /dev/null +++ b/src/converter/settings.cpp @@ -0,0 +1,65 @@ +#include "settings.hpp" + +namespace smtp::converter +{ + + manage::SettingsFileDataType Settings::Convert( manage::SettingsFields const& from ) const + { + manage::SettingsFileDataType result; + + ApplyPort( from, result ); + ApplyHost( from, result ); + ApplyPassword( from, result ); + ApplyUsername( from, result ); + ApplySsl( from, result ); + ApplyAuth( from, result ); + + return result; + } + + void Settings::ApplyAuth( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + { + static const std::string FIELD = "need_auth"; + static const std::string TRUE_AS_STRING = "true"; + static const std::string FALSE_AS_STRING = "false"; + + from.is_need_auth ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING}); + } + + void Settings::ApplySsl( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + { + static const std::string FIELD = "need_ssl"; + static const std::string TRUE_AS_STRING = "true"; + static const std::string FALSE_AS_STRING = "false"; + + from.is_need_ssl ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING}); + } + + void Settings::ApplyUsername( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + { + static const std::string FIELD = "username"; + + result.insert({FIELD, from.username}); + } + + void Settings::ApplyPassword( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + { + static const std::string FIELD = "password"; + + result.insert({FIELD, from.password}); + } + + void Settings::ApplyHost( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + { + static const std::string FIELD = "host"; + + result.insert({FIELD, from.host}); + } + + void Settings::ApplyPort( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + { + static const std::string FIELD = "port"; + + result.insert({FIELD, from.port}); + } +} diff --git a/src/converter/settings.hpp b/src/converter/settings.hpp new file mode 100644 index 0000000..d25a550 --- /dev/null +++ b/src/converter/settings.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +#include "managment/general.hpp" + +namespace smtp::converter +{ + class Settings + { + public: + Settings() = default; + ~Settings() = default; + + std::unordered_map Convert( manage::SettingsFields const& from ) const; + private: + void ApplyAuth( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const; + void ApplySsl( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const; + + void ApplyUsername( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const; + void ApplyPassword( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const; + void ApplyHost( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const; + void ApplyPort( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const; + }; +} + + diff --git a/src/converter/string.cpp b/src/converter/string.cpp new file mode 100644 index 0000000..cbdc544 --- /dev/null +++ b/src/converter/string.cpp @@ -0,0 +1,82 @@ +#include "string.hpp" + +namespace smtp::converter +{ + std::string String::Convert( manage::SettingsFields const& from ) const + { + std::string result; + + ApplyPort( from, result ); + ApplyHost( from, result ); + ApplyPassword( from, result ); + ApplyUsername( from, result ); + ApplySsl( from, result ); + ApplyAuth( from, result ); + + return result; + } + + void String::ApplyAuth( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "need_auth"; + + result += GetBoolParam( FIELD, from.is_need_auth); + } + + void String::ApplySsl( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "need_ssl"; + + result += GetBoolParam( FIELD, from.is_need_ssl); + } + + void String::ApplyUsername( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "username"; + + result += GetStringParam( FIELD, from.username ); + } + + void String::ApplyPassword( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "password"; + + result += GetStringParam( FIELD, from.password ); + } + + void String::ApplyHost( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "host"; + + result += GetStringParam( FIELD, from.host ); + } + + void String::ApplyPort( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "port"; + + result += GetStringParam( FIELD, from.port ); + } + + std::string String::GetStringParam(const std::string &field, const std::string ¶m) const + { + std::string result; + result += field; + result += '='; + result += param; + result += '&'; + return result; + } + + std::string String::GetBoolParam(const std::string &field, bool param) const + { + std::string result; + + result += field; + result += '='; + result += param ? "true" : "false"; + result += '&'; + + return result; + } +} diff --git a/src/converter/string.hpp b/src/converter/string.hpp new file mode 100644 index 0000000..f1752ad --- /dev/null +++ b/src/converter/string.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +#include "managment/general.hpp" + +namespace smtp::converter +{ + class String + { + public: + String() = default; + ~String() = default; + + std::string Convert( manage::SettingsFields const& from ) const; + private: + void ApplyAuth( manage::SettingsFields const& from, std::string& result ) const; + void ApplySsl( manage::SettingsFields const& from, std::string& result ) const; + + void ApplyUsername( manage::SettingsFields const& from, std::string& result ) const; + void ApplyPassword( manage::SettingsFields const& from, std::string& result ) const; + void ApplyHost( manage::SettingsFields const& from, std::string& result ) const; + void ApplyPort( manage::SettingsFields const& from, std::string& result ) const; + + std::string GetStringParam( std::string const& field, std::string const& param ) const; + std::string GetBoolParam( std::string const& field, bool param ) const; + }; +} + + -- cgit v1.2.3