mirror of
https://github.com/ShaYmez/P25Clients.git
synced 2024-11-25 13:48:45 -05:00
Allow for more than one P25 hosts file.
This commit is contained in:
parent
9a19634d51
commit
fd54404691
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -47,7 +47,8 @@ m_lookupTime(0U),
|
|||||||
m_logFilePath(),
|
m_logFilePath(),
|
||||||
m_logFileRoot(),
|
m_logFileRoot(),
|
||||||
m_networkPort(0U),
|
m_networkPort(0U),
|
||||||
m_networkHosts(),
|
m_networkHosts1(),
|
||||||
|
m_networkHosts2(),
|
||||||
m_networkReloadTime(0U),
|
m_networkReloadTime(0U),
|
||||||
m_networkParrotAddress("127.0.0.1"),
|
m_networkParrotAddress("127.0.0.1"),
|
||||||
m_networkParrotPort(0U),
|
m_networkParrotPort(0U),
|
||||||
@ -125,8 +126,10 @@ bool CConf::read()
|
|||||||
} else if (section == SECTION_NETWORK) {
|
} else if (section == SECTION_NETWORK) {
|
||||||
if (::strcmp(key, "Port") == 0)
|
if (::strcmp(key, "Port") == 0)
|
||||||
m_networkPort = (unsigned int)::atoi(value);
|
m_networkPort = (unsigned int)::atoi(value);
|
||||||
else if (::strcmp(key, "Hosts") == 0)
|
else if (::strcmp(key, "HostsFile1") == 0)
|
||||||
m_networkHosts = value;
|
m_networkHosts1 = value;
|
||||||
|
else if (::strcmp(key, "HostsFile2") == 0)
|
||||||
|
m_networkHosts2 = value;
|
||||||
else if (::strcmp(key, "ReloadTime") == 0)
|
else if (::strcmp(key, "ReloadTime") == 0)
|
||||||
m_networkReloadTime = (unsigned int)::atoi(value);
|
m_networkReloadTime = (unsigned int)::atoi(value);
|
||||||
else if (::strcmp(key, "ParrotAddress") == 0)
|
else if (::strcmp(key, "ParrotAddress") == 0)
|
||||||
@ -202,9 +205,14 @@ unsigned int CConf::getNetworkPort() const
|
|||||||
return m_networkPort;
|
return m_networkPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CConf::getNetworkHosts() const
|
std::string CConf::getNetworkHosts1() const
|
||||||
{
|
{
|
||||||
return m_networkHosts;
|
return m_networkHosts1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CConf::getNetworkHosts2() const
|
||||||
|
{
|
||||||
|
return m_networkHosts2;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CConf::getNetworkReloadTime() const
|
unsigned int CConf::getNetworkReloadTime() const
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -48,7 +48,8 @@ public:
|
|||||||
|
|
||||||
// The Network section
|
// The Network section
|
||||||
unsigned int getNetworkPort() const;
|
unsigned int getNetworkPort() const;
|
||||||
std::string getNetworkHosts() const;
|
std::string getNetworkHosts1() const;
|
||||||
|
std::string getNetworkHosts2() const;
|
||||||
unsigned int getNetworkReloadTime() const;
|
unsigned int getNetworkReloadTime() const;
|
||||||
std::string getNetworkParrotAddress() const;
|
std::string getNetworkParrotAddress() const;
|
||||||
unsigned int getNetworkParrotPort() const;
|
unsigned int getNetworkParrotPort() const;
|
||||||
@ -72,7 +73,8 @@ private:
|
|||||||
std::string m_logFileRoot;
|
std::string m_logFileRoot;
|
||||||
|
|
||||||
unsigned int m_networkPort;
|
unsigned int m_networkPort;
|
||||||
std::string m_networkHosts;
|
std::string m_networkHosts1;
|
||||||
|
std::string m_networkHosts2;
|
||||||
unsigned int m_networkReloadTime;
|
unsigned int m_networkReloadTime;
|
||||||
std::string m_networkParrotAddress;
|
std::string m_networkParrotAddress;
|
||||||
unsigned int m_networkParrotPort;
|
unsigned int m_networkParrotPort;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
|
* Copyright (C) 2016,2017,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -178,7 +178,7 @@ void CP25Gateway::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CReflectors reflectors(m_conf.getNetworkHosts(), m_conf.getNetworkReloadTime());
|
CReflectors reflectors(m_conf.getNetworkHosts1(), m_conf.getNetworkHosts2(), m_conf.getNetworkReloadTime());
|
||||||
if (m_conf.getNetworkParrotPort() > 0U)
|
if (m_conf.getNetworkParrotPort() > 0U)
|
||||||
reflectors.setParrot(m_conf.getNetworkParrotAddress(), m_conf.getNetworkParrotPort());
|
reflectors.setParrot(m_conf.getNetworkParrotAddress(), m_conf.getNetworkParrotPort());
|
||||||
reflectors.load();
|
reflectors.load();
|
||||||
|
@ -16,7 +16,8 @@ FileRoot=P25Gateway
|
|||||||
|
|
||||||
[Network]
|
[Network]
|
||||||
Port=42010
|
Port=42010
|
||||||
Hosts=P25Hosts.txt
|
HostsFile1=./P25Hosts.txt
|
||||||
|
HostsFile2=./private/P25Hosts.txt
|
||||||
ReloadTime=60
|
ReloadTime=60
|
||||||
ParrotAddress=127.0.0.1
|
ParrotAddress=127.0.0.1
|
||||||
ParrotPort=42011
|
ParrotPort=42011
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -26,8 +26,9 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) :
|
CReflectors::CReflectors(const std::string& hostsFile1, const std::string& hostsFile2, unsigned int reloadTime) :
|
||||||
m_hostsFile(hostsFile),
|
m_hostsFile1(hostsFile1),
|
||||||
|
m_hostsFile2(hostsFile2),
|
||||||
m_parrotAddress(),
|
m_parrotAddress(),
|
||||||
m_parrotPort(0U),
|
m_parrotPort(0U),
|
||||||
m_reflectors(),
|
m_reflectors(),
|
||||||
@ -59,7 +60,7 @@ bool CReflectors::load()
|
|||||||
|
|
||||||
m_reflectors.clear();
|
m_reflectors.clear();
|
||||||
|
|
||||||
FILE* fp = ::fopen(m_hostsFile.c_str(), "rt");
|
FILE* fp = ::fopen(m_hostsFile1.c_str(), "rt");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
char buffer[100U];
|
char buffer[100U];
|
||||||
while (::fgets(buffer, 100U, fp) != NULL) {
|
while (::fgets(buffer, 100U, fp) != NULL) {
|
||||||
@ -88,6 +89,35 @@ bool CReflectors::load()
|
|||||||
::fclose(fp);
|
::fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fp = ::fopen(m_hostsFile2.c_str(), "rt");
|
||||||
|
if (fp != NULL) {
|
||||||
|
char buffer[100U];
|
||||||
|
while (::fgets(buffer, 100U, fp) != NULL) {
|
||||||
|
if (buffer[0U] == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char* p1 = ::strtok(buffer, " \t\r\n");
|
||||||
|
char* p2 = ::strtok(NULL, " \t\r\n");
|
||||||
|
char* p3 = ::strtok(NULL, " \t\r\n");
|
||||||
|
|
||||||
|
if (p1 != NULL && p2 != NULL && p3 != NULL) {
|
||||||
|
std::string host = std::string(p2);
|
||||||
|
|
||||||
|
in_addr address = CUDPSocket::lookup(host);
|
||||||
|
if (address.s_addr != INADDR_NONE) {
|
||||||
|
CP25Reflector* refl = new CP25Reflector;
|
||||||
|
refl->m_id = (unsigned int)::atoi(p1);
|
||||||
|
refl->m_address = address;
|
||||||
|
refl->m_port = (unsigned int)::atoi(p3);
|
||||||
|
|
||||||
|
m_reflectors.push_back(refl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = m_reflectors.size();
|
size_t size = m_reflectors.size();
|
||||||
LogInfo("Loaded %u P25 reflectors", size);
|
LogInfo("Loaded %u P25 reflectors", size);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
class CReflectors {
|
class CReflectors {
|
||||||
public:
|
public:
|
||||||
CReflectors(const std::string& hostsFile, unsigned int reloadTime);
|
CReflectors(const std::string& hostsFile1, const std::string& hostsFile2, unsigned int reloadTime);
|
||||||
~CReflectors();
|
~CReflectors();
|
||||||
|
|
||||||
void setParrot(const std::string& address, unsigned int port);
|
void setParrot(const std::string& address, unsigned int port);
|
||||||
@ -53,7 +53,8 @@ public:
|
|||||||
void clock(unsigned int ms);
|
void clock(unsigned int ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_hostsFile;
|
std::string m_hostsFile1;
|
||||||
|
std::string m_hostsFile2;
|
||||||
std::string m_parrotAddress;
|
std::string m_parrotAddress;
|
||||||
unsigned int m_parrotPort;
|
unsigned int m_parrotPort;
|
||||||
std::vector<CP25Reflector*> m_reflectors;
|
std::vector<CP25Reflector*> m_reflectors;
|
||||||
|
Loading…
Reference in New Issue
Block a user