Beispiel #1
0
void dumpLocalContacts(SIPX_INST hInst)
{
    SIPX_CONTACT_ADDRESS contacts[10] ;
    size_t nContacts;

    SIPX_RESULT status = sipxConfigGetLocalContacts(hInst, contacts, 10, &nContacts) ;
    if (status == SIPX_RESULT_SUCCESS)
    {
        for (size_t i = 0; i<nContacts; i++)
        {
            const char* szType = "UNKNOWN" ;
            switch (contacts[i].eContactType)
            {
                case CONTACT_LOCAL:
                    szType = "LOCAL" ;
                    break ;
                case CONTACT_NAT_MAPPED:
                    szType = "NAT_MAPPED" ;
                    break ;
                case CONTACT_RELAY:
                    szType = "RELAY" ;
                    break ;
            }
            printf("<-> Type %s, Interface: %s, Ip %s, Port %d\n",
                    szType, contacts[i].cInterface, contacts[i].cIpAddress,
                    contacts[i].iPort) ;
        }
    }
    else
    {
        printf("<-> Unable to query local contact addresses\n") ;
    }
}
Beispiel #2
0
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 ;
}
Beispiel #3
0
// 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 ;
}
Beispiel #4
0
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 ;
}