UtlContainable* UtlSListIterator::peekAtNext(void)
{
   UtlContainable* match = NULL;

   UtlContainer::acquireIteratorConnectionLock();
   OsLock takeContainer(mContainerRefLock);
   UtlSList* myList = dynamic_cast<UtlSList*>(mpMyContainer);

   if (myList != NULL) // list still valid?
   {
      OsLock take(myList->mContainerLock);
      UtlContainer::releaseIteratorConnectionLock();

      // advance the iterator
      UtlLink* nextLink = (mpCurrentNode == NULL
                           ? myList->head()
                           : mpCurrentNode->next()
                           );
      if( nextLink )
      {
         match = (UtlContainable*)nextLink->data;
      }
   }
   else
   {
      UtlContainer::releaseIteratorConnectionLock();
   }

   return match;
}
   void testNoRouteLocal()
      {
         const char* message =
            "INVITE sip:[email protected] SIP/2.0\r\n"
            "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n"
            "To: sip:[email protected]\r\n"
            "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n"
            "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n"
            "Cseq: 1 INVITE\r\n"
            "Max-Forwards: 20\r\n"
            "Contact: [email protected]\r\n"
            "Content-Length: 0\r\n"
            "\r\n";

         SipMessage testMsg(message, strlen(message));
         Url requestUri;
         UtlSList removedRoutes;
         
         testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes);

         UtlString normalizedMsg;
         int msgLen;
         testMsg.getBytes(&normalizedMsg, &msgLen);

         ASSERT_STR_EQUAL(message, normalizedMsg.data());

         UtlString requestUriResult;
         requestUri.toString(requestUriResult);
         
         ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data());

         CPPUNIT_ASSERT(removedRoutes.isEmpty());
      }
OsStatus CpNotificationRegister::unsubscribe(CP_NOTIFICATION_TYPE notificationType,
                                             const SipDialog& callbackSipDialog)
{
   OsStatus result = OS_FAILED;

   UtlInt key((int)notificationType);
   UtlSList* pDialogList = dynamic_cast<UtlSList*>(m_register.findValue(&key));
   if (!pDialogList)
   {
      return OS_SUCCESS;
   }

   if (pDialogList)
   {
      UtlSListIterator itor(*pDialogList);

      while (itor())
      {
         SipDialog* pSipDialog = dynamic_cast<SipDialog*>(itor.item());
         if (pSipDialog && pSipDialog->compareDialogs(callbackSipDialog) != SipDialog::DIALOG_MISMATCH)
         {
            pDialogList->destroy(pSipDialog);
         }
      }

      result = OS_SUCCESS;
   }

   return result;
}
Example #4
0
    /*!a  Test the occurancesOf() method .
    * 
    *     The test data for this test are :-
    *        a) When the search data is the first entry
    *        b) When the search data is the last entry
    *        c) When the search data is the mid(unique) entry
    *        d) When the search data has a matching value but not ref. 
    *        e) When the search data has multiple matches - mixture of ref / values
    *        f) When the search data has no match at all. 
    */
    void testOccurancesOf()
    {
        const int testCount = 6 ; 
        const char* prefix = "Test the occurancesOf(UtlContainable* cl); where cl " ; 
        const char* Msgs[] = { \
               "is the first entry ", \
               "is the last entry and ref matches ", \
               "is the mid entry and is unique ", \
               "has a matching value but not reference ", \
               "has multiple matches ", \
               "has no match at all " \
        } ; 

        commonList.insertAt(3, commonContainables_Clone[4]) ; 
        commonList.insertAt(5, commonContainables[4]) ; 
        UtlString notExistCollectable("This cannot and willnot exist"); 
       
        UtlContainable* searchValues[] = { \
                   commonContainables[0], commonContainables[commonEntriesCount -1], \
                   commonContainables[2], commonContainables_Clone[3], \
                   commonContainables[4], &notExistCollectable \
        } ;        
        int matchCount[] = { 1, 1, 1, 1, 3, 0 } ; 
        for (int i = 0 ; i < testCount ; i++)
        {
            string msg ; 
            TestUtilities::createMessage(2, &msg, prefix, Msgs[i]) ; 
            int actual = commonList.occurrencesOf(searchValues[i]) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), matchCount[i], actual) ; 
        }
    } //testOccurancesOf
Example #5
0
   void testUpdateExistingBinding()
      {
         UtlSList bindings;
         RegistrationBinding* binding;

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Get an existing binding
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         binding = (RegistrationBinding*)bindings.first();

         // Increment the CSeq number
         int newCseq = binding->getCseq() + 1;
         binding->setCseq(newCseq);
         regDb->updateBinding(*binding);
         binding->setCseq(0);

         // Get the same binding
         bindings.destroyAll();
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         // Test if the new CSeq number got updated
         binding = (RegistrationBinding*)bindings.first();
         CPPUNIT_ASSERT_EQUAL(newCseq, binding->getCseq());
      }
Example #6
0
    /*!a Test case to test the destroyAll()
    *    method.
    */
    void testClearAndDestroy()
    {
        const char* prefix  = "test the destroyAll() method " ;

        const char* suffix1 = ":- Verify that all entries are removed" ; 
        const char* suffix2 = ":- The objects are deleted" ;

        UtlContainableTestStub* uStub ;
        UtlContainableTestStub* uStubPtr ;
        uStub = new UtlContainableTestStub(0) ; 
        uStubPtr = new UtlContainableTestStub(1) ;
        emptyList.append(uStub) ;
        emptyList.append(uStubPtr) ;

        emptyList.destroyAll() ;
        int cCountAfter = UtlContainableTestStub::getCount() ; 

        string msg ;
        TestUtilities::createMessage(2, &msg, prefix, suffix1) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ; 

        // Since the TestStub has been implemented such that destructor
        // decrements the static counter, to verify that the objects have
        // been deleted, verify that the static counter has been decremented. 
        TestUtilities::createMessage(2, &msg, prefix, suffix2) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;

    } //testClearAndDestroy
Example #7
0
void
RegistrationDB::getUnexpiredContactsFieldsContaining (
   UtlString& substringToMatch,
   const int& timeNow,   
   UtlSList& matchingContactFields ) const
{
   // Clear the results
   matchingContactFields.destroyAll();
   if( m_pFastDB != NULL )
   {
       SMART_DB_ACCESS;
       dbCursor< RegistrationRow > cursor;
       UtlString queryString = "contact like '%" + substringToMatch + "%' and expires>";
       queryString.appendNumber( timeNow );
       dbQuery query;
       query = queryString;

       if ( cursor.select(query) > 0 )
       {
           // Copy all the unexpired contacts into the result list
           do
           {
               UtlString* contactValue = new UtlString(cursor->contact);
               matchingContactFields.append( contactValue );
           } while ( cursor.next() );
       }
   }
   else
   {
      OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getUnexpiredContactsFieldsContaining failed - no DB");
   }
}
Example #8
0
// Find the next like-instance of the designated object .
UtlContainable* UtlSListIterator::findNext(const UtlContainable* containableToMatch) 
{
   UtlContainable* match = NULL;

   UtlContainer::acquireIteratorConnectionLock();
   OsLock takeContainer(mContainerRefLock);
   UtlSList* myList = static_cast<UtlSList*>(mpMyContainer);
   
   OsLock take(myList->mContainerLock);
   UtlContainer::releaseIteratorConnectionLock();

   // advance the iterator
   UtlLink* nextLink = (mpCurrentNode == NULL
                        ? myList->head()
                        : mpCurrentNode->next()
                        );

   // search for the next match forward
   while (nextLink && !match)
   {
      UtlContainable *candidate = (UtlContainable*)nextLink->data;
      if (candidate && candidate->compareTo(containableToMatch) == 0)
      {
         mpCurrentNode = nextLink;
         match = candidate;
      }
      else
      {
         nextLink = nextLink->next();
      }
   }
   
   return match;
}
Example #9
0
   void testUpdateExistingUriNewContact()
      {
         UtlSList bindings;
         RegistrationBinding* binding;

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Get an existing binding
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         binding = (RegistrationBinding*)bindings.first();

         // Change the contact address
         const UtlString* oldContact = binding->getContact();
         UtlString newContact(*oldContact);
         newContact.replace('2', '3');
         binding->setContact(newContact);
         regDb->updateBinding(*binding);

         // We should have 2 bindings now
         bindings.destroyAll();
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(2LL, seqOneUpdates);
      }
Example #10
0
   void testUpdateSameBinding()
      {
         UtlSList bindings;
         RegistrationBinding* binding;

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Get an existing binding
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         binding = (RegistrationBinding*)bindings.first();

         // Call updateBinding with the same binding
         regDb->updateBinding(*binding);

         // Get it back and make sure we still only have one
         bindings.destroyAll();
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);
      }
Example #11
0
    /*!a Test case to test the destroy() 
    *    method. 
    */ 
    void testRemoveAndDestroy()
    {
        const char* prefix  = "test the destroy() method " ; 
        
        UtlContainableTestStub uStub(0) ;
        UtlContainableTestStub* uStubPtr ;
        uStubPtr = new UtlContainableTestStub(1) ;
        commonList.append(&uStub) ;
        commonList.append(uStubPtr) ;
        
        int cCountBefore = UtlContainableTestStub :: getCount() ; 

        UtlBoolean returnValue = commonList.destroy(uStubPtr) ; 
        UtlContainable* uLast = commonList.last() ; 
        string msg ; 
        TestUtilities::createMessage(2, &msg, prefix, ":- Verify the return value") ; 
        CPPUNIT_ASSERT_MESSAGE(msg.data(), returnValue) ;
        TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the entry is removed") ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)&uStub, (void*)uLast) ; 
        // The CollectableTestStub has been implemented such that a static counter gets decremented
        // for every descruction of an object instance. To verify that the object was destroyed, 
        // verify that the static count went down. 
        int cCountAfter = UtlContainableTestStub :: getCount() ;
        TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the object was deleted") ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ; 
    }
Example #12
0
void XmlRpcResponse::cleanUp(UtlContainable* value)
{
   if (value)
   {
      if (value->isInstanceOf(UtlHashMap::TYPE))
      {
         UtlHashMap* map = dynamic_cast<UtlHashMap*>(value);
         UtlHashMapIterator iterator(*map);
         UtlString* key;
         while ((key = dynamic_cast<UtlString*>(iterator())))
         {
            UtlContainable *pName;
            UtlContainable *member;
            pName = map->removeKeyAndValue(key, member);
            delete pName;
            cleanUp(member);
         }
      }
      else if (value->isInstanceOf(UtlSList::TYPE))
      {
         UtlSList* array = dynamic_cast<UtlSList*>(value);
         UtlContainable *element;
         while ((element = array->get()/* pop */))
         {
            cleanUp(element);
         }
      }

      delete value;
   }
}
    /*!a Test case for the findNext() method
    *
    *    The test data for this test case are :-
    *      a) When the match is the first element.
    *      b) When the match is the last element.
    *      c) When the match is a mid element(unique).
    *      d) When the match has two value matches (but a single ref match)
    *      e) When the match has two ref matches.
    *      f) When there is no match at all!
    *      g) When the match is after the current find.
    */
    void testFindNext()
    {
        struct TestFindNextStruct
        {
            const char* testDescription ;
            const UtlContainable* searchValue ;
            const UtlContainable* expectedValue ;
        } ;
        const char* prefix = "Test the find() method when the match " ;

        UtlString noExist("This cannot and should not exist!!!") ;
        TestFindNextStruct testData[] = { \
            { "is the first element ", commonContainables[0], commonContainables[0] }, \
            { "is the last element ", commonContainables[5], commonContainables[5] }, \
            { "is a mid element (unique match) ", commonContainables[2], \
              commonContainables[2] }, \
            { "has two value matches but a single ref match ", commonContainables[4], \
              commonContainables_Clone[4] }, \
            { "has two ref matches", commonContainables[3], commonContainables[3] }, \
            { "has a value match but no ref match", commonContainables_Clone[1], \
              commonContainables[1] }, \
            { "has no match at all", &noExist, NULL } \
        } ;
       // insert a clone of the 4th element to the 1st position
       commonList.insertAt(1, (UtlContainable*)commonContainables_Clone[4]) ;
       // The new index for a value match of commonContainables[4] must be 1.

       // insert another copy of the 3rd element to the 2nd position.
       commonList.insertAt(2, (UtlContainable*)commonContainables[3]) ;
       // The new index for commonContainables[3] must be 2) ;
       // what used to be the second element has now moved to 4.


        const int testCount = sizeof(testData)/sizeof(testData[0])  ;
        UtlSListIterator iter(commonList) ;
        for (int i = 0 ; i < testCount ; i++)
        {
            string msg ;

            const UtlContainable* actualValue = iter.findNext(testData[i].searchValue) ;
            TestUtilities::createMessage(2, &msg, prefix, testData[i].testDescription) ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), testData[i].expectedValue, \
                actualValue) ;
            iter.reset() ;
        }

        // Now test the case where the iterator is 'past' the index
        iter.reset() ;
        iter() ;
        iter() ;
        iter() ;
        iter() ;
        iter() ;
        UtlContainable* actualValue = iter.findNext(commonContainables[1]) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE("test findNext() when the iterator has " \
           "moved past the search index", (void*)NULL, (void*)actualValue) ;
    }//testFindNext
void getCountItems(UtlSList& list, size_t itemsToPop)
{
   assert(itemsToPop);
   
   for (; !list.isEmpty() && itemsToPop; itemsToPop--)
   {
      delete dynamic_cast<UtlString*>(list.get());
   }
}
   void testDoubleRoute()
      {
         const char* message =
            "INVITE sip:[email protected] SIP/2.0\r\n"
            "Route: <sip:[email protected];lr>, <sip:[email protected];lr>\r\n"
            "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n"
            "To: sip:[email protected]\r\n"
            "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n"
            "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n"
            "Cseq: 1 INVITE\r\n"
            "Max-Forwards: 20\r\n"
            "Contact: [email protected]\r\n"
            "Content-Length: 0\r\n"
            "\r\n";

         SipMessage testMsg(message, strlen(message));
         Url requestUri;
         UtlSList removedRoutes;
         
         testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes);

         UtlString normalizedMsg;
         int msgLen;
         testMsg.getBytes(&normalizedMsg, &msgLen);

         const char* expectedMessage = // route header removed, uri swapped
            "INVITE sip:[email protected] SIP/2.0\r\n"
            "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n"
            "To: sip:[email protected]\r\n"
            "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n"
            "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n"
            "Cseq: 1 INVITE\r\n"
            "Max-Forwards: 20\r\n"
            "Contact: [email protected]\r\n"
            "Content-Length: 0\r\n"
            "\r\n";

         ASSERT_STR_EQUAL(expectedMessage, normalizedMsg.data());

         UtlString requestUriResult;
         requestUri.toString(requestUriResult);
         
         ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data());

         UtlString* removedRoute;

         CPPUNIT_ASSERT( removedRoute = static_cast<UtlString*>(removedRoutes.get()));
         ASSERT_STR_EQUAL("<sip:[email protected];lr>", removedRoute->data());
         delete removedRoute;

         CPPUNIT_ASSERT( removedRoute = static_cast<UtlString*>(removedRoutes.get()));
         ASSERT_STR_EQUAL("<sip:[email protected];lr>", removedRoute->data());
         delete removedRoute;

         CPPUNIT_ASSERT(removedRoutes.isEmpty());

      }
void doListOperations()
{
   UtlSList testList;

   // fill the list
   appendCountItems(testList, NUM_PERFORMANCE_STRINGS);
   
   // take the first half off the front
   if (!testList.isEmpty())
   {
      getCountItems(testList, NUM_PERFORMANCE_STRINGS / 2);
   }

   // take the rest off the end by reference
   if (!testList.isEmpty())
   {
      UtlContainable* lastItem = testList.last();
      delete dynamic_cast<UtlString*>(testList.removeReference(lastItem));
   }

   // fill the list
   appendCountItems(testList, NUM_PERFORMANCE_STRINGS);

   // search the list for each item by value
   UtlString target;
   int targetIndex;
   for (targetIndex = 0; targetIndex < NUM_PERFORMANCE_STRINGS; targetIndex += 1)
   {
      target = string[targetIndex];
      UtlString* found = dynamic_cast<UtlString*>(testList.find(&target));
      if (found)
      {
         externalForSideEffects = found->length();
      }
   }
   
   // get the object in the middle of the list by index, and remove it by value
   while(!testList.isEmpty())
   {
      int numberLeft = testList.entries();
      UtlString* middle = dynamic_cast<UtlString*>(testList.at((numberLeft / 2)));
      delete dynamic_cast<UtlString*>(testList.remove(middle));
   }

   // fill the list
   appendCountItems(testList, NUM_PERFORMANCE_STRINGS);

   // iterate over each item in the list
   UtlSListIterator iterate(testList);
   UtlString* item;
   while ((item = dynamic_cast<UtlString*>(iterate())))
   {
      externalForSideEffects = item->length();
      delete item;
   }
}
Example #17
0
UtlBoolean
DialByNameDB::insertRow ( const Url& contact ) const
{
    UtlBoolean result = FALSE;

    if ( m_pFastDB != NULL )
    {
        // Fetch the display name
        UtlString identity, displayName, contactString;
        contact.getIdentity( identity );
        contact.getDisplayName( displayName );
        contact.toString( contactString );

        // Make sure that the contact URL is valid and contains
        // a contactIdentity and a contactDisplayName
        if ( !identity.isNull() && !displayName.isNull() )
        {
            UtlSList dtmfStrings;
            getDigitStrings ( displayName, dtmfStrings );
            if ( !dtmfStrings.isEmpty() )
            {
                // Thread Local Storage
                m_pFastDB->attach();

                // Search for a matching row before deciding to update or insert
                dbCursor< DialByNameRow > cursor(dbCursorForUpdate);

                DialByNameRow row;

                dbQuery query;
                // Primary Key is identity
                query="np_identity=",identity;

                // Purge all existing entries associated with this identity
                if ( cursor.select( query ) > 0 )
                {
                    cursor.removeAllSelected();
                } 

                // insert all dtmf combinations for this user
                unsigned int i;
                for (i=0; i<dtmfStrings.entries(); i++)
                {
                    UtlString* digits = (UtlString*)dtmfStrings.at(i);
                    row.np_contact = contactString;
                    row.np_identity = identity;
                    row.np_digits = digits->data();
                    insert (row);
                }
                // Commit rows to memory - multiprocess workaround
                m_pFastDB->detach(0);
            }
        }
    }
    return result;
}
    /*!a test case for the interaction of remove() and item().
    */
    void removeItem()
    {
       UtlString v1("a");
       UtlString v2("b");
       UtlString v3("c");
       UtlString v4("d");
       UtlContainable* e;

       UtlSList h;
       h.insert(&v1);
       h.insert(&v2);
       h.insert(&v3);
       h.insert(&v4);

       UtlSListIterator iter(h);

       // Check that item() returns NULL in the initial state.
       CPPUNIT_ASSERT(iter.item() == NULL);

       // Step the iterator and check that item() returns v1.
       e = iter();
       CPPUNIT_ASSERT(e == &v1);
       CPPUNIT_ASSERT(iter.item() == &v1);

       // Delete the element and check that item() returns NULL.
       h.remove(e);
       CPPUNIT_ASSERT(iter.item() == NULL);

       // Step the iterator and check that item() returns v2.
       e = iter();
       CPPUNIT_ASSERT(e == &v2);
       CPPUNIT_ASSERT(iter.item() == &v2);

       // Step the iterator and check that item() returns v3.
       e = iter();
       CPPUNIT_ASSERT(e == &v3);
       CPPUNIT_ASSERT(iter.item() == &v3);

       // Delete the element and check that item() returns v2.
       // (Because deleting an element of a list backs the iterator up
       // to the previous element.)
       h.remove(e);
       CPPUNIT_ASSERT(iter.item() == &v2);

       // Step the iterator and check that item() returns v4.
       e = iter();
       CPPUNIT_ASSERT(e == &v4);
       CPPUNIT_ASSERT(iter.item() == &v4);

       // Step the iterator after the last element and check that
       // item() returns NULL.
       e = iter();
       CPPUNIT_ASSERT(e == NULL);
       CPPUNIT_ASSERT(iter.item() == NULL);

    } //removeItem()
Example #19
0
OsStatus SmsNotifier::handleAlarm(const OsTime alarmTime,
      const UtlString& callingHost,
      const cAlarmData* alarmData,
      const UtlString& alarmMsg)
{
   OsStatus retval = OS_FAILED;

   //execute the mail command for each user
   UtlString groupKey(alarmData->getGroupName());
   if (!groupKey.isNull())
   {
      UtlContainable* pContact = mContacts.findValue(&groupKey);
      if (pContact)
      {
         // Process the comma separated list of contacts
         UtlString* contactList = dynamic_cast<UtlString*> (pContact);
         if (!contactList->isNull())
         {
            MailMessage message(mSmsStrFrom, mReplyTo, mSmtpServer);
            UtlTokenizer tokenList(*contactList);

            UtlString entry;
            while (tokenList.next(entry, ","))
            {
               message.To(entry, entry);
            }

            UtlString body;
            UtlString tempStr;

            UtlString sevStr = Os::Logger::instance().priorityName(alarmData->getSeverity());
            body.append(alarmMsg);

            Os::Logger::instance().log(FAC_ALARM, PRI_DEBUG, "AlarmServer: sms body is %s", body.data());

            message.Body(body);

            UtlSList subjectParams;
            UtlString codeStr(alarmData->getCode());
            UtlString titleStr(sevStr);
            subjectParams.append(&codeStr);
            subjectParams.append(&titleStr);
            assembleMsg(mSmsStrSubject, subjectParams, tempStr);
            message.Subject(tempStr);

            // delegate send to separate task so as not to block
            EmailSendTask::getInstance()->sendMessage(message);
         }
      }
   }

   return retval;
}
void MpRtpInputAudioConnection::handleStartReceiveRtp(UtlSList& codecList,
                                                      OsSocket& rRtpSocket,
                                                      OsSocket& rRtcpSocket)
{
   m_bAudioReceived = FALSE;
   m_inactiveFrameCount = 0;

   if (codecList.entries() > 0)
   {
      // if RFC2833 DTMF is disabled
      if (!m_bRFC2833DTMFEnabled)
      {
         UtlSListIterator itor(codecList);
         SdpCodec* pCodec = NULL;
         // go through all codecs, if you find telephone event, remove it
         while (itor())
         {
            pCodec = dynamic_cast<SdpCodec*>(itor.item());
            if (pCodec && pCodec->getCodecType() == SdpCodec::SDP_CODEC_TONES)
            {
               codecList.destroy(pCodec);
            }
         }
      }

      // continue only if numCodecs is still greater than 0
      if (codecList.entries() > 0)
      {
         // initialize jitter buffers for all codecs
         mpDejitter->initJitterBuffers(codecList);
         mpDecode->selectCodecs(codecList);
      }
   }
   // No need to synchronize as the decoder is not part of the
   // flowgraph.  It is part of this connection/resource
   //mpFlowGraph->synchronize();
   prepareStartReceiveRtp(rRtpSocket, rRtcpSocket);
   // No need to synchronize as the decoder is not part of the
   // flowgraph.  It is part of this connection/resource
   //mpFlowGraph->synchronize();
   if (codecList.entries() > 0)
   {
      mpDecode->enable();
      if (mpDtmfDetector)
      {
         mpDtmfDetector->enable();
      }
   }

   sendConnectionNotification(MP_NOTIFICATION_START_RTP_RECEIVE, 0);
}
    void testPeekAtNext()
    {
       UtlString v1("a");
       UtlString v2("b");
       UtlString v3("c");
       UtlString v4("d");
       UtlContainable* e;

       UtlSList h;
       h.insert(&v1);
       h.insert(&v2);
       h.insert(&v3);
       h.insert(&v4);

       UtlSListIterator iter(h);

       // check that peekAtNext() returns v1 while iterator points at NULL
       e = iter.peekAtNext();
       CPPUNIT_ASSERT(e == &v1);
       CPPUNIT_ASSERT(iter.item() == NULL );

       // Step the iterator and check that peekAtNext() returns v2
       // while iterator points at v1
       iter();
       e = iter.peekAtNext();
       CPPUNIT_ASSERT(e == &v2);
       CPPUNIT_ASSERT(iter.item() == &v1);

       // Step the iterator and check that peekAtNext() returns v3
       // while iterator points at v2
       iter();
       e = iter.peekAtNext();
       CPPUNIT_ASSERT(e == &v3);
       CPPUNIT_ASSERT(iter.item() == &v2);

       // Step the iterator and check that peekAtNext() returns v4
       // while iterator points at v3
       iter();
       e = iter.peekAtNext();
       CPPUNIT_ASSERT(e == &v4);
       CPPUNIT_ASSERT(iter.item() == &v3);

       // Step the iterator and check that peekAtNext() returns NULL
       // while iterator points at v4
       iter();
       e = iter.peekAtNext();
       CPPUNIT_ASSERT(e == NULL);
       CPPUNIT_ASSERT(iter.item() == &v4);
    }
Example #22
0
    /*!a Test case to verify insertAt(size_t, UtlContainable*) for a
    *     list that is not empty.
    *     The test data for this test are
    *     a) Insert any UtlContainable to the 0th location,
    *     b) Insert a UtlInt to a 'mid' location,
    *     c) Insert any UtlString object to a 'mid' location
    *     d) Insert any UtlContainable object to the last location
    */
    void testInsertAt_NonEmptyList()
    {
        const int testCount = 4 ;
        const char* prefix = "Test insert(n, Collectable*) for a list that is not empty; "\
              "where Collectable is "  ;
        const char* Msgs[] = { \
               "a UtlContainableXXX and n = 0", \
               "a UtlString and n > 0 && n < size", \
               "a UtlInt and n > 0 && n < size", \
               "a UtlContainableXXX where n = size-1" \
        };
        const char* suffix1 = " :- Verify return value" ; 
        const char* suffix2 = " :- Verify value is appended"  ; 
        const char* suffix3 = " :- Verify new list size" ;  

        UtlString testFirst("First Entry") ; 
        UtlInt testInt(102) ;
        UtlString testString("Test String") ;
        UtlInt testLast(99999) ; 
        UtlContainable* itemToAdd[] = { &testFirst, &testInt, &testString, &testLast } ;
        UtlContainable* expectedValue[] = { &testFirst, &testInt, &testString, &testLast} ;
        int insertLocation[] = { 0, 2, 3, commonEntriesCount+3} ;
        int tmpCount = commonEntriesCount ; 
        int expectedEntries[] = {++tmpCount, ++tmpCount, ++tmpCount, ++tmpCount} ; 

        for (int i = 0 ; i < testCount ; i++)
        {
            UtlContainable* uActual ; 
            string msg ; 
              
            // comment out for now. Uncomment if implementation returns Collectable
            uActual = commonList.insertAt(insertLocation[i], itemToAdd[i]);
            //verify that the right value is returned.
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], uActual) ;
            //`commonList.insertAt(insertLocation[i], itemToAdd[i]);

            // verify that the value is inserted
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; 
            uActual = commonList.at(insertLocation[i]) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], uActual) ;
 
            //verify that the total number of entries has incremented by one. 
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix3) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedEntries[i], \
                (int)commonList.entries()) ; 
            
        }
    }//testInsertAt_NonEmptyList()
Example #23
0
int
RegistrationDB::getUpdatesForRegistrar(dbQuery&  query,
                                       UtlSList& bindings) const
{
   int numRows = 0;
   if ( m_pFastDB != NULL )
   {
      SMART_DB_ACCESS;
      dbCursor<RegistrationRow> cursor(dbCursorForUpdate);
      numRows = cursor.select(query);
      if (numRows > 0)
      {
         do {
            RegistrationBinding* reg = copyRowToRegistrationBinding(cursor);
            bindings.append(reg);
         }
         while (cursor.next());
      }
   }
   else
   {
      OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getNewUpdatesForRegistrar failed - no DB");
   }
   return numRows;
}
Example #24
0
// Generate the partial RLMI list.
// Generate list of ResourceReference's corresponding to the URIs in mResourcesList.
// Returns true if partialList is non-empty.
UtlBoolean ResourceList::genPartialList(UtlSList& partialList)
{
   UtlSListIterator resourcesItor(mResourcesList);
   ResourceReference* resource;
   UtlBoolean any_found = FALSE;

   // Check the resource list for changed items.
   while ((resource = dynamic_cast <ResourceReference*> (resourcesItor())))
   {
      UtlSListIterator changesItor(mChangesList);
      UtlString* changedRsrc;
      UtlBoolean found = FALSE;

      while ((changedRsrc = dynamic_cast <UtlString*> (changesItor())))
      {
         // Send a partial RLMI (only for resources that changed).
         if (strcmp(resource->getUri()->data(), changedRsrc->data()) == 0)
         {
            found = TRUE;
            any_found = TRUE;
         }
      }

      if (found)
      {
         partialList.append(resource);
      }
   }

   return any_found;
}
Example #25
0
//deep copy of aliases
void SipLine::copyAliases(UtlSList& dest, const UtlSList& source) const
{
    // Clear dest list
    if (!dest.isEmpty())
    {
        dest.destroyAll() ;
    }
    
    // Copy maintaining order
    int length = source.entries() ;
    for (int i=0; i<length; i++)
    {
        UtlString* pEntry = (UtlString*) source.at(i) ;
        dest.append(new UtlString(*pEntry)) ;
    }    
}
Example #26
0
// Stores a list of strings to the configuration datadase using the 
// designated prefix as the base for the list items. 
void OsConfigDb::addList(const UtlString& rPrefix,
                         UtlSList& rList) 
{
    OsWriteLock lock(mRWMutex);
    size_t iNumEntries ;
    UtlString key ;
    UtlString* pValue ;

    // First remove all items start with the specified prefix
    removeByPrefix(rPrefix) ;

    // Next add all of the new items
    iNumEntries = rList.entries() ;
    if (iNumEntries > 0)
    {
        key = rPrefix ;
        key.append(".COUNT") ;
        set(key, iNumEntries) ;

        UtlSListIterator itor(rList) ;        
        int iCount = 1 ;
        char cTemp[64] ;
        while ((pValue = (UtlString*) itor()))
        {
            sprintf(cTemp, "%d", iCount++);   
            key = rPrefix ;
            key.append(".") ;
            key.append(cTemp) ;

            set(key, *pValue) ;            
        }
    }
}
Example #27
0
// Loads a list of strings from the configuration datadase using the 
// designated prefix as the base for the list items.
int OsConfigDb::loadList(const UtlString& rPrefix,
                         UtlSList& rList) const
{
    OsReadLock lock(mRWMutex);
    int iNumEntries ;
    int rc = 0 ; 
    UtlString key ;
    UtlString value ;
    char cTemp[64] ;

    // Get number of items
    key = rPrefix ;
    key.append(".COUNT") ;    
    if (get(key, iNumEntries) == OS_SUCCESS)
    {
        for (int i = 0; i < iNumEntries; i++)
        {            
            sprintf(cTemp, "%d", i+1);
            key = rPrefix ;
            key.append(".") ;
            key.append(cTemp) ;

            if (get(key, value) == OS_SUCCESS)
            {
                rList.append(new UtlString(value)) ;
                rc++ ;
            }
        }        
    }

    return rc ;
}
    /**
     * Test for SListIterator::findNext only at places that could break
     *  - find item not in list
     *  - find items at endpoints
     *  - find items after reseting iterator
     */
    void testFindNextForDummies()
    {
        UtlString fruitData[] = {
            UtlString("apple"),         // 0
            UtlString("orange"),        // 1
            UtlString("banana"),        // 2
            UtlString("apple"),         // 3
            UtlString("banana"),        // 4
            UtlString("apple")          // 5
        };
        int n = sizeof(fruitData) / sizeof(fruitData[0]);

        UtlSList fruit;
        for (int i = 0; i < n; i++)
        {
            fruit.append(&fruitData[i]);
        }

        // nonexistant items
        UtlSListIterator pineapples(fruit);
        UtlString pineapple("pineapple");
        CPPUNIT_ASSERT_MESSAGE("Do not find item not in list", pineapples.findNext(&pineapple) == NULL);

        // test items at endpoints
        UtlSListIterator apples(fruit);
        UtlString apple("apple");
        CPPUNIT_ASSERT_MESSAGE("Find first item", apples.findNext(&apple) == &fruitData[0]);
        CPPUNIT_ASSERT_MESSAGE("Find second item", apples.findNext(&apple) == &fruitData[3]);
        CPPUNIT_ASSERT_MESSAGE("Find third item", apples.findNext(&apple) == &fruitData[5]);
        CPPUNIT_ASSERT_MESSAGE("Find no more items", apples.findNext(&apple) == NULL);

        // test scattered items
        UtlSListIterator bananas(fruit);
        UtlString banana("banana");
        CPPUNIT_ASSERT_MESSAGE("Find first item", bananas.findNext(&banana) == &fruitData[2]);
        CPPUNIT_ASSERT_MESSAGE("Find second item", bananas.findNext(&banana) == &fruitData[4]);
        CPPUNIT_ASSERT_MESSAGE("Find no more items", bananas.findNext(&banana) == NULL);

        // test adjustments in iterator
        UtlSListIterator picker(fruit);
        CPPUNIT_ASSERT_MESSAGE("Find first item", picker.findNext(&apple) == &fruitData[0]);
        picker.reset();
        CPPUNIT_ASSERT_MESSAGE("Find first item again after reset",
            picker.findNext(&apple) == &fruitData[0]);
        CPPUNIT_ASSERT_MESSAGE("Find second item after initial reset",
            picker.findNext(&apple) == &fruitData[3]);
    }
    /*!a Test case for the () operator.
    *
    *    The test data for this test is :-
    *       1) The next entry is a UtlString
    *       2) The next entry is a UtlInt
    *       3) The next entry is the last entry
    *       4) All entries have been read
    */
    void testAdvancingOperator()
    {
        struct TestAdvancingOperatorStruct
        {
            const char* testDescription ;
            const UtlContainable* expectedValue ;
        } ;

        const int testCount = 4 ;
        const char* prefix = "Verify the () operator for an iterator when " ;

        const char* suffix1 = " :- verify return value" ;
        const char* suffix2 = " :- verify number of entries in the list" ;

        UtlSList testList ;
        testList.append(&commonString1) ;
        testList.append(&commonInt1) ;
        testList.append(&commonString2) ;
        UtlSListIterator iter(testList) ;

        TestAdvancingOperatorStruct testData[] = { \
            { "the first entry is a UtlString", &commonString1 }, \
            { "the first entry is a UtlInt", &commonInt1 }, \
            { "when the list has only one entry", &commonString2 }, \
            { "when the list is empty", NULL } \
        } ;
        int expectedEntries = 3 ;

        for (int i = 0 ; i < testCount ; i++)
        {
             string msg ;
             TestUtilities::createMessage(3, &msg, prefix, \
                 testData[i].testDescription, suffix1) ;
             CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[i].expectedValue, \
                 (void*)iter()) ;
             TestUtilities::createMessage(3, &msg, prefix, testData[i].testDescription, \
                 suffix2);
             CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedEntries, \
                 (int)testList.entries()) ;
        }

        // Test the () operator for an empty list
        UtlSListIterator emptyIter(emptyList) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Test the () operator for an empty list iterator" , \
            (void*)NULL, (void*)emptyIter()) ;

    } //testAdvancingOperator()
Example #30
0
bool AlarmRpcGetAlarmCount::execute(const HttpRequestContext& requestContext,
                                     UtlSList& params,
                                     void* userData,
                                     XmlRpcResponse& response,
                                     ExecutionStatus& status)
{
   bool result = false;
   status = XmlRpcMethod::FAILED;

   if (!params.at(0) || !params.at(0)->isInstanceOf(UtlString::TYPE))
   {
      handleMissingExecuteParam(name(), PARAM_NAME_CALLING_HOST, response, status);
   }
   else
   {
      UtlString* pCallingHostname = dynamic_cast<UtlString*>(params.at(0));

      if (1 != params.entries())
      {
         handleExtraExecuteParam(name(), response, status);
      }
      else
      {
         SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData);

         if(validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name()))
         {
            OsSysLog::add(FAC_ALARM, PRI_INFO,
                          "AlarmRpc::getAlarmCount: host %s requested alarm count",
                          pCallingHostname->data()
                          );

            // Get the count of alarms since last restart
            UtlInt alarm_count;
            alarm_count = UtlInt(cAlarmServer::getInstance()->getAlarmCount());

            // Construct and set the response.
            response.setResponse(&alarm_count);
            status = XmlRpcMethod::OK;
            result = true;

         }
      }
   }

   return result;
}