void testConstructor()
      {
         /*
          * This test exists to initialize the singleton plugin.
          * Doing it as a static ran into ordering problems.
          */
         CPPUNIT_ASSERT((xferctl=dynamic_cast<MSFT_ExchangeTransferHack*>(getAuthPlugin("msft"))));

         OsConfigDb xferConfigDb;
         xferConfigDb.set(MSFT_ExchangeTransferHack::RecognizerConfigKey, "^RTCC/");
         xferctl->readConfig(xferConfigDb);

         testUserAgent.setIsUserAgent(FALSE);

         testUserAgent.setUserAgentHeaderProperty("sipXecs/testproxy");

         testUserAgent.setForking(FALSE);  // Disable forking

         OsConfigDb configDb;
         configDb.set("SIPX_PROXY_AUTHENTICATE_ALGORITHM", "MD5");
         configDb.set("SIPX_PROXY_HOSTPORT", "sipx.example.edu");

         testSipRouter = new SipRouter(testUserAgent, mForwardingRules, configDb);
         xferctl->announceAssociatedSipRouter( testSipRouter );
      }
Ejemplo n.º 2
0
SipConfigServerAgent* SipConfigServerAgent::startAgents(const char* configFileName)
{
    int sipTcpPort;
    int sipUdpPort;
    int sipTlsPort;
    OsConfigDb configDb;

    if(configDb.loadFromFile(configFileName) == OS_SUCCESS)
    {
      osPrintf("Found config file: %s\n", configFileName);
    }
    else
    {
        configDb.set("SIP_SDS_UDP_PORT", "5090");
        configDb.set("SIP_SDS_TCP_PORT", "5090");
        configDb.set("SIP_SDS_TLS_PORT", "5091");
        configDb.set(CONFIG_SETTING_LOG_DIR, "");
        configDb.set(CONFIG_SETTING_LOG_LEVEL, "");
        configDb.set(CONFIG_SETTING_LOG_CONSOLE, "");

        if (configDb.storeToFile(configFileName) != OS_SUCCESS)
                      osPrintf("Could not store config file: %s\n", configFileName);
    }
    
    sipTcpPort = configDb.getPort("SIP_SDS_UDP_PORT") ;
    sipUdpPort = configDb.getPort("SIP_SDS_TCP_PORT") ;
    sipTlsPort = configDb.getPort("SIP_SDS_TLS_PORT") ;

    // Start the sip stack
    SipUserAgent* pAgent = new SipUserAgent(sipTcpPort,
        sipUdpPort,   
        sipTlsPort,
        NULL, // public IP address (nopt used in proxy)
        NULL, // default user (not used in proxy)
        NULL, // default SIP address (not used in proxy)
        NULL, // outbound proxy
        NULL, // directory server
        NULL, // registry server
        NULL, // auth scheme
        NULL, //auth realm
        NULL, // auth DB
        NULL, // auth user IDs
        NULL, // auth passwords
        NULL, // line mgr
        SIP_DEFAULT_RTT, // first resend timeout
        TRUE, // default to UA transaction
        SIPUA_DEFAULT_SERVER_UDP_BUFFER_SIZE, // socket layer read buffer size
        SIPUA_DEFAULT_SERVER_OSMSG_QUEUE_SIZE // OsServerTask message queue size
        );
    pAgent->start();

    // Start the SipConfigServerAgent
    SipConfigServerAgent* pConfigAgent = new SipConfigServerAgent(pAgent) ;
    pConfigAgent->start() ;

    return(pConfigAgent);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    OsConfigDb configDb;
    UtlString configDbFile = TEST_FILENAME;
    
    parseArgs(argc, argv);
    
    if (MemCheckDelay)
    {
        // Delay 45 seconds to allow memcheck start
        printf("Wating %d seconds for start of memcheck ...", MemCheckDelay);
        OsTask::delay(MemCheckDelay * 1000);
        printf("starting\n");
    }    
    
    initLogger(argv);

    // Reset database content an rewrite the file
    configDb.set("TestItem1", "Value1");
    configDb.set("TestItem2", "Value2");
    configDb.set("TestItem3", "Value3");
    configDb.set("TestItem3", "Value4");        

    configDb.storeToFile(configDbFile);
    
    ConfigRPC_Callback* confCallbacks;
    ConfigRPC*          configRPC;
    XmlRpcDispatch*     rpc;
 
    // start a simple XmlRpc test server
    rpc = new XmlRpcDispatch(HTTP_PORT, false);

    confCallbacks = new test_Callback();
    configRPC     = new ConfigRPC( TEST_DATASET,
                                   TEST_VERSION,
                                   configDbFile,
                                   confCallbacks);
    // enter the connector RPC methods in the XmlRpcDispatch table
    ConfigRPC::registerMethods(*rpc);
    
    printf("Server will be up for %d seconds on port %d\n", Duration/1000, HttpPort);
    OsTask::delay(Duration);
    
    if (MemCheckDelay)
    {
        // Delay 45 seconds to allow memcheck start
        printf("Wating %d seconds for stop of memcheck ...", MemCheckDelay);
        OsTask::delay(MemCheckDelay * 1000);
        printf("starting\n");
    }
 
    exit(0);
}
Ejemplo n.º 4
0
   void testReadConfig()
      {
         OsConfigDb configuration;

         configuration.set("READCONFIG_NOTPASSED_HOOK_LIBRARY.Error", PLUGIN_LIB_DIR "libfoo" PLUGIN_EXT);
         configuration.set("READCONFIG_OTHERPARAM", "DummyValue");

         // configure a hook
         configuration.set("READCONFIG_TEST_HOOK_LIBRARY.Only",
                           PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
         // with two configuration values
         configuration.set("READCONFIG_TEST.Only.VALUE1", "FirstValue");
         configuration.set("READCONFIG_TEST.Only.VALUE2", "SecondValue");

         PluginHooks testPlugins("getTestPlugin", "READCONFIG_TEST");
         testPlugins.readConfig(configuration);

         PluginIterator plugin(testPlugins);

         UtlString name;
         TestPlugin* thePlugin;

         // get the hook and confirm the name
         thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         CPPUNIT_ASSERT(!name.isNull());
         ASSERT_STR_EQUAL("Only",name.data());
         UtlString fullName;
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginA::Only",fullName.data());

         // read the two parameters and confirm that the hook got them
         UtlString pluginValue;
         CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor("VALUE1", pluginValue));
         ASSERT_STR_EQUAL("FirstValue",pluginValue.data());

         CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor("VALUE2", pluginValue));
         ASSERT_STR_EQUAL("SecondValue",pluginValue.data());

         // try some bogus parameter
         CPPUNIT_ASSERT(!thePlugin->getConfiguredValueFor("UNCONFIGURED", pluginValue));

         // confirm that this is the only hook
         CPPUNIT_ASSERT(plugin.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());
      }
Ejemplo n.º 5
0
 void setUp()
 {
    UtlString name("ntap");
    RouteState::setSecret("fixed");
    pNatTraversalAgent = new NatTraversalAgent( name );
    
    OsConfigDb configuration;
    configuration.set("NATRULES", TEST_DATA_DIR "/NatTraversalAgent/nattraversalrules3.xml");
    pNatTraversalAgent->readConfig( configuration );
 }
Ejemplo n.º 6
0
   RequestLinterTest() :
      identity(""),
      requestUri("sip:[email protected]")
   {
      
      testUserAgent.setIsUserAgent(FALSE);
      testUserAgent.setUserAgentHeaderProperty("sipXecs/testproxy");
      testUserAgent.setForking(FALSE);  // Disable forking
      UtlString hostAliases("mydomainalias.com mydomainotheralias.com");
      testUserAgent.setHostAliases(hostAliases);

      OsConfigDb configDb;
      configDb.set("SIPX_PROXY_AUTHENTICATE_ALGORITHM", "MD5");
      configDb.set("SIPX_PROXY_DOMAIN_NAME", "mydomain.com");
      configDb.set("SIPX_PROXY_AUTHENTICATE_REALM", "mydomain.com");
      configDb.set("SIPX_PROXY_HOSTPORT", "mydomain.com");

      testSipRouter = new SipRouter(testUserAgent, mForwardingRules, configDb);
      spLinter->announceAssociatedSipRouter( testSipRouter );

   }
Ejemplo n.º 7
0
   void testNoHooks()
      {
         OsConfigDb configuration;

         configuration.set("NOHOOKS_NOTPASSED_HOOK_LIBRARY.Error", PLUGIN_LIB_DIR "libfoo" PLUGIN_EXT);
         configuration.set("NOHOOKS_OTHERPARAM", "DummyValue");

         // there are no hooks configured for this prefix
         PluginHooks testPlugins("getTestPlugin", "NOHOOKS_PASSED");
         testPlugins.readConfig(configuration);

         PluginIterator shouldBeEmpty(testPlugins);

         UtlString name;

         // confirm that there are no hooks configured.
         CPPUNIT_ASSERT(shouldBeEmpty.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());

         CPPUNIT_ASSERT(shouldBeEmpty.next() == NULL);
      }
Ejemplo n.º 8
0
   // Test that a response message is allowed and is not modified
   void testNoPermResponse()
      {
         OsConfigDb configuration;
         configuration.set("RULES", TEST_DATA_DIR "/enforcerules.xml");

         enforcer->readConfig(configuration);

         UtlString identity; // no authenticated identity
         Url requestUri("sip:somewhere@forbidden");

         const char* message =
            "SIP/2.0 200 Ok\r\n"
            "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n"
            "To: sip:somewhere@forbidden\r\n"
            "From: Caller <sip:[email protected]>; tag=99911983748\r\n"
            "Call-Id: b1373e736d7d359ead76fa5cd467d999\r\n"
            "Cseq: 2 ACK\r\n"
            "Max-Forwards: 20\r\n"
            "Contact: [email protected]\r\n"
            "Content-Length: 0\r\n"
            "Record-Route: <sip:example.com;lr;sipXecs-rs=enforce%2Aauth%7E%21d1e296555015a54cb746fa7ac5695cf7>\r\n"
            "\r\n";
         SipMessage testMsg(message, strlen(message));

         UtlSList noRemovedRoutes;
         UtlString routeName("example.com");
         RouteState routeState( testMsg, noRemovedRoutes, routeName );

         const char unmodifiedRejectReason[] = "unmodified";
         UtlString rejectReason(unmodifiedRejectReason);

         UtlString method("INVITE");
         const bool bSpiralingRequest = false;
         AuthPlugin::AuthResult priorResult = AuthPlugin::ALLOW; // SipRouter passes this for responses

         CPPUNIT_ASSERT(AuthPlugin::CONTINUE
                        == enforcer->authorizeAndModify(identity,
                                                        requestUri,
                                                        routeState,
                                                        method,
                                                        priorResult,
                                                        testMsg,
                                                        bSpiralingRequest,
                                                        rejectReason
                                                        ));
         ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data());

         UtlString recordRoute;
         CPPUNIT_ASSERT(testMsg.getRecordRouteField(0, &recordRoute));
         ASSERT_STR_EQUAL( "<sip:example.com;lr;sipXecs-rs=enforce%2Aauth%7E%21d1e296555015a54cb746fa7ac5695cf7>", recordRoute );
      }
Ejemplo n.º 9
0
   void testNoLibrary()
      {
         OsConfigDb configuration;

         configuration.set("NO_LIB_NOTPASSED_HOOK_LIBRARY.Error", PLUGIN_LIB_DIR "libfoo" PLUGIN_EXT);
         configuration.set("NO_LIB_OTHERPARAM", "DummyValue");

         // configure two instances of the same hook library, with different parameters
         configuration.set("NO_LIB_TEST_HOOK_LIBRARY.1-First",
                           PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
         configuration.set("NO_LIB_TEST.1-First.VALUE", "FirstValue");

         configuration.set("NO_LIB_TEST_HOOK_LIBRARY.2-EmptyLib", "");
         configuration.set("NO_LIB_TEST.2-EmptyLib.VALUE", "EmptyLibValue");

         configuration.set("NO_LIB_TEST_HOOK_LIBRARY.3-Third",
                           PLUGIN_LIB_DIR "libtestpluginB" PLUGIN_EXT);
         configuration.set("NO_LIB_TEST.3-Third.VALUE", "ThirdValue");

         // load up the hooks
         PluginHooks testPlugins("getTestPlugin", "NO_LIB_TEST");
         testPlugins.readConfig(configuration);
         PluginIterator plugin(testPlugins);

         UtlString name;
         TestPlugin* thePlugin;

         // get the first instance and check its name
         thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         CPPUNIT_ASSERT(!name.isNull());
         ASSERT_STR_EQUAL("1-First",name.data());
         UtlString fullName;
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginA::1-First",fullName.data());

         // get the second instance and confirm its name
         thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         CPPUNIT_ASSERT(!name.isNull());
         ASSERT_STR_EQUAL("3-Third",name.data());
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginB::3-Third",fullName.data());

         // and make sure that is the end of the iteration
         CPPUNIT_ASSERT(plugin.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());
      }
Ejemplo n.º 10
0
   void testOneHook()
      {
         OsConfigDb configuration;

         configuration.set("ONEHOOK_NOTPASSED_HOOK_LIBRARY.Error", PLUGIN_LIB_DIR "libfoo" PLUGIN_EXT);
         configuration.set("ONEHOOK_OTHERPARAM", "DummyValue");

         // configure one hook, with no parameters
         configuration.set("ONEHOOK_TEST_HOOK_LIBRARY.Only",
                           PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);

         PluginHooks testPlugins("getTestPlugin", "ONEHOOK_TEST");
         testPlugins.readConfig(configuration);

         PluginIterator plugin(testPlugins);

         UtlString name;
         TestPlugin* thePlugin;

         // get that one hook
         thePlugin = static_cast<TestPlugin*>(plugin.next(&name));

         // confirm that it is loaded and that it has the right instance name
         CPPUNIT_ASSERT(thePlugin != NULL);
         CPPUNIT_ASSERT(!name.isNull());
         ASSERT_STR_EQUAL("Only",name.data());

         // invoke the pluginName method from the hook to confirm that it's there
         UtlString fullName;
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginA::Only",fullName.data());

         // confirm that it is the only configured hook
         CPPUNIT_ASSERT(plugin.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());
      }
Ejemplo n.º 11
0
   void testTwoInstances()
      {
         OsConfigDb configuration;

         configuration.set("TWO_INST_NOTPASSED_HOOK_LIBRARY.Error", PLUGIN_LIB_DIR "libfoo" PLUGIN_EXT);
         configuration.set("TWO_INST_OTHERPARAM", "DummyValue");

         // configure two instances of the same hook library, with different parameters
         configuration.set("TWO_INST_TEST_HOOK_LIBRARY.First",
                           PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
         configuration.set("TWO_INST_TEST.First.VALUE", "FirstValue");

         configuration.set("TWO_INST_TEST_HOOK_LIBRARY.Second",
                           PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
         configuration.set("TWO_INST_TEST.Second.VALUE", "SecondValue");

         // load up the hooks
         PluginHooks testPlugins("getTestPlugin", "TWO_INST_TEST");
         testPlugins.readConfig(configuration);
         PluginIterator plugin(testPlugins);

         UtlString name;
         TestPlugin* thePlugin;

         // get the first instance and check its name
         thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         CPPUNIT_ASSERT(!name.isNull());
         ASSERT_STR_EQUAL("First",name.data());
         UtlString fullName;
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginA::First",fullName.data());

         const UtlString ValueKey("VALUE");

         // check that the first instance is using the correct configuration value
         UtlString pluginValue;
         CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
         ASSERT_STR_EQUAL("FirstValue",pluginValue.data());

         // get the second instance and confirm its name
         thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         CPPUNIT_ASSERT(!name.isNull());
         ASSERT_STR_EQUAL("Second",name.data());
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginA::Second",fullName.data());

         // check that the second instance is using the correct configuration value
         CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
         ASSERT_STR_EQUAL("SecondValue",pluginValue.data());

         // and make sure that is the end of the iteration
         CPPUNIT_ASSERT(plugin.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());
      }
Ejemplo n.º 12
0
void
StatusServer::parseList (
    const UtlString& keyPrefix,
    const UtlString& separatedList,
    OsConfigDb& list )
{
    if (!separatedList.isNull())
    {
        int index = 1;
        UtlString value;
        while( NameValueTokenizer::getSubField( separatedList.data(), index, ", \t", &value) )
        {
            char temp[10];
            sprintf(temp, "%d", index);
            UtlString key = temp;
            list.set(key, value);
            index ++;
        }
    }
}
Ejemplo n.º 13
0
   void testReconfigure()
      {
         PluginHooks testPlugins("getTestPlugin", "RECONFIG_TEST");

         const UtlString ValueKey("VALUE");

         UtlString name;
         TestPlugin* thePlugin;
         UtlString pluginValue;
         UtlString fullName;


         {
            // Do the initial configuration of two instances of a hook
            OsConfigDb configuration;

            configuration.set("RECONFIG_TEST_HOOK_LIBRARY.First",
                              PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
            configuration.set("RECONFIG_TEST.First.VALUE", "FirstValue");

            configuration.set("RECONFIG_TEST_HOOK_LIBRARY.Second",
                              PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
            configuration.set("RECONFIG_TEST.Second.VALUE", "SecondValue");

            // load them up
            testPlugins.readConfig(configuration);

            PluginIterator plugin(testPlugins);

            // check the first instance
            thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
            CPPUNIT_ASSERT(thePlugin != NULL);
            CPPUNIT_ASSERT(!name.isNull());
            ASSERT_STR_EQUAL("First",name.data());
            thePlugin->pluginName(fullName);
            ASSERT_STR_EQUAL("TestPluginA::First",fullName.data());
            CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
            ASSERT_STR_EQUAL("FirstValue",pluginValue.data());

            // check the second instance
            thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
            CPPUNIT_ASSERT(thePlugin != NULL);
            CPPUNIT_ASSERT(!name.isNull());
            ASSERT_STR_EQUAL("Second",name.data());
            thePlugin->pluginName(fullName);
            ASSERT_STR_EQUAL("TestPluginA::Second",fullName.data());
            CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
            ASSERT_STR_EQUAL("SecondValue",pluginValue.data());

            // and confirm that is the end
            CPPUNIT_ASSERT(plugin.next(&name) == NULL);
            CPPUNIT_ASSERT(name.isNull());
         }

         {
            // Now create a new configuration that eliminates the First instance
            // and changes the configuration value for the Second instance
            OsConfigDb configuration;
            configuration.set("RECONFIG_TEST_HOOK_LIBRARY.Second",
                              PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
            configuration.set("RECONFIG_TEST.Second.VALUE", "NewValue");

            // reconfigure the plugins
            testPlugins.readConfig(configuration);

            PluginIterator plugin(testPlugins);

            // confirm that we still get the Second instance (but we get it first :-)
            thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
            CPPUNIT_ASSERT(thePlugin != NULL);
            CPPUNIT_ASSERT(!name.isNull());
            ASSERT_STR_EQUAL("Second",name.data());
            thePlugin->pluginName(fullName);
            ASSERT_STR_EQUAL("TestPluginA::Second",fullName.data());

            // and check that it has the new configuration value
            CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
            ASSERT_STR_EQUAL("NewValue",pluginValue.data());

            // and that it's the only hook configured now
            CPPUNIT_ASSERT(plugin.next(&name) == NULL);
            CPPUNIT_ASSERT(name.isNull());
         }

         {
            // Now create a third configuration that changes the library for the Second instance
            OsConfigDb configuration;
            configuration.set("RECONFIG_TEST_HOOK_LIBRARY.Second",
                              PLUGIN_LIB_DIR "libtestpluginB" PLUGIN_EXT);
            configuration.set("RECONFIG_TEST.Second.VALUE", "ChangedValue");

            // reconfigure the plugins
            testPlugins.readConfig(configuration);

            PluginIterator plugin(testPlugins);

            // confirm that we still get the Second instance (but we get it first :-)
            thePlugin = static_cast<TestPlugin*>(plugin.next(&name));
            CPPUNIT_ASSERT(thePlugin != NULL);
            CPPUNIT_ASSERT(!name.isNull());
            ASSERT_STR_EQUAL("Second",name.data());
            thePlugin->pluginName(fullName);
            ASSERT_STR_EQUAL("TestPluginB::Second",fullName.data());

            // and check that it has the new configuration value
            CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
            ASSERT_STR_EQUAL("ChangedValue",pluginValue.data());

            // and that it's the only hook configured now
            CPPUNIT_ASSERT(plugin.next(&name) == NULL);
            CPPUNIT_ASSERT(name.isNull());
         }
      }
Ejemplo n.º 14
0
   void testTwoHookTypes()
      {
         OsConfigDb configuration;

         configuration.set("TWO_TYPE_NOTPASSED_HOOK_LIBRARY.Error", PLUGIN_LIB_DIR "libfoo" PLUGIN_EXT);
         configuration.set("TWO_TYPE_OTHERPARAM", "DummyValue");

         // Configure two different hook types - each in its own library
         //   (we cheat - it's the same source, modified by configuration
         //    switches; see comments in ../testplugin/TestPlugin.cpp)
         configuration.set("TWO_TYPE1_HOOK_LIBRARY.First",
                           PLUGIN_LIB_DIR "libtestpluginA" PLUGIN_EXT);
         configuration.set("TWO_TYPE1.First.VALUE", "FirstValue");

         configuration.set("TWO_TYPE2_HOOK_LIBRARY.Second",
                           PLUGIN_LIB_DIR "libtestpluginB" PLUGIN_EXT);
         configuration.set("TWO_TYPE2.Second.VALUE", "SecondValue");

         // load the first hook type
         PluginHooks test1Plugins("getTestPlugin", "TWO_TYPE1");
         test1Plugins.readConfig(configuration);

         // load the second hook type
         PluginHooks test2Plugins("getTestPlugin", "TWO_TYPE2");
         test2Plugins.readConfig(configuration);

         // create iterators for both hook types
         PluginIterator plugin1(test1Plugins);
         PluginIterator plugin2(test2Plugins);

         UtlString name;
         TestPlugin* thePlugin;
         UtlString fullName;

         // get the first instance of the first hook type and confirm the names
         thePlugin = static_cast<TestPlugin*>(plugin1.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginA::First",fullName.data());

         // confirm the first hook type is using the correct configuration value
         const UtlString ValueKey("VALUE");
         UtlString pluginValue;
         CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
         ASSERT_STR_EQUAL("FirstValue",pluginValue.data());

         // get the first instance of the second hook type and confim its names
         thePlugin = static_cast<TestPlugin*>(plugin2.next(&name));
         CPPUNIT_ASSERT(thePlugin != NULL);
         thePlugin->pluginName(fullName);
         ASSERT_STR_EQUAL("TestPluginB::Second",fullName.data());

         // confirm the configuration of the second hook type
         CPPUNIT_ASSERT(thePlugin->getConfiguredValueFor(ValueKey, pluginValue));
         ASSERT_STR_EQUAL("SecondValue",pluginValue.data());

         // make sure each type only has the one instance
         CPPUNIT_ASSERT(plugin1.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());
         CPPUNIT_ASSERT(plugin2.next(&name) == NULL);
         CPPUNIT_ASSERT(name.isNull());
      }
Ejemplo n.º 15
0
// Constructor
SipPresenceMonitor::SipPresenceMonitor(SipUserAgent* userAgent,
                                       SipSubscriptionMgr* subscriptionMgr,
                                       UtlString& domainName,
                                       int hostPort,
                                       OsConfigDb* configFile,
                                       bool toBePublished,
                                       const char* persistentFile) :
   mpUserAgent(userAgent),
   mDomainName(domainName),
   mToBePublished(toBePublished),
   mLock(OsBSem::Q_PRIORITY, OsBSem::FULL),
   mpSubscriptionMgr(subscriptionMgr),
   mPersistentFile(persistentFile),
   mPersistenceTimer(mPersistTask.getMessageQueue(), 0),
   mPersistTask(this)
{
   // Read the persistent file to initialize mPersenceEventList, if
   // one is supplied.
   if (!mPersistentFile.isNull())
   {
      readPersistentFile();
   }

   char buffer[80];
   sprintf(buffer, "@%s:%d", mDomainName.data(), hostPort);
   mHostAndPort = UtlString(buffer);

   UtlString localAddress;
   OsSocket::getHostIp(&localAddress);

   OsConfigDb configDb;
   configDb.set("PHONESET_MAX_ACTIVE_CALLS_ALLOWED", 2*MAX_CONNECTIONS);

#ifdef INCLUDE_RTCP
   CRTCManager::getRTCPControl();
#endif //INCLUDE_RTCP
   // Start the media processing tasks.
   mpStartTasks();

   // Instantiate the call processing subsystem
   mpCallManager = new CallManager(FALSE,
                                   NULL,
                                   TRUE,                              // early media in 180 ringing
                                   &mCodecFactory,
                                   RTP_START_PORT,                    // rtp start
                                   RTP_START_PORT + (2*MAX_CONNECTIONS), // rtp end
                                   localAddress,
                                   localAddress,
                                   mpUserAgent,
                                   0,                                 // sipSessionReinviteTimer
                                   NULL,                              // mgcpStackTask
                                   NULL,                              // defaultCallExtension
                                   Connection::RING,                  // availableBehavior
                                   NULL,                              // unconditionalForwardUrl
                                   -1,                                // forwardOnNoAnswerSeconds
                                   NULL,                              // forwardOnNoAnswerUrl
                                   Connection::BUSY,                  // busyBehavior
                                   NULL,                              // sipForwardOnBusyUrl
                                   NULL,                              // speedNums
                                   CallManager::SIP_CALL,             // phonesetOutgoingCallProtocol
                                   4,                                 // numDialPlanDigits
                                   CallManager::NEAR_END_HOLD,        // holdType
                                   5000,                              // offeringDelay
                                   "",                                // pLocal
                                   CP_MAXIMUM_RINGING_EXPIRE_SECONDS, // inviteExpiresSeconds
                                   QOS_LAYER3_LOW_DELAY_IP_TOS,       // expeditedIpTos
                                   MAX_CONNECTIONS,                   // maxCalls
                                   sipXmediaFactoryFactory(&configDb));    // CpMediaInterfaceFactory

   mpDialInServer = new PresenceDialInServer(mpCallManager, configFile);
   mpCallManager->addTaoListener(mpDialInServer);
   mpDialInServer->start();

   // Start the call processing system
   mpCallManager->start();

   // Add self to the presence dial-in server for state change notification
   mpDialInServer->addStateChangeNotifier("Presence_Dial_In_Server", this);

   if (mToBePublished)
   {
      // Create the SIP Subscribe Server
      mpSubscribeServer = new SipSubscribeServer(*mpUserAgent, mSipPublishContentMgr,
                                                 *mpSubscriptionMgr, mPolicyHolder);
      // Arrange to generate default content for presence events.
      mSipPublishContentMgr.publishDefault(PRESENCE_EVENT_TYPE, PRESENCE_EVENT_TYPE,
                                           new PresenceDefaultConstructor);
      mpSubscribeServer->enableEventType(PRESENCE_EVENT_TYPE);
      mpSubscribeServer->start();
   }

   // Enable the xmlrpc sign-in/sign-out
   int HttpPort;
   if (configDb.get(CONFIG_SETTING_HTTP_PORT, HttpPort) != OS_SUCCESS)
   {
      HttpPort = PRESENCE_DEFAULT_HTTP_PORT;
   }

   mpXmlRpcSignIn = new XmlRpcSignIn(this, HttpPort);

   // Start the persist task.
   if (!mPersistentFile.isNull())
   {
      mPersistTask.start();
   }
}
Ejemplo n.º 16
0
   virtual bool execute(const HttpRequestContext& requestContext, ///< request context
                        UtlSList& params,                         ///< request param list
                        void* userData,                           ///< user data
                        XmlRpcResponse& response,                 ///< request response
                        ExecutionStatus& status
                        )
      {
         UtlString* dbName = dynamic_cast<UtlString*>(params.at(0));

         if (dbName && !dbName->isNull())
         {
            OsReadLock lock(*ConfigRPC::spDatabaseLock);

            ConfigRPC* db = ConfigRPC::find(*dbName);
            if (db)
            {
               status = db->mCallback->accessAllowed(requestContext, ConfigRPC_Callback::Set);
               if ( XmlRpcMethod::OK == status )
               {
                  // read in the dataset
                  OsConfigDb dataset;
                  OsStatus datasetStatus = db->load(dataset);
                  if ( OS_SUCCESS == datasetStatus )
                  {
                     // get the list of names that the request is asking for
                     UtlContainable* secondParam = params.at(1);
                     if ( secondParam )
                     {
                        UtlHashMap* paramList = dynamic_cast<UtlHashMap*>(secondParam);
                        if (paramList)
                        {
                           /*
                            * Iterate over the requested name/value pairs
                            */
                           UtlHashMapIterator params(*paramList);
                           UtlContainable* nextParam = NULL;
                           size_t paramsSet = 0;

                           while (    XmlRpcMethod::OK == status
                                  && (nextParam = params())
                                  )
                           {
                              UtlString* name = dynamic_cast<UtlString*>(params.key());
                              if ( name )
                              {
                                 UtlString* value = dynamic_cast<UtlString*>(params.value());
                                 if (value)
                                 {
                                    dataset.set(*name, *value);
                                    paramsSet++;
                                 }
                                 else
                                 {
                                    UtlString faultMsg;
                                    faultMsg.append("parameter name '");
                                    faultMsg.append(*name);
                                    faultMsg.append("' value is not a string");
                                    response.setFault(ConfigRPC::invalidType, faultMsg.data());
                                    status = XmlRpcMethod::FAILED;
                                 }
                              }
                              else
                              {
                                 UtlString faultMsg;
                                 faultMsg.append("parameter number ");
                                 char paramIndex[10];
                                 sprintf(paramIndex,"%zu", paramsSet + 1);
                                 faultMsg.append(paramIndex);
                                 faultMsg.append(" name is not a string");
                                 response.setFault(ConfigRPC::invalidType, faultMsg.data());
                                 status = XmlRpcMethod::FAILED;
                              }
                           }

                           if ( XmlRpcMethod::OK == status )
                           {
                              if (OS_SUCCESS == db->store(dataset))
                              {
                                 UtlInt numberSet(paramList->entries());
                                 response.setResponse(&numberSet);
                              }
                              else
                              {
                                 response.setFault( ConfigRPC::storeFailed
                                                   ,"error storing dataset"
                                                   );
                                 status = XmlRpcMethod::FAILED;
                              }
                           }
                        }
                        else
                        {
                           // The second parameter was not a list
                           response.setFault( ConfigRPC::invalidType
                                             ,"second parameter is not a struct"
                                             );
                           status = XmlRpcMethod::FAILED;
                        }
                     }
                     else // no parameter names specified
                     {
                        // No second parameter
                        response.setFault( ConfigRPC::invalidType
                                          ,"no second parameter of name/value pairs"
                                          );
                        status = XmlRpcMethod::FAILED;
                     }
                  }
                  else
                  {
                     UtlString faultMsg("dataset load failed");
                     response.setFault(ConfigRPC::loadFailed, faultMsg);
                     status = XmlRpcMethod::FAILED;
                  }
               }
               else
               {
                  UtlString faultMsg("Access Denied");
                  response.setFault(XmlRpcMethod::FAILED, faultMsg.data());
               }
            }
            else
            {
               UtlString faultMsg;
               faultMsg.append("db lookup failed for '");
               faultMsg.append(*dbName);
               faultMsg.append("'");
               response.setFault( XmlRpcResponse::UnregisteredMethod, faultMsg.data());
               status = XmlRpcMethod::FAILED;
            }
         }
         else
         {
            response.setFault( XmlRpcResponse::EmptyParameterValue
                              ,"'dbname' parameter is missing or invalid type"
                              );
            status = XmlRpcMethod::FAILED;
         }

         return true;
      }
Ejemplo n.º 17
0
    void testManipulators()
    {
        OsConfigDb *pDb = new OsConfigDb();
        pDb->set("Key1", "Value1");
        CPPUNIT_ASSERT_MESSAGE("verify that the database is not empty", 
                               !pDb->isEmpty());
        CPPUNIT_ASSERT_MESSAGE("has one entry", pDb->numEntries()==1);
                                                                                
        // test the remove() method
        //
        // We put the following block in its own scope so that the UtlString
        // reference (stored in "value") is released as a side effect of going
        // out of scope.  Otherwise, it will look like a memory leak.
        {
            UtlString value;
                                                                                
            pDb->remove("Key1");
            CPPUNIT_ASSERT_MESSAGE("verify that it looks empty", pDb->isEmpty());
            CPPUNIT_ASSERT_MESSAGE("has zero entries", pDb->numEntries()==0);
                                                                                
            pDb->set("Key1", "Value1");   // add the entry back
            pDb->set("Key1", "Value1b");  // change the value for an existing entry
            CPPUNIT_ASSERT_MESSAGE("verify that the database is not empty", 
                                   !pDb->isEmpty());
            CPPUNIT_ASSERT_EQUAL_MESSAGE("has one entry", 1, pDb->numEntries());
                                                                                
            OsStatus res = pDb->get("Key1", value);
            CPPUNIT_ASSERT(res == OS_SUCCESS);
            CPPUNIT_ASSERT_MESSAGE("that contains the revised value", 
                value.compareTo("Value1b") == 0);
                                                                                
            pDb->set("Key2", "Value2");
            pDb->set("Key3", "Value3");
            pDb->set("Key4", "Value4");
            CPPUNIT_ASSERT_MESSAGE("check the number of entries", 
                                   pDb->numEntries()==4);
            value.remove(0);
        }
                                                                                
        // test the storeToFile() method
        pDb->storeToFile("tmpdb");         // store the config db to the file
        delete pDb;                   // delete the database
                                                                                
        // test the loadFromFile() method
        //
        // We put the following block in its own scope so that the UtlString
        // reference (stored in "value") is released as a side effect of going
        // out of scope.  Otherwise, it will look like a memory leak.
        {
            UtlString  value;
            
            pDb = new OsConfigDb();       // create an empty database
            pDb->loadFromFile("tmpdb");        // load the data from a file
        }
                                                                                
        CPPUNIT_ASSERT_MESSAGE("verify the database is not empty", 
                               !pDb->isEmpty());

        CPPUNIT_ASSERT_MESSAGE("has four entries", pDb->numEntries()==4);

        UtlString value;
        OsStatus res = pDb->get("Key1", value);
        CPPUNIT_ASSERT_MESSAGE("contains correct data", 
            res == OS_SUCCESS && value.compareTo("Value1b") == 0);

        res = pDb->get("Key2", value);
        CPPUNIT_ASSERT_MESSAGE("contains correct data",
            res == OS_SUCCESS && value.compareTo("Value2") == 0);

        res = pDb->get("Key3", value);
        CPPUNIT_ASSERT_MESSAGE("contains correct data",
            res == OS_SUCCESS && value.compareTo("Value3") == 0);

        res = pDb->get("Key4", value);
        CPPUNIT_ASSERT_MESSAGE("contains correct data",
            res == OS_SUCCESS && value.compareTo("Value4") == 0);

        delete pDb;                   // delete the database
        value.remove(0);
    }
Ejemplo n.º 18
0
   // Test that an out-of-dialog request gets a Record-Route, even if it does not
   // require authorization/authentication, and test that the Record-Route has no
   // extraneous parameters applied.
   void testNoPermNeededOut()
      {
         OsConfigDb configuration;
         configuration.set("RULES", TEST_DATA_DIR "/enforcerules.xml");

         enforcer->readConfig(configuration);

         UtlString identity; // no authenticated identity
         Url requestUri("sip:911@emergency-gw");

         const char* message =
            "INVITE sip:911@emergency-gw SIP/2.0\r\n"
            "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n"
            "To: sip:911@emergency-gw\r\n"
            "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n"
            "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n"
            "Cseq: 2 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));

         UtlSList noRemovedRoutes;
         UtlString routeName("example.com");
         RouteState routeState( testMsg, noRemovedRoutes, routeName );

         const char unmodifiedRejectReason[] = "unmodified";
         UtlString rejectReason(unmodifiedRejectReason);

         UtlString method("INVITE");
         const bool bSpiralingRequest = false;
         AuthPlugin::AuthResult priorResult = AuthPlugin::CONTINUE;

         CPPUNIT_ASSERT(AuthPlugin::ALLOW
                        == enforcer->authorizeAndModify(identity,
                                                        requestUri,
                                                        routeState,
                                                        method,
                                                        priorResult,
                                                        testMsg,
                                                        bSpiralingRequest,
                                                        rejectReason
                                                        ));
         ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data());

         // No Record-Route header.
         routeState.update(&testMsg);
         UtlString recordRoute;
         CPPUNIT_ASSERT(!testMsg.getRecordRouteField(0, &recordRoute));

         RouteState spiraledRouteState(testMsg, noRemovedRoutes, routeName);

         // now simulate a spiral with the same message
         CPPUNIT_ASSERT(AuthPlugin::ALLOW
                        == enforcer->authorizeAndModify(identity,
                                                        requestUri,
                                                        spiraledRouteState,
                                                        method,
                                                        priorResult,
                                                        testMsg,
                                                        bSpiralingRequest,
                                                        rejectReason
                                                        ));
         ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data());

         // No Record-Route header.
         spiraledRouteState.update(&testMsg);
         CPPUNIT_ASSERT(!testMsg.getRecordRouteField(0, &recordRoute));
      }
Ejemplo n.º 19
0
   // Test that an ACK is not challenged and not RecordRouted
   void testNoPermAck()
      {
         OsConfigDb configuration;
         configuration.set("RULES", TEST_DATA_DIR "/enforcerules.xml");

         enforcer->readConfig(configuration);

         UtlString identity; // no authenticated identity
         Url requestUri("sip:somewhere@forbidden");

         const char* message =
            "ACK sip:somewhere@forbidden SIP/2.0\r\n"
            "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n"
            "To: sip:somewhere@forbidden\r\n"
            "From: Caller <sip:[email protected]>; tag=99911983748\r\n"
            "Call-Id: b1373e736d7d359ead76fa5cd467d999\r\n"
            "Cseq: 2 ACK\r\n"
            "Max-Forwards: 20\r\n"
            "Contact: [email protected]\r\n"
            "Content-Length: 0\r\n"
            "\r\n";
         SipMessage testMsg(message, strlen(message));

         UtlSList noRemovedRoutes;
         UtlString routeName("example.com");
         RouteState routeState( testMsg, noRemovedRoutes, routeName );

         const char unmodifiedRejectReason[] = "unmodified";
         UtlString rejectReason(unmodifiedRejectReason);

         UtlString method("ACK");
         const bool bSpiralingRequest = false;
         AuthPlugin::AuthResult priorResult = AuthPlugin::ALLOW;

         CPPUNIT_ASSERT(AuthPlugin::CONTINUE
                        == enforcer->authorizeAndModify(identity,
                                                        requestUri,
                                                        routeState,
                                                        method,
                                                        priorResult,
                                                        testMsg,
                                                        bSpiralingRequest,
                                                        rejectReason
                                                        ));
         ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data());

         routeState.update(&testMsg);

         UtlString recordRoute;
         CPPUNIT_ASSERT(!testMsg.getRecordRouteField(0, &recordRoute));

         // now simulate a spiral with the same message
         CPPUNIT_ASSERT(AuthPlugin::CONTINUE
                        == enforcer->authorizeAndModify(identity,
                                                        requestUri,
                                                        routeState,
                                                        method,
                                                        priorResult,
                                                        testMsg,
                                                        bSpiralingRequest,
                                                        rejectReason
                                                        ));
         ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data());

         routeState.update(&testMsg);

         CPPUNIT_ASSERT(!testMsg.getRecordRouteField(0, &recordRoute));
      }
Ejemplo n.º 20
0
int main(int argc, char* argv[])
{
   const char* configFileName = "siptest-config";
   int proxyTcpPort;
   int proxyUdpPort;
   int proxyTlsPort;
   OsConfigDb configDb;

   // siptest uses osPrintf for output, so we have to un-suppress it.
   enableConsoleOutput(TRUE);

   if(configDb.loadFromFile(configFileName) == OS_SUCCESS)
   {
      osPrintf("Found config file: %s\n", configFileName);
   }
   else
   {
      configDb.set("SIP_TEST_UDP_PORT", "3000");
      configDb.set("SIP_TEST_TCP_PORT", "3000");
      configDb.set("SIP_TEST_TLS_PORT", "3001");

      if(configDb.storeToFile(configFileName) == OS_SUCCESS)
      {
         osPrintf("Could not write config file: %s\n", configFileName);
      }
   }

   proxyUdpPort = configDb.getPort("SIP_TEST_UDP_PORT") ;
   proxyTcpPort = configDb.getPort("SIP_TEST_TCP_PORT") ;
   proxyTlsPort = configDb.getPort("SIP_TEST_TLS_PORT") ;

   UtlBoolean commandStatus = CommandProcessor::COMMAND_SUCCESS;
   char buffer[1024];
   char* commandLine;
   CommandProcessor processor;

   SipLineMgr*    lineMgr = new SipLineMgr();
   SipRefreshMgr* refreshMgr = new SipRefreshMgr();

   lineMgr->StartLineMgr();
   lineMgr->initializeRefreshMgr( refreshMgr );

   SipUserAgent*  sipUA = new SipUserAgent( proxyTcpPort
                                            ,proxyUdpPort
                                            ,proxyTlsPort
                                            ,NULL         // default publicAddress
                                            ,NULL         // default defaultUser
                                            ,NULL         // default defaultSipAddress
                                            ,NULL         // default sipProxyServers
                                            ,NULL         // default sipDirectoryServers
                                            ,NULL         // default sipRegistryServers
                                            ,NULL         // default authenicateRealm
                                            ,NULL         // default authenticateDb
                                            ,NULL         // default authorizeUserIds
                                            ,NULL         // default authorizePasswords
                                            ,lineMgr
      );
   sipUA->allowMethod(SIP_REGISTER_METHOD);
   sipUA->allowMethod(SIP_SUBSCRIBE_METHOD);
   sipUA->allowMethod(SIP_NOTIFY_METHOD);

   sipUA->start();

   sipUA->startMessageLog();
   osPrintf( "SIP logging Started\n" );

   refreshMgr->init( sipUA );

   CommandMsgProcessor* msgProc = new CommandMsgProcessor(sipUA);
   msgProc->start();

   processor.registerCommand("help", new HelpCommand(&processor));
   processor.registerCommand("?", new HelpCommand(&processor));
   processor.registerCommand("history", new HistoryCommand(&processor));
   processor.registerCommand("send", new SipSendCommand(sipUA));
   processor.registerCommand("lsend", new SipLSendCommand());
   processor.registerCommand("get", new HttpGetCommand());
   processor.registerCommand("respond", new RespondCommand(msgProc));
   processor.registerCommand("rt", new RespondTemplate(msgProc));
   processor.registerCommand("rrespond", new ResendResponse(msgProc));
   processor.registerCommand("log", new SipLogCommand(*sipUA));
   processor.registerCommand("auth", new AuthCommand(lineMgr));
   processor.registerCommand("sleep", new SleepCommand());
   processor.registerCommand("quit", new ExitCommand());
   processor.registerCommand("exit", new ExitCommand());

   //Initialization
   UtlBoolean doPrompt = isatty(STDIN_FILENO);

   if ( doPrompt )
   {
      printf("Enter command or help/? for help\n");
      printf("SIPdriver: ");
   }

   for ( commandStatus = CommandProcessor::COMMAND_SUCCESS;
         (   commandStatus < CommandProcessor::COMMAND_FAILED_EXIT
             && commandStatus != CommandProcessor::COMMAND_SUCCESS_EXIT
             && (commandLine = fgets(buffer,1024,stdin))
            );
      )
   {
      //printf("GOT command line:\"%s\"\n", commandLine);
      commandStatus = processor.executeCommand(commandLine);
      //printf("command status: %d exit status: %d\n", commandStatus,
      //CommandProcessor::COMMAND_SUCCESS_EXIT);
      if ( doPrompt )
      {
         printf("SIPdriver: ");
      }
   }

   delete msgProc;
   delete sipUA;

   return CommandProcessor::COMMAND_SUCCESS_EXIT != commandStatus;
}
Ejemplo n.º 21
0
   void testApplyUpdates()
      {
         // Test that applying updates detects out-of-order situations correctly.

         OsConfigDb configuration;
         // Must declare an XMLRPC port to activate peering.
         configuration.set("SIP_REGISTRAR_XMLRPC_PORT", "DEFAULT");
         // Configure self to be R0 and R1 and R2 to be peers.
         configuration.set("SIP_REGISTRAR_NAME", "R0");
         configuration.set("SIP_REGISTRAR_SYNC_WITH", "R1, R2");

         SipRegistrar registrar(&configuration);

         // Create and start the persist thread, because applying updates
         // will try to trigger the persist thread.
         registrar.createAndStartPersist();

         // Get the updates to apply.

         unsigned long timeNow = OsDateTime::getSecsSinceEpoch();

         // update1 - one update with update number 11 that is in-order
         UtlSList update1;
         readUpdateList(TEST_DATA_DIR "/regdbdata/update1.xml", update1, timeNow);
         //dumpList(update1);

         // update2 - one update with update number 12 that is out-of-order
         UtlSList update2;
         readUpdateList(TEST_DATA_DIR "/regdbdata/update2.xml", update2, timeNow);
         //dumpList(update2);

         // update3 - two updates with update number 13 that are in-order
         UtlSList update3;
         readUpdateList(TEST_DATA_DIR "/regdbdata/update3.xml", update3, timeNow);
         //dumpList(update3);

         // update4 - two updates with update number 14 with the first out-of-order
         UtlSList update4;
         readUpdateList(TEST_DATA_DIR "/regdbdata/update4.xml", update4, timeNow);
         //dumpList(update4);

         // update5 - two updates with update number 15 with the second out-of-order
         UtlSList update5;
         readUpdateList(TEST_DATA_DIR "/regdbdata/update5.xml", update5, timeNow);
         //dumpList(update5);

         // update6 - two updates with update number 16 which would trigger
         // XECS-371, viz., they have the same Call-Id, CSeq, and AOR.
         UtlSList update6;
         readUpdateList(TEST_DATA_DIR "/regdbdata/update6.xml", update6, timeNow);
         //dumpList(update6);

         // Run the tests.

         UtlString err;

         CPPUNIT_ASSERT_EQUAL((Int64) 11,
                              registrar.getRegistrarServer().
                              applyUpdatesToDirectory(update1, &err));
         CPPUNIT_ASSERT_EQUAL((Int64) (-1),
                              registrar.getRegistrarServer().
                              applyUpdatesToDirectory(update2, &err));
         CPPUNIT_ASSERT_EQUAL((Int64) 13,
                              registrar.getRegistrarServer().
                              applyUpdatesToDirectory(update3, &err));
         CPPUNIT_ASSERT_EQUAL((Int64) (-1),
                              registrar.getRegistrarServer().
                              applyUpdatesToDirectory(update4, &err));
         CPPUNIT_ASSERT_EQUAL((Int64) (-1),
                              registrar.getRegistrarServer().
                              applyUpdatesToDirectory(update5, &err));
         CPPUNIT_ASSERT_EQUAL((Int64) 16,
                              registrar.getRegistrarServer().
                              applyUpdatesToDirectory(update6, &err));
      }
Ejemplo n.º 22
0
 void testAccessors()
 {
     OsConfigDb *pDb = new OsConfigDb();
                                                                             
     // the get() method is tested by testManipulators()
                                                                             
     // test the getNext() method
     //
     // We put the following block in its own scope so that the UtlString
     // references (stored in "name" and "value") are released as a side effect
     // of going out of scope.  Otherwise, it will look like a memory leak.
     {
         UtlString  name;
         UtlString  value;
                                                                             
         pDb->set("Key3", "Value3");   // add several entries (not in
         pDb->set("Key2", "Value2");   //  alphabetical or reverse alphabetical
         pDb->set("Key4", "Value4");   //  order
         pDb->set("Key1", "Value1");
         CPPUNIT_ASSERT_MESSAGE("verify that the database is not empty",
                                !pDb->isEmpty());
         CPPUNIT_ASSERT_MESSAGE("has four entries", pDb->numEntries()==4);
                                                                             
         OsStatus res = pDb->getNext("", name, value);      // call getNext("", ...)
         CPPUNIT_ASSERT_MESSAGE("verify that Key1/Value1", 
             res == OS_SUCCESS &&
             name.compareTo("Key1") == 0 &&     //  is returned
             value.compareTo("Value1") == 0);
                                                                             
         res = pDb->getNext("Key1", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key1\", ...)",
             res == OS_SUCCESS &&               //  verify that Key2/Value2
             name.compareTo("Key2") == 0 &&     //  is returned
             value.compareTo("Value2") == 0);
                                                                             
         res = pDb->getNext("Key2", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key2\", ...)", 
             res == OS_SUCCESS &&               //  verify that Key3/Value3
             name.compareTo("Key3") == 0 &&     //  is returned
             value.compareTo("Value3") == 0);
                                                                             
         res = pDb->getNext("Key3", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key3\", ...)", 
             res == OS_SUCCESS &&
             name.compareTo("Key4") == 0 &&
             value.compareTo("Value4") == 0);
     
         res = pDb->getNext("Key4", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key4\", ...)", 
              res == OS_NO_MORE_DATA &&
              name.compareTo("") == 0 &&
              value.compareTo("") == 0);
                                                                             
         res = pDb->getNext("XXX", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext with a key not in the database and verify",
             res == OS_NOT_FOUND &&         
             name.compareTo("") == 0 &&      //  that empty strings are
            value.compareTo("") == 0);       //  returned for the next name
                                             //  and value pair.
                                                                             
         delete pDb;                               // delete the database
         name.remove(0);
         value.remove(0);
     }
 }