本文整理汇总了C++中SubscriberRegistry类的典型用法代码示例。如果您正苦于以下问题:C++ SubscriberRegistry类的具体用法?C++ SubscriberRegistry怎么用?C++ SubscriberRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubscriberRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateRand
// generate a 128' random number
string generateRand(string imsi)
{
string ki = gSubscriberRegistry.imsiGet(imsi, "ki");
string ret;
if (ki.length() != 0) {
LOG(INFO) << "ki is known";
// generate and return rand (clear any cached rand or sres)
gSubscriberRegistry.imsiSet(imsi, "rand", "", "sres", "");
ret = soGenerateIt();
} else {
string wRand = gSubscriberRegistry.imsiGet(imsi, "rand");
if (wRand.length() != 0) {
LOG(INFO) << "ki is unknown, rand is cached";
// return cached rand
ret = wRand;
} else {
LOG(INFO) << "ki is unknown, rand is not cached";
// generate rand, cache rand, clear sres, and return rand
wRand = soGenerateIt();
gSubscriberRegistry.imsiSet(imsi, "rand", wRand, "sres", "");
ret = wRand;
}
}
return ret;
}
示例2: table
void table(const char *tableName, vector<string> &cols, bool addButtonP, const char *note)
{
cout << "<h4>" << gDatabase << "." << tableName << " " << note << "</h4>\n";
initTable(cols);
ostringstream os;
os << "select id," << join(",", cols) << " from " << tableName;
sqlite3_stmt *stmt;
if (sqlite3_prepare_statement(gSubscriberRegistry.db(), &stmt,os.str().c_str())) {
LOG(ERR) << "sqlite3_prepare_statement problem - statement: " << os.str();
LOG(ERR) << " " << sqlite3_errmsg(gSubscriberRegistry.db());
return;
}
int src = sqlite3_run_query(gSubscriberRegistry.db(), stmt);
while (src == SQLITE_ROW) {
vector<string> values;
const char *id = (const char*)sqlite3_column_text(stmt, 0);
for (int i = 1; i <= (int)cols.size(); i++) {
const char *value = (const char*)sqlite3_column_text(stmt, i);
values.push_back(value ? value : "(null)");
}
tableRow(cols, values, UPDATE_BUTTON | DELETE_BUTTON, id);
src = sqlite3_run_query(gSubscriberRegistry.db(), stmt);
}
sqlite3_finalize(stmt);
if (addButtonP) {
vector<string> dummy;
tableRow(cols, dummy, ADD_BUTTON, "0");
}
}
示例3: authenticate
// verify sres given rand and imsi's ki
// may set kc
// may cache sres and rand
bool authenticate(string imsi, string randx, string sres, string *kc)
{
string ki = gSubscriberRegistry.imsiGet(imsi, "ki");
bool ret;
if (ki.length() == 0) {
// Ki is unknown
string sres2 = gSubscriberRegistry.imsiGet(imsi, "sres");
if (sres2.length() == 0) {
LOG(INFO) << "ki unknown, no upstream server, sres not cached";
// first time - cache sres and rand so next time
// correct cell phone will calc same sres from same rand
gSubscriberRegistry.imsiSet(imsi, "sres", sres, "rand", randx);
ret = true;
} else {
LOG(INFO) << "ki unknown, no upstream server, sres cached";
// check against cached values of rand and sres
string rand2 = gSubscriberRegistry.imsiGet(imsi, "rand");
// TODO - on success, compute and return kc
LOG(DEBUG) << "comparing " << sres << " to " << sres2 << " and " << randx << " to " << rand2;
ret = sresEqual(sres, sres2) && randEqual(randx, rand2);
}
} else {
LOG(INFO) << "ki known";
// Ki is known, so do normal authentication
ostringstream os;
// per user value from subscriber registry
string a3a8 = gSubscriberRegistry.imsiGet(imsi, "a3_a8");
if (a3a8.length() == 0) {
// config value is default
a3a8 = gConfig.getStr("SubscriberRegistry.A3A8");
}
os << a3a8 << " 0x" << ki << " 0x" << randx;
// must not put ki into the log
// LOG(INFO) << "running " << os.str();
FILE *f = popen(os.str().c_str(), "r");
if (f == NULL) {
LOG(CRIT) << "error: popen failed";
return false;
}
char sres2[26];
char *str = fgets(sres2, 26, f);
if (str != NULL && strlen(str) == 25) str[24] = 0;
if (str == NULL || strlen(str) != 24) {
LOG(CRIT) << "error: popen result failed";
return false;
}
int st = pclose(f);
if (st == -1) {
LOG(CRIT) << "error: pclose failed";
return false;
}
// first 8 chars are SRES; rest are Kc
*kc = sres2+8;
sres2[8] = 0;
LOG(INFO) << "result = " << sres2;
ret = sresEqual(sres, sres2);
}
LOG(INFO) << "returning = " << ret;
return ret;
}
示例4: main
int main(int argc, char *argv[]) {
SubscriberRegistry gHLR;
gLogInit("HLRTest");
gConfig.set("Log.Level","DEBUG");
if (argc!=2) {
std::cerr << "usage: " << argv[0] << " <number>" << std::endl;
exit(-1);
}
const char *targ = argv[1];
char *IMSI = gHLR.getIMSI(targ);
if (IMSI) std::cout << "IMSI for " << targ << " is " << IMSI << std::endl;
else std::cout << "no IMSI found for " << targ << std::endl;
char *CLID = gHLR.getCLIDLocal(IMSI);
if (CLID) std::cout << "CLID for " << IMSI << " is " << CLID << std::endl;
else std::cout << "no CLID found for " << IMSI << std::endl;
char *regIP = gHLR.getRegistrationIP("234100223456161");
if (regIP) std::cout << "registration IP for " << IMSI << " is " << regIP << std::endl;
else std::cout << "no regIP found for " << IMSI << std::endl;
IMSI = gHLR.getIMSI(targ);
if (IMSI) std::cout << "IMSI for " << targ << " is " << IMSI << std::endl;
else std::cout << "no IMSI found for " << targ << std::endl;
CLID = gHLR.getCLIDLocal(IMSI);
if (CLID) std::cout << "CLID for " << IMSI << " is " << CLID << std::endl;
else std::cout << "no CLID found for " << IMSI << std::endl;
const char targ2[] = "1234567890";
gHLR.addUser("123456789012345",targ2);
sleep(2);
IMSI = gHLR.getIMSI(targ2);
if (IMSI) std::cout << "IMSI for " << targ2 << " is " << IMSI << std::endl;
else std::cout << "no IMSI found for " << targ2 << std::endl;
CLID = gHLR.getCLIDLocal(IMSI);
if (CLID) std::cout << "CLID for " << IMSI << " is " << CLID << std::endl;
else std::cout << "no CLID found for " << IMSI << std::endl;
}
示例5: imsiSet
void imsiSet(string imsi, string key1, string value1, string key2, string value2)
{
string name = imsi.substr(0,4) == "IMSI" ? imsi : "IMSI" + imsi;
ostringstream os2;
os2 << "update sip_buddies set " << key1 << " = \"" << value1 << "\"," << key2 << " = \"" << value2 << "\" where username = \"" << name << "\"";
if (!sqlite3_command(gSubscriberRegistry.db(), os2.str().c_str())) {
LOG(ERR) << "sqlite3_command problem";
return;
}
}
示例6: getFields
void getFields(vector<string> *fields, vector<bool> *isSet)
{
vector<string> vsc;
split(' ', gVisibleSipColumns, &vsc);
sqlite3_stmt *stmt;
const char *cmd = "pragma table_info(sip_buddies)";
if (sqlite3_prepare_statement(gSubscriberRegistry.db(), &stmt, cmd)) {
LOG(ERR) << "sqlite3_prepare_statement problem - statement: " << cmd;
LOG(ERR) << " " << sqlite3_errmsg(gSubscriberRegistry.db());
return;
}
int src = sqlite3_run_query(gSubscriberRegistry.db(), stmt);
while (src == SQLITE_ROW) {
string field = (char*)sqlite3_column_text(stmt, 1);
fields->push_back(field);
isSet->push_back(find(vsc.begin(), vsc.end(), field) != vsc.end());
src = sqlite3_run_query(gSubscriberRegistry.db(), stmt);
}
sqlite3_finalize(stmt);
}
示例7: imsiGet
string imsiGet(string imsi, string key)
{
string name = imsi.substr(0,4) == "IMSI" ? imsi : "IMSI" + imsi;
char *value;
if (!sqlite3_single_lookup(gSubscriberRegistry.db(), "sip_buddies", "username", name.c_str(), key.c_str(), value)) {
return "";
}
if (!value) { return ""; }
string retValue = value;
free(value);
return retValue;
}
示例8: generateSqlResponse
// run an sql statement through sqlite3 to get a response
void generateSqlResponse()
{
string stmts = getArg("stmts");
vector<string> vstmts;
split(';', stmts, &vstmts);
vector<string>::iterator it;
for (it = vstmts.begin(); it != vstmts.end(); it++) {
sqlite3_stmt *stmt;
if (sqlite3_prepare_statement(gSubscriberRegistry.db(), &stmt, it->c_str())) {
LOG(ERR) << "sqlite3_prepare_statement problem - statement: " << it->c_str();
return;
}
int src = sqlite3_run_query(gSubscriberRegistry.db(), stmt);
while (src == SQLITE_ROW) {
string resp = "res=";
int cols = sqlite3_column_count(stmt);
for (int i = 0; i < cols; i++) {
resp.append((const char*)sqlite3_column_text(stmt, i));
}
gResponse.push_back(resp);
src = sqlite3_run_query(gSubscriberRegistry.db(), stmt);
}
}
}
示例9: randEqual
bool randEqual(string a, string b)
{
uint64_t rand1h = 0;
uint64_t rand1l = 0;
uint64_t rand2h = 0;
uint64_t rand2l = 0;
if (a.empty() || b.empty())
return false;
gSubscriberRegistry.stringToUint(a, &rand1h, &rand1l);
gSubscriberRegistry.stringToUint(b, &rand2h, &rand2l);
LOG(DEBUG) << "rand1h = " << rand1h << ", rand1l = " << rand1l;
LOG(DEBUG) << "rand2h = " << rand2h << ", rand2l = " << rand2l;
return (rand1h == rand2h) && (rand1l == rand2l);
}
示例10: doCmd
void doCmd(string cmd)
{
string table;
vector<string> cols;
if (gArgs.find("dial") == gArgs.end()) {
table = "sip_buddies";
split(' ', gVisibleSipColumns, &cols);
} else {
table = "dialdata_table";
split(' ', gVisibleExtColumns, &cols);
}
string id = gArgs["id"];
ostringstream os;
if (cmd == "add") {
string names = join(",", cols);
vector<string> values0;
vector<string>::iterator it;
for (it = cols.begin(); it != cols.end(); it++) {
values0.push_back(nullCheck(gArgs[*it]));
}
string values = join(",", values0);
os << "insert into " << table << " (" << names << ") values (" << values << ")";
} else if (cmd == "delete") {
os << "delete from " << table << " where id = " << id;
} else if (cmd == "update") {
vector<string> sets0;
vector<string>::iterator it;
for (it = cols.begin(); it != cols.end(); it++) {
sets0.push_back(*it + "=" + nullCheck(gArgs[*it]));
}
string sets = join(",", sets0);
os << "update " << table << " set " << sets << " where id = " << id;
} else {
LOG(ERR) << "internal error";
}
LOG(INFO) << os.str();
if (!sqlite3_command(gSubscriberRegistry.db(), os.str().c_str())) {
LOG(ERR) << "sqlite3_command problem - statement: " << os.str();
return;
}
mainTables();
}
示例11: main
int main(int argc, char **argv)
{
// start the html return
initHtml();
// read the config file
gVisibleSipColumns = gConfig.getStr("SubscriberRegistry.Manager.VisibleColumns");
gUrl = "/cgi/srmanager.cgi";
gTitle = gConfig.getStr("SubscriberRegistry.Manager.Title");
// connect to the database
gDatabase = gConfig.getStr("SubscriberRegistry.db");
// decode the http query
decodeQuery(gArgs);
// execute command
string what = gArgs["what"];
if (!what.length() || what == "Main") {
mainTables();
} else if (what == "Add") {
doCmd("add");
} else if (what == "Update") {
doCmd("update");
} else if (what == "Delete") {
doCmd("delete");
} else if (what == "Provision") {
gSubscriberRegistry.addUser(gArgs["imsi"].c_str(), gArgs["phonenumber"].c_str());
mainTables();
} else if (what == "Submit") {
doVisibles();
mainTables();
} else {
cout << "unrecognized what parameter<br>\n";
map<string,string>::iterator it;
for (it = gArgs.begin(); it != gArgs.end(); it++) {
cout << it->first << " -> " << it->second << "<br>\n";
}
}
// finish the html return
endHtml();
}
示例12: main
int main(int argc, char *argv[])
{
try {
srandom(time(NULL));
gConfig.setUpdateHook(purgeConfig);
gLogInit("openbts",gConfig.getStr("Log.Level").c_str(),LOG_LOCAL7);
LOG(ALERT) << "OpenBTS starting, ver " << VERSION << " build date " << __DATE__;
COUT("\n\n" << gOpenBTSWelcome << "\n");
gTMSITable.open(gConfig.getStr("Control.Reporting.TMSITable").c_str());
gTransactionTable.init();
gPhysStatus.open(gConfig.getStr("Control.Reporting.PhysStatusTable").c_str());
gBTS.init();
gSubscriberRegistry.init();
gParser.addCommands();
COUT("\nStarting the system...");
Thread transceiverThread;
transceiverThread.start((void*(*)(void*)) startTransceiver, NULL);
// Start the SIP interface.
gSIPInterface.start();
//
// Configure the radio.
//
// Start the transceiver interface.
// Sleep long enough for the USRP to bootload.
sleep(5);
gTRX.start();
// Set up the interface to the radio.
// Get a handle to the C0 transceiver interface.
ARFCNManager* C0radio = gTRX.ARFCN();
// Tuning.
// Make sure its off for tuning.
C0radio->powerOff();
// Get the ARFCN list.
unsigned C0 = gConfig.getNum("GSM.Radio.C0");
// Tune the radio.
LOG(INFO) << "tuning TRX to ARFCN " << C0;
ARFCNManager* radio = gTRX.ARFCN();
radio->tune(C0);
// Set TSC same as BCC everywhere.
C0radio->setTSC(gBTS.BCC());
// Set maximum expected delay spread.
C0radio->setMaxDelay(gConfig.getNum("GSM.Radio.MaxExpectedDelaySpread"));
// Set Receiver Gain
C0radio->setRxGain(gConfig.getNum("GSM.Radio.RxGain"));
// Turn on and power up.
C0radio->powerOn();
C0radio->setPower(gConfig.getNum("GSM.Radio.PowerManager.MinAttenDB"));
//
// Create a C-V channel set on C0T0.
//
// C-V on C0T0
C0radio->setSlot(0,5);
// SCH
SCHL1FEC SCH;
SCH.downstream(C0radio);
SCH.open();
// FCCH
FCCHL1FEC FCCH;
FCCH.downstream(C0radio);
FCCH.open();
// BCCH
BCCHL1FEC BCCH;
BCCH.downstream(C0radio);
BCCH.open();
// RACH
RACHL1FEC RACH(gRACHC5Mapping);
RACH.downstream(C0radio);
RACH.open();
// CCCHs
CCCHLogicalChannel CCCH0(gCCCH_0Mapping);
CCCH0.downstream(C0radio);
CCCH0.open();
CCCHLogicalChannel CCCH1(gCCCH_1Mapping);
CCCH1.downstream(C0radio);
CCCH1.open();
CCCHLogicalChannel CCCH2(gCCCH_2Mapping);
CCCH2.downstream(C0radio);
CCCH2.open();
// use CCCHs as AGCHs
gBTS.addAGCH(&CCCH0);
gBTS.addAGCH(&CCCH1);
gBTS.addAGCH(&CCCH2);
//.........这里部分代码省略.........
示例13: LOG
char *processBuffer(char *buffer)
{
int i;
// parse sip message
osip_message_t *sip;
i=osip_message_init(&sip);
if (i!=0) {
LOG(ERR) << "cannot allocate";
osip_message_free(sip);
return NULL;
}
i=osip_message_parse(sip, buffer, strlen(buffer));
if (i!=0) {
LOG(ERR) << "cannot parse sip message";
osip_message_free(sip);
return NULL;
}
prettyPrint("request", sip);
// response starts as clone of message
osip_message_t *response;
osip_message_clone(sip, &response);
osip_from_t * contact_header = (osip_from_t*)osip_list_get(&sip->contacts,0);
osip_uri_t* contact_url = contact_header->url;
char *remote_host = contact_url->host;
char *remote_port = contact_url->port;
// return via
ostringstream newvia;
// newvia << "SIP/2.0/UDP localhost:5063;branch=1;[email protected]";
const char *my_ipaddress = "localhost";
newvia << "SIP/2.0/UDP " << my_ipaddress << ":" << my_udp_port << ";branch=1;received="
<< "[email protected]"; // << my_network.string_addr((struct sockaddr *)netaddr, netaddrlen, false);
osip_message_append_via(response, newvia.str().c_str());
// no method
osip_message_set_method(response, NULL);
string imsi = imsiClean(imsiFromSip(sip));
string imsiTo = imsiClean(imsiToSip(sip));
if ((imsi == "EXIT") && (imsiTo == "EXIT")) exit(0); // for testing only
if (!imsiFound(imsi)) {
LOG(NOTICE) << "imsi unknown";
// imsi problem => 404 IMSI Not Found
osip_message_set_status_code (response, 404);
osip_message_set_reason_phrase (response, osip_strdup("IMSI Not Found"));
} else if (gConfig.defines("SubscriberRegistry.IgnoreAuthentication")) {
osip_message_set_status_code (response, 200);
osip_message_set_reason_phrase (response, osip_strdup("OK"));
LOG(INFO) << "success, imsi " << imsi << " registering for IP address " << remote_host;
gSubscriberRegistry.imsiSet(imsi,"ipaddr", remote_host, "port", remote_port);
} else {
// look for rand and sres in Authorization header (assume imsi same as in from)
string randx;
string sres;
// sip parser is not working reliably for Authorization, so we'll do the parsing
char *RAND = strcasestr(buffer, "nonce=");
char *SRES = strcasestr(buffer, "response=");
if (RAND && SRES) {
// find RAND digits
RAND += 6;
while (!isalnum(*RAND)) { RAND++; }
RAND[32] = 0;
int j=0;
// FIXME -- These loops should use strspn instead.
while(isalnum(RAND[j])) { j++; }
RAND[j] = '\0';
// find SRES digits
SRES += 9;
while (!isalnum(*SRES)) { SRES++; }
int i=0;
// FIXME -- These loops should use strspn instead.
while(isalnum(SRES[i])) { i++; }
SRES[i] = '\0';
LOG(INFO) << "rand = /" << RAND << "/";
LOG(INFO) << "sres = /" << SRES << "/";
}
if (!RAND || !SRES) {
LOG(NOTICE) << "imsi " << imsi << " known, 1st register";
// no rand and sres => 401 Unauthorized
osip_message_set_status_code (response, 401);
osip_message_set_reason_phrase (response, osip_strdup("Unauthorized"));
// but include rand in www_authenticate
osip_www_authenticate_t *auth;
osip_www_authenticate_init(&auth);
// auth type is required by osip_www_authenticate_to_str (and therefore osip_message_to_str)
string auth_type = "Digest";
osip_www_authenticate_set_auth_type(auth, osip_strdup(auth_type.c_str()));
// returning RAND in www_authenticate header
string randz = generateRand(imsi);
osip_www_authenticate_set_nonce(auth, osip_strdup(randz.c_str()));
i = osip_list_add (&response->www_authenticates, auth, -1);
if (i < 0) LOG(ERR) << "problem adding www_authenticate";
} else {
string kc;
bool sres_good = authenticate(imsi, RAND, SRES, &kc);
LOG(INFO) << "imsi " << imsi << " known, 2nd register, good = " << sres_good;
//.........这里部分代码省略.........
示例14: main
int main(int argc, char *argv[])
{
// TODO: Properly parse and handle any arguments
if (argc > 1) {
for (int argi = 0; argi < argc; argi++) {
if (!strcmp(argv[argi], "--version") ||
!strcmp(argv[argi], "-v")) {
cout << gVersionString << endl;
}
}
return 0;
}
createStats();
gReports.incr("OpenBTS.Starts");
int sock = socket(AF_UNIX,SOCK_DGRAM,0);
if (sock<0) {
perror("creating CLI datagram socket");
LOG(ALERT) << "cannot create socket for CLI";
gReports.incr("OpenBTS.Exit.CLI.Socket");
exit(1);
}
try {
srandom(time(NULL));
gConfig.setUpdateHook(purgeConfig);
gLogInit("openbts",gConfig.getStr("Log.Level").c_str());
LOG(ALERT) << "OpenBTS starting, ver " << VERSION << " build date " << __DATE__;
COUT("\n\n" << gOpenBTSWelcome << "\n");
gTMSITable.open(gConfig.getStr("Control.Reporting.TMSITable").c_str());
gTransactionTable.init(gConfig.getStr("Control.Reporting.TransactionTable").c_str());
gPhysStatus.open(gConfig.getStr("Control.Reporting.PhysStatusTable").c_str());
gBTS.init();
gSubscriberRegistry.init();
gParser.addCommands();
COUT("\nStarting the system...");
// is the radio running?
// Start the transceiver interface.
LOG(INFO) << "checking transceiver";
//gTRX.ARFCN(0)->powerOn();
//sleep(gConfig.getNum("TRX.Timeout.Start",2));
bool haveTRX = gTRX.ARFCN(0)->powerOn(false);
Thread transceiverThread;
if (!haveTRX) {
transceiverThread.start((void*(*)(void*)) startTransceiver, NULL);
// sleep to let the FPGA code load
// TODO: we should be "pinging" the radio instead of sleeping
sleep(5);
} else {
LOG(NOTICE) << "transceiver already running";
}
// Start the SIP interface.
gSIPInterface.start();
//
// Configure the radio.
//
gTRX.start();
// Set up the interface to the radio.
// Get a handle to the C0 transceiver interface.
ARFCNManager* C0radio = gTRX.ARFCN(0);
// Tuning.
// Make sure its off for tuning.
//C0radio->powerOff();
// Get the ARFCN list.
unsigned C0 = gConfig.getNum("GSM.Radio.C0");
unsigned numARFCNs = gConfig.getNum("GSM.Radio.ARFCNs");
for (unsigned i=0; i<numARFCNs; i++) {
// Tune the radios.
unsigned ARFCN = C0 + i*2;
LOG(INFO) << "tuning TRX " << i << " to ARFCN " << ARFCN;
ARFCNManager* radio = gTRX.ARFCN(i);
radio->tune(ARFCN);
}
// Send either TSC or full BSIC depending on radio need
if (gConfig.getBool("GSM.Radio.NeedBSIC")) {
// Send BSIC to
C0radio->setBSIC(gBTS.BSIC());
} else {
// Set TSC same as BCC everywhere.
C0radio->setTSC(gBTS.BCC());
}
// Set maximum expected delay spread.
C0radio->setMaxDelay(gConfig.getNum("GSM.Radio.MaxExpectedDelaySpread"));
//.........这里部分代码省略.........
示例15: imsiFound
// is imsi in the database?
bool imsiFound(string imsi)
{
string x = gSubscriberRegistry.imsiGet(imsi, "id");
return x.length() != 0;
}