📄 digitcollector.cxx
字号:
colonPos1 = phoneNum.find( ":" ); colonPos2 = phoneNum.rfind( ":" ); atPos = phoneNum.find( "@" ); if( colonPos1 == string::npos ) { // No ':' if( atPos == string::npos ) { // No '@' // In this case, do we need to make sure that destination // is only [0-9]* ? userName = phoneNum; password = ""; destination = "@" + destHostIpAddr; sipPort = ":" + sipPortNum; } else { // We have an '@' userName = phoneNum.substr( 0, atPos ); password = ""; destination = phoneNum.substr( atPos ); sipPort = ":5060"; } } else // We have at least one ':' { // In this case, we need an '@' if( atPos == string::npos ) { cpLog( LOG_ERR, "Error: No @ in Speed_Dial, exiting...\n" ); return 0; } if( colonPos1 != colonPos2 ) { // We have a port & a password// cpLog( LOG_DEBUG, "We have a port & a password" ); userName = phoneNum.substr( 0, colonPos1 ); password = phoneNum.substr( colonPos1, atPos - colonPos1 ); destination = phoneNum.substr( atPos, colonPos2 - atPos ); sipPort = phoneNum.substr( colonPos2 ); } else { // We have either a port, or a password if( colonPos1 < atPos ) { // We have a password, but no port// cpLog( LOG_DEBUG, "We have a password, but no port" ); userName = phoneNum.substr( 0, colonPos1 ); password = phoneNum.substr( colonPos1, atPos - colonPos1 ); destination = phoneNum.substr( atPos ); sipPort = ":5060"; } else { // We have a port, but no password// cpLog( LOG_DEBUG, "We have a port, but no password" ); userName = phoneNum.substr( 0, atPos ); password = ""; destination = phoneNum.substr( atPos, colonPos2 - atPos ); sipPort = phoneNum.substr( colonPos2 ); } } } // Set the SipUrl url = "sip:" + userName + password + destination + sipPort; if( atPos == string::npos ) { dialedType = dial_phone; } else { dialedType = dial_ip; } } regfree(&re); cpLog( LOG_DEBUG , "DigitCollector url is returning %s", url.c_str()); return url;}/*stringDigitCollector::getUrlFromIpAddr(){ //get the current 3 digits of the IP address. string url = "sip:user@"; string firstIPpart = theSystem.getFirstIPpart(); url += firstIPpart; //returns the first three digits. //getdial returns the last IP part. url += "."; string dial2 = dial; dial2.erase(0, 1); const char *dialStr = dial2.c_str(); if ( dialStr[0] != '0' ) url += dial; else if ( dialStr[1] != '0' ) { url += dialStr[1]; url += dialStr[2]; } else url += dialStr[2]; if (sipPortNum == "" ) { url += ":5060"; } else { url += string(":"); url += sipPortNum; } dialedType = dial_ip; cpLog( LOG_DEBUG , "DigitCollector url is returning %s", url.c_str()); return url;}*////stringDigitCollector::getCallReturnUrl(){ string url = ""; if ( prevInUrls.size() > 0 ) { list < string > ::iterator iter = prevInUrls.begin(); url = *iter; if ( url.find(dial_phone) != string::npos ) dialedType = dial_phone; else dialedType = dial_ip; } cpLog( LOG_DEBUG , "DigitCollector url is returning %s", url.c_str()); return url;}///voidDigitCollector::addSpeedDial(const string& key, const string& phoneNum){ speedDialMap[key] = phoneNum;}///voidDigitCollector::addDialPlan(const DialingPlan* dialingPlan){ if ( dialingPlan == 0 ) { return; } for( DialingPlanListType::iterator iter = dialingPlanList.begin(); iter != dialingPlanList.end(); iter++ ) { const DialingPlan* pDialingPlan = *iter; if( pDialingPlan != 0 && *pDialingPlan == *dialingPlan ) { dialingPlanList.erase( iter ); break; } } dialingPlanList.push_back( dialingPlan ); unsigned int patternLen = dialingPlan->getDialPattern().length(); if ( patternLen > maxDialPatternLen ) { maxDialPatternLen = patternLen; }}///voidDigitCollector::flushDialPlan(){ DialingPlanListType::iterator iDialingPlanList = dialingPlanList.begin(); while ( iDialingPlanList != dialingPlanList.end() ) { const DialingPlan* dialingPlan = *iDialingPlanList; delete dialingPlan; ++iDialingPlanList; } dialingPlanList.clear();}///DialMethodsTypeDigitCollector::findDialPlan(){ regex_t re; DialMethodsType method = INCOMPLETE_DIAL; if(dialMethod == URL_DIAL) { return URL_DIAL; } //if the number of digits already dialed is longer than max length of all //dialing patterns we have, then we just return WRONG_DIAL if ( dial.length() > maxDialPatternLen ) { cpLog( LOG_DEBUG, "WRONG_DIAL-Number of dialed digits(%d) is too long", dial.length() ); return WRONG_DIAL; } //match the patterns. We assume that there is only match in the list //of patterns we have DialingPlanListType::iterator iDialingPlanList = dialingPlanList.begin(); cpLog( LOG_DEBUG, "Dialed string \"%s\"", dial.c_str() ); while ( iDialingPlanList != dialingPlanList.end() ) { const DialingPlan* dialingPlan = *iDialingPlanList; if ( !dialingPlan ) continue; const char *pattern = dialingPlan->getDialPattern().c_str(); if ( 0 != regcomp(&re, pattern, REG_EXTENDED) ) { cpLog( LOG_DEBUG, "WRONG_DIAL-Pattern not match" ); return WRONG_DIAL; } const char *dialstr = dial.c_str(); if ( REG_NOMATCH == regexec( &re, dialstr, 0, NULL, 0) ) ++iDialingPlanList; else { method = dialingPlan->getDialMethod(); break; } regfree(&re); } switch ( method ) { case SPEED_DIAL: { cpLog( LOG_DEBUG, "SPEED_DIAL" ); } break; case SPECIAL_KEY_DIAL: { cpLog( LOG_DEBUG, "SPECIAL_KEY_DIAL" ); } break; case NORMAL_DIAL: { cpLog( LOG_DEBUG, "NORMAL_DIAL" ); } break; case INTERNAL_IP_DIAL: { cpLog( LOG_DEBUG, "INTERNAL_IP_DIAL" ); } break; case INCOMPLETE_DIAL: { cpLog( LOG_DEBUG, "INCOMPLETE_DIAL" ); } break; default: { cpLog( LOG_DEBUG, "WRONG_DIAL" ); } } /* switch */ return method;}//voidDigitCollector::addIncomingUrl( const string& url ){ if ( prevInUrls.size() >= MAX_PREV_IN_URLS_SIZE ) { prevInUrls.pop_back(); } prevInUrls.insert(prevInUrls.begin(), url);}///constructor for the dialing planDialingPlan::DialingPlan(string pattern, DialMethodsType method){ dialPattern = pattern; dialMethod = method;}///DialingPlan::DialingPlan(const DialingPlan& src){ dialPattern = src.dialPattern; dialMethod = src.dialMethod;}///equality operator for DialingPlan.///returns true if the dialPattern are equivalentboolDialingPlan::operator ==(const DialingPlan& dialPlan) const{ return dialPattern == dialPlan.dialPattern;}///voidDialingPlan::operator =(const DialingPlan& src){ dialPattern = src.dialPattern; dialMethod = src.dialMethod;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -