SipLine* SipLineList::getLine ( const UtlString& userId, int& numOfMatches ) { SipLine* nextline = NULL; SipLine* firstMatchedLine = NULL; UtlString nextUserId; numOfMatches = 0; if (!userId.isNull()) { int iteratorHandle = m_LineList.getIteratorHandle(); while(NULL != (nextline = (SipLine*) m_LineList.next(iteratorHandle))) { if (nextline->matchesUserId(userId)) { if( numOfMatches == 0) { firstMatchedLine = nextline; } numOfMatches ++; } } m_LineList.releaseIteratorHandle(iteratorHandle); } return firstMatchedLine; }
UtlBoolean SipLineList::lineExists(const SipLine& line, UtlBoolean bConsiderAliases) const { UtlBoolean result = m_lineMap.contains(&line.getLineUri().toString()); if (!result && bConsiderAliases) { // not found, try aliases result = m_lineAliasMap.contains(&line.getLineUri().toString()); } return result; }
SipLine* SipLineList::getLine( const Url& lineIdentityUrl ) { SipLine* nextline = NULL; int iteratorHandle = m_LineList.getIteratorHandle(); while(NULL != (nextline = (SipLine*) m_LineList.next(iteratorHandle))) { if (nextline->matchesIdentity(lineIdentityUrl)) { break ; } } m_LineList.releaseIteratorHandle(iteratorHandle); return nextline; }
void SipLineList::getLineUris(UtlSList& lineUris) const { SipLine* pLine = NULL; UtlHashMapIterator itor(m_lineMap); UtlContainable* pKey = NULL; int i = 0; while ((pKey = itor()) != NULL) { pLine = dynamic_cast<SipLine*>(itor.value()); if (pLine) { // copy line uri into list lineUris.append(pLine->getLineUri().toString().clone()); } } }
void SipLineList::dumpLines() { SipLine* pLine = NULL; UtlHashMapIterator itor(m_lineMap); UtlContainable* pKey = NULL; int i = 0; while ((pKey = itor()) != NULL) { pLine = dynamic_cast<SipLine*>(itor.value()); if (pLine) { OsSysLog::add(FAC_LINE_MGR, PRI_DEBUG, "LineList %x, Line [%d]: lineURI=%s, lineState=%d", this, i++, pLine->getLineUri().toString().data(), (int)pLine->getState()); } } }
SipLine* SipLineList::getLine(const UtlString& lineId) { SipLine* nextline = NULL; if ( !lineId.isNull() ) { int iteratorHandle = m_LineList.getIteratorHandle(); while(NULL != (nextline = (SipLine*) m_LineList.next(iteratorHandle))) { if (nextline->matchesLineId(lineId)) { break; } } m_LineList.releaseIteratorHandle(iteratorHandle); } return nextline; }
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 ); }
SipLine* SipLineList::getLineByUserId(const UtlString& userId) const { SipLine* pLine = NULL; if (!userId.isNull()) { UtlHashMapIterator itor(m_lineMap); UtlContainable* pKey = NULL; while ((pKey = itor()) != NULL) { pLine = dynamic_cast<SipLine*>(itor.value()); if (pLine && !pLine->getUserId().compareTo(userId)) { return pLine; } } } return 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; }
UtlBoolean SipLineList::getDeviceLine(SipLine *line) { UtlBoolean retVal = FALSE; UtlString user; int iteratorHandle = m_LineList.getIteratorHandle(); SipLine* nextLine = NULL; while ((nextLine = (SipLine*) m_LineList.next(iteratorHandle))!= NULL) { user = nextLine->getUser(); if ( user.compareTo("device" , UtlString::ignoreCase) == 0) { *line = *nextLine; retVal = TRUE; break; } user.remove(0); } m_LineList.releaseIteratorHandle(iteratorHandle); return retVal; }
// // Priorities: // 1. Matches first lineUri // 2. Matches line alias // 3. Matches first userId // SipLine* SipLineList::findLine(const Url& lineUri, const UtlString& userId, UtlBoolean bConsiderAliases) const { // firt lookup by lineUri and/or alias SipLine* pLine = getLine(lineUri, bConsiderAliases); if (pLine) { return pLine; } else { // not found, try userId if (!userId.isNull()) { // only search by userId if its not empty UtlHashMapIterator itor(m_lineMap); UtlContainable* pKey = NULL; while ((pKey = itor()) != NULL) { pLine = dynamic_cast<SipLine*>(itor.value()); if (pLine) { if (pLine->getUserId().compareTo(userId, UtlString::ignoreCase) == 0) { return pLine; } } } } } // is NULL if nothing was found return NULL; }
UtlBoolean SipLineList::remove(const SipLine& line) { removeAliasesForLine(line.getLineUri()); return m_lineMap.destroy(&line.getLineUri().toString()); }
// // 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; }