HP-UX C SIP Stack Programmer's Guide (Novembery 2007)

Working with SIP Messages 153
Working with SIP Messages
WORKING WITH SIP
M
ESSAGES
The SIP Stack Message API provides a set of functions for accessing, encoding,
parsing and adding new headers to messages.
READING AND
M
ODIFYING SIP
M
ESSAGES
The Message API provides a set of functions for reading and modifying various
message parts such as the start-line field, headers and body.
You can access the To, From, CSeq, Call-ID, ContentLength, and ContentType
headers directly since they are held separately in the message and can appear
only once in a SIP message. All other headers are kept in a linked list. Some of
these headers can appear more than once and you can get these headers from
messages based on the header type, name or position in the list.
Sample Code
The following code demonstrates ways of manipulating a message:
/*===================================================================================*/
RvStatus ProcessMessage(RvSipMsgHandle hMsg)
{
RvSipMsgType msgType;
RvSipPartyHeaderHandle fromHeader;
RvSipViaHeaderHandle viaHeader;
RvSipHeaderListElemHandle listElem;
/*Checks if this is a request or response message.*/
msgType = RvSipMsgGetMsgType(hMsg);
if (msgType == RVSIP_MSG_REQUEST)
{
/*This is a request. Gets the method (request) type.*/
RvSipMethodType methodType;
methodType = RvSipMsgGetRequestMethod(hMsg);
printf("the received message is a request, method type is %d",methodType);
}
else if (msgType == RVSIP_MSG_RESPONSE)
{
/*This is a response. Gets the response code.*/
RvUint32 respCode;
respCode = RvSipMsgGetStatusCode(hMsg);
printf("the received message is a response, response code is %d", respCode);
}
else
{
/* msgType == RVSIP_MSG_UNDEFINED */
printf("The received message is of undefined type.Fail");