Ejemplo n.º 1
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);
      }
Ejemplo n.º 2
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());
      }
Ejemplo n.º 3
0
// Dump the contents of a list of RegistrationBinding's.
void dumpList(const UtlSList& list)
{
   fprintf(stderr, "=== start\n");
   UtlSListIterator list_iter(list);
   RegistrationBinding* item;
   int item_no = 0;
   while ((item = dynamic_cast <RegistrationBinding*> (list_iter())))
   {
      fprintf(stderr, "--- item %d\n", item_no);
      UtlHashMap contents;
      item->copy(contents);
      UtlHashMapIterator iter(contents);
      UtlString* name;
      while ((name = dynamic_cast <UtlString*> (iter())))
      {
         UtlContainable* value = iter.value();
         UtlContainableType type = value->getContainableType();
         if (type == UtlString::TYPE)
         {
            fprintf(stderr, "%s = '%s'\n",
                    name->data(),
                    (dynamic_cast <UtlString*> (iter.value()))->data());
         }
         else if (type == UtlLongLongInt::TYPE)
         {
            Int64 value =
               (dynamic_cast <UtlLongLongInt*> (iter.value()))->getValue();
            fprintf(stderr, "%s = 0x%" FORMAT_INTLL "x = %" FORMAT_INTLL "d\n",
                    name->data(), value, value);
         }
         else if (type == UtlInt::TYPE)
         {
            fprintf(stderr, "%s = %" PRIdPTR "\n",
                    name->data(),
                    (dynamic_cast <UtlInt*> (iter.value()))->getValue());
         }
         else
         {
            fprintf(stderr, "%s has unknown type %s\n",
                    name->data(), type);
         }                  
      }
      item_no++;
   }
   fprintf(stderr, "=== end\n");
}
Ejemplo n.º 4
0
   void testGetNextUpdateForRegistrar()
      {
         UtlSList bindings;
         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("getMaxUpdate.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         Int64 seqOneUpdates = regDb->getNextUpdateForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         UtlSListIterator iterator(bindings);

         // Loop through all returned bindings and mark the ones we've seen.
         // Also check correctness of bindings
         RegistrationBinding *binding;
         while ((binding = (RegistrationBinding*)iterator()))
         {
             CPPUNIT_ASSERT_EQUAL(binding->getCallId()->compareTo("ID3"), 0);
             CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
             CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
             CPPUNIT_ASSERT_EQUAL(300, binding->getCseq());
         }

         bindings.destroyAll();
         // Pass in high update number value, expect nothing to be returned
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 8, bindings);
         CPPUNIT_ASSERT_EQUAL(0LL, seqOneUpdates);

         bindings.destroyAll();
         // Test the other registrar, expect one binding
         Int64 seqTwoUpdates = regDb->getNewUpdatesForRegistrar("seqTwo", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqTwoUpdates);

         binding = (RegistrationBinding*)bindings.first();
         CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
         CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
         CPPUNIT_ASSERT_EQUAL(800, binding->getCseq());
      }
Ejemplo n.º 5
0
void
RegistrationDB::updateBinding(const RegistrationBinding& reg)
{
   updateBinding(*(reg.getUri()),    // must not be null
                 *(reg.getContact() ? reg.getContact() : &nullString),
                 *(reg.getQvalue() ? reg.getQvalue() : &nullString),
                 *(reg.getCallId() ? reg.getCallId() : &nullString),
                 reg.getCseq(),
                 reg.getExpires(),
                 *(reg.getInstanceId() ? reg.getInstanceId() : &nullString),
                 *(reg.getGruu() ? reg.getGruu() : &nullString),
                 *(reg.getPath() ? reg.getPath() : &nullString),
                 *(reg.getPrimary() ? reg.getPrimary() : &nullString),
                 reg.getUpdateNumber());
}
Ejemplo n.º 6
0
RegistrationBinding*
RegistrationDB::copyRowToRegistrationBinding(dbCursor<RegistrationRow>& cursor) const
{
   RegistrationBinding *reg = new RegistrationBinding();
   reg->setUri(* new UtlString(cursor->uri));
   reg->setCallId(* new UtlString(cursor->callid));
   reg->setContact(* new UtlString(cursor->contact));
   reg->setQvalue(* new UtlString(cursor->qvalue));
   reg->setInstanceId(* new UtlString(cursor->instance_id));
   reg->setGruu(* new UtlString(cursor->gruu));
   reg->setPath(* new UtlString(cursor->path));
   reg->setCseq(cursor->cseq);
   reg->setExpires(cursor->expires);
   reg->setPrimary(* new UtlString(cursor->primary));
   reg->setUpdateNumber(cursor->update_number);
   return reg;
}
Ejemplo n.º 7
0
   void testUpdateNewBinding()
      {
         Url uri;
         UtlString contact;
         UtlSList bindings;
         RegistrationBinding* binding;
         RegistrationBinding newBinding;

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

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Make sure an existing binding doesn't exist
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 3, bindings);
         CPPUNIT_ASSERT_EQUAL(0LL, seqOneUpdates);

         // Create new binding with update number 3
         uri.setUserId("300");
         uri.setHostAddress("testdomain.example.com");
         newBinding.setUri(uri);

         newBinding.setContact("sip:[email protected]");
         newBinding.setCallId("ID3");
         newBinding.setPrimary("seqOne");
         newBinding.setUpdateNumber(3);

         // Add new binding
         regDb->updateBinding(newBinding);

         bindings.destroyAll();

         // We should now have two bindings - the original with update number 2 and the new one
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(2LL, seqOneUpdates);

         // Test if the registration data corresponds to what we expect
         UtlBoolean bSeenId2 = FALSE;
         UtlBoolean bSeenId3 = FALSE;
         UtlBoolean bSeenAnythingElse = FALSE;
         UtlSListIterator iterator(bindings);

         while ((binding = (RegistrationBinding*)iterator()))
         {
             const UtlString *s = binding->getCallId();
             if (s->compareTo("ID2") == 0)
             {
                 bSeenId2 = TRUE;
                 CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
                 CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
             }
             else if (s->compareTo("ID3") == 0)
             {
                 bSeenId3 = TRUE;
                 CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
                 CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
                 CPPUNIT_ASSERT_EQUAL(binding->getUpdateNumber(), 3LL);
             }
             else
             {
                 bSeenAnythingElse = TRUE;
             }
         }
         CPPUNIT_ASSERT(!bSeenAnythingElse);
         CPPUNIT_ASSERT(bSeenId2);
         CPPUNIT_ASSERT(bSeenId3);
      }