// // The main entry point to sipXrls. // int main(int argc, char* argv[]) { // Configuration Database (used for OsSysLog) OsConfigDb configDb; UtlString argString; for (int argIndex = 1; argIndex < argc; argIndex++) { osPrintf("arg[%d]: %s\n", argIndex, argv[argIndex]); argString = argv[argIndex]; NameValueTokenizer::frontBackTrim(&argString, "\t "); if (argString.compareTo("-v") == 0) { osPrintf("Version: %s (%s)\n", VERSION, PACKAGE_REVISION); return 1; } else { osPrintf("usage: %s [-v]\nwhere:\n -v provides the software version\n", argv[0]); return 1; } } // Load configuration file. OsPath workingDirectory; if (OsFileSystem::exists(CONFIG_ETC_DIR)) { workingDirectory = CONFIG_ETC_DIR; OsPath path(workingDirectory); path.getNativePath(workingDirectory); } else { OsPath path; OsFileSystem::getWorkingDirectory(path); path.getNativePath(workingDirectory); } UtlString fileName = workingDirectory + OsPathBase::separator + CONFIG_SETTINGS_FILE; if (configDb.loadFromFile(fileName) != OS_SUCCESS) { fprintf(stderr, "Failed to load config DB from file '%s'", fileName.data()); exit(1); } // Initialize log file initSysLog(&configDb); // Read the user agent parameters from the config file. int udpPort; if (configDb.get(CONFIG_SETTING_UDP_PORT, udpPort) != OS_SUCCESS) { udpPort = RLS_DEFAULT_UDP_PORT; } int tcpPort; if (configDb.get(CONFIG_SETTING_TCP_PORT, tcpPort) != OS_SUCCESS) { tcpPort = RLS_DEFAULT_TCP_PORT; } UtlString bindIp; if (configDb.get(CONFIG_SETTING_BIND_IP, bindIp) != OS_SUCCESS || !OsSocket::isIp4Address(bindIp)) bindIp = RLS_DEFAULT_BIND_IP; UtlString resourceListFile; if ((configDb.get(CONFIG_SETTING_RLS_FILE, resourceListFile) != OS_SUCCESS) || resourceListFile.isNull()) { Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT, "Resource list file name is not configured"); return 1; } UtlString domainName; if ((configDb.get(CONFIG_SETTING_DOMAIN_NAME, domainName) != OS_SUCCESS) || domainName.isNull()) { Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT, "Resource domain name is not configured"); return 1; } UtlString realm; if ((configDb.get(CONFIG_SETTING_AUTHENTICATE_REALM, realm) != OS_SUCCESS) || realm.isNull()) { Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT, "Resource realm is not configured"); return 1; } int resubscribeInterval; if (configDb.get(CONFIG_SETTING_RESUBSCRIBE_INTERVAL, resubscribeInterval) != OS_SUCCESS) { resubscribeInterval = RLS_DEFAULT_RESUBSCRIBE_INTERVAL; } int minResubscribeInterval; if (configDb.get(CONFIG_SETTING_MIN_RESUBSCRIBE_INTERVAL, minResubscribeInterval) != OS_SUCCESS) { minResubscribeInterval = RLS_DEFAULT_MIN_RESUBSCRIBE_INTERVAL; } int serverMinExpiration; if (configDb.get(CONFIG_SETTING_SERVER_MIN_EXPIRATION, serverMinExpiration) != OS_SUCCESS) { serverMinExpiration = RLS_DEFAULT_SERVER_MIN_EXPIRATION; } int serverDefaultExpiration; if (configDb.get(CONFIG_SETTING_SERVER_DEFAULT_EXPIRATION, serverDefaultExpiration) != OS_SUCCESS) { serverDefaultExpiration = RLS_DEFAULT_SERVER_DEFAULT_EXPIRATION; } int serverMaxExpiration; if (configDb.get(CONFIG_SETTING_SERVER_MAX_EXPIRATION, serverMaxExpiration) != OS_SUCCESS) { serverMaxExpiration = RLS_DEFAULT_SERVER_MAX_EXPIRATION; } // add the ~~sipXrls credentials so that sipXrls can respond to challenges SipLineMgr* lineMgr = addCredentials(domainName, realm); if(NULL == lineMgr) { return 1; } if (!gShutdownFlag) { // Initialize the ResourceListServer. ResourceListServer rls(domainName, realm, lineMgr, DIALOG_EVENT_TYPE, DIALOG_EVENT_CONTENT_TYPE, tcpPort, udpPort, PORT_NONE, bindIp, &resourceListFile, resubscribeInterval, minResubscribeInterval, RLS_PUBLISH_DELAY, 20, 20, 20, 20, serverMinExpiration, serverDefaultExpiration, serverMaxExpiration); rls.start(); // Loop forever until signaled to shut down while (!Os::UnixSignals::instance().isTerminateSignalReceived() && !gShutdownFlag) { OsTask::delay(2000); // See if the list configuration file has changed. rls.getResourceListFileReader().refresh(); } // Shut down the server. rls.shutdown(); } lineMgr->requestShutdown(); while (!lineMgr->isShutDown()) { OsTask::delay(100); } // Delete the LineMgr Object delete lineMgr; // Flush the log file Os::Logger::instance().flush(); // Say goodnight Gracie... return 0; }
void testRefreshMgrUATeardown() { for (int i=0; i<NUM_OF_RUNS; ++i) { SipLineMgr* lineMgr = new SipLineMgr(); SipRefreshMgr* refreshMgr = new SipRefreshMgr(); lineMgr->startLineMgr(); lineMgr->initializeRefreshMgr( refreshMgr ); SipUserAgent* sipUA = new SipUserAgent( 5090 ,5090 ,5091 ,NULL // default publicAddress ,NULL // default defaultUser ,"127.0.0.1" // 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->start(); refreshMgr->init(sipUA); CallManager *pCallManager = new CallManager(FALSE, NULL, //LineMgr TRUE, // early media in 180 ringing NULL, // CodecFactory 9000, // rtp start 9002, // rtp end "sip:[email protected]", "sip:[email protected]", sipUA, //SipUserAgent 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, //inviteExpireSeconds QOS_LAYER3_LOW_DELAY_IP_TOS, // expeditedIpTos 10, //maxCalls sipXmediaFactoryFactory(NULL)); //pMediaFactory #if 0 printf("Starting CallManager\n"); #endif pCallManager->start(); lineMgr->requestShutdown(); refreshMgr->requestShutdown(); sipUA->shutdown(TRUE); pCallManager->requestShutdown(); #if 0 printf("Deleting CallManager\n"); #endif delete pCallManager; delete refreshMgr; delete lineMgr; } for (int i=0; i<NUM_OF_RUNS; ++i) { sipxDestroyMediaFactoryFactory() ; } }
void testShutdownNonBlocking() { int myPID = OsProcess::getCurrentPID(); int startingThreads; // Stop TimerTask and NatAgentTask before counting threads. // Some tests do not bother stopping them, so they may come started. OsTimerTask::destroyTimerTask(); OsNatAgentTask::releaseInstance(); // Count number of threads now. startingThreads = getNumThreads(myPID); // Simple invite message from siptest/src/siptest/invite.txt const char* SimpleMessage = "INVITE sip:[email protected] SIP/2.0\r\n" "Route: <sip:[email protected]:5064;lr>\r\n" "From: <sip:[email protected];user=phone>;tag=bbb\r\n" "To: <sip:[email protected]:3000;user=phone>\r\n" "Call-Id: 8\r\n" "Cseq: 1 INVITE\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg( SimpleMessage, strlen( SimpleMessage ) ); for(int i = 0; i < SHUTDOWN_TEST_ITERATIONS; ++i) { // Limit life time of lineMgr and refreshMgr. They should be freed // before releasing OsNatAgentTask instance, or we will crash. { SipLineMgr lineMgr; SipRefreshMgr refreshMgr; lineMgr.StartLineMgr(); lineMgr.initializeRefreshMgr( &refreshMgr ); SipUserAgent sipUA( 5090 ,5090 ,5091 ,NULL // default publicAddress ,NULL // default defaultUser ,"127.0.0.1" // default defaultSipAddress ,NULL // default sipProxyServers ,NULL // default sipDirectoryServers ,NULL // default sipRegistryServers ,NULL // default authenticationScheme ,NULL // default authenicateRealm ,NULL // default authenticateDb ,NULL // default authorizeUserIds ,NULL // default authorizePasswords ,&lineMgr ); sipUA.start(); refreshMgr.init(&sipUA); sipUA.send(testMsg); // Wait long enough for some stack timeouts/retransmits to occur OsTask::delay(10000); // 10 seconds sipUA.shutdown(FALSE); lineMgr.requestShutdown(); refreshMgr.requestShutdown(); while(!sipUA.isShutdownDone()) { ; } CPPUNIT_ASSERT(sipUA.isShutdownDone()); } // Stop TimerTask and NatAgentTask again before counting threads. // They were started while testing. OsTimerTask::destroyTimerTask(); OsNatAgentTask::releaseInstance(); // Test to see that all the threads created by the above operations // get properly shut down. // Since the threads do not shut down synchronously with the above // calls, we have to wait before we know they will be cleared. OsTask::delay(1000); // 1 second int numThreads = getNumThreads(myPID); CPPUNIT_ASSERT_EQUAL(startingThreads,numThreads); } };
void testShutdownBlocking() { pid_t myPID = OsProcess::getCurrentPID(); int startingThreads = getNumThreads(myPID); // Simple invite message from siptest/src/siptest/invite.txt const char* SimpleMessage = "INVITE sip:[email protected] SIP/2.0\r\n" "Route: <sip:[email protected]:5064;lr>\r\n" "From: <sip:[email protected];user=phone>;tag=bbb\r\n" "To: <sip:[email protected]:3000;user=phone>\r\n" "Call-Id: 8\r\n" "Cseq: 1 INVITE\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg( SimpleMessage, strlen( SimpleMessage ) ); for(int i = 0; i < SHUTDOWN_TEST_ITERATIONS; ++i) { { SipLineMgr lineMgr; SipRefreshMgr refreshMgr; lineMgr.StartLineMgr(); lineMgr.initializeRefreshMgr( &refreshMgr ); SipUserAgent sipUA( 5090 ,5090 ,5091 ,NULL // default publicAddress ,NULL // default defaultUser ,"127.0.0.1" // default defaultSipAddress ,NULL // default sipProxyServers ,NULL // default sipDirectoryServers ,NULL // default sipRegistryServers ,NULL // default authenticationScheme ,NULL // default authenicateRealm ,NULL // default authenticateDb ,NULL // default authorizeUserIds ,NULL // default authorizePasswords ,&lineMgr ); sipUA.start(); refreshMgr.init(&sipUA); sipUA.send(testMsg); // Wait long enough for some stack timeouts/retansmits to occur OsTask::delay(10000); // 10 seconds // Shut down the tasks in reverse order. refreshMgr.requestShutdown(); sipUA.shutdown(TRUE); lineMgr.requestShutdown(); CPPUNIT_ASSERT(sipUA.isShutdownDone()); OsTimerTask::destroyTimerTask(); OsStunAgentTask::releaseInstance(); } // Test to see that all the threads created by the above operations // get properly shut down. int numThreads = getNumThreads(myPID); OsSysLog::add(FAC_SIP, PRI_NOTICE, "SipUserAgentTest::testShutdownBlocking " "numThreads=%d startingThreads=%d", numThreads, startingThreads); KNOWN_BUG("XECS-48", "Some threads are not cleaned up?"); CPPUNIT_ASSERT(numThreads <= startingThreads); } };