📄 cmras.c
字号:
/*
NOTICE:
This document contains information that is proprietary to RADVISION LTD..
No part of this publication may be reproduced in any form whatsoever without
written prior approval by RADVISION LTD..
RADVISION LTD. reserves the right to revise this publication and make changes
without obligation to notify any person of such revisions or changes.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <cmCrossReference.h>
#include <rasdef.h>
#include <rasutils.h>
#include <rasin.h>
#include <rasout.h>
#include <rasirr.h>
#include <rasparams.h>
#include <cmras.h>
#include <cmdebprn.h>
#include <cmutils.h>
/************************************************************************
*
* Public functions
*
************************************************************************/
/************************************************************************
* cmRASStartTransaction
* purpose: Create a RAS transaction.
* This function exchanges handles with the application and connects
* between the transaction and the call (if applicable).
* input : hApp - Application's handle for a stack instance
* haRas - Application's handle for the RAS transaction
* transaction - The transaction type we want to start
* destAddress - Address of the destination.
* If set to NULL, then it's for the gatekeeper
* hsCall - Stack's call handle if the transaction is related
* to a call. NULL otherwise.
* output : lphsRas - The stack's RAS transaction handle that was
* created.
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
int RVCALLCONV cmRASStartTransaction(
IN HAPP hApp,
IN HAPPRAS haRas,
OUT LPHRAS lphsRas,
IN cmRASTransaction transaction,
IN cmRASTransport* destAddress,
IN HCALL hsCall)
{
rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);
rasOutTx* tx;
int ret = 0;
if (lphsRas != NULL) *lphsRas = NULL;
cmiAPIEnter(hApp, "cmRASStartTransaction(hApp=0x%p,haRas=0x%p,transaction=%d,hsCall=0x%p)",
hApp, haRas, transaction, hsCall);
/* Create the transaction */
tx = rasCreateOutTx(ras, haRas, transaction, destAddress);
/* See what happened */
if (tx != NULL)
{
/* Transaction was created successfuly */
tx->hsCall = hsCall;
/* IRR transactions get some special treatment */
if ((transaction == cmRASUnsolicitedIRR) && (hsCall != NULL))
{
RvPvtNodeId irrNode = pvtAdd(ras->hVal, tx->txProperty, __q931(request), 0, NULL, NULL);
ret = rasSetIrrFields(ras, (HRAS)tx, irrNode, hsCall);
}
/* See if we have to set any call related information */
if ((hsCall != NULL) && (ret >= 0))
{
char callid[16];
RvInt32 rasCrv, callidLen;
callidLen = sizeof(callid);
if (cmCallGetParam(hsCall, cmParamCallID, 0, &callidLen, callid) >= 0)
rasSetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamCallID, 0, callidLen, callid);
callidLen = sizeof(callid);
if (cmCallGetParam(hsCall, cmParamCID, 0, &callidLen, callid) >= 0)
rasSetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamCID, 0, callidLen, callid);
if (cmCallGetParam(hsCall, cmParamRASCRV, 0, &rasCrv, NULL) >= 0)
rasSetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamCRV, 0, rasCrv, NULL);
rasSetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamAnswerCall, 0, !cmCallGetOrigin(hsCall,NULL), NULL);
}
}
else
ret = RV_ERROR_UNKNOWN;
/* Check the return value and clear the transaction if we failed somewhere */
if (ret < 0)
{
if (tx != NULL)
{
rasCloseOutTx(ras, tx);
tx = NULL;
}
}
else
{
/* Success value should always be 0 for this function */
ret = 0;
}
/* Return this transaction to the application */
if (lphsRas != NULL) *lphsRas = (HRAS)tx;
cmiAPIExit(hApp, "cmRASStartTransaction(haRas=0x%p,hsRas=0x%p,ret=%d)",
haRas, tx, ret);
return ret;
}
/************************************************************************
* cmRASSetHandle
* purpose: Sets or changes the application handle for a RAS transaction.
* input : hsRas - Stack's handle for the RAS transaction
* haRas - Application's handle for the RAS transaction to be set
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
RVAPI
int RVCALLCONV cmRASSetHandle(
IN HRAS hsRas,
IN HAPPRAS haRas)
{
rasModule* ras;
int ret;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app, "cmRASSetHandle(hsRas=0x%p,haRas=0x%p)", hsRas, haRas);
/* Update the application's handle */
ret = emaSetApplicationHandle((EMAElement)hsRas, (void*)haRas);
cmiAPIExit(ras->app, "cmRASSetHandle(hsRas=0x%p)=%d", hsRas, ret);
return ret;
}
/************************************************************************
* cmRASGetParam
* purpose: Get a parameter about the RAS transaction
* input : hsRas - Stack's handle for the RAS transaction
* trStage - The transaction stage the parameters
* param - Type of the RAS parameter
* index - If the parameter has several instances, the index
* that identifies the specific instance (0-based).
* 0 otherwise.
* value - If the parameter value is a structure, the value
* represents the length of the parameter.
* output : value - For a simple integer - the parameter's value.
* For a structure - the length of the parameter.
* svalue - For a structure - svalue represents the parameter
* itself. Can be set to NULL if we're only interested
* in its length.
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
int RVCALLCONV cmRASGetParam(
IN HRAS hsRas,
IN cmRASTrStage trStage,
IN cmRASParam param,
IN int index,
IN OUT RvInt32* value,
IN char* svalue)
{
rasModule* ras;
int status = RV_ERROR_UNKNOWN;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app,
"cmRASGetParam(hsRas=0x%p,trStage=%d,%s[%d])",
hsRas, trStage, rasGetParamName(param), index);
if(emaLock((EMAElement)hsRas))
{
status = rasGetParam(ras, hsRas, trStage, param, index, value, svalue);
emaUnlock((EMAElement)hsRas);
}
cmiAPIExit(ras->app, "cmRASGetParam(hsRas=0x%p,ret=%d)", hsRas, status);
return status;
}
/************************************************************************
* cmRASSetParam
* purpose: Set a parameter about the RAS transaction
* input : hsRas - Stack's handle for the RAS transaction
* trStage - The transaction stage the parameters
* param - Type of the RAS parameter
* index - If the parameter has several instances, the index
* that identifies the specific instance (0-based).
* 0 otherwise.
* value - For a simple integer - the parameter's value.
* For a structure - the length of the parameter.
* svalue - For a structure - svalue represents the parameter
* itself.
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
int RVCALLCONV cmRASSetParam(
IN HRAS hsRas,
IN cmRASTrStage trStage,
IN cmRASParam param,
IN int index,
IN RvInt32 value,
IN char* svalue)
{
rasModule* ras;
int status = RV_ERROR_UNKNOWN;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app,"cmRASSetParam(hsRas=0x%p,trStage=%d,%s[%d]=%d)",
hsRas, trStage, rasGetParamName(param), index, value);
if(emaLock((EMAElement)hsRas))
{
status = rasSetParam(ras, hsRas, trStage, param, index, value, svalue);
emaUnlock((EMAElement)hsRas);
}
if (status > 0)
status = 0; /* We want the gatekeeper to work, so we set successful return values to 0 */
cmiAPIExit(ras->app, "cmRASSetParam(hsRas=0x%p,ret=%d)", hsRas, status);
return status;
}
/************************************************************************
* cmRASGetNumOfParams
* purpose: Returns the number of params in sequences on the property
* tree.
* input : hsRas - Stack's handle for the RAS transaction
* trStage - The transaction stage the parameters
* param - Type of the RAS parameter
* output : none
* return : Number of params in sequence on the property tree on success
* Negative value on failure
************************************************************************/
RVAPI
int RVCALLCONV cmRASGetNumOfParams(
IN HRAS hsRas,
IN cmRASTrStage trStage,
IN cmRASParam param)
{
rasModule* ras;
int status = RV_ERROR_UNKNOWN;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app,
"cmRASGetNumOfParams(hsRas=0x%p,trStage=%d,%s)",
hsRas, trStage, rasGetParamName(param));
if(emaLock((EMAElement)hsRas))
{
status = rasGetNumOfParams(ras, hsRas, trStage, param);
emaUnlock((EMAElement)hsRas);
}
cmiAPIExit(ras->app, "cmRASGetNumOfParams(hsRas=0x%p,ret=%d)", hsRas, status);
return status;
}
/************************************************************************
* cmRASRequest
* purpose: Send an outgoing RAS transaction
* input : hsRas - Stack's handle for the RAS transaction
* output : none
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
int RVCALLCONV cmRASRequest(
IN HRAS hsRas)
{
rasModule* ras;
rasOutTx* tx;
int status;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app, "cmRASRequest(hsRas=0x%p)", hsRas);
/* Get the transaction */
tx = rasGetOutgoing(hsRas);
if (tx != NULL)
{
if (tx->retryCount == 0)
{
/* Reset the retryCount */
tx->retryCount = rasCfgGetRetries(ras);
}
status = rasSendRequestMessage(ras, tx);
}
else
{
RvLogError(&ras->log,
(&ras->log, "cmRASRequest: Bad outgoing transaction handle (0x%p)", hsRas));
status = RV_ERROR_UNKNOWN;
}
cmiAPIExit(ras->app, "cmRASRequest(hsRas=0x%p,ret=%d)", hsRas, status);
return status;
}
/************************************************************************
* cmRASDummyRequest
* purpose: Called after cmRASStartTransaction() on cmRASUnsolicitedIRR.
* It allows the application to wait for an unsolicited IRR on
* a specific call.
* input : hsRas - Stack's handle for the RAS transaction
* output : none
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
int RVCALLCONV cmRASDummyRequest(
IN HRAS hsRas)
{
rasModule* ras;
rasOutTx* tx;
int status;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app, "cmRASDummyRequest(hsRas=0x%p)", hsRas);
/* Get the transaction */
tx = rasGetOutgoing(hsRas);
if (tx != NULL)
status = rasDummyRequest(ras, tx);
else
{
RvLogError(&ras->log,
(&ras->log, "cmRASDummyRequest: Bad outgoing transaction handle (0x%p)", hsRas));
status = RV_ERROR_UNKNOWN;
}
cmiAPIExit(ras->app, "cmRASDummyRequest(hsRas=0x%p,ret=%d)", hsRas, status);
return status;
}
/************************************************************************
* cmRASConfirm
* purpose: Sends a confirm response on an incoming RAS request
* input : hsRas - Stack's handle for the RAS transaction
* output : none
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
int RVCALLCONV cmRASConfirm(
IN HRAS hsRas)
{
rasModule* ras;
rasInTx* tx;
int status;
if (hsRas == NULL) return RV_ERROR_UNKNOWN;
ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
cmiAPIEnter(ras->app, "cmRASConfirm(hsRas=0x%p)", hsRas);
/* Get the transaction */
tx = rasGetIncoming(hsRas);
if (tx != NULL)
status = rasSendConfirmMessage(ras, tx);
else
{
rasOutTx* tx = rasGetOutgoing(hsRas);
/* check if this is an unsolicitated IRR without an incoming transaction */
if ((tx != NULL) && (tx->transactionType == cmRASUnsolicitedIRR))
{
/* use "cmRASRequest()" instead, done for backwards competability */
status = cmRASRequest(hsRas);
}
else
{
RvLogError(&ras->log,
(&ras->log, "cmRASConfirm: Bad outgoing transaction handle (0x%p)", hsRas));
status = RV_ERROR_UNKNOWN;
}
}
cmiAPIExit(ras->app, "cmRASConfirm(hsRas=0x%p,ret=%d)", hsRas, status);
return status;
}
/************************************************************************
* cmRASReject
* purpose: Sends a reject response on an incoming RAS request
* input : hsRas - Stack's handle for the RAS transaction
* reason - The reject reason to use
* output : none
* return : If an error occurs, the function returns a negative value.
* If no error occurs, the function returns a non-negative value.
************************************************************************/
RVAPI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -