📄 sipurl.cxx
字号:
//we have a matchedparam, and value, but it is not //a recognized one. This may be other Params or //tel params. userInfo+=";"; userInfo+=key; userInfo+="="; userInfo+=value; } else { //belongs to SipUrl param. otherName = key; otherParam = value; } } matchedParam = false; //reset it back. } else { // done done = true; } } if (myData == "lr") { lrParam = true; } if ( (!userParamValid) || ( (userParamValid) && (userParam == "ip") ) ) { //did not find userParam. , or found ip in userParam. if (userValid) { user = new SipUser(userInfo); } } else //this is phone userparam. { if (userValid) { user = new SipTelSubscriberUser(userInfo); } } return true;}///DataSipUrl::encode() const{ // SIP-URL = "sip:" [ userinfo "@" ] hostport url-parameters [ headers ] Data sipurl; if (schemeName.length()) { sipurl = schemeName; } sipurl+= COLON; // userinfo = user [ ":" password ] if (user.getPtr() != 0) { Data u = user->encode(); u.removeSpaces(); if (u.length() > 0) { sipurl += user->encode(); if (passwd.length() > 0) { sipurl += COLON; sipurl += passwd; } sipurl += "@"; } } // hostport = host [ ":" port ] if(ipv6Addr) { sipurl += "["; sipurl += host; sipurl += "]"; } else { sipurl += host; } if (port.length() > 0 && port != "0") { sipurl += COLON; sipurl += port; } // url-parameters = *( ";" url-parameter ) // url-parameter = transport-param | user-param | method-param // | ttl-param | maddr-param | other-param // | tag-param // transport-param = "transport=" ( "udp" | "tcp" ) if (transportParam.length() > 0) { sipurl += SEMICOLON; sipurl += SipUrlParamTransport; sipurl += transportParam; } // ttl-param = "ttl=" ttl if (ttlParam.length() > 0) { sipurl += SEMICOLON; sipurl += SipUrlParamTtl; sipurl += ttlParam; } // maddr-param = "maddr=" host if (maddrParam.length() > 0) { sipurl += SEMICOLON; sipurl += SipUrlParamMaddr; sipurl += maddrParam; } // user-param = "user=" ( "phone" | "ip" ) if (userParam.length() > 0) { sipurl += SEMICOLON; sipurl += SipUrlParamUser; sipurl += userParam; } // method-param = "method=" Method if (methodParam.length() > 0) { sipurl += SEMICOLON; sipurl += SipUrlParamMethod; sipurl += methodParam; } // method-param = "method=" Method if (lrParam) { sipurl += SEMICOLON; sipurl += "lr"; // !jf! } // other-param = ( token | ( token "=" ( token | quoted-string ))) if (otherParam.length() > 0 ) { sipurl += SEMICOLON; sipurl += otherName; sipurl += "="; sipurl += otherParam; } // headers = "?" header *( "&" header ) // header = hname "=" hvalue if(EscObj != 0){ sipurl += "?"; sipurl += EscObj->getforwardEscapeheader(); } if (headers.length() > 0) //this should be a list separated by & { sipurl += "?"; sipurl += headers; } if (user.getPtr() != 0) { if (user->getType() == TEL_USER) { Sptr <SipTelSubscriberUser> telUser; sipurl += (telUser.dynamicCast(user))->getTelParams(); } } return sipurl;} // SipUrl::encodeDataSipUrl::getNameAddr() const{ // return before the url-parameters. Data nameaddr; if (schemeName.length()) { nameaddr = schemeName; nameaddr += COLON; } if (user.getPtr() != 0) { Data u = user->encode(); u.removeSpaces(); if (u.length() > 0) { nameaddr += user->encode(); if (passwd.length() > 0) { nameaddr += COLON; nameaddr += passwd; } nameaddr += "@"; } } if(ipv6Addr) { nameaddr += "["; nameaddr += host; nameaddr += "]"; } else { nameaddr += host; } if ( (port.length()) && port != "0") { nameaddr += ":"; nameaddr += port; } return nameaddr;}DataSipUrl::getUniqueKey() const{ return getNameAddr();}DataSipUrl::getNameAddrNoPort() const{ // return before the url-parameters. Data nameaddr = schemeName; Data userValue = getUserValue(); nameaddr += userValue; Data lpasswd = getPasswd(); if (lpasswd.length() > 0) { nameaddr += COLON; nameaddr += lpasswd; } if (userValue.length()) { nameaddr += "@"; } if(ipv6Addr) { nameaddr += "["; nameaddr += getHost(); nameaddr += "]"; } else { nameaddr += getHost(); } Data myport = getPort(); if (myport.length() > 0 && (myport != "0") && (myport != "5060")) { nameaddr += ":"; nameaddr += myport; } return nameaddr;}DataSipUrl::getUserValue() const{ Data userInfo; if (user.getPtr() != 0) { userInfo = user->encode(); } return userInfo;}DataSipUrl::getUrlParam() const{ //return only the url parms. Data urlparam1; if (transportParam.length() ) { urlparam1 += SEMICOLON; urlparam1 += TRANSPORT; urlparam1 += EQUAL; urlparam1 += transportParam; } if (ttlParam.length() ) { urlparam1 += SEMICOLON; urlparam1 += TTL; urlparam1 += EQUAL; urlparam1 += ttlParam; } if (maddrParam.length() ) { urlparam1 += SEMICOLON; urlparam1 += MADDR_PARM; urlparam1 += EQUAL; urlparam1 += maddrParam; } // user-param = "user=" ( "phone" | "ip" ) if (userParam.length() ) { cpLog(LOG_DEBUG_STACK, "SipUrl::encode : %s", userParam.logData()); urlparam1 += SEMICOLON; urlparam1 += SipUrlParamUser; urlparam1 += userParam; } // method-param = "method=" Method if (methodParam.length() ) { urlparam1 += SEMICOLON; urlparam1 += SipUrlParamMethod; urlparam1 += methodParam; } // other-param = ( token | ( token "=" ( token | quoted-string ))) if (otherParam.length() ) { urlparam1 += SEMICOLON; urlparam1 += otherName; urlparam1 += EQUAL; urlparam1 += otherParam; } if(EscObj != 0){ urlparam1 += "?"; urlparam1 += EscObj->getforwardEscapeheader(); } // headers = "?" header *( "&" header ) // header = hname "=" hvalue if (headers.length() > 0) { urlparam1 += "?"; urlparam1 += headers; } return urlparam1;}voidSipUrl::setTtlParam(const Data& newttl) throw(SipUrlParserException&){ Data temp = newttl; int myttl = temp.convertInt(); if ( (myttl < 0 ) || (myttl > 255 )) { cpLog(LOG_ERR, "Failed in URL_PARMS(Ttl) Parse'n :~( "); throw SipUrlParserException("Failed in URL_PARMS(Ttl) Parse'n :~(", __FILE__, __LINE__, NOT_VALID_TTL_PARM); } else { ttlParam = newttl; }} bool SipUrl::setUserValue(const Data& newUser, const Data& newUserParam){ if (user.getPtr() == 0) { if ( ( newUserParam == "") || (newUserParam == "ip") ) { user = new SipUser(); } else if (newUserParam == "phone") { user = new SipTelSubscriberUser(); } else { //userparam neither blank, ip, nor phone. return false. return false; } } user->decode(newUser); userParam = newUserParam; return true; } voidSipUrl::setUser(Sptr <BaseUser> newUser){ if (newUser.getPtr() != 0) { user = newUser->duplicate(); }} void SipUrl::setEscObj(Sptr<EmbeddedObj> newescobj){ EscObj = newescobj;} Sptr <BaseUser> SipUrl::getUser() const{ if (user.getPtr() != 0) { return user->duplicate(); } else { return 0; //NULL }} const Data&SipUrl:: getHost() const{ return host;} voidSipUrl::setHost(const Data& newhost){ if(NetworkAddress::is_valid_ip6_addr(newhost)) { ipv6Addr = true; } else { ipv6Addr = false; } host = newhost;} const Data&SipUrl::getPort() const{ return port;} void SipUrl::setPort(const Data& newport){ port = newport;} const Data&SipUrl::getPasswd() const{ return passwd;} void SipUrl::setPasswd(const Data& newpasswd){ passwd = newpasswd;} const Data&SipUrl::getTransportParam() const{ return transportParam;}void SipUrl::setTransportParam(const Data& newtransport){ transportParam = newtransport;}const Data& SipUrl::getMaddrParam() const{ return maddrParam;}voidSipUrl::setMaddrParam(const Data& newmaddr){ maddrParam = newmaddr;} const Data&SipUrl::getTtlParam() const{ return ttlParam;} const Data& SipUrl::getUserParam() const{ return userParam;} voidSipUrl::setUserParam(const Data& newUserParam){ userParam = newUserParam;} const Data& SipUrl::getMethodParam() const{ return methodParam ;} void SipUrl::setMethodParam(const Data& newmethodParm){ methodParam = newmethodParm;} const Data& SipUrl::getOtherParam() const{ return otherParam;} void SipUrl::setOtherParam(const Data& newotherParm){ otherParam = newotherParm;} void SipUrl::setOtherName(const Data& newOtherName){ otherName = newOtherName;} const Data&SipUrl::getOtherName() const{ return otherName;}boolSipUrl::isLooseRouterPresent() const{ return lrParam;} const Data& SipUrl::getHeaders() const{ return headers;} void SipUrl::setHeaders(const Data& newheader){ headers = newheader;}boolSipUrl::parseIpv6Address(Data& inData){ //Look for "]" char matchedChar; Data aAddr = inData.matchChar("]", &matchedChar); if(matchedChar == ']') { //aAddr is a IPV6 address //I think Validation of the address should be done //at common place, like in NetworkAddress- SP //So just keep in the raw form Data tmp; tmp = "["; tmp += aAddr; tmp += "]"; //ipv6Addr = true; host = tmp; return true; } return false;}NetworkAddressSipUrl::asNetworkAddress() const{ // could cache this in the SipUrl !jf! return NetworkAddress(host.convertString(), port == "" ? 5060 : port.convertInt());}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -