laforge
/
openbts-osmo
Archived
1
0
Fork 0

Added MO-USSD handlers map to config.

Now you can configure which request will go to which handler.
This commit is contained in:
Alexander Chemeris 2010-08-19 00:10:15 +04:00
parent 58821a8f74
commit 7d9b0497bc
3 changed files with 42 additions and 8 deletions

View File

@ -37,6 +37,7 @@
#include <SIPEngine.h>
#include <SIPInterface.h>
#include <Regexp.h>
using namespace std;
using namespace GSM;
@ -1051,7 +1052,30 @@ void Control::resolveIMSI(L3MobileIdentity& mobileIdentity, LogicalChannel* LCH
}
}
unsigned Control::USSDDispatcher(GSM::L3MobileIdentity &mobileIdentity, unsigned TIFlag, unsigned TIValue,Control::USSDData::USSDMessageType messageType, string ussdString, bool MO)
bool USSDMatchHandler(const std::string &handlerName, const std::string &ussdString)
{
std::string handlerKeyName("USSD.Handler.");
handlerKeyName += handlerName;
if (gConfig.defines(handlerKeyName))
{
std::string handlerRegexpStr = gConfig.getStr(handlerKeyName);
Regexp handlerRegexp(handlerRegexpStr.data());
if (handlerRegexp.match(ussdString.data()))
{
LOG(DEBUG) << "Request " << ussdString << " matches regexp \""
<< handlerRegexpStr << "\" for USSD handler " << handlerName;
return true;
}
}
return false;
}
unsigned Control::USSDDispatcher(GSM::L3MobileIdentity &mobileIdentity,
unsigned TIFlag,
unsigned TIValue,
Control::USSDData::USSDMessageType messageType,
const std::string &ussdString,
bool MO)
{
TransactionEntry transaction(mobileIdentity, GSM::L3CMServiceType::SupplementaryService, TIFlag, TIValue, new USSDData(messageType));
gTransactionTable.add(transaction);
@ -1063,19 +1087,19 @@ unsigned Control::USSDDispatcher(GSM::L3MobileIdentity &mobileIdentity, unsigned
transaction.Q931State(Control::TransactionEntry::USSDworking);
transaction.ussdData()->postMS();
gTransactionTable.update(transaction);
std::string handleName = gConfig.getStr("USSD.Handler.MO");
Thread* thread = new Thread;
if (handleName=="HTTP")
if (USSDMatchHandler("HTTP", ussdString))
{
MOHttpHandler* handler = new MOHttpHandler(transaction.ID());
thread->start((void*(*)(void*))USSDHandler::runWrapper, handler);
}
else if (handleName=="CLI")
else if (USSDMatchHandler("CLI", ussdString))
{
MOCLIHandler* handler = new MOCLIHandler(transaction.ID());
thread->start((void*(*)(void*))USSDHandler::runWrapper, handler);
}
else if (handleName=="Test")
else if (USSDMatchHandler("Test", ussdString))
{
MOTestHandler* handler = new MOTestHandler(transaction.ID());
thread->start((void*(*)(void*))USSDHandler::runWrapper, handler);

View File

@ -913,7 +913,10 @@ extern Control::TMSITable gTMSITable;
namespace Control {
unsigned USSDDispatcher(GSM::L3MobileIdentity &mobileIdentity, unsigned TIFlag, unsigned TIValue, Control::USSDData::USSDMessageType messageType, std::string ussdString, bool MO);
bool USSDMatchHandler(const std::string &handlerName, const std::string &ussdString);
unsigned USSDDispatcher(GSM::L3MobileIdentity &mobileIdentity, unsigned TIFlag,
unsigned TIValue, Control::USSDData::USSDMessageType messageType,
const std::string &ussdString, bool MO);
class USSDHandler {

View File

@ -183,8 +183,15 @@ SMS.DefaultDestSMSC 0000
# USSD timeout for waiting MS response
USSD.timeout 100000
# USSD MO Handler (HTTP, CLI or Test)
USSD.Handler.MO CLI
# USSD handlers map.
# Option key has form USSD.Handler.<handler>, where <handler> is
# one of the following: HTTP, CLI and Test.
# Option value is a regexp. If it matches initial MO-USSD request,
# then request is passed for processing to according USSD handler.
# Comment out a handler option to completely disable the handler.
USSD.Handler.CLI \*101#
USSD.Handler.Test \*(100|1011|102)#
#USSD.Handler.HTTP
# The USSD HTTP gateway.
USSD.HTTP.Gateway api.clickatell.com