summaryrefslogtreecommitdiff
path: root/src/converter/struct_to_string.cpp
diff options
context:
space:
mode:
authoreportnov <eportnov@ibs.ru>2022-10-03 11:38:05 +0300
committereportnov <eportnov@ibs.ru>2022-10-03 11:38:05 +0300
commit2b03fece7f5895591eabd2f04baa2df19b4c3417 (patch)
treef68d57d9b472cbe1186f235034b97a1be75cac08 /src/converter/struct_to_string.cpp
parent7e2843c706c1a6e033662c45957a76e01d167438 (diff)
parente41b247e61ce4d4cc96badab3a14bf413e4f46f2 (diff)
downloadobmc-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.cpp82
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 &param) 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;
+ }
+}