Click here to Skip to main content
15,892,768 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 30.1K   1.7K   4  
SIP Stack Implementation on the basis of RFC SIP 3261 Specification
#include "SIPParserInclude\CSIPProxyAuthorizationParser.h"

namespace SIPParserFW
{
	CSIPProxyAuthorizationParser::CSIPProxyAuthorizationParser()
	{
		ReleaseCSIPProxyAuthorizationParserData() ;
	}

	CSIPProxyAuthorizationParser::CSIPProxyAuthorizationParser( const CSIPProxyAuthorizationParser &SIPProxyAuthorizationParser )
		: CSIPAuthorizationParser( SIPProxyAuthorizationParser )
	{
		ReleaseCSIPProxyAuthorizationParserData() ;

		CopyCSIPProxyAuthorizationParserData( SIPProxyAuthorizationParser ) ;
	}

	CSIPProxyAuthorizationParser::~CSIPProxyAuthorizationParser()
	{
		ReleaseCSIPProxyAuthorizationParserData() ;
	}

	CSIPProxyAuthorizationParser& CSIPProxyAuthorizationParser::operator=( const CSIPProxyAuthorizationParser &SIPProxyAuthorizationParser )
	{
		ReleaseCSIPProxyAuthorizationParserData() ;

		CSIPAuthorizationParser::operator=( SIPProxyAuthorizationParser ) ;

		CopyCSIPProxyAuthorizationParserData( SIPProxyAuthorizationParser ) ;

		return *this ;
	}

	CSIPProxyAuthorizationParser& CSIPProxyAuthorizationParser::operator=( const CSIPProxyAuthenticateParser &SIPProxyAuthenticateParser )
	{
		ReleaseCSIPProxyAuthorizationParserData() ;

		CSIPAuthorizationParser::operator=( SIPProxyAuthenticateParser ) ;

		CopyCSIPProxyAuthorizationParserData( SIPProxyAuthenticateParser ) ;

		return *this ;
	}

	void CSIPProxyAuthorizationParser::ReleaseCSIPProxyAuthorizationParserData()
	{
	}

	void CSIPProxyAuthorizationParser::CopyCSIPProxyAuthorizationParserData( const CSIPProxyAuthorizationParser &SIPProxyAuthorizationParser )
	{
	}

	void CSIPProxyAuthorizationParser::CopyCSIPProxyAuthorizationParserData( const CSIPProxyAuthenticateParser &SIPProxyAuthenticateParser )
	{
	}

	CSIPProxyAuthorizationParser* CSIPProxyAuthorizationParser::GetAvailable()
	{
		CSIPProxyAuthorizationParser *pSIPProxyAuthorizationParser = CPoolObject<CSIPProxyAuthorizationParser>::GetAvailable() ;
		return pSIPProxyAuthorizationParser ;
	}

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

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

	void CSIPProxyAuthorizationParser::ReleaseParameters()
	{
		ReleaseCSIPProxyAuthorizationParserData() ;
		
		CSIPAuthorizationParser::ReleaseParameters() ;
	}

	ASIPParser* CSIPProxyAuthorizationParser::Copy()
	{
		CSIPProxyAuthorizationParser *pSIPProxyAuthorizationParser = CSIPProxyAuthorizationParser::GetAvailable() ;
		if( pSIPProxyAuthorizationParser == NULL )
			return NULL ;

		*pSIPProxyAuthorizationParser = *this ;

		return pSIPProxyAuthorizationParser ;
	}

	/* Grammer
	Authorization = "Authorization" HCOLON credentials
	credentials = ("Digest" LWS digest-response) / other-response
	digest-response = dig-resp *(COMMA dig-resp)
	dig-resp = username / realm / nonce / digest-uri / dresponse / algorithm / cnonce / opaque /  message-qop / nonce-count / auth-param 
	username = "username" EQUAL username-value
	username-value = quoted-string
	realm = "realm" EQUAL realm-value
	realm-value = quoted-string
	nonce = "nonce" EQUAL nonce-value
	nonce-value = quoted-string
	digest-uri = "uri" EQUAL LDQUOT digest-uri-value RDQUOT
	digest-uri-value = rquest-uri ; Equal to request-uri as specified by HTTP/1.1
	dresponse = "response" EQUAL request-digest
	request-digest = LDQUOT 32LHEX RDQUOT
	algorithm = "algorithm" EQUAL ( "MD5" / "MD5-sess" / token )
	cnonce = "cnonce" EQUAL cnonce-value
	cnonce-value = nonce-value
	opaque = "opaque" EQUAL quoted-string
	message-qop = "qop" EQUAL qop-value
	qop-value = "auth" / "auth-int" / token
	nonce-count = "nc" EQUAL nc-value
	nc-value = 8LHEX
	auth-param = auth-param-name EQUAL ( token / quoted-string )
	auth-param-name = token
	other-response = auth-scheme LWS auth-param *(COMMA auth-param)
	auth-scheme = token
	*/

	//Proxy-Authorization = "Proxy-Authorization" HCOLON credentials

	// Please see RFC3261, Pages 165
	// Please see RFC3261, Pages 175
	// Please see RFC3261, Pages 196
	// Please see RFC3261, Pages 197
	// Please see RFC3261, Pages 199
	// Please see RFC3261, Pages from 219 to 232 for ABNF forms
	// Please see file ..\Document\SIPProxyAuthorization Parsing Logic.txt for parsing algorithm
	
	// Page 165:
		//This header field, along with Proxy-Authorization, breaks the general
		//rules about multiple header field values. Although not a commaseparated
		//list, this header field name may be present multiple times,
		//and MUST NOT be combined into a single header line using the usual
		//rules described in Section 7.3.

	// Page 175:
		//The Proxy-Authorization header field allows the client to identify
		//itself (or its user) to a proxy that requires authentication. A
		//Proxy-Authorization field value consists of credentials containing
		//the authentication information of the user agent for the proxy and/or
		//realm of the resource being requested.
		//See Section 22.3 for a definition of the usage of this header field.
		//This header field, along with Authorization, breaks the general rules
		//about multiple header field names. Although not a comma-separated
		//list, this header field name may be present multiple times, and MUST
		//NOT be combined into a single

	// Page 196:
		//When a UAC resubmits a request with its credentials after receiving a
		//401 (Unauthorized) or 407 (Proxy Authentication Required) response,
		//it MUST increment the CSeq header field value as it would normally
		//when sending an updated request.

	// Page 197:
		//If a proxy were to resubmit a request adding a Proxy-Authorization
		//header field value, it would need to increment the CSeq in the new
		//request. However, this would cause the UAC that submitted the
		//original request to discard a response from the UAS, as the CSeq
		//value would be different.
		//When the originating UAC receives the 407 (Proxy Authentication
		//Required) it SHOULD, if it is able, re-originate the request with the
		//proper credentials. It should follow the same procedures for the
		//display of the "realm" parameter that are given above for responding
		//to 401.
		//If no credentials for a realm can be located, UACs MAY attempt to
		//retry the request with a username of "anonymous" and no password (a
		//password of "").
		//The UAC SHOULD also cache the credentials used in the re-originated
		//request.

	// Page 199:
		//This section describes the modifications and clarifications required
		//to apply the HTTP Digest authentication scheme to SIP. The SIP
		//scheme usage is almost completely identical to that for HTTP [17].
		//Since RFC 2543 is based on HTTP Digest as defined in RFC 2069 [39],
		//SIP servers supporting RFC 2617 MUST ensure they are backwards
		//compatible with RFC 2069. Procedures for this backwards
		//compatibility are specified in RFC 2617. Note, however, that SIP
		//servers MUST NOT accept or request Basic authentication.

	FW_RETURN_TYPE CSIPProxyAuthorizationParser::Parse( const std::string &strStringToParse )
	{
		return CSIPAuthorizationParser::Parse( strStringToParse ) ;
	}

	std::string CSIPProxyAuthorizationParser::ToString() const
	{
		return CSIPAuthorizationParser::ToString() ;
	}

	std::string CSIPProxyAuthorizationParser::GetHeaderName() const
	{
		return GetRuntimeHeaderName( SIP_HEADER_PROXY_AUTHORIZATION ) ;
	}

} // 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