summaryrefslogtreecommitdiff
path: root/src/file/converter
diff options
context:
space:
mode:
Diffstat (limited to 'src/file/converter')
-rw-r--r--src/file/converter/file.cpp87
-rw-r--r--src/file/converter/file.hpp30
-rw-r--r--src/file/converter/full.cpp17
-rw-r--r--src/file/converter/full.hpp25
-rw-r--r--src/file/converter/settings.cpp65
-rw-r--r--src/file/converter/settings.hpp30
6 files changed, 254 insertions, 0 deletions
diff --git a/src/file/converter/file.cpp b/src/file/converter/file.cpp
new file mode 100644
index 0000000..d0bb032
--- /dev/null
+++ b/src/file/converter/file.cpp
@@ -0,0 +1,87 @@
+#include "file.hpp"
+
+namespace smtp::file::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/file/converter/file.hpp b/src/file/converter/file.hpp
new file mode 100644
index 0000000..63ff6dd
--- /dev/null
+++ b/src/file/converter/file.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <unordered_map>
+#include <string>
+
+#include "managment/general.hpp"
+
+namespace smtp::file::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/file/converter/full.cpp b/src/file/converter/full.cpp
new file mode 100644
index 0000000..61f5a85
--- /dev/null
+++ b/src/file/converter/full.cpp
@@ -0,0 +1,17 @@
+#include "full.hpp"
+#include "file.hpp"
+#include "settings.hpp"
+
+namespace smtp::file::converter
+{
+ manage::SettingsFields Full::Convert( ParsedDataType const& from ) const
+ {
+ return File{}.Convert( from );
+ }
+
+ std::unordered_map<std::string, std::string> Full::Convert( manage::SettingsFields const& from ) const
+ {
+ return Settings{}.Convert( from );
+
+ }
+}
diff --git a/src/file/converter/full.hpp b/src/file/converter/full.hpp
new file mode 100644
index 0000000..5ffccd4
--- /dev/null
+++ b/src/file/converter/full.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <unordered_map>
+#include <string>
+
+#include "managment/general.hpp"
+
+namespace smtp::file::converter
+{
+ using ParsedDataType = std::unordered_map<std::string, std::string>;
+
+ class Full
+ {
+ public:
+ Full() = default;
+ ~Full() = default;
+
+ manage::SettingsFields Convert( std::unordered_map<std::string, std::string> const& from ) const;
+ std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const;
+ private:
+
+ };
+}
+
+
diff --git a/src/file/converter/settings.cpp b/src/file/converter/settings.cpp
new file mode 100644
index 0000000..809eef8
--- /dev/null
+++ b/src/file/converter/settings.cpp
@@ -0,0 +1,65 @@
+#include "settings.hpp"
+
+namespace smtp::file::converter
+{
+
+ ParsedDataType Settings::Convert( manage::SettingsFields const& from ) const
+ {
+ ParsedDataType 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, ParsedDataType& 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, ParsedDataType& 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, ParsedDataType& result ) const
+ {
+ static const std::string FIELD = "username";
+
+ result.insert({FIELD, from.username});
+ }
+
+ void Settings::ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const
+ {
+ static const std::string FIELD = "password";
+
+ result.insert({FIELD, from.password});
+ }
+
+ void Settings::ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const
+ {
+ static const std::string FIELD = "host";
+
+ result.insert({FIELD, from.host});
+ }
+
+ void Settings::ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const
+ {
+ static const std::string FIELD = "port";
+
+ result.insert({FIELD, from.port});
+ }
+}
diff --git a/src/file/converter/settings.hpp b/src/file/converter/settings.hpp
new file mode 100644
index 0000000..8f94942
--- /dev/null
+++ b/src/file/converter/settings.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <unordered_map>
+#include <string>
+
+#include "managment/general.hpp"
+
+namespace smtp::file::converter
+{
+ using ParsedDataType = std::unordered_map<std::string, std::string>;;
+
+ class Settings
+ {
+ public:
+ Settings() = default;
+ ~Settings() = default;
+
+ std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const;
+ private:
+ void ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const;
+ void ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const;
+
+ void ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const;
+ void ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const;
+ void ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const;
+ void ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const;
+ };
+}
+
+