diff options
author | eportnov <eportnov@ibs.ru> | 2022-10-03 11:37:47 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-10-03 11:37:47 +0300 |
commit | e41b247e61ce4d4cc96badab3a14bf413e4f46f2 (patch) | |
tree | f68d57d9b472cbe1186f235034b97a1be75cac08 /src/converter/file_to_struct.cpp | |
parent | 7e2843c706c1a6e033662c45957a76e01d167438 (diff) | |
download | obmc-sila-smtp-e41b247e61ce4d4cc96badab3a14bf413e4f46f2.tar.xz |
refactoring
Diffstat (limited to 'src/converter/file_to_struct.cpp')
-rw-r--r-- | src/converter/file_to_struct.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/converter/file_to_struct.cpp b/src/converter/file_to_struct.cpp new file mode 100644 index 0000000..4c4bec8 --- /dev/null +++ b/src/converter/file_to_struct.cpp @@ -0,0 +1,87 @@ +#include "file_to_struct.hpp" + +namespace smtp::converter +{ + manage::SettingsFields FileToStruct::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 FileToStruct::ApplyAuth( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "is_need_auth"; + + ApplyBool(from, FIELD, result.is_need_auth); + } + + void FileToStruct::ApplySsl( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "is_need_ssl"; + + ApplyBool(from, FIELD, result.is_need_ssl); + } + + void FileToStruct::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); + } + + void FileToStruct::ApplyUsername( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "username"; + + ApplyString( from, FIELD, result.username ); + } + + void FileToStruct::ApplyPassword( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "password"; + + ApplyString( from, FIELD, result.password ); + } + + void FileToStruct::ApplyHost( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "host"; + + ApplyString( from, FIELD, result.host ); + } + + void FileToStruct::ApplyPort( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + { + static const std::string FIELD = "port"; + + ApplyString(from, FIELD, result.port); + } + + void FileToStruct::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; + } +} |