📄 cppeercall.cpp
字号:
} return TRUE ;}// Handles the processing of a CallManager::CP_GET_SESSION // messageUtlBoolean CpPeerCall::handleGetSession(OsMsg* pEventMessage){ UtlString address; UtlString callId; ((CpMultiStringMessage*)pEventMessage)->getString1Data(callId); ((CpMultiStringMessage*)pEventMessage)->getString2Data(address); SipSession* sessionPtr; OsProtectedEvent* getFieldEvent = (OsProtectedEvent*) ((CpMultiStringMessage*)pEventMessage)->getInt1Data(); getFieldEvent->getIntData((int&)sessionPtr); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetSession session: %p for callId %s address %s", sessionPtr, callId.data(), address.data()); // Check whether the tag is set in addresses or not. If so, do not need to use callId // for comparison. UtlString address_without_tag; UtlBoolean hasTag = checkForTag(address, address_without_tag); // Get the remote connection(s)/address(es) Connection* connection = NULL; UtlString localAddress; UtlString remoteAddress; UtlString connCallId; OsReadLock lock(mConnectionMutex); UtlDListIterator iterator(mConnections); while ((connection = (Connection*) iterator())) { connection->getCallId(&connCallId); connection->getLocalAddress(&localAddress); connection->getRemoteAddress(&remoteAddress); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetSession looking at %s, %s, %s", connCallId.data(), localAddress.data(), remoteAddress.data()); // Compare the call-ID and the address, both with the tag parameter // (as the address is stored after call establishment) and without // (as the address is stored during call offering). if (callId.compareTo(connCallId) == 0 && (address.compareTo(localAddress) == 0 || address.compareTo(remoteAddress) == 0 || (hasTag && address_without_tag.compareTo(localAddress) == 0) || (hasTag && address_without_tag.compareTo(remoteAddress) == 0))) { SipSession session; connection->getSession(session); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetSession copying session: %p", sessionPtr); *sessionPtr = SipSession(session); // Signal the caller that we are done. break; } } // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == getFieldEvent->signal(1)) { // The other end must have timed out on the wait OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetSession deleting session: %p", sessionPtr); delete sessionPtr; sessionPtr = NULL; OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); eventMgr->release(getFieldEvent); } return TRUE ;}// Handles the processing of a CallManager::CP_GET_INVITE // messageUtlBoolean CpPeerCall::handleGetInvite(OsMsg* pEventMessage){ UtlString address; UtlString callId; ((CpMultiStringMessage*)pEventMessage)->getString1Data(callId); ((CpMultiStringMessage*)pEventMessage)->getString2Data(address); SipMessage* messagePtr; OsProtectedEvent* getFieldEvent = (OsProtectedEvent*) ((CpMultiStringMessage*)pEventMessage)->getInt1Data(); getFieldEvent->getIntData((int&)messagePtr); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetInvite message: %p for callId %s address %s", messagePtr, callId.data(), address.data()); // Check whether the tag is set in addresses or not. If so, do not need to use callId // for comparison. UtlString address_without_tag; UtlBoolean hasTag = checkForTag(address, address_without_tag); // Get the remote connection(s)/address(es) Connection* connection = NULL; UtlString localAddress; UtlString remoteAddress; UtlString connCallId; OsReadLock lock(mConnectionMutex); UtlDListIterator iterator(mConnections); while ((connection = (Connection*) iterator())) { connection->getCallId(&connCallId); connection->getLocalAddress(&localAddress); connection->getRemoteAddress(&remoteAddress); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetInvite looking at %s, %s, %s", connCallId.data(), localAddress.data(), remoteAddress.data()); // Compare the call-ID and the address, both with the tag parameter // (as the address is stored after call establishment) and without // (as the address is stored during call offering). if (callId.compareTo(connCallId) == 0 && (address.compareTo(localAddress) == 0 || address.compareTo(remoteAddress) == 0 || (hasTag && address_without_tag.compareTo(localAddress) == 0) || (hasTag && address_without_tag.compareTo(remoteAddress) == 0))) { // Have to cast the Connection* into a SipConnection*, because only // SipConnection has an INVITE attached. SipConnection* sipConnection = dynamic_cast <SipConnection*> (connection); // No action if the cast fails. if (sipConnection) { // Copy the saved INVITE from the SipConnection into *messagePtr. sipConnection->getInvite(messagePtr); if (OsSysLog::willLog(FAC_CP, PRI_DEBUG)) { UtlString text; int length; messagePtr->getBytes(&text, &length); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetInvite INVITE found '%s'", text.data()); } } else { // The connection should always be a SipConnection. OsSysLog::add(FAC_CP, PRI_WARNING, "CpPeerCall::handleGetInvite could not cast Connection %p to SipConnection", connection); } // Signal the caller that we are done. break; } } // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == getFieldEvent->signal(1)) { // The other end must have timed out on the wait OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleGetInvite deleting message: %p", messagePtr); delete messagePtr; messagePtr = NULL; OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); eventMgr->release(getFieldEvent); } return TRUE ;}// Handles CP_SEND_SIP_REQUESTUtlBoolean CpPeerCall::handleSendSipRequest(OsMsg* pEventMessage){ UtlString callId; UtlString address; OsProtectedEvent* sentEvent = NULL; SipMessage* request = NULL; OsMsgQ* requestQueue = NULL; void* requestListenerData = 0; ((CpMultiStringMessage*)pEventMessage)->getString1Data(callId); ((CpMultiStringMessage*)pEventMessage)->getString2Data(address); sentEvent = (OsProtectedEvent*) ((CpMultiStringMessage*)pEventMessage)->getInt1Data(); request = (SipMessage*) ((CpMultiStringMessage*)pEventMessage)->getInt2Data(); requestQueue = (OsMsgQ*) ((CpMultiStringMessage*)pEventMessage)->getInt3Data(); requestListenerData = (void*) ((CpMultiStringMessage*)pEventMessage)->getInt4Data(); if(sentEvent) { UtlBoolean requestSent = FALSE; if(request) { // Find the SipConnection which had the dialog on which to // send this request. OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleSendSipRequest request: %p for callId %s address %s", request, callId.data(), address.data()); // Check whether the tag is set in addresses or not. If so, do not need to use callId // for comparison. UtlString address_without_tag; UtlBoolean hasTag = checkForTag(address, address_without_tag); // Get the remote connection(s)/address(es) Connection* connection = NULL; UtlString localAddress; UtlString remoteAddress; UtlString connCallId; OsReadLock lock(mConnectionMutex); UtlDListIterator iterator(mConnections); while ((connection = (Connection*) iterator())) { connection->getCallId(&connCallId); connection->getLocalAddress(&localAddress); connection->getRemoteAddress(&remoteAddress); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleSendSipRequest looking for the Dialog for %s, %s, %s", connCallId.data(), localAddress.data(), remoteAddress.data()); if ((hasTag && (address.compareTo(localAddress) == 0)) || (hasTag && (address.compareTo(remoteAddress) == 0)) || (callId.compareTo(connCallId) == 0) && (address.compareTo(localAddress) == 0 || address.compareTo(remoteAddress) == 0)) { // Send the request in the context of the connection's SIP dialog requestSent = connection->sendInDialog(*request, requestQueue, requestListenerData); OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleSendSipRequest sent request: %p $s", request, requestSent ? "succeeded" : "failed"); // Signal the caller that we are done. break; } } } // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == sentEvent->signal(requestSent)) { // The other end must have timed out on the wait OsSysLog::add(FAC_CP, PRI_DEBUG, "CpPeerCall::handleSendSipRequest deleting request: %p", request); if(request) { delete request; request = NULL; } OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); eventMgr->release(sentEvent); } } return(TRUE);}// Handles the processing of a CallManager::CP_GET_CALLSTATE // messageUtlBoolean CpPeerCall::handleGetCallState(OsMsg* pEventMessage){ OsProtectedEvent* getStateEvent = (OsProtectedEvent*) ((CpMultiStringMessage*)pEventMessage)->getInt1Data(); // Signal the caller that we are done. // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == getStateEvent->signal(mCallState)) { // The other end must have timed out on the wait OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); eventMgr->release(getStateEvent); } return TRUE ;}// Handles the processing of a CallManager::CP_GET_CONNECTIONSTATE // messageUtlBoolean CpPeerCall::handleGetConnectionState(OsMsg* pEventMessage){ UtlString remoteAddress; ((CpMultiStringMessage*)pEventMessage)->getString2Data(remoteAddress); OsProtectedEvent* getStateEvent = (OsProtectedEvent*) ((CpMultiStringMessage*)pEventMessage)->getInt1Data(); int state = 0; if (!getConnectionState(remoteAddress, state)) { state = PtConnection::UNKNOWN; } // Signal the caller that we are done. // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == getStateEvent->signal(state)) { // The other end must have timed out on the wait OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); eventMgr->release(getStateEvent); } return TRUE ;}// Handles the processing of a CallManager::CP_GET_NEXT_CSEQ // messageUtlBoolean CpPeerCall::handleGetNextCseq(OsMsg* pEventMessage){ UtlString remoteAddress; ((CpMultiStringMessage*)pEventMessage)->getString2Data(remoteAddress); OsProtectedEvent* getStateEvent = (OsProtectedEvent*) ((CpMultiStringMessage*)pEventMessage)->getInt1Data(); Connection* connection = findHandlingConnection(remoteAddress); int nextCseq = -1; if(connection) { // Bad bad assumption on the connection type // This suppose to be a short term solution nextCseq = ((SipConnection*)connection)->getNextCseq(); } // Signal the caller that we are done. // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == getStateEvent->signal(nextCseq)) { // The other end must have timed out on the wait OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); eventMgr->release(getStateEvent); } return TRUE ;}// Enumerate possible contact addressesvoid CpPeerCall::getLocalContactAddresses( CONTACT_ADDRESS contacts[], size_t nMaxContacts, size_t& nActualContacts){ UtlString ipAddress ; int port ; // Order: Local, NAT, configure nActualContacts = 0 ; if ( (nActualContacts < nMaxContacts) && (sipUserAgent->getLocalAddress(&ipAddress, &port))) { contacts[nActualContacts].eContactType = LOCAL_CONTACT ; strncpy(contacts[nActualContacts].cIpAddress, ipAddress.data(), 32) ; contacts[nActualContacts].iPort = port ; nActualContacts++ ; } if ( (nActualContacts < nMaxContacts) && (sipUserAgent->getNatMappedAddress(&ipAddress, &port))) { contacts[nActualContacts].eContactType = NAT_MAPPED ; strncpy(contacts[nActualContacts].cIpAddress, ipAddress.data(), 32) ; contacts[nActualContacts].iPort = port ; nActualContacts++ ; } if ( (nActualContacts < nMaxContacts) && (sipUserAgent->getConfiguredPublicAddress(&ipAddress, &port))) { contacts[nActualContacts].eContactType = CONFIG ; strncpy(contacts[nActualContacts].cIpAddress, ipA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -