Click here to Skip to main content
15,886,052 members
Articles / Programming Languages / Visual C++ 10.0

SIP Stack (1 of 3)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
20 Aug 2012CPOL3 min read 30K   1.7K   4  
SIP Stack Implementation on the basis of RFC SIP 3261 Specification
#include "SIPParserInclude\CSIPMaxForwardsParser.h"

namespace SIPParserFW
{
	CSIPMaxForwardsParser::CSIPMaxForwardsParser()
	{
		ReleaseCSIPMaxForwardsParserData() ;
	}

	CSIPMaxForwardsParser::CSIPMaxForwardsParser( const CSIPMaxForwardsParser &SIPMaxForwardsParser )
		: ASIPParser( SIPMaxForwardsParser )
	{
		ReleaseCSIPMaxForwardsParserData() ;

		CopyCSIPMaxForwardsParserData( SIPMaxForwardsParser ) ;
	}

	CSIPMaxForwardsParser::~CSIPMaxForwardsParser()
	{
		ReleaseCSIPMaxForwardsParserData() ;
	}

	CSIPMaxForwardsParser& CSIPMaxForwardsParser::operator=( const CSIPMaxForwardsParser &SIPMaxForwardsParser )
	{
		ReleaseCSIPMaxForwardsParserData() ;

		ASIPParser::operator=( SIPMaxForwardsParser ) ;

		CopyCSIPMaxForwardsParserData( SIPMaxForwardsParser ) ;

		return *this ;
	}

	void CSIPMaxForwardsParser::ReleaseCSIPMaxForwardsParserData()
	{
		m_strMaxForwards.erase() ;
	}

	void CSIPMaxForwardsParser::CopyCSIPMaxForwardsParserData( const CSIPMaxForwardsParser &SIPMaxForwardsParser )
	{
		m_strMaxForwards = SIPMaxForwardsParser.m_strMaxForwards ;
	}

	CSIPMaxForwardsParser* CSIPMaxForwardsParser::GetAvailable()
	{
		CSIPMaxForwardsParser *pSIPMaxForwardsParser = CPoolObject<CSIPMaxForwardsParser>::GetAvailable() ;
		return pSIPMaxForwardsParser ;
	}

	void CSIPMaxForwardsParser::Release()
	{
		ReleaseParameters() ;

		CPoolObject<CSIPMaxForwardsParser>::Release( this ) ;
	}

	void CSIPMaxForwardsParser::ReleaseParameters()
	{
		ReleaseCSIPMaxForwardsParserData() ;
		
		ASIPParser::ReleaseParameters() ;
	}

	ASIPParser* CSIPMaxForwardsParser::Copy()
	{
		CSIPMaxForwardsParser *pSIPMaxForwardsParser = CSIPMaxForwardsParser::GetAvailable() ;
		if( pSIPMaxForwardsParser == NULL )
			return NULL ;

		*pSIPMaxForwardsParser = *this ;

		return pSIPMaxForwardsParser ;
	}

	// Grammer
	//Max-Forwards = "Max-Forwards" HCOLON 1*DIGIT

	// Please see RFC3261, Pages 173
	// Please see RFC3261, Pages from 219 to 232 for ABNF forms
	// Please see file ..\Document\SIPMaxForwards Parsing Logic.txt for parsing algorithm

	// Page 173:
		//The Max-Forwards header field must be used with any SIP method to
		//limit the number of proxies or gateways that can forward the request
		//to the next downstream server. This can also be useful when the
		//client is attempting to trace a request chain that appears to be
		//failing or looping in mid-chain.
		//The Max-Forwards value is an integer in the range 0-255 indicating
		//the remaining number of times this request message is allowed to be
		//forwarded. This count is decremented by each server that forwards
		//the request. The recommended initial value is 70.
		//This header field should be inserted by elements that can not
		//otherwise guarantee loop detection. For example, a B2BUA should
		//insert a Max-Forwards header field.

	FW_RETURN_TYPE CSIPMaxForwardsParser::Parse( const std::string &strStringToParse )
	{
		if( strStringToParse.empty() )
			return SIP_PARSE_ERR_EMPTY_STRING_TO_PARSE ;

		m_strMaxForwards = strStringToParse ;
		
		return SIP_ERR_SUCCESS ;
	}

	std::string CSIPMaxForwardsParser::ToString() const
	{
		std::string strSIPMaxForwardsString = "" ;

		if( !m_strMaxForwards.empty() )
			strSIPMaxForwardsString = m_strMaxForwards ;

		return strSIPMaxForwardsString ;
	}

	std::string CSIPMaxForwardsParser::GetHeaderName() const
	{
		return GetRuntimeHeaderName( SIP_HEADER_MAX_FORWARDS ) ;
	}
	
} // End namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Hatim Haidry

VC++, Technical Architect

India

haidryhatim@gmail.com

Comments and Discussions