|
|
|
|
@ -35,11 +35,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
class IRCDDBAppUserObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
std::string nick;
|
|
|
|
|
std::string name;
|
|
|
|
|
std::string host;
|
|
|
|
|
bool op;
|
|
|
|
|
unsigned int usn;
|
|
|
|
|
std::string m_nick;
|
|
|
|
|
std::string m_name;
|
|
|
|
|
std::string m_host;
|
|
|
|
|
bool m_op;
|
|
|
|
|
unsigned int m_usn;
|
|
|
|
|
|
|
|
|
|
IRCDDBAppUserObject()
|
|
|
|
|
{
|
|
|
|
|
@ -48,20 +48,20 @@ public:
|
|
|
|
|
|
|
|
|
|
IRCDDBAppUserObject(const std::string& n, const std::string& nm, const std::string& h)
|
|
|
|
|
{
|
|
|
|
|
nick = n;
|
|
|
|
|
name = nm;
|
|
|
|
|
host = h;
|
|
|
|
|
op = false;
|
|
|
|
|
usn = 0;
|
|
|
|
|
m_nick = n;
|
|
|
|
|
m_name = nm;
|
|
|
|
|
m_host = h;
|
|
|
|
|
m_op = false;
|
|
|
|
|
m_usn = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IRCDDBAppRptrObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
std::string arearp_cs;
|
|
|
|
|
time_t lastChanged;
|
|
|
|
|
std::string zonerp_cs;
|
|
|
|
|
std::string m_arearp_cs;
|
|
|
|
|
time_t m_lastChanged;
|
|
|
|
|
std::string m_zonerp_cs;
|
|
|
|
|
|
|
|
|
|
IRCDDBAppRptrObject ()
|
|
|
|
|
{
|
|
|
|
|
@ -69,9 +69,9 @@ public:
|
|
|
|
|
|
|
|
|
|
IRCDDBAppRptrObject (time_t &dt, std::string& repeaterCallsign, std::string& gatewayCallsign, time_t &maxTime)
|
|
|
|
|
{
|
|
|
|
|
arearp_cs = repeaterCallsign;
|
|
|
|
|
lastChanged = dt;
|
|
|
|
|
zonerp_cs = gatewayCallsign;
|
|
|
|
|
m_arearp_cs = repeaterCallsign;
|
|
|
|
|
m_lastChanged = dt;
|
|
|
|
|
m_zonerp_cs = gatewayCallsign;
|
|
|
|
|
|
|
|
|
|
if (dt > maxTime)
|
|
|
|
|
maxTime = dt;
|
|
|
|
|
@ -82,10 +82,10 @@ class IRCDDBAppPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
IRCDDBAppPrivate()
|
|
|
|
|
: tablePattern("^[0-9]$")
|
|
|
|
|
, datePattern("^20[0-9][0-9]-((1[0-2])|(0[1-9]))-((3[01])|([12][0-9])|(0[1-9]))$")
|
|
|
|
|
, timePattern("^((2[0-3])|([01][0-9])):[0-5][0-9]:[0-5][0-9]$")
|
|
|
|
|
, dbPattern("^[0-9A-Z_]{8}$")
|
|
|
|
|
: m_tablePattern("^[0-9]$")
|
|
|
|
|
, m_datePattern("^20[0-9][0-9]-((1[0-2])|(0[1-9]))-((3[01])|([12][0-9])|(0[1-9]))$")
|
|
|
|
|
, m_timePattern("^((2[0-3])|([01][0-9])):[0-5][0-9]:[0-5][0-9]$")
|
|
|
|
|
, m_dbPattern("^[0-9A-Z_]{8}$")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -97,35 +97,35 @@ public:
|
|
|
|
|
IRCMessageQueue *sendQ;
|
|
|
|
|
IRCMessageQueue replyQ;
|
|
|
|
|
|
|
|
|
|
std::string currentServer;
|
|
|
|
|
std::string myNick;
|
|
|
|
|
std::string updateChannel;
|
|
|
|
|
std::string channelTopic;
|
|
|
|
|
std::string bestServer;
|
|
|
|
|
std::string m_currentServer;
|
|
|
|
|
std::string m_myNick;
|
|
|
|
|
std::string m_updateChannel;
|
|
|
|
|
std::string m_channelTopic;
|
|
|
|
|
std::string m_bestServer;
|
|
|
|
|
|
|
|
|
|
std::regex tablePattern;
|
|
|
|
|
std::regex datePattern;
|
|
|
|
|
std::regex timePattern;
|
|
|
|
|
std::regex dbPattern;
|
|
|
|
|
std::regex m_tablePattern;
|
|
|
|
|
std::regex m_datePattern;
|
|
|
|
|
std::regex m_timePattern;
|
|
|
|
|
std::regex m_dbPattern;
|
|
|
|
|
|
|
|
|
|
bool initReady;
|
|
|
|
|
bool terminateThread;
|
|
|
|
|
bool m_initReady;
|
|
|
|
|
bool m_terminateThread;
|
|
|
|
|
|
|
|
|
|
std::map<std::string, IRCDDBAppUserObject> user;
|
|
|
|
|
std::mutex userMapMutex;
|
|
|
|
|
std::map<std::string, IRCDDBAppUserObject> m_userMap;
|
|
|
|
|
std::mutex m_userMapMutex;
|
|
|
|
|
|
|
|
|
|
std::map<std::string, IRCDDBAppRptrObject> rptrMap;
|
|
|
|
|
std::mutex rptrMapMutex;
|
|
|
|
|
std::map<std::string, IRCDDBAppRptrObject> m_rptrMap;
|
|
|
|
|
std::mutex m_rptrMapMutex;
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> moduleQRG;
|
|
|
|
|
std::mutex moduleQRGMutex;
|
|
|
|
|
std::map<std::string, std::string> m_moduleQRG;
|
|
|
|
|
std::mutex m_moduleQRGMutex;
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> moduleQTH;
|
|
|
|
|
std::map<std::string, std::string> moduleURL;
|
|
|
|
|
std::mutex moduleQTHURLMutex;
|
|
|
|
|
std::map<std::string, std::string> m_moduleQTH;
|
|
|
|
|
std::map<std::string, std::string> m_moduleURL;
|
|
|
|
|
std::mutex m_moduleQTHURLMutex;
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> moduleWD;
|
|
|
|
|
std::mutex moduleWDMutex;
|
|
|
|
|
std::map<std::string, std::string> m_moduleWD;
|
|
|
|
|
std::mutex m_moduleWDMutex;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IRCDDBApp::IRCDDBApp(const std::string& u_chan)
|
|
|
|
|
@ -133,17 +133,17 @@ IRCDDBApp::IRCDDBApp(const std::string& u_chan)
|
|
|
|
|
, m_maxTime((time_t)950000000) //februray 2000
|
|
|
|
|
{
|
|
|
|
|
d->sendQ = NULL;
|
|
|
|
|
d->initReady = false;
|
|
|
|
|
d->m_initReady = false;
|
|
|
|
|
|
|
|
|
|
userListReset();
|
|
|
|
|
|
|
|
|
|
d->state = 0;
|
|
|
|
|
d->timer = 0;
|
|
|
|
|
d->myNick = std::string("none");
|
|
|
|
|
d->m_myNick = std::string("none");
|
|
|
|
|
|
|
|
|
|
d->updateChannel = u_chan;
|
|
|
|
|
d->m_updateChannel = u_chan;
|
|
|
|
|
|
|
|
|
|
d->terminateThread = false;
|
|
|
|
|
d->m_terminateThread = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRCDDBApp::~IRCDDBApp()
|
|
|
|
|
@ -177,11 +177,11 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon
|
|
|
|
|
CUtils::ReplaceChar(d2, ' ', '_');
|
|
|
|
|
CUtils::ReplaceChar(cs, ' ', '_');
|
|
|
|
|
|
|
|
|
|
std::lock_guard lochQTHURL(d->moduleQTHURLMutex);
|
|
|
|
|
std::lock_guard lochQTHURL(d->m_moduleQTHURLMutex);
|
|
|
|
|
|
|
|
|
|
d->moduleQTH[cs] = cs + std::string(" ") + pos + std::string(" ") + d1 + std::string(" ") + d2;
|
|
|
|
|
d->m_moduleQTH[cs] = cs + std::string(" ") + pos + std::string(" ") + d1 + std::string(" ") + d2;
|
|
|
|
|
|
|
|
|
|
CLog::logInfo("QTH: %s\n", d->moduleQTH[cs].c_str());
|
|
|
|
|
CLog::logInfo("QTH: %s\n", d->m_moduleQTH[cs].c_str());
|
|
|
|
|
|
|
|
|
|
std::string url = infoURL;
|
|
|
|
|
|
|
|
|
|
@ -190,8 +190,8 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon
|
|
|
|
|
url.erase(sm.position(0), sm.length());
|
|
|
|
|
|
|
|
|
|
if (url.size()) {
|
|
|
|
|
d->moduleURL[cs] = cs + std::string(" ") + url;
|
|
|
|
|
CLog::logInfo("URL: %s\n", d->moduleURL[cs].c_str());
|
|
|
|
|
d->m_moduleURL[cs] = cs + std::string(" ") + url;
|
|
|
|
|
CLog::logInfo("URL: %s\n", d->m_moduleURL[cs].c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->infoTimer = 5; // send info in 5 seconds
|
|
|
|
|
@ -207,9 +207,9 @@ void IRCDDBApp::rptrQRG(const std::string& callsign, double txFrequency, double
|
|
|
|
|
std::string f(fstr);
|
|
|
|
|
CUtils::ReplaceChar(f, ',', '.');
|
|
|
|
|
|
|
|
|
|
std::lock_guard lockModuleQRG(d->moduleQRGMutex);
|
|
|
|
|
d->moduleQRG[cs] = cs + std::string(" ") + f;
|
|
|
|
|
CLog::logInfo("QRG: %s\n", d->moduleQRG[cs].c_str());
|
|
|
|
|
std::lock_guard lockModuleQRG(d->m_moduleQRGMutex);
|
|
|
|
|
d->m_moduleQRG[cs] = cs + std::string(" ") + f;
|
|
|
|
|
CLog::logInfo("QRG: %s\n", d->m_moduleQRG[cs].c_str());
|
|
|
|
|
|
|
|
|
|
d->infoTimer = 5; // send info in 5 seconds
|
|
|
|
|
}
|
|
|
|
|
@ -227,8 +227,8 @@ void IRCDDBApp::kickWatchdog(const std::string& callsign, const std::string& s)
|
|
|
|
|
std::string cs = callsign;
|
|
|
|
|
CUtils::ReplaceChar(cs, ' ', '_');
|
|
|
|
|
|
|
|
|
|
std::lock_guard lockModuleWD(d->moduleWDMutex);
|
|
|
|
|
d->moduleWD[cs] = cs + std::string(" ") + text;
|
|
|
|
|
std::lock_guard lockModuleWD(d->m_moduleWDMutex);
|
|
|
|
|
d->m_moduleWD[cs] = cs + std::string(" ") + text;
|
|
|
|
|
d->wdTimer = 60;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -267,13 +267,13 @@ IRCMessage *IRCDDBApp::getReplyMessage()
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::startWork()
|
|
|
|
|
{
|
|
|
|
|
d->terminateThread = false;
|
|
|
|
|
d->m_terminateThread = false;
|
|
|
|
|
m_future = std::async(std::launch::async, &IRCDDBApp::Entry, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::stopWork()
|
|
|
|
|
{
|
|
|
|
|
d->terminateThread = true;
|
|
|
|
|
d->m_terminateThread = true;
|
|
|
|
|
m_future.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -286,10 +286,10 @@ unsigned int IRCDDBApp::calculateUsn(const std::string& nick)
|
|
|
|
|
for (int i = 1; i <= 4; i++) {
|
|
|
|
|
std::string ircUser = lnick + std::to_string(i);
|
|
|
|
|
|
|
|
|
|
if (d->user.count(ircUser) == 1) {
|
|
|
|
|
IRCDDBAppUserObject obj = d->user[ircUser];
|
|
|
|
|
if (obj.usn > maxUsn)
|
|
|
|
|
maxUsn = obj.usn;
|
|
|
|
|
if (d->m_userMap.count(ircUser) == 1) {
|
|
|
|
|
IRCDDBAppUserObject obj = d->m_userMap[ircUser];
|
|
|
|
|
if (obj.m_usn > maxUsn)
|
|
|
|
|
maxUsn = obj.m_usn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return maxUsn + 1;
|
|
|
|
|
@ -297,17 +297,17 @@ unsigned int IRCDDBApp::calculateUsn(const std::string& nick)
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::userJoin(const std::string& nick, const std::string& name, const std::string& host)
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard lockUserMap(d->userMapMutex);
|
|
|
|
|
std::lock_guard lockUserMap(d->m_userMapMutex);
|
|
|
|
|
|
|
|
|
|
std::string lnick = nick;
|
|
|
|
|
CUtils::ToLower(lnick);
|
|
|
|
|
|
|
|
|
|
IRCDDBAppUserObject u(lnick, name, host);
|
|
|
|
|
u.usn = calculateUsn(lnick);
|
|
|
|
|
u.m_usn = calculateUsn(lnick);
|
|
|
|
|
|
|
|
|
|
d->user[lnick] = u;
|
|
|
|
|
d->m_userMap[lnick] = u;
|
|
|
|
|
|
|
|
|
|
if (d->initReady) {
|
|
|
|
|
if (d->m_initReady) {
|
|
|
|
|
std::string::size_type hyphenPos = nick.find('-');
|
|
|
|
|
|
|
|
|
|
if ((hyphenPos >= 4) && (hyphenPos <= 6)) {
|
|
|
|
|
@ -329,25 +329,25 @@ void IRCDDBApp::userLeave(const std::string& nick)
|
|
|
|
|
std::string lnick = nick;
|
|
|
|
|
CUtils::ToLower(lnick);
|
|
|
|
|
|
|
|
|
|
std::lock_guard lockUserMap(d->userMapMutex);
|
|
|
|
|
d->user.erase(lnick);
|
|
|
|
|
std::lock_guard lockUserMap(d->m_userMapMutex);
|
|
|
|
|
d->m_userMap.erase(lnick);
|
|
|
|
|
|
|
|
|
|
if (d->currentServer.size()) {
|
|
|
|
|
if (d->user.count(d->myNick) != 1) {
|
|
|
|
|
if (d->m_currentServer.size()) {
|
|
|
|
|
if (d->m_userMap.count(d->m_myNick) != 1) {
|
|
|
|
|
CLog::logInfo("IRCDDBApp::userLeave: could not find own nick\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRCDDBAppUserObject me = d->user[d->myNick];
|
|
|
|
|
IRCDDBAppUserObject me = d->m_userMap[d->m_myNick];
|
|
|
|
|
|
|
|
|
|
if (me.op == false) {
|
|
|
|
|
if (me.m_op == false) {
|
|
|
|
|
// if I am not op, then look for new server
|
|
|
|
|
|
|
|
|
|
if (0 == d->currentServer.compare(lnick)) {
|
|
|
|
|
// currentServer = null;
|
|
|
|
|
if (0 == d->m_currentServer.compare(lnick)) {
|
|
|
|
|
// m_currentServer = null;
|
|
|
|
|
d->state = 2; // choose new server
|
|
|
|
|
d->timer = 200;
|
|
|
|
|
d->initReady = false;
|
|
|
|
|
d->m_initReady = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -355,39 +355,39 @@ void IRCDDBApp::userLeave(const std::string& nick)
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::userListReset()
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard lockUserMap(d->userMapMutex);
|
|
|
|
|
d->user.clear();
|
|
|
|
|
std::lock_guard lockUserMap(d->m_userMapMutex);
|
|
|
|
|
d->m_userMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::setCurrentNick(const std::string& nick)
|
|
|
|
|
{
|
|
|
|
|
d->myNick = nick;
|
|
|
|
|
d->m_myNick = nick;
|
|
|
|
|
CLog::logInfo("IRCDDBApp::setCurrentNick %s\n", nick.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::setBestServer(const std::string& ircUser)
|
|
|
|
|
{
|
|
|
|
|
d->bestServer = ircUser;
|
|
|
|
|
d->m_bestServer = ircUser;
|
|
|
|
|
CLog::logInfo("IRCDDBApp::setBestServer %s\n", ircUser.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::setTopic(const std::string& topic)
|
|
|
|
|
{
|
|
|
|
|
d->channelTopic = topic;
|
|
|
|
|
d->m_channelTopic = topic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IRCDDBApp::findServerUser()
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
std::lock_guard lockUserMap(d->userMapMutex);
|
|
|
|
|
std::lock_guard lockUserMap(d->m_userMapMutex);
|
|
|
|
|
|
|
|
|
|
std::map<std::string, IRCDDBAppUserObject>::iterator it;
|
|
|
|
|
|
|
|
|
|
for (it = d->user.begin(); it != d->user.end(); ++it) {
|
|
|
|
|
for (it = d->m_userMap.begin(); it != d->m_userMap.end(); ++it) {
|
|
|
|
|
IRCDDBAppUserObject u = it->second;
|
|
|
|
|
|
|
|
|
|
if (0==u.nick.compare(0, 2, "s-") && u.op && d->myNick.compare(u.nick) && 0==u.nick.compare(d->bestServer)) {
|
|
|
|
|
d->currentServer = u.nick;
|
|
|
|
|
if (0==u.m_nick.compare(0, 2, "s-") && u.m_op && d->m_myNick.compare(u.m_nick) && 0==u.m_nick.compare(d->m_bestServer)) {
|
|
|
|
|
d->m_currentServer = u.m_nick;
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -397,12 +397,12 @@ bool IRCDDBApp::findServerUser()
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (8 == d->bestServer.size()) {
|
|
|
|
|
for (it = d->user.begin(); it != d->user.end(); ++it) {
|
|
|
|
|
if (8 == d->m_bestServer.size()) {
|
|
|
|
|
for (it = d->m_userMap.begin(); it != d->m_userMap.end(); ++it) {
|
|
|
|
|
IRCDDBAppUserObject u = it->second;
|
|
|
|
|
|
|
|
|
|
if (0==u.nick.compare(d->bestServer.substr(0,7)) && u.op && d->myNick.compare(u.nick) ) {
|
|
|
|
|
d->currentServer = u.nick;
|
|
|
|
|
if (0==u.m_nick.compare(d->m_bestServer.substr(0,7)) && u.m_op && d->m_myNick.compare(u.m_nick) ) {
|
|
|
|
|
d->m_currentServer = u.m_nick;
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -413,10 +413,10 @@ bool IRCDDBApp::findServerUser()
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (it = d->user.begin(); it != d->user.end(); ++it) {
|
|
|
|
|
for (it = d->m_userMap.begin(); it != d->m_userMap.end(); ++it) {
|
|
|
|
|
IRCDDBAppUserObject u = it->second;
|
|
|
|
|
if (0==u.nick.compare(0, 2, "s-") && u.op && d->myNick.compare(u.nick)) {
|
|
|
|
|
d->currentServer = u.nick;
|
|
|
|
|
if (0==u.m_nick.compare(0, 2, "s-") && u.m_op && d->m_myNick.compare(u.m_nick)) {
|
|
|
|
|
d->m_currentServer = u.m_nick;
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -426,13 +426,13 @@ bool IRCDDBApp::findServerUser()
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::userChanOp(const std::string& nick, bool op)
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard lockUserMap(d->userMapMutex);
|
|
|
|
|
std::lock_guard lockUserMap(d->m_userMapMutex);
|
|
|
|
|
|
|
|
|
|
std::string lnick = nick;
|
|
|
|
|
CUtils::ToLower(lnick);
|
|
|
|
|
|
|
|
|
|
if (d->user.count(lnick) == 1)
|
|
|
|
|
d->user[lnick].op = op;
|
|
|
|
|
if (d->m_userMap.count(lnick) == 1)
|
|
|
|
|
d->m_userMap[lnick].m_op = op;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const int numberOfTables = 2;
|
|
|
|
|
@ -446,16 +446,16 @@ std::string IRCDDBApp::getIPAddress(std::string& zonerp_cs)
|
|
|
|
|
CUtils::ToLower(gw);
|
|
|
|
|
CUtils::Trim(gw);
|
|
|
|
|
|
|
|
|
|
std::lock_guard lockUserMap(d->userMapMutex);
|
|
|
|
|
std::lock_guard lockUserMap(d->m_userMapMutex);
|
|
|
|
|
for (int j=1; j <= 4; j++) {
|
|
|
|
|
std::string ircUser = gw + std::string("-") + std::to_string(j);
|
|
|
|
|
|
|
|
|
|
if (d->user.count(ircUser) == 1) {
|
|
|
|
|
IRCDDBAppUserObject o = d->user[ircUser];
|
|
|
|
|
if (d->m_userMap.count(ircUser) == 1) {
|
|
|
|
|
IRCDDBAppUserObject o = d->m_userMap[ircUser];
|
|
|
|
|
|
|
|
|
|
if (o.usn >= max_usn) {
|
|
|
|
|
max_usn = o.usn;
|
|
|
|
|
ipAddr = o.host.c_str();
|
|
|
|
|
if (o.m_usn >= max_usn) {
|
|
|
|
|
max_usn = o.m_usn;
|
|
|
|
|
ipAddr = o.m_host.c_str();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -509,7 +509,7 @@ static void findReflector(const std::string& rptrCall, IRCDDBAppPrivate *d)
|
|
|
|
|
|
|
|
|
|
bool IRCDDBApp::findRepeater(const std::string& rptrCall)
|
|
|
|
|
{
|
|
|
|
|
if (0==rptrCall.compare(0, 3, "XRF") || 0==rptrCall.compare(0, 3, "REF")) {
|
|
|
|
|
if (0==rptrCall.compare(0, 3, "XRF") || 0==rptrCall.compare(0, 3, "REF") || 0==rptrCall.compare(0, 3, "DCS") || 0==rptrCall.compare(0, 3, "XLX") ) {
|
|
|
|
|
findReflector(rptrCall, d);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@ -519,15 +519,15 @@ bool IRCDDBApp::findRepeater(const std::string& rptrCall)
|
|
|
|
|
|
|
|
|
|
std::string s("NONE");
|
|
|
|
|
std::string zonerp_cs;
|
|
|
|
|
std::lock_guard lockRptrMap(d->rptrMapMutex);
|
|
|
|
|
std::lock_guard lockRptrMap(d->m_rptrMapMutex);
|
|
|
|
|
|
|
|
|
|
if (1 == d->rptrMap.count(arearp_cs)) {
|
|
|
|
|
IRCDDBAppRptrObject o = d->rptrMap[arearp_cs];
|
|
|
|
|
zonerp_cs = o.zonerp_cs;
|
|
|
|
|
if (1 == d->m_rptrMap.count(arearp_cs)) {
|
|
|
|
|
IRCDDBAppRptrObject o = d->m_rptrMap[arearp_cs];
|
|
|
|
|
zonerp_cs = o.m_zonerp_cs;
|
|
|
|
|
CUtils::ReplaceChar(zonerp_cs, '_', ' ');
|
|
|
|
|
zonerp_cs.resize(7, ' ');
|
|
|
|
|
zonerp_cs.push_back('G');
|
|
|
|
|
s = o.zonerp_cs;
|
|
|
|
|
s = o.m_zonerp_cs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRCMessage * m2 = new IRCMessage("IDRT_REPEATER");
|
|
|
|
|
@ -542,7 +542,7 @@ bool IRCDDBApp::findRepeater(const std::string& rptrCall)
|
|
|
|
|
void IRCDDBApp::sendDStarGatewayInfo(const std::string &subcommand, const std::vector<std::string> &pars)
|
|
|
|
|
{
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
std::string srv(d->currentServer);
|
|
|
|
|
std::string srv(d->m_currentServer);
|
|
|
|
|
if (srv.size() && d->state>=6 && q) {
|
|
|
|
|
std::string command("DStarGateway ");
|
|
|
|
|
command.append(subcommand);
|
|
|
|
|
@ -582,7 +582,7 @@ bool IRCDDBApp::sendHeard(const std::string& myCall, const std::string& myCallEx
|
|
|
|
|
|
|
|
|
|
bool statsMsg = (tx_stats.size() > 0);
|
|
|
|
|
|
|
|
|
|
std::string srv(d->currentServer);
|
|
|
|
|
std::string srv(d->m_currentServer);
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
|
|
|
|
|
if (srv.size() && d->state>=6 && q) {
|
|
|
|
|
@ -616,7 +616,7 @@ bool IRCDDBApp::sendHeard(const std::string& myCall, const std::string& myCallEx
|
|
|
|
|
|
|
|
|
|
bool IRCDDBApp::findUser(const std::string& usrCall)
|
|
|
|
|
{
|
|
|
|
|
std::string srv(d->currentServer);
|
|
|
|
|
std::string srv(d->m_currentServer);
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
|
|
|
|
|
if (srv.size()>0 && d->state>=6 && q) {
|
|
|
|
|
@ -637,7 +637,7 @@ bool IRCDDBApp::findUser(const std::string& usrCall)
|
|
|
|
|
void IRCDDBApp::msgChannel(IRCMessage *m)
|
|
|
|
|
{
|
|
|
|
|
if (0==m->getPrefixNick().compare(0, 2, "s-") && m->numParams>=2) // server msg
|
|
|
|
|
doUpdate(m->params[1]);
|
|
|
|
|
doUpdate(m->m_params[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRCDDBApp::doNotFound(std::string& msg, std::string& retval)
|
|
|
|
|
@ -651,7 +651,7 @@ void IRCDDBApp::doNotFound(std::string& msg, std::string& retval)
|
|
|
|
|
std::string tk = tkz.front();
|
|
|
|
|
tkz.erase(tkz.begin());
|
|
|
|
|
|
|
|
|
|
if (std::regex_match(tk, d->tablePattern)) {
|
|
|
|
|
if (std::regex_match(tk, d->m_tablePattern)) {
|
|
|
|
|
tableID = std::stoi(tk);
|
|
|
|
|
|
|
|
|
|
if (tableID<0 || tableID>=numberOfTables) {
|
|
|
|
|
@ -667,7 +667,7 @@ void IRCDDBApp::doNotFound(std::string& msg, std::string& retval)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (0 == tableID) {
|
|
|
|
|
if (! std::regex_match(tk, d->dbPattern))
|
|
|
|
|
if (! std::regex_match(tk, d->m_dbPattern))
|
|
|
|
|
return; // no valid key
|
|
|
|
|
retval = tk;
|
|
|
|
|
}
|
|
|
|
|
@ -683,7 +683,7 @@ void IRCDDBApp::doUpdate(std::string& msg)
|
|
|
|
|
std::string tk = tkz.front();
|
|
|
|
|
tkz.erase(tkz.begin());
|
|
|
|
|
|
|
|
|
|
if (std::regex_match(tk, d->tablePattern)) {
|
|
|
|
|
if (std::regex_match(tk, d->m_tablePattern)) {
|
|
|
|
|
tableID = std::stoi(tk);
|
|
|
|
|
if ((tableID < 0) || (tableID >= numberOfTables)) {
|
|
|
|
|
CLog::logInfo("invalid table ID %d\n", tableID);
|
|
|
|
|
@ -697,13 +697,13 @@ void IRCDDBApp::doUpdate(std::string& msg)
|
|
|
|
|
tkz.erase(tkz.begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (std::regex_match(tk, d->datePattern)) {
|
|
|
|
|
if (std::regex_match(tk, d->m_datePattern)) {
|
|
|
|
|
if (tkz.empty())
|
|
|
|
|
return; // nothing after date string
|
|
|
|
|
|
|
|
|
|
std::string timeToken = tkz.front(); // time token
|
|
|
|
|
tkz.erase(tkz.begin());
|
|
|
|
|
if (! std::regex_match(timeToken, d->timePattern))
|
|
|
|
|
if (! std::regex_match(timeToken, d->m_timePattern))
|
|
|
|
|
return; // no time string after date string
|
|
|
|
|
|
|
|
|
|
time_t dt = CUtils::parseTime(tk + std::string(" ") + timeToken);
|
|
|
|
|
@ -715,7 +715,7 @@ void IRCDDBApp::doUpdate(std::string& msg)
|
|
|
|
|
std::string key = tkz.front();
|
|
|
|
|
tkz.erase(tkz.begin());
|
|
|
|
|
|
|
|
|
|
if (! std::regex_match(key, d->dbPattern))
|
|
|
|
|
if (! std::regex_match(key, d->m_dbPattern))
|
|
|
|
|
return; // no valid key
|
|
|
|
|
|
|
|
|
|
if (tkz.empty())
|
|
|
|
|
@ -724,15 +724,15 @@ void IRCDDBApp::doUpdate(std::string& msg)
|
|
|
|
|
std::string value = tkz.front();
|
|
|
|
|
tkz.erase(tkz.begin());
|
|
|
|
|
|
|
|
|
|
if (! std::regex_match(value, d->dbPattern))
|
|
|
|
|
if (! std::regex_match(value, d->m_dbPattern))
|
|
|
|
|
return; // no valid key
|
|
|
|
|
|
|
|
|
|
if (tableID == 1) {
|
|
|
|
|
std::lock_guard lockRptrMap(d->rptrMapMutex);
|
|
|
|
|
std::lock_guard lockRptrMap(d->m_rptrMapMutex);
|
|
|
|
|
IRCDDBAppRptrObject newRptr(dt, key, value, m_maxTime);
|
|
|
|
|
d->rptrMap[key] = newRptr;
|
|
|
|
|
d->m_rptrMap[key] = newRptr;
|
|
|
|
|
|
|
|
|
|
if (d->initReady) {
|
|
|
|
|
if (d->m_initReady) {
|
|
|
|
|
std::string arearp_cs(key);
|
|
|
|
|
std::string zonerp_cs(value);
|
|
|
|
|
CUtils::ReplaceChar(arearp_cs, '_', ' ');
|
|
|
|
|
@ -746,8 +746,8 @@ void IRCDDBApp::doUpdate(std::string& msg)
|
|
|
|
|
m2->addParam(getIPAddress(value));
|
|
|
|
|
d->replyQ.putMessage(m2);
|
|
|
|
|
}
|
|
|
|
|
} else if (0==tableID && d->initReady) {
|
|
|
|
|
std::lock_guard lockRptrMap(d->rptrMapMutex);
|
|
|
|
|
} else if (0==tableID && d->m_initReady) {
|
|
|
|
|
std::lock_guard lockRptrMap(d->m_rptrMapMutex);
|
|
|
|
|
std::string userCallsign(key);
|
|
|
|
|
std::string arearp_cs(value);
|
|
|
|
|
std::string zonerp_cs;
|
|
|
|
|
@ -755,13 +755,13 @@ void IRCDDBApp::doUpdate(std::string& msg)
|
|
|
|
|
CUtils::ReplaceChar(userCallsign, '_', ' ');
|
|
|
|
|
CUtils::ReplaceChar(arearp_cs, '_', ' ');
|
|
|
|
|
|
|
|
|
|
if (1 == d->rptrMap.count(value)) {
|
|
|
|
|
IRCDDBAppRptrObject o = d->rptrMap[value];
|
|
|
|
|
zonerp_cs = o.zonerp_cs;
|
|
|
|
|
if (1 == d->m_rptrMap.count(value)) {
|
|
|
|
|
IRCDDBAppRptrObject o = d->m_rptrMap[value];
|
|
|
|
|
zonerp_cs = o.m_zonerp_cs;
|
|
|
|
|
CUtils::ReplaceChar(zonerp_cs, '_', ' ');
|
|
|
|
|
zonerp_cs.resize(7, ' ');
|
|
|
|
|
zonerp_cs.push_back('G');
|
|
|
|
|
ip_addr = getIPAddress(o.zonerp_cs);
|
|
|
|
|
ip_addr = getIPAddress(o.m_zonerp_cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRCMessage *m2 = new IRCMessage("IDRT_USER");
|
|
|
|
|
@ -793,7 +793,7 @@ static std::string getTableIDString(int tableID, bool spaceBeforeNumber)
|
|
|
|
|
void IRCDDBApp::msgQuery(IRCMessage *m)
|
|
|
|
|
{
|
|
|
|
|
if (0==m->getPrefixNick().compare(0, 2, "s-") && m->numParams>=2) { // server msg
|
|
|
|
|
std::string msg(m->params[1]);
|
|
|
|
|
std::string msg(m->m_params[1]);
|
|
|
|
|
std::vector<std::string> tkz = CUtils::stringTokenizer(msg);
|
|
|
|
|
|
|
|
|
|
if (tkz.empty())
|
|
|
|
|
@ -870,7 +870,7 @@ static bool needsDatabaseUpdate(int tableID)
|
|
|
|
|
void IRCDDBApp::Entry()
|
|
|
|
|
{
|
|
|
|
|
int sendlistTableID = 0;
|
|
|
|
|
while (!d->terminateThread) {
|
|
|
|
|
while (!d->m_terminateThread) {
|
|
|
|
|
if (d->timer > 0)
|
|
|
|
|
d->timer--;
|
|
|
|
|
switch(d->state) {
|
|
|
|
|
@ -923,7 +923,7 @@ void IRCDDBApp::Entry()
|
|
|
|
|
d->state = 10; // disconnect DB
|
|
|
|
|
else {
|
|
|
|
|
if (needsDatabaseUpdate(sendlistTableID)) {
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->currentServer, std::string("SENDLIST") + getTableIDString(sendlistTableID, true) + std::string(" ") + getLastEntryTime(sendlistTableID));
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->m_currentServer, std::string("SENDLIST") + getTableIDString(sendlistTableID, true) + std::string(" ") + getLastEntryTime(sendlistTableID));
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
if (q)
|
|
|
|
|
q->putMessage(m);
|
|
|
|
|
@ -952,7 +952,7 @@ void IRCDDBApp::Entry()
|
|
|
|
|
else {
|
|
|
|
|
CLog::logInfo( "IRCDDBApp: state=6 initialization completed\n");
|
|
|
|
|
d->infoTimer = 2;
|
|
|
|
|
d->initReady = true;
|
|
|
|
|
d->m_initReady = true;
|
|
|
|
|
d->state = 7;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
@ -966,35 +966,35 @@ void IRCDDBApp::Entry()
|
|
|
|
|
|
|
|
|
|
if (0 == d->infoTimer) {
|
|
|
|
|
{ // Scope for mutext locking
|
|
|
|
|
std::lock_guard lochQTHURL(d->moduleQTHURLMutex);
|
|
|
|
|
for (auto it = d->moduleQTH.begin(); it != d->moduleQTH.end(); ++it) {
|
|
|
|
|
std::lock_guard lochQTHURL(d->m_moduleQTHURLMutex);
|
|
|
|
|
for (auto it = d->m_moduleQTH.begin(); it != d->m_moduleQTH.end(); ++it) {
|
|
|
|
|
std::string value = it->second;
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQTH: ") + value);
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->m_currentServer, std::string("IRCDDB RPTRQTH: ") + value);
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
if (q != NULL)
|
|
|
|
|
q->putMessage(m);
|
|
|
|
|
}
|
|
|
|
|
d->moduleQTH.clear();
|
|
|
|
|
d->m_moduleQTH.clear();
|
|
|
|
|
|
|
|
|
|
for (auto it = d->moduleURL.begin(); it != d->moduleURL.end(); ++it) {
|
|
|
|
|
for (auto it = d->m_moduleURL.begin(); it != d->m_moduleURL.end(); ++it) {
|
|
|
|
|
std::string value = it->second;
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRURL: ") + value);
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->m_currentServer, std::string("IRCDDB RPTRURL: ") + value);
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
if (q != NULL)
|
|
|
|
|
q->putMessage(m);
|
|
|
|
|
}
|
|
|
|
|
d->moduleURL.clear();
|
|
|
|
|
d->m_moduleURL.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::lock_guard lockModuleQRG(d->moduleQRGMutex);
|
|
|
|
|
for (auto it = d->moduleQRG.begin(); it != d->moduleQRG.end(); ++it) {
|
|
|
|
|
std::lock_guard lockModuleQRG(d->m_moduleQRGMutex);
|
|
|
|
|
for (auto it = d->m_moduleQRG.begin(); it != d->m_moduleQRG.end(); ++it) {
|
|
|
|
|
std::string value = it->second;
|
|
|
|
|
IRCMessage* m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQRG: ") + value);
|
|
|
|
|
IRCMessage* m = new IRCMessage(d->m_currentServer, std::string("IRCDDB RPTRQRG: ") + value);
|
|
|
|
|
IRCMessageQueue* q = getSendQ();
|
|
|
|
|
if (q != NULL)
|
|
|
|
|
q->putMessage(m);
|
|
|
|
|
}
|
|
|
|
|
d->moduleQRG.clear();
|
|
|
|
|
d->m_moduleQRG.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1002,16 +1002,16 @@ void IRCDDBApp::Entry()
|
|
|
|
|
d->wdTimer--;
|
|
|
|
|
|
|
|
|
|
if (0 == d->wdTimer) {
|
|
|
|
|
std::lock_guard lockModuleWD(d->moduleWDMutex);
|
|
|
|
|
std::lock_guard lockModuleWD(d->m_moduleWDMutex);
|
|
|
|
|
|
|
|
|
|
for (auto it = d->moduleWD.begin(); it != d->moduleWD.end(); ++it) {
|
|
|
|
|
for (auto it = d->m_moduleWD.begin(); it != d->m_moduleWD.end(); ++it) {
|
|
|
|
|
std::string value = it->second;
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRSW: ") + value);
|
|
|
|
|
IRCMessage *m = new IRCMessage(d->m_currentServer, std::string("IRCDDB RPTRSW: ") + value);
|
|
|
|
|
IRCMessageQueue *q = getSendQ();
|
|
|
|
|
if (q)
|
|
|
|
|
q->putMessage(m);
|
|
|
|
|
}
|
|
|
|
|
d->moduleWD.clear();
|
|
|
|
|
d->m_moduleWD.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
@ -1020,7 +1020,7 @@ void IRCDDBApp::Entry()
|
|
|
|
|
// disconnect db
|
|
|
|
|
d->state = 0;
|
|
|
|
|
d->timer = 0;
|
|
|
|
|
d->initReady = false;
|
|
|
|
|
d->m_initReady = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|