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 ; }
// Place a call to szSipUrl as szFromIdentity bool placeCall(char* szSipUrl, char* szFromIdentity, char* szUsername, char* szPassword, char *szRealm) { bool bRC = false ; if ((szFromIdentity == NULL) || strlen(szFromIdentity) == 0) { szFromIdentity = "\"PlaceCall Demo\" <sip:placecalldemo@localhost>" ; } printf("<-> Placing call to \"%s\" as \"%s\"\n", szSipUrl, szFromIdentity) ; printf("<-> Username: %s, passwd: %s, realm: %s (all required for auth)\n", szUsername, szPassword, szRealm) ; sipxLineAdd(g_hInst, szFromIdentity, &g_hLine) ; if (szUsername && szPassword && szRealm) { sipxLineAddCredential(g_hLine, szUsername, szPassword, szRealm) ; } #if defined(_WIN32) && defined(VIDEO) if (bVideo) { gPreviewDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gPreviewDisplay.handle = ghPreview; sipxConfigSetVideoPreviewDisplay(g_hInst, &gPreviewDisplay); } #endif sipxCallCreate(g_hInst, g_hLine, &g_hCall) ; dumpLocalContacts(g_hCall) ; // get first contact size_t numAddresses = 0; SIPX_CONTACT_ADDRESS address; sipxConfigGetLocalContacts(g_hInst, &address, 1, numAddresses); if (bUseCustomTransportReliable) { sipxConfigExternalTransportAdd(g_hInst, ghTransport, true, "tribble", address.cIpAddress, -1, tribbleProc, "tribble"); startTribbleListener(address.cIpAddress); } if (bUseCustomTransportUnreliable) { startFlibbleListener(address.cIpAddress); sipxConfigExternalTransportAdd(g_hInst, ghTransport, true, "flibble", address.cIpAddress, -1, flibbleProc, address.cIpAddress); gContactId = lookupContactId(address.cIpAddress, "flibble", ghTransport); } #if defined(_WIN32) && defined(VIDEO) if (bVideo) { gDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gDisplay.handle = ghVideo; sipxCallConnect(g_hCall, szSipUrl, gContactId, &gDisplay, NULL); } else #endif { sipxCallConnect(g_hCall, szSipUrl, gContactId); } bRC = WaitForSipXEvent(CALLSTATE_CONNECTED, 30) ; return bRC ; }
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 ; }
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 ; }