UtlBoolean SipLineList::remove(const Url& lineIdentityUrl) { SipLine* nextline = NULL; int iteratorHandle = m_LineList.getIteratorHandle(); while(NULL != (nextline = (SipLine*) m_LineList.next(iteratorHandle))) { // compare the line identities Url nextLineUrl = nextline->getIdentity(); if (lineIdentityUrl.isUserHostPortEqual(nextLineUrl)) { m_LineList.remove(iteratorHandle); break; } } m_LineList.releaseIteratorHandle(iteratorHandle); return( nextline != NULL ); }
UtlBoolean SipLineList::isDuplicate( const Url& lineIdentityUrl ) { SipLine* nextline = NULL; UtlBoolean isDuplicate = FALSE; int iteratorHandle = m_LineList.getIteratorHandle(); while(NULL != (nextline = (SipLine*) m_LineList.next(iteratorHandle))) { // compare the line identities Url nextLineUrl = nextline->getIdentity(); if (lineIdentityUrl.isUserHostPortEqual(nextLineUrl)) { isDuplicate = TRUE; break; } } m_LineList.releaseIteratorHandle(iteratorHandle); return isDuplicate; }
// // Priorities: // 1. Matches first lineID & realm // 2. Matches first matches toFromUrl & realm // 3. Matches first user & realm // 4. Matches first default line & realm // SipLine* SipLineList::findLine(const char* lineId, const char* realm, const Url& toFromUrl, const char* userId, const Url& defaultLine) { SipLine* pLineMatchingLineID = NULL ; SipLine* pLineMatchingUrl = NULL ; SipLine* pLineMatchingUser = NULL ; SipLine* pLineMatchingDefault = NULL ; Os::Logger::instance().log(FAC_LINE_MGR, PRI_DEBUG, "SipLineList::findLine " "searching for lineId '%s' realm '%s' toFromUrl '%s' userId '%s' defaultLine '%s'", lineId, realm, toFromUrl.toString().data(), userId, defaultLine.toString().data() ); int iteratorHandle = m_LineList.getIteratorHandle(); SipLine* nextLine = NULL; for (nextLine = (SipLine*) m_LineList.next(iteratorHandle); pLineMatchingLineID == NULL && nextLine != NULL; nextLine = (SipLine*) m_LineList.next(iteratorHandle) ) { # ifdef TEST_PRINT Url tmpLineUrl = nextLine->getIdentity(); Os::Logger::instance().log(FAC_LINE_MGR, PRI_DEBUG, "SipLineList::findLine checking tmpLineUrl='%s'", tmpLineUrl.toString().data()); # endif // If the realm doesn't match, simply skip it if ((realm != NULL) && strlen(realm) && (nextLine->IsDuplicateRealm(realm))) { // // Priority 1: Check LineId // if ( lineId != NULL && nextLine->matchesLineId(lineId)) { // We have match for the given lineId pLineMatchingLineID = nextLine ; // since this is the best possible match, it will exit the loop. Os::Logger::instance().log(FAC_LINE_MGR, PRI_DEBUG, "SipLineList::findLine matched line id '%s'", lineId); } else { if (Os::Logger::instance().willLog(FAC_LINE_MGR, PRI_DEBUG)) { Url nextLineIdentity = nextLine->getIdentity(); Os::Logger::instance().log(FAC_LINE_MGR, PRI_DEBUG, "SipLineList::findLine checking nextLineIdentity='%s'", nextLineIdentity.toString().data()); } // // Priority 2: check ToFromUrl // if ( pLineMatchingUrl == NULL && nextLine->matchesIdentity(toFromUrl) ) { pLineMatchingUrl = nextLine ; // Continue searching, because we may find a better match } else { // // Priority 3: Matches user & realm // if ( pLineMatchingUser == NULL && userId != NULL && nextLine->matchesUserId(userId) // should be case sensitive ) { pLineMatchingUser = nextLine ; // Continue searching, because we may find a better match } else { // // Priority 4: Check for default line // if (nextLine->matchesIdentity(defaultLine)) { pLineMatchingDefault = nextLine ; // Continue searching, because we may find a better match } } } } } } m_LineList.releaseIteratorHandle(iteratorHandle) ; // This is ugly, but needed for the desired effect SipLine* foundLine = ( pLineMatchingLineID ? pLineMatchingLineID : pLineMatchingUrl ? pLineMatchingUrl : pLineMatchingUser ? pLineMatchingUser : pLineMatchingDefault ? pLineMatchingDefault : NULL ); Os::Logger::instance().log(FAC_LINE_MGR, PRI_DEBUG, "SipLineList::findLine %s", foundLine ? "found" : "NOT found"); return foundLine; }
SIPX_LINE sipxLineLookupHandleByURI(SIPX_INSTANCE_DATA* pInst, const char* szURI) { SIPX_LINE hLine = 0 ; Url urlLine(szURI) ; // Use the line manager to find identity if available if (pInst && pInst->pLineManager) { SipLine* pLine = pInst->pLineManager->findLineByURL(urlLine, "unknown") ; if (pLine) urlLine = pLine->getIdentity() ; } if (gpLineHandleMap->lock()) { UtlHashMapIterator iter(*gpLineHandleMap); UtlInt* pIndex = NULL; UtlVoidPtr* pObj = NULL; while (pIndex = dynamic_cast<UtlInt*>( iter() ) ) { pObj = dynamic_cast<UtlVoidPtr*>(gpLineHandleMap->findValue(pIndex)); SIPX_LINE_DATA* pData = NULL ; if (pObj) { pData = (SIPX_LINE_DATA*) pObj->getValue() ; if (pData) { // Check main line definition if (urlLine.isUserHostPortEqual(*pData->lineURI)) { hLine = pIndex->getValue() ; break ; } // Check for line aliases if (pData->pLineAliases) { UtlVoidPtr* pValue ; Url* pUrl ; UtlSListIterator iterator(*pData->pLineAliases) ; while (pValue = (UtlVoidPtr*) iterator()) { pUrl = (Url*) pValue->getValue() ; if (urlLine.isUserHostPortEqual(*pUrl)) { hLine = pIndex->getValue() ; break ; } } } } } } gpLineHandleMap->unlock() ; } return hLine; }