Fixes #693 in public. Basically, refactoring to force all SR messages through the SR class. Also fixed a memory leak in the SR itself.

git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@3163 19bc5d8c-e614-43d4-8b26-e1612bc8e597
This commit is contained in:
Kurtis Heimerl
2012-02-09 08:06:16 +00:00
parent f255bf728c
commit 2f2d75383c
4 changed files with 35 additions and 25 deletions

View File

@@ -207,20 +207,20 @@ void Control::LocationUpdatingController(const L3LocationUpdatingRequest* lur, L
}
//query subscriber registry for old imei, update if neccessary
char* old_imei;
string name = string("IMSI") + IMSI;
sqlite3_single_lookup(gSubscriberRegistry.db(), "sip_buddies", "name", name.c_str(),
"hardware", old_imei);
char* old_imei = gSubscriberRegistry.sqlQuery("hardware", "sip_buddies", "name", name.c_str());
//if we have a new imei and either there's no old one, or it is different...
if (new_imei && (!old_imei || strncmp(old_imei,new_imei, 15) != 0)){
ostringstream os2;
os2 << "update sip_buddies set RRLPSupported = \"1\", hardware = \"" << new_imei << "\" where name = \"IMSI" << IMSI << "\"";
LOG(INFO) << "Updating IMSI" << IMSI << " to IMEI:" << new_imei;
if (!sqlite3_command(gSubscriberRegistry.db(), os2.str().c_str())) {
LOG(INFO) << "sqlite3_command problem";
if (!gSubscriberRegistry.sqlUpdate(os2.str().c_str())) {
LOG(INFO) << "SR update problem";
}
}
if (old_imei)
free(old_imei);
delete msg;
}

View File

@@ -33,6 +33,8 @@ using namespace std;
#include <GSMLogicalChannel.h>
#include <GSML3MMMessages.h>
#include <SubscriberRegistry.h>
#include <Logger.h>
using namespace GSM;
@@ -99,9 +101,12 @@ RRLPServer::RRLPServer(L3MobileIdentity wMobileID, LogicalChannel *wDCCH)
//otherwise just go on
if (gConfig.defines("Control.LUR.QueryIMEI")){
unsigned int supported = 0;
char* supported_str;
//check supported bit
sqlite3_single_lookup(gSubscriberRegistry.db(), "sip_buddies", "name", name.c_str(),
"RRLPSupported", supported);
supported_str = gSubscriberRegistry.sqlQuery("RRLPSupported", "sip_buddies", "name", name.c_str());
if (supported_str)
supported = atoi(supported_str);
free(supported_str);
if(!supported){
LOG(INFO) << "RRLP not supported for " << name;
trouble = true;
@@ -186,8 +191,8 @@ bool RRLPServer::transact()
"datetime('now')"
")";
LOG(INFO) << os.str();
if (!sqlite3_command(gSubscriberRegistry.db(), os.str().c_str())) {
LOG(INFO) << "sqlite3_command problem";
if (!gSubscriberRegistry.sqlUpdate(os.str().c_str())) {
LOG(INFO) << "SR update problem";
return false;
}
return true;
@@ -246,8 +251,8 @@ bool RRLPServer::transact()
if (gConfig.defines("Control.LUR.QueryIMEI")){
// flag unsupported in SR so we don't waste time on it again
os2 << "update sip_buddies set RRLPSupported = \"0\" where name = \"" << name.c_str() << "\"";
if (!sqlite3_command(gSubscriberRegistry.db(), os2.str().c_str())) {
LOG(INFO) << "sqlite3_command problem";
if (!gSubscriberRegistry.sqlUpdate(os2.str().c_str())) {
LOG(INFO) << "SR update problem";
}
}
return false;

View File

@@ -312,9 +312,16 @@ SubscriberRegistry::Status SubscriberRegistry::addUser(const char* IMSI, const c
LOG(WARNING) << "SubscriberRegistry::addUser attempting add of NULL CLID";
return FAILURE;
}
if (getIMSI(CLID) != NULL || getCLIDLocal(IMSI) != NULL) {
//this was a memory leak -kurtis
char* old_imsi = getIMSI(CLID);
char* old_clid = getCLIDLocal(IMSI);
if (old_imsi || old_clid) {
LOG(WARNING) << "SubscriberRegistry::addUser attempting user duplication";
// technically this is a failure, but I don't want it to keep trying
if (old_imsi)
free(old_imsi);
if (old_clid)
free(old_clid);
return SUCCESS;
}
LOG(INFO) << "addUser(" << IMSI << "," << CLID << ")";

View File

@@ -117,19 +117,8 @@ class SubscriberRegistry {
bool useGateway(const char* ISDN);
private:
/**
Run sql statments locally.
@param stmt The sql statements.
@param resultptr Set this to point to the result of executing the statements.
*/
Status sqlLocal(const char *stmt, char **resultptr);
/* Generic Update/Get functions.
Make sure your SQL is generic too */
/**
Run an sql query (select unknownColumn from table where knownColumn = knownValue).
@param unknownColumn The column whose value you want.
@@ -150,6 +139,15 @@ class SubscriberRegistry {
private:
/**
Run sql statments locally.
@param stmt The sql statements.
@param resultptr Set this to point to the result of executing the statements.
*/
Status sqlLocal(const char *stmt, char **resultptr);