blob: 1372e85df775e84fffa78ba87a637e47b5a9c2d1 [file] [log] [blame]
Deepak Kodihallic4966192018-08-23 02:19:58 -05001#include "server-conf.hpp"
2#include "utils.hpp"
3#include <fstream>
4
5namespace phosphor
6{
7namespace rsyslog_config
8{
9
10namespace utils = phosphor::rsyslog_utils;
11
12std::string Server::address(std::string value)
13{
Deepak Kodihalli0febd262018-08-27 05:45:02 -050014 auto serverAddress = address();
15 if (serverAddress == value)
16 {
17 return serverAddress;
18 }
19
Deepak Kodihallic4966192018-08-23 02:19:58 -050020 writeConfig(value, port(), configFilePath.c_str());
21 auto result = NetworkClient::address(value);
22 return result;
23}
24
25uint16_t Server::port(uint16_t value)
26{
Deepak Kodihalli0febd262018-08-27 05:45:02 -050027 auto serverPort = port();
28 if (serverPort == value)
29 {
30 return serverPort;
31 }
32
Deepak Kodihallic4966192018-08-23 02:19:58 -050033 writeConfig(address(), value, configFilePath.c_str());
34 auto result = NetworkClient::port(value);
35 return result;
36}
37
38void Server::writeConfig(
39 const std::string& serverAddress,
40 uint16_t serverPort,
41 const char* filePath)
42{
Deepak Kodihalli0febd262018-08-27 05:45:02 -050043 std::fstream stream(filePath, std::fstream::out);
44
Deepak Kodihallic4966192018-08-23 02:19:58 -050045 if (serverPort && !serverAddress.empty())
46 {
Deepak Kodihalli0febd262018-08-27 05:45:02 -050047 // write '*.* @@<remote-host>:<port>'
Deepak Kodihallic4966192018-08-23 02:19:58 -050048 stream << "*.* @@" << serverAddress << ":" << serverPort;
Deepak Kodihallic4966192018-08-23 02:19:58 -050049 }
Deepak Kodihalli0febd262018-08-27 05:45:02 -050050 else // this is a disable request
51 {
52 // write '#*.* @@remote-host:port'
53 stream << "#*.* @@remote-host:port";
54 }
55
56 utils::restart();
Deepak Kodihallic4966192018-08-23 02:19:58 -050057}
58
59} // namespace rsyslog_config
60} // namespace phosphor