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

📄 cmcall.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
                                IN HATRANSHOST haTransHost,
                                IN RvBool      wasConnected)
{
    HAPP hApp=(HAPP)cmTransGetHApp(hsTransHost);
    cmElem* app=(cmElem*)hApp;

    if (haTransHost);

    if (!wasConnected)
    {
        cmTransportAddress ta;
        int addrRemote,addrLocal;

        addrRemote=pvtAddRoot(app->hVal,app->hAddrSyn,0,NULL);
        addrLocal=pvtAddRoot(app->hVal,app->hAddrSyn,0,NULL);
        if (addrRemote>=0 && addrLocal>=0)
            if (cmTransGetHostParam(hsTransHost, cmTransHostParam_remoteAddress, (void*)&ta)==cmTransOK)
            {
                cmTAToVt(app->hVal,addrRemote,&ta);
                if (cmTransGetHostParam(hsTransHost, cmTransHostParam_localAddress, (void*)&ta)==cmTransOK)
                    cmTAToVt(app->hVal,addrLocal,&ta);

                if (app->cmMyProtocolEvent.hookOutConn!=NULL)
                    app->cmMyProtocolEvent.hookOutConn((HPROTCONN)hsTransHost,addrLocal,addrRemote,RV_FALSE);
            }
        pvtDelete(app->hVal,addrRemote);
        pvtDelete(app->hVal,addrLocal);
    }

    if (app->cmMyProtocolEvent.hookClose!=NULL)
        app->cmMyProtocolEvent.hookClose((HPROTCONN)hsTransHost);

    cmTransCloseHost(hsTransHost);
    return cmTransOK;
}


TRANSERR cmEvTransNewRawMessage(IN  HSTRANSHOST             hsTransHost,
                                IN  HATRANSHOST             haTransHost,
                                IN  RvH323ConnectionType    type,
                                INOUT int                   pvtNode,
                                IN  RvUint8                 *msg,
                                IN  int                     msgSize,
                                OUT int                     *decoded,
                                OUT void                    **hMsgContext)
{
    HAPP hApp=(HAPP)cmTransGetHApp(hsTransHost);
    cmElem* app=(cmElem*)hApp;
    TRANSERR err;
    cmProtocol prot;

    if (haTransHost);

    cmCallPreCallBack(hApp);

    /* Decode the message. We call a callback function in Q931 case, since we might be using
       H.235v2 module in this part */
    if (app->cmEvCallNewRawMessage && (type == RvH323ConnectionQ931))
        err=(app->cmEvCallNewRawMessage(hApp, (HPROTCONN)hsTransHost, pvtNode, msg, msgSize, decoded, hMsgContext)<0)?cmTransErr:cmTransOK;
    else
        err=(cmEmDecode(app->hVal, pvtNode, msg, msgSize, decoded)<0)?cmTransErr:cmTransOK;
    if (err != cmTransOK)
    {
        RvLogError(&app->logTPKT,
            (&app->logTPKT, "New message (channel %d) ignored (error)", emaGetIndex((EMAElement)hsTransHost)));
        RvH323CmPrintMessage(&app->logTPKT, "Bad message:", app->hVal, -1, msg, msgSize, RV_TRUE);
        return err;
    }

    RvLogInfo(&app->logTPKT,
        (&app->logTPKT, "New message (channel %d) recv <-- %s:", emaGetIndex((EMAElement)hsTransHost), nprn(cmGetProtocolMessageName((HAPP)app,pvtNode))));
    RvH323CmPrintMessage(&app->logTPKT, "Binary:", app->hVal, pvtNode, msg, msgSize, RV_TRUE);

    /* MIB - incoming message */
    if (type == RvH323ConnectionQ931)
        prot = cmProtocolQ931;
    else
        prot = cmProtocolH245;
    addStatistic(app->hStatistic, prot, app->hVal, pvtNode, RV_TRUE);

    if (app->cmMyProtocolEvent.hookRecv!=NULL)
        err=(app->cmMyProtocolEvent.hookRecv((HPROTCONN)hsTransHost,pvtNode,RV_FALSE))?cmTransIgnoreMessage:err;

    return err;
}

TRANSERR cmEvTransSendRawMessage(   IN  HSTRANSHOST     hsTransHost,
                                    IN  HATRANSHOST     haTransHost,
                                    IN  HSTRANSSESSION  hsTransSession,
                                    IN  HATRANSSESSION  haTransSession,
                                    IN  int             pvtNode,
                                    IN  int             size,
                                    OUT RvUint8         *msg,
                                    OUT int             *msgSize)
{
    HAPP hApp=(HAPP)cmTransGetHApp(hsTransHost);
    callElem*call=(callElem*)haTransSession;
    cmElem* app=(cmElem*)hApp;
    TRANSERR err;
    RvBool process=RV_TRUE;

    if (hsTransSession || haTransHost);

    /* See if we've got a hook and if the outgoing message should be send or not */
    if (app->cmMyProtocolEvent.hookSend!=NULL)
        process=!app->cmMyProtocolEvent.hookSend((HPROTCONN)hsTransHost,pvtNode,RV_FALSE);
    if (process)
    {
        cmProtocol prot = cmProtocolGetProtocol(hApp,pvtNode);

        if (call && (prot == cmProtocolQ931))
        {
            int nesting;
            if(app->cmMyCallEvent.cmEvCallSendMessage)
            {
                cmiCBEnter((HAPP)app,(char*)"cmEvCallSendMessage(haCall=0x%p,hsCall=0x%p)",(HAPPCALL)emaGetApplicationHandle((EMAElement)call),(HCALL)call);
                nesting=emaPrepareForCallback((EMAElement)call);
                (app->cmMyCallEvent.cmEvCallSendMessage)((HAPPCALL)emaGetApplicationHandle((EMAElement)call),(HCALL)call, pvtNode);
                emaReturnFromCallback((EMAElement)call,nesting);
                cmiCBExit((HAPP)app,(char*)"cmEvCallSendMessage");
            }
        }

        if (app->cmEvCallSendRawMessage)
            err=(app->cmEvCallSendRawMessage(hApp,(HPROTCONN)hsTransHost,(HCALL)call, pvtNode, size, msg, msgSize)<0)?cmTransErr:cmTransOK;
        else
            err=(cmEmEncode(app->hVal, pvtNode, msg, size, msgSize)<0)?cmTransErr:cmTransOK;
        if (err == cmTransOK)
        {
            RvLogInfo(&app->logTPKT,
                (&app->logTPKT, "New message (channel %d) sent --> %s:", emaGetIndex((EMAElement)hsTransHost), nprn(cmGetProtocolMessageName((HAPP)app,pvtNode))));

            /* Make sure we notify the MIB component of the stack */
            addStatistic(app->hStatistic, prot, app->hVal, pvtNode, RV_FALSE);
        }
        else
        {
            RvLogError(&app->logTPKT,
                (&app->logTPKT, "New message (channel %d) Not sent (encoding error) --> %s:", emaGetIndex((EMAElement)hsTransHost), nprn(cmGetProtocolMessageName((HAPP)app,pvtNode))));
            *msgSize = -1;
        }

        RvH323CmPrintMessage(&app->logTPKT, "Message:",
            app->hVal, pvtNode, msg, *msgSize, RV_FALSE);
    }
    else
        err = cmTransIgnoreMessage;

    return err;
}



/********************************************************************************************
 * cmCallSimulateMessage
 * purpose : "Push" a message into the stack as if it was received from the network.
 * input   : hsCall     - Call the message is received on
 *           message    - PVT node ID of the received message
 *                        This node must be a Q931 or H245 message.
 * output  : none
 * return  : Non-negative value on success
 *           Negative value on failure
 ********************************************************************************************/
RVAPI
int RVCALLCONV cmCallSimulateMessage(
                         IN HCALL               hsCall,
                         IN int                 message)
{
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)hsCall);
    callElem*call=(callElem*)hsCall;
    HPVT hVal = ((cmElem *)hApp)->hVal;

    cmiAPIEnter(hApp,"cmCallSimulateMessage: hsCall=0x%p, message=%d",hsCall,message);

    if (!emaLock((EMAElement)call))
    {
        cmiAPIExit(hApp,"cmCallSimulateMessage: -1");
        return cmTransErr;
    }

    switch(cmProtocolGetProtocol(hApp,message))
    {
        case cmProtocolQ931:
        {

            int msgNodeId,nodeId;

            /* Find out the remote's side version if we don't know it yet */
            __pvtGetNodeIdByFieldIds(msgNodeId,hVal,message, {_q931(message) _anyField _q931(userUser)
                                                              _q931(h323_UserInformation) _q931(h323_uu_pdu)
                                                              _q931(h323_message_body) _anyField LAST_TOKEN});

            if (m_callget(call,remoteVersion)==0 && (nodeId=pvtGetChild(hVal,msgNodeId,__q931(protocolIdentifier),NULL))>=0)
            {
                char buff[20];
                int object[6];
                int buffLen;
                buffLen=pvtGetString(hVal, nodeId, sizeof(buff), buff);
                if (utlDecodeOIDInt(buffLen, buff, sizeof(object)/sizeof(*object), object)>=6)
                    /*itu-t recomendation h 2250 version (version number)*/
                    /*0     1             2 3    4        5              */
                    m_callset(call,remoteVersion,object[5]);
            }

            q931ProcessMessage(cmiGetQ931((HCALL)call),message);
        }
        break;
        case cmProtocolH245:
        {
            if(m_callget(call,control))
                h245ProcessIncomingMessage(cmiGetControl((HCALL)call), message);
        }
        break;
        default:
      break;
    }
    emaUnlock((EMAElement)call);
    cmiAPIExit(hApp,"cmCallSimulateMessage: 0");
    return 0;
}



TRANSERR cmEvTransNewMessage(IN HSTRANSSESSION          hsTransSession,
                             IN HATRANSSESSION          haTransSession,
                             IN RvH323ConnectionType    type,
                             IN int                     message,
                             IN void                    *hMsgContext)
{
    callElem*call=(callElem*)haTransSession;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    cmElem* app=(cmElem*)hApp;
    if (hsTransSession);

    cmCallPreCallBack(hApp);
    if (!emaLock((EMAElement)call))
        return cmTransErr;

    {
        int nesting;
        if(app->cmMyCallEvent.cmEvCallRecvMessage)
        {
            cmiCBEnter((HAPP)app,(char*)"cmEvCallRecvMessage(haCall=0x%p,hsCall=0x%p)",(HAPPCALL)emaGetApplicationHandle((EMAElement)call),(HCALL)call);
            nesting=emaPrepareForCallback((EMAElement)call);
            app->cmMyCallEvent.cmEvCallRecvMessage(
                (HAPPCALL)emaGetApplicationHandle((EMAElement)call),(HCALL)call, message);
            emaReturnFromCallback((EMAElement)call,nesting);
            cmiCBExit((HAPP)app,(char*)"cmEvCallRecvMessage");
        }
    }

    if (!emaWasDeleted((EMAElement)call) && (type == RvH323ConnectionQ931))
    {
        /*Release old message context, if any */
        int nesting=emaPrepareForCallback((EMAElement)call);
        if (call->hMsgContext!=NULL)
            if (app->cmEvCallReleaseMessageContext)
                app->cmEvCallReleaseMessageContext(hMsgContext);
        call->hMsgContext=hMsgContext;
        emaReturnFromCallback((EMAElement)call,nesting);

    }

    if (!emaWasDeleted((EMAElement)call))
        cmCallSimulateMessage((HCALL)call,message);
    emaUnlock((EMAElement)call);
    return cmTransOK;
}




/**************************************************************************************
 * cmEvTransBadMessage
 *
 * Purpose: To report to the user that a message for a session could not be decoded
 *          or encoded.
 *          Here, undecoded Q931 messages on a session cause a STATUS message to be
 *          sent in reply.
 *
 * Input:   hsTransSession  - The stack handle of the session.
 *          haTransSession  - The application handle of the session.
 *          type            - The type of the message (Q.931/H.245).
 *          msg             - The encoded message
 *          msgSize         - The encoded message size
 *          outgoing        - RV_TRUE: outgoing message, RV_FALSE-incoming message
 *
 **************************************************************************************/
TRANSERR cmEvTransBadMessage(IN HSTRANSSESSION  hsTransSession,
                             IN HATRANSSESSION  haTransSession,
                             IN TRANSTYPE       type,
                             RvUint8            *msg,
                             int                msgSize,
                             RvBool             outgoing)
{
    RV_UNUSED_ARG(hsTransSession);
    RV_UNUSED_ARG(msg);
    RV_UNUSED_ARG(msgSize);

    if ((type == cmTransQ931Type) && (!outgoing))
    {
        /* Q931... We should send a STATUS message for this one */
        q931DecodingFailure(cmiGetQ931((HCALL)haTransSession));
    }

    return cmTransOK;
}


/************************************************************************
 * enqueueDummyStates
 * purpose: Put an artificial state inside an empty states queue.
 *          This is used for callbacks other than cmEvCallStateChange such
 *          as cmEvNewCall.
 * input  : call        - Stack's call object
 * output : none
 * return : none
 ************************************************************************/
void enqueueDummyState(IN callElem* call)
{
    if (call->q_numStates != 0)
    {
        /* There's no reason to enqueue an Idle state if there are already states in this queue */
        return;
    }

    call->q_states[call->q_nextState] = RV_H323CALL_STATE_DUMMY;
    call->q_numStates = 1;
}


/************************************************************************
 * dequeueCallStates
 * purpose: Dequeue all pending states in the list of states
 * input  : app         - Stack instance
 *          call        - Stack's call object
 *          state       - State of call we want to process first
 *                        If set to cmCallStateIdle, then it is ignored
 *          stateMode   - Mode of the state we want to process first

⌨️ 快捷键说明

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