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

📄 cmgeneral.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
/***********************************************************************
        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 "rvcbase.h"
#include "rvstdio.h"
#include "rvtimestamp.h"
#include "rvinternal.h"
#include "rvassert.h"
#include "cm.h"
#include "msg.h"
#include "cmintr.h"
#include "cmictrl.h"
#include "cmConfig.h"
#include "cmparam.h"
#include "cmConf.h"
#include "per.h"
#include "q931asn1.h"
#include "stkutils.h"
#include "cmutils.h"
#include "intutils.h"
#include "cmdebprn.h"
#include "cmCrossReference.h"
#include "cmiFastStart.h"
#include "cmrasinit.h"
#include "rvh323mibstats.h"
#include "seli.h"
#include "rvthreadinstance.h"
#include "rvhost.h"
#include "h323Version.h"

#ifdef __cplusplus
extern "C" {
#endif



/* Indentification string of this version.
   Unix systems like to search for such a string in the binary file itself */
char rvcm_ident[] = "@(#)RADVISION H.323 Protocol Stack "RV_H323_STACK_VERSION;

/* Global lock, used for cmInit() and cmEnd() calls */
static RvMutex rvCmGlobalMutex;

/* Number of times cmStartup() was called without cmShutdown() being called */
static RvInt rvCmStartupTimes = 0;

/* Number of bytes used after first call to cmStartup(). Used to make sure all memory was
   deallocated after cmShutdown(). */
static RvSize_t rvCmStartingMemorySize = 0;

/* Indication if we allocated a thread information object */
static RvBool rvCmAllocatedThreadInfo = RV_FALSE;



/************************************************************************
 * endPVT_PST
 * purpose: Deallocate any information related to PVT and PST
 * input  : app         - Stack instance handle
 * output : none
 * return : none
 ************************************************************************/
static void endPVT_PST(IN cmElem* app)
{
    pstDestruct(app->hSyn);
    pstDestruct(app->hRASSyn);

    pstDestruct(app->synProtQ931);
    pstDestruct(app->synProtH245);
    pstDestruct(app->synProtRAS);

    pstDestruct(app->h245TransCap);
    pstDestruct(app->h245RedEnc);
    pstDestruct(app->h245DataType);

    pstDestruct(app->hAddrSyn);
    pstDestruct(app->hAddrSynH245);
    pstDestruct(app->synOLC);
    pstDestruct(app->synConfQ931);
    pstDestruct(app->synConfH245);
    pstDestruct(app->synConfRAS);

    pstDestruct(app->synAnnexL);
    pstDestruct(app->synAnnexM);

    pstDestruct(app->synQ931UU);
    pstDestruct(app->synTerminalLabel);
    pstDestruct(app->synGkCrypto);
    pstDestruct(app->synGkPwdCert);

    pstDestruct(app->synKeySync);

    endParamSyntax(app);

    pvtDestruct(app->hVal);
}


/************************************************************************
 * initPVT_PST
 * purpose: Initialize any information related to PVT and PST
 * input  : app         - Stack instance handle
 *          vtNodeCount - Number of nodes in PVT node pool
 * output : none
 * return : non-negative value on success
 *          negative value on failure
 ************************************************************************/
static int initPVT_PST(IN cmElem*app, IN int vtNodeCount)
{
    int res;

    app->hSyn    =pstConstruct(cmEmGetQ931Syntax(),(char *)"Q931ApplicationMessage");
    app->hRASSyn =pstConstruct(cmEmGetQ931Syntax(),(char *)"RasApplicationMessage");

    app->synProtQ931=pstConstruct(cmEmGetQ931Syntax(),(char *)"Q931Message");
    app->synProtH245=pstConstruct(cmEmGetH245Syntax(),(char *)"MultimediaSystemControlMessage");
    app->synProtRAS =pstConstruct(cmEmGetQ931Syntax(),(char *)"RasMessage");

    app->h245TransCap=pstConstruct(cmEmGetH245Syntax(),(char *)"TransportCapability");
    app->h245RedEnc=pstConstruct(cmEmGetH245Syntax(),(char *)"RedundancyEncodingMethod");
    app->h245DataType=pstConstruct(cmEmGetH245Syntax(),(char *)"DataType");

    app->hAddrSyn=pstConstruct(cmEmGetQ931Syntax(),(char *)"TransportAddress");
    app->hAddrSynH245=pstConstruct(cmEmGetH245Syntax(),(char *)"TransportAddress");
    app->synOLC=pstConstruct(cmEmGetH245Syntax(),(char *)"OpenLogicalChannel");
    app->synConfQ931=pstConstruct(cmEmGetQ931Syntax(),(char *)"Q931Configuration");
    app->synConfH245=pstConstruct(cmEmGetH245Syntax(),(char *)"H245Configuration");
    app->synConfRAS=pstConstruct(cmEmGetQ931Syntax(),(char *)"RASConfiguration");

    app->synAnnexL=pstConstruct(cmEmGetQ931Syntax(),(char *)"StimulusControl");
    app->synAnnexM=pstConstruct(cmEmGetQ931Syntax(),(char *)"H323-UU-PDU.tunnelledSignallingMessage");

    app->synQ931UU=pstConstruct(cmEmGetQ931Syntax(),(char *)"H323-UU-PDU");
    app->synTerminalLabel=pstConstruct(cmEmGetQ931Syntax(),(char *)"TerminalLabel");
    app->synGkCrypto=pstConstruct(cmEmGetQ931Syntax(),(char *)"CryptoH323Token");
    app->synGkPwdCert=pstConstruct(cmEmGetQ931Syntax(),(char *)"PwdCertToken");

    app->synKeySync = pstConstruct(cmEmGetH245Syntax(),(char *)"KeySyncMaterial");

    res = initParamSyntax(app);

    app->hVal=pvtConstruct(0, vtNodeCount);

    /* Make sure we were able to construct everything */
    if (app->hSyn && app->hRASSyn && app->synProtQ931 && app->synProtH245 && app->synProtRAS &&
        app->h245TransCap && app->h245RedEnc && app->h245DataType && app->hAddrSyn && app->hAddrSynH245 &&
        app->synOLC && app->synConfQ931 &&
        app->synConfH245 && app->synConfRAS && app->synAnnexL && app->synAnnexM && app->hVal && (res >= 0))

            return 0;

    endPVT_PST(app);
    return RV_ERROR_UNKNOWN;
}


/************************************************************************
 * configTreesInit
 * purpose: Load the configuration related to the RAS, Q931 and H245
 *          standards into PVT structures.
 * input  : app         - Stack instance handle
 * output : none
 * return : none
 ************************************************************************/
static void configTreesInit(cmElem*app)
{
    app->rasConf=pvtAddRoot(app->hVal,app->synConfRAS,0,NULL);
    pvtLoadFromConfig(app->hCfg, app->hVal, (char *)"RAS", app->rasConf, &app->logConfig);

    app->q931Conf = pvtAddRoot(app->hVal,app->synConfQ931,0,NULL);
    pvtLoadFromConfig(app->hCfg, app->hVal, (char *)"Q931", app->q931Conf, &app->logConfig);

    app->h245Conf = pvtAddRoot(app->hVal,app->synConfH245,0,NULL);
    pvtLoadFromConfig(app->hCfg, app->hVal, (char *)"h245", app->h245Conf, &app->logConfig);

}

/************************************************************************
 * configTreesEnd
 * purpose: Delete the PVT structures of the configuration.
 * input  : app         - Stack instance handle
 * output : none
 * return : none
 ************************************************************************/
static void configTreesEnd(cmElem*app)
{
    if(app->rasConf >= 0)
    {
        pvtDelete(app->hVal,app->rasConf);
        app->rasConf = RV_ERROR_UNKNOWN;
    }
    if(app->q931Conf >= 0)
    {
        pvtDelete(app->hVal,app->q931Conf);
        app->q931Conf = RV_ERROR_UNKNOWN;
    }
    if(app->h245Conf >= 0)
    {
        pvtDelete(app->hVal,app->h245Conf);
        app->h245Conf = RV_ERROR_UNKNOWN;
    }
}


/************************************************************************
 * readSystemParameters
 * purpose: Get the system parameters from the configuration.
 *          These parameters are found under the "system" root of the
 *          configuration.
 * input  : app         - Stack instance handle
 * output : maxCalls    - Maximum number of calls supported
 *          maxChannels - Maximum number of channels sopported
 *          vtNodeCount - Number of nodes in PVT trees
 *          maxBuffSize - Maximum size of encoded message buffers
 *          maxPoolSizeInKB - Maximum size of the transport pool to save
 *                            encoded but still not sent messages
 * return : none
 ************************************************************************/
static void readSystemParameters(
    IN  cmElem* app,
    OUT int*    maxCalls,
    OUT int*    maxChannels,
    OUT int*    vtNodeCount,
    OUT int*    maxBuffSize,
    OUT int*    maxPoolSizeInKB)
{
    /* Find out which property mode is used for the property database of the calls */
    app->callPropertyMode=pmodeFullProperty;
    if (ciGetValue(app->hCfg,"system.callPropertyMode.copySingleMessages",NULL,NULL)>=0)
        app->callPropertyMode=pmodeCopySingleMessages;
    else if (ciGetValue(app->hCfg,"system.callPropertyMode.deleteSingleMessages",NULL,NULL)>=0)
        app->callPropertyMode=pmodeDeleteSingleMessages;
    else if (ciGetValue(app->hCfg,"system.callPropertyMode.doNotUseProperty",NULL,NULL)>=0)
        app->callPropertyMode=pmodeDoNotUseProperty;

    /* Find the number of calls and channels if written */
    ciGetValue(app->hCfg,"system.maxCalls" ,NULL,maxCalls);
    ciGetValue(app->hCfg,"system.maxChannels" ,NULL,maxChannels);

    /* Calculate the number of nodes if we won't have it later on */
    if (*maxCalls > 0)
    {
        switch (app->callPropertyMode)
        {
            case pmodeFullProperty:
            case pmodeCopySingleMessages:
            case pmodeDeleteSingleMessages:
                          /* maxCalls *(525call +75ras+maxChannels *75)+ 700init+200ras*/
                *vtNodeCount = (*maxCalls) * (600 + (*maxChannels) * 75) + 900;
                break;

            case pmodeDoNotUseProperty:
                /* Here we want to use less resources... */
                *vtNodeCount = (*maxCalls) * (300 + (*maxChannels) * 45) + 900;
                break;
        }
    }

    /* Find number of nodes , buffer  and pool size */
    ciGetValue(app->hCfg,"system.allocations.vtNodeCount",NULL,vtNodeCount);
    ciGetValue(app->hCfg,"system.allocations.maxBuffSize",NULL,maxBuffSize);
    *maxPoolSizeInKB=*maxCalls*
                     *maxBuffSize/1024; /*One message per call in the pool*/
    ciGetValue(app->hCfg,"system.allocations.maxPoolSizeInKB",NULL,maxPoolSizeInKB);

    /* local IP address */
    {
      char tempIp[5];
      memset(tempIp, 0, sizeof(tempIp));
      ciGetString(app->hCfg,"system.localIPAddress",(char*)tempIp,sizeof(tempIp));
      memcpy((char*)&app->localIPAddress, (char*)tempIp, sizeof(app->localIPAddress));
    }

    /* port range allocation */
    {
        RvInt portFrom;
        RvInt portTo;
        app->portRange = NULL;

        if ((ciGetValue(app->hCfg,"system.portFrom",NULL,&portFrom) >= 0) &&
            (ciGetValue(app->hCfg,"system.portTo",NULL,&portTo) >= 0))
        {
            /* We've got a port range to work with */
            if (RvMemoryAlloc(NULL, (void**)&app->portRange, sizeof(RvPortRange)) == RV_OK)
                RvPortRangeConstruct(app->portRange, (RvUint)portFrom, (RvUint)portTo);
        }
    }

    app->cidAssociate = (ciGetValue(app->hCfg,"system.cidAssociate",NULL,NULL)>=0);
    app->delimiter=',';
    {
        char delimiter[2];
        if (ciGetString(app->hCfg,"system.delimiter",delimiter,2)>=0)
            app->delimiter=delimiter[0];
    }
}


TRANSERR cmEvTransNewSession(   IN  HAPPTRANS        hsTrans,
                                IN  HAPPATRANS       haTrans,
                                IN  HSTRANSSESSION   hsTransSession,
                                OUT HATRANSSESSION   *haTransSession,
                                IN  int              pvtNode,
                                OUT int              *cause,
                                OUT RvPstFieldId     *reasonNameId);

TRANSERR cmEvTransConnectionOnSessionClosed(IN HSTRANSSESSION hsTransSession,
                                            IN HATRANSSESSION haTransSession,
                                            IN TRANSCONNTYPE  type);

TRANSERR cmEvTransSessionNewConnection( IN HSTRANSSESSION   hsTransSession,
                                        IN HATRANSSESSION   haTransSession,
                                        IN TRANSCONNTYPE    type);


⌨️ 快捷键说明

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