From e3c7dca99949fbc4816f1f873218067f7a914010 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Thu, 16 Apr 2020 08:40:32 -0700 Subject: [PATCH] new FindGW w/o address and port params --- QnetDB.cpp | 28 ++++++++++++++++++++++++++++ QnetDB.h | 1 + QnetLink.cpp | 14 ++++++-------- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/QnetDB.cpp b/QnetDB.cpp index 98368bc..1dc795c 100644 --- a/QnetDB.cpp +++ b/QnetDB.cpp @@ -221,6 +221,7 @@ bool CQnetDB::FindLS(const char mod, std::list &linklist) } bool CQnetDB::FindGW(const char *name, std::string &address, unsigned short &port) +// returns true if NOT found { if (NULL == db) return false; @@ -248,6 +249,33 @@ bool CQnetDB::FindGW(const char *name, std::string &address, unsigned short &por } } +bool CQnetDB::FindGW(const char *name) +// returns true if found +{ + if (NULL == db) + return false; + std::string n(name); + n.resize(6, ' '); + std::string sql("SELECT address,port FROM GATEWAYS WHERE name=='"); + sql.append(n); + sql.append("';"); + + sqlite3_stmt *stmt; + int rval = sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, 0); + if (SQLITE_OK != rval) { + fprintf(stderr, "CQnetDB::FindGW error: %d\n", rval); + return true; + } + + if (SQLITE_ROW == sqlite3_step(stmt)) { + sqlite3_finalize(stmt); + return true; + } else { + sqlite3_finalize(stmt); + return false; + } +} + void CQnetDB::ClearGW() { if (NULL == db) diff --git a/QnetDB.h b/QnetDB.h index 6769c70..a5c8418 100644 --- a/QnetDB.h +++ b/QnetDB.h @@ -59,6 +59,7 @@ public: bool DeleteLS(const char *address); bool FindLS(const char mod, std::list &linklist); bool FindGW(const char *name, std::string &address, unsigned short &port); + bool FindGW(const char *name); void ClearGW(); int Count(const char *table); diff --git a/QnetLink.cpp b/QnetLink.cpp index 4d83a09..aedc61b 100644 --- a/QnetLink.cpp +++ b/QnetLink.cpp @@ -1199,18 +1199,16 @@ void CQnetLink::Process() i = 2; /* Is this repeater listed in gwys.txt? */ - std::string Address; - unsigned short Port; - if (qnDB.FindGW(call, Address, Port)) { - /* We did NOT find this repeater in gwys.txt, reject the incoming link request */ - printf("Incoming link from %s,%s but not found in gwys.txt\n", call, ip.c_str()); - i = -1; - } else { + if (qnDB.FindGW(call)) { int rc = regexec(&preg, call, 0, NULL, 0); if (rc != 0) { - printf("Invalid repeater %s,%s requesting to link\n", call, ip.c_str()); + printf("Invalid repeater %s, %s requesting to link\n", call, ip.c_str()); i = -1; } + } else { + /* We did NOT find this repeater in gwys.txt, reject the incoming link request */ + printf("Incoming link from %s,%s but not found in gwys.txt\n", call, ip.c_str()); + i = -1; } if (i >= 0) {