⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmcontroltransport.c

📁 基于h323协议的软phone
💻 C
字号:
/***********************************************************************
        Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..

RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/

#include "rvinternal.h"
#include "cm.h"
#include "cmutils.h"
#include "cmictrl.h"
#include "q931asn1.h"
#include "transport.h"
#include "cmdebprn.h"
#include "cmCall.h"


#ifdef __cplusplus
extern "C" {
#endif


void getGoodAddressForCall(HCALL hCall, cmTransportAddress* ta)
{
    callElem* call=(callElem*)hCall;

    /* if we already have a full address, we assume it's good, and just return */
    if ((ta->type == cmTransportTypeIP) && (ta->ip != 0) && (ta->port != 0))
        return;

    if (call != NULL)
    {
        RvUint16 port = ta->port;
        cmTransGetGoodAddressForH245(call->hsTransSession,ta);

        /* If we had a port in the original address, we should just leave it as it was */
        if (port != 0)
            ta->port = port;
    }
}

void getGoodAddressForCtrl(HCONTROL ctrl, cmTransportAddress* ta)
{
    getGoodAddressForCall(cmiGetByControl(ctrl), ta);
}

RVAPI int RVCALLCONV
cmCallCreateControlSession(
          IN     HCALL           hsCall,
          IN OUT cmTransportAddress* addr)
{
    int ret=0;
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp,"cmCallCreateControlSession hsCall=0x%p",hsCall);
    if (emaLock((EMAElement)call))
    {
        if (addr)
            ret=cmTransCreateControlSession(call->hsTransSession, addr, (RvBool)(!addr->ip || !addr->port), RV_FALSE);
        else
        {
            cmTransportAddress dummyAddr;
            ret=cmTransCreateControlSession(call->hsTransSession, &dummyAddr, RV_FALSE, RV_TRUE);
        }
        emaUnlock((EMAElement)call);
    }
    cmiAPIExit(hApp,"cmCallCreateControlSession [%d]",ret);
    return ret;
}


RVAPI int RVCALLCONV
cmCallCloseControlSession(
              /* Close the H.245 session for the call */
              IN     HCALL               hsCall)
{
    callElem*call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp,"cmCallCloseControlSession: hsCall=0x%p",hsCall);
    if (emaLock((EMAElement)call))
    {
        if (cmTransHasControlSession(call->hsTransSession))
        {
            if (m_callget(call,control))
            {
                stopControl(cmiGetControl(hsCall));
                m_callset(call,control,RV_FALSE);
            }
            closeChannels(cmiGetControl(hsCall));
        }
        cmTransCloseControlSession(call->hsTransSession);
        emaUnlock((EMAElement)call);
    }
    cmiAPIExit(hApp,"cmCallCloseControlSession: [1]");
    return RV_TRUE;
}


RVAPI int RVCALLCONV
cmCallHasControlSession(
              /* Does call has the H.245 protocol? */
              IN     HCALL               hsCall)
{
    callElem*call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    int has=0;
    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp,"cmCallHasControlSession: hsCall=0x%p",hsCall);
    if (emaLock((EMAElement)call))
    {
        has=cmTransHasControlSession(call->hsTransSession);
        emaUnlock((EMAElement)call);
    }
    cmiAPIExit(hApp,"cmCallHasControlSession: (hsCall=0x%p)=%d",hsCall,has);
    return has;
}


RVAPI
int RVCALLCONV cmCallConnectControl(
                IN      HCALL               hsCall
                                  )
{
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    int res = RV_ERROR_UNKNOWN;

    if ((hsCall == NULL) || (hApp == NULL))
        return RV_ERROR_NULLPTR;

    cmiAPIEnter(hApp,(char*)"cmCallConnectControl(hsCall=0x%p)",hsCall);
    if (emaLock((EMAElement)call))
    {
        TRANSERR transRes = cmTransEstablishControl(call->hsTransSession);
        if (transRes == cmTransOK)
            res = RV_OK;
        emaUnlock((EMAElement)call);
    }
    cmiAPIExit(hApp,(char*)"cmCallConnectControl=%d", res);
    return res;
}

RVAPI int RVCALLCONV
cmCallSw2SeparateH245(IN      HCALL               hsCall)
{
    callElem*call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    int res = RV_ERROR_UNKNOWN;

    if ((hsCall == NULL) || (hApp == NULL))
        return RV_ERROR_NULLPTR;

    cmiAPIEnter(hApp,(char*)"cmCallSw2SeparateH245(hsCall=0x%p)",hsCall);
    if (emaLock((EMAElement)call))
    {
        TRANSERR transRes = cmTransSwitchToSeparate(call->hsTransSession);
        if (transRes == cmTransOK)
            res = RV_OK;
        emaUnlock((EMAElement)call);
    }
    cmiAPIExit(hApp,(char*)"cmCallSw2SeparateH245=%d", res);
    return res;
}

RVAPI
int RVCALLCONV cmCallSetControlRemoteAddress(
                IN      HCALL               hsCall,
                IN      cmTransportAddress  *addr
                                  )
{
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    TRANSERR transErr = cmTransErr;
    int res;

    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp,(char*)"cmCallSetControlRemoteAddress(hsCall=0x%p)",hsCall);
    if (emaLock((EMAElement)call))
    {
        HSTRANSHOST host = NULL;

        cmTransGetSessionParam(call->hsTransSession,
                               cmTransParam_H245Connection,
                               (void *)&host);
        if (host)
            transErr = cmTransSetHostParam(host,
                                           cmTransHostParam_remoteAddress,
                                           (void *)addr,
                                           RV_FALSE);
        else
            transErr = cmTransErr;

        emaUnlock((EMAElement)call);
    }

    if (transErr != cmTransOK)
        res = RV_ERROR_UNKNOWN;
    else
        res = 0;

    cmiAPIExit(hApp,(char*)"cmCallSetControlRemoteAddress=%d", res);
    return res;
}


int cmCallTryControlAfterACF(
    IN  HCALL hsCall
    )
{
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);

    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    if(m_callget(call,callInitiator)) return 0;

    if (emaLock((EMAElement)call))
    {
        cmTransTryControlAfterACF(call->hsTransSession);
        emaUnlock((EMAElement)call);
    }
    return 0;
}

#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -