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

280 HP-UX C SIP Stack Programmers Guide
Implementing REFER-related Application Callbacks
RvSipSubsStateChangedEv() Callback Implementation
The following code is an implementation of the Subscription-state changed
callback. The sample demonstrates how to respond to an incoming REFER
request with 202, and then connect the new call with the Refer-to party. In this
sample, if the method parameter in the Refer-To URI indicates a method
different than INVITE, the REFER is rejected with a 400 response.
Sample Code
/*=========================================================================================*/
void RVCALLCONV AppSubsStateChangedEvHandler(
IN RvSipSubsHandle hSubs,
IN RvSipAppSubsHandle hAppSubs,
IN RvSipSubsState eState,
IN RvSipSubsStateChangeReason eReason)
{
RvStatus rv;
RvSipCommonStackObjectType eObjType = RVSIP_COMMON_STACK_OBJECT_TYPE_UNDEFINED;
RvSipCallLegHandle hCallLeg;
RvSipReferToHeaderHandle hReferTo;
RvSipAddressHandle hReferToAddr;
RvSipMethodType eMethod;
if(RVSIP_SUBS_STATE_SUBS_RCVD != eState)
{
/* Handle only the subs rcvd state*/
return;
}
if(RVSIP_SUBS_REASON_REFER_RCVD == eReason ||
RVSIP_SUBS_REASON_REFER_RCVD_WITH_REPLACES == eReason)
{
/* check that the refer request is for a new call-leg object */
RvSipSubsGetReferToHeader(hSubs, &hReferTo);
hReferToAddr = RvSipReferToHeaderGetAddrSpec(hReferTo);
eMethod = RvSipAddrUrlGetMethod(hReferToAddr);
if(eMethod != RVSIP_METHOD_UNDEFINED &&
eMethod != RVSIP_METHOD_INVITE)
{
printf("Refer has a method parameter different than INVITE. Reject it\n");
RvSipSubsRespondReject(hSubs, 400, "Unsupported Method In Refer-To header");
return;