diff options
Diffstat (limited to 'src/converter/string.cpp')
-rw-r--r-- | src/converter/string.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
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; + } +} |