⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipvia.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
    Data parmvalue;    viaparm = data;    parmvalue = pvalue;    viaparm.removeSpaces();    parmvalue.removeSpaces();    //Check for Hidden Parm First since this the Only Param Without "="    if (viaparm == HIDDEN)    {	viaHidden=true;    }    else    {	Data value;	// Check for the Parms With Constant "=" sign	int check = viaparm.match("=", &value , true);	  		if ( check == NOT_FOUND)	{		viaparm.removeSpaces();     		if (viaparm != RPORT)		{		   if (SipParserMode::sipParserMode())	    	   {			cpLog(LOG_ERR,"not a valid Viaparm syntax  <%s>", pvalue.logData());			throw SipViaParserException( "not a valid Viaparm syntax",			    __FILE__,__LINE__,PARSE_VIAPRAM_ERR);	    	    }		}		else rport = true;	}	else if (check == FIRST)	{	    if (SipParserMode::sipParserMode())	    {		cpLog(LOG_ERR,"not a valid Viaparm syntax  <%s>", pvalue.logData());		throw SipViaParserException("not a valid Viaparm syntax",		    __FILE__,__LINE__,PARSE_VIAPRAM_ERR);	    }	}	else if (check == FOUND)	{		    //value has the correct 	    	    if (viaparm.length())	    {		try 		{		    value.removeSpaces();		    viaparm.removeSpaces(); 		    parseViaParm(value,viaparm);		}		catch (SipViaParserException& exception)		{ 		    if (SipParserMode::sipParserMode())		    {			cpLog(LOG_ERR,"The Via String Contains Null  <%s>", pvalue.logData());			throw SipViaParserException (exception.getDescription(),			    __FILE__,__LINE__,PARSE_VIAPRAM_ERR); 		    }						}	    }	}    }}voidSipVia::parseViaParm(const Data & data, const Data & value){    Data viaparm;    Data parmvalue;    viaparm = data;    parmvalue = value;    if (viaparm == MADDR_PARM)    {	setMaddr(parmvalue);    }    else if (viaparm == RECEIVED)    {	parseRecevied(parmvalue);    }    else if (viaparm == TTL)    {   	int phvalue1 = parmvalue.convertInt();	if (phvalue1>=0 && phvalue1<=255) 	{	    setTtl(parmvalue);	}	else	{	    if (SipParserMode::sipParserMode())	    {		cpLog(LOG_ERR,"not a valid Viaparm ttl syntax  <%s>", value.logData());		throw SipViaParserException("not a valid ttl syntax",		    __FILE__,__LINE__,PARSE_VIAPRAM_ERR);	    }	}    }    else if (viaparm == BRANCH)    {	parseBranch(parmvalue);    }    else if (viaparm == RPORT)    {	setRPort(parmvalue);    }    else    {	// This introduced with New SIpDraft not Offical(2543b)	parseExtension(viaparm,parmvalue);	           }}void SipVia::parseRecevied(const Data& recevieddata){    setReceivedhost(recevieddata);}void SipVia::parseBranch(const Data& branchdata){    Data branchdat =  branchdata;    branchdat.removeSpaces();    Data branchval;    int test = branchdat.match("(",&branchval,true);    if (test == FOUND)    {	setBranch(branchval);	Data brdat=branchdat;	Data brval;	int ret = brdat.match(")",&brval,true);	if (ret == FOUND)	{	    setComment(brval);	}	else if (ret == NOT_FOUND)	{	}	else if (ret == FIRST)	{	}    }    else if (test == NOT_FOUND)    {	setBranch(branchdat);    }    else if (test == FIRST)    {    }}void SipVia::parseExtension(const Data& extensiondata, const Data& extensionvalue){	Data tokenparm = extensiondata ;	Data tokenvalue = extensionvalue;	setExtensionParm(tokenparm);       	setExtensionValue(tokenvalue);	    }void SipVia::parseTransport(const Data& tdata){    Data transdata=tdata;    setTransport(transdata);}void SipVia::setprotoName(const Data& protoName){    protocolName = protoName;}voidSipVia::setRPort(const Data& port){	rportValue = port;	rport = true;}voidSipVia::setRPort(const bool flag){	rport = flag;	rportValue = "";}DataSipVia::getRPort() const{	return rportValue;}DataSipVia::getprotoName() const{        return protocolName;}void SipVia::setprotoVersion(const Data& protoVer){    protocolVersion = protoVer;}Data SipVia::getprotoVersion() const{    return protocolVersion;}void SipVia::setTransport(const Data& trans){    transport = trans;}/* This is the transport which appears in sent-protocol, and not in * transport-param. Hence it is stored here */DataSipVia::getTransport() const{    return transport;}void SipVia::parseHost(const Data& newHost){    Data hostport = newHost;    Data hostdata;    // v6 Address    int ret = hostport.match("]",&hostdata,true);    if (ret == FOUND) {	hostdata += "]";	char tmp = ':';	hostport.matchChar(&tmp);    }    else if (ret == NOT_FOUND) {	ret = hostport.match(":",&hostdata,true);    }    if (ret == FOUND)    {	Data testo;	int retu = hostdata.match(" ",&testo,true);	if (retu == FIRST)	{	    setHost(hostdata);	}	else  if(retu == NOT_FOUND)	{	    setHost(hostdata);	}	else  if (retu == FOUND)	{	    cpLog(LOG_ERR, "Spaces between Net Address <%s>", newHost.logData());	}	setPort(hostport.convertInt());    }    else if (ret == FIRST)    {	        }    else if (ret == NOT_FOUND)    {        hostport.removeSpaces();	setHost(hostport);    }}void SipVia::setHost( const Data&  newHost){    host = newHost;}const Data&SipVia::getHost() const{    return host;}void SipVia::setPort(int newport){    port = Data(newport);}void SipVia::setPortData( const Data&  newport){    port = newport;}int SipVia::getPort() const{    return port.convertInt();}void SipVia::setTtl(const Data& newttl){    ttl = newttl;    if (ttl.length()>0)    {	viaTtl=true;    }}void SipVia::setMaddr(const Data& newmaddr){    maddr=newmaddr;    if (maddr.length()>0)    {	viaMaddr=true;    }}DataSipVia::getMaddr() const{    return maddr;}/***This belongs to the other-parms. So, maintain here? */voidSipVia::setReceivedhost(const Data& recvdhost){    if(NetworkAddress::is_valid_ip6_addr(recvdhost))    {        receivedHost = "[";        receivedHost += recvdhost;        receivedHost += "]";    }    else    {        receivedHost = recvdhost;    }    if (receivedHost.length())    {        viaReceived = true;    }}DataSipVia::getReceivedhost() const{    return receivedHost;}/** This belongs to the other-parms. So, maintain here? */voidSipVia::setHidden(const Data& hidden){    if (hidden == HIDDEN)    {        viaHidden = true;    }}boolSipVia::getHidden() const{    return viaHidden;}void SipVia::setBranch(const Data& newtoken){    branchToken = newtoken;    if (branchToken.length())    {        viaBranch = true;    }    else    {        viaBranch = false;    }}DataSipVia::getBranch() const{    return branchToken;}/** This belongs to the other-parms. So, maintain here? */void SipVia::setComment(const Data& newcomment){    comment = newcomment;    if (comment.length())    {        viaComment = true;    }}DataSipVia::getComment() const{    return comment;}    /*** return the encoded string version of this. This call should only be         used inside the stack and is not part of the API */DataSipVia::encode() const{    Data ret;        ret = VIA;        ret+= SP;        //construct the sent-protocol    Data sentprotocol = getprotoName();    sentprotocol+= "/";    sentprotocol+= DEFAULT_VERSION;    sentprotocol+= "/";    sentprotocol+= getTransport();    sentprotocol+= SP;        ret += sentprotocol;    ret +=getHost();    Data pport = Data(getPort());    if (pport.length() > 0)    {        ret+= ":";        ret+= pport;    }    ret+= formOtherparms();     ret+= CRLF;          return ret;}Data SipVia::formOtherparms() const{    Data otherparms;    //construct via-parms.    if ( (viaHidden) ||(viaTtl)||(viaMaddr)||(viaReceived) ||	 (viaBranch) || (viaComment) || (rport))    {        if (viaHidden)	{	    otherparms+=";";	    otherparms+=HIDDEN;	}	if (viaTtl)	{	    otherparms += ";";	    otherparms +=TTL;	    otherparms +="=";	    otherparms +=getTtl();	}	if (rport)	{	    otherparms= otherparms+";"+RPORT;	    if (rportValue.length())		otherparms = otherparms+"="+rportValue;	}	if (viaMaddr)	{	    otherparms += ";";	    otherparms += MADDR_PARM;	    otherparms += "=";	    otherparms += getMaddr();	}	if (viaReceived)	{	    otherparms+=";";	    otherparms+=RECEIVED;	    otherparms+="=";	    otherparms+= getReceivedhost();	}	if (viaBranch)	{	    otherparms+=";"; 	    otherparms+=BRANCH;	    otherparms+="=";	    otherparms+= getBranch();	}		if (viaComment)	{	    otherparms+= "(";	    otherparms+= getComment();	    otherparms+= ")";	}    }        return otherparms;}DataSipVia::getExtensionValue() const {  return extvalue;}DataSipVia:: getExtensionParm() const {  return extparm;}void SipVia::setExtensionParm(const Data & newextparm){  extparm = newextparm;}voidSipVia:: setExtensionValue(const Data& newextvalue){  extvalue = newextvalue;}Data SipVia::getTtl()const{   return ttl;}     voidSipVia::setReceivedport(const Data& recvdport){    setRPort(recvdport);}Data SipVia::getReceivedport() const{    return getRPort();}bool SipVia::isViaReceived() const{    return viaReceived;    }SipHeader*SipVia::duplicate() const{    return new SipVia(*this);}boolSipVia::compareSipHeader(SipHeader* msg) const{    SipVia* otherMsg = dynamic_cast<SipVia*>(msg);    if(otherMsg != 0)    {	return (*this == *otherMsg);    }    else    {	return false;    }}/* 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 + -