summaryrefslogtreecommitdiff
path: root/src/converter/string.cpp
blob: 149d8b60d3ee1a36a6417fd41f5f86efa637fa32 (plain)
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 "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 = "is_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 = "is_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 &param) 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;
    }
}