diff options
author | eportnov <eportnov@ibs.ru> | 2022-09-14 09:44:52 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-09-14 09:44:52 +0300 |
commit | a78e04585b2d4097a88ab681c1beebe8fe9586a1 (patch) | |
tree | 0c7b4585ba47af057db150f6226ffcdeca66c7ba /src/converter/file.cpp | |
parent | bab12f829beb53feb6f48db7a0ef33574740989c (diff) | |
parent | 942b22b2ef5ba188ea077dd545c5f240a043cf6f (diff) | |
download | obmc-sila-smtp-a78e04585b2d4097a88ab681c1beebe8fe9586a1.tar.xz |
Merge branch 'feature/add_new_interfaces'
Diffstat (limited to 'src/converter/file.cpp')
-rw-r--r-- | src/converter/file.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
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; + } +} |