diff options
author | eportnov <eportnov@ibs.ru> | 2022-10-03 11:38:05 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-10-03 11:38:05 +0300 |
commit | 2b03fece7f5895591eabd2f04baa2df19b4c3417 (patch) | |
tree | f68d57d9b472cbe1186f235034b97a1be75cac08 /src/converter/struct_to_string.cpp | |
parent | 7e2843c706c1a6e033662c45957a76e01d167438 (diff) | |
parent | e41b247e61ce4d4cc96badab3a14bf413e4f46f2 (diff) | |
download | obmc-sila-smtp-2b03fece7f5895591eabd2f04baa2df19b4c3417.tar.xz |
Merge branch 'refactor/3009'
Diffstat (limited to 'src/converter/struct_to_string.cpp')
-rw-r--r-- | src/converter/struct_to_string.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/converter/struct_to_string.cpp b/src/converter/struct_to_string.cpp new file mode 100644 index 0000000..c86a6c8 --- /dev/null +++ b/src/converter/struct_to_string.cpp @@ -0,0 +1,82 @@ +#include "struct_to_string.hpp" + +namespace smtp::converter +{ + std::string StructToString::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 StructToString::ApplyAuth( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "is_need_auth"; + + result += GetBoolParam( FIELD, from.is_need_auth); + } + + void StructToString::ApplySsl( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "is_need_ssl"; + + result += GetBoolParam( FIELD, from.is_need_ssl); + } + + void StructToString::ApplyUsername( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "username"; + + result += GetStringParam( FIELD, from.username ); + } + + void StructToString::ApplyPassword( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "password"; + + result += GetStringParam( FIELD, from.password ); + } + + void StructToString::ApplyHost( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "host"; + + result += GetStringParam( FIELD, from.host ); + } + + void StructToString::ApplyPort( manage::SettingsFields const& from, std::string& result ) const + { + static const std::string FIELD = "port"; + + result += GetStringParam( FIELD, from.port ); + } + + std::string StructToString::GetStringParam(const std::string &field, const std::string ¶m) const + { + std::string result; + result += field; + result += '='; + result += param; + result += '&'; + return result; + } + + std::string StructToString::GetBoolParam(const std::string &field, bool param) const + { + std::string result; + + result += field; + result += '='; + result += param ? "true" : "false"; + result += '&'; + + return result; + } +} |