Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SessionControl.cpp : Implementation of CSessionControl
- #include "stdafx.h"
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- #ifndef _WIN32_WCE
- #include "MediaSession_win.h"
- #else
- #include "MediaSession_win.h"
- #endif
- #include <WinInet.h>
- #include "SessionControl.h"
- #include "registry.h"
- #ifdef _WIN32_WCE
- # include "PALthread.h"
- # include "Msgqueue.h"
- # include "pm.h"
- #endif
- #else
- #include "SessionControl_unix.h"
- #include "MFControl_unix.h"
- #endif
- #include "SessionAgent.h"
- #include "CallHistory.h"
- #include "Framework.h"
- #include "TextUtil.h"
- #include "CallLine.h"
- #include "CodecConfig.h"
- #ifndef NO_DATA_TRAVELER
- #include "DataTraveler.h"
- #endif
- #if (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- #include "WinRtInet.h"
- #else
- #include "PALinet.h"
- #endif
- #include "MediaSessionUtil.h"
- #include "SipAccount.h"
- #include "PALdebuglog.h"
- #include "PALsystime.h"
- #include "common.h"
- #include <jni.h>
- #include <android/log.h>
- #include <android/asset_manager.h>
- #include <android/asset_manager_jni.h>
- #include <openssl/ssl.h>
- #include <openssl/asn1.h>
- #include <openssl/bio.h>
- #include <openssl/x509.h>
- #include <openssl/x509_vfy.h>
- #include <openssl/pem.h>
- #include <openssl/x509v3.h>
- #include <openssl/err.h>
- #include <openssl/conf.h>
- #include <string.h>
- using std::string;
- #ifndef __unix__
- #include "EComUtil2.h"
- using namespace eyeball;
- #endif
- #if (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- #define ToInternalBstr
- #else
- #define ToInternalBstr ToBstr
- #endif
- using namespace MediaSessionUtil;
- #ifndef _WIN32_WCE
- #define FIREWALL_INFO_FILENAME PAL_FILE_IN_LOG_DIR("MediaSession.txt")
- #else
- #define FIREWALL_INFO_FILENAME "FirewallInfo.txt"
- #endif
- #define CALL_HISTORY_FILENAME "eyeball_call_history.log"
- #define CHECK_POINTER(X) \
- if (NULL == (X))\
- return ThrowError("ERROR: NULL pointer.");
- #define CHECK_MEDIAFRAMEWORK() \
- if (!m_pFramework->m_mediaFramework)\
- return ThrowError("ERROR: Media Framework control is not registered.");
- #define CHECK_SIP_ACCOUNT() \
- if (m_iSelectedAccount == -1)\
- return ThrowError("ERROR: No sip account is selected.");
- #if defined(__unix__)
- #define FIRE_EVENT(X, ...) if(m_CallbackHandler) { m_CallbackHandler->X(__VA_ARGS__); }
- #elif (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- #define FIRE_EVENT(X, ...) if(m_CallbackHandler) { m_CallbackHandler->FireEvent##X(__VA_ARGS__); }
- #else
- #define FIRE_EVENT(X, ...) { Fire_##X(__VA_ARGS__); }
- #endif
- #define CUSTOM_REGISTRATION_RESPONSE_TIMEOUT 20 // 45
- #define CUSTOM_INVITE_RESPONSE_TIMEOUT 32 // used to be 2...
- #define CUSTOM_LOGOUT_RESPONSE_TIMEOUT 7 //36
- #define REGISTRATION_RFRESH_TIMER_ID 1
- #define SIGNAL_CHANNEL_KEEP_ALIVE_TIMER_ID ((REGISTRATION_RFRESH_TIMER_ID) + (MAXIMUM_SIP_ACCOUNT) )
- #define TRANSACTION_TIMER_ID ((REGISTRATION_RFRESH_TIMER_ID) + ((MAXIMUM_SIP_ACCOUNT) * 2))
- #define REGISTRATION_RESPONSE_TIMER_ID ((REGISTRATION_RFRESH_TIMER_ID) + ((MAXIMUM_SIP_ACCOUNT) * 3))
- #define INVITE_RESPONSE_TIMER_ID ((REGISTRATION_RFRESH_TIMER_ID) + ((MAXIMUM_SIP_ACCOUNT) * 4))
- #define LOGOUT_RESPONSE_TIMER_ID ((REGISTRATION_RFRESH_TIMER_ID) + ((MAXIMUM_SIP_ACCOUNT) * 5))
- #define DATA_CHANNEL_KEEP_ALIVE_TIMER_ID ((REGISTRATION_RFRESH_TIMER_ID) + ((MAXIMUM_SIP_ACCOUNT) * 6))
- #ifdef _SUPPORT_EVENT_PACKAGE
- #define MWI_RFRESH_TIMER_ID REGISTRATION_RFRESH_TIMER_ID + (MAXIMUM_SIP_ACCOUNT * 7)
- #endif
- #define UPDATE_CONF_LIST_TIMER_ID REGISTRATION_RFRESH_TIMER_ID + (MAXIMUM_SIP_ACCOUNT * 8)
- // timeout in second
- #define REGISTRATION_RESPONSE_TIMEOUT 10 // 10 second
- #define INVITE_RESPONSE_TIMEOUT 10 // 10 second
- #define LOGOUT_RESPONSE_TIMEOUT 5 // 5 second
- #define TRANSACTION_TIMER_INTERVAL 1000 // 500
- #define DATA_CHANNEL_KEEP_ALIVE_PERIOD 10
- #define MAX_SENT_KEEP_ALIVE_COUNT 3
- #define KILL_TIMER(X) if (X) {KillTimer(X); (X) = 0;}
- #define INVALID_ACCOUNT_ID (-1)
- #define _CUSTOM_TIMER_
- int g_AFPPMultiplier = 1; // AudioFramesPerPacket
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CSessionControl *g_pSessionControl = NULL;
- CPostMessage *g_pSipPostMessageControl = NULL;
- #endif
- #ifdef _WIN32_WCE
- bool g_AudioPTime60MsInVideoCalls = true;
- #endif
- #if (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- static int iPARAM2;
- #define SetChannelOption(A, B, C) SetChannelOption(A, B, &(iPARAM2=C))
- #endif
- //#define SIP_URI_CASE_SENSITIVE
- //void OpenGLPause(bool bPause); // Defined in VideoX
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CSessionControl::CSessionControl(CSipCommEventHandler_PTR callback_handler):
- CCustomTimer(this)
- {
- g_pSessionControl = this;
- g_pSipPostMessageControl = this;
- m_bWindowOnly = TRUE;
- m_CallbackHandler = callback_handler;
- FinalConstruct();
- BOOL b = false;
- OnCreate(0,0,0,b);
- }
- #endif
- #define SAFE_LOG(...) if(g_pSessionControl) g_pSessionControl->m_pFramework->Log(__VA_ARGS__)
- #define DEBUG_LOG_TAG "kaidul_SSL"
- #define SSL_ASSERT(X, ...) \
- if(!(X)) { \
- __android_log_print(ANDROID_LOG_DEBUG, DEBUG_LOG_TAG, __VA_ARGS__); \
- SAFE_LOG(__VA_ARGS__); \
- return 0; \
- }
- #define SSL_LOG(...) \
- __android_log_print(ANDROID_LOG_DEBUG, DEBUG_LOG_TAG, __VA_ARGS__); \
- SAFE_LOG(__VA_ARGS__);
- static int verify_certificate_hostname(X509 *cert, char *hostname) {
- int extcount;
- int success = 0;
- char name[256];
- X509_NAME *subj;
- const char *extstr;
- CONF_VALUE *nval;
- X509_EXTENSION *ext;
- X509V3_EXT_METHOD *meth;
- STACK_OF(CONF_VALUE) *val;
- void *ext_internal;
- if ((extcount = X509_get_ext_count(cert)) > 0) {
- for (int i = 0; !success && i < extcount; i++) {
- ext = X509_get_ext(cert, i);
- extstr = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext)));
- if (!strcasecmp(extstr, "subjectAltName")) {
- if (!(meth = X509V3_EXT_get(ext))) break;
- const unsigned char *data = ext->value->data;
- ext_internal = X509V3_EXT_d2i(ext);
- val = meth->i2v(meth, ext_internal, 0);
- for (int j = 0; j < sk_CONF_VALUE_num(val); j++) {
- nval = sk_CONF_VALUE_value(val, j);
- if (!strcasecmp(nval->name, "DNS") && !strcasecmp(nval->value, hostname)) {
- success = 1;
- break;
- }
- }
- }
- }
- }
- if (!success && (subj = X509_get_subject_name(cert)) && X509_NAME_get_text_by_NID(subj, NID_commonName, name, sizeof(name)) > 0) {
- name[sizeof(name) - 1] = '\0';
- if (!strcasecmp(name, hostname)) success = 1;
- }
- return success;
- }
- static int certificate_verifier_callback(void *ctx, void *arg)
- {
- SSL_LOG("Callback called for certificate verification.");
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
- char *hostname = "www.smartbabymonitor.ugrow.philips.com";
- X509_STORE_CTX store_ctx = X509_STORE_CTX(*(X509_STORE_CTX*)ctx);
- int rc = X509_verify_cert(&store_ctx);
- X509 *cert = X509_STORE_CTX_get_current_cert(&store_ctx);
- SSL_ASSERT(cert != NULL, "Server certificate invalid.");
- SSL_LOG("Server Certificate valid.");
- int err = X509_STORE_CTX_get_error(&store_ctx);
- switch(err) {
- case X509_V_ERR_CERT_NOT_YET_VALID:
- case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
- SSL_ASSERT(false, "Certificate is not valid yet.");
- break;
- case X509_V_ERR_CERT_HAS_EXPIRED:
- case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
- SSL_ASSERT(false, "Certificate is expired.");
- break;
- case X509_V_ERR_CRL_NOT_YET_VALID:
- SSL_ASSERT(false, "Certificate Revocation List is not yet valid.");
- break;
- case X509_V_ERR_CRL_HAS_EXPIRED:
- SSL_ASSERT(false, "Certificate Revocation List is expired.");
- break;
- default:
- break;
- }
- SSL_LOG("Certificate is up-to-date.");
- SSL_LOG("CRL list checking success.");
- /* Server Certificate hostname verification */
- SSL_ASSERT(verify_certificate_hostname(cert, hostname) == 1, "Hostname verification failed.");
- SSL_LOG("Hostname verification success.");
- /*
- AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
- AAssetDir* assetDir = AAssetManager_openDir(mgr, "");
- const char* filename = "philips_trusted_cert.pem";
- while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
- AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_STREAMING);
- char buf[BUFSIZ];
- int nb_read = 0;
- FILE* out = fopen(filename, "w");
- while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0)
- fwrite(buf, nb_read, 1, out);
- fclose(out);
- AAsset_close(asset);
- }
- AAssetDir_close(assetDir);
- */
- return 1;
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- const char *path = "/home/nayeem/Desktop/philips_trusted_cert.pem";
- FILE* fp = fopen(path, "r");
- if(!fp) {
- SAFE_LOG("Unable to open local certificate.");
- __android_log_print(ANDROID_LOG_DEBUG, DEBUG_LOG_TAG, "\nUnable to open local certificate.\n");
- return 0;
- }
- fseek(fp, 0, SEEK_END);
- size_t size = ftell(fp);
- char* data = new char[size];
- rewind(fp);
- fread(data, sizeof(char), size, fp);
- fclose(fp);
- BIO *bio = BIO_new(BIO_s_mem());
- BIO_puts(bio, data);
- delete[] data;
- X509 *cert2 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
- BIO_free(bio);
- if(!cert2) {
- X509_free(cert);
- //SAFE_LOG("Local certificate X509 object invalid..");
- return 0;
- }
- EVP_PKEY *pkey = X509_get_pubkey(cert2);
- int result = X509_verify(cert, pkey);
- if(result > 0) {
- //SAFE_LOG("Certificate Verification Success.");
- __android_log_print(ANDROID_LOG_DEBUG, DEBUG_LOG_TAG, "\nCertificate Verification Success.\n");
- } else {
- //SAFE_LOG("Certificate Verification Failed.");
- __android_log_print(ANDROID_LOG_DEBUG, DEBUG_LOG_TAG, "\nCertificate Verification Failed.\n");
- }
- EVP_PKEY_free(pkey);
- X509_free(cert2);
- X509_free(cert);
- return result == 1;
- }
- HRESULT CSessionControl::FinalConstruct()
- {
- m_iMaximumAccount = MAXIMUM_SIP_ACCOUNT;
- #ifdef USE_NSSTREAM_FOR_SIP
- m_pApplicationModeMutex = new PAL::Mutex;
- #endif
- SipAccount* sipAccount = new SipAccount(this);
- PAL_DB_ASSERT(sipAccount);
- m_iSelectedAccount = DEFAULT_ACCOUNT_ID; /* Automatically set selectedAccount to the just-created account */
- m_pFramework = new CFramework(this);
- m_pCallHistory = new CCallHistory(this);
- m_pCallLine = new CCallLine(this);
- m_pCodecConfig = new CCodecConfig;
- #ifndef NO_DATA_TRAVELER
- m_pDataTraveler = new CDataTraveler(this);
- #endif
- PAL_ASSERT(m_pFramework);
- PAL_ASSERT(m_pCallHistory);
- PAL_ASSERT(m_pCallLine);
- PAL_ASSERT(m_pCodecConfig);
- #ifndef NO_DATA_TRAVELER
- PAL_ASSERT(m_pDataTraveler);
- #endif
- /*order is important. First add(..), then Init(..)*/
- AddAccount(m_iSelectedAccount, sipAccount);
- sipAccount->Init(m_iSelectedAccount);
- /**Init() not-account-specific objects
- with Selected SipAccnt.*/
- m_pFramework->Init(m_iSelectedAccount);
- m_pCallHistory->Init(m_iSelectedAccount);
- m_pCallLine->Init(m_iSelectedAccount);
- #ifndef NO_DATA_TRAVELER
- /*must call this, so the accountID in DataTraveler is valid.*/
- m_pDataTraveler->SetSipAccountId(m_iSelectedAccount);
- #endif
- m_pFramework->Log("AFEngine loading...");
- m_pAFEngine.reset(new CAnyFirewallEngine);
- PAL_ASSERT(m_pAFEngine.get());
- #ifdef USE_NSSTREAM_FOR_SIP
- m_pNSsocket.reset(new CNSsocket);
- PAL_ASSERT(m_pNSsocket.get());
- #endif
- m_bAFEngineInit = false;
- LoadAFEngine();
- m_pFramework->SetAFEngine(m_pAFEngine, m_iAFEServerStoreID);
- SipAccount* sipAccnt = GetSipAccount(m_iSelectedAccount);
- RET_ERROR_STR(sipAccnt);
- if(m_bAFEngineInit)
- {
- #ifdef USE_NSSTREAM_FOR_SIP
- // This must be set before setting AFEngine since setting AFEngine starts thread which uses the NSsocket
- sipAccnt->m_pAgent->SetNSsocket(m_pNSsocket);
- #endif
- sipAccnt->m_pAgent->SetAFEngine(m_pAFEngine, m_iAFEServerStoreID);
- #ifndef NO_DATA_TRAVELER
- m_pDataTraveler->SetAFEngine(m_pAFEngine, m_iAFEServerStoreID);
- #endif
- }
- m_iUpdateConferenceListTimer = 0;
- #ifdef WCE_PLATFORM_STANDARDSDK_500
- m_hNewWindowsMessage = NULL;
- m_hQuitWindowsMessageThread = NULL;
- // events
- m_hNewWindowsMessage = new PAL::Event;
- m_hQuitWindowsMessageThread = new PAL::Event;
- PAL_ASSERT(m_hNewWindowsMessage);
- PAL_ASSERT(m_hQuitWindowsMessageThread);
- m_pWindowsMessageQueueMutex.reset(new PAL::Mutex);
- PAL_ASSERT(m_pWindowsMessageQueueMutex.get());
- m_pWindowsMessageThread.reset(new PAL::Thread(WindowsMessageThread, this));
- PAL_ASSERT(m_pWindowsMessageThread.get());
- #endif
- #ifdef _WIN32_WCE
- MSGQUEUEOPTIONS mqo;
- mqo.dwSize = sizeof(MSGQUEUEOPTIONS);
- mqo.dwFlags = 0;
- mqo.dwMaxMessages = 0;
- mqo.cbMaxMessage = 30;
- mqo.bReadAccess = true;
- if (m_hPowerMsgQueue = CreateMsgQueue(NULL, &mqo)) {
- m_hPowerNotifications
- = RequestPowerNotifications(m_hPowerMsgQueue, PBT_RESUME);
- if (m_hPowerNotifications == NULL) {
- CloseMsgQueue(m_hPowerMsgQueue);
- m_hPowerMsgQueue = NULL;
- }
- }
- if (m_hPowerMsgQueue) {
- m_hQuitSuspendMonitorThread = CreateEvent(NULL, FALSE, FALSE, NULL);
- PAL_ASSERT(m_hQuitSuspendMonitorThread);
- m_pSuspendMonitorThread.reset(new PAL::Thread(SuspendMonitorThread, this));
- PAL_ASSERT(m_pSuspendMonitorThread.get());
- }
- #endif
- m_pAFEngine->SetCertificateVerificationCallback(certificate_verifier_callback);
- m_bDisableCalls = false;
- m_pNonBlockingCallMutex = new PAL::Mutex;
- if(PAL::IsLogEnabled(PAL::PAL_LOG_MSA))
- m_fp = fopen(PAL_LOG_FILENAME_MSA,"w+");
- else
- m_fp = NULL;
- MSA_LOG("starting log...");
- return S_OK;
- }
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CSessionControl::~CSessionControl()
- {
- BOOL b = false;
- OnDestroy(0,0,0,b);
- FinalRelease();
- g_pSessionControl = NULL;
- g_pSipPostMessageControl = NULL;
- }
- #endif
- void CSessionControl::FinalRelease()
- {
- #ifdef WCE_PLATFORM_STANDARDSDK_500
- m_hQuitWindowsMessageThread.set();
- m_pWindowsMessageThread->join();
- // threads
- m_pWindowsMessageThread.reset();
- // mutexs
- m_pWindowsMessageQueueMutex.reset();
- delete m_hNewWindowsMessage;
- delete m_hQuitWindowsMessageThread;
- #endif
- m_bDisableCalls = true;
- JoinNonBlockingCallThreads(true);
- //Logout();
- ShutDownAllAccounts(); //shuts down and logs out all SIP accounts
- MSA_LOG("In SessionControl FinalRelease...");
- PAL_DB("Final Release.");
- m_iSelectedAccount = -1; /*reset Selected Account index.*/
- for (SipAccountMap::iterator accntIter = m_sipAccountMap.begin(); accntIter != m_sipAccountMap.end(); ++accntIter)
- {
- SipAccount* pAccnt = (SipAccount*)accntIter->second;
- delete pAccnt;
- }
- m_sipAccountMap.clear(); //clear the map.
- SAFE_DELETE(m_pCallHistory);
- SAFE_DELETE(m_pCodecConfig);
- #ifndef NO_DATA_TRAVELER
- SAFE_DELETE(m_pDataTraveler);
- #endif
- SAFE_DELETE(m_pCallLine);
- SAFE_DELETE(m_pNonBlockingCallMutex);
- MSA_LOG("Final release done: " + itoa(m_sipAccountMap.size()));
- if (m_pAFEngine.get())
- {
- UnloadAFEngine();
- m_pAFEngine.reset();
- MSA_LOG("Anyfirewall library is released.");
- }
- #ifdef USE_NSSTREAM_FOR_SIP
- SAFE_DELETE(m_pApplicationModeMutex);
- if (m_pNSsocket.get())
- {
- m_pNSsocket.reset();
- MSA_LOG("NSsocket object is released.");
- }
- #endif
- // Close this at the end, otherwise logs cannot be written in Framework's log file after that
- m_pFramework->Close(); //close mediaFramework.
- m_pFramework->Shutdown();
- SAFE_DELETE(m_pFramework);
- if(m_fp)
- fclose(m_fp);
- }
- bool CSessionControl::LoadAFEngine()
- {
- m_pFramework->Log("Loading AFEngine...");
- if(m_bAFEngineInit){
- m_pFramework->Log("AFEngine already loaded");
- return true;
- }
- if(!m_pAFEngine.get())
- return false;
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CLSID clsid = DEF_CLSID_ANYFIREWALL;
- LPOLESTR wszCLSID = NULL;
- HRESULT hr = StringFromCLSID(clsid, &wszCLSID);
- tstring sClsID = wszCLSID;
- // Free memory.
- CoTaskMemFree(wszCLSID);
- tstring sKey = TEXT("CLSID\\");
- sKey += sClsID;
- sKey += TEXT("\\InprocServer32");
- tstring sData;
- tstring sValue;
- GetRegistryEntry(HKEY_CLASSES_ROOT, sKey, sValue, sData);
- #endif
- m_bAFEngineInit =
- #if (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- m_pAFEngine->Init(AF_MODE_STANDARD, true);
- #elif defined(WIN32)
- m_pAFEngine->InitDll(_Module.GetModuleInstance(),
- #if (AF_DLL_VERSION > 950000 && AF_DLL_VERSION < 9600000)
- AF_MODE_AUTO, true
- #else
- sData.mbs()
- #endif
- );
- #else
- m_pAFEngine->Init(
- #if (AF_DLL_VERSION > 950000 && AF_DLL_VERSION < 9600000)
- AF_MODE_AUTO, true
- #endif
- );
- #endif
- if(m_bAFEngineInit)
- {
- m_pFramework->Log("AFEngine loaded.");
- //m_pAFEngine->SetFirewallDetectionPeriod(0);
- }
- else
- {
- m_pFramework->Log("AFEngine cannot load!!!");
- }
- PAL_ASSERT(m_bAFEngineInit);
- #if (AF_DLL_VERSION > 9600000)
- #if (AF_DLL_VERSION > 10011600)
- if(PAL::IsLogEnabled(PAL::PAL_LOG_AF_MESSAGE)){
- m_pAFEngine->SetLogFilePath(PAL::GetLogPath().c_str());
- }
- #endif
- m_pAFEngine->SetLogFileOptions(5, 2);
- m_iAFEServerStoreID = m_pAFEngine->CreateServerStore(AF_MODE_AUTO, true);
- #if (AF_DLL_VERSION >= 10011619)
- m_pAFEngine->SetNetworkType(m_iAFEServerStoreID, EAfIPv4Only);
- #endif
- #endif
- int iAfOptionTrue = AF_OPTION_TRUE;
- #if (AF_DLL_VERSION >= 10011629)
- m_pAFEngine->SetChannelOption(0, EAfOptionManualMode, &iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableStun, &iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableTurn, &iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableHTTPTunneling, &iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableUPnP, &iAfOptionTrue);
- #else
- m_pAFEngine->SetChannelOption(0, EAfOptionManualMode, iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableStun, iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableTurn, iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableHTTPTunneling, iAfOptionTrue);
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableUPnP, iAfOptionTrue);
- #endif
- return m_bAFEngineInit;
- }
- void CSessionControl::UnloadAFEngine()
- {
- if(m_pFramework)
- m_pFramework->Log("Unloading AFEngine...");
- if(!m_bAFEngineInit){
- if(m_pFramework)
- m_pFramework->Log("AFEngine is not even loaded!!!");
- return;
- }
- if (m_pAFEngine.get())
- {
- #if (AF_DLL_VERSION > 9600000)
- m_pAFEngine->CloseServerStore(m_iAFEServerStoreID);
- #endif
- m_pAFEngine->Release();
- }
- m_bAFEngineInit = false;
- }
- #ifdef NO_SIP
- STDMETHODIMP CSessionControl::GetAFEngine(void **pAFEngine)
- {
- *pAFEngine = (void *)m_pAFEngine.get();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::OpenSession(int iLine, char chAudioPayload, char chVideoPayload, int iAudioRTPChannel, int iAudioRTCPChannel, int iVideoRTPChannel, int iVideoRTCPChannel, bool bCaller)
- {
- CallDialog *pDlg = m_pCallLine->GetDialog(iLine);
- if(!pDlg){
- return ThrowError("No dialog found with this line");
- }
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CallDialog &dlg = *pDlg;
- dlg.m_iCallStartTime = (int)PAL::getCurrentTimeInMilliSeconds();
- dlg.m_bConf = false;
- dlg.m_iAcct = sipAccnt->m_pAgent->m_iAccnt;
- //only caller can send reinvite.
- dlg.m_bReInvite = true;
- m_pCallLine->SetSelectedLine(iLine);
- dlg.m_bEnableIceSupport = sipAccnt->m_pAgent->m_bEnableIceSupport;
- dlg.m_bIsSdpInInvite = sipAccnt->m_pAgent->m_bInviteSDP;
- dlg.m_bPhoneCall = false;
- if(dlg.m_bPhoneCall)
- {
- dlg.m_bEnableIceSupport = sipAccnt->m_pAgent->m_GatewayPreferences.bEnableICE;
- dlg.m_bIsSdpInInvite = !sipAccnt->m_pAgent->m_GatewayPreferences.bEnableNoSDPINVITE;
- }
- dlg.m_bAnonymousCall = false;
- dlg.m_sFromPhoneNumber = sipAccnt->m_pAgent->m_sFromPhoneNumber;
- dlg.m_sMyURI = sipAccnt->m_pAgent->GetUsername() + "@" + sipAccnt->m_pAgent->GetDomainName();
- dlg.m_pAgent = sipAccnt->m_pAgent;
- dlg.m_iLine = iLine;
- m_pCallLine->SetPendingLineStatus(dlg);
- /////////////////////////////////////////////////////////
- dlg.m_chAudioPayload = chAudioPayload;
- dlg.m_chVideoPayload = chVideoPayload;
- if (dlg.m_chAudioPayload != INVALID_PAYLOAD_TYPE)
- {
- dlg.m_iAudioRTPChannel = iAudioRTPChannel;
- dlg.m_iAudioRTCPChannel = iAudioRTCPChannel;
- }
- if (dlg.m_chVideoPayload != INVALID_PAYLOAD_TYPE)
- {
- dlg.m_iVideoRTPChannel = iVideoRTPChannel;
- dlg.m_iVideoRTCPChannel = iVideoRTCPChannel;
- }
- // dlg.m_iSession = iSession;
- ///////////////////////////////////////
- dlg.m_sDisplayName = MediaSessionUtil::GetUserNameFromURI(sipAccnt->m_pAgent->GetUsername());
- dlg.m_iRefferedLine = -1;
- dlg.m_bSrtpCall = sipAccnt->m_pAgent->m_bSrtpCall;
- if(dlg.m_bSrtpCall)
- {
- m_pFramework->m_mediaFramework->put_EnableSrtp(TRUE);
- }
- else
- {
- m_pFramework->m_mediaFramework->put_EnableSrtp(FALSE);
- }
- dlg.m_bCaller = bCaller;
- dlg.m_callState = CALL_CALLING;
- dlg.m_sTargetID = m_pCallLine->MakeUniqueTargetID(dlg.m_sTargetURI);
- dlg.m_iProxy = sipAccnt->m_pAgent->GetSelectedProxy();
- dlg.m_sProxyAuthentication = sipAccnt->m_pAgent->GetProxyAuthentication();
- #ifndef _WIN32_WCE
- time_t t;
- time(&t);
- dlg.m_iCallingTime = (long)t;
- #else
- GetLocalTime(&dlg.m_stCallingTime);
- #endif
- //m_pCallLine->AddDialog(iLine, dlg);
- m_pFramework->OpenSession(dlg);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::CloseSession(int iLine, char chAudioPayload, char chVideoPayload)
- {
- CallDialog *pDlg = m_pCallLine->GetDialog(iLine);
- if(!pDlg){
- return ThrowError("No dialog found with this line");
- }
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CallDialog &dlg = *pDlg;
- dlg.m_chAudioPayload = chAudioPayload;
- dlg.m_chVideoPayload = chVideoPayload;
- sipAccnt->m_pAgent->CloseSession(dlg);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ReleaseLine(int iLine)
- {
- m_pCallLine->RemoveLine(iLine);
- return S_OK;
- }
- #endif
- LRESULT CSessionControl::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- #ifdef CUSTOM_POST_MESSAGE
- m_hWndControl = this;
- #else
- m_hWndControl = m_hWnd;
- #endif
- sipAccnt->m_pAgent->SetAppWindow(m_hWndControl);
- #ifndef NO_DATA_TRAVELER
- m_pDataTraveler->SetAppWindow(m_hWndControl);
- #endif
- if (m_pFramework->m_mediaFramework)
- {
- m_pFramework->SetAppWindow(m_hWndControl);
- m_pFramework->m_mediaFramework->SetVideoSizeNotify(m_hWndControl, WM_VIDEO_WINDOW_SIZE);
- }
- sipAccnt->m_iTransactionTimer = SetTimer(TRANSACTION_TIMER_ID + GetAccountID(sipAccnt) , TRANSACTION_TIMER_INTERVAL);
- sipAccnt->m_iDataChannelKeepAliveTimer = SetTimer(
- DATA_CHANNEL_KEEP_ALIVE_TIMER_ID + GetAccountID(sipAccnt),
- DATA_CHANNEL_KEEP_ALIVE_PERIOD * 1000);
- return 0;
- }
- LRESULT CSessionControl::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- //moved this here from FinalRelease because suspendMonitorThread
- //needs the sipAccountID to callshutdown/logout
- //This code might be duplicate of the code below it.
- #ifdef _WIN32_WCE
- if (m_hPowerMsgQueue) {
- StopPowerNotifications(m_hPowerNotifications);
- SetEvent(m_hQuitSuspendMonitorThread);
- m_pSuspendMonitorThread->join();
- CloseMsgQueue(m_hPowerMsgQueue);
- m_hPowerMsgQueue = NULL;
- }
- #endif
- int selectedAccount = -1;
- SipAccountMap::iterator iter = m_sipAccountMap.begin();
- for (; iter != m_sipAccountMap.end(); ++iter)
- {
- m_iSelectedAccount = iter->first; //for EndCall, LogOut, ShutDown
- selectedAccount = m_iSelectedAccount; //save selected account
- //set the m_pAgent pointer to the pAgent pointer of the
- //currently active account.
- m_pFramework->Init(m_iSelectedAccount);
- m_pCallHistory->Init(m_iSelectedAccount);
- m_pCallLine->Init(m_iSelectedAccount);
- #ifndef NO_DATA_TRAVELER
- m_pDataTraveler->SetSipAccountId(m_iSelectedAccount);
- #endif
- Logout();
- m_iSelectedAccount = selectedAccount;
- Shutdown();
- }
- return 0;
- }
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- LRESULT CSessionControl::MessageHandlers(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- MESSAGE_HANDLER(WM_FIRE_EVENT, OnFireEvent)
- MESSAGE_HANDLER(WM_KILL_TRANSACTION, OnKillTransaction)
- MESSAGE_HANDLER(WM_VIDEO_WINDOW_SIZE, OnVideoWindowSize)
- MESSAGE_HANDLER(WM_AUDIO, OnAudioEvent)
- MESSAGE_HANDLER(WM_FUNCTION_CALL, OnFunctionCall)
- MESSAGE_HANDLER(WM_TIMER, OnTimer)
- // Reaching here means no matching handler found.
- return -1;
- }
- #endif
- void CSessionControl::ShutDownAllAccounts()
- {
- SipAccountMap::iterator iter = m_sipAccountMap.begin();
- for (; iter != m_sipAccountMap.end(); ++iter)
- {
- //delete SIPAccount object, pAgent, and stop threads.
- ReleaseAccount(iter->second);
- }
- }
- /*sipAccnt specific.*/
- LRESULT CSessionControl::OnKillTransaction(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- int accnt = *((int*) lParam);
- SipAccount* sipAccnt = GetSipAccount(accnt);
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->KillTransaction(wParam);
- bHandled = TRUE;
- return 0;
- }
- LRESULT CSessionControl::OnDrawVideo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- if (!m_pFramework->m_mediaFramework)
- return E_FAIL;
- ATL_DRAWINFO& di = *(ATL_DRAWINFO*)lParam;
- HWND hWnd = HWND(wParam);
- return m_pFramework->m_mediaFramework->DrawVideo(hWnd, lParam);
- #else
- return 0;
- #endif
- }
- LRESULT CSessionControl::OnVideoWindowSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- HWND hWnd = (HWND)wParam;
- int iWidth = LOWORD(lParam);
- int iHeight = HIWORD(lParam);
- m_pFramework->Log("OnVideoWindowSize " + tostring(uMsg) + " " + tostring(iWidth) + " x " + tostring(iHeight));
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(3);
- aMsg.PutNumber(0, (long)hWnd);
- aMsg.PutNumber(1, iWidth);
- aMsg.PutNumber(2, iHeight);
- FIRE_EVENT(OnVideoSizeChange, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnVideoSizeChange, (long)hWnd, iWidth, iHeight);
- #endif
- return 0;
- }
- LRESULT CSessionControl::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- int accnt = (int)(wParam - 1) % MAXIMUM_SIP_ACCOUNT; //get account id.
- SipAccount* sipAccnt = GetSipAccount(accnt);
- RET_ERROR_STR(sipAccnt);
- if (wParam == sipAccnt->m_iRegistrationRefreshTimer)
- {
- if (sipAccnt->m_pAgent->RefreshRegistration())
- SetRegistrationResponseTimer(accnt);
- }
- else if (wParam == sipAccnt->m_iSignalChannelKeepAliveTimer)
- {
- if (NULL != sipAccnt->m_pAgent->m_pConnectToSIPServerhread.get())
- return 0;
- if (sipAccnt->m_iSentKeepAliveCount >= MAX_SENT_KEEP_ALIVE_COUNT)
- {
- PAL_DB("No response for keep-alive.");
- m_pFramework->Log("No response for keep-alive.");
- sipAccnt->m_iSentKeepAliveCount = 0;
- HandleTimeoutOrError(accnt);
- }
- if (sipAccnt->m_bEnableBindingResponseFailover &&
- sipAccnt->m_iSignalChannelKeepAlivePeriod &&
- sipAccnt->m_pAgent->KeepSignalSocketAlive() )
- {
- sipAccnt->m_iSentKeepAliveCount++;
- PAL_DB2("Sending keep-alive request: ", sipAccnt->m_iSentKeepAliveCount);
- }
- else
- {
- sipAccnt->m_iSentKeepAliveCount = 0;
- }
- }
- else if (wParam == sipAccnt->m_iDataChannelKeepAliveTimer)
- {
- if (NULL == sipAccnt->m_pAgent->m_pConnectToSIPServerhread.get())
- sipAccnt->m_pAgent->KeepDataSocketAlive();
- }
- else if (wParam == sipAccnt->m_iTransactionTimer)
- {
- sipAccnt->m_pAgent->HandleTransactionTimer();
- }
- else if (wParam == sipAccnt->m_iRegistrationResponseTimer)
- {
- if (sipAccnt->m_pAgent->IsDelayingRegistration())
- {
- PAL_DB("Resetting registration timeout...");
- // reset the time-out
- SetRegistrationResponseTimer(accnt);
- }
- else
- {/*sipAccnt->m_pAgent->*/
- if (sipAccnt->m_pAgent->HasNextProxyServerIndex()){
- RegisterFailOver(sipAccnt);
- }else{
- HandleTimeoutOrError(accnt);
- PAL_DB("No response for registration.");
- m_pFramework->Log("No response for registration.");
- }
- }
- }
- else if (wParam == sipAccnt->m_iInviteResponseTimer)
- {
- PAL_DB("No response for invite.");
- // Note: no response from other client - no need to panic...
- KILL_TIMER(sipAccnt->m_iInviteResponseTimer);
- }
- else if (wParam == sipAccnt->m_iLogoutResponseTimer)
- {
- HandleLogoutTimeoutOrError(accnt);
- }
- #ifdef _SUPPORT_EVENT_PACKAGE
- else if(wParam == sipAccnt->m_iMWIRefreshTimer)
- {
- //call MWIRefreshTimer.
- sipAccnt->m_pAgent->RefreshSubscription();
- }
- #endif
- else if(wParam == m_iUpdateConferenceListTimer)
- {
- KillTimer(wParam);
- m_pCallLine->NotifyConfList();
- }
- else
- {
- PAL_DB_ASSERT(0 && "Invalid SipComm timer.");
- KillTimer(wParam);
- }
- return 0;
- }
- #ifdef __unix__
- void CSessionControl::OnWriteLog(int log_type, const std::string &str_log)
- {
- if ( g_pSessionControl && g_pSessionControl->m_CallbackHandler )
- {
- g_pSessionControl->m_CallbackHandler->OnLog(log_type, str_log + "\r\n");
- }
- }
- #endif
- LRESULT CSessionControl::OnFireEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- StartProfileTimer("OnFireEvent");
- FireEventData* p = (FireEventData*)wParam;
- if (!p)
- {
- PAL_DB_ASSERT(0);
- return 0;
- }
- int accnt = p->m_iAccnt;
- SipAccount* sipAccnt = GetSipAccount(accnt);
- RET_ERROR_STR(sipAccnt);
- switch (p->m_iEventID)
- {
- case EVENT_REGISTER_RESPONSE:
- {
- if (p->m_iStatusCode == 401 || p->m_iStatusCode == 407)
- {
- if (sipAccnt->m_pAgent->RegisterWithAuthorization(p->m_iProxy))
- break;
- }
- if (p->m_iStatusCode == 423)
- {
- if (sipAccnt->m_pAgent->RegisterWithNewExpire(p->m_iProxy))
- break;
- }
- KILL_TIMER(sipAccnt->m_iRegistrationResponseTimer);
- bool bRegistered = sipAccnt->m_bRegistered;
- if (p->m_iResponse == RESPONSE_SUCCESS)
- {
- sipAccnt->m_bRegistered = true;
- SetRegistrationRefreshTimer(accnt);
- SetSignalChannelKeepAliveTimer(accnt);
- //#ifdef __unix__
- #if 0
- if(sipAccnt->m_pAgent->GetTransportMode() != UDP){
- #if 0
- int mib[4], ival;
- mib[0] = CTL_NET;
- mib[1] = AF_INET;
- mib[2] = IPPROTO_TCP;
- mib[3] = 19; //TCPCTL_KEEPCNT;
- ival = 1; /* Number of keepalive probe attempts (default is 8) */
- sysctl(mib, 4, NULL, NULL, &ival, sizeof(ival));
- #endif
- #ifndef USE_NSSTREAM_FOR_SIP
- struct timeval tval;
- memset(&tval, 0, sizeof(tval));
- tval.tv_sec = 30;
- struct AfSocketOptionParams afsop;
- afsop.iLevel = IPPROTO_TCP; //6;
- afsop.iOptName = 4; //TCP_KEEPALIVE;
- afsop.pOptVal = (void *)&tval;
- afsop.iOptLen = sizeof(tval);
- m_pAFEngine->SetChannelOption(sipAccnt->m_pAgent->m_iSipChannel, EAfOptionSocket, (intptr_t)&afsop);
- #endif
- }
- #endif
- #if 0
- // added by MC -- request immediate keep-alive
- #ifndef __unix__
- #ifndef WCE_PLATFORM_STANDARDSDK_500
- PostMessage(WM_TIMER, sipAccnt->m_iSignalChannelKeepAliveTimer, 0);
- #else
- SendWindowsMessage(WM_TIMER, sipAccnt->m_iSignalChannelKeepAliveTimer, 0);
- #endif
- #else
- SetTimer(sipAccnt->m_iSignalChannelKeepAliveTimer, 0);
- #endif
- #endif
- if (!sipAccnt->m_sCallUri.empty())
- {
- // invite failover
- Call(ToInternalBstr(sipAccnt->m_sCallUri), ToInternalBstr(""), VARIANT_FALSE, VARIANT_FALSE);
- }
- else if (bRegistered)
- {
- // registered again, need to send target refresh request
- sipAccnt->m_pAgent->HandleRegistrationFailover();
- }
- }
- //if(p->m_iStatusCode == 401)
- else
- {
- sipAccnt->m_pAgent->CloseConnection();
- }
- if (!bRegistered)
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(5);
- aMsg.PutNumber(0, p->m_iResponse);
- aMsg.PutNumber(1, p->m_iStatusCode);
- aMsg.PutString(2, p->m_sReason);
- aMsg.PutNumber(3, p->m_iProxy);
- aMsg.PutNumber(4, p->m_iAccnt);
- FIRE_EVENT(OnRegisterResponse, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnRegisterResponse, p->m_iResponse,
- p->m_iStatusCode,
- ToBstr(p->m_sReason),
- p->m_iProxy,
- p->m_iAccnt);
- #endif
- //test();
- }
- else
- {
- // this is response to failover
- }
- }
- break;
- case EVENT_CALL_RESPONSE:
- {
- MSA_LOG("recieved response for account: " + itoa(accnt));
- KILL_TIMER(sipAccnt->m_iInviteResponseTimer);
- sipAccnt->m_sCallUri = "";
- string sTargetURI = p->m_sTargetURI;
- string sUsername = MediaSessionUtil::GetUserNameFromURI(sTargetURI);
- string sDomain = MediaSessionUtil::GetDomainNameFromURI(sTargetURI);
- char *tmp = __osip_uri_escape_userinfo (sUsername.c_str());
- sUsername = tmp;
- osip_free (tmp);
- if(!sDomain.empty())
- sUsername += "@" + sDomain;
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(10);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutNumber(1, p->m_iResponse);
- aMsg.PutNumber(2, p->m_iStatusCode);
- aMsg.PutString(3, p->m_sReason);
- aMsg.PutString(4, p->m_sDisplayName);
- aMsg.PutString(5, sUsername);
- aMsg.PutNumber(6, p->m_bVideoCall);
- aMsg.PutNumber(7, p->m_iAccnt);
- aMsg.PutNumber(8, p->m_bEarlyMedia);
- if (p->m_iStatusCode == 200)
- {
- CallDialog * pCallDialog = m_pCallLine->GetDialog(p->m_iLine);
- if (pCallDialog)
- {
- if (m_pAFEngine->GetSessionProperty(pCallDialog->m_iSession, EAfSessionNonICEPeer))
- aMsg.PutNumber(9, 0); // Peer is Non-ICE
- else
- aMsg.PutNumber(9, 1); // Peer is ICE agent
- }
- else
- {
- aMsg.PutNumber(9, -1); // Unknown
- }
- }else
- {
- aMsg.PutNumber(9, -1); // Unknown
- }
- FIRE_EVENT(OnCallResponse, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnCallResponse, p->m_iLine,
- p->m_iResponse,
- p->m_iStatusCode,
- ToBstr(p->m_sReason),
- ToBstr(p->m_sDisplayName),
- ToBstr(sUsername),
- ToVB(p->m_bVideoCall),
- p->m_iAccnt,
- p->m_bEarlyMedia);
- #endif
- #ifdef _SUPPORT_EVENT_PACKAGE
- if(p->m_iRefferedLine != -1)
- {
- PAL_DB("Reffered line existes.");
- string sBody ="SIP/2.0 ";
- sBody += itoa(p->m_iStatusCode);
- sBody +=" ";
- sBody += p->m_sReason;
- string sState;
- if(p->m_iStatusCode < 200) // 1XX response
- sState = "active";
- else
- sState = "terminated";
- int iRet = sipAccnt->m_pAgent->Notify(p->m_iRefferedLine,sBody,sState);
- if(iRet == -1)
- {
- PAL_DB("Notify sending err.");
- }
- else
- {
- PAL_DB("Notify sending success.");
- }
- }
- else
- {
- PAL_DB("Referred line doesn't exist.");
- }
- #endif
- }
- break;
- case EVENT_CALL_AUTHENTICATION:
- sipAccnt->m_pAgent->CallWithAuthorization(p->m_iLine);
- break;
- case EVENT_MAKE_REINVITE:
- sipAccnt->m_pAgent->SendUpdateReinvite(p->m_iLine);
- break;
- case EVENT_MAKE_RELAY_REINVITE:
- sipAccnt->m_pAgent->SendReinviteRelay(p->m_iLine);
- break;
- case EVENT_ICE_CHECK_COMPLETED:
- sipAccnt->m_pAgent->OpenSessionOnICECompleted(p->m_iLine);
- break;
- case EVENT_MOVE_TO_CONFERENCE:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(3);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutNumber(1, p->m_iAccnt);
- aMsg.PutBool(2, p->m_bVideoCall);
- FIRE_EVENT(OnMoveToConference, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnMoveToConference, p->m_iLine,
- p->m_iAccnt,
- ToVB(p->m_bVideoCall));
- #endif
- }
- break;
- case EVENT_UPDATE_CONFERENCE_LIST:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(2);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutNumber(1, p->m_iAccnt);
- FIRE_EVENT(OnConferenceMemberListUpdate, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnConferenceMemberListUpdate, p->m_iLine, p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_CALL_REQUEST:
- {
- //added to decide wheather the replace call will proceed or not.
- if (m_pCallLine->NumberOfSecureLines() > 1)
- {
- sipAccnt->m_pAgent->AutoRejectCall(p->m_iLine, true);
- break;
- }
- if (p->m_bSent)
- {
- sipAccnt->m_pAgent->AutoRejectCall(p->m_iLine, false, true);
- break;
- }
- if ((p->m_iLine < 0) || (m_pCallLine->GetUserMode() != MODE_AVAILABLE))
- {
- sipAccnt->m_pAgent->AutoRejectCall(p->m_iLine, false);//it will return immediately.
- break;
- }
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(7);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutString(1, p->m_sDisplayName);
- aMsg.PutString(2, p->m_sTargetURI);
- aMsg.PutNumber(3, p->m_bVideoCall);
- aMsg.PutNumber(4, p->m_iSpitRating);
- aMsg.PutNumber(5, p->m_iAccnt);
- aMsg.PutString(6, p->m_sReason);
- FIRE_EVENT(OnCallRequest, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnCallRequest, p->m_iLine,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- ToVB(p->m_bVideoCall),
- p->m_iSpitRating,
- p->m_iAccnt,
- ToBstr(p->m_sReason));
- #endif
- }
- break;
- case EVENT_END_CALL:
- //for supporting call transfer. If call transfer is active, then don't
- //fire EVENT_END_CALL event to the app.
- MSA_LOG("Ending call for account: " + itoa(p->m_iAccnt) + " line: " + itoa(p->m_iLine));
- if(p->m_bSent)//isCallTransfer active
- {
- PAL_DB("in EVENT_END_CALL: CallTransfer is enabled. ");
- if (!CheckCallURI(p->m_sProxyName, sipAccnt))//sCallURI
- {
- #ifdef _SUPPORT_EVENT_PACKAGE
- string sBody ="SIP/2.0 503 Service Unavailable";
- sipAccnt->m_pAgent->Notify(p->m_iRefferedLine,sBody,"terminated");
- #endif
- //fire end call event.
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutString(1, p->m_sDisplayName);
- aMsg.PutString(2, p->m_sTargetURI);
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnEndCall, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnEndCall, p->m_iLine,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- p->m_iAccnt);
- #endif
- }
- else
- {
- // attempt to re-use the previously selected line
- m_pCallLine->GrabOutboundLine(p->m_iLine);
- int iLine = m_pCallLine->GrabOutboundLine();
- if (iLine >= 0)
- {
- sipAccnt->m_pAgent->Call(p->m_sProxyName,iLine,p->m_iRefferedLine);
- }
- }
- }
- else
- {
- PAL_DB("in EVENT_END_CALL: CallTransfer is disabled. ");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutString(1, p->m_sDisplayName);
- aMsg.PutString(2, p->m_sTargetURI);
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnEndCall, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnEndCall, p->m_iLine,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_CALL_REDIRECT:
- // this is final response
- sipAccnt->m_sCallUri = "";
- KILL_TIMER(sipAccnt->m_iInviteResponseTimer);
- // attempt to re-use the previously selected line
- m_pCallLine->GrabOutboundLine(p->m_iLine);
- CSessionControl::Call(ToInternalBstr(p->m_sTargetURI), ToInternalBstr(""), ToBOOL(p->m_bAudioCall), ToBOOL(sipAccnt->m_bAnonymous) );
- break;
- case EVENT_REINVITE:
- sipAccnt->m_pAgent->HandleReinviteRequest(p->m_iLine, p->m_iProxy, (osip_transaction_t*)p->m_pData);
- break;
- case EVENT_REINVITE_REQUEST:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(6);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutString(1, p->m_sTargetURI);
- aMsg.PutString(2, p->m_sDisplayName);
- aMsg.PutNumber(3, p->m_bAudioCall);
- aMsg.PutNumber(4, p->m_bVideoCall);
- aMsg.PutNumber(5, p->m_iAccnt);
- FIRE_EVENT(OnReinviteRequest, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnReinviteRequest, p->m_iLine,
- ToBstr(p->m_sTargetURI),
- ToBstr(p->m_sDisplayName),
- ToVB(p->m_bAudioCall),
- ToVB(p->m_bVideoCall),
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_REINVITE_RESPONSE:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(6);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutString(1, p->m_sTargetURI);
- aMsg.PutString(2, p->m_sDisplayName);
- aMsg.PutNumber(3, p->m_bAudioCall);
- aMsg.PutNumber(4, p->m_bVideoCall);
- aMsg.PutNumber(5, p->m_iAccnt);
- FIRE_EVENT(OnReinviteResponse, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnReinviteResponse, p->m_iLine,
- ToBstr(p->m_sTargetURI),
- ToBstr(p->m_sDisplayName),
- ToVB(p->m_bAudioCall),
- ToVB(p->m_bVideoCall),
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_SIP_MESSAGE:
- {
- if (!p->m_bSent)
- {
- sipAccnt->m_pAgent->SetSelectedProxy(p->m_iProxy);
- sipAccnt->m_pAgent->HandleOsipEvent((osip_event_t*)p->m_pData);
- }
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- aMsg.PutNumber(0, p->m_bSent);
- aMsg.PutString(1, p->m_sProxyName);
- aMsg.PutString(2, p->m_sSipMessage);
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnSipMessage, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnSipMessage, ToVB(p->m_bSent),
- ToBstr(p->m_sProxyName),
- ToBstr(p->m_sSipMessage),
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_BYE_AUTHENTICATION:
- sipAccnt->m_pAgent->ByeWithAuthorization((osip_message_t*)p->m_pData);
- break;
- #ifdef _SUPPORT_EVENT_PACKAGE
- case EVENT_REFER_AUTHENTICATION:
- sipAccnt->m_pAgent->ReferWithAuthorization(p->m_iLine, (osip_message_t*)p->m_pData);
- break;
- case EVENT_SUBSCRIBE_AUTHENTICATION:
- sipAccnt->m_pAgent->SubscribeWithAuthorization(p->m_iLine, (osip_message_t*)p->m_pData);
- break;
- #endif
- case EVENT_TRANSPORT_ERROR:
- m_pFramework->Log("Transport error event");
- HandleTimeoutOrError(accnt, true);
- break;
- case EVENT_RECV_ERROR:
- {
- bool b = sipAccnt->m_pAgent->IsRecvErrorFromProxy(p->m_dwProxyAddr, p->m_wProxyPort);
- if (!b)
- {
- // connection to proxy is still alive.
- SAFE_DELETE(p);
- return 0;
- }
- m_pFramework->Log("Receive error event");
- HandleTimeoutOrError(accnt);
- }
- break;
- case EVENT_NAT_FAILURE:
- if (sipAccnt->m_pAgent->RefreshRegistration())
- SetRegistrationResponseTimer(accnt);
- break;
- case EVENT_RECEIVED_KEEP_ALIVE:
- sipAccnt->m_iSentKeepAliveCount = 0;
- break;
- case EVENT_LOGOUT_COMPLETE:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(1);
- aMsg.PutNumber(0, accnt);
- FIRE_EVENT(OnLogoutComplete, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnLogoutComplete, accnt);
- #endif
- if(sipAccnt->m_bAccountRemoved)
- {
- m_iSelectedAccount = p->m_iAccnt;
- Shutdown();
- //delete dynamic memory allocated in SipAccount.
- ReleaseAccount(sipAccnt);
- m_sipAccountMap.erase(p->m_iAccnt);
- SAFE_DELETE(sipAccnt);
- m_iSelectedAccount = INVALID_ACCOUNT_ID;
- MSA_LOG("Account: " + itoa(p->m_iAccnt) + " is now removed...");
- }
- }
- break;
- #ifdef _SUPPORT_EVENT_PACKAGE
- case EVENT_SUBCRIBE_RESPONSE:
- {
- PAL_DB("EVENT_SUBCRIBE_RESPONSE: ");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(5);
- aMsg.PutNumber(0, p->m_iStatusCode); //response code
- aMsg.PutString(1, p->m_sReason); //reason string
- aMsg.PutNumber(2,p->m_iLine);//eventType
- aMsg.PutNumber(3,p->m_iAccnt);
- #endif
- switch(p->m_iLine)//eventType
- {
- case EVENT_MWI:
- {
- if(p->m_iResponse > 0) // this field contains the expiry period of the sub. req.
- {
- SetMWIRefreshTimer(accnt);
- #ifdef USE_VARIANT_IN_EVENT
- aMsg.PutNumber(4,1);
- #endif
- }
- else if(p->m_iResponse == 0)
- {
- PAL_DB("MWI Timer is killed");
- KILL_TIMER(sipAccnt->m_iMWIRefreshTimer);
- #ifdef USE_VARIANT_IN_EVENT
- aMsg.PutNumber(4,0);
- #endif
- }
- else
- {
- #ifdef USE_VARIANT_IN_EVENT
- aMsg.PutNumber(4,-1);
- #endif
- }
- }
- break;
- case EVENT_REFER:
- break;
- case EVENT_CONFERENCE:
- break;
- case EVENT_CML:
- break;
- }
- //it should not fire for refresh MWI subscription.
- #ifdef USE_VARIANT_IN_EVENT
- FIRE_EVENT(OnSubscribeResponse, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnSubscribeResponse, p->m_iStatusCode,
- ToBstr(p->m_sReason),
- p->m_iLine,
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_NOTIFY_REQUEST:
- {
- PAL_DB2("in EVENT_NOTIFY_REQUEST: ", p->m_sSipMessage.c_str());
- //now need to separate 3 notification events: MWI, REFER, CONFERENCE.
- switch(p->m_iLine) //eventType
- {
- case EVENT_MWI:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(5);
- aMsg.PutBool(0,p->m_bSent); //messages
- aMsg.PutString(1, p->m_sDisplayName); // account
- aMsg.PutString(2, p->m_sProxyName); // message class
- aMsg.PutString(3, p->m_sSipMessage); //new/old
- aMsg.PutString(4, p->m_sTargetURI); //urgent new/old
- FIRE_EVENT(OnMessageWaitingIndication, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnMessageWaitingIndication, ToVB(p->m_bSent),
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sProxyName),
- ToBstr(p->m_sSipMessage),
- ToBstr(p->m_sTargetURI));
- #endif
- }
- break;
- case EVENT_REFER:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(3);
- aMsg.PutString(0,p->m_sReason); //package name.
- aMsg.PutString(1, p->m_sSipMessage); // message-body
- aMsg.PutNumber(2, p->m_iAccnt);
- FIRE_EVENT(OnRefer, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnRefer, ToBstr(p->m_sReason),
- ToBstr(p->m_sSipMessage),
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_CONFERENCE:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(3);
- aMsg.PutString(0,p->m_sReason); //package name.
- aMsg.PutString(1, p->m_sSipMessage); // message-body
- aMsg.PutNumber(2, p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_CML:
- {
- PAL_DB("conference member list notify request...");
- }
- break;
- }
- }
- break;
- case EVENT_REFER_REQUEST:
- {
- PAL_DB("EVENT_REFER_REQUEST");
- //1st send sync notify. This may not be a requirement.
- string sBody = "SIP/2.0 100 Trying";
- sBody +="\n";
- sipAccnt->m_pAgent->Notify(p->m_iLine,sBody,"active");
- #if 0 // for call transfer purpose.
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(5);
- aMsg.PutNumber(0,p->m_iLine);
- aMsg.PutString(1,p->m_sDisplayName);//from header.
- aMsg.PutString(2,p->m_sTargetURI); // refer uri.
- aMsg.PutString(3, p->m_sReason);//method name.
- aMsg.PutNumber(4, p->m_iAccnt);
- FIRE_EVENT(OnReferRequest, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnReferRequest, p->m_iLine,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- ToBstr(p->m_sReason),
- p->m_iAccnt);
- #endif
- #endif
- }
- break;
- case EVENT_OPTION_RESPONSE:
- {
- PAL_DB(" OPTION RESPONSE");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(6);
- aMsg.PutString(0,p->m_sDisplayName);//methods
- aMsg.PutString(1,p->m_sTargetURI); // content type
- aMsg.PutString(2, p->m_sProxyName);//codec
- aMsg.PutNumber(3,p->m_iStatusCode); // status code
- aMsg.PutString(4, p->m_sReason);//reason string
- aMsg.PutNumber(5, p->m_iAccnt);
- FIRE_EVENT(OnOptionResponse, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnOptionResponse, ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- ToBstr(p->m_sProxyName),
- p->m_iStatusCode,
- ToBstr(p->m_sReason),
- p->m_iAccnt);
- #endif
- }
- break;
- #endif // _SUPPORT_EVENT_PACKAGE
- case EVENT_FIREWALL_STATUS_CHANGE:
- {
- PAL_DB(" FIREWALL STATUS CHANGE");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(6);
- aMsg.PutNumber(0,p->m_iLine);
- aMsg.PutString(1,p->m_sDisplayName);
- aMsg.PutString(2,p->m_sTargetURI);
- aMsg.PutBool(3,p->m_bVideoCall);
- aMsg.PutString(4,p->m_sReason);
- aMsg.PutNumber(5, p->m_iAccnt);
- FIRE_EVENT(OnFirewallStatusChange, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnFirewallStatusChange, p->m_iLine,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- ToVB(p->m_bVideoCall),
- ToBstr(p->m_sReason),
- p->m_iAccnt);
- #endif
- }
- break;
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- case EVENT_BANDWIDTH_WARNING:
- {
- PAL_DB(" BANDWIDTH_WARNING");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(6);
- aMsg.PutNumber(0,p->m_iLine);
- aMsg.PutString(1,p->m_sDisplayName);
- aMsg.PutString(2,p->m_sTargetURI);
- aMsg.PutBool(3,p->m_bVideoCall);
- aMsg.PutString(4,p->m_sReason);
- aMsg.PutNumber(5, p->m_iAccnt);
- FIRE_EVENT(OnBandwidthWarning, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnBandwidthWarning, p->m_iLine,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- ToVB(p->m_bVideoCall),
- ToBstr(p->m_sReason),
- p->m_iAccnt);
- #endif
- }
- break;
- #endif
- case EVENT_CONFERENCE_JOIN:
- {
- m_pCallLine->NotifyConfList();
- SetUpdateConferenceListTimer();
- }
- break;
- case EVENT_CONFERENCE_QUERY:
- {
- m_pCallLine->QueryConfClient(p->m_iLine);
- }
- break;
- case EVENT_TEXT_MESSAGE:
- {
- //PAL_DB(" TEXT MESSAGE");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- BSTR bstrMsg = SysAllocStringByteLen((
- LPCSTR)(p->m_sSipMessage).data(),
- (p->m_sSipMessage).size());
- aMsg.PutString(0,p->m_sDisplayName);
- aMsg.PutString(1,p->m_sTargetURI);
- aMsg.PutBstr(2, (CComBSTR&)bstrMsg);
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnTextMessage, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnTextMessage,
- ToBstr(p->m_sDisplayName),
- ToBstr(p->m_sTargetURI),
- ToBstr(p->m_sSipMessage),
- p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_MESSAGE_USER_NOT_FOUND:
- break;
- #ifndef NO_DATA_TRAVELER
- case EVENT_DATATRANSFER_REQUEST:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(2);
- aMsg.PutString(0,p->m_sTargetURI);
- aMsg.PutNumber(1, p->m_iAccnt);
- FIRE_EVENT(OnDataRequest, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnDataRequest, ToBstr(p->m_sTargetURI), p->m_iAccnt);
- #endif
- }
- break;
- case EVENT_DATATRANSFER_UPDATE:
- {
- int id = p->m_iLine;
- int iSendStats = 0;
- int iRecvStats = 0;
- int iretSend = m_pDataTraveler->GetSendStatus(id, iSendStats);
- int iretRecv = m_pDataTraveler->GetRecvStatus(id, iRecvStats);
- if(iretRecv > 0)
- {
- #ifdef USE_VARIANT_IN_EVENT
- m_pFramework->Log("GetRecvStatus > 0");
- GeneralSafeArray aMsg(4);
- aMsg.PutString(0,p->m_sTargetURI);
- aMsg.PutString(1,"Recv Status");
- aMsg.PutString(2, "Data");
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnDataUpdate, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnDataUpdate, ToBstr(p->m_sTargetURI),
- ToBstr("Recv Status"),
- ToBstr("Data"),
- p->m_iAccnt);
- #endif
- }
- if(iretRecv == 0)
- {
- m_pFramework->Log("GetRecvStatus == 0");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- aMsg.PutString(0, p->m_sTargetURI);
- aMsg.PutString(1,"Recv Status");
- aMsg.PutString(2, "Close");
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnDataUpdate, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnDataUpdate, ToBstr(p->m_sTargetURI),
- ToBstr("Recv Status"),
- ToBstr("Close"),
- p->m_iAccnt);
- #endif
- }
- if(iretRecv < 0)
- {
- m_pFramework->Log("GetRecvStatus < 0");
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- aMsg.PutString(0,p->m_sTargetURI);
- aMsg.PutString(1,"Recv Status");
- aMsg.PutString(2, itoa(iRecvStats));
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnDataUpdate, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnDataUpdate, ToBstr(p->m_sTargetURI),
- ToBstr("Recv Status"),
- ToBstr(itoa(iRecvStats)),
- p->m_iAccnt);
- #endif
- }
- if(iSendStats >= 0)
- {
- m_pFramework->Log("GetSendStatus = " + itoa(iSendStats));
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(4);
- aMsg.PutString(0,p->m_sTargetURI);
- aMsg.PutString(1,"Send Status");
- aMsg.PutString(2, itoa(iSendStats));
- aMsg.PutNumber(3, p->m_iAccnt);
- FIRE_EVENT(OnDataUpdate, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnDataUpdate, ToBstr(p->m_sTargetURI),
- ToBstr("Send Status"),
- ToBstr(itoa(iSendStats)),
- p->m_iAccnt);
- #endif
- }
- }
- break;
- #endif
- case EVENT_SIP_CONNECTION_LOST:
- m_pFramework->Log("SIP connection lost event");
- HandleTimeoutOrError(accnt, true);
- break;
- case EVENT_SRTP_NOT_ENABLED:
- {
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(3);
- aMsg.PutNumber(0, p->m_iLine);
- aMsg.PutNumber(1, p->m_iAccnt);
- aMsg.PutString(2, p->m_sTargetURI);
- FIRE_EVENT(OnSRTPDisabled, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnSRTPDisabled, p->m_iLine, p->m_iAccnt, ToBstr(p->m_sTargetURI));
- #endif
- }
- break;
- }
- SAFE_DELETE(p);
- bHandled = TRUE;
- StopProfileTimer("OnFireEvent");
- return 0;
- }
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- LRESULT CSessionControl::OnAudioEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- switch (wParam) {
- case WM_AUDIO_NO_DATA:
- ThrowError("no audio data received");
- break;
- case WM_INVALID_MEDIA:
- ThrowError("invalid media");
- break;
- #ifdef PHILIPS
- case WM_REMOTE_SOUND_LEVEL:
- FIRE_EVENT(OnRemoteSoundLevel, lParam);
- break;
- #endif
- default:
- return -1;
- }
- return 0;
- }
- LRESULT CSessionControl::OnFunctionCall(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- switch (wParam) {
- case WM_FC_SIP_END_CALL:
- EndCall(lParam == 1);
- break;
- default:
- return -1;
- }
- return 0;
- }
- #endif
- void CSessionControl::HandleLogoutTimeoutOrError(int iAccnt)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- MSA_LOG("timer: " + itoa(sipAccnt->m_iLogoutResponseTimer));
- KILL_TIMER(sipAccnt->m_iLogoutResponseTimer);
- if (sipAccnt->m_pAgent->Logout(true/*failover*/))
- {
- #ifdef _CUSTOM_TIMER_
- sipAccnt->m_iLogoutResponseTimer = SetTimer(
- LOGOUT_RESPONSE_TIMER_ID + GetAccountID(sipAccnt),
- CUSTOM_LOGOUT_RESPONSE_TIMEOUT*1000);
- #else
- sipAccnt->m_iLogoutResponseTimer = SetTimer(
- LOGOUT_RESPONSE_TIMER_ID + GetAccountID(sipAccnt),
- LOGOUT_RESPONSE_TIMEOUT*1000);
- #endif
- }
- else
- {
- PAL_DB("No response for logout.");
- m_pFramework->Log("No response for logout. restore session network");
- sipAccnt->m_pAgent->HandleTimeoutOrError();
- sipAccnt->m_pAgent->RestoreSessionNetwork();
- HandleLogoutComplete(iAccnt);
- }
- }
- void CSessionControl::HandleTimeoutOrError(int iAccnt, bool bSipConnectionLost /* = false */)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- // transport error fired from transaction layer
- // recv error
- // x - invite response times out (no longer called)
- // register response times out
- // register renew times out
- // stun keep alive times out
- KILL_TIMER(sipAccnt->m_iRegistrationResponseTimer);
- KILL_TIMER(sipAccnt->m_iInviteResponseTimer);
- KILL_TIMER(sipAccnt->m_iRegistrationRefreshTimer);
- KILL_TIMER(sipAccnt->m_iSignalChannelKeepAliveTimer);
- #ifdef _SUPPORT_EVENT_PACKAGE
- KILL_TIMER(sipAccnt->m_iMWIRefreshTimer);
- #endif
- KILL_TIMER(m_iUpdateConferenceListTimer);
- if (sipAccnt->m_iLogoutResponseTimer)
- {
- HandleLogoutTimeoutOrError(iAccnt);
- return;
- }
- if (!sipAccnt->m_sCallUri.empty())
- {
- sipAccnt->m_pAgent->HandleCallTimeoutOrError();
- }
- // close framework and call line
- // reset registration state to idle
- // register to a new server if available
- // start response timer
- // start refresh-response timer?
- // reinvite if invite failed
- // fire no response during the first registration
- // fire connection lost during the rest registration
- if (sipAccnt->m_pAgent->HandleTimeoutOrError())
- {
- PAL_DB("Sip account already IDLE.");
- return;
- }
- m_pFramework->Log("HandleTimeoutOrError. restore session network");
- sipAccnt->m_pAgent->RestoreSessionNetwork();
- if (sipAccnt->m_bRegistered)
- {
- sipAccnt->m_bRegistered = false;
- sipAccnt->m_sCallUri = "";
- sipAccnt->m_pAgent->Logout(false);
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(1);
- aMsg.PutNumber(0, iAccnt);
- FIRE_EVENT(OnConnectionLost, aMsg.GetVariantRef());
- #else
- FIRE_EVENT(OnConnectionLost, iAccnt);
- #endif
- sipAccnt->m_pAgent->LogText("Connection Lost for account " + itoa(iAccnt));
- }
- else
- {
- if (sipAccnt->m_pAgent->HasNextProxyServerIndex()){
- RegisterFailOver(sipAccnt);
- }
- else{
- FireEventData* p = new FireEventData;
- PAL_ASSERT(p);
- p->m_iAccnt = iAccnt;
- p->m_iEventID = EVENT_REGISTER_RESPONSE;
- if (bSipConnectionLost)
- {
- p->m_iResponse = RESPONSE_FAILURE;
- p->m_sReason = "Tcp connection error.";
- }
- else
- {
- p->m_iResponse = RESPONSE_TIMEOUT;
- p->m_sReason = "Registration timed out.";
- }
- sipAccnt->m_pAgent->ResetRegistrationState();
- sipAccnt->m_pAgent->FireEvent(p);
- }
- }
- }
- void CSessionControl::HandleRefreshRegistrationComplete(int iAccnt)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- KILL_TIMER(sipAccnt->m_iRegistrationResponseTimer);
- }
- void CSessionControl::HandleLogoutComplete(int iAccnt)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- MSA_LOG("########### tttttimer: " + itoa(sipAccnt->m_iLogoutResponseTimer));
- KILL_TIMER(sipAccnt->m_iLogoutResponseTimer);
- sipAccnt->m_pAgent->RestoreSessionNetwork();
- FireEventData* p = new FireEventData;
- PAL_ASSERT(p);
- p->m_iAccnt = iAccnt;
- p->m_iEventID = EVENT_LOGOUT_COMPLETE;
- sipAccnt->m_pAgent->FireEvent(p);
- sipAccnt->m_pAgent->CloseConnection();
- }
- #ifdef _WIN32_WCE
- HRESULT CSessionControl::ThrowError(const string& sError)
- {
- CComBSTR bstr = ToBstr(sError);
- Fire_OnWinMobileError(bstr);
- return E_FAIL;
- }
- #else
- HRESULT CSessionControl::ThrowError(const string& sError)
- {
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- FIRE_EVENT(OnError, ToBstr(sError));
- return E_FAIL;
- #else
- return Error(ToBstr(sError), IID_ISipComm, E_FAIL);
- #endif
- }
- #endif
- STDMETHODIMP CSessionControl::SetProxyServer(int iIndex, BSTR bstrProxyServer, int iProxyPort)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sProxyServer = TruncateSpace(ToStringA(bstrProxyServer));
- sipAccnt->m_SipSetting.m_sProxyServer = sProxyServer;
- sipAccnt->m_SipSetting.m_iProxyPort = iProxyPort;
- sipAccnt->m_SipSetting.m_iProxyIndex = iIndex;
- sipAccnt->m_pAgent->SetProxy(iIndex, sProxyServer, iProxyPort);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetAccount(int iIndex, BSTR bstrSipUri, BSTR bstrAuthenticationID, BSTR bstrPassword)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- #ifdef SIP_URI_CASE_SENSITIVE
- string sURI = TruncateSpace(ToStringA(bstrSipUri));
- string sAuthID = TruncateSpace(ToStringA(bstrAuthenticationID));
- #else
- string sURI = tolower(TruncateSpace(ToStringA(bstrSipUri)));
- string sAuthID = tolower(TruncateSpace(ToStringA(bstrAuthenticationID)));
- #endif
- if (sURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!MediaSessionUtil::IsValidSIPURI(sURI))
- return ThrowError("ERROR: Invalid SIP URI.");
- MSA_LOG("Account: " + sURI + " accnt: " + itoa(m_iSelectedAccount));
- string sPassword = TruncateSpace(ToStringA(bstrPassword));
- sipAccnt->m_SipSetting.m_sSipUri = sURI;
- sipAccnt->m_SipSetting.m_sAuthID = sAuthID;
- sipAccnt->m_SipSetting.m_sPassword = sPassword;
- sipAccnt->m_pAgent->SetAccount(
- iIndex,
- sURI,
- sAuthID,
- sPassword);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetDomain(int iIndex, BSTR bstrDomain)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sDomain = TruncateSpace(ToStringA(bstrDomain));
- if (!AreURICharactersValid(sDomain))
- return ThrowError("ERROR: Invalid characters in domain.");
- sipAccnt->m_SipSetting.m_sDomain = sDomain;
- sipAccnt->m_pAgent->SetDomain(iIndex, sDomain);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetDisplayName(int iIndex, BSTR bstrDisplayName)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sDisplayName = TruncateSpace(ToStringA(bstrDisplayName));
- sipAccnt->m_SipSetting.m_sDisplayName = sDisplayName;
- sipAccnt->m_pAgent->SetDisplayName(iIndex, sDisplayName);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::Register()
- {
- m_pFramework->Log("Registering for account " + tostring(m_iSelectedAccount));
- #ifndef USE_NSSTREAM_FOR_SIP
- if (!m_bAFEngineInit)
- {
- if (m_pAFEngine->VersionCheckFailed())
- {
- return ThrowError("ERROR: AnyFirewallEngine version mismatch");
- }
- if (!m_pAFEngine->LoadLibraryFailed())
- {
- return ThrowError("ERROR: License expired");
- }
- return ThrowError("ERROR: AnyFirewallEngine failed to load");
- }
- #endif
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- StartProfileTimer("Register");
- sipAccnt->Configure(); //re-initialize an account's state in case
- //it was altered during an error.
- HRESULT hr = sipAccnt->m_pAgent->Register();
- if (FAILED(hr))
- {
- return hr;
- }
- sipAccnt->m_bRegistered = false;
- SetRegistrationResponseTimer(m_iSelectedAccount);
- StopProfileTimer("Register");
- return S_OK;
- }
- void CSessionControl::RegisterFailOver(SipAccount* sipAccnt)
- {
- StartProfileTimer("Register");
- sipAccnt->m_pAgent->ResetRegistrationState();
- // sipAccnt->Configure(); //re-initialize an account's state in case
- //it was altered during an error.
- // sipAccnt->m_pAgent->HandleTimeoutOrError();
- HRESULT hr = sipAccnt->m_pAgent->Register();
- if (FAILED(hr))
- {
- return;
- }
- sipAccnt->m_bRegistered = false;
- SetRegistrationResponseTimer(m_iSelectedAccount);
- StopProfileTimer("Register");
- return;
- }
- STDMETHODIMP CSessionControl::SetGatewayPreferences(VARIANT_BOOL bLocalMCLine, VARIANT_BOOL bEnableICE, VARIANT_BOOL bEnableNoSDPINVITE, VARIANT_BOOL bSupportSymmetricRTP)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetGatewayPreferences(Tobool(bLocalMCLine), Tobool(bEnableICE), Tobool(bEnableNoSDPINVITE), Tobool(bSupportSymmetricRTP));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::Call(BSTR bstrCallURI, BSTR bstrDomain, VARIANT_BOOL bAnonymous, VARIANT_BOOL bPhone, VARIANT_BOOL bConf)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- StartProfileTimer("Call");
- m_pFramework->Log("API Call()");
- CHECK_MEDIAFRAMEWORK();
- #ifdef SIP_URI_CASE_SENSITIVE
- string sCallURI = TruncateSpace(ToStringA(bstrCallURI));
- #else
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- #endif
- if (sCallURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sCallURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- string sDomain = tolower(TruncateSpace(ToStringA(bstrDomain)));
- if(!sDomain.empty())
- sCallURI += "@" + sDomain;
- string sHostPart = MediaSessionUtil::GetDomainNameFromURI(sCallURI);
- string sCallee = sCallURI;
- if (sHostPart.empty())
- {
- sCallee += "@" + sipAccnt->m_pAgent->GetDomainName();
- }
- if(m_pCallLine->IsDialogExists(sCallee))
- return ThrowError("ERROR: Already in call.");
- int iLineStatus = m_pCallLine->IsCallValid( -1, Tobool(bConf));
- if( -1 == iLineStatus)
- return ThrowError("ERROR: Only one line can be active at a time.");
- else if ( -2 == iLineStatus)
- return ThrowError("ERROR: Active conference.");
- else if( -3 == iLineStatus)
- return ThrowError("ERROR: Part of a remote conference.");
- if((sipAccnt->m_pAgent->IsSrtpEnabled() ) && (m_pCallLine->NumberOfSecureLines() > 0))
- return ThrowError("ERROR: Only one SRTP call can be established at a time.");
- m_pFramework->Log((string)"### Call to = " + sCallURI);
- if (!sipAccnt->m_pAgent->SmartSelectProxy(sCallURI))
- return ThrowError("ERROR: No proxy selected to make call.");
- int iLine = m_pCallLine->GrabOutboundLine();
- if (iLine < 0)
- return ThrowError("ERROR: No line is available to make call.");
- if (m_pCodecConfig->GetAudioFormats().empty() && m_pCodecConfig->GetVideoFormats().empty() )
- {
- m_pFramework->Log("Audio and Video codec are empty");
- return ThrowError("ERROR: Audio and video codec are empty.");
- }
- MakeNonBlockingCall(sipAccnt, sCallURI, iLine, -1, "", Tobool(bConf), Tobool(bAnonymous), Tobool(bPhone));
- m_pFramework->Log("API Call() returned");
- StopProfileTimer("Call");
- return S_OK;
- }
- void CSessionControl::MakeNonBlockingCall(
- SipAccount* sipAccnt,
- const std::string& sCallURI,
- int iLine,
- int iRefferedLine /* = -1 */,
- const std::string& sReplaceInfo /* = "" */,
- bool bConf /* = false */,
- bool bAnonymous /* = false */,
- bool bPhone /* = false */)
- {
- NonBlockingCallInfo* pInfo = new NonBlockingCallInfo;
- pInfo->pControl = this;
- pInfo->sipAccnt = sipAccnt;
- pInfo->sCallURI = sCallURI;
- pInfo->iLine = iLine;
- pInfo->iRefferedLine = iRefferedLine;
- pInfo->sReplaceInfo = sReplaceInfo;
- pInfo->bConf = bConf;
- pInfo->bAnonymous = bAnonymous;
- pInfo->bPhone = bPhone;
- pInfo->pThread = NULL;
- pInfo->bThreadDone = false;
- #if 0 //blocking
- PAL::Thread* pThread
- = new PAL::Thread(CSessionControl::NonBlockingCallThread, pInfo);
- if (pThread)
- {
- pThread->join();
- delete pThread;
- }
- #else //non-blocking
- { PAL::Critical_Section cs(*m_pNonBlockingCallMutex);
- if (m_bDisableCalls)
- {
- delete pInfo;
- }
- else
- {
- PAL::Thread* pThread
- = new PAL::Thread(CSessionControl::NonBlockingCallThread, pInfo);
- if (pThread)
- {
- pInfo->pThread = pThread;
- m_lsNonBlockingCallThreads.push_back(pInfo);
- }
- }
- } //end of critical section
- #endif
- }
- void* CSessionControl::NonBlockingCallThread(void* arg)
- {
- SET_CURRENT_THREAD_NAME;
- NonBlockingCallInfo* p = (NonBlockingCallInfo*)arg;
- if (!p)
- {
- PAL_DB_ASSERT(0 && "Bad argument to NonBlockingCallThread");
- return NULL;
- }
- //Wait on mutex for thread info to be pushed onto the list
- //Delete any old threads
- p->pControl->JoinNonBlockingCallThreads(false);
- p->sipAccnt->m_pAgent->Call(
- p->sCallURI,
- p->iLine,
- p->iRefferedLine,
- p->sReplaceInfo,
- p->bConf,
- p->bAnonymous,
- p->bPhone);
- p->sipAccnt->m_sCallUri = p->sCallURI;
- if (p->sipAccnt->m_iInviteResponseTimer)
- {
- p->pControl->KillTimer(p->sipAccnt->m_iInviteResponseTimer);
- p->sipAccnt->m_iInviteResponseTimer = 0;
- }
- #ifdef _CUSTOM_TIMER_
- p->sipAccnt->m_iInviteResponseTimer = p->pControl->SetTimer(
- INVITE_RESPONSE_TIMER_ID + p->pControl->GetAccountID(p->sipAccnt),
- CUSTOM_INVITE_RESPONSE_TIMEOUT*1000);
- #else
- p->sipAccnt->m_iInviteResponseTimer = p->pControl->SetTimer(
- INVITE_RESPONSE_TIMER_ID + p->pControl->GetAccountID(p->sipAccnt),
- INVITE_RESPONSE_TIMEOUT*1000);
- #endif
- p->bThreadDone = true;
- return NULL;
- }
- void CSessionControl::MakeNonBlockingRespondCall(
- SipAccount* sipAccnt,
- int iLine,
- bool bAccept,
- bool bConf)
- {
- NonBlockingRespondCallInfo* pInfo = new NonBlockingRespondCallInfo;
- pInfo->pControl = this;
- pInfo->sipAccnt = sipAccnt;
- pInfo->iLine = iLine;
- pInfo->bAccept = bAccept;
- pInfo->bConf = bConf;
- pInfo->pThread = NULL;
- pInfo->bThreadDone = false;
- #if 0 //blocking
- PAL::Thread* pThread
- = new PAL::Thread(CSessionControl::NonBlockingRespondCallThread, pInfo);
- if (pThread)
- {
- pThread->join();
- delete pThread;
- }
- #else //non-blocking
- { PAL::Critical_Section cs(*m_pNonBlockingCallMutex);
- if (m_bDisableCalls)
- {
- delete pInfo;
- }
- else
- {
- PAL::Thread* pThread
- = new PAL::Thread(CSessionControl::NonBlockingRespondCallThread, pInfo);
- if (pThread)
- {
- pInfo->pThread = pThread;
- m_lsNonBlockingRespondCallThreads.push_back(pInfo);
- }
- }
- } //end of critical section
- #endif
- }
- void* CSessionControl::NonBlockingRespondCallThread(void* arg)
- {
- SET_CURRENT_THREAD_NAME;
- NonBlockingRespondCallInfo* p = (NonBlockingRespondCallInfo*)arg;
- if (!p)
- {
- PAL_DB_ASSERT(0 && "Bad argument to NonBlockingRespondCallThread");
- return NULL;
- }
- //Wait on mutex for thread info to be pushed onto the list
- //Delete any old threads
- p->pControl->JoinNonBlockingCallThreads(false);
- p->sipAccnt->m_pAgent->RespondCall(
- p->iLine,
- p->bAccept,
- p->bConf);
- p->bThreadDone = true;
- return NULL;
- }
- void CSessionControl::JoinNonBlockingCallThreads(bool bWait)
- {
- { PAL::Critical_Section cs(*m_pNonBlockingCallMutex);
- //Close Call Threads
- {
- std::list<NonBlockingCallInfo*>::iterator iter;
- std::list<NonBlockingCallInfo*>::iterator iterEnd;
- iter = m_lsNonBlockingCallThreads.begin();
- iterEnd = m_lsNonBlockingCallThreads.end();
- //Close threads that are "done"
- while (iter != iterEnd)
- {
- NonBlockingCallInfo* pInfo = (*iter);
- if (pInfo)
- {
- if (bWait || pInfo->bThreadDone)
- {
- //Thread is finished
- if (pInfo->pThread)
- {
- pInfo->pThread->join();
- delete pInfo->pThread;
- }
- delete pInfo;
- m_lsNonBlockingCallThreads.erase(iter++);
- }
- else
- {
- ++iter;
- }
- }
- else
- {
- //erase NULL pointer
- PAL_DB_ASSERT(0 && "NULL in nonblocking call thread list");
- m_lsNonBlockingCallThreads.erase(iter++);
- }
- }
- } //Done Close Call Threads
- //Close RespondCall Threads
- {
- std::list<NonBlockingRespondCallInfo*>::iterator iter;
- std::list<NonBlockingRespondCallInfo*>::iterator iterEnd;
- iter = m_lsNonBlockingRespondCallThreads.begin();
- iterEnd = m_lsNonBlockingRespondCallThreads.end();
- //Close threads that are "done"
- while (iter != iterEnd)
- {
- NonBlockingRespondCallInfo* pInfo = (*iter);
- if (pInfo)
- {
- if (bWait || pInfo->bThreadDone)
- {
- //Thread is finished
- if (pInfo->pThread)
- {
- pInfo->pThread->join();
- delete pInfo->pThread;
- }
- delete pInfo;
- m_lsNonBlockingRespondCallThreads.erase(iter++);
- }
- else
- {
- ++iter;
- }
- }
- else
- {
- //erase NULL pointer
- PAL_DB_ASSERT(0 && "NULL in nonblocking respond call thread list");
- m_lsNonBlockingRespondCallThreads.erase(iter++);
- }
- }
- }//Done Close RespondCall Threads
- } //end of critical section
- }
- #ifdef _SUPPORT_EVENT_PACKAGE
- STDMETHODIMP CSessionControl::ReferredCall(BSTR bstrCallURI, BSTR bstrRefferedLine, VARIANT_BOOL bAccept)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sLine = tolower(TruncateSpace(ToStringA(bstrRefferedLine)));
- string sBody = "SIP/2.0 503 Service Unavailable";
- int iLineNo = atoi(sLine.c_str());
- PAL_DB2("Line no: ", iLineNo);
- //check wheather SDK got the permission from user.
- if(!ToBOOL(bAccept))
- {
- PAL_DB("User didn't give permission");
- int iRet = sipAccnt->m_pAgent->Notify(iLineNo,sBody,"terminated");
- if(iRet == -1)
- {
- PAL_DB("Notify sending err.");
- }
- else
- {
- PAL_DB("Notify sending success.");
- }
- return S_OK;
- }
- CHECK_MEDIAFRAMEWORK();
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- if (sCallURI.empty())
- {
- sipAccnt->m_pAgent->Notify(iLineNo,sBody,"terminated");
- return ThrowError("ERROR: No SIP URI is given");
- }
- if (!CheckCallURI(sCallURI, sipAccnt))
- {
- sipAccnt->m_pAgent->Notify(iLineNo,sBody,"terminated");
- return ThrowError("ERROR: Invalid SIP URI.");
- }
- if (!sipAccnt->m_pAgent->IsRegistered())
- {
- sipAccnt->m_pAgent->Notify(iLineNo,sBody,"terminated");
- return ThrowError("ERROR: Not registered yet.");
- }
- int iLine = m_pCallLine->GrabOutboundLine();
- if (iLine < 0)
- {
- sipAccnt->m_pAgent->Notify(iLineNo,sBody,"terminated");
- return ThrowError("ERROR: No line is avaialable to make call.");
- }
- if (m_pCodecConfig->GetAudioFormats().empty() && m_pCodecConfig->GetVideoFormats().empty() )
- {
- m_pFramework->Log("Audio and Video codec are empty");
- return ThrowError("ERROR: Audio and video codec are empty.");
- }
- MakeNonBlockingCall(sipAccnt,sCallURI,iLine,iLineNo);
- return S_OK;
- }
- #endif //_SUPPORT_EVENT_PACKAGE
- //TBD: try to determine the account ID from the URI.
- STDMETHODIMP CSessionControl::TransferCall(BSTR bstrTransferURI)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sReferURI = tolower(TruncateSpace(ToStringA(bstrTransferURI)));
- if (sReferURI.empty())
- return ThrowError("ERROR: No SIP URI is given ");
- if (!CheckCallURI(sReferURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- int iSelectedLine = m_pCallLine->GetSelectedLine();
- string sTargetURI;
- if ( !sipAccnt->m_pAgent->GetCallTransferParams(iSelectedLine, sTargetURI,false) ) //callee
- {
- if ( !sipAccnt->m_pAgent->GetCallTransferParams(iSelectedLine, sTargetURI, true) ) //caller
- {
- PAL_DB("User is not callee. Call Transfer failed");
- return ThrowError("ERROR: Call Transfer failed.");
- }
- }
- if( sTargetURI.empty() )
- {
- return ThrowError("ERROR: TargetURI is empty Call Transfer.");
- }
- #ifdef _SUPPORT_EVENT_PACKAGE
- int iRet = sipAccnt->m_pAgent->Refer(sTargetURI,sReferURI,"invite");
- if (iRet < 0)
- return ThrowError("ERROR: Refer failed in Call Transfer.");
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::EndCall(VARIANT_BOOL bAllCall)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- StartProfileTimer("EndCall");
- m_pFramework->Log("End Call");
- /////////////////////////////////////////
- sipAccnt->m_sCallUri = "";
- KILL_TIMER(sipAccnt->m_iInviteResponseTimer);
- //if endAllCalls, end calls on the selected sip account
- if (ToBOOL(bAllCall))
- {
- sipAccnt->m_pAgent->EndAllCall();
- }
- else
- {
- //else end the call on the selected line.
- CallDialog* p = m_pCallLine->GetSelectedDialog();
- if (!p)
- {
- // Maybe still in Call thread, so no CallDialog is still present in m_pCallLine
- // So make sure the Call thead finishes its operation thereby adding its CallDialog
- m_pFramework->Log("Trying to end a call but dialog doesn't exist. Waiting for all Call threads to exit...");
- JoinNonBlockingCallThreads(true);
- p = m_pCallLine->GetSelectedDialog();
- m_pFramework->Log("Waiting done.");
- }
- if (!p)
- return ThrowError("ERROR: EndCall::Invalid Line");
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->EndCall();
- }
- StopProfileTimer("EndCall");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::RespondCall(int iLine, VARIANT_BOOL bAccept, VARIANT_BOOL bConf)
- {
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p)
- {
- return ThrowError("ERROR: RespondCall::Invalid Line");
- }
- if( Tobool(bAccept))
- {
- int iLineStatus = m_pCallLine->IsCallValid(iLine, Tobool(bConf));
- if( -1 == iLineStatus)
- return ThrowError("ERROR: Another one-one call Active.");
- else if ( -2 == iLineStatus)
- return ThrowError("ERROR: Active conference.");
- else if( -3 == iLineStatus)
- return ThrowError("ERROR: Part of a remote conference.");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- CHECK_MEDIAFRAMEWORK();
- MakeNonBlockingRespondCall(sipAccnt, iLine, Tobool(bAccept), Tobool(bConf));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::Subscribe(BSTR bstrCallURI)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- if (sCallURI.empty())
- return ThrowError("ERROR: No SIP URI is given");
- if (!CheckCallURI(sCallURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- int iLine = sipAccnt->m_pAgent->Subscribe(sCallURI);
- if (iLine < 0)
- return ThrowError("ERROR: Subscribe failed.");
- return S_OK;
- }
- #ifdef _SUPPORT_EVENT_PACKAGE
- STDMETHODIMP CSessionControl::MWISubscribe(BSTR bstrResourceURI)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sResourceURI = tolower(TruncateSpace(ToStringA(bstrResourceURI)));
- if (sResourceURI.empty())
- return ThrowError("ERROR: No SIP URI is given");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- int iLine = sipAccnt->m_pAgent->MwiSubscribe(sResourceURI);
- if (iLine < 0)
- return ThrowError("ERROR: MWI Subscribe already done.");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::MWIUnSubscribe()
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- int iLine = sipAccnt->m_pAgent->UnSubscribe();
- if (iLine < 0)
- return ThrowError("ERROR: Not Subscribe yet.");
- KILL_TIMER(sipAccnt->m_iMWIRefreshTimer);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::Refer(BSTR bstrCallURI,BSTR bstrReferURI,BSTR bstrMethod)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- if (sCallURI.empty())
- return ThrowError("ERROR: No SIP URI is given");
- if (!CheckCallURI(sCallURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- string sReferURI = tolower(TruncateSpace(ToStringA(bstrReferURI)));
- if (sReferURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sReferURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- string sMethod = tolower(TruncateSpace(ToStringA(bstrMethod)));
- int iLine = sipAccnt->m_pAgent->Refer(sCallURI,sReferURI,"invite");
- if (iLine < 0)
- return ThrowError("ERROR: Refer failed.");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::Option(BSTR bstrCallURI)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- if (sCallURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sCallURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- int iLine = sipAccnt->m_pAgent->Option(sCallURI);
- if (iLine < 0)
- return ThrowError("ERROR: Option failed.");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ReplaceCall(BSTR bstrCallURI,BSTR bstrDialogInfo)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_MEDIAFRAMEWORK();
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- if (sCallURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sCallURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- string sDialogInfo = TruncateSpace(ToStringA(bstrDialogInfo));
- PAL_DB2("Dialog Info: ", sDialogInfo.c_str());
- int iLine = m_pCallLine->GrabOutboundLine();
- if (iLine < 0)
- return ThrowError("ERROR: No line is available to make call.");
- if (m_pCodecConfig->GetAudioFormats().empty() && m_pCodecConfig->GetVideoFormats().empty() )
- {
- m_pFramework->Log("Audio and Video codec are empty");
- return ThrowError("ERROR: Audio and video codec are empty.");
- }
- MakeNonBlockingCall(sipAccnt,sCallURI,iLine,-1,sDialogInfo);
- return S_OK;
- }
- #endif
- //Dhaka 4-6-2005
- STDMETHODIMP CSessionControl::Notify(BSTR bstrCallURI)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_MEDIAFRAMEWORK();
- string sCallURI = tolower(TruncateSpace(ToStringA(bstrCallURI)));
- int iLine = sipAccnt->m_pAgent->Notify(sCallURI);
- if (iLine < 0)
- return ThrowError("ERROR: Notify failed.");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SendDTMF(BSTR bstrKey)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_MEDIAFRAMEWORK();
- string sKey = ToString(bstrKey).mbs();
- char cDigit = atoi(sKey.c_str());
- if ((cDigit >= 10) || (cDigit < 0))
- {
- return S_FALSE;
- }
- if (cDigit == 0)
- {
- if (sKey == "*")
- cDigit = '*';
- else if (sKey == "#")
- cDigit = '#';
- else
- cDigit = '0';
- }
- else
- {
- cDigit = sKey.at(0);
- }
- if(sipAccnt->m_iSipInfoDtmf == 0) //RFC 2833
- sipAccnt->m_pAgent->SendDTMF(cDigit, false);
- else if(sipAccnt->m_iSipInfoDtmf == 1) //SIP INFO
- sipAccnt->m_pAgent->SendSipInfoDTMF(cDigit);
- else //inband
- sipAccnt->m_pAgent->SendDTMF(cDigit, true);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_IsLineIdle(VARIANT_BOOL* pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = m_pCallLine->IsLineIdle();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetLineStatus(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- int i = m_pCallLine->GetCallStatus();
- string s;
- switch (i)
- {
- case CALL_IDLE:
- s = "idle";
- break;
- case CALL_CALLING:
- s = "calling";
- break;
- case CALL_RINGING:
- s = "ringing";
- break;
- case CALL_PROCEEDING:
- s = "proceeding";
- break;
- case CALL_COMPLETED:
- s = "established";
- break;
- }
- if (m_pCallLine->IsLineHeld())
- s = "on hold"; // red
- // for Zunnun
- CallDialog* pDlg = m_pCallLine->GetSelectedDialog();
- if (NULL != pDlg)
- {
- if(pDlg->m_bHold && pDlg->m_bRemoteHold)
- {
- s = "on hold by both"; //
- }
- else if(pDlg->m_bRemoteHold)
- {
- s = "on hold by remote"; // orange
- }
- }
- BstrFromString(pVal, s);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetDisplayName(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- string s = m_pCallLine->GetDisplayName();
- BstrFromString(pVal, s);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetCallURI(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- string s = m_pCallLine->GetTargetURI();
- BstrFromString(pVal, s);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_HoldLine(VARIANT_BOOL *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = ToVB(m_pCallLine->IsLineHeld());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_LineStatusChanging(VARIANT_BOOL *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = ToVB(m_pCallLine->IsLineStatusChanging());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetFirewallStatus(int iLine, BSTR* pVal)
- {
- CHECK_POINTER(pVal);
- CallDialog* pDlg = m_pCallLine->GetDialog(iLine);
- if (pDlg == NULL) {
- tstring status = "";
- BstrFromString(pVal, status);
- }
- else {
- string sFirewallStatus = pDlg->m_sFirewallStatus;
- if(sFirewallStatus == "UDP Relay" || sFirewallStatus == "TCP Relay" || sFirewallStatus == "HTTP Relay")
- {
- sFirewallStatus = "Relay";
- }else if (sFirewallStatus == "Eyeball")
- {
- sFirewallStatus = "";
- }
- BstrFromString(pVal, sFirewallStatus);
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SendTextMessage(BSTR bstrURI, BSTR bstrText)
- {
- //GET AGENT, FROM THERE GET DOMAIN, APPEND IT...
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sURI = tolower(TruncateSpace(ToStringA(bstrURI)));
- if (sURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- int nLen = SysStringByteLen(bstrText);
- const char* pBuf = (const char*)bstrText;
- #else
- int nLen = bstrText.length();
- const char* pBuf = bstrText.c_str();
- #endif
- string sData;
- sData.assign(pBuf, nLen);
- sipAccnt->m_pAgent->SendUserMessage(ToStringA(bstrURI), sData);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SendData(BSTR bstrURI, BSTR bstrData)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sURI = tolower(TruncateSpace(ToStringA(bstrURI)));
- if (sURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- if (NULL == bstrData)
- #else
- if ( bstrData.length() == 0 )
- #endif
- {
- return ThrowError("ERROR: NULL data");
- }
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- int nLen = SysStringByteLen(bstrData);
- const char* pBuf = (const char*)bstrData;
- #else
- int nLen = bstrData.length();
- const char* pBuf = bstrData.c_str();
- #endif
- string sData;
- sData.assign(pBuf, nLen);
- m_pFramework->Log("DATATRANSFER send data size = " + itoa(nLen));
- if(!sipAccnt->m_pAgent->SendUserData(ToStringA(bstrURI), sData))
- return ThrowError("ERROR: Failed to send data");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::RespondData(BSTR bstrURI, VARIANT_BOOL bAccept)
- {
- #ifndef NO_DATA_TRAVELER
- //bstrURI is guaranteed to be in "user@domain" form
- //if application passes to us what it recieved in
- //OnDataUpdate event.
- CDataDialog *p = NULL;
- p = m_pDataTraveler->FindDataDialog(ToStringA(bstrURI));
- if(!p)
- {
- return ThrowError("ERROR: URI is malformed.");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAccnt);
- RET_ERROR_STR(sipAccnt);
- string sURI = tolower(TruncateSpace(ToStringA(bstrURI)));
- if (sURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- sipAccnt->m_pAgent->RespondUserData(ToStringA(bstrURI), Tobool(bAccept));
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::EndData(BSTR bstrURI)
- {
- #ifndef NO_DATA_TRAVELER
- //we end data on selected account.
- //If user provides "user@domain" bstrURI, we can
- //end it on any account. TBD.
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sURI = tolower(TruncateSpace(ToStringA(bstrURI)));
- if (sURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- sipAccnt->m_pAgent->EndUserData(ToStringA(bstrURI));
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::RecvData(BSTR bstrURI, BSTR* pVal)
- {
- #ifndef NO_DATA_TRAVELER
- //bstrURI is guaranteed to be in "user@domain" form
- //if application passes to us what it recieved in
- //OnDataUpdate event.
- CDataDialog *p = NULL;
- p = m_pDataTraveler->FindDataDialog(ToStringA(bstrURI));
- if(!p)
- {
- return ThrowError("ERROR: URI is malformed.");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAccnt);
- RET_ERROR_STR(sipAccnt);
- string sURI = tolower(TruncateSpace(ToStringA(bstrURI)));
- if (sURI.empty())
- return ThrowError("ERROR: No SIP URI is given.");
- if (!CheckCallURI(sURI, sipAccnt))
- return ThrowError("ERROR: Invalid SIP URI.");
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- string recvData;
- sipAccnt->m_pAgent->RecvUserData(ToStringA(bstrURI), recvData);
- m_pFramework->Log("DATATRANSFER RecvData, size = " + itoa(recvData.size()));
- #ifndef __unix__
- *pVal = SysAllocStringByteLen((LPCSTR)recvData.data(), recvData.size());
- #endif
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_HoldMediaInLine(VARIANT_BOOL bAudio, VARIANT_BOOL bVideo)
- {
- CHECK_MEDIAFRAMEWORK();
- return m_pCallLine->HoldMedia(Tobool(bAudio), Tobool(bVideo)) ? S_OK : E_FAIL;
- }
- STDMETHODIMP CSessionControl::put_HoldLine(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- return m_pCallLine->HoldLine(Tobool(newVal)) ? S_OK : E_FAIL;
- }
- STDMETHODIMP CSessionControl::put_HoldConference(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- //for unhold conf, check pre-condition
- if( false == Tobool(newVal) )
- {
- if(m_pCallLine->IsAnyActiveCall(-1))
- return S_OK;
- }
- m_pFramework->m_mediaFramework->put_HoldConference(ToVB(newVal));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_HoldConference(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_HoldConference(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_ConferenceLine(VARIANT_BOOL newVal)
- {
- //move to conference
- CHECK_MEDIAFRAMEWORK();
- CallDialog* pDlg = m_pCallLine->GetSelectedDialog();
- if(!pDlg)
- return S_OK;
- bool bConf = Tobool(newVal);
- m_pFramework->Log("Putting line " + tostring(pDlg->m_iLine) + " conference state to " + tostring(bConf) + ". Old state conf " + tostring(pDlg->m_bConf) + ", remote conf " + tostring(pDlg->m_bRemoteConf) + ", hold " + tostring(pDlg->m_bHold) + ", remote hold " + tostring(pDlg->m_bRemoteHold));
- if(bConf) //move to conference
- {
- if(pDlg->m_bConf) //already in conference
- return S_OK;
- if(/*pDlg->m_bRemoteHold ||*/ pDlg->m_bRemoteConf)
- return S_OK;
- if(pDlg->m_bHold) //unhold first
- m_pCallLine->HoldLine(false);
- if(m_pCallLine->NumberOfSecureLines() > 0)
- return ThrowError("ERROR: Cannot add secure line to conference.");
- m_pFramework->MoveToConference(pDlg);
- }
- else //remove from conference
- {
- if(!pDlg->m_bConf) //already removed from conf.
- return S_OK;
- m_pCallLine->NotifyConfRemove(pDlg->m_iLine);
- m_pFramework->RemoveFromConference(pDlg);
- m_pCallLine->HoldLine(true);
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_ConferenceLine(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- *pVal = VARIANT_FALSE;
- CallDialog* pDlg = m_pCallLine->GetSelectedDialog();
- if(!pDlg)
- return S_OK;
- if(pDlg->m_bConf)
- *pVal = VARIANT_TRUE;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_NoSdpInvite(VARIANT_BOOL *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = ToVB(sipAccnt->m_pAgent->GetNoSdpInvite());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_NoSdpInvite(VARIANT_BOOL newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetNoSdpInvite(Tobool(newVal));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_MuteSender(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_Mute(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_MuteSender(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_Mute(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_SelectedLine(int *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = m_pCallLine->GetSelectedLine();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_SelectedLine(int newVal)
- {
- if(m_pCallLine->GetSelectedLine() != newVal){
- m_pCallLine->SetSelectedLine(newVal);
- m_pFramework->Log("### Selected Line = " + itoa(newVal));
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_ConferenceLine(int *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = m_pCallLine->GetConferenceLine();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_ConferenceLine(int newVal)
- {
- m_pCallLine->SetConferenceLine(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_MaximumLine(int *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = m_pCallLine->GetMaximumLine();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_MaximumLine(int newVal)
- {
- m_pCallLine->SetMaximumLine(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_UserMode(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- int iMode = m_pCallLine->GetUserMode();
- string sMode;
- switch (iMode)
- {
- case MODE_AVAILABLE:
- sMode = "available";
- break;
- case MODE_AWAY:
- sMode = "away";
- break;
- case MODE_DND:
- sMode = "DND";
- break;
- }
- BstrFromString(pVal, sMode);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_UserMode(BSTR newVal)
- {
- string sMode = tolower(ToStringA(newVal));
- int iMode;
- if (sMode == "available")
- {
- iMode = MODE_AVAILABLE;
- }
- else if (sMode == "away")
- {
- iMode = MODE_AWAY;
- }
- else if (sMode == "dnd")
- {
- iMode = MODE_DND;
- }
- else
- {
- return ThrowError("ERROR: Invalid user mode.");
- }
- m_pCallLine->SetUserMode(iMode);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_CallHistorySize(VARIANT_BOOL bDialed, int *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = m_pCallHistory->GetHistorySize(Tobool(bDialed));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_CallHistorySize(VARIANT_BOOL bDialed, int newVal)
- {
- if (newVal < 0)
- return ThrowError("ERROR: Invalid call history size.");
- m_pCallHistory->SetHistorySize(Tobool(bDialed), newVal);
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetCallHistory(VARIANT_BOOL bDialed, SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetCallHistory(VARIANT_BOOL bDialed, std::vector<std::string> *pVal)
- #endif
- {
- CHECK_POINTER(pVal);
- CallHistoryList callList;
- m_pCallHistory->GetCallHistory(Tobool(bDialed), callList);
- CallHistoryList::iterator iter = callList.begin();
- #ifdef USE_VARIANT_IN_EVENT
- GeneralSafeArray aMsg(callList.size() * 4);
- for (int i = 0; iter != callList.end(); iter++)
- {
- CallHistoryElement& v = *iter;
- aMsg.PutString(i++, v.m_sDisplayName);
- aMsg.PutString(i++, v.m_sTargetURI);
- aMsg.PutString(i++, v.m_sCallingTime);
- aMsg.PutNumber(i++, v.m_iDuration);
- }
- aMsg.Detach(pVal);
- #else
- pVal->clear();
- for(; iter != callList.end(); iter++)
- {
- CallHistoryElement& v = *iter;
- pVal->push_back(v.m_sDisplayName);
- pVal->push_back(v.m_sTargetURI);
- pVal->push_back(v.m_sCallingTime);
- pVal->push_back(itoa(v.m_iDuration));
- }
- #endif
- return S_OK;
- }
- #if defined(WIN32) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- STDMETHODIMP CSessionControl::GetCallDetail(int iLine, SAFEARRAY **pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- if (!sipAccnt->m_pAgent->IsRegistered())
- return ThrowError("ERROR: Not registered yet.");
- vector<string> vCallInfo;
- int iRet = sipAccnt->m_pAgent->GetCallDetail(iLine,vCallInfo);
- if( iRet != 0 )
- return ThrowError("ERROR: Line Doesn't exists.");
- int iSize = vCallInfo.size();
- GeneralSafeArray aMsg(iSize);
- /*
- * aMsg(0) contains Called ID.If P-Called-Party-ID header not present,
- * then it is empty string.
- * aMsg(1,2 or more) contains Caller ID.
- * sizeof(aMsg) = 1 + #PAID present in INVITE message.
- */
- for(int i=0; i< iSize; i++)
- {
- aMsg.PutString(i, vCallInfo[i]);
- }
- aMsg.Detach(pVal);
- return S_OK;
- }
- #endif
- STDMETHODIMP CSessionControl::get_ForwardURI(BSTR *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- BstrFromString(pVal, sipAccnt->m_pAgent->m_sForwardURI);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_ForwardURI(BSTR newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetForwardURI(ToStringA(newVal));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ForwardCall(int iLine, BSTR bstrURI, BSTR bstrReason)
- {
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p)
- {
- return ThrowError("ERROR: ForwardCall::Invalid Line");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- string sURI = ToStringA(bstrURI);
- if (sURI.empty())
- return ThrowError("ERROR: ForwardCall::Invalid URI.");
- string sReason = ToStringA(bstrReason);
- sipAccnt->m_pAgent->ForwardCall(iLine, sURI, sReason);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_CallHistoryFileName(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- BstrFromString(pVal, m_pCallHistory->GetFileName());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_CallHistoryFileName(BSTR newVal)
- {
- m_pCallHistory->SetFileName(ToString(newVal));
- #ifdef __unix__
- m_pCallHistory->LoadCallHistory();
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::RemoveCallHistory(VARIANT_BOOL bDialed, int iIndex)
- {
- m_pCallHistory->RemoveCallHistory(Tobool(bDialed), iIndex);
- m_pCallHistory->SaveCallHistory();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GrabLine(int iLineToGrab, int *iLineGrabbed)
- {
- CHECK_POINTER(iLineGrabbed);
- #ifdef NO_SIP
- *iLineGrabbed = -1;
- if(m_pCallLine->GetDialog(iLineToGrab)){
- return ThrowError("Line is already in use.");
- }
- if(iLineToGrab >= 0 && iLineToGrab < m_pCallLine->GetMaximumLine()){
- *iLineGrabbed = iLineToGrab;
- }
- if(*iLineGrabbed == -1){
- for (int i = 0; i < m_pCallLine->GetMaximumLine(); i++)
- {
- if (!m_pCallLine->GetDialog(i))
- {
- *iLineGrabbed = i;
- break;
- }
- }
- }
- if(*iLineGrabbed >= 0 && *iLineGrabbed < m_pCallLine->GetMaximumLine()){
- CallDialog dlg;
- m_pCallLine->AddDialog(*iLineGrabbed, dlg);
- }
- else{
- return ThrowError("Error in grabbling line.");
- }
- #else
- *iLineGrabbed = m_pCallLine->GrabOutboundLine(iLineToGrab);
- #endif
- m_pFramework->Log((string)"### Grab Line = " + itoa(iLineToGrab) + " Grabbed = " + itoa(*iLineGrabbed));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ReleaseLine()
- {
- m_pCallLine->FreeOutboundLine();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_EnablePreview(VARIANT_BOOL *pVal)
- {
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_EnablePreview(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnablePreview(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_EnablePreview(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_ImageSize(int *pVal)
- {
- #ifndef __NOVIDEO__
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_ImageSize(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_ImageSize(int newVal)
- {
- #ifndef __NOVIDEO__
- CHECK_MEDIAFRAMEWORK();
- //if (INVALID_IMAGE_SIZE(newVal))
- // return ThrowError("ERROR: Image size out of range.");
- m_pFramework->m_mediaFramework->put_ImageSize(newVal);
- #endif
- return S_OK;
- }
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- STDMETHODIMP CSessionControl::AttachVideoWindow(int iLine, void *pWnd)
- {
- #if !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- if (iLine == -1)
- m_pFramework->m_mediaFramework->SetPreviewWindow(pWnd);
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p)
- {
- return S_OK;//Dont throw Error. We use line = -1 for attaching preview window.
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->AttachVideoWindow(iLine, 0, pWnd);
- #endif
- return S_OK;
- }
- #else
- STDMETHODIMP CSessionControl::AttachVideoWindow(int iLine, int nWnd)
- {
- CHECK_MEDIAFRAMEWORK();
- HWND hWnd = (HWND)nWnd; // convert type
- if ((!hWnd) || (!::IsWindow(hWnd)))
- {
- #ifndef _WIN32_WCE
- return Error("Invalid window handle");
- #else
- return ThrowError("ERROR: Invalid window handle");
- #endif
- }
- DWORD dwProcessId = 0;
- GetWindowThreadProcessId(hWnd, &dwProcessId);
- if (dwProcessId != GetWindowProcessID())
- {
- #ifndef _WIN32_WCE
- return Error("Invalid window handle");
- #else
- return ThrowError("ERROR: Invalid window handle");
- #endif
- }
- ::PostMessage(hWnd, WM_CONFIG_VIDEO_WINDOW, WPARAM(WPARAM_SET_HANDLE), LPARAM(m_hWnd));
- if (iLine == -1)
- m_pFramework->m_mediaFramework->SetPreviewWindow(hWnd);
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p)
- {
- return S_OK;//Dont throw Error. We use line = -1 for attaching preview window.
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->AttachVideoWindow(iLine, 0, hWnd);
- return S_OK;
- }
- #endif
- STDMETHODIMP CSessionControl::AttachVideoWindowEx(int iLine, int iIndex, int hWnd)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- if (HWND(hWnd))
- {
- ::PostMessage(
- HWND(hWnd),
- WM_CONFIG_VIDEO_WINDOW,
- WPARAM(WPARAM_SET_HANDLE),
- LPARAM(m_hWnd));
- }
- if (iLine == -1)
- m_pFramework->m_mediaFramework->SetPreviewWindow((HWND)hWnd);
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p)
- {
- return S_OK;//Dont throw Error. We use line = -1 for attaching preview window.
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->AttachVideoWindow(iLine, iIndex, (HWND)hWnd);
- #endif
- return S_OK;
- }
- HRESULT CSessionControl::LoadCallHistory()
- {
- return m_pCallHistory->LoadCallHistory();
- }
- HRESULT CSessionControl::SaveCallHistory()
- {
- return m_pCallHistory->SaveCallHistory();
- }
- /**Logout of the selectedSipAccount.
- * it also ends the call(s) associated with it.
- */
- STDMETHODIMP CSessionControl::Logout()
- {
- m_pFramework->Log("Logging out account " + tostring(m_iSelectedAccount));
- MSA_LOG("Logging out account: " + itoa(m_iSelectedAccount));
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- //if we cancelled a pre-mature registration, that has not
- //finished firewall detection process, stop the detection thread.
- if(sipAccnt->m_pAgent->m_pConnectToSIPServerhread.get())
- {
- sipAccnt->m_pAgent->CloseConnection();
- sipAccnt->m_pAgent->CloseLoginDnsChannel();
- sipAccnt->m_pAgent->StopConnectToSIPServer();
- }
- KILL_TIMER(sipAccnt->m_iRegistrationResponseTimer);
- KILL_TIMER(sipAccnt->m_iRegistrationRefreshTimer);
- KILL_TIMER(sipAccnt->m_iSignalChannelKeepAliveTimer);
- #ifdef _SUPPORT_EVENT_PACKAGE
- KILL_TIMER(sipAccnt->m_iMWIRefreshTimer);
- #endif
- KILL_TIMER(m_iUpdateConferenceListTimer);
- EndCall(VARIANT_TRUE);
- if (sipAccnt->m_pAgent->Logout(false/*failover*/))
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- if (m_hWnd)
- #endif
- {
- #ifdef _CUSTOM_TIMER_
- sipAccnt->m_iLogoutResponseTimer = SetTimer(
- LOGOUT_RESPONSE_TIMER_ID + GetAccountID(sipAccnt),
- CUSTOM_LOGOUT_RESPONSE_TIMEOUT * 1000);
- MSA_LOG("######################### Timer = " + itoa(LOGOUT_RESPONSE_TIMER_ID + GetAccountID(sipAccnt)));
- #else
- sipAccnt->m_iLogoutResponseTimer = SetTimer(
- LOGOUT_RESPONSE_TIMER_ID + GetAccountID(sipAccnt),
- LOGOUT_RESPONSE_TIMEOUT * 1000);
- #endif
- }
- }
- sipAccnt->m_bRegistered = false;
- MSA_LOG("Logged out account: " + itoa(m_iSelectedAccount));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::IsVideoCall(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- *pVal = ToVB(m_pCallLine->HasMedia(false));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::IsAudioCall(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- *pVal = ToVB(m_pCallLine->HasMedia(true));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::IsIncomingCall(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- *pVal = ToVB(m_pCallLine->IsIncomingCall());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetAnonymous(VARIANT_BOOL pVal) //7-6
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_bAnonymous = Tobool(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_TransportMode(BSTR *pbstrTrasportMode)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pbstrTrasportMode);
- int iTransportMode = sipAccnt->m_pAgent->GetTransportMode();
- switch(iTransportMode)
- {
- case UDP:
- BstrFromString(pbstrTrasportMode, "udp");
- break;
- case TCP:
- BstrFromString(pbstrTrasportMode, "tcp");
- break;
- case TLS:
- BstrFromString(pbstrTrasportMode, "tls");
- break;
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_TransportMode(BSTR bstrTrasportMode)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sMode = TruncateSpace(ToStringA(bstrTrasportMode));
- if (sMode.empty())
- return ThrowError("ERROR: Empty Transport Mode.");
- if(sipAccnt->m_pAgent->IsRegistered())
- {
- return ThrowError("ERROR: Must be logged out first.");
- }
- if(!_stricmp(sMode.c_str(),"udp"))
- {
- sipAccnt->m_pAgent->SetTransportMode(UDP);
- }
- else if(!_stricmp(sMode.c_str(),"tcp"))
- {
- sipAccnt->m_pAgent->SetTransportMode(TCP);
- }
- else if(!_stricmp(sMode.c_str(),"tls"))
- {
- sipAccnt->m_pAgent->SetTransportMode(TLS);
- }
- else
- {
- return ThrowError(sMode +" Transport Mode not supported.");
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_KeepAliveMethod(BSTR *pbstrMethod)
- {
- CHECK_POINTER(pbstrMethod);
- SipAccount* sipAccnt = GetSelectedSipAccount();
- if(sipAccnt->m_pAgent->GetKeepAliveMethod())
- {
- BstrFromString(pbstrMethod, "STUN");
- }
- else
- {
- BstrFromString(pbstrMethod, "SIP");
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_KeepAliveMethod(BSTR bstrMethod)
- {
- string sMode = TruncateSpace(ToStringA(bstrMethod));
- SipAccount* sipAccnt = GetSelectedSipAccount();
- if(!_stricmp(sMode.c_str(),"stun"))
- {
- sipAccnt->m_pAgent->SetKeepAliveMethod(true);
- }
- else
- {
- sipAccnt->m_pAgent->SetKeepAliveMethod(false);
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::AudioFramesPerPacket(int iValue)
- {
- if(iValue<1 || iValue>3)
- return ThrowError("ERROR: Input range is 1-3");
- g_AFPPMultiplier = iValue;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetTURNUsernamePassword(BSTR bstrUsername, BSTR bstrPassword)
- {
- m_sTurnUsername = ToStringA(bstrUsername);
- m_sTurnPassword = ToStringA(bstrPassword);
- SetTURNUsernamePassword();
- return S_OK;
- }
- void CSessionControl::SetTURNUsernamePassword()
- {
- m_pAFEngine->SetTURNUsernamePassword(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID,
- #endif
- m_sTurnUsername, m_sTurnPassword);
- }
- string CSessionControl::CreateHost(EServerType eServerType, const string &sProtocol)
- {
- if(m_lstNATTraversalServers.find(eServerType) == m_lstNATTraversalServers.end())
- return "";
- string sHost;
- #if (AF_DLL_VERSION > 950000)
- struct AfConnectionParams connParams;
- connParams.iRTO = 500;
- connParams.iRc = 1;
- connParams.iRm = 16;
- connParams.iTi = 3000;
- #endif
- for(set<pair<string, int> >::const_iterator iter = m_lstNATTraversalServers[eServerType].begin(); iter != m_lstNATTraversalServers[eServerType].end(); iter++)
- {
- sHost += m_pAFEngine->CreateHost(AF_HOST_PUBLIC, iter->first, iter->second, sProtocol
- #if (AF_DLL_VERSION > 950000)
- , &connParams
- #endif
- );
- }
- return sHost;
- }
- STDMETHODIMP CSessionControl::SetNATTraversalServer(int iServerType, BSTR bstrAddr, int iPort, VARIANT_BOOL bDone)
- {
- m_pFramework->Log("Setting AFS: iServerType = " + tostring(iServerType) + " " + ToStringA(bstrAddr) + ":" + tostring(iPort) + ", bDone = " + tostring(bDone));
- EServerType eServerType = (EServerType)iServerType;
- string sServerName = TruncateSpace(ToStringA(bstrAddr));
- if(sServerName.length() > 0 && iPort > 0){
- if(eServerType == eServerSRV)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_SipSetting.m_sSrvDomain = sServerName;
- sipAccnt->m_pAgent->SetSrvDomain(0, sServerName);
- // Only one server can be set for SRV, hence clear its list
- m_lstNATTraversalServers[eServerSRV].clear();
- }
- m_lstNATTraversalServers[eServerType].insert(make_pair(sServerName, iPort));
- }
- if(Tobool(bDone) == false)
- return S_OK;
- map<EServerType, set<pair<string, int> > >::const_iterator iter = m_lstNATTraversalServers.find(eServerHttpProxy);
- if(iter != m_lstNATTraversalServers.end())
- {
- PAL_DB2("HTTP Proxy address: ", iter->second.begin()->first.c_str());
- PAL_DB2("HTTP Proxy port : ", iter->second.begin()->second);
- #if (AF_DLL_VERSION > 9600000)
- m_pAFEngine->SetHTTPProxy(m_iAFEServerStoreID, CreateHost(eServerHttpProxy, AF_PROTOCOL_TCP),
- m_pAFEngine->GetHTTPProxyUsername(m_iAFEServerStoreID),
- m_pAFEngine->GetHTTPProxyPassword(m_iAFEServerStoreID),
- m_pAFEngine->GetHTTPProxyDomain(m_iAFEServerStoreID));
- #else
- m_pAFEngine->SetHTTPProxy(CreateHost(eServerHttpProxy, AF_PROTOCOL_TCP),
- m_pAFEngine->GetHTTPProxyUsername(),
- m_pAFEngine->GetHTTPProxyPassword(),
- m_pAFEngine->GetHTTPProxyDomain());
- #endif
- }
- string sStunServers = CreateHost(eServerStunUdp, AF_PROTOCOL_UDP) + CreateHost(eServerStunTcp, AF_PROTOCOL_TCP);
- string sTurnServers = CreateHost(eServerTurnUdp, AF_PROTOCOL_UDP) + CreateHost(eServerTurnTcp, AF_PROTOCOL_TCP);
- iter = m_lstNATTraversalServers.find(eServerSRV);
- if(iter != m_lstNATTraversalServers.end())
- {
- string sDomain = iter->second.begin()->first;
- if(sDomain.length() > 0){
- #if (AF_DLL_VERSION > 950000)
- struct AfConnectionParams connParams;
- connParams.iRTO = 500;
- connParams.iRc = 1;
- connParams.iRm = 16;
- connParams.iTi = 3000;
- #endif
- sStunServers += m_pAFEngine->CreateHost(AF_HOST_DNS_SRV, "_stun._udp." + sDomain, 0, AF_PROTOCOL_UDP
- #if (AF_DLL_VERSION > 950000)
- , &connParams
- #endif
- );
- sStunServers += m_pAFEngine->CreateHost(AF_HOST_DNS_SRV, "_stun._tcp." + sDomain, 0, AF_PROTOCOL_TCP
- #if (AF_DLL_VERSION > 950000)
- , &connParams
- #endif
- );
- sTurnServers += m_pAFEngine->CreateHost(AF_HOST_DNS_SRV, "_turn._udp." + sDomain, 0, AF_PROTOCOL_UDP
- #if (AF_DLL_VERSION > 950000)
- , &connParams
- #endif
- );
- sTurnServers += m_pAFEngine->CreateHost(AF_HOST_DNS_SRV, "_turn._tcp." + sDomain, 0, AF_PROTOCOL_TCP
- #if (AF_DLL_VERSION > 950000)
- , &connParams
- #endif
- );
- }
- }
- m_pAFEngine->SetSTUNServer(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID,
- #endif
- sStunServers);
- m_pAFEngine->SetTURNServer(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID,
- #endif
- sTurnServers);
- #if (AF_DLL_VERSION > 950000)
- AfFirewallDetectionParams param;
- param.iDetectUdpConnectivity = 1;
- param.iDetectTcpConnectivity = 1;
- param.iDetectProxyConnectivity = 1;
- param.iDetectUPnPConnectivity = 1;
- param.iCheckTurnCredentials = 0;
- param.iUPnPDeviceDiscoveryTimeout = 500;
- m_pAFEngine->DetectConnectivity(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID,
- #endif
- /*NULL*/¶m);
- #else
- m_pAFEngine->DetectConnectivity();
- #endif
- m_pFramework->Log("DetectConnectivity called");
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetStunServerAddr(int iIndex, BSTR* pVal)
- {
- string sNewStunServers;
- string sStunServers = m_pAFEngine->GetSTUNServer(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- int iNumServers = m_pAFEngine->GetHostListSize(sStunServers);
- int iNumUdpServers = 0;
- for (int i = 0; i < iNumServers; i++)
- {
- string sHost = m_pAFEngine->GetHostFromList(sStunServers, i);
- if (m_pAFEngine->GetHostProtocol(sHost) == AF_PROTOCOL_UDP)
- {
- sNewStunServers += sHost;
- iNumUdpServers++;
- }
- }
- int nMapIndex = 0;
- string sAddr;
- if (iNumUdpServers > 0)
- {
- nMapIndex = (iIndex % iNumUdpServers);
- string sHost = m_pAFEngine->GetHostFromList(sNewStunServers, nMapIndex);
- string sAddr = m_pAFEngine->GetHostAddress(sHost);
- }
- BstrFromString(pVal, sAddr);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetStunServerPort(int iIndex, int* pVal)
- {
- string sNewStunServers;
- string sStunServers = m_pAFEngine->GetSTUNServer(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- int iNumServers = m_pAFEngine->GetHostListSize(sStunServers);
- int iNumUdpServers = 0;
- for (int i = 0; i < iNumServers; i++)
- {
- string sHost = m_pAFEngine->GetHostFromList(sStunServers, i);
- if (m_pAFEngine->GetHostProtocol(sHost) == AF_PROTOCOL_UDP)
- {
- sNewStunServers += sHost;
- iNumUdpServers++;
- }
- }
- int nMapIndex = 0;
- int nPort = 0;
- if (iNumUdpServers > 0)
- {
- nMapIndex = (iIndex % iNumUdpServers);
- string sHost = m_pAFEngine->GetHostFromList(sNewStunServers, nMapIndex);
- nPort = m_pAFEngine->GetHostPort(sHost);
- }
- *pVal = nPort;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetHttpProxyAddr(BSTR* pVal)
- {
- string sProxy = m_pAFEngine->GetHTTPProxy(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- string sAddr = m_pAFEngine->GetHostAddress(sProxy);
- BstrFromString(pVal, sAddr);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetHttpProxyPort(int* pVal)
- {
- string sProxy = m_pAFEngine->GetHTTPProxy(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- int nPort = m_pAFEngine->GetHostPort(sProxy);
- *pVal = nPort;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetHttpProxyAuthentication(BSTR bstrUserName, BSTR bstrPassword, BSTR bstrDomain)
- {
- string sUserName = TruncateSpace(ToStringA(bstrUserName));
- string sPassword = TruncateSpace(ToStringA(bstrPassword));
- string sDomain = TruncateSpace(ToStringA(bstrDomain));
- m_pAFEngine->SetHTTPProxy(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID,
- #endif
- m_pAFEngine->GetHTTPProxy(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- ),
- sUserName, sPassword, sDomain);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetHttpProxyUserName(BSTR* pVal)
- {
- string s = m_pAFEngine->GetHTTPProxyUsername(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- BstrFromString(pVal, s);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetHttpProxyPassword(BSTR* pVal)
- {
- string s = m_pAFEngine->GetHTTPProxyPassword(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- BstrFromString(pVal, s);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetHttpProxyDomain(BSTR* pVal)
- {
- string s = m_pAFEngine->GetHTTPProxyDomain(
- #if (AF_DLL_VERSION > 9600000)
- m_iAFEServerStoreID
- #endif
- );
- BstrFromString(pVal, s);
- return S_OK;
- }
- #if 0
- STDMETHODIMP CSessionControl::DetectFirewall()
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->StartConnectToSIPServer();
- return S_OK;
- }
- #endif
- bool CSessionControl::CheckCallURI(const string& sURI, SipAccount* sipAccnt)
- {
- //SipAccount* sipAccnt = GetSelectedSipAccount();
- if (sipAccnt == NULL)
- return false;
- if (sURI.empty())
- return false;
- if (sURI.length() > MAX_SIP_URI_LENGTH)
- return false; // maximum length exceeded
- if (!AreURICharactersValid(sURI))
- return false;
- int iPos = sURI.find("@");
- // the first char is "@"
- if (iPos == 0)
- return false;
- // the last char is "@"
- if (iPos == sURI.size() - 1)
- return false;
- if (iPos == string::npos)
- {
- if (sURI == sipAccnt->m_pAgent->GetDisplayName())
- return false;
- if (sURI == sipAccnt->m_pAgent->GetUsername())
- return false;
- }
- else
- {
- string sContact = sipAccnt->m_pAgent->GetUsername();
- sContact += "@";
- sContact += sipAccnt->m_pAgent->GetProxyName();
- if (sContact == sURI)
- return false;
- }
- return true;
- }
- STDMETHODIMP CSessionControl::get_Framerate(int *pVal)
- {
- #ifndef __NOVIDEO__
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_FrameRate(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_Framerate(int newVal)
- {
- #ifndef __NOVIDEO__
- CHECK_MEDIAFRAMEWORK();
- if (newVal < 0 || newVal > 30)
- return ThrowError("ERROR: Framerate out of range.");
- m_pFramework->m_mediaFramework->put_FrameRate(newVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetOutboundProxy(BSTR bstrProxyServer, int iProxyPort)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetOutboundProxy(ToStringA(bstrProxyServer), iProxyPort);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::EnableRegistration(int iIndex, VARIANT_BOOL bEnable)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->EnableRegistration(iIndex, Tobool(bEnable));
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetVideoCaptureDeviceName(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetVideoCaptureDeviceName(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->GetVideoCaptureDeviceName(pVal);
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetAudioCaptureDeviceName(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetAudioCaptureDeviceName(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->GetAudioCaptureDeviceName(pVal);
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetVideoCaptureInputName(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetVideoCaptureInputName(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->GetVideoCaptureInputName(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SetVideoSource()
- {
- #ifndef __unix__
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->SetVideoSource();
- #endif
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetAudioPlaybackDeviceName(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetAudioPlaybackDeviceName(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->GetAudioPlaybackDeviceName(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::HasCamera(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->HasCamera(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::HasMicrophone(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->HasMicrophone(pVal);
- return S_OK;
- }
- #if defined(__unix__) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- STDMETHODIMP CSessionControl::SetCamera(const std::string &sCamera)
- {
- #ifndef __NOVIDEO__
- CHECK_MEDIAFRAMEWORK();
- string _sCamera = tolower(sCamera);
- if(_sCamera != "front" && _sCamera != "back")
- return ThrowError("ERROR: Invalid camera");
- m_pFramework->m_mediaFramework->SetCamera(_sCamera);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ChangeCameraParameters(int nFrameRate, int nBitRate, int nKeyFrameInterval, int nRotateAngle)
- {
- #ifndef __NOVIDEO__
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->ChangeCameraParameters(nFrameRate, nBitRate, nKeyFrameInterval, nRotateAngle);
- #endif
- return S_OK;
- }
- #endif
- STDMETHODIMP CSessionControl::get_VideoCaptureDevice(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_VideoCaptureDevice(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_VideoCaptureDevice(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_VideoCaptureDevice(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_VideoCaptureInput(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_VideoCaptureInput(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_VideoCaptureInput(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_VideoCaptureInput(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_AudioCaptureDevice(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_AudioCaptureDevice(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioCaptureDevice(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_AudioCaptureDevice(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_AudioPlaybackDevice(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_AudioPlaybackDevice(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioPlaybackDevice(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_AudioPlaybackDevice(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_MicrophoneVolume(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_MicrophoneVolume(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_MicrophoneVolume(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_MicrophoneVolume(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_WaveVolume(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- m_pFramework->m_mediaFramework->get_WaveVolume(ToMFExportString(sTargetID), pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_WaveVolume(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- string sTargetID = m_pCallLine->GetTargetID();
- m_pFramework->m_mediaFramework->put_WaveVolume(ToMFExportString(sTargetID), newVal);
- m_pCallLine->SaveWaveVolume(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_LineVolume(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- m_pFramework->m_mediaFramework->get_LineVolume(ToMFExportString(sTargetID), pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_LineVolume(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- string sTargetID = m_pCallLine->GetTargetID();
- m_pFramework->m_mediaFramework->put_LineVolume(ToMFExportString(sTargetID), newVal);
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetVideoSenderStat(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetVideoSenderStat(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- return m_pFramework->m_mediaFramework->GetVideoSenderStat(pVal);
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetVideoReceiverStat(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetVideoReceiverStat(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- return m_pFramework->m_mediaFramework->GetVideoReceiverStat(ToMFExportString(sTargetID), pVal);
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetAudioSenderStat(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetAudioSenderStat(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- return m_pFramework->m_mediaFramework->GetAudioSenderStat(ToMFExportString(sTargetID), pVal);
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::GetAudioReceiverStat(SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::GetAudioReceiverStat(std::vector<std::string> *pVal)
- #endif
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- return m_pFramework->m_mediaFramework->GetAudioReceiverStat(ToMFExportString(sTargetID), pVal);
- }
- STDMETHODIMP CSessionControl::get_PauseSender(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_Pause(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_PauseSender(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_Pause(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_PauseReceiver(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return S_OK;
- *pVal = ToVB(m_pCallLine->IsLinePaused());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_PauseReceiver(VARIANT_BOOL newVal)
- {
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return S_OK;
- m_pCallLine->PauseLine(Tobool(newVal));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_MuteReceiver(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return S_OK;
- m_pFramework->m_mediaFramework->get_MuteClient(ToMFExportString(sTargetID), pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_MuteReceiver(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return S_OK;
- return m_pFramework->m_mediaFramework->put_MuteClient(ToMFExportString(sTargetID), ToBOOL(newVal));
- }
- STDMETHODIMP CSessionControl::ResetVideoSenderStat()
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->ResetVideoSenderStat();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ResetAudioSenderStat()
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->ResetAudioSenderStat();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ResetVideoReceiverStat()
- {
- CHECK_MEDIAFRAMEWORK();
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- m_pFramework->m_mediaFramework->ResetVideoReceiverStat(ToMFExportString(sTargetID));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ResetAudioReceiverStat()
- {
- CHECK_MEDIAFRAMEWORK();
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- m_pFramework->m_mediaFramework->ResetAudioReceiverStat(ToMFExportString(sTargetID));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_VideoCodecs(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- BstrFromString(pVal, m_pCodecConfig->GetVideoCodecs());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_VideoCodecs(BSTR newVal)
- {
- #ifdef USE_MJPEG
- return S_OK;
- #endif
- string sOldCodecs = m_pCodecConfig->GetVideoCodecs();
- string sNewCodecs = ToStringA(newVal);
- if (_stricmp(sOldCodecs.c_str(), sNewCodecs.c_str()) == 0) {
- return S_OK;
- }
- m_pFramework->Log("Set Video Codec = " + (sNewCodecs.empty() ? "\"\"" : sNewCodecs));
- m_pCodecConfig->SetVideoCodecs(sNewCodecs);
- if (!m_pCallLine->IsAllLineIdle())
- {
- m_pFramework->Log("Changing video codec in call");
- CallDialog* p = m_pCallLine->GetSelectedDialog();
- if (!p)
- {
- return ThrowError("ERROR: put_VideoCodecs::Invalid Line");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- if (!sipAccnt->m_pAgent->ChangeMedia(false))
- return E_FAIL; //S_OK;
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_AudioCodecs(BSTR *pVal)
- {
- CHECK_POINTER(pVal);
- BstrFromString(pVal, m_pCodecConfig->GetAudioCodecs());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioCodecs(BSTR newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- string sOldCodecs = m_pCodecConfig->GetAudioCodecs();
- string sNewCodecs = ToStringA(newVal);
- if (_stricmp(sOldCodecs.c_str(), sNewCodecs.c_str()) == 0) {
- return S_OK;
- }
- m_pFramework->Log("Set Audio Codec = " + (sNewCodecs.empty() ? "\"\"" : sNewCodecs));
- m_pCodecConfig->SetAudioCodecs(sNewCodecs);
- if (!m_pCallLine->IsAllLineIdle())
- {
- m_pFramework->Log("Changing audio codec in call");
- if (!sipAccnt->m_pAgent->ChangeMedia(true))
- return E_FAIL; //ThrowError("ERROR: Invalid call state.");
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_RegistrationExpire(int *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = sipAccnt->m_pAgent->GetRegistrationExpire();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_RegistrationExpire(int newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- if (newVal <= 10)
- return ThrowError("ERROR: Invalid expiration value.");
- sipAccnt->m_pAgent->SetRegistrationExpire(newVal);
- if (sipAccnt->m_iRegistrationRefreshTimer)
- {
- SetRegistrationRefreshTimer(m_iSelectedAccount);
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_SignalPort(int *pVal)
- {
- return ThrowError("ERROR: not supported by AFE");
- }
- STDMETHODIMP CSessionControl::put_SignalPort(int newVal)
- {
- return ThrowError("ERROR: not supported by AFE");
- }
- STDMETHODIMP CSessionControl::get_AudioRtpPort(int *pVal)
- {
- CHECK_POINTER(pVal);
- // get the port from selected dialog. We need AFE support.
- *pVal = 0;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioRtpPort(int newVal)
- {
- // put the port to selected dialog. We need AFE support.
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_AudioRtcpPort(int *pVal)
- {
- CHECK_POINTER(pVal);
- // get the port from selected dialog. We need AFE support.
- *pVal = 0;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioRtcpPort(int newVal)
- {
- // put the port to selected dialog. We need AFE support.
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_VideoRtpPort(int *pVal)
- {
- CHECK_POINTER(pVal);
- // get the port from selected dialog. We need AFE support.
- *pVal = 0;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_VideoRtpPort(int newVal)
- {
- // put the port to selected dialog. We need AFE support.
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_VideoRtcpPort(int *pVal)
- {
- CHECK_POINTER(pVal);
- // get the port from selected dialog. We need AFE support.
- *pVal = 0;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_VideoRtcpPort(int newVal)
- {
- // put the port to selected dialog. We need AFE support.
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_RegistrationPeriod(int *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = sipAccnt->m_pAgent->GetRegistrationPeriod();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_RegistrationPeriod(int newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- if (newVal <= 0 || newVal >= sipAccnt->m_pAgent->GetRegistrationExpire())
- return ThrowError("ERROR: Invalid registration period.");
- sipAccnt->m_pAgent->SetRegistrationPeriod(newVal);
- if (sipAccnt->m_iRegistrationRefreshTimer)
- {
- SetRegistrationRefreshTimer(m_iSelectedAccount);
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_KeepAlivePeriod(int *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = sipAccnt->m_iSignalChannelKeepAlivePeriod;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_KeepAlivePeriod(int newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- if (newVal < 0)
- return ThrowError("ERROR: Invalid keep alive period.");
- m_pFramework->Log("Setting keep alive period to " + tostring(newVal));
- sipAccnt->m_iSignalChannelKeepAlivePeriod = newVal;
- if (!sipAccnt->m_pAgent->IsAllProxyIdle())
- SetSignalChannelKeepAliveTimer(m_iSelectedAccount);
- return S_OK;
- }
- void CSessionControl::SetUpdateConferenceListTimer()
- {
- KILL_TIMER(m_iUpdateConferenceListTimer);
- m_iUpdateConferenceListTimer = SetTimer(UPDATE_CONF_LIST_TIMER_ID, 10000);
- m_pFramework->Log("SetUpdateConferenceListTimer.");
- }
- //UPDATE_CONF_LIST_TIMER_ID
- void CSessionControl::SetSignalChannelKeepAliveTimer(int iAccnt)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- KILL_TIMER(sipAccnt->m_iSignalChannelKeepAliveTimer);
- if(sipAccnt->m_iSignalChannelKeepAlivePeriod)
- {
- sipAccnt->m_iSignalChannelKeepAliveTimer = SetTimer(
- SIGNAL_CHANNEL_KEEP_ALIVE_TIMER_ID + GetAccountID(sipAccnt),
- sipAccnt->m_iSignalChannelKeepAlivePeriod * 1000);
- MSA_LOG("SipAccnt->SetSignalChannelKeepAliveTimer() = " + itoa(sipAccnt->m_iSignalChannelKeepAliveTimer));
- }
- else
- {
- MSA_LOG("sipAccnt->m_iSignalChannelKeepAlivePeriod = invalid.............");
- }
- }
- void CSessionControl::SetRegistrationRefreshTimer(int iAccnt)
- {
- MSA_LOG("Setting Registration refresh timer for: " + itoa(iAccnt));
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- KILL_TIMER(sipAccnt->m_iRegistrationRefreshTimer);
- sipAccnt->m_iRegistrationRefreshTimer = SetTimer(
- REGISTRATION_RFRESH_TIMER_ID + GetAccountID(sipAccnt),
- sipAccnt->m_pAgent->GetRegistrationPeriod() * 1000);
- MSA_LOG("timer id: " + itoa(REGISTRATION_RFRESH_TIMER_ID));
- MSA_LOG(" accnt timerid: " + itoa(sipAccnt->m_iRegistrationRefreshTimer));
- }
- #ifdef _SUPPORT_EVENT_PACKAGE
- void CSessionControl::SetMWIRefreshTimer(int iAccnt)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- KILL_TIMER(sipAccnt->m_iMWIRefreshTimer);
- int iExpire = sipAccnt->m_pAgent->GetMWIExpire() - 10;//this param may be changed later.
- if(iExpire <10 )
- iExpire = 10;
- PAL_DB2("In SetMWIRefreshTImer: iExpire is set to : ", iExpire);
- sipAccnt->m_iMWIRefreshTimer = SetTimer(
- MWI_RFRESH_TIMER_ID + GetAccountID(sipAccnt),
- iExpire * 1000);
- }
- #endif
- ////////////////////// INTERNAL /////////////////////
- void CSessionControl::SetRegistrationResponseTimer(int iAccnt)
- {
- SipAccount* sipAccnt = GetSipAccount(iAccnt);
- RET_IF_NULL(sipAccnt);
- KILL_TIMER(sipAccnt->m_iRegistrationResponseTimer);
- #ifdef _CUSTOM_TIMER_
- sipAccnt->m_iRegistrationResponseTimer = SetTimer(
- REGISTRATION_RESPONSE_TIMER_ID + GetAccountID(sipAccnt),
- CUSTOM_REGISTRATION_RESPONSE_TIMEOUT*1000);
- #else
- sipAccnt->m_iRegistrationResponseTimer = SetTimer(
- REGISTRATION_RESPONSE_TIMER_ID + GetAccountID(sipAccnt),
- REGISTRATION_RESPONSE_TIMEOUT*1000);
- #endif
- }
- STDMETHODIMP CSessionControl::RespondReinvite(int iLine)
- {
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p) {
- return ThrowError("ERROR: RespondReinvite::Invalid Line");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->RespondReinvite(iLine);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::IsRegistered(VARIANT_BOOL *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = ToVB(sipAccnt->m_pAgent->IsRegistered());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_EnableEchoCancellation(VARIANT_BOOL *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_EnableEchoCancellation(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableEchoCancellation(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- return m_pFramework->m_mediaFramework->put_EnableEchoCancellation(newVal);
- }
- STDMETHODIMP CSessionControl::get_QualityProfile(int *pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- CHECK_POINTER(pVal);
- m_pFramework->m_mediaFramework->get_QualityProfile(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_QualityProfile(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- return m_pFramework->m_mediaFramework->put_QualityProfile(newVal);
- }
- STDMETHODIMP CSessionControl::get_EnableKeepAliveFailover(VARIANT_BOOL *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = ToVB(sipAccnt->m_bEnableBindingResponseFailover);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableKeepAliveFailover(VARIANT_BOOL newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- m_pFramework->Log("Keep alive failover = " + tostring(Tobool(newVal)));
- sipAccnt->m_bEnableBindingResponseFailover = Tobool(newVal);
- if (!sipAccnt->m_bEnableBindingResponseFailover)
- {
- sipAccnt->m_iSentKeepAliveCount = 0;
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::TakeSnapshot(BSTR bstrFileName)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- return m_pFramework->m_mediaFramework->TakeSnapshot(bstrFileName);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::TakeIncomingVideoSnapshot(BSTR bstrFileName, int nIndex)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- string sTargetID = m_pCallLine->GetTargetID();
- if (sTargetID.empty())
- return ThrowError("ERROR: Not in session.");
- return m_pFramework->m_mediaFramework->TakeSnapshot2(ToBstr(sTargetID),
- bstrFileName,
- nIndex);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::get_PlayCapturedAudio(VARIANT_BOOL* pVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_PlayCapturedAudio(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_PlayCapturedAudio(VARIANT_BOOL newVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_PlayCapturedAudio(newVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_AudioPlaybackBufferSize(int* pVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_AudioPlaybackBufferSize(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioPlaybackBufferSize(int newVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_AudioPlaybackBufferSize(newVal);
- #endif
- return S_OK;
- }
- //Packet Loss Concealment
- STDMETHODIMP CSessionControl::get_EnablePacketLossConcealment(VARIANT_BOOL* pVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_EnablePacketLossConcealment(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnablePacketLossConcealment(VARIANT_BOOL newVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_EnablePacketLossConcealment(newVal);
- #endif
- return S_OK;
- }
- //Voice Activity Detection
- STDMETHODIMP CSessionControl::get_EnableVoiceActivityDetection(VARIANT_BOOL* pVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_EnableVoiceActivityDetection(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableVoiceActivityDetection(VARIANT_BOOL newVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_EnableVoiceActivityDetection(newVal);
- #endif
- return S_OK;
- }
- //20-7
- //Auto Gain Control
- STDMETHODIMP CSessionControl::get_EnableAGC(VARIANT_BOOL* pVal)
- {
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_EnableAGC(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableAGC(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_EnableAGC(newVal);
- return S_OK;
- }
- //return whether or not srtp is enabled
- STDMETHODIMP CSessionControl::get_EnableSrtp(VARIANT_BOOL* pVal)
- {
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- *pVal = ToVB(sipAccnt->m_pAgent->GetSrtpCall());
- return S_OK;
- }
- //enable Srtp
- STDMETHODIMP CSessionControl::put_EnableSrtp(VARIANT_BOOL newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->Log("Enable SRTP = " + itoa((int)ToBOOL(newVal)));
- sipAccnt->m_pAgent->SetSrtpCall(Tobool(newVal));
- return S_OK;
- }
- //Denoise
- STDMETHODIMP CSessionControl::get_EnableDenoise(VARIANT_BOOL* pVal)
- {
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_EnableDenoise(pVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableDenoise(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->put_EnableDenoise(newVal);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_HashedPassword(int iIndex, BSTR* pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- BstrFromString(pVal, sipAccnt->m_pAgent->GetHashedPassword(iIndex));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_HashedPassword(int iIndex, BSTR newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetHashedPassword(iIndex, ToStringA(newVal));
- return S_OK;
- }
- #ifdef USE_VARIANT_IN_EVENT
- STDMETHODIMP CSessionControl::ConferenceMemberList(VARIANT_BOOL bVideoOnly, SAFEARRAY **pVal)
- #else
- STDMETHODIMP CSessionControl::ConferenceMemberList(VARIANT_BOOL bVideoOnly, std::vector<std::string> *pVal)
- #endif
- {
- CHECK_POINTER(pVal);
- list<string> ls;
- m_pCallLine->GetConferenceMemberList(ls, Tobool(bVideoOnly));
- #ifdef USE_VARIANT_IN_EVENT
- BstrArray a(ls.size());
- list<string>::iterator iter = ls.begin();
- for (int i = 0; iter != ls.end(); iter++, i++)
- {
- a.PutString(i, *iter);
- }
- a.Detach(pVal);
- #else
- pVal->clear();
- for(list<string>::iterator iter = ls.begin(); iter != ls.end(); iter++)
- {
- pVal->push_back(*iter);
- }
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::SubscribeConferenceMemberList()
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SubscribeConferenceMemberList();
- return S_OK;
- }
- STDMETHODIMP CSessionControl::GetVideoWindowCount(int iLine, int* pVal)
- {
- CallDialog* p = m_pCallLine->GetDialog(iLine);
- if (!p)
- {
- return ThrowError("ERROR: GetVideoWindowCount::Invalid Line");
- }
- SipAccount* sipAccnt = GetSipAccount(p->m_iAcct);
- RET_ERROR_STR(sipAccnt);
- //SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = sipAccnt->m_pAgent->GetVideoWindowCount(iLine);
- return S_OK;
- }
- #ifdef WCE_PLATFORM_STANDARDSDK_500
- //////////////////////////////////////////////////////////////////////
- // network thread and message handler
- //////////////////////////////////////////////////////////////////////
- void* CSessionControl::WindowsMessageThread(void *arg)
- {
- SET_CURRENT_THREAD_NAME;
- CSessionControl *pThis = (CSessionControl *)(arg);
- CoInit coInit;
- const long iNumEvents = 2;
- HANDLE EventArray[iNumEvents];
- EventArray[0] = pThis->m_hQuitWindowsMessageThread;
- EventArray[1] = pThis->m_hNewWindowsMessage;
- for (;;)
- {
- // Wait for an event (or a queued callback function) to wake
- // us up. This is an alertable wait state (fAlertable == TRUE).
- u_int32_t WaitStatus = WaitForMultipleObjects(iNumEvents,
- EventArray,
- FALSE,
- 5000);
- switch (WaitStatus)
- {
- case WAIT_FAILED:
- PAL_DB_ASSERT(0 && "WaitForMultipleObjects() failed");
- break;
- case WAIT_OBJECT_0:
- return NULL;
- case WAIT_OBJECT_0 + 1:
- pThis->ProcessNextWindowsMessage();
- break;
- default:
- break;
- }
- }
- return NULL;
- }
- void CSessionControl::ProcessNextWindowsMessage()
- {
- UINT uMsg = m_qWindowsMessageMsgTypeQueue.front();
- WPARAM wParam = m_qWindowsMessageWparamQueue.front();
- LPARAM lParam = m_qWindowsMessageLparamQueue.front();
- {
- PAL::Time_Critical_Section cs(*m_pWindowsMessageQueueMutex.get());
- m_qWindowsMessageMsgTypeQueue.pop();
- m_qWindowsMessageWparamQueue.pop();
- m_qWindowsMessageLparamQueue.pop();
- if (!m_qWindowsMessageMsgTypeQueue.empty())
- SetEvent(m_hNewWindowsMessage);
- }
- LRESULT lResult;
- ProcessWindowMessage(NULL, uMsg, wParam, lParam, lResult);
- }
- void CSessionControl::SendWindowsMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- {
- PAL::Time_Critical_Section cs(*m_pWindowsMessageQueueMutex.get());
- m_qWindowsMessageMsgTypeQueue.push(uMsg);
- m_qWindowsMessageWparamQueue.push(wParam);
- m_qWindowsMessageLparamQueue.push(lParam);
- SetEvent(m_hNewWindowsMessage);
- }
- }
- #endif
- STDMETHODIMP CSessionControl::get_MyPhoneNumber(BSTR *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- BstrFromString(pVal, sipAccnt->m_pAgent->GetFromPhoneNumber());
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_MyPhoneNumber(BSTR newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetFromPhoneNumber(ToStringA(newVal));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::WriteFirewallInfo(void)
- {
- return ThrowError("ERROR: WriteFirewallInfo not supported by Any-Firewall Engine");
- }
- STDMETHODIMP CSessionControl::get_ArchiveSentStreams(VARIANT_BOOL *pVal)
- {
- #ifndef __unix__
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_ArchiveSentStreams(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_ArchiveSentStreams(VARIANT_BOOL newVal)
- {
- #ifndef __unix__
- CHECK_MEDIAFRAMEWORK();
- return m_pFramework->m_mediaFramework->put_ArchiveSentStreams(newVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::get_ArchiveFileName(BSTR *pVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_POINTER(pVal);
- CHECK_MEDIAFRAMEWORK();
- m_pFramework->m_mediaFramework->get_ArchiveFileName(pVal);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_ArchiveFileName(BSTR newVal)
- {
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- CHECK_MEDIAFRAMEWORK();
- return m_pFramework->m_mediaFramework->put_ArchiveFileName(newVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::get_DTMFMode(int *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- // 0 = DTMF using RTP Payload
- // 1 = DTMF using SIP INFO method
- // 2 = DTMF using inband audio signal
- *pVal = sipAccnt->m_iSipInfoDtmf;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_DTMFMode(int newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- // 0 = DTMF using RTP Payload, RFC 2833
- // 1 = DTMF using SIP INFO method
- // 2 = DTMF using inband audio signal
- if (newVal < 0 || newVal > 2)
- return ThrowError("ERROR: DTMFMode is out of range. Valid range is 0-2");
- sipAccnt->m_iSipInfoDtmf = newVal;
- return S_OK;
- }
- #ifdef _WIN32_WCE
- void* CSessionControl::SuspendMonitorThread(void* arg)
- {
- SET_CURRENT_THREAD_NAME;
- CSessionControl *pThis = (CSessionControl *)(arg);
- CoInit coInit;
- const long iNumEvents = 2;
- HANDLE EventArray[iNumEvents];
- EventArray[0] = pThis->m_hQuitSuspendMonitorThread;
- EventArray[1] = pThis->m_hPowerMsgQueue;
- for (;;)
- {
- // Wait for an event (or a queued callback function) to wake
- // us up. This is an alertable wait state (fAlertable == TRUE).
- u_int32_t WaitStatus = WaitForMultipleObjects(iNumEvents,
- EventArray,
- FALSE,
- INFINITE);
- switch (WaitStatus)
- {
- case WAIT_FAILED:
- PAL_DB_ASSERT(0 && "WaitForMultipleObjects() failed");
- break;
- case WAIT_OBJECT_0:
- return NULL;
- case WAIT_OBJECT_0 + 1:
- BYTE messageBuffer[30];
- LPDWORD numBytesRead;
- //u_int32_t dwFlags;
- LPDWORD dwFlags;
- ReadMsgQueue(pThis->m_hPowerMsgQueue, messageBuffer, sizeof(messageBuffer),
- numBytesRead, 0, dwFlags);
- pThis->HandleSuspendResume();
- break;
- default:
- break;
- }
- }
- return NULL;
- }
- void CSessionControl::HandleSuspendResume()
- {
- // transport error fired from transaction layer
- // recv error
- // invite response times out
- // register response times out
- // register renew times out
- // stun keep alive times out
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_IF_NULL(sipAccnt)
- KILL_TIMER(sipAccnt->m_iRegistrationResponseTimer);
- KILL_TIMER(sipAccnt->m_iInviteResponseTimer);
- KILL_TIMER(sipAccnt->m_iRegistrationRefreshTimer);
- KILL_TIMER(sipAccnt->m_iSignalChannelKeepAliveTimer);
- #ifdef _SUPPORT_EVENT_PACKAGE
- KILL_TIMER(sipAccnt->m_iMWIRefreshTimer);
- #endif
- if (!sipAccnt->m_sCallUri.empty())
- {
- sipAccnt->m_pAgent->HandleCallTimeoutOrError();
- }
- // close framework and call line
- // reset registration state to idle
- // register to a new server if available
- // start response timer
- // start refresh-response timer?
- // reinvite if invite failed
- // fire no response during the first registration
- // fir connection lost during the rest registration
- if (sipAccnt->m_pAgent->HandleTimeoutOrError())
- {
- PAL_DB("timeout or error is handled.");
- }
- sipAccnt->m_pAgent->RestoreSessionNetwork();
- if (sipAccnt->m_bRegistered)
- {
- sipAccnt->m_bRegistered = false;
- sipAccnt->m_sCallUri = "";
- Fire_OnConnectionLost(m_iSelectedAccount);
- }
- }
- #endif
- STDMETHODIMP CSessionControl::put_EnableStunSupport(VARIANT_BOOL newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- int iAfOption = (Tobool(newVal) ? AF_OPTION_TRUE : AF_OPTION_FALSE);
- #if (AF_DLL_VERSION >= 10011629)
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableStun, &iAfOption);
- #else
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableStun, iAfOption);
- #endif
- m_pFramework->Log((string)"STUN Support: " + (newVal ? "on" : "off"));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_EnableStunSupport(VARIANT_BOOL *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- bool bret = m_pAFEngine->GetChannelOption(0, EAfOptionEnableStun) == AF_OPTION_TRUE;
- CHECK_POINTER(pVal);
- *pVal = ToVB(bret);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableRelaySupport(VARIANT_BOOL newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- int iAfOption = (Tobool(newVal) ? AF_OPTION_TRUE : AF_OPTION_FALSE);
- #if (AF_DLL_VERSION >= 10011629)
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableTurn, &iAfOption);
- #else
- m_pAFEngine->SetChannelOption(0, EAfOptionEnableTurn, iAfOption);
- #endif
- m_pFramework->Log((string)"Relay Support: " + (newVal ? "on" : "off"));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_EnableRelaySupport(VARIANT_BOOL *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- bool bret = m_pAFEngine->GetChannelOption(0, EAfOptionEnableTurn) == AF_OPTION_TRUE;
- CHECK_POINTER(pVal);
- *pVal = ToVB(bret);
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_EnableIceSupport(VARIANT_BOOL newVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- sipAccnt->m_pAgent->SetEnableIceSupport(Tobool(newVal));
- m_pFramework->Log((string)"ICE Support: " + (newVal ? "on" : "off"));
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_DialupDetected(VARIANT_BOOL *pVal)
- {
- CHECK_POINTER(pVal);
- #if !defined(__unix__) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
- DWORD dwFlags = 0;
- ::InternetGetConnectedState(&dwFlags, 0);
- bool bLan = ((dwFlags & INTERNET_CONNECTION_LAN) != 0);
- bool bModem = ((dwFlags & INTERNET_CONNECTION_MODEM) != 0);
- *pVal = ToVB(bModem);
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_EnableIceSupport(VARIANT_BOOL *pVal)
- {
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_ERROR_STR(sipAccnt);
- CHECK_POINTER(pVal);
- *pVal = ToVB(sipAccnt->m_pAgent->GetEnableIceSupport());
- return S_OK;
- }
- #ifdef _WIN32_WCE
- STDMETHODIMP CSessionControl::SetVoSIPServer(BSTR address, int port)
- {
- #ifdef AEGIS
- CHECK_MEDIAFRAMEWORK();
- string sAddress = TruncateSpace(ToStringA(address));
- if (sAddress.length() > 0) {
- if (!AreURICharactersValid(sAddress)) {
- CComBSTR dummyAddress(L"LocalHost");
- m_pFramework->m_mediaFramework->VoSIPSetServer(dummyAddress, port);
- return ThrowError("ERROR: Invalid characters in VoSIP Server address.");
- }
- }
- m_pFramework->m_mediaFramework->VoSIPSetServer(ToBstr(sAddress), port);
- return S_OK;
- #else
- return E_FAIL;
- #endif //AEGIS
- }
- STDMETHODIMP CSessionControl::get_VideoCaptureACFrequency(int* pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- #ifndef _WIN32_WCE
- return m_pFramework->m_mediaFramework->get_VideoCaptureACFrequency(pVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::put_VideoCaptureACFrequency(int newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- #ifndef _WIN32_WCE
- //not implemented for WinCE in VideoSender
- return m_pFramework->m_mediaFramework->put_VideoCaptureACFrequency(newVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::get_VideoCaptureUpsideDown(VARIANT_BOOL* pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- #ifndef _WIN32_WCE
- return m_pFramework->m_mediaFramework->get_VideoCaptureUpsideDown(pVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::put_VideoCaptureUpsideDown(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- #ifndef _WIN32_WCE
- return m_pFramework->m_mediaFramework->put_VideoCaptureUpsideDown(newVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::get_VideoCaptureIndoorMode(VARIANT_BOOL* pVal)
- {
- CHECK_MEDIAFRAMEWORK();
- #ifndef _WIN32_WCE
- return m_pFramework->m_mediaFramework->get_VideoCaptureIndoorMode(pVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::put_VideoCaptureIndoorMode(VARIANT_BOOL newVal)
- {
- CHECK_MEDIAFRAMEWORK();
- #ifndef _WIN32_WCE
- return m_pFramework->m_mediaFramework->put_VideoCaptureIndoorMode(newVal);
- #else
- return S_OK;
- #endif
- }
- STDMETHODIMP CSessionControl::get_AudioPTime60MsInVideoCalls(VARIANT_BOOL* pVal)
- {
- *pVal = g_AudioPTime60MsInVideoCalls;
- return S_OK;
- }
- STDMETHODIMP CSessionControl::put_AudioPTime60MsInVideoCalls(VARIANT_BOOL newVal)
- {
- g_AudioPTime60MsInVideoCalls = Tobool(newVal);
- return S_OK;
- }
- #endif //_WIN32_WCE
- void CSessionControl::Shutdown()
- {
- if (NULL != m_pFramework)
- {
- // final log message from this control
- m_pFramework->Log("Session Control shutting down...");
- }
- SipAccount* sipAccnt = GetSelectedSipAccount();
- RET_IF_NULL(sipAccnt);
- MSA_LOG("Sip Account is valid");
- sipAccnt->m_pAgent->Shutdown(); /*Remove this to final release.
- // * It will nullify MFramework.*/
- MSA_LOG("Killing Xact timer...");
- KILL_TIMER(sipAccnt->m_iTransactionTimer); //otherwise, it'll keep firing on a dead object.
- MSA_LOG("Killed Xact timer...");
- //ReleaseAccount(sipAccnt); //You can't refer to them later.
- m_iSelectedAccount = -1;
- }
- void CSessionControl::StartProfileTimer(const string& /*s*/)
- {
- #if 0
- if (NULL == m_pFramework)
- return;
- m_dwProfileStartTime = (u_int32_t)PAL::getCurrentTimeInMilliSeconds();
- #endif
- }
- void CSessionControl::StopProfileTimer(const string& /*s*/)
- {
- #if 0
- if (NULL == m_pFramework)
- return;
- u_int32_t dwEndTime = (u_int32_t)PAL::getCurrentTimeInMilliSeconds();
- u_int32_t dwElapsed = dwEndTime - m_dwProfileStartTime;
- #endif
- }
- /////////////////////////////////////////////////////
- // NEW METHODS for MSA (Multiple Sip Account) feature.
- //////////////////////////////////////////////////////
- /**
- * Get a pointer to the SipAccount with ID iAccnt.
- */
- SipAccount* CSessionControl::GetSipAccount(int id)
- {
- SipAccountMap::iterator iter = m_sipAccountMap.find(id);
- if (iter == m_sipAccountMap.end())
- {
- return NULL;
- }
- return iter->second;
- }
- /**
- * Get a pointer to the selected SipAccount.
- */
- SipAccount* CSessionControl::GetSelectedSipAccount()
- {
- if (m_iSelectedAccount == -1)
- return NULL;
- return GetSipAccount(m_iSelectedAccount);
- }
- /* remove SIP Account. */
- STDMETHODIMP CSessionControl::RemoveSipAccount(int iAccnt)
- {
- if(m_sipAccountMap.empty())
- return ThrowError("ERROR: No accounts to remove.");
- SipAccountMap::iterator iter = m_sipAccountMap.find(iAccnt);
- if (iter == m_sipAccountMap.end())
- return ThrowError("ERROR: Invalid SIP account ID.");
- SipAccount* sipAccnt = iter->second;
- sipAccnt->m_bAccountRemoved = true;
- Logout();
- return S_OK;
- }
- ///////////////////////////////////////////////////////////
- STDMETHODIMP CSessionControl::SetApplicationActiveMode(int iApplicationActiveMode)
- {
- #ifdef USE_NSSTREAM_FOR_SIP
- printf("Application entered %d mode", iApplicationActiveMode);
- if(m_pFramework)
- m_pFramework->Log("Application entered " + itoa(iApplicationActiveMode) + " mode");
- PAL::Critical_Section cs(*m_pApplicationModeMutex);
- EApplicationActiveMode eApplicationActiveMode = (EApplicationActiveMode)iApplicationActiveMode;
- if (eApplicationActiveMode == eApplicationActiveModeEnteringBackground || eApplicationActiveMode == eApplicationActiveModeEnteredBackground)
- {
- //OpenGLPause(true);
- for (SipAccountMap::iterator accntIter = m_sipAccountMap.begin(); accntIter != m_sipAccountMap.end(); ++accntIter)
- {
- SipAccount* pAccnt = (SipAccount*)accntIter->second;
- if(pAccnt)
- pAccnt->m_pAgent->StopThread(false);
- }
- UnloadAFEngine();
- }
- else
- {
- //OpenGLPause(false);
- if(!m_bAFEngineInit)
- {
- LoadAFEngine();
- m_pFramework->SetAFEngine(m_pAFEngine, m_iAFEServerStoreID);
- for (SipAccountMap::iterator accntIter = m_sipAccountMap.begin(); accntIter != m_sipAccountMap.end(); ++accntIter)
- {
- SipAccount* pAccnt = (SipAccount*)accntIter->second;
- if(pAccnt)
- pAccnt->m_pAgent->SetAFEngine(m_pAFEngine, m_iAFEServerStoreID);
- }
- SetTURNUsernamePassword();
- SetNATTraversalServer(0, ToInternalBstr(""), 0, true);
- }
- }
- if(m_pFramework)
- m_pFramework->Log("Application mode change done");
- #endif
- return S_OK;
- }
- STDMETHODIMP CSessionControl::ApplicationKeepAliveHandler()
- {
- for (SipAccountMap::iterator accntIter = m_sipAccountMap.begin(); accntIter != m_sipAccountMap.end(); ++accntIter)
- {
- SipAccount* pAccnt = (SipAccount*)accntIter->second;
- if(pAccnt)
- pAccnt->m_pAgent->KeepSignalSocketAlive();
- }
- return S_OK;
- }
- STDMETHODIMP CSessionControl::get_SelectedSipAccount(int *pVal)
- {
- CHECK_POINTER(pVal);
- *pVal = m_iSelectedAccount;
- return (*pVal == -1) ? ThrowError("ERROR: No Account is currently selected.") : S_OK;
- }
- /**
- * Takes account id; selects the account whose map_index = newVal.
- * If account does not exist, create it.
- */
- STDMETHODIMP CSessionControl::put_SelectedSipAccount(int newVal)
- {
- if(newVal >= m_iMaximumAccount)
- return ThrowError("ERROR: Account ID must not exceed maximum accounts");
- if (m_sipAccountMap.find(newVal) == m_sipAccountMap.end())
- {
- MSA_LOG("Account does not exist. Creating account...");
- if(-1 == CreateSipAccount(newVal))
- return ThrowError("ERROR: Maximum number of accounts exceeded.");
- }
- m_iSelectedAccount = newVal;
- /*Sets the Framework to point to this account*/
- m_pFramework->Init(m_iSelectedAccount);
- m_pCallHistory->Init(m_iSelectedAccount);
- m_pCallLine->Init(m_iSelectedAccount);
- #ifndef NO_DATA_TRAVELER
- m_pDataTraveler->SetSipAccountId(m_iSelectedAccount);
- #endif
- MSA_LOG("Account: " + itoa(m_iSelectedAccount) + " is now selected");
- return S_OK;
- }
- /**
- * Creates account with the specified ID.
- * returns -1 if max accounts is exceeded.
- */
- int CSessionControl::CreateSipAccount(int iAccnt)
- {
- if(m_sipAccountMap.size() >= m_iMaximumAccount)
- return -1;
- SipAccount* sipAccount = new SipAccount(this);
- PAL_DB_ASSERT(sipAccount);
- m_iSelectedAccount = iAccnt; /*Automatically set selectedAccount to the
- *Just-created account*/
- AddAccount(m_iSelectedAccount, sipAccount);
- sipAccount->Init(m_iSelectedAccount);
- /*Sets the Framework to point to this account*/
- m_pFramework->Init(m_iSelectedAccount);
- m_pCallHistory->Init(m_iSelectedAccount);
- m_pCallLine->Init(m_iSelectedAccount);
- #ifndef NO_DATA_TRAVELER
- m_pDataTraveler->SetSipAccountId(m_iSelectedAccount);
- #endif
- #ifdef USE_NSSTREAM_FOR_SIP
- // This must be set before setting AFEngine since setting AFEngine starts thread which uses the NSsocket
- sipAccount->m_pAgent->SetNSsocket(m_pNSsocket);
- #endif
- sipAccount->m_pAgent->SetAFEngine(m_pAFEngine, m_iAFEServerStoreID);
- sipAccount->m_pAgent->SetAppWindow(m_hWndControl);
- sipAccount->m_iTransactionTimer = SetTimer(TRANSACTION_TIMER_ID + GetAccountID(sipAccount), TRANSACTION_TIMER_INTERVAL);
- sipAccount->m_iDataChannelKeepAliveTimer = SetTimer(
- DATA_CHANNEL_KEEP_ALIVE_TIMER_ID + GetAccountID(sipAccount),
- DATA_CHANNEL_KEEP_ALIVE_PERIOD * 1000);
- MSA_LOG("Created account: " + itoa(iAccnt));
- return iAccnt;
- }
- ////////////////////////////////////////////////////////////
- /*release memory resources associated with a SipAccount object.*/
- void CSessionControl::ReleaseAccount(SipAccount* sipAccnt)
- {
- SAFE_DELETE(sipAccnt->m_pAgent);
- }
- void CSessionControl::AddAccount(int id, SipAccount* accnt)
- {
- if (m_sipAccountMap.find(id) != m_sipAccountMap.end())
- {
- PAL_DB_ASSERT(0);
- }
- m_sipAccountMap.insert(SipAccountMap::value_type(id, accnt));
- }
- int CSessionControl::GetAccountID(SipAccount* sipAccnt)
- {
- SipAccountMap::iterator iter = m_sipAccountMap.begin();
- for(; iter != m_sipAccountMap.end(); iter++)
- {
- if(sipAccnt == iter->second)
- return iter->first;
- }
- return -1;
- }
- void CSessionControl::WriteMSALog(const string &str)
- {
- #ifdef __unix__
- OnWriteLog(CSessionControl::LOG_MSA, str);
- #endif
- if(m_fp == NULL)
- return;
- #ifndef __unix__
- SYSTEMTIME st;
- GetLocalTime(&st);
- char buff[100] = {};
- sprintf(buff,"%d-%d-%d %d:%d:%d::%d ",st.wYear,st.wMonth,st.wDay,
- st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
- fwrite(buff,1,strlen(buff),m_fp);
- #endif
- fwrite(str.c_str(),1,str.length(),m_fp);
- fwrite("\n",1,1,m_fp);
- fflush(m_fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment