qnrelay uses QnetConfigure

pull/12/head
Tom Early 7 years ago
parent f1eb7897d6
commit 93ec44e055

@ -25,7 +25,6 @@ class CQnetConfigure {
public: public:
CQnetConfigure(); CQnetConfigure();
virtual ~CQnetConfigure(); virtual ~CQnetConfigure();
//virtual bool ReadCfgFile() = 0;
bool Initialize(const char *configfile); bool Initialize(const char *configfile);
bool GetValue(const std::string &path, const std::string &mod, bool &value); bool GetValue(const std::string &path, const std::string &mod, bool &value);
bool GetValue(const std::string &path, const std::string &mod, double &value, const double min, const double max); bool GetValue(const std::string &path, const std::string &mod, double &value, const double min, const double max);

@ -35,6 +35,7 @@
#include "versions.h" #include "versions.h"
#include "QnetRelay.h" #include "QnetRelay.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "QnetConfigure.h"
std::atomic<bool> CQnetRelay::keep_running(true); std::atomic<bool> CQnetRelay::keep_running(true);
@ -345,75 +346,22 @@ bool CQnetRelay::ProcessMMDVM(const int len, const unsigned char *raw)
return false; return false;
} }
bool CQnetRelay::GetValue(const Config &cfg, const char *path, int &value, const int min, const int max, const int default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%d]\n", path, value);
return true;
}
bool CQnetRelay::GetValue(const Config &cfg, const char *path, double &value, const double min, const double max, const double default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%lg]\n", path, value);
return true;
}
bool CQnetRelay::GetValue(const Config &cfg, const char *path, bool &value, const bool default_value)
{
if (! cfg.lookupValue(path, value))
value = default_value;
printf("%s = [%s]\n", path, value ? "true" : "false");
return true;
}
bool CQnetRelay::GetValue(const Config &cfg, const char *path, std::string &value, int min, int max, const char *default_value)
{
if (cfg.lookupValue(path, value)) {
int l = value.length();
if (l<min || l>max) {
printf("%s value '%s' is wrong size\n", path, value.c_str());
return false;
}
} else
value = default_value;
printf("%s = [%s]\n", path, value.c_str());
return true;
}
// process configuration file and return true if there was a problem // process configuration file and return true if there was a problem
bool CQnetRelay::ReadConfig(const char *cfgFile) bool CQnetRelay::ReadConfig(const char *cfgFile)
{ {
Config cfg; CQnetConfigure cfg;
printf("Reading file %s\n", cfgFile); printf("Reading file %s\n", cfgFile);
// Read the file. If there is an error, report it and exit. if (cfg.Initialize(cfgFile))
try {
cfg.readFile(cfgFile);
}
catch(const FileIOException &fioex) {
printf("Can't read %s\n", cfgFile);
return true; return true;
}
catch(const ParseException &pex) {
printf("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError());
return true;
}
std::string value; const std::string estr; // an empty GetDefaultString
std::string mmdvm_path("module."); std::string type;
std::string mmdvm_path("module_");
mmdvm_path.append(1, 'a' + assigned_module); mmdvm_path.append(1, 'a' + assigned_module);
if (cfg.lookupValue(mmdvm_path + ".type", value)) { if (cfg.KeyExists(mmdvm_path)) {
if (value.compare("mmdvm")) { cfg.GetValue(mmdvm_path, estr, type, 1, 16);
fprintf(stderr, "assigned module is not 'mmdvm' type!\n"); if (type.compare("mmdvm")) {
fprintf(stderr, "%s = %s is not 'mmdvm' type!\n", mmdvm_path.c_str(), type.c_str());
return true; return true;
} }
} else { } else {
@ -421,63 +369,17 @@ bool CQnetRelay::ReadConfig(const char *cfgFile)
return true; return true;
} }
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
char unixsockname[16];
snprintf(unixsockname, 16, "gate2module%d", assigned_module);
GetValue(cfg, std::string(mmdvm_path+".fromgateway").c_str(), gate2modem, 1, FILENAME_MAX, unixsockname);
snprintf(unixsockname, 16, "module2gate%d", assigned_module);
GetValue(cfg, std::string(mmdvm_path+",togateway").c_str(), modem2gate, 1, FILENAME_MAX, unixsockname);
if (cfg.lookupValue(std::string(mmdvm_path+".callsign").c_str(), value) || cfg.lookupValue("ircddb.login", value)) {
int l = value.length();
if (l<3 || l>CALL_SIZE-2) {
fprintf(stderr, "Call '%s' is invalid length!\n", value.c_str());
return true;
} else {
for (int i=0; i<l; i++) {
if (islower(value[i]))
value[i] = toupper(value[i]);
}
value.resize(CALL_SIZE, ' ');
}
strcpy(RPTR, value.c_str());
} else {
fprintf(stderr, "%s.login is not defined!\n", mmdvm_path.c_str());
return true;
}
if (cfg.lookupValue("ircddb.login", value)) {
int l = value.length();
if (l<3 || l>CALL_SIZE-2) {
fprintf(stderr, "Call '%s' is invalid length!\n", value.c_str());
return true;
} else {
for (int i=0; i<l; i++) {
if (islower(value[i]))
value[i] = toupper(value[i]);
}
value.resize(CALL_SIZE, ' ');
}
strcpy(OWNER, value.c_str());
printf("ircddb.login = [%s]\n", OWNER);
} else {
printf("ircddb.login is not defined!\n");
return true;
}
if (GetValue(cfg, std::string(mmdvm_path+".internal_ip").c_str(), value, 7, IP_SIZE, "0.0.0.0")) {
MMDVM_IP = value;
} else
return true;
cfg.GetValue(mmdvm_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX);
cfg.GetValue(mmdvm_path+"_modem2gate"+std::to_string(assigned_module), type, modem2gate, 1, FILENAME_MAX);
cfg.GetValue(mmdvm_path+"_internal_ip", type, MMDVM_IP, 7, IP_SIZE);
int i; int i;
cfg.GetValue(mmdvm_path+"_local_port", type, i, 10000, 65535);
GetValue(cfg, "mmdvm.local_port", i, 10000, 65535, 20011);
MMDVM_IN_PORT = (unsigned short)i; MMDVM_IN_PORT = (unsigned short)i;
cfg.GetValue(mmdvm_path+"+gateway_port", type, i, 10000, 65535);
GetValue(cfg, "mmdvm.gateway_port", i, 10000, 65535, 20010);
MMDVM_OUT_PORT = (unsigned short)i; MMDVM_OUT_PORT = (unsigned short)i;
GetValue(cfg, "log.qso", log_qso, false); cfg.GetValue("log.qso", estr, log_qso);
return false; return false;
} }

@ -20,13 +20,10 @@
#include <atomic> #include <atomic>
#include <string> #include <string>
#include <libconfig.h++>
#include <netinet/in.h> #include <netinet/in.h>
#include "UnixDgramSocket.h" #include "UnixDgramSocket.h"
using namespace libconfig;
#define CALL_SIZE 8 #define CALL_SIZE 8
#define IP_SIZE 15 #define IP_SIZE 15
@ -52,10 +49,6 @@ private:
// read configuration file // read configuration file
bool ReadConfig(const char *); bool ReadConfig(const char *);
bool GetValue(const Config &cfg, const char *path, int &value, const int min, const int max, const int default_value);
bool GetValue(const Config &cfg, const char *path, double &value, const double min, const double max, const double default_value);
bool GetValue(const Config &cfg, const char *path, bool &value, const bool default_value);
bool GetValue(const Config &cfg, const char *path, std::string &value, const int min, const int max, const char *default_value);
// Unix sockets // Unix sockets
int assigned_module; int assigned_module;
@ -65,8 +58,6 @@ private:
// config data // config data
char RPTR_MOD; char RPTR_MOD;
char RPTR[CALL_SIZE + 1];
char OWNER[CALL_SIZE + 1];
std::string MMDVM_IP; std::string MMDVM_IP;
unsigned short MMDVM_IN_PORT, MMDVM_OUT_PORT; unsigned short MMDVM_IN_PORT, MMDVM_OUT_PORT;
bool log_qso; bool log_qso;

@ -1,9 +1,9 @@
// version strings must be 55 characters or less! // version strings must be 55 characters or less!
#define IRCDDB_VERSION "QnetGateway-7.4.6" #define IRCDDB_VERSION "QnetGateway-8.0.0"
#define LINK_VERSION "QnetLink-6.4.0" #define LINK_VERSION "QnetLink7.0.0"
#define DVAP_VERSION "QnetDVAP-5.1.2" #define DVAP_VERSION "QnetDVAP-6.0.0"
#define RELAY_VERSION "QnetRelay-0.2.3" #define RELAY_VERSION "QnetRelay-1.0.0"
#define ITAP_VERSION "QnetITAP-0.2.1" #define ITAP_VERSION "QnetITAP-1.0.0"
#define DVRPTR_VERSION "QnetDVRPTR-5.1.0" #define DVRPTR_VERSION "QnetDVRPTR-6.0.0"
#define MMDVM_VERSION "QnetGateway-MMDVM-0.1.0" #define MMDVM_VERSION "QnetGateway-MMDVM-1.0.0"
#define ICOM_VERSION IRCDDB_VERSION #define ICOM_VERSION IRCDDB_VERSION

Loading…
Cancel
Save

Powered by TurnKey Linux.