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

156 HP-UX C SIP Stack Programmers Guide
Working with SIP Messages
/*===================================================================================*/
void EncodeMessage(RvSipMsgHandle hMessage, HRPOOL hPool)
{
RvUint32 length = 0;
HPAGE hPage;
RvStatus status;
RvChar *msgBuf;
status = RvSipMsgEncode(hMessage, hPool, &hPage, &length);
if (status != RV_OK)
{
printf("RvSipMsgEncode failed. status is %d\n",status);
return;
}
/*Allocate a consecutive buffer.*/
msgBuf = malloc(length+1);
/*Copies the encoded message to a consecutive buffer and sets '\ at the end of the
string.*/
status = RPOOL_CopyToExternal(hPool, hPage, 0, msgBuf, length);
msgBuf[length] = '\0';
if (status != RV_OK)
{
printf("RPOOL_CopyToExternal failed. status is %d\n",status);
}
else
{
/*print the message*/
printf("%s",msgBuf);
}
/*Free resources.*/
free(msgBuf);
RPOOL_FreePage(hPool, hPage);
}
/*===================================================================================*/