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

📄 cmhook.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 "cmintr.h"
#include "cmdebprn.h"
#include "psyntreeStackApi.h"
#include "rasutils.h"
#include "cmutils.h"
#include "cmCall.h"

#ifdef __cplusplus
extern "C" {
#endif

RVAPI
int RVCALLCONV cmSetProtocolEventHandlerReplacement(
        IN  HAPP        hApp,
        IN  CMPROTOCOLEVENT cmProtocolEventReplacement,
        IN  int     size)
{
    cmElem* app=(cmElem*)hApp;
    cmiAPIEnter(hApp,"cmSetProtocolEventHandlerReplacement(hApp=0x%p,cmProtocolEventReplacement=%p,size=%d)",hApp,cmProtocolEventReplacement,size);
    app->cmMyProtocolEventReplacement=cmProtocolEventReplacement;
    app->cmMyProtocolEventReplacementSize=size;
    cmiAPIExit(hApp,"cmSetProtocolEventHandlerReplacement=%d",0);
    return 0;
}
RVAPI
int RVCALLCONV cmSetProtocolEventHandler(
        IN  HAPP        hApp,
        IN  CMPROTOCOLEVENT cmProtocolEvent,
        IN  int     size)
{
    cmElem* app=(cmElem*)hApp;
    cmiAPIEnter(hApp,"cmSetProtocolEventHandler(hApp=0x%p,cmProtocolEvent,size=%d)",hApp,size);
    if (app->cmMyProtocolEventReplacement)
    {
        memset(((cmElem*)hApp)->cmMyProtocolEventReplacement, 0, (RvSize_t)app->cmMyProtocolEventReplacementSize);
        memcpy(((cmElem*)hApp)->cmMyProtocolEventReplacement, cmProtocolEvent, (RvSize_t)RvMin(app->cmMyProtocolEventReplacementSize,size));
    }
    else
    {
        memset(&((cmElem*)hApp)->cmMyProtocolEvent, 0, sizeof(((cmElem*)hApp)->cmMyProtocolEvent));
        memcpy(&((cmElem*)hApp)->cmMyProtocolEvent, cmProtocolEvent, (RvSize_t)RvMin((int)sizeof(((cmElem*)hApp)->cmMyProtocolEvent),size));
    }
    cmiAPIExit(hApp,"cmSetProtocolEventHandler=%d",0);
    return 0;
}


/************************************************************************
 * cmProtocolSendMessage
 * purpose: Send a message through a given connection
 *          This function should be used for Q931 and H.245 messages
 * input  : hApp    - Stack handle for the application
 *          hConn   - Connection to use
 *          msg     - Node id of the message to send
 *                    The message is not deleted by the call to this function
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
int RVCALLCONV cmProtocolSendMessage(
        IN  HAPP        hApp,
        IN  HPROTCONN   hConn,
        IN  int         msg)
{
    TRANSERR result = cmTransErr;

    cmiAPIEnter(hApp, "cmProtocolSendMessage(hApp=0x%p, hConn=0x%p, msg=%d)", hApp, hConn, msg);
    result = cmTransHostSendMessage((HSTRANSHOST)hConn,  msg);
    if (result > 0)
        result = cmTransErr;
    cmiAPIExit(hApp, "cmProtocolSendMessage() = %d", result);

    return (int)result;
}


RVAPI
int RVCALLCONV cmProtocolSendMessageTo(
        IN  HAPP        hApp,
        IN  HPROTCONN   hConn,
        IN  int         msg,
        IN  int         addr)
{
    int result=RV_ERROR_UNKNOWN;
    cmElem* app=(cmElem*)hApp;
    cmTransportAddress ta;

    cmiAPIEnter(hApp,"cmProtocolSendMessageTo(hApp=0x%p)",hApp);

    cmVtToTA(app->hVal,addr,&ta);
    result = rasEncodeAndSend((rasModule*)app->rasManager, NULL, cmRASTrStageDummy, msg, 
                              (RvBool)(hConn==cmGetRASConnectionHandle(hApp)), 
                              &ta, RV_FALSE, NULL);

    cmiAPIExit(hApp,"cmProtocolSendMessageTo=%d", result);
    return result;
}


RVAPI
int RVCALLCONV
cmProtocolCreateMessage(
                IN      HAPP                    hApp,
                IN      cmProtocol              protocol)
{
    cmElem* app=(cmElem*)hApp;
    int rootId;
    cmiAPIEnter(hApp,"cmProtocolCreateMessage (hApp=0x%p)",hApp);

    switch(protocol)
    {
        case cmProtocolQ931:
            rootId = pvtAddRoot(app->hVal,app->synProtQ931,0,NULL);
            break;
        case cmProtocolH245:
            rootId = pvtAddRoot(app->hVal,app->synProtH245,0,NULL);
            break;
        case cmProtocolRAS:
            rootId = pvtAddRoot(app->hVal,app->synProtRAS,0,NULL);
            break;
        default:
            rootId = RV_ERROR_UNKNOWN;
    }

    cmiAPIExit(hApp,"cmProtocolCreateMessage root=%d",rootId);
    return rootId;
}

RVAPI
cmProtocol RVCALLCONV cmProtocolGetProtocol(
                IN      HAPP                    hApp,
                IN      int                     msg)
{
    cmElem* app=(cmElem*)hApp;
    HPST hSyn;
    int synNodeId;
    if (!app || msg<0)
        return (cmProtocol)RV_ERROR_UNKNOWN;

    hSyn = pvtGetSynTree(app->hVal, msg);

    cmiAPIEnter(hApp,"cmProtocolGetProtocol hApp=0x%p",hApp);

    pvtGet(app->hVal, msg, NULL, &synNodeId, NULL, NULL);

    if (pstAreNodesCongruent(hSyn,synNodeId,app->synProtQ931,pstGetRoot(app->synProtQ931)))
    {
        cmiAPIExit(hApp,"cmProtocolGetProtocol hApp=0x%p cmProtocolQ931",hApp);
        return cmProtocolQ931;
    }
    if (pstAreNodesCongruent(hSyn,synNodeId,app->synProtRAS,pstGetRoot(app->synProtRAS)))
    {
        cmiAPIExit(hApp,"cmProtocolGetProtocol hApp=0x%p cmProtocolRAS",hApp);
        return cmProtocolRAS;
    }
    if (pstAreNodesCongruent(hSyn,synNodeId,app->synProtH245,pstGetRoot(app->synProtH245)))
    {
        cmiAPIExit(hApp,"cmProtocolGetProtocol hApp=0x%p cmProtocolH245",hApp);
        return cmProtocolH245;
    }

    cmiAPIExit(hApp,"cmProtocolGetProtocol hApp=0x%p cmProtocolUnknown",hApp);
    return cmProtocolUnknown;
}

RVAPI
char* RVCALLCONV cmProtocolGetProtocolName(
                IN      cmProtocol              protocol)
{
    switch(protocol)
    {
        case cmProtocolQ931:return (char*)"Q931";
        case cmProtocolH245:return (char*)"H245";
        case cmProtocolRAS: return (char*)"RAS";
        default:            return (char*)"Unknown";
    }
}


/************************************************************************
 * cmProtocolGetLocalAddress
 * purpose: Get the local address of a given connection of the stack.
 *          This function can be used on Q.931 or H.245 connections.
 * input  : hApp    - Stack handle for the application
 *          hConn   - Connection to use
 * output : address - The local address of this connection
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
int RVCALLCONV cmProtocolGetLocalAddress(
        IN  HAPP                hApp,
        IN  HPROTCONN           hConn,
        OUT cmTransportAddress* address)
{
    RV_UNUSED_ARG(hApp);

    if (address == NULL)
        return RV_ERROR_BADPARAM;

    if ( cmTransGetHostParam( (HSTRANSHOST)hConn, cmTransHostParam_localAddress, address ) != cmTransOK )
        return RV_ERROR_UNKNOWN;

    return RV_OK;
}


/************************************************************************
 * cmProtocolGetRemoteAddress
 * purpose: Get the remote address of a given connection of the stack.
 *          This function can be used on Q.931 or H.245 connections.
 * input  : hApp    - Stack handle for the application
 *          hConn   - Connection to use
 * output : address - The remote address of this connection
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
int RVCALLCONV cmProtocolGetRemoteAddress(
        IN  HAPP                hApp,
        IN  HPROTCONN           hConn,
        OUT cmTransportAddress* address)
{
    RV_UNUSED_ARG(hApp);

    if (address == NULL)
        return RV_ERROR_BADPARAM;

    if ( cmTransGetHostParam( (HSTRANSHOST)hConn, cmTransHostParam_remoteAddress, address ) != cmTransOK )
        return RV_ERROR_UNKNOWN;

    return RV_OK;
}


/************************************************************************
 * cmProtocolSetTypeOfService
 * purpose: Set the connection's DiffServ Code Point value. This is used
 *          for QoS.
 *          This function can be used on RAS, Q.931 or H.245 connections.
 * input  : hApp            - Stack handle for the application
 *          hConn           - Connection to use
 *          typeOfService   - Type of service value
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
int RVCALLCONV cmProtocolSetTypeOfService(
        IN  HAPP        hApp,
        IN  HPROTCONN   hConn,
        IN  RvInt       typeOfService)
{
    HPROTCONN rasConn;
    RvH323Connection* connection = NULL;

    /* First let's see if the protocol handle we got is a RAS handle */
    rasConn = cmGetRASConnectionHandle(hApp);

    if (rasConn == hConn)
    {
        /* RAS */
        cmElem* app = (cmElem *)hApp;
        connection = &app->rasUnicastConnection;
    }
    else
    {
        /* Q931/H245/AnnexE */
        if (cmTransGetHostParam((HSTRANSHOST)hConn, cmTransHostParam_socketConnection, (void*)&connection) != cmTransOK)
            return RV_ERROR_UNKNOWN;
    }

    if (connection != NULL)
        return RvSocketSetTypeOfService(&connection->socket, typeOfService);

    return RV_ERROR_NOTSUPPORTED;
}



#ifdef __cplusplus
}
#endif



⌨️ 快捷键说明

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