Click here to Skip to main content
15,886,422 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\CSIPCSeqParser.h"

namespace SIPParserFW
{
	CSIPCSeqParser::CSIPCSeqParser()
	{
		ReleaseCSIPCSeqParserData() ;
	}

	CSIPCSeqParser::CSIPCSeqParser( const CSIPCSeqParser &SIPCSeqParser )
		: ASIPParser( SIPCSeqParser )
	{
		ReleaseCSIPCSeqParserData() ;

		CopyCSIPCSeqParserData( SIPCSeqParser ) ;
	}

	CSIPCSeqParser::~CSIPCSeqParser()
	{
		ReleaseCSIPCSeqParserData() ;
	}

	CSIPCSeqParser& CSIPCSeqParser::operator=( const CSIPCSeqParser &SIPCSeqParser )
	{
		ReleaseCSIPCSeqParserData() ;

		ASIPParser::operator=( SIPCSeqParser ) ;

		CopyCSIPCSeqParserData( SIPCSeqParser ) ;

		return *this ;
	}

	void CSIPCSeqParser::ReleaseCSIPCSeqParserData()
	{
		m_strNumber.erase() ;

		m_strMethod.erase() ;
	}

	void CSIPCSeqParser::CopyCSIPCSeqParserData( const CSIPCSeqParser &SIPCSeqParser )
	{
		m_strNumber = SIPCSeqParser.m_strNumber ;
		m_strMethod = SIPCSeqParser.m_strMethod ;
	}

	CSIPCSeqParser* CSIPCSeqParser::GetAvailable()
	{
		CSIPCSeqParser *pSIPCSeqParser = CPoolObject<CSIPCSeqParser>::GetAvailable() ;
		return pSIPCSeqParser ;
	}

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

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

	void CSIPCSeqParser::ReleaseParameters()
	{
		ReleaseCSIPCSeqParserData() ;
		
		ASIPParser::ReleaseParameters() ;
	}

	ASIPParser* CSIPCSeqParser::Copy()
	{
		CSIPCSeqParser *pSIPCSeqParser = CSIPCSeqParser::GetAvailable() ;
		if( pSIPCSeqParser == NULL )
			return NULL ;

		*pSIPCSeqParser = *this ;

		return pSIPCSeqParser ;
	}

	// Grammer
	//CSeq = "CSeq" HCOLON 1*DIGIT LWS Method
	//Method = INVITEm / ACKm / OPTIONSm / BYEm / CANCELm / REGISTERm / extension-method
	//extension-method = token

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

	// Page 170:
		//A CSeq header field in a request contains a single decimal sequence
		//number and the request method. The sequence number MUST be
		//expressible as a 32-bit unsigned integer. The method part of CSeq is
		//case-sensitive. The CSeq header field serves to order transactions
		//within a dialog, to provide a means to uniquely identify
		//transactions, and to differentiate between new requests and request
		//retransmissions. Two CSeq header fields are considered equal if the
		//sequence number and the request method are identical.

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

		std::string::size_type iSIPMethodPosition = strStringToParse.find( SIP_CONST_SPACE ) ;

		if(	iSIPMethodPosition == std::string::npos )
			return SIP_PARSE_ERR_INVALID_SIP_CSEQ ;

		m_strNumber = strStringToParse.substr( 0, iSIPMethodPosition ) ;
		m_strMethod = strStringToParse.substr( iSIPMethodPosition + strlen( SIP_CONST_SPACE ) ) ;
		
		return SIP_ERR_SUCCESS ;
	}

	std::string CSIPCSeqParser::ToString() const
	{
		std::string strSIPCSeqString = "" ;

		if( !m_strNumber.empty() )
			strSIPCSeqString = m_strNumber ;

		if( !m_strMethod.empty() )
			strSIPCSeqString = strSIPCSeqString + SIP_CONST_SPACE + m_strMethod ;

		return strSIPCSeqString ;
	}

	std::string CSIPCSeqParser::GetHeaderName() const
	{
		return GetRuntimeHeaderName( SIP_HEADER_CSEQ ) ;
	}
	
} // 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