1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include "struct_to_string.hpp"
namespace smtp::converter
{
std::string StructToString::Convert( general::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( general::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( general::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( general::SettingsFields const& from, std::string& result ) const
{
static const std::string FIELD = "username";
result += GetStringParam( FIELD, from.username );
}
void StructToString::ApplyPassword( general::SettingsFields const& from, std::string& result ) const
{
static const std::string FIELD = "password";
result += GetStringParam( FIELD, from.password );
}
void StructToString::ApplyHost( general::SettingsFields const& from, std::string& result ) const
{
static const std::string FIELD = "host";
result += GetStringParam( FIELD, from.host );
}
void StructToString::ApplyPort( general::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;
}
}
|