bool SipXMessageObserver::handleStunOutcome(OsEventMsg* pMsg) { SIPX_CONTACT_ADDRESS sipxContact; // contact structure for notifying // sipxtapi event listeners ContactAddress* pContact = NULL; pMsg->getEventData((intptr_t&)pContact) ; SIPX_CONFIG_INFO eventInfo ; memset(&eventInfo, 0, sizeof(SIPX_CONFIG_INFO)) ; eventInfo.nSize = sizeof(SIPX_CONFIG_INFO) ; if (pContact) { // first, find the user-agent, and add the contact to // the user-agent's db SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) mhInst; pInst->pSipUserAgent->addContactAddress(*pContact); // ok, now generate an event for the sipXtapi application layer strcpy(sipxContact.cInterface, pContact->cInterface); strcpy(sipxContact.cIpAddress, pContact->cIpAddress); sipxContact.eContactType = CONTACT_NAT_MAPPED; sipxContact.id = pContact->id; sipxContact.iPort = pContact->iPort; eventInfo.pData = &sipxContact; eventInfo.event = CONFIG_STUN_SUCCESS ; delete pContact; } else { eventInfo.event = CONFIG_STUN_FAILURE ; } sipxFireEvent(this, EVENT_CATEGORY_CONFIG, &eventInfo) ; return true ; }
void sipxSubscribeClientSubCallback(SipSubscribeClient::SubscriptionState newState, const char* earlyDialogHandle, const char* dialogHandle, void* applicationData, int responseCode, const char* responseText, long expiration, const SipMessage* subscribeResponse) { SIPX_SUB subscriptionHandle = (SIPX_SUB)applicationData; SIPX_SUBSCRIPTION_DATA* subscriptionData = (SIPX_SUBSCRIPTION_DATA*) gpSubHandleMap->findHandle(subscriptionHandle); if(subscriptionData && subscriptionData->pInst) { SIPX_SUBSTATUS_INFO pInfo; pInfo.nSize = sizeof(SIPX_SUBSTATUS_INFO); UtlString userAgent; if(subscribeResponse) { subscribeResponse->getUserAgentField(&userAgent); } pInfo.szSubServerUserAgent = userAgent; pInfo.hSub = subscriptionHandle; // TODO: Should probably set some cause codes based upon // the response code from the sip message pInfo.cause = SUBSCRIPTION_CAUSE_NORMAL; UtlString errorState; switch(newState) { case SipSubscribeClient::SUBSCRIPTION_INITIATED: // Early dialog pInfo.state = SIPX_SUBSCRIPTION_PENDING; break; case SipSubscribeClient::SUBSCRIPTION_SETUP: // Established dialog pInfo.state = SIPX_SUBSCRIPTION_ACTIVE; break; case SipSubscribeClient::SUBSCRIPTION_TERMINATED: pInfo.state = SIPX_SUBSCRIPTION_EXPIRED; break; default: { pInfo.state = SIPX_SUBSCRIPTION_FAILED; errorState = "unknown: "; char numBuf[20]; sprintf(numBuf, "%d", newState); errorState.append(numBuf); } break; } // If the dialog changed from and early dialog to an // established dialog, update the dialog handle in the // subcription data structure if(earlyDialogHandle && dialogHandle && SipDialog::isEarlyDialog(*subscriptionData->pDialogHandle)) { *(subscriptionData->pDialogHandle) = dialogHandle; } // Fire the event if it is a supported state change if(errorState.isNull()) { sipxFireEvent(subscriptionData->pInst->pCallManager, EVENT_CATEGORY_SUB_STATUS, &pInfo); } else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxSubscribeClientSubCallback: invalid SubscriptionState: %s", errorState.data()); } } // Cannot find subsription data for this handle else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxSubscribeClientSubCallback: cannot find subscription data for handle: %p", applicationData); } }
bool sipxSubscribeClientNotifyCallback(const char* earlyDialogHandle, const char* dialogHandle, void* applicationData, const SipMessage* notifyRequest) { SIPX_SUB subscriptionHandle = (SIPX_SUB)applicationData; SIPX_SUBSCRIPTION_DATA* subscriptionData = (SIPX_SUBSCRIPTION_DATA*) gpSubHandleMap->findHandle(subscriptionHandle); if(subscriptionData && subscriptionData->pInst) { SIPX_NOTIFY_INFO pInfo; UtlString userAgent; UtlString contentType; const HttpBody* contentBody = NULL; ssize_t bodyLength = 0; const char* bodyBytes = NULL; // If the dialog changed from and early dialog to an // established dialog, update the dialog handle in the // subcription data structure if(earlyDialogHandle && dialogHandle && SipDialog::isEarlyDialog(*subscriptionData->pDialogHandle)) { *(subscriptionData->pDialogHandle) = dialogHandle; } if(notifyRequest) { notifyRequest->getUserAgentField(&userAgent); notifyRequest->getContentType(&contentType); contentBody = notifyRequest->getBody(); if(contentBody) { contentBody->getBytes(&bodyBytes, &bodyLength); } } pInfo.nSize = sizeof(SIPX_NOTIFY_INFO); pInfo.hSub = (SIPX_SUB) applicationData; pInfo.szNotiferUserAgent = userAgent; pInfo.nContentLength = bodyLength; pInfo.pContent = bodyBytes; pInfo.szContentType = contentType; sipxFireEvent(subscriptionData->pInst->pCallManager, EVENT_CATEGORY_NOTIFY, &pInfo); } // No data for the subscription handle else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxSubscribeClientNotifyCallback: cannot find subscription data for handle: %p", applicationData); } return true; }
bool SipXMessageObserver::handleStunOutcome(OsEventMsg* pMsg) { SIPX_CONTACT_ADDRESS sipxContact; // contact structure for notifying // sipxtapi event listeners SIPX_CONTACT_ADDRESS* pContact = NULL; pMsg->getEventData((intptr_t&)pContact) ; SIPX_CONFIG_INFO eventInfo ; memset(&eventInfo, 0, sizeof(SIPX_CONFIG_INFO)) ; eventInfo.nSize = sizeof(SIPX_CONFIG_INFO) ; if (pContact) { // first, find the user-agent, and add the contact to // the user-agent's db SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) mhInst; assert(pInst != NULL) ; pInst->pSipUserAgent->addContactAddress(*pContact); // If we have an external transport, also create a record for the // external transport SIPX_CONTACT_ADDRESS externalTransportContact ; SIPX_CONTACT_ADDRESS* pNewContact = NULL ; // TODO: At the point where we support multiple external // transports, this code needs to iterate through ALL of // the external transports. if (pInst->pSipUserAgent->getContactDb().getRecordForAdapter(externalTransportContact, pContact->cInterface, CONTACT_LOCAL, TRANSPORT_CUSTOM)) { pNewContact = new SIPX_CONTACT_ADDRESS(externalTransportContact) ; pNewContact->eContactType = CONTACT_NAT_MAPPED ; pNewContact->id = 0 ; strcpy(pNewContact->cIpAddress, pContact->cIpAddress); pNewContact->iPort = pContact->iPort ; pInst->pSipUserAgent->addContactAddress(*pNewContact) ; } // Fire off an event for the STUN contact (normal) sipxContact.id = pContact->id; sipxContact.eContactType = CONTACT_NAT_MAPPED; strcpy(sipxContact.cInterface, pContact->cInterface); strcpy(sipxContact.cIpAddress, pContact->cIpAddress); sipxContact.iPort = pContact->iPort; eventInfo.pData = &sipxContact; eventInfo.event = CONFIG_STUN_SUCCESS ; sipxFireEvent(this, EVENT_CATEGORY_CONFIG, &eventInfo) ; delete pContact; // Fire off an event for the STUN contact (external transport) if (pNewContact) { sipxContact.id = pNewContact->id; sipxContact.eContactType = CONTACT_NAT_MAPPED; strcpy(sipxContact.cInterface, pNewContact->cInterface); strcpy(sipxContact.cIpAddress, pNewContact->cIpAddress); sipxContact.iPort = pNewContact->iPort; eventInfo.pData = &sipxContact; eventInfo.event = CONFIG_STUN_SUCCESS ; sipxFireEvent(this, EVENT_CATEGORY_CONFIG, &eventInfo) ; delete pNewContact; } } else { eventInfo.event = CONFIG_STUN_FAILURE ; sipxFireEvent(this, EVENT_CATEGORY_CONFIG, &eventInfo) ; } return true ; }