summaryrefslogtreecommitdiffstats
path: root/phosphor-rsyslog-config/server-conf.cpp
blob: 1372e85df775e84fffa78ba87a637e47b5a9c2d1 (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
#include "server-conf.hpp"
#include "utils.hpp"
#include <fstream>

namespace phosphor
{
namespace rsyslog_config
{

namespace utils = phosphor::rsyslog_utils;

std::string Server::address(std::string value)
{
    auto serverAddress = address();
    if (serverAddress == value)
    {
        return serverAddress;
    }

    writeConfig(value, port(), configFilePath.c_str());
    auto result = NetworkClient::address(value);
    return result;
}

uint16_t Server::port(uint16_t value)
{
    auto serverPort = port();
    if (serverPort == value)
    {
        return serverPort;
    }

    writeConfig(address(), value, configFilePath.c_str());
    auto result = NetworkClient::port(value);
    return result;
}

void Server::writeConfig(
                 const std::string& serverAddress,
                 uint16_t serverPort,
                 const char* filePath)
{
    std::fstream stream(filePath, std::fstream::out);

    if (serverPort && !serverAddress.empty())
    {
        // write '*.* @@<remote-host>:<port>'
        stream << "*.* @@" << serverAddress << ":" << serverPort;
    }
    else // this is a disable request
    {
        // write '#*.* @@remote-host:port'
        stream << "#*.* @@remote-host:port";
    }

    utils::restart();
}

} // namespace rsyslog_config
} // namespace phosphor
OpenPOWER on IntegriCloud