From af0d399cd4cc6741b436d3bf291bfb6e22c73e63 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Mon, 15 Jun 2020 10:26:25 -0700 Subject: [PATCH] better CQnetDB error msgs && okay for a few bytes before a GPS $ --- Location.cpp | 6 ++++-- QnetDB.cpp | 22 +++++++++++----------- QnetGateway.cpp | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Location.cpp b/Location.cpp index 4d9851b..fa309bf 100644 --- a/Location.cpp +++ b/Location.cpp @@ -36,11 +36,13 @@ bool CLocation::Parse(const char *instr) std::string s(instr); std::cmatch cm; trim(s); + if (s.size() < 20) + return false; bool success; - if (0 == s.find("$$CRC")) { + if (3 > s.find("$$CRC")) { success = std::regex_search(s.c_str(), cm, crc, std::regex_constants::match_default); - } else if ((0 == s.find("$GPGGA")) || (0 == s.find("$GPRMC"))) { + } else if ((3 > s.find("$GPGGA")) || (3 > s.find("$GPRMC"))) { success = std::regex_search(s.c_str(), cm, rmc, std::regex_constants::match_default); } else { std::cerr << "Unrecognized GPS string: " << s << std::endl; diff --git a/QnetDB.cpp b/QnetDB.cpp index a78989f..72a009d 100644 --- a/QnetDB.cpp +++ b/QnetDB.cpp @@ -48,7 +48,7 @@ bool CQnetDB::Init() ") WITHOUT ROWID;"); if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::Open create table LHEARD error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::Init [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -62,7 +62,7 @@ bool CQnetDB::Init() ") WITHOUT ROWID;"); if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::Open create table LINKSTATUS error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::Init [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -74,7 +74,7 @@ bool CQnetDB::Init() ") WITHOUT ROWID;"); if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::Open create table GATEWAYS error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::Init [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -99,7 +99,7 @@ bool CQnetDB::UpdateLH(const char *callsign, const char *sfx, const char module, char *eMsg; if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), countcallback, &count, &eMsg)) { - fprintf(stderr, "CQnetDB::Count error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::UpdateLH [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -129,7 +129,7 @@ bool CQnetDB::UpdateLH(const char *callsign, const char *sfx, const char module, } if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::UpdateLH error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::UpdateLH [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -154,7 +154,7 @@ bool CQnetDB::UpdatePosition(const char *callsign, const char *maidenhead, doubl char *eMsg; if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::UpdatePosition error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::UpdatePosition [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -175,7 +175,7 @@ bool CQnetDB::UpdateMessage(const char *callsign, const char *message) char *eMsg; if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::UpdateMessage error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::UpdateMessage [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -201,7 +201,7 @@ bool CQnetDB::UpdateLS(const char *address, const char from_mod, const char *to_ char *eMsg; if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::UpdateLS error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::UpdateLS [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -225,7 +225,7 @@ bool CQnetDB::UpdateGW(const char *name, const char *address, unsigned short por char *eMsg; if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::UpdateGW error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::UpdateGW [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -268,7 +268,7 @@ bool CQnetDB::DeleteLS(const char *address) char *eMsg; if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) { - fprintf(stderr, "CQnetDB::DeleteLS error: %s\n", eMsg); + fprintf(stderr, "CQnetDB::DeleteLS [%s] error: %s\n", sql.c_str(), eMsg); sqlite3_free(eMsg); return true; } @@ -287,7 +287,7 @@ bool CQnetDB::FindLS(const char mod, std::list &linklist) sqlite3_stmt *stmt; int rval = sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, 0); if (SQLITE_OK != rval) { - fprintf(stderr, "CQnetDB::FindLS prepare_v2 error\n"); + fprintf(stderr, "CQnetDB::FindLS [%s] error\n", sql.c_str()); return true; } diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 17628bf..de873e6 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -54,7 +54,7 @@ #define CFG_DIR "/usr/local/etc" #endif -const std::string GW_VERSION("QnetGateway-614"); +const std::string GW_VERSION("QnetGateway-615"); int CQnetGateway::FindIndex(const int i) const {