new FindGW w/o address and port params

pull/14/head
Tom Early 6 years ago
parent 05d01f44a0
commit e3c7dca999

@ -221,6 +221,7 @@ bool CQnetDB::FindLS(const char mod, std::list<CLink> &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)

@ -59,6 +59,7 @@ public:
bool DeleteLS(const char *address);
bool FindLS(const char mod, std::list<CLink> &linklist);
bool FindGW(const char *name, std::string &address, unsigned short &port);
bool FindGW(const char *name);
void ClearGW();
int Count(const char *table);

@ -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());
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) {

Loading…
Cancel
Save

Powered by TurnKey Linux.