From 93ec44e055ddc9aa729c8261b8df441e6922be61 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Wed, 26 Dec 2018 12:16:17 -0700 Subject: [PATCH] qnrelay uses QnetConfigure --- QnetConfigure.h | 1 - QnetRelay.cpp | 130 ++++++------------------------------------------ QnetRelay.h | 9 ---- versions.h | 14 +++--- 4 files changed, 23 insertions(+), 131 deletions(-) diff --git a/QnetConfigure.h b/QnetConfigure.h index 97ff257..efb404f 100644 --- a/QnetConfigure.h +++ b/QnetConfigure.h @@ -25,7 +25,6 @@ class CQnetConfigure { public: CQnetConfigure(); virtual ~CQnetConfigure(); - //virtual bool ReadCfgFile() = 0; 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, double &value, const double min, const double max); diff --git a/QnetRelay.cpp b/QnetRelay.cpp index a0da66c..0fd72c2 100644 --- a/QnetRelay.cpp +++ b/QnetRelay.cpp @@ -35,6 +35,7 @@ #include "versions.h" #include "QnetRelay.h" #include "QnetTypeDefs.h" +#include "QnetConfigure.h" std::atomic CQnetRelay::keep_running(true); @@ -345,75 +346,22 @@ bool CQnetRelay::ProcessMMDVM(const int len, const unsigned char *raw) 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 (lmax) { - 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 bool CQnetRelay::ReadConfig(const char *cfgFile) { - Config cfg; - + CQnetConfigure cfg; printf("Reading file %s\n", cfgFile); - // Read the file. If there is an error, report it and exit. - try { - cfg.readFile(cfgFile); - } - catch(const FileIOException &fioex) { - printf("Can't read %s\n", cfgFile); + if (cfg.Initialize(cfgFile)) 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; - std::string mmdvm_path("module."); + const std::string estr; // an empty GetDefaultString + std::string type; + std::string mmdvm_path("module_"); mmdvm_path.append(1, 'a' + assigned_module); - if (cfg.lookupValue(mmdvm_path + ".type", value)) { - if (value.compare("mmdvm")) { - fprintf(stderr, "assigned module is not 'mmdvm' type!\n"); + if (cfg.KeyExists(mmdvm_path)) { + cfg.GetValue(mmdvm_path, estr, type, 1, 16); + if (type.compare("mmdvm")) { + fprintf(stderr, "%s = %s is not 'mmdvm' type!\n", mmdvm_path.c_str(), type.c_str()); return true; } } else { @@ -421,63 +369,17 @@ bool CQnetRelay::ReadConfig(const char *cfgFile) return true; } 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; iCALL_SIZE-2) { - fprintf(stderr, "Call '%s' is invalid length!\n", value.c_str()); - return true; - } else { - for (int i=0; i #include -#include #include #include "UnixDgramSocket.h" -using namespace libconfig; - #define CALL_SIZE 8 #define IP_SIZE 15 @@ -52,10 +49,6 @@ private: // read configuration file 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 int assigned_module; @@ -65,8 +58,6 @@ private: // config data char RPTR_MOD; - char RPTR[CALL_SIZE + 1]; - char OWNER[CALL_SIZE + 1]; std::string MMDVM_IP; unsigned short MMDVM_IN_PORT, MMDVM_OUT_PORT; bool log_qso; diff --git a/versions.h b/versions.h index a7b4b13..ab25e36 100644 --- a/versions.h +++ b/versions.h @@ -1,9 +1,9 @@ // version strings must be 55 characters or less! -#define IRCDDB_VERSION "QnetGateway-7.4.6" -#define LINK_VERSION "QnetLink-6.4.0" -#define DVAP_VERSION "QnetDVAP-5.1.2" -#define RELAY_VERSION "QnetRelay-0.2.3" -#define ITAP_VERSION "QnetITAP-0.2.1" -#define DVRPTR_VERSION "QnetDVRPTR-5.1.0" -#define MMDVM_VERSION "QnetGateway-MMDVM-0.1.0" +#define IRCDDB_VERSION "QnetGateway-8.0.0" +#define LINK_VERSION "QnetLink7.0.0" +#define DVAP_VERSION "QnetDVAP-6.0.0" +#define RELAY_VERSION "QnetRelay-1.0.0" +#define ITAP_VERSION "QnetITAP-1.0.0" +#define DVRPTR_VERSION "QnetDVRPTR-6.0.0" +#define MMDVM_VERSION "QnetGateway-MMDVM-1.0.0" #define ICOM_VERSION IRCDDB_VERSION