From c21521eb10f10df43830992d2b6343fe6ba3bbbd Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sun, 12 Feb 2023 09:54:05 -0700 Subject: [PATCH] restuctured json key string constants --- reflector/CallsignListItem.cpp | 4 +- reflector/Configure.cpp | 244 +++++++++++++++++---------------- reflector/Configure.h | 48 ------- reflector/DMRMMDVMProtocol.cpp | 2 +- reflector/Defines.h | 1 - reflector/G3Protocol.cpp | 4 +- reflector/GateKeeper.cpp | 6 +- reflector/Global.h | 2 + reflector/JsonKeys.h | 57 ++++++++ reflector/LookupDmr.cpp | 12 +- reflector/LookupNxdn.cpp | 12 +- reflector/LookupYsf.cpp | 16 +-- reflector/Main.cpp | 5 +- reflector/NXDNProtocol.cpp | 4 +- reflector/P25Protocol.cpp | 6 +- reflector/Protocol.cpp | 6 +- reflector/Protocols.cpp | 24 ++-- reflector/Reflector.cpp | 8 +- reflector/USRPProtocol.cpp | 6 +- reflector/WiresXCmdHandler.cpp | 2 +- reflector/YSFProtocol.cpp | 2 +- 21 files changed, 242 insertions(+), 229 deletions(-) create mode 100644 reflector/JsonKeys.h diff --git a/reflector/CallsignListItem.cpp b/reflector/CallsignListItem.cpp index 01bebab..27cfba8 100644 --- a/reflector/CallsignListItem.cpp +++ b/reflector/CallsignListItem.cpp @@ -33,7 +33,7 @@ CCallsignListItem::CCallsignListItem() CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, const char *modules) { - const std::string mods(g_Conf.GetString(g_Conf.j.modules.modules)); + const std::string mods(g_Conf.GetString(g_Keys.modules.modules)); m_Callsign = callsign; memset(m_szUrl, 0, sizeof(m_szUrl)); m_Ip = ip; @@ -60,7 +60,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url, const char *modules) { - const std::string mods(g_Conf.GetString(g_Conf.j.modules.modules)); + const std::string mods(g_Conf.GetString(g_Keys.modules.modules)); m_Callsign = callsign; ::strncpy(m_szUrl, url, URL_MAXLEN); m_Ip = CIp(m_szUrl); diff --git a/reflector/Configure.cpp b/reflector/Configure.cpp index de6b31f..73b46f6 100644 --- a/reflector/Configure.cpp +++ b/reflector/Configure.cpp @@ -27,7 +27,7 @@ #include #include -#include "Configure.h" +#include "Global.h" // ini file keywords #define JAUTOLINKMODULE "AutoLinkModule" @@ -183,7 +183,7 @@ bool CConfigure::ReadData(const std::string &path) bool rval = false; ESection section = ESection::none; counter = 0; - REFLECTOR::DB *pdb; + SJsonKeys::DB *pdb; //data.ysfalmodule = 0; //data.DPlusPort = data.DCSPort = data.DExtraPort = data.BMPort = data.DMRPlusPort = 0; @@ -287,32 +287,32 @@ bool CConfigure::ReadData(const std::string &path) { case ESection::names: if (0 == key.compare(JCALLSIGN)) - data[j.names.cs] = value; + data[g_Keys.names.cs] = value; else if (0 == key.compare(JSYSOPEMAIL)) - data[j.names.email] = value; + data[g_Keys.names.email] = value; else if (0 == key.compare(JCOUNTRY)) - data[j.names.country] = value.substr(0,2); + data[g_Keys.names.country] = value.substr(0,2); else if (0 == key.compare(JSPONSOR)) - data[j.names.sponsor] = value; + data[g_Keys.names.sponsor] = value; else badParam(key); break; case ESection::ip: if (0 == key.compare(JIPV4BINDING)) { - data[j.ip.ipv4bind] = value; + data[g_Keys.ip.ipv4bind] = value; } else if (0 == key.compare(JIPV6BINDING)) { - data[j.ip.ipv6bind] = value; + data[g_Keys.ip.ipv6bind] = value; } else if (0 == key.compare(JIPV4EXTERNAL)) { - data[j.ip.ipv4address] = value; + data[g_Keys.ip.ipv4address] = value; } else if (0 == key.compare(JIPV6EXTERNAL)) { - data[j.ip.ipv6address] = value; + data[g_Keys.ip.ipv6address] = value; } else if (0 == key.compare(JTRANSCODER)) { @@ -320,7 +320,7 @@ bool CConfigure::ReadData(const std::string &path) { std::cout << "WARNING: Line #" << counter << ": malformed transcoder address, '" << value << "', resetting..." << std::endl; } - data[j.ip.transcoder] = "local"; + data[g_Keys.ip.transcoder] = "local"; } else badParam(key); @@ -334,7 +334,7 @@ bool CConfigure::ReadData(const std::string &path) std::cerr << "ERROR: line #" << counter << ": no letters found in Modules: '" << m << "'" << std::endl; rval = true; } else - data[j.modules.modules] = m; + data[g_Keys.modules.modules] = m; } else if (0 == key.compare(JTRANSCODED)) { @@ -344,7 +344,7 @@ bool CConfigure::ReadData(const std::string &path) std::cerr << "ERROR: line #" << counter << ": no letters found in Transcoded: '" << m << "'" << std::endl; rval = true; } else - data[j.modules.tcmodules] = m; + data[g_Keys.modules.tcmodules] = m; } else if (0 == key.compare(0, 11, "Description")) { @@ -358,79 +358,79 @@ bool CConfigure::ReadData(const std::string &path) break; case ESection::bm: if (0 == key.compare(JPORT)) - data[j.bm.port] = getUnsigned(value, "Brandmeister Port", 1024, 65535, 10002); + data[g_Keys.bm.port] = getUnsigned(value, "Brandmeister Port", 1024, 65535, 10002); else badParam(key); break; case ESection::dcs: if (0 == key.compare(JPORT)) - data[j.dcs.port] = getUnsigned(value, "DCS Port", 1024, 65535, 30051); + data[g_Keys.dcs.port] = getUnsigned(value, "DCS Port", 1024, 65535, 30051); else badParam(key); break; case ESection::dextra: if (0 == key.compare(JPORT)) - data[j.dextra.port] = getUnsigned(value, "DExtra Port", 1024, 65535, 30001); + data[g_Keys.dextra.port] = getUnsigned(value, "DExtra Port", 1024, 65535, 30001); else badParam(key); break; case ESection::dmrplus: if (0 == key.compare(JPORT)) - data[j.dmrplus.port] = getUnsigned(value, "DMRPlus Port", 1024, 65535, 8880); + data[g_Keys.dmrplus.port] = getUnsigned(value, "DMRPlus Port", 1024, 65535, 8880); else badParam(key); break; case ESection::dplus: if (0 == key.compare(JPORT)) - data[j.dplus.port] = getUnsigned(value, "DPlus Port", 1024, 65535, 20001); + data[g_Keys.dplus.port] = getUnsigned(value, "DPlus Port", 1024, 65535, 20001); else badParam(key); break; case ESection::m17: if (0 == key.compare(JPORT)) - data[j.m17.port] = getUnsigned(value, "M17 Port", 1024, 65535, 17000); + data[g_Keys.m17.port] = getUnsigned(value, "M17 Port", 1024, 65535, 17000); else badParam(key); break; case ESection::mmdvm: if (0 == key.compare(JPORT)) - data[j.mmdvm.port] = getUnsigned(value, "MMDVM Port", 1024, 65535, 62030); + data[g_Keys.mmdvm.port] = getUnsigned(value, "MMDVM Port", 1024, 65535, 62030); else if (0 == key.compare(JDEFAULTID)) - data[j.mmdvm.defaultid] = getUnsigned(value, "MMDVM DefaultID", 0, 9999999, 0); + data[g_Keys.mmdvm.defaultid] = getUnsigned(value, "MMDVM DefaultID", 0, 9999999, 0); else badParam(key); break; case ESection::nxdn: if (0 == key.compare(JPORT)) - data[j.nxdn.port] = getUnsigned(value, "NDXN Port", 1024, 65535, 41400); + data[g_Keys.nxdn.port] = getUnsigned(value, "NDXN Port", 1024, 65535, 41400); else if (0 == key.compare(JAUTOLINKMODULE)) - setAutolink(JNXDN, j.nxdn.autolinkmod, value); + setAutolink(JNXDN, g_Keys.nxdn.autolinkmod, value); else if (0 == key.compare(JREFLECTORID)) - data[j.nxdn.reflectorid] = getUnsigned(value, "NXDN ReflectorID", 0, 65535, 0); + data[g_Keys.nxdn.reflectorid] = getUnsigned(value, "NXDN ReflectorID", 0, 65535, 0); else badParam(key); break; case ESection::p25: if (0 == key.compare(JPORT)) - data[j.p25.port] = getUnsigned(value, "P25 Port", 1024, 65535, 41000); + data[g_Keys.p25.port] = getUnsigned(value, "P25 Port", 1024, 65535, 41000); else if (0 == key.compare(JAUTOLINKMODULE)) - setAutolink(JP25, j.p25.autolinkmod, value); + setAutolink(JP25, g_Keys.p25.autolinkmod, value); else if (0 == key.compare(JREFLECTORID)) - data[j.p25.reflectorid] = getUnsigned(value, "P25 ReflectorID", 0, 16777215, 0); + data[g_Keys.p25.reflectorid] = getUnsigned(value, "P25 ReflectorID", 0, 16777215, 0); else badParam(key); break; case ESection::urf: if (0 == key.compare(JPORT)) - data[j.urf.port] = getUnsigned(value, "URF Port", 1024, 65535, 10017); + data[g_Keys.urf.port] = getUnsigned(value, "URF Port", 1024, 65535, 10017); else badParam(key); break; case ESection::usrp: if (0 == key.compare(JPORT)) - data[j.usrp.port] = getUnsigned(value, "USRP Port", 1024, 65535, 34001); + data[g_Keys.usrp.port] = getUnsigned(value, "USRP Port", 1024, 65535, 34001); else if (0 == key.compare(JAUTOLINKMODULE)) - setAutolink(JUSRP, j.usrp.autolinkmod, value); + setAutolink(JUSRP, g_Keys.usrp.autolinkmod, value); else if (0 == key.compare(JDEFAULTCALLSIGN)) { std::string cs; @@ -438,35 +438,35 @@ bool CConfigure::ReadData(const std::string &path) if (isalnum(c)) cs.append(1, toupper(c)); if (cs.size() > 7) cs.resize(7); - data[j.usrp.defaultcallsign] = cs; + data[g_Keys.usrp.defaultcallsign] = cs; } else if (0 == key.compare(JCLIENTSPATH)) - data[j.usrp.clientfilepath] = value; + data[g_Keys.usrp.clientfilepath] = value; else badParam(key); break; case ESection::ysf: if (0 == key.compare(JPORT)) - data[j.ysf.port] = getUnsigned(value, "YSF Port", 1024, 65535, 42000); + data[g_Keys.ysf.port] = getUnsigned(value, "YSF Port", 1024, 65535, 42000); else if (0 == key.compare(JAUTOLINKMODULE)) - setAutolink(JYSF, j.ysf.autolinkmod, value); + setAutolink(JYSF, g_Keys.ysf.autolinkmod, value); else if (0 == key.compare(JDEFAULTTXFREQ)) - data[j.ysf.defaulttxfreq] = getUnsigned(value, "YSF DefaultTxFreq", 40000000, 2600000000, 439000000); + data[g_Keys.ysf.defaulttxfreq] = getUnsigned(value, "YSF DefaultTxFreq", 40000000, 2600000000, 439000000); else if (0 == key.compare(JDEFAULTRXFREQ)) - data[j.ysf.defaultrxfreq] = getUnsigned(value, "YSF DefaultRxFreq", 40000000, 2600000000, 439000000); + data[g_Keys.ysf.defaultrxfreq] = getUnsigned(value, "YSF DefaultRxFreq", 40000000, 2600000000, 439000000); else if (0 == key.compare(JREGISTRATIONID)) - data[j.ysf.ysfreflectordb.id] = getUnsigned(value, "YSF RegistrationID", 0, 9999999, 0); + data[g_Keys.ysf.ysfreflectordb.id] = getUnsigned(value, "YSF RegistrationID", 0, 9999999, 0); else if (0 == key.compare(JREGISTRATIONNAME)) { std::string name(value); if (name.size() > 13) name.resize(13); - data[j.ysf.ysfreflectordb.name] = name; + data[g_Keys.ysf.ysfreflectordb.name] = name; } else if (0 == key.compare(JREGISTRATIONDESCRIPTION)) { std::string desc(value); if (desc.size() > 16) desc.resize(16); - data[j.ysf.ysfreflectordb.description] = desc; + data[g_Keys.ysf.ysfreflectordb.description] = desc; } else badParam(key); @@ -476,9 +476,9 @@ bool CConfigure::ReadData(const std::string &path) case ESection::ysffreq: switch (section) { - case ESection::dmrid: pdb = &j.dmriddb; break; - case ESection::nxdnid: pdb = &j.nxdniddb; break; - case ESection::ysffreq: pdb = &j.ysftxrxdb; break; + case ESection::dmrid: pdb = &g_Keys.dmriddb; break; + case ESection::nxdnid: pdb = &g_Keys.nxdniddb; break; + case ESection::ysffreq: pdb = &g_Keys.ysftxrxdb; break; } if (0 == key.compare(JHOSTNAME)) data[pdb->hostname] = value; @@ -503,17 +503,17 @@ bool CConfigure::ReadData(const std::string &path) break; case ESection::files: if (0 == key.compare(JPIDPATH)) - data[j.files.pid] = value; + data[g_Keys.files.pid] = value; else if (0 == key.compare(JJSONPATH)) - data[j.files.json] = value; + data[g_Keys.files.json] = value; else if (0 == key.compare(JWHITELISTPATH)) - data[j.files.white] = value; + data[g_Keys.files.white] = value; else if (0 == key.compare(JBLACKLISTPATH)) - data[j.files.black] = value; + data[g_Keys.files.black] = value; else if (0 == key.compare(JINTERLINKPATH)) - data[j.files.interlink] = value; + data[g_Keys.files.interlink] = value; else if (0 == key.compare(JG3TERMINALPATH)) - data[j.files.terminal] = value; + data[g_Keys.files.terminal] = value; else badParam(key); break; @@ -526,9 +526,9 @@ bool CConfigure::ReadData(const std::string &path) ////////////////////////////// check the input // Names section - if (isDefined(ErrorLevel::fatal, JNAMES, JCALLSIGN, j.names.cs, rval)) + if (isDefined(ErrorLevel::fatal, JNAMES, JCALLSIGN, g_Keys.names.cs, rval)) { - const auto cs = data[j.names.cs].get(); + const auto cs = data[g_Keys.names.cs].get(); auto RefRegEx = std::regex("^URF([A-Z0-9]){3,3}$", std::regex::extended); if (! std::regex_match(cs, RefRegEx)) { @@ -537,19 +537,19 @@ bool CConfigure::ReadData(const std::string &path) } } - isDefined(ErrorLevel::mild, JNAMES, JSYSOPEMAIL, j.names.email, rval); - isDefined(ErrorLevel::mild, JNAMES, JCOUNTRY, j.names.country, rval); - isDefined(ErrorLevel::mild, JNAMES, JSPONSOR, j.names.sponsor, rval); + isDefined(ErrorLevel::mild, JNAMES, JSYSOPEMAIL, g_Keys.names.email, rval); + isDefined(ErrorLevel::mild, JNAMES, JCOUNTRY, g_Keys.names.country, rval); + isDefined(ErrorLevel::mild, JNAMES, JSPONSOR, g_Keys.names.sponsor, rval); // IP Address section // ipv4 bind and external - if (isDefined(ErrorLevel::fatal, JIPADDRESSES, JIPV4BINDING, j.ip.ipv4bind, rval)) + if (isDefined(ErrorLevel::fatal, JIPADDRESSES, JIPV4BINDING, g_Keys.ip.ipv4bind, rval)) { - if (std::regex_match(data[j.ip.ipv4bind].get(), IPv4RegEx)) + if (std::regex_match(data[g_Keys.ip.ipv4bind].get(), IPv4RegEx)) { - if (data.contains(j.ip.ipv4address)) + if (data.contains(g_Keys.ip.ipv4address)) { - auto v4 = data[j.ip.ipv4address].get(); + auto v4 = data[g_Keys.ip.ipv4address].get(); if (std::regex_match(v4, IPv4RegEx)) { if (ipv4.compare(v4)) @@ -565,7 +565,7 @@ bool CConfigure::ReadData(const std::string &path) { // make sure curl worked! if (std::regex_match(ipv4, IPv4RegEx)) - data[j.ip.ipv4address] = ipv4; + data[g_Keys.ip.ipv4address] = ipv4; else { std::cerr << "ERROR: could not detect IPv4 address at this time" << std::endl; @@ -575,19 +575,19 @@ bool CConfigure::ReadData(const std::string &path) } else { - std::cerr << "ERROR: IPv4 binding address, " << data[j.ip.ipv4address].get() << ", is malformed" << std::endl; + std::cerr << "ERROR: IPv4 binding address, " << data[g_Keys.ip.ipv4address].get() << ", is malformed" << std::endl; rval = true; } } // ipv6 bind and external - if (data.contains(j.ip.ipv6bind)) + if (data.contains(g_Keys.ip.ipv6bind)) { - if (std::regex_match(data[j.ip.ipv6bind].get(), IPv6RegEx)) + if (std::regex_match(data[g_Keys.ip.ipv6bind].get(), IPv6RegEx)) { - if (data.contains(j.ip.ipv6address)) + if (data.contains(g_Keys.ip.ipv6address)) { - auto v6 = data[j.ip.ipv6address].get(); + auto v6 = data[g_Keys.ip.ipv6address].get(); if (std::regex_match(v6, IPv6RegEx)) { if (ipv6.compare(v6)) @@ -603,7 +603,7 @@ bool CConfigure::ReadData(const std::string &path) { // make sure curl worked! if (std::regex_match(ipv6, IPv6RegEx)) - data[j.ip.ipv6address] = ipv6; + data[g_Keys.ip.ipv6address] = ipv6; else { std::cerr << "ERROR: could not detect IPv6 address at this time" << std::endl; @@ -613,23 +613,23 @@ bool CConfigure::ReadData(const std::string &path) } else { - std::cerr << "ERROR: IPv6 binding address, " << data[j.ip.ipv6address].get() << ", is malformed" << std::endl; + std::cerr << "ERROR: IPv6 binding address, " << data[g_Keys.ip.ipv6address].get() << ", is malformed" << std::endl; rval = true; } } else { - data[j.ip.ipv4bind] = nullptr; - data[j.ip.ipv6address] = nullptr; + data[g_Keys.ip.ipv4bind] = nullptr; + data[g_Keys.ip.ipv6address] = nullptr; } // Modules section - if (isDefined(ErrorLevel::fatal, JMODULES, JMODULES, j.modules.modules, rval)) + if (isDefined(ErrorLevel::fatal, JMODULES, JMODULES, g_Keys.modules.modules, rval)) { - const auto mods(data[j.modules.modules].get()); - if (data.contains(j.modules.tcmodules)) + const auto mods(data[g_Keys.modules.modules].get()); + if (data.contains(g_Keys.modules.tcmodules)) { - const auto tcmods(data[j.modules.tcmodules].get()); + const auto tcmods(data[g_Keys.modules.tcmodules].get()); // how many transcoded modules auto size = tcmods.size(); @@ -637,7 +637,7 @@ bool CConfigure::ReadData(const std::string &path) std::cout << "WARNING: [" << JMODULES << "] " << JTRANSCODED << " doesn't define three (or one) modules" << std::endl; // make sure each transcoded module is configured - for (auto c : data[j.modules.tcmodules]) + for (auto c : data[g_Keys.modules.tcmodules]) { if (std::string::npos == mods.find(c)) { @@ -647,69 +647,69 @@ bool CConfigure::ReadData(const std::string &path) } } else - data[j.modules.tcmodules] = nullptr; + data[g_Keys.modules.tcmodules] = nullptr; // finally, check the module descriptions for (unsigned i=0; i<26; i++) { if (std::string::npos == mods.find('A'+i)) { - if (data.contains(j.modules.descriptor[i])) + if (data.contains(g_Keys.modules.descriptor[i])) { - std::cout << "WARNING: " << j.modules.descriptor[i] << " defined for an unconfigured module. Deleting..." << std::endl; - data.erase(j.modules.descriptor[i]); + std::cout << "WARNING: " << g_Keys.modules.descriptor[i] << " defined for an unconfigured module. Deleting..." << std::endl; + data.erase(g_Keys.modules.descriptor[i]); } } else { - if (! data.contains(j.modules.descriptor[i])) + if (! data.contains(g_Keys.modules.descriptor[i])) { std::string value("Module "); value.append(1, 'A'+i); - std::cout << "WARNING: " << j.modules.descriptor[i] << " not found. Setting to " << value << std::endl; - data[j.modules.descriptor[i]] = value; + std::cout << "WARNING: " << g_Keys.modules.descriptor[i] << " not found. Setting to " << value << std::endl; + data[g_Keys.modules.descriptor[i]] = value; } } } } // "simple" protocols with only a Port - isDefined(ErrorLevel::fatal, JBRANDMEISTER, JPORT, j.bm.port, rval); - isDefined(ErrorLevel::fatal, JDCS, JPORT, j.dcs.port, rval); - isDefined(ErrorLevel::fatal, JDEXTRA, JPORT, j.dextra.port, rval); - isDefined(ErrorLevel::fatal, JDMRPLUS, JPORT, j.dmrplus.port, rval); - isDefined(ErrorLevel::fatal, JDPLUS, JPORT, j.dplus.port, rval); - isDefined(ErrorLevel::fatal, JM17, JPORT, j.m17.port, rval); - isDefined(ErrorLevel::fatal, JURF, JPORT, j.urf.port, rval); + isDefined(ErrorLevel::fatal, JBRANDMEISTER, JPORT, g_Keys.bm.port, rval); + isDefined(ErrorLevel::fatal, JDCS, JPORT, g_Keys.dcs.port, rval); + isDefined(ErrorLevel::fatal, JDEXTRA, JPORT, g_Keys.dextra.port, rval); + isDefined(ErrorLevel::fatal, JDMRPLUS, JPORT, g_Keys.dmrplus.port, rval); + isDefined(ErrorLevel::fatal, JDPLUS, JPORT, g_Keys.dplus.port, rval); + isDefined(ErrorLevel::fatal, JM17, JPORT, g_Keys.m17.port, rval); + isDefined(ErrorLevel::fatal, JURF, JPORT, g_Keys.urf.port, rval); // MMDVM - isDefined(ErrorLevel::fatal, JMMDVM, JPORT, j.mmdvm.port, rval); - isDefined(ErrorLevel::fatal, JMMDVM, JDEFAULTID, j.mmdvm.defaultid, rval); + isDefined(ErrorLevel::fatal, JMMDVM, JPORT, g_Keys.mmdvm.port, rval); + isDefined(ErrorLevel::fatal, JMMDVM, JDEFAULTID, g_Keys.mmdvm.defaultid, rval); // NXDN - isDefined(ErrorLevel::fatal, JNXDN, JPORT, j.nxdn.port, rval); - checkAutoLink(JNXDN, JAUTOLINKMODULE, j.nxdn.autolinkmod, rval); - isDefined(ErrorLevel::fatal, JNXDN, JREFLECTORID, j.nxdn.reflectorid, rval); + isDefined(ErrorLevel::fatal, JNXDN, JPORT, g_Keys.nxdn.port, rval); + checkAutoLink(JNXDN, JAUTOLINKMODULE, g_Keys.nxdn.autolinkmod, rval); + isDefined(ErrorLevel::fatal, JNXDN, JREFLECTORID, g_Keys.nxdn.reflectorid, rval); // P25 - isDefined(ErrorLevel::fatal, JP25, JPORT, j.p25.port, rval); - checkAutoLink(JP25, JAUTOLINKMODULE, j.p25.autolinkmod, rval); - isDefined(ErrorLevel::fatal, JP25, JREFLECTORID, j.p25.reflectorid, rval); + isDefined(ErrorLevel::fatal, JP25, JPORT, g_Keys.p25.port, rval); + checkAutoLink(JP25, JAUTOLINKMODULE, g_Keys.p25.autolinkmod, rval); + isDefined(ErrorLevel::fatal, JP25, JREFLECTORID, g_Keys.p25.reflectorid, rval); // USRP - isDefined(ErrorLevel::fatal, JUSRP, JPORT, j.usrp.port, rval); - checkAutoLink(JUSRP, JAUTOLINKMODULE, j.usrp.autolinkmod, rval); - isDefined(ErrorLevel::fatal, JUSRP, JDEFAULTCALLSIGN, j.usrp.defaultcallsign, rval); - isDefined(ErrorLevel::fatal, JUSRP, JCLIENTSPATH, j.usrp.clientfilepath, rval); + isDefined(ErrorLevel::fatal, JUSRP, JPORT, g_Keys.usrp.port, rval); + checkAutoLink(JUSRP, JAUTOLINKMODULE, g_Keys.usrp.autolinkmod, rval); + isDefined(ErrorLevel::fatal, JUSRP, JDEFAULTCALLSIGN, g_Keys.usrp.defaultcallsign, rval); + isDefined(ErrorLevel::fatal, JUSRP, JCLIENTSPATH, g_Keys.usrp.clientfilepath, rval); // YSF - isDefined(ErrorLevel::fatal, JYSF, JPORT, j.ysf.port, rval); - checkAutoLink(JYSF, JAUTOLINKMODULE, j.ysf.autolinkmod, rval); - isDefined(ErrorLevel::fatal, JYSF, JDEFAULTRXFREQ, j.ysf.defaultrxfreq, rval); - isDefined(ErrorLevel::fatal, JYSF, JDEFAULTTXFREQ, j.ysf.defaulttxfreq, rval); - isDefined(ErrorLevel::mild, JYSF, JREGISTRATIONID, j.ysf.ysfreflectordb.id, rval); - isDefined(ErrorLevel::mild, JYSF, JREGISTRATIONNAME, j.ysf.ysfreflectordb.name, rval); - isDefined(ErrorLevel::mild, JYSF, JREGISTRATIONDESCRIPTION, j.ysf.ysfreflectordb.description, rval); + isDefined(ErrorLevel::fatal, JYSF, JPORT, g_Keys.ysf.port, rval); + checkAutoLink(JYSF, JAUTOLINKMODULE, g_Keys.ysf.autolinkmod, rval); + isDefined(ErrorLevel::fatal, JYSF, JDEFAULTRXFREQ, g_Keys.ysf.defaultrxfreq, rval); + isDefined(ErrorLevel::fatal, JYSF, JDEFAULTTXFREQ, g_Keys.ysf.defaulttxfreq, rval); + isDefined(ErrorLevel::mild, JYSF, JREGISTRATIONID, g_Keys.ysf.ysfreflectordb.id, rval); + isDefined(ErrorLevel::mild, JYSF, JREGISTRATIONNAME, g_Keys.ysf.ysfreflectordb.name, rval); + isDefined(ErrorLevel::mild, JYSF, JREGISTRATIONDESCRIPTION, g_Keys.ysf.ysfreflectordb.description, rval); // Databases - std::list> dbs = { - { JDMRIDDB, &j.dmriddb }, - { JNXDNIDDB, &j.nxdniddb }, - { JYSFTXRXDB, &j.ysftxrxdb } + std::list> dbs = { + { JDMRIDDB, &g_Keys.dmriddb }, + { JNXDNIDDB, &g_Keys.nxdniddb }, + { JYSFTXRXDB, &g_Keys.ysftxrxdb } }; for ( auto &item : dbs ) { @@ -720,12 +720,12 @@ bool CConfigure::ReadData(const std::string &path) isDefined(ErrorLevel::fatal, item.first, JFILEPATH, item.second->filepath, rval); } // Other files - isDefined(ErrorLevel::fatal, JFILES, JPIDPATH, j.files.pid, rval); - isDefined(ErrorLevel::fatal, JFILES, JJSONPATH, j.files.json, rval); - isDefined(ErrorLevel::fatal, JFILES, JWHITELISTPATH, j.files.white, rval); - isDefined(ErrorLevel::fatal, JFILES, JBLACKLISTPATH, j.files.black, rval); - isDefined(ErrorLevel::fatal, JFILES, JINTERLINKPATH, j.files.interlink, rval); - isDefined(ErrorLevel::fatal, JFILES, JG3TERMINALPATH, j.files.terminal, rval); + isDefined(ErrorLevel::fatal, JFILES, JPIDPATH, g_Keys.files.pid, rval); + isDefined(ErrorLevel::fatal, JFILES, JJSONPATH, g_Keys.files.json, rval); + isDefined(ErrorLevel::fatal, JFILES, JWHITELISTPATH, g_Keys.files.white, rval); + isDefined(ErrorLevel::fatal, JFILES, JBLACKLISTPATH, g_Keys.files.black, rval); + isDefined(ErrorLevel::fatal, JFILES, JINTERLINKPATH, g_Keys.files.interlink, rval); + isDefined(ErrorLevel::fatal, JFILES, JG3TERMINALPATH, g_Keys.files.terminal, rval); return rval; } @@ -752,8 +752,8 @@ void CConfigure::checkAutoLink(const std::string §ion, const std::string &pn { if (data.contains(key)) { - auto ismods = data.contains(j.modules.modules); - const auto mods(ismods ? data[j.modules.modules].get() : ""); + auto ismods = data.contains(g_Keys.modules.modules); + const auto mods(ismods ? data[g_Keys.modules.modules].get() : ""); const auto c = data[key].get().at(0); if (std::string::npos == mods.find(c)) { @@ -913,16 +913,18 @@ bool CConfigure::IsString(const std::string &key) const } #ifdef INICHECK +SJsonKeys g_Keys; int main(int argc, char *argv[]) { - if (argc == 2 || argc == 3) + if (3 == argc && strlen(argv[1]) > 1 && '-' == argv[1][0]) { CConfigure d; - auto rval = d.ReadData(argv[argc-1]); - d.Dump((2==argc) ? false : true); + auto rval = d.ReadData(argv[2]); + if ('q' != argv[1][1]) + d.Dump(('n' == argv[1][1]) ? true : false); return rval ? EXIT_FAILURE : EXIT_SUCCESS; } - std::cerr << "Usage: " << argv[0] << " FILENAME\nWhere is anything.\nThis option only shows values whose key begins with an uppercase letter." << std::endl; + std::cerr << "Usage: " << argv[0] << " -(q|n|v) FILENAME\nWhere:\n\t-q just prints warnings and errors.\n\t-n also prints keys that begin with an uppercase letter.\n\t-v prints all keys, warnings and errors." << std::endl; return EXIT_SUCCESS; } #endif diff --git a/reflector/Configure.h b/reflector/Configure.h index dee5086..9686ed9 100644 --- a/reflector/Configure.h +++ b/reflector/Configure.h @@ -32,54 +32,6 @@ enum class ESection { none, names, ip, modules, urf, dplus, dextra, dcs, dmrplus class CConfigure { public: - // json names - struct REFLECTOR { - struct BM { const std::string port; } bm; - struct DCS { const std::string port; } dcs; - struct DEXTRA { const std::string port; } dextra; - struct DMRPLUS { const std::string port; } dmrplus; - struct DPLUS { const std::string port; } dplus; - struct M17 { const std::string port; } m17; - struct URF { const std::string port; } urf; - struct NAMES { const std::string cs, email, country, sponsor; } names; - struct IP { const std::string ipv4bind, ipv4address, ipv6bind, ipv6address, transcoder; } ip; - struct MODULES { const std::string modules, tcmodules, descriptor[26]; } modules; - struct USRP { const std::string port, autolinkmod, defaultcallsign, clientfilepath; } usrp; - struct P25NXDN { const std::string port, autolinkmod, reflectorid; } p25, nxdn; - struct YSF { - const std::string port, autolinkmod, defaulttxfreq, defaultrxfreq; - struct YSLREG { const std::string id, name, description; } ysfreflectordb; - } ysf; - struct MMDVM { const std::string port, defaultid; } mmdvm; - struct DB { const std::string hostname, suffix, mode, refreshmin, filepath; } dmriddb, nxdniddb, ysftxrxdb; - struct FILES { const std::string pid, json, white, black, interlink, terminal; } files; - } j = { - { "BrandMeisterPort" }, - { "DCSPort" }, - { "DExtraPort" }, - { "DMRPlusPort" }, - { "DPlusPort" }, - { "M17Port" }, - { "URFPort" }, - { "Callsign", "SysopEmail", "Country", "Sponsor" }, - { "ipv4bind", "IPv4Address", "ipv6bind", "IPv6Address", "tcaddress" }, - { "Modules", "TranscodedModules", "DescriptionA", "DescriptionB", "DescriptionC", - "DescriptionD", "DescriptionE", "DescriptionF", "DescriptionG", "DescriptionH", - "DescriptionI", "DescriptionJ", "DescriptionK", "DescriptionL", "DescriptionM", - "DescriptionN", "DescriptionO", "DescriptionP", "DescriptionQ", "DescriptionR", - "DescriptionS", "DescriptionT", "DescriptionU", "DescriptionV", "DescriptionW", - "DescriptionX", "DescriptionY", "DescriptionZ" }, - { "USRPPort", "USRPAutolinkMod", "usrpDefaultCallsign", "usrpClientfilePath" }, - { "P25Port", "P25AutolinkMod", "P25ReflectorID" }, - { "NXDNPort", "NXDNAutolinkMod", "NXDNReflectorID" }, - { "YSFPort", "YSFAutoLinkMod", "YSFDefaultTxFreq", "YSFDefaultRxFreq", { "ysfrefdbid", "ysfrefdbname", "ysfrefdbdesc" } }, - { "MMDVMPort", "mmdvmdefaultid" }, - { "dmrIdDbHost", "dmrIdDbSuffix", "dmrIdDbMode", "dmrIdDbRefresh", "dmrIdDbFilePath" }, - { "nxdnIdDbHost", "nxdnIdDbSuffix", "nxdnIdDbMode", "nxdnIdDbRefresh", "nxdnIdDbFilePath" }, - { "ysfIdDbHost", "ysfIdDbSuffix", "ysfIdDbMode", "ysfIdDbRefresh", "ysfIdDbFilePath" }, - { "pidFilePath", "jsonFilePath", "whitelistFilePath", "blacklistFilePath", "interlinkFilePath", "g3TerminalFilePath" } - }; - CConfigure(); bool ReadData(const std::string &path); void Dump(bool justpublic) const; diff --git a/reflector/DMRMMDVMProtocol.cpp b/reflector/DMRMMDVMProtocol.cpp index ec0b60e..0515537 100644 --- a/reflector/DMRMMDVMProtocol.cpp +++ b/reflector/DMRMMDVMProtocol.cpp @@ -48,7 +48,7 @@ static uint8_t g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; bool CDmrmmdvmProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { - m_DefaultId = g_Conf.GetUnsigned(g_Conf.j.mmdvm.defaultid); + m_DefaultId = g_Conf.GetUnsigned(g_Keys.mmdvm.defaultid); // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; diff --git a/reflector/Defines.h b/reflector/Defines.h index 862451d..8d28a4a 100644 --- a/reflector/Defines.h +++ b/reflector/Defines.h @@ -135,7 +135,6 @@ enum class EProtocol { any, none, dextra, dplus, dcs, g3, bm, urf, dmrplus, dmrm // macros #define MIN(a,b) ((a)<(b))?(a):(b) -#define MAX(a,b) ((a)>(b))?(a):(b) #define MAKEWORD(low, high) ((uint16_t)(((uint8_t)(low)) | (((uint16_t)((uint8_t)(high))) << 8))) #define MAKEDWORD(low, high) ((uint32_t)(((uint16_t)(low)) | (((uint32_t)((uint16_t)(high))) << 16))) #define LOBYTE(w) ((uint8_t)(uint16_t)(w & 0x00FF)) diff --git a/reflector/G3Protocol.cpp b/reflector/G3Protocol.cpp index 46bcb0f..c49ffc1 100644 --- a/reflector/G3Protocol.cpp +++ b/reflector/G3Protocol.cpp @@ -33,8 +33,8 @@ bool CG3Protocol::Initialize(const char */*type*/, const EProtocol /*type*/, con // everything is hard coded until ICOM gets their act together and start supporting IPv6 { //config data - m_TerminalPath.assign(g_Conf.GetString(g_Conf.j.files.terminal)); - const std::string ipv4address(g_Conf.GetString(g_Conf.j.ip.ipv4bind)); + m_TerminalPath.assign(g_Conf.GetString(g_Keys.files.terminal)); + const std::string ipv4address(g_Conf.GetString(g_Keys.ip.ipv4bind)); ReadOptions(); diff --git a/reflector/GateKeeper.cpp b/reflector/GateKeeper.cpp index ce357dd..1ec17e9 100644 --- a/reflector/GateKeeper.cpp +++ b/reflector/GateKeeper.cpp @@ -49,9 +49,9 @@ bool CGateKeeper::Init(void) { // load lists from files - m_NodeWhiteList.LoadFromFile(g_Conf.GetString(g_Conf.j.files.white)); - m_NodeBlackList.LoadFromFile(g_Conf.GetString(g_Conf.j.files.black)); - m_PeerList.LoadFromFile(g_Conf.GetString(g_Conf.j.files.interlink)); + m_NodeWhiteList.LoadFromFile(g_Conf.GetString(g_Keys.files.white)); + m_NodeBlackList.LoadFromFile(g_Conf.GetString(g_Keys.files.black)); + m_PeerList.LoadFromFile(g_Conf.GetString(g_Keys.files.interlink)); // reset run flag keep_running = true; diff --git a/reflector/Global.h b/reflector/Global.h index 39c515d..611f347 100644 --- a/reflector/Global.h +++ b/reflector/Global.h @@ -21,6 +21,7 @@ #include "LookupDmr.h" #include "LookupNxdn.h" #include "LookupYsf.h" +#include "JsonKeys.h" extern CReflector g_Refl; extern CGateKeeper g_Gate; @@ -29,3 +30,4 @@ extern CVersion g_Vers; extern CLookupDmr g_LDid; extern CLookupNxdn g_LNid; extern CLookupYsf g_LYtr; +extern SJsonKeys g_Keys; diff --git a/reflector/JsonKeys.h b/reflector/JsonKeys.h new file mode 100644 index 0000000..02921bc --- /dev/null +++ b/reflector/JsonKeys.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 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 + +#pragma once + +// configuration key names +struct SJsonKeys { + struct PORTONLY { const std::string port; } + bm { "BrandMeisterPort" }, + dcs { "DCSPort" }, + dextra { "DExtraPort" }, + dmrplus { "DMRPlusPort" }, + dplus { "DPlusPort" }, + m17 { "M17Port" }, + urf { "URFPort" }; + struct MMDVM { const std::string port, defaultid; } + mmdvm { "MMDVMPort", "mmdvmdefaultid" }; + struct NAMES { const std::string cs, email, country, sponsor; } + names { "Callsign", "SysopEmail", "Country", "Sponsor" }; + struct IP { const std::string ipv4bind, ipv4address, ipv6bind, ipv6address, transcoder; } + ip { "ipv4bind", "IPv4Address", "ipv6bind", "IPv6Address", "tcaddress" }; + struct MODULES { const std::string modules, tcmodules, descriptor[26]; } + modules { "Modules", "TranscodedModules", + "DescriptionA", "DescriptionB", "DescriptionC", "DescriptionD", "DescriptionE", "DescriptionF", "DescriptionG", "DescriptionH", "DescriptionI", "DescriptionJ", "DescriptionK", "DescriptionL", "DescriptionM", "DescriptionN", "DescriptionO", "DescriptionP", "DescriptionQ", "DescriptionR", "DescriptionS", "DescriptionT", "DescriptionU", "DescriptionV", "DescriptionW", "DescriptionX", "DescriptionY", "DescriptionZ" }; + struct USRP { const std::string port, autolinkmod, defaultcallsign, clientfilepath; } + usrp { "USRPPort", "USRPAutolinkMod", "usrpDefaultCallsign", "usrpClientfilePath" }; + struct P25NXDN { const std::string port, autolinkmod, reflectorid; } + p25 { "P25Port", "P25AutolinkMod", "P25ReflectorID" }, + nxdn { "NXDNPort", "NXDNAutolinkMod", "NXDNReflectorID" }; + struct YSF { const std::string port, autolinkmod, defaulttxfreq, defaultrxfreq; + struct YSLREG { const std::string id, name, description; } ysfreflectordb; } + ysf { "YSFPort", "YSFAutoLinkMod", "YSFDefaultTxFreq", "YSFDefaultRxFreq", + { "ysfrefdbid", "ysfrefdbname", "ysfrefdbdesc" } }; + struct DB { const std::string hostname, suffix, mode, refreshmin, filepath; } + dmriddb { "dmrIdDbHost", "dmrIdDbSuffix", "dmrIdDbMode", "dmrIdDbRefresh", "dmrIdDbFilePath" }, + nxdniddb { "nxdnIdDbHost", "nxdnIdDbSuffix", "nxdnIdDbMode", "nxdnIdDbRefresh", "nxdnIdDbFilePath" }, + ysftxrxdb { "ysfIdDbHost", "ysfIdDbSuffix", "ysfIdDbMode", "ysfIdDbRefresh", "ysfIdDbFilePath" }; + struct FILES { const std::string pid, json, white, black, interlink, terminal; } + files { "pidFilePath", "jsonFilePath", "whitelistFilePath", "blacklistFilePath", "interlinkFilePath", "g3TerminalFilePath" }; +}; diff --git a/reflector/LookupDmr.cpp b/reflector/LookupDmr.cpp index 2e64812..14c7363 100644 --- a/reflector/LookupDmr.cpp +++ b/reflector/LookupDmr.cpp @@ -31,11 +31,11 @@ void CLookupDmr::ClearContents() void CLookupDmr::LoadParameters() { - m_Type = g_Conf.GetRefreshType(g_Conf.j.dmriddb.mode); - m_Refresh = g_Conf.GetUnsigned(g_Conf.j.dmriddb.refreshmin); - m_Path.assign(g_Conf.GetString(g_Conf.j.dmriddb.filepath)); - m_Host.assign(g_Conf.GetString(g_Conf.j.dmriddb.hostname)); - m_Suffix.assign(g_Conf.GetString(g_Conf.j.dmriddb.suffix)); + m_Type = g_Conf.GetRefreshType(g_Keys.dmriddb.mode); + m_Refresh = g_Conf.GetUnsigned(g_Keys.dmriddb.refreshmin); + m_Path.assign(g_Conf.GetString(g_Keys.dmriddb.filepath)); + m_Host.assign(g_Conf.GetString(g_Keys.dmriddb.hostname)); + m_Suffix.assign(g_Conf.GetString(g_Keys.dmriddb.suffix)); } uint32_t CLookupDmr::FindDmrid(const CCallsign &callsign) @@ -200,7 +200,7 @@ bool CLookupDmr::HttpGet(const char *hostname, const char *filename, int port, C { // send the GET request char request[DMRID_HTTPGET_SIZEMAX]; - ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Conf.j.names.cs).c_str()); + ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Keys.names.cs).c_str()); ::write(sock_id, request, strlen(request)); // config receive timeouts diff --git a/reflector/LookupNxdn.cpp b/reflector/LookupNxdn.cpp index ee0da2a..1aac8fa 100644 --- a/reflector/LookupNxdn.cpp +++ b/reflector/LookupNxdn.cpp @@ -31,11 +31,11 @@ void CLookupNxdn::ClearContents() void CLookupNxdn::LoadParameters() { - m_Type = g_Conf.GetRefreshType(g_Conf.j.nxdniddb.mode); - m_Refresh = g_Conf.GetUnsigned(g_Conf.j.nxdniddb.refreshmin); - m_Path.assign(g_Conf.GetString(g_Conf.j.nxdniddb.filepath)); - m_Host.assign(g_Conf.GetString(g_Conf.j.nxdniddb.hostname)); - m_Suffix.assign(g_Conf.GetString(g_Conf.j.nxdniddb.suffix)); + m_Type = g_Conf.GetRefreshType(g_Keys.nxdniddb.mode); + m_Refresh = g_Conf.GetUnsigned(g_Keys.nxdniddb.refreshmin); + m_Path.assign(g_Conf.GetString(g_Keys.nxdniddb.filepath)); + m_Host.assign(g_Conf.GetString(g_Keys.nxdniddb.hostname)); + m_Suffix.assign(g_Conf.GetString(g_Keys.nxdniddb.suffix)); } const CCallsign *CLookupNxdn::FindCallsign(uint16_t nxdnid) @@ -202,7 +202,7 @@ bool CLookupNxdn::HttpGet(const char *hostname, const char *filename, int port, { // send the GET request char request[NXDNID_HTTPGET_SIZEMAX]; - ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Conf.j.names.cs).c_str()); + ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Keys.names.cs).c_str()); ::write(sock_id, request, strlen(request)); // config receive timeouts diff --git a/reflector/LookupYsf.cpp b/reflector/LookupYsf.cpp index 7b389e4..bb45b69 100644 --- a/reflector/LookupYsf.cpp +++ b/reflector/LookupYsf.cpp @@ -31,13 +31,13 @@ void CLookupYsf::ClearContents() void CLookupYsf::LoadParameters() { - m_Type = g_Conf.GetRefreshType(g_Conf.j.ysftxrxdb.mode); - m_Refresh = g_Conf.GetUnsigned(g_Conf.j.ysftxrxdb.refreshmin); - m_Path.assign(g_Conf.GetString(g_Conf.j.ysftxrxdb.filepath)); - m_Host.assign(g_Conf.GetString(g_Conf.j.ysftxrxdb.hostname)); - m_Suffix.assign(g_Conf.GetString(g_Conf.j.ysftxrxdb.suffix)); - m_DefaultTx = g_Conf.GetUnsigned(g_Conf.j.ysf.defaulttxfreq); - m_DefaultRx = g_Conf.GetUnsigned(g_Conf.j.ysf.defaultrxfreq); + m_Type = g_Conf.GetRefreshType(g_Keys.ysftxrxdb.mode); + m_Refresh = g_Conf.GetUnsigned(g_Keys.ysftxrxdb.refreshmin); + m_Path.assign(g_Conf.GetString(g_Keys.ysftxrxdb.filepath)); + m_Host.assign(g_Conf.GetString(g_Keys.ysftxrxdb.hostname)); + m_Suffix.assign(g_Conf.GetString(g_Keys.ysftxrxdb.suffix)); + m_DefaultTx = g_Conf.GetUnsigned(g_Keys.ysf.defaulttxfreq); + m_DefaultRx = g_Conf.GetUnsigned(g_Keys.ysf.defaultrxfreq); } bool CLookupYsf::LoadContentFile(CBuffer &buffer) @@ -178,7 +178,7 @@ bool CLookupYsf::HttpGet(const char *hostname, const char *filename, int port, C { // send the GET request char request[YSFNODE_HTTPGET_SIZEMAX]; - sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Conf.j.names.cs).c_str()); + sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Keys.names.cs).c_str()); write(sock_id, request, strlen(request)); // config receive timeouts diff --git a/reflector/Main.cpp b/reflector/Main.cpp index 556c2ab..21d8205 100644 --- a/reflector/Main.cpp +++ b/reflector/Main.cpp @@ -30,6 +30,7 @@ CVersion g_Vers(3,0,0); // The major byte should only change if the interlink CLookupDmr g_LDid; CLookupNxdn g_LNid; CLookupYsf g_LYtr; +SJsonKeys g_Keys; //////////////////////////////////////////////////////////////////////////////////////// @@ -45,8 +46,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; // remove pidfile - const std::string pidpath(g_Conf.GetString(g_Conf.j.files.pid)); - const std::string callsign(g_Conf.GetString(g_Conf.j.names.cs)); + const std::string pidpath(g_Conf.GetString(g_Keys.files.pid)); + const std::string callsign(g_Conf.GetString(g_Keys.names.cs)); remove(pidpath.c_str()); // splash diff --git a/reflector/NXDNProtocol.cpp b/reflector/NXDNProtocol.cpp index 66f43ce..a46f488 100644 --- a/reflector/NXDNProtocol.cpp +++ b/reflector/NXDNProtocol.cpp @@ -53,8 +53,8 @@ CNXDNProtocol::CNXDNProtocol() bool CNXDNProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // config value - m_ReflectorId = g_Conf.GetUnsigned(g_Conf.j.nxdn.reflectorid); - m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.nxdn.autolinkmod); + m_ReflectorId = g_Conf.GetUnsigned(g_Keys.nxdn.reflectorid); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Keys.nxdn.autolinkmod); // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) diff --git a/reflector/P25Protocol.cpp b/reflector/P25Protocol.cpp index 38f86b6..f93da67 100644 --- a/reflector/P25Protocol.cpp +++ b/reflector/P25Protocol.cpp @@ -50,9 +50,9 @@ const uint8_t REC80[] = {0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, bool CP25Protocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // config data - m_ReflectorId = g_Conf.GetUnsigned(g_Conf.j.p25.reflectorid); - m_DefaultId = g_Conf.GetUnsigned(g_Conf.j.mmdvm.defaultid); - m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.p25.autolinkmod); + m_ReflectorId = g_Conf.GetUnsigned(g_Keys.p25.reflectorid); + m_DefaultId = g_Conf.GetUnsigned(g_Keys.mmdvm.defaultid); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Keys.p25.autolinkmod); m_uiStreamId = 0; // base class diff --git a/reflector/Protocol.cpp b/reflector/Protocol.cpp index 7792901..c5fa213 100644 --- a/reflector/Protocol.cpp +++ b/reflector/Protocol.cpp @@ -64,7 +64,7 @@ bool CProtocol::Initialize(const char *type, const EProtocol ptype, const uint16 // create our sockets if (has_ipv4) { - const std::string ipv4binding(g_Conf.GetString(g_Conf.j.ip.ipv4bind)); + const std::string ipv4binding(g_Conf.GetString(g_Keys.ip.ipv4bind)); CIp ip4(AF_INET, port, ipv4binding.c_str()); if ( ip4.IsSet() ) { @@ -74,11 +74,11 @@ bool CProtocol::Initialize(const char *type, const EProtocol ptype, const uint16 std::cout << "Listening on " << ip4 << std::endl; } - if (g_Conf.IsString(g_Conf.j.ip.ipv6bind)) + if (g_Conf.IsString(g_Keys.ip.ipv6bind)) { if (has_ipv6) { - const std::string ipv6binding(g_Conf.j.ip.ipv6bind); + const std::string ipv6binding(g_Keys.ip.ipv6bind); CIp ip6(AF_INET6, port, ipv6binding.c_str()); if ( ip6.IsSet() ) { diff --git a/reflector/Protocols.cpp b/reflector/Protocols.cpp index b52c801..b14a1d4 100644 --- a/reflector/Protocols.cpp +++ b/reflector/Protocols.cpp @@ -49,51 +49,51 @@ bool CProtocols::Init(void) m_Mutex.lock(); { m_Protocols.emplace_back(std::unique_ptr(new CDextraProtocol)); - if (! m_Protocols.back()->Initialize("XRF", EProtocol::dextra, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dextra.port)), DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("XRF", EProtocol::dextra, uint16_t(g_Conf.GetUnsigned(g_Keys.dextra.port)), DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDplusProtocol)); - if (! m_Protocols.back()->Initialize("REF", EProtocol::dplus, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dplus.port)), DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("REF", EProtocol::dplus, uint16_t(g_Conf.GetUnsigned(g_Keys.dplus.port)), DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDcsProtocol)); - if (! m_Protocols.back()->Initialize("DCS", EProtocol::dcs, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dcs.port)), DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("DCS", EProtocol::dcs, uint16_t(g_Conf.GetUnsigned(g_Keys.dcs.port)), DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDmrmmdvmProtocol)); - if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrmmdvm, uint16_t(g_Conf.GetUnsigned(g_Conf.j.mmdvm.port)), DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrmmdvm, uint16_t(g_Conf.GetUnsigned(g_Keys.mmdvm.port)), DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CBMProtocol)); - if (! m_Protocols.back()->Initialize("XLX", EProtocol::bm, uint16_t(g_Conf.GetUnsigned(g_Conf.j.bm.port)), DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize("XLX", EProtocol::bm, uint16_t(g_Conf.GetUnsigned(g_Keys.bm.port)), DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDmrplusProtocol)); - if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrplus, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dmrplus.port)), DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrplus, uint16_t(g_Conf.GetUnsigned(g_Keys.dmrplus.port)), DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CYsfProtocol)); - if (! m_Protocols.back()->Initialize("YSF", EProtocol::ysf, uint16_t(g_Conf.GetUnsigned(g_Conf.j.ysf.port)), YSF_IPV4, YSF_IPV6)) + if (! m_Protocols.back()->Initialize("YSF", EProtocol::ysf, uint16_t(g_Conf.GetUnsigned(g_Keys.ysf.port)), YSF_IPV4, YSF_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CM17Protocol)); - if (! m_Protocols.back()->Initialize("URF", EProtocol::m17, uint16_t(g_Conf.GetUnsigned(g_Conf.j.m17.port)), M17_IPV4, M17_IPV6)) + if (! m_Protocols.back()->Initialize("URF", EProtocol::m17, uint16_t(g_Conf.GetUnsigned(g_Keys.m17.port)), M17_IPV4, M17_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CP25Protocol)); - if (! m_Protocols.back()->Initialize("P25", EProtocol::p25, uint16_t(g_Conf.GetUnsigned(g_Conf.j.p25.port)), P25_IPV4, P25_IPV6)) + if (! m_Protocols.back()->Initialize("P25", EProtocol::p25, uint16_t(g_Conf.GetUnsigned(g_Keys.p25.port)), P25_IPV4, P25_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CNXDNProtocol)); - if (! m_Protocols.back()->Initialize("NXDN", EProtocol::nxdn, uint16_t(g_Conf.GetUnsigned(g_Conf.j.nxdn.port)), NXDN_IPV4, NXDN_IPV6)) + if (! m_Protocols.back()->Initialize("NXDN", EProtocol::nxdn, uint16_t(g_Conf.GetUnsigned(g_Keys.nxdn.port)), NXDN_IPV4, NXDN_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CUSRPProtocol)); - if (! m_Protocols.back()->Initialize("USRP", EProtocol::usrp, uint16_t(g_Conf.GetUnsigned(g_Conf.j.usrp.port)), USRP_IPV4, USRP_IPV6)) + if (! m_Protocols.back()->Initialize("USRP", EProtocol::usrp, uint16_t(g_Conf.GetUnsigned(g_Keys.usrp.port)), USRP_IPV4, USRP_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CURFProtocol)); - if (! m_Protocols.back()->Initialize("URF", EProtocol::urf, uint16_t(g_Conf.GetUnsigned(g_Conf.j.urf.port)), URF_IPV4, URF_IPV6)) + if (! m_Protocols.back()->Initialize("URF", EProtocol::urf, uint16_t(g_Conf.GetUnsigned(g_Keys.urf.port)), URF_IPV4, URF_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CG3Protocol)); diff --git a/reflector/Reflector.cpp b/reflector/Reflector.cpp index a5605ba..2bebf44 100644 --- a/reflector/Reflector.cpp +++ b/reflector/Reflector.cpp @@ -47,9 +47,9 @@ CReflector::~CReflector() bool CReflector::Start(void) { // get config stuff - m_Callsign = CCallsign(g_Conf.GetString(g_Conf.j.names.cs).c_str(), false); - m_Modules.assign(g_Conf.GetString(g_Conf.j.modules.modules)); - std::string tcmods(g_Conf.GetString(g_Conf.j.modules.tcmodules)); + m_Callsign = CCallsign(g_Conf.GetString(g_Keys.names.cs).c_str(), false); + m_Modules.assign(g_Conf.GetString(g_Keys.modules.modules)); + std::string tcmods(g_Conf.GetString(g_Keys.modules.tcmodules)); // let's go! keep_running = true; @@ -323,7 +323,7 @@ void CReflector::RouterThread(const char ThisModule) void CReflector::XmlReportThread() { - const std::string path(g_Conf.GetString(g_Conf.j.files.json)); + const std::string path(g_Conf.GetString(g_Keys.files.json)); while (keep_running) { // report to xml file diff --git a/reflector/USRPProtocol.cpp b/reflector/USRPProtocol.cpp index 9a559fb..0c6c794 100644 --- a/reflector/USRPProtocol.cpp +++ b/reflector/USRPProtocol.cpp @@ -38,8 +38,8 @@ const uint8_t TLV_TAG_SET_INFO = 8; bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // config data - m_DefaultCallsign.assign(g_Conf.GetString(g_Conf.j.usrp.defaultcallsign)); - m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.usrp.autolinkmod); + m_DefaultCallsign.assign(g_Conf.GetString(g_Keys.usrp.defaultcallsign)); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Keys.usrp.autolinkmod); CBuffer buffer; m_uiStreamId = 0; CCallsign cs(m_DefaultCallsign.c_str()); @@ -51,7 +51,7 @@ bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const ui if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; - file.open(g_Conf.GetString(g_Conf.j.usrp.clientfilepath), std::ios::in | std::ios::binary | std::ios::ate); + file.open(g_Conf.GetString(g_Keys.usrp.clientfilepath), std::ios::in | std::ios::binary | std::ios::ate); if ( file.is_open() ) { // read file diff --git a/reflector/WiresXCmdHandler.cpp b/reflector/WiresXCmdHandler.cpp index e2c8d63..919c886 100644 --- a/reflector/WiresXCmdHandler.cpp +++ b/reflector/WiresXCmdHandler.cpp @@ -334,7 +334,7 @@ bool CWiresxCmdHandler::ReplyToWiresxAllReqPacket(const CIp &Ip, const CWiresxIn memcpy(data + 12U, WiresxInfo.GetNode(), 10U); // number of entries - const std::string modules(g_Conf.GetString(g_Conf.j.modules.modules)); + const std::string modules(g_Conf.GetString(g_Keys.modules.modules)); uint NB_OF_MODULES = modules.size(); uint total = NB_OF_MODULES; uint n = NB_OF_MODULES - Start; diff --git a/reflector/YSFProtocol.cpp b/reflector/YSFProtocol.cpp index 30fbf46..6869148 100644 --- a/reflector/YSFProtocol.cpp +++ b/reflector/YSFProtocol.cpp @@ -38,7 +38,7 @@ CYsfProtocol::CYsfProtocol() bool CYsfProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // config data - m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.ysf.autolinkmod); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Keys.ysf.autolinkmod); // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6))