-
Notifications
You must be signed in to change notification settings - Fork 1
/
SGSXLApp.cpp
159 lines (129 loc) · 5.03 KB
/
SGSXLApp.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright (C) 2010,2011 by Jonathan Naylor G4KLX
* Copyright (c) 2017,2018 by Thomas A. Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include <iostream>
#include "SGSXLConfig.h"
#include "SGSXLApp.h"
#include "Version.h"
#include "IRCDDBMultiClient.h"
#include "IRCDDBClient.h"
#include "Utils.h"
#include "GitVersion.h"
int main(int argc, char *argv[])
{
setbuf(stdout, NULL);
if (2 != argc) {
printf("usage: %s path_to_config_file\n", argv[0]);
printf(" %s --version\n", argv[0]);
return 1;
}
if ('-' == argv[1][0]) {
printf("\nSmart Group Server Version %s (GitID #%.7s) Copyright (C) %s\n", VERSION.c_str(), gitversion, VENDOR_NAME.c_str());
printf("Smart Group Server XL comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0;
}
std::string cfgFile(argv[1]);
CSGSXLApp gateway(cfgFile);
if (!gateway.init()) {
return 1;
}
gateway.run();
return 0;
}
CSGSXLApp::CSGSXLApp(const std::string &configFile) : m_configFile(configFile), m_thread(NULL)
{
}
CSGSXLApp::~CSGSXLApp()
{
}
bool CSGSXLApp::init()
{
return createThread();
}
void CSGSXLApp::run()
{
m_thread->run();
printf("exiting\n");
}
bool CSGSXLApp::createThread()
{
printf("\nSmart Group Server Version %s (GitID #%.7s) Copyright (C) %s\n", VERSION.c_str(), gitversion, VENDOR_NAME.c_str());
printf("Smart Group Server XL comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
CSGSXLConfig config(m_configFile);
if(config.hasErrors()) {
printf("Configuration has one or more errors. Aborting.\n");
return false;
}
m_thread = new CSGSXLThread(config.getLinkCount("XRF"), config.getLinkCount("DCS"));
std::string CallSign, address;
config.getGateway(CallSign, address);
CallSign.resize(7, ' ');
CallSign.push_back('G');
bool audioEnabled;
TEXT_LANG audioLang;
config.getAudio(audioEnabled, audioLang);
m_thread->setLanguage(audioEnabled, audioLang);
printf("Gateway callsign set to %s, local address set to %s\n", CallSign.c_str(), address.c_str());
CIRCDDB_Array clients;
for(unsigned int i=0; i < config.getIrcDDBCount(); i++) {
std::string hostname, username, password;
bool isQuadNet;
config.getIrcDDB(i, hostname, username, password, isQuadNet);
std::cout << "ircDDB " << i + 1 << " set to " << hostname << " username set to " << username << " QuadNet " << isQuadNet << std::endl;
CIRCDDB *ircDDB = new CIRCDDBClient(hostname, 9007U, username, password, std::string("linux_SmartGroupServerXL-") + VERSION, address, isQuadNet);
clients.push_back(ircDDB);
}
CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients);
bool res = multiClient->open();
if (!res) {
printf("Cannot initialise the ircDDB protocol handler\n");
return false;
}
m_thread->setIRC(multiClient);
for (unsigned int i=0; i<config.getModCount(); i++) {
std::string band, callsign, logoff, info, permanent, reflector;
unsigned int usertimeout;
CALLSIGN_SWITCH callsignswitch;
bool txmsgswitch;
config.getGroup(i, band, callsign, logoff, info, permanent, usertimeout, callsignswitch, txmsgswitch, reflector);
if (callsign.size() && isalnum(callsign[0])) {
std::string repeater(CallSign);
repeater.resize(7, ' ');
repeater.push_back(band[0]);
m_thread->addGroup(callsign, logoff, repeater, info, permanent, usertimeout, callsignswitch, txmsgswitch, reflector);
printf("Group %d: %s/%s using %s, \"%s\", perm: %s, timeout: %u mins, c/s switch: %s, msg switch: %s, Linked: %s\n",
i, callsign.c_str(), logoff.c_str(), repeater.c_str(), info.c_str(), permanent.c_str(), usertimeout,
SCS_GROUP_CALLSIGN==callsignswitch ? "Group" : "User", txmsgswitch ? "true" : "false", reflector.c_str());
}
}
bool remoteEnabled;
std::string remotePassword;
unsigned int remotePort;
config.getRemote(remoteEnabled, remotePassword, remotePort);
printf("Remote enabled set to %d, port set to %u\n", int(remoteEnabled), remotePort);
m_thread->setRemote(remoteEnabled, remotePassword, remotePort);
m_thread->setAddress(address);
m_thread->setCallsign(CallSign);
return true;
}