📄 sipxtapi.cpp
字号:
} } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallPlayBufferStop(const SIPX_CALL hCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallPlayBufferStop hCall=%d", hCall); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA *pInst ; UtlString callId ; if (sipxCallGetCommonData(hCall, &pInst, &callId, NULL, NULL)) { pInst->pCallManager->audioStop(callId.data()) ; sr = SIPX_RESULT_SUCCESS ; } else { sr = SIPX_RESULT_INVALID_ARGS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallSetMediaProperty(const SIPX_CALL hCall, const char* szPropertyName, const char* szPropertyValue){ SIPX_RESULT sipXresult = SIPX_RESULT_FAILURE ; OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallSetMediaProperty hCall=%d szPropertyName=\"%s\" szPropertyValue=\"%s\"", hCall, szPropertyName, szPropertyValue); if (hCall) { SIPX_INSTANCE_DATA *pInst; UtlString callId; UtlString remoteAddress; UtlString lineId; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, &lineId)) { SIPX_CALL_DATA *pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); if (pCallData) { if(pInst->pCallManager->setConnectionMediaProperty(callId, remoteAddress, szPropertyName, szPropertyValue) == OS_SUCCESS) { sipXresult = SIPX_RESULT_SUCCESS; } sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE); } } } return(sipXresult);}SIPXTAPI_API SIPX_RESULT sipxCallSubscribe(const SIPX_CALL hCall, const char* szEventType, const char* szAcceptType, SIPX_SUB* phSub, bool bRemoteContactIsGruu){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallSubscribe hCall=%d szEventType=\"%s\" szAcceptType=\"%s\"", hCall, szEventType ? szEventType : "<null>", szAcceptType ? szAcceptType : "<null>"); SIPX_RESULT sipXresult = SIPX_RESULT_FAILURE; SIPX_INSTANCE_DATA *pInst; UtlString callId; UtlString remoteAddress; UtlString lineId; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, &lineId)) { SIPX_SUBSCRIPTION_DATA* subscriptionData = new SIPX_SUBSCRIPTION_DATA; subscriptionData->pDialogHandle = new UtlString; subscriptionData->pInst = pInst; *phSub = gpSubHandleMap->allocHandle(subscriptionData); int subscriptionPeriod = 3600; // Need to get the resourceId, To, From and Contact from // the associated call SipSession session; if(pInst->pCallManager->getSession(callId, remoteAddress, session)) { Url toUrl; session.getToUrl(toUrl); toUrl.removeFieldParameters(); UtlString toField; toUrl.toString(toField); UtlString contactField; Url contactUrl; session.getLocalContact(contactUrl); contactUrl.toString(contactField); // If remoteContactIsGruu is set we assume the // remote contact is a globally routable unique URI (GRUU). // Normally one cannot assume the Contact header is a // publicly addressable address and we assume that the // To or From from the remote side has a better chance of // being globally routable as it typically is an address // of record (AOR). UtlString resourceId; Url requestUri; if(bRemoteContactIsGruu) { requestUri = contactUrl; } else { requestUri = toUrl; } requestUri.removeFieldParameters(); requestUri.toString(resourceId); // May need to get the from field from the line manager // For now, use the From in the session UtlString fromField; Url fromUrl; session.getFromUrl(fromUrl); fromUrl.removeFieldParameters(); fromUrl.toString(fromField); UtlBoolean sessionDataGood = TRUE; if(resourceId.length() <= 1 || fromField.length() <= 4 || toField.length() <= 4 || contactField.length() <= 4) { sessionDataGood = FALSE; OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxCallSubscribe bad session data: hCall=%d szEventType=\"%s\" szAcceptType=\"%s\" resourceId=\"%s\" From=\"%s\" To=\"%s\" Contact=\"%s\"", hCall, szEventType ? szEventType : "<null>", szAcceptType ? szAcceptType : "<null>", resourceId.data(), fromField.data(), toField.data(), contactField.data()); } // Session data is big enough else { OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallSubscribe subscribing: hCall=%d szEventType=\"%s\" szAcceptType=\"%s\" resourceId=\"%s\" From=\"%s\" To=\"%s\" Contact=\"%s\"", hCall, szEventType ? szEventType : "<null>", szAcceptType ? szAcceptType : "<null>", resourceId.data(), fromField.data(), toField.data(), contactField.data()); } // Subscribe and keep the subscription refreshed if(sessionDataGood && pInst->pSubscribeClient->addSubscription(resourceId, szEventType, fromField, toField, contactField, subscriptionPeriod, (void*)*phSub, sipxSubscribeClientSubCallback, sipxSubscribeClientNotifyCallback, *(subscriptionData->pDialogHandle))) { sipXresult = SIPX_RESULT_SUCCESS; } } // Could not find session for given call handle else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxCallSubscribe: could not get session for call handle: %d callId: %s remote address: %s", hCall, callId.data(), remoteAddress.data()); sipXresult = SIPX_RESULT_INVALID_ARGS; } } else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxCallSubscribe: could not find call data for call handle: %d", hCall); sipXresult = SIPX_RESULT_INVALID_ARGS; } return sipXresult;}SIPXTAPI_API SIPX_RESULT sipxCallUnsubscribe(const SIPX_SUB hSub){ SIPX_RESULT sipXresult = SIPX_RESULT_FAILURE; OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallSubscribe hSub=%x", hSub); SIPX_SUBSCRIPTION_DATA* subscriptionData = (SIPX_SUBSCRIPTION_DATA*) gpSubHandleMap->findHandle(hSub); if(subscriptionData && subscriptionData->pInst) { if(subscriptionData->pInst->pSubscribeClient->endSubscription(*(subscriptionData->pDialogHandle))) { sipXresult = SIPX_RESULT_SUCCESS; } else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxCallUnsubscribe endSubscription failed for subscription handle: %d dialog handle: \"%s\"", hSub, subscriptionData->pDialogHandle->data()); sipXresult = SIPX_RESULT_INVALID_ARGS; } // Remove and free up the subscription handle and data gpSubHandleMap->removeHandle(hSub); if(subscriptionData->pDialogHandle) { delete subscriptionData->pDialogHandle; subscriptionData->pDialogHandle = NULL; } delete subscriptionData; subscriptionData = NULL; } // Invalid subscription handle else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "sipxCallUnsubscribe: cannot find subscription data for handle: %d", hSub); sipXresult = SIPX_RESULT_INVALID_ARGS; } return(sipXresult);}SIPXTAPI_API SIPX_RESULT sipxCallBlindTransfer(const SIPX_CALL hCall, const char* pszAddress){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallBlindTransfer hCall=%d Address=%s", hCall, pszAddress); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA *pInst ; UtlString callId ; if (sipxCallGetCommonData(hCall, &pInst, &callId, NULL, NULL)) { if (pszAddress) { UtlString ghostCallId ; // first, get rid of any existing ghost connection SIPX_CALL_DATA* pData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); assert(pData != NULL); if (pData->ghostCallId) { if (pData->ghostCallId->length() > 0) { pInst->pCallManager->drop(pData->ghostCallId->data()) ; } delete pData->ghostCallId; pData->ghostCallId = NULL; } sipxCallReleaseLock(pData, SIPX_LOCK_WRITE) ; // call the transfer pInst->pCallManager->transfer_blind(callId.data(), pszAddress, &ghostCallId) ; pData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); // set the new ghost call Id pData->ghostCallId = new UtlString(ghostCallId); sipxCallReleaseLock(pData, SIPX_LOCK_WRITE) ; sr = SIPX_RESULT_SUCCESS ; } else { sr = SIPX_RESULT_INVALID_ARGS ; } } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallTransfer(const SIPX_CALL hSourceCall, const SIPX_CALL hTargetCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallTransfer hSourceCall=%d hTargetCall=%d\n", hSourceCall, hTargetCall); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA *pInst ; UtlString sourceCallId; UtlString sourceAddress; UtlString targetCallId ; UtlString targetAddress; if ( sipxCallGetCommonData(hSourceCall, &pInst, &sourceCallId, &sourceAddress, NULL) && sipxCallGetCommonData(hTargetCall, NULL, &targetCallId, &targetAddress, NULL)) { // call the transfer if (pInst->pCallManager->transfer(sourceCallId, sourceAddress, targetCallId, targetAddress) == PT_SUCCESS) { sr = SIPX_RESULT_SUCCESS ; } } else { sr = SIPX_RESULT_INVALID_ARGS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallSendInfo(SIPX_INFO* phInfo, const SIPX_CALL hCall, const char* szContentType, const char* szContent, const size_t nContentLength){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallSendInfo phInfo=%p hCall=%d contentType=%s content=%p contentLength=%d", phInfo, hCall, szContentType, szContent, nContentLength); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA *pInst ; UtlString callId ; UtlString lineId; if (sipxCallGetCommonData(hCall, &pInst, &callId, NULL, &lineId)) { if (callId.length() != 0) { SIPX_LINE hLine = sipxLineLookupHandle(lineId.data()) ; SIPX_INFO_DATA* pInfoData = new SIPX_INFO_DATA; memset((void*) pInfoData, 0, sizeof(SIPX_INFO_DATA)); SIPX_CALL_DATA* pCall = sipxCallLookup(hCall, SIPX_LOCK_READ); pInfoData->pInst = pInst; // Create Mutex pInfoData->pMutex = new OsRWMutex(OsRWMutex::Q_FIFO); pInfoData->infoData.nSize = sizeof(SIPX_INFO_INFO); pInfoData->infoData.hCall = hCall; pInfoData->infoData.hLine = hLine; pInfoData->infoData.szFromURL = strdup(lineId.data()); pInfoData->infoData.nContentLength = nContentLength; pInfoData->infoData.szContentType = strdup(szContentType); pInfoData->infoData.pContent = strdup(szContent); *phInfo = gpInfoHandleMap->allocHandle(pInfoData) ; assert(*phInfo != 0) ; SipSession* pSession = new SipSession(callId, pCall->remoteAddress->data(), pInfoData->infoData.szFromURL); pInst->pSipUserAgent->addMessageObserver(*(pInst->pMessageObserver->getMessageQueue()), SIP_INFO_METHOD, 0, 1, 1, 0, 0, pSession, (void*)*phInfo); pInst->pCallManager->sendInfo(callId.data(), szContentType, nContentLength, szContent) ; // call manager makes copies // of the strings, so no // duplication is needed here
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -