Examples Showing the use of the SIP Codec API

The following sections describe the use of the SIP Codec API.

Decoding a Contact Header using the SIP stack

The following code snippet shows how an application decodes a Contact header that uses the SIP stack:

       
        
       
       RPointerArray<CSIPContactHeader> headers;
_LIT8 (KThreeParams, "sip:user@localhost;expires=0;q=1.0;p=value");
headers = CSIPContactHeader::DecodeL(KThreeParams);
TInt count = headers.Count(); //count == 1
iSIPContactHeader = headers[0];
headers.Reset();
iSIPContactHeader->ExpiresParameter();//return zero
iSIPContactHeader->QParameter();//return 1.0
delete iSIPContactHeader; iSIPContactHeader = 0;
      

Decoding several Contact Headers using the SIP stack

The following code snippet shows how an application decodes the Contact headers that use the SIP stack:

       
        
       
       RPointerArray<CSIPContactHeader> headers;
_LIT8 (KHeaders1, "<sip:u1@host>, u2 <sip:u2@host> , sip:host  ");
headers = CSIPContactHeader::DecodeL(KHeaders1);
headers.Count();//return 3
headers.ResetAndDestroy();
      

Creating a CSIPContactHeader using the SIP stack

The following code snippet shows how an application creates CSIPContactHeader that uses the SIP stack :

       
        
       
       TUriParser8 parser;
_LIT8 (KValue, "sip:user@host1");
User::LeaveIfError(parser.Parse(KValue));
CUri8* uri8 = CUri8::NewLC(parser);
CSIPAddress* sipAddress = CSIPAddress::NewL(uri8);
CleanupStack::Pop(); // uri8, ownership given to sipAddress
CleanupStack::PushL(sipAddress);
CSIPContactHeader* contactHeader = CSIPContactHeader::NewL(sipAddress);
CleanupStack::Pop(); // sipAddress, ownership given to contactHeader
      

Note: Open the string pool before you use it. All the predefined SIP constants are in the string table, which are accessed by the string pool. At the end of handling, the SIP Codec string pool must be closed.

       
        
       
       #include "sipstrings.h"
SIPStrings::OpenL();
RStringPool pool = SIPStrings::Pool();