void sipXtapiTestSuite::testLineEvents() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestLineEvents (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst, lineCallback, NULL), SIPX_RESULT_SUCCESS); // TODO - we need to figure out how to better test registrar interaction. // It might require creating a test registrar that responds to REGISTER messages. SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:[email protected]", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_REGISTER_FAILED_COULD_NOT_CONNECT); OsTask::delay(500); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks(); }
void sipXtapiTestSuite::testReRegistrationFailure() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestReRegistrationFailure (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxConfigSetOutboundProxy(g_hInst4, "127.0.0.1:5070"), SIPX_RESULT_SUCCESS); SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:[email protected]:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxConfigSetRegisterExpiration(g_hInst4, 10), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineAddCredential(hLine, "mike", "1234", "TestRegistrar"), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; OsTask::delay(9000); g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_REGISTER_FAILED_TIMEOUT); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); TestRegistrar* pTestRegistrar = new TestRegistrar(); pTestRegistrar->init(); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); OsTask::delay(8000); pTestRegistrar->pause(true); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_REGISTER_FAILED_TIMEOUT); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_REGISTER_FAILED_TIMEOUT); OsTask::delay(20000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; pTestRegistrar->pause(false); sipxLineRegister(hLine, false); g_lineRecorder.addCompareEvent(hLine, LINESTATE_UNREGISTERING, LINESTATE_UNREGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_UNREGISTERED, LINESTATE_UNREGISTERED_NORMAL); CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; OsTask::delay(3000); CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); delete pTestRegistrar; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ; }
void sipXtapiTestSuite::testBadRegistrarRegistration() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { TestRegistrar testRegistrar; testRegistrar.init(); printf("\ntestBadRegistrarRegistration (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxConfigSetOutboundProxy(g_hInst4, "127.0.0.1:5070"), SIPX_RESULT_SUCCESS); // receiving a 480 response SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:[email protected]:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_CAUSE_UNKNOWN); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; g_lineRecorder.clear() ; // receiving a 503 response CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:[email protected]:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_CAUSE_UNKNOWN); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; g_lineRecorder.clear() ; // receiving a 600 response CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:[email protected]:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_CAUSE_UNKNOWN); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); } OsTask::delay(TEST_DELAY) ; checkForLeaks() ; }
void sipXtapiTestSuite::testReRegistration() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { TestRegistrar testRegistrar; testRegistrar.init(); printf("\ntestReRegistration (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxConfigSetOutboundProxy(g_hInst4, "127.0.0.1:5070"), SIPX_RESULT_SUCCESS); SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:[email protected]:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxConfigSetRegisterExpiration(g_hInst4, 10), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineAddCredential(hLine, "mike", "1234", "TestRegistrar"), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); printf("\nWaiting for 12 seconds! (for the re-registration test)"); OsTask::delay(12000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; OsTask::delay(1000); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); } OsTask::delay(TEST_DELAY) ; checkForLeaks() ; }
int local_main(int argc, char* argv[]) { bool bError = true ; int iDuration, iSipPort, iRtpPort ; char* szIdentity ; char* szUsername ; char* szPassword ; char* szRealm ; char* szStunServer ; char* szProxy ; SIPX_INST hInst ; SIPX_LINE hLine ; // Parse Arguments if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &g_szPlayTones, &g_szFile, &szIdentity, &szUsername, &szPassword, &szRealm, &szStunServer, &szProxy) && (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort))) { // Initialize sipX TAPI-like API sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ; sipxConfigSetLogFile("ReceiveCall.log"); if (sipxInitialize(&hInst, iSipPort, iSipPort, 5061, iRtpPort, 16, szIdentity) == SIPX_RESULT_SUCCESS) { g_hInst1 = hInst; if (szProxy) { sipxConfigSetOutboundProxy(hInst, szProxy); } sipxConfigEnableRport(hInst, true) ; if (szStunServer) { sipxConfigEnableStun(hInst, szStunServer, DEFAULT_STUN_PORT, 28) ; } sipxEventListenerAdd(hInst, EventCallBack, NULL) ; if (sipxConfigSelectAudioCodecByName(g_hInst1, "PCMU PCMA") == SIPX_RESULT_FAILURE) { printf("!! Setting audio codecs to PCMU PCMA failed !!\n"); }; #if defined(_WIN32) && defined(VIDEO) if (bVideo) { gPreviewDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gPreviewDisplay.handle = ghPreview; sipxConfigSetVideoPreviewDisplay(hInst, &gPreviewDisplay); } #endif // get first contact size_t numAddresses = 0; SIPX_CONTACT_ADDRESS address; sipxConfigGetLocalContacts(hInst, &address, 1, &numAddresses); hLine = lineInit(hInst, szIdentity, szUsername, szPassword, szRealm) ; dumpLocalContacts(hInst) ; while (true) { SLEEP(1000) ; } } else { printf("unable to initialize sipXtapi layer\n") ; } } else { usage(argv[0]) ; } #if defined(_WIN32) && defined(VIDEO) PostMessage(hMain, WM_CLOSE, 0, 0L); #endif return (int) bError ; }
int main(int argc, char* argv[]) { bool bError = true ; int iSipPort, iRtpPort ; bool bLoopback ; char* szIdentity ; char* szUsername ; char* szPassword ; char* szRealm ; char* szStunServer ; char* szProxy ; bool bDialogEvents ; // The default run time is 2^31-1 seconds, which is over 68 years. long int runTime = LONG_MAX; SIPX_INST hInst ; SIPX_LINE hLine ; // Support for the dialog event notifier. // Component for holding the subscription data SipSubscriptionMgr* pSubscriptionMgr; // Component for granting the subscription rights SipSubscribeServerEventHandler* pPolicyHolder; // Component for publishing the event contents SipPublishContentMgr* pPublisher; SipSubscribeServer* pSubscribeServer; // The dialog event publisher DialogEventPublisher* pDialogEvents; // Parse Arguments if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &g_szPlayTones, &g_szFile, &bLoopback, &szIdentity, &szUsername, &szPassword, &szRealm, &szStunServer, &szProxy, &bDialogEvents, &g_callAnswerDelay, &g_timestamp, &runTime) && (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort))) { if (bLoopback) { initLoopback() ; } // initialize sipx TAPI-like API sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ; sipxConfigSetLogFile("ReceiveCall.log"); if (sipxInitialize(&hInst, iSipPort, iSipPort, 5061, iRtpPort, 16, szIdentity) == SIPX_RESULT_SUCCESS) { // Start dialog event notifier if requested. if (bDialogEvents) { // Get pointer to the call manager. CallManager* pCallManager = ((SIPX_INSTANCE_DATA*) hInst)->pCallManager; SipUserAgent* pUserAgent = ((SIPX_INSTANCE_DATA*) hInst)->pSipUserAgent; // Start the SIP Subscribe Server pSubscriptionMgr = new SipSubscriptionMgr(); pPolicyHolder = new SipSubscribeServerEventHandler; pPublisher = new SipPublishContentMgr; pSubscribeServer = new SipSubscribeServer(*pUserAgent, *pPublisher, *pSubscriptionMgr, *pPolicyHolder); pSubscribeServer->enableEventType(DIALOG_EVENT_TYPE, NULL, NULL, NULL, NULL, SipSubscribeServer::standardVersionCallback); pSubscribeServer->start(); // Create the dialog event publisher pDialogEvents = new DialogEventPublisher(pCallManager, pPublisher); pCallManager->addTaoListener(pDialogEvents); pDialogEvents->start(); } if (szProxy) { sipxConfigSetOutboundProxy(hInst, szProxy); } sipxConfigEnableRport(hInst, true) ; if (szStunServer) { sipxConfigEnableStun(hInst, szStunServer, 28) ; } sipxEventListenerAdd(hInst, EventCallBack, NULL) ; hLine = lineInit(hInst, szIdentity, szUsername, szPassword, szRealm) ; dumpLocalContacts(hInst) ; // Run as long as requested. for (long int i = 0; i < runTime; i++) { SLEEP(1000) ; } lineShutdown(hInst, hLine); // Wait a bit, so that we can re-send the REGISTER if it needs // authorization. SLEEP(5000); } else { printf("unable to initialize sipXtapi layer\n") ; } } else { usage(argv[0]) ; } return (int) bError ; }
OsStatus ACDCallManager::start(void) { sipxEventListenerAdd(mAcdCallManagerHandle, ACDCallManager_EventCallback, static_cast<void*>(this)); return OS_SUCCESS; }
int local_main(int argc, char* argv[]) { bool bError = false ; int iDuration, iSipPort, iRtpPort, iRepeatCount ; char* szPlayTones; char* szSipUrl; char* szFile; char* szFileBuffer; char* szUsername; char* szPassword; char* szRealm; char* szFromIdentity; char* szStunServer; char* szProxy; char* szBindAddr; char* szOutDevice; char* szInDevice; char* szCodec; bool bUseRport; bool bCList; bool bAEC; bool bAGC; bool bDenoise; if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR ) { printf("Couldn't install signal handler for SIGINT\n"); exit(1); } if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR ) { printf("Couldn't install signal handler for SIGTERM\n"); exit(1); } // Parse Arguments if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &szPlayTones, &szFile, &szFileBuffer, &szSipUrl, &bUseRport, &szUsername, &szPassword, &szRealm, &szFromIdentity, &szStunServer, &szProxy, &szBindAddr, &iRepeatCount, &szInDevice, &szOutDevice, &szCodec, &bCList, &bAEC, &bAGC, &bDenoise, &bUseCustomTransportReliable, &bUseCustomTransportUnreliable) && (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort))) { // initialize sipx TAPI-like API sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ; sipxConfigSetLogFile("PlaceCall.log"); int mediaEngineSampleRate = 16000; sipxInitialize(&g_hInst, iSipPort, iSipPort, -1, iRtpPort, DEFAULT_CONNECTIONS, DEFAULT_IDENTITY, szBindAddr, false, // use sequential RTP/RTCP ports NULL, // cert. nickname NULL, // cert. password NULL, // DB location true, // Enable local audio mediaEngineSampleRate, 48000); // Audio device sample rate sipxConfigEnableRport(g_hInst, bUseRport) ; dumpInputOutputDevices() ; sipxEventListenerAdd(g_hInst, EventCallBack, NULL) ; // Enable/disable AEC. if (bAEC) sipxAudioSetAECMode(g_hInst, SIPX_AEC_CANCEL_AUTO) ; else sipxAudioSetAECMode(g_hInst, SIPX_AEC_DISABLED) ; // Enable/disable AGC sipxAudioSetAGCMode(g_hInst, bAGC); if (bDenoise) sipxAudioSetNoiseReductionMode(g_hInst, SIPX_NOISE_REDUCTION_HIGH); else sipxAudioSetNoiseReductionMode(g_hInst, SIPX_NOISE_REDUCTION_DISABLED); if (bCList) { int numAudioCodecs; int numVideoCodecs; int index; SIPX_AUDIO_CODEC audioCodec; SIPX_VIDEO_CODEC videoCodec; printf("Audio codecs:\n"); if (sipxConfigGetNumAudioCodecs(g_hInst, &numAudioCodecs) == SIPX_RESULT_SUCCESS) { for (index=0; index<numAudioCodecs; ++index) { if (sipxConfigGetAudioCodec(g_hInst, index, &audioCodec) == SIPX_RESULT_SUCCESS) { printf(" audio %02d : %s\n", index, audioCodec.cName); } else { printf("Error in retrieving audio codec #%d\n", index); } } } else { printf("Error in retrieving number of audio codecs\n"); } #ifdef VIDEO printf("Video codecs:\n"); if (sipxConfigGetNumVideoCodecs(g_hInst, &numVideoCodecs) == SIPX_RESULT_SUCCESS) { for (index=0; index<numVideoCodecs; ++index) { if (sipxConfigGetVideoCodec(g_hInst, index, &videoCodec) == SIPX_RESULT_SUCCESS) { printf(" video %02d : %s\n", index, videoCodec.cName); } else { printf("Error in retrieving video codec #%d\n"); } } } else { printf("Error in retrieving number of video codecs\n"); } #endif // VIDEO sipxUnInitialize(g_hInst, true); exit(0); } if (szProxy) { sipxConfigSetOutboundProxy(g_hInst, szProxy); } if (szStunServer) { sipxConfigEnableStun(g_hInst, szStunServer, DEFAULT_STUN_PORT, 28) ; } if (szOutDevice) { if (sipxAudioSetCallOutputDevice(g_hInst, szOutDevice) != SIPX_RESULT_SUCCESS) { printf("!! Setting output device %s failed !!\n", szOutDevice); } } if (szInDevice) { if (sipxAudioSetCallInputDevice(g_hInst, szInDevice) != SIPX_RESULT_SUCCESS) { printf("!! Setting input device %s failed !!\n", szOutDevice); } } if (szCodec) { if (sipxConfigSetAudioCodecByName(g_hInst, szCodec) == SIPX_RESULT_FAILURE) { printf("!! Setting audio codec to %s failed !!\n", szCodec); }; } // Wait for a STUN response (should actually look for the STUN event status // (config event) ; SLEEP(1500) ; for (int i=0; i<iRepeatCount; i++) { ClearSipXEvents() ; printf("<-> Attempt %d of %d\n", i+1, iRepeatCount) ; // Place a call to designed URL if (placeCall(szSipUrl, szFromIdentity, szUsername, szPassword, szRealm)) { bError = false ; // Play tones if provided if (szPlayTones) { if (!playTones(szPlayTones)) { printf("%s: Failed to play tones: %s\n", argv[0], szPlayTones) ; } else { bError = true ; } } // Play file if provided if (szFile) { if (!playFile(szFile)) { printf("%s: Failed to play file: %s\n", argv[0], szFile) ; } else { bError = true ; } } // Play file from buffer if provided if (szFileBuffer) { if (!playFileBuffer(szFileBuffer)) { printf("%s: Failed to play file from buffer: %s\n", argv[0], szFileBuffer) ; } else { bError = true ; } } // Leave the call up for specified time period (or wait for hangup) WaitForSipXEvent(CALLSTATE_DISCONNECTED, iDuration) ; // Shutdown / cleanup if (!shutdownCall()) { printf("%s: Failed to shutdown call\n", argv[0]) ; bError = true ; } } else { printf("%s: Unable to complete call\n", argv[0]) ; shutdownCall() ; bError = true ; } if (bError) { break ; } } sipxEventListenerRemove(g_hInst, EventCallBack, NULL) ; sipxUnInitialize(g_hInst, true); } else { usage(argv[0]) ; } #if defined(_WIN32) && defined(VIDEO) PostMessage(hMain, WM_CLOSE, 0, 0L); #endif return (int) bError ; }
void sipXtapiTestSuite::testLineAliases() { bool bRC ; EventValidator validatorCalling("testLineAliases.calling") ; EventValidator validatorCalled("testLineAliases.called") ; for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestLineAliases (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); SIPX_CALL hCall ; SIPX_LINE hLine ; SIPX_LINE hReceivingLine; SIPX_RESULT rc ; validatorCalling.reset() ; validatorCalled.reset() ; validatorCalling.ignoreEventCategory(EVENT_CATEGORY_MEDIA); validatorCalled.ignoreEventCategory(EVENT_CATEGORY_MEDIA); // Setup Auto-answer call back resetAutoAnswerCallback() ; sipxEventListenerAdd(g_hInst2, AutoAnswerCallback, NULL) ; sipxEventListenerAdd(g_hInst2, UniversalEventValidatorCallback, &validatorCalled) ; sipxEventListenerAdd(g_hInst, UniversalEventValidatorCallback, &validatorCalling) ; sipxLineAdd(g_hInst2, "sip:[email protected]:9100", &hReceivingLine, CONTACT_AUTO); bRC = validatorCalled.waitForLineEvent(hReceivingLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; rc = sipxLineAddAlias(hReceivingLine, "sip:[email protected]:9100") ; CPPUNIT_ASSERT(rc == SIPX_RESULT_SUCCESS) ; createCall(&hLine, &hCall) ; bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; sipxCallConnect(hCall, "sip:[email protected]:9100") ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; int connectionId = -1; CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT(connectionId != -1) ; SIPX_CALL hDestroyedCall = hCall ; destroyCall(hCall) ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; validatorCalling.reset() ; validatorCalled.reset() ; validatorCalling.ignoreEventCategory(EVENT_CATEGORY_MEDIA); validatorCalled.ignoreEventCategory(EVENT_CATEGORY_MEDIA); resetAutoAnswerCallback() ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS); createCall(&hLine, &hCall) ; bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; sipxCallConnect(hCall, "sip:[email protected]:9100") ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; connectionId = -1; CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT(connectionId != -1) ; hDestroyedCall = hCall ; destroyCall(hCall) ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, UniversalEventValidatorCallback, &validatorCalling), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, AutoAnswerCallback, NULL), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, UniversalEventValidatorCallback, &validatorCalled), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hReceivingLine), SIPX_RESULT_SUCCESS); } OsTask::delay(TEST_DELAY) ; checkForLeaks(); }
void sipXtapiTestSuite::testLines() { OsSysLog::initialize(0, "sipxTapi_testLines"); OsSysLog::setLoggingPriority(PRI_DEBUG); OsSysLog::setOutputFile(0, "/sdcard/sipxtapi.log"); for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_CALL hCall ; SIPX_LINE hLineGeorge ; SIPX_LINE hLineJane ; SIPX_LINE hLineBob ; SIPX_LINE hLineJill ; printf("\ntestLines (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, URL_GEORGE_AT_JUNGLE, &hLineGeorge), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, URL_JANE_AT_JUNGLE, &hLineJane), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, URL_BOB_AT_LOCALHOST, &hLineBob), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, URL_JILL_AT_LOCALHOST, &hLineJill), SIPX_RESULT_SUCCESS) ; /** * Make call as George to Jill */ // Setup Auto-answer call back sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST) ; printf("createCall line: %d %s\n", hLineGeorge, URL_GEORGE_AT_JUNGLE); createCall(hLineGeorge, &hCall) ; sipxCallConnect(hCall, URL_JILL_AT_LOCALHOST) ; OsTask::delay(CALL_DELAY*2) ; destroyCall(hCall) ; OsTask::delay(CALL_DELAY*4) ; // Remove George's line g_lineRecorder2.clear() ; SIPX_RESULT rc = sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST); CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineGeorge), SIPX_RESULT_SUCCESS) ; OsTask::delay(CALL_DELAY*2); /** * Make call as Jane to Bob */ sipxEventListenerAdd(g_hInst, linetest_verify_lineurl, (void*)URL_JANE_AT_JUNGLE) ; sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_BOB_AT_LOCALHOST) ; printf("createCall line: %d %s\n", hLineJane, URL_JANE_AT_JUNGLE); createCall(hLineJane, &hCall) ; sipxCallConnect(hCall, URL_BOB_AT_LOCALHOST) ; OsTask::delay(CALL_DELAY*2) ; destroyCall(hCall) ; OsTask::delay(CALL_DELAY*4) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, linetest_verify_lineurl, (void*)URL_JANE_AT_JUNGLE), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_BOB_AT_LOCALHOST), SIPX_RESULT_SUCCESS) ; /** * Make call as Jane to BOGUS (line not defined) */ sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_EMPTY_STRING) ; createCall(hLineJane, &hCall) ; sipxCallConnect(hCall, URL_BOGUS_AT_LOCALHOST) ; OsTask::delay(22000) ; destroyCall(hCall) ; OsTask::delay(CALL_DELAY*4) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_EMPTY_STRING), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineJane), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineBob), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineJill), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks(); }
int local_main(int argc, char* argv[]) { bool bError = true ; int iDuration, iSipPort, iRtpPort ; char* szBindAddr; bool bLoopback ; char* szIdentity ; char* szUsername ; char* szPassword ; char* szRealm ; char* szStunServer ; char* szProxy ; SIPX_INST hInst ; SIPX_LINE hLine ; if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR ) { printf("Couldn't install signal handler for SIGINT\n"); exit(1); } if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR ) { printf("Couldn't install signal handler for SIGTERM\n"); exit(1); } // Parse Arguments if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &szBindAddr, &g_szPlayTones, &g_szFile, &bLoopback, &gbOneCallMode, &szIdentity, &szUsername, &szPassword, &szRealm, &szStunServer, &szProxy) && (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort))) { if (bLoopback) { initLoopback() ; } // Initialize sipX TAPI-like API sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ; sipxConfigSetLogFile("ReceiveCall.log"); if (sipxInitialize(&hInst, iSipPort, iSipPort, 5061, iRtpPort, 16, szIdentity, szBindAddr) == SIPX_RESULT_SUCCESS) { g_hInst = hInst; if (szProxy) { sipxConfigSetOutboundProxy(hInst, szProxy); } sipxConfigEnableRport(hInst, true) ; if (szStunServer) { sipxConfigEnableStun(hInst, szStunServer, DEFAULT_STUN_PORT, 28) ; } sipxEventListenerAdd(hInst, EventCallBack, NULL) ; #if defined(_WIN32) && defined(VIDEO) if (bVideo) { gPreviewDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gPreviewDisplay.handle = ghPreview; sipxConfigSetVideoPreviewDisplay(hInst, &gPreviewDisplay); } #endif // get first contact size_t numAddresses = 0; SIPX_CONTACT_ADDRESS address; sipxConfigGetLocalContacts(hInst, &address, 1, numAddresses); if (bUseCustomTransportReliable) { sipxConfigExternalTransportAdd(hInst, ghTransport, true, "tribble", address.cIpAddress, -1, tribbleProc, "tribble"); startTribbleListener(address.cIpAddress); } if (bUseCustomTransportUnreliable) { startFlibbleListener(address.cIpAddress); sipxConfigExternalTransportAdd(hInst, ghTransport, false, "flibble", address.cIpAddress, -1, flibbleProc, address.cIpAddress); gContactId = lookupContactId(address.cIpAddress, "flibble", ghTransport); } hLine = lineInit(hInst, szIdentity, szUsername, szPassword, szRealm) ; dumpLocalContacts(hInst) ; while (!gbShutdown) { SLEEP(200) ; } sipxUnInitialize(hInst, true); } else { printf("unable to initialize sipXtapi layer\n") ; } } else { usage(argv[0]) ; } #if defined(_WIN32) && defined(VIDEO) PostMessage(hMain, WM_CLOSE, 0, 0L); #endif return (int) bError ; }