Esempio n. 1
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);
}
Esempio n. 2
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);
}
Esempio n. 3
0
OsStatus ConfigRPC::store(OsConfigDb& dataset)
{
   OsStatus status = dataset.storeToFile(mPath);
   if ( OS_SUCCESS != status )
   {
      Os::Logger::instance().log(FAC_KERNEL, PRI_ERR,
                    "ConfigRPC failed to store '%s' to '%s'",
                    data(), mPath.data()
                    );
   }
   return status;
}
Esempio n. 4
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;
}
Esempio n. 5
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);
    }