?? rvwpct.c
字號:
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include "rvtypes.h"
#include "cm.h"
#include "cmintr.h"
#include "pvaltree.h"
#include "psyntree.h"
#include "q931asn1.h"
#include "h245.h"
#include "rvwpt.h"
#include "rvwpct.h"
#include "rasdef.h"
#include <time.h>
/*#include "bepcommon.h"*/
/*#define TRACE(a) ;
#define wPGetCallIndex(p) 0
#define wpSendMsgToApp(a) ;
*/
int versionNumber;
OutParam AppParam;
/*ttl time, received from gk, for resend full rrq, replace light rrq*/
RvInt globleTTL = 60;
/*get app param for wp*/
void GetOutParam(OutParam TransParam)
{
strcpy(AppParam.localE164,TransParam.localE164);
strcpy(AppParam.localShow,TransParam.localShow);
strcpy(AppParam.localId,TransParam.localId);
strcpy(AppParam.password,TransParam.password);
AppParam.gkstatus = TransParam.gkstatus;
}
/********************************************************************************************
* convertToH450Address
* purpose : Convert an address represented by a string to an address string that H450
* recognizes.
* input : inString - String to convert
* output : resultString - Converted string
* return : none
********************************************************************************************/
void convertToH450Address(const char* inString, char* resultString)
{
if (isdigit((int)inString[0]))
{
/* If it's a transport address, we'll add the TA: prefix...
Otherwise, we should add the TEL: prefix... */
int a, b, c, d, e;
if (sscanf(inString, "%d.%d.%d.%d:%d", &a, &b, &c, &d, &e) == 5)
{
sprintf(resultString, "TA:%s", inString);
}
else
{
sprintf(resultString, "TEL:%s", inString);
}
}
else
{
strcpy(resultString, inString);
}
}
extern RvSemaphore* fileSem;
extern FILE* fp;
void wpSendCTorCF(WrapperMsg * msg)
{
int retVal;
char destAddr[40];
HCALL callP = NULL;
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"wpSendCTorCF()\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
if (msg->baseInfo.callIndex > MAX_CONCURRENT_CALL_NUM)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"callIndex in wpSendCallTransfer is %d, out of range\nreturn ...\n", msg->baseInfo.callIndex);
ReleaseSemaphore(fileSem,1,NULL);
}*/
return;
}
if (WP_INITIATE_CALL_TRANSFER == msg->msgId)
convertToH450Address(msg->d.CallTransferInfo.transferToNumber, destAddr);
else if (WP_SEND_CALL_FORWARD == msg->msgId)
{
strncpy(destAddr, msg->d.CallForwardInfo.ForwardToNumber,39);
destAddr[39]='\0';
}
/*convertToH450Address(msg->d.CallTransferInfo.transferToNumber, destAddr);*/
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"ct or cf destAddr:%s!\n", destAddr);
ReleaseSemaphore(fileSem,1,NULL);
}*/
/*and go a-go-go
sseCallTransfer(Call->hSSECall, NULL, destAddr);*/
retVal = cmCallForward(wpCallInfo[msg->baseInfo.callIndex].hsCall, destAddr);
if (retVal < 0)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"cmCallForward in transfer return error!\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
}
else
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"cmCallForward in transfer return ok!\n");
ReleaseSemaphore(fileSem,1,NULL);
}*/
if (WP_INITIATE_CALL_TRANSFER == msg->msgId)
{
wpCallInfo[msg->baseInfo.callIndex].isTransferring = RV_TRUE;
}
}
}
void wpSendTransferSetup(WrapperMsg* msg)
{
CallInfo* Call;
int retVal;
HCALL hsCall;
char dstAddr[128], srcAddr[128];
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"wpSendQuery()\n");
ReleaseSemaphore(fileSem,1,NULL);
}*/
Call = (CallInfo*)malloc(sizeof(CallInfo));
memset(Call, 0, sizeof(CallInfo));
/* Create new call */
retVal = cmCallNew(hApp,(HAPPCALL) Call, &hsCall);
if (retVal < 0)
{
free(Call);
return;
}
if (IPADDR_TYPE == msg->d.CallTransferInfo.transferToAddrType)
{
sprintf(dstAddr, "TA:%s:%d", (char *)msg->d.CallTransferInfo.transferToNumber, H245_SEND_PORT);
}
else
{
sprintf(dstAddr, "TEL:%s", (char *)msg->d.CallTransferInfo.transferToNumber);
}
if (msg->baseInfo.localE164Num[0] != '\0')
{
sprintf(srcAddr, "TEL:%s", msg->baseInfo.localE164Num);
}
else
{
srcAddr[0] = '\0';
}
if ((retVal = cmCallMake(hsCall,
BANDWIDTH,
0,
dstAddr,
srcAddr,
(char *)msg->baseInfo.display,
0,
0)) >= 0)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Make the call successd\n");
ReleaseSemaphore(fileSem,1,NULL);
}*/
}
else
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Make the call failed\n");
ReleaseSemaphore(fileSem,1,NULL);
}*/
}
}
wpForwardCycleFun wpForwardCycleFunc;
void wpSetForwardCycleCallback(wpForwardCycleFun callbackFun)
{
wpForwardCycleFunc = callbackFun;
}
OutParam AppParam;
/*extern char localDisplay[MAX_DISPLAY_LENGTH+1]; */ /* Terminal's display string */
/*extern char localE164Num[MAX_E164NUM_LENGTH+1]; *//* Terminal's E.164 number */
static void processForwarding(int callIndex, int ipAddr, char *e164, int type)
{
HCALL hsCall;
WrapperMsg wpmsg;
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"processForwarding()\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
wpCallInfo[callIndex].isForwarded = RV_TRUE;
memset(&wpmsg, 0 ,sizeof(WrapperMsg));
wpmsg.baseInfo.callIndex = callIndex;
hsCall = wpCallInfo[callIndex].hsCall;
cmCallSetParam(hsCall, cmParamReleaseCompleteReason, 0, cmReasonTypeFacilityCallDeflection, NULL);
wpSendTerm(&wpmsg);
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Forwarded: send query to third party, ip = %x, e164 = %s\n",ipAddr, e164);
ReleaseSemaphore(fileSem,1,NULL);
}*/
memset(&wpmsg, 0 ,sizeof(WrapperMsg));
wpmsg.baseInfo.callIndex = callIndex;
if (type == REROUTE_TYPE_IPADDR)
{
unsigned char ip[4];
ip[0] = ipAddr >> 24;
ip[1] = (ipAddr >> 16) & 0xFF;
ip[2] = (ipAddr >> 8) & 0xFF;
ip[3] = ipAddr & 0xFF;
wpmsg.baseInfo.remoteIpAddr = ip[0] + ip[1]*0x100 + ip[2]*0x10000 + ip[3]*0x1000000;
}
else
{
strncpy(wpmsg.baseInfo.remoteE164Num, e164, MAX_E164NUM_LENGTH);
wpmsg.baseInfo.remoteE164Num[MAX_E164NUM_LENGTH] = '\0';
strncpy(wpmsg.baseInfo.localE164Num, AppParam.localE164, MAX_E164NUM_LENGTH);
wpmsg.baseInfo.localE164Num[MAX_E164NUM_LENGTH] = '\0';
}
strncpy(wpmsg.baseInfo.display, AppParam.localShow, MAX_DISPLAY_LENGTH);
wpmsg.baseInfo.display[MAX_DISPLAY_LENGTH] = '\0';
wpSendQuery(&wpmsg);
}
/***********************************************************************************
* Routine Name: wpcmEvCallFacility
* Description : Notify the application when the a new facility message is received.
* The applcation should check for parameters Param and Display that
* they are not NULL.
* Input : haCall - Application handle to the call.
* hsCall - CM handle to the call.
* handle - node ID of the message.
* Output: proceed - if set to true, the stack will process the message. o.w,
* the app will
* Return: none
***********************************************************************************/
int RVCALLCONV wpcmEvCallFacility(IN HAPPCALL haCall,
IN HCALL hsCall,
IN int handle,
INOUT RvBool* proceed)
{
int status;
cmAlias altalias;
cmTransportAddress altaddr;
int size = sizeof(cmTransportAddress);
int callIndex;
WrapperMsg msg;
int facRea = -1;
status = cmCallGetParam(hsCall, cmParamFacilityReason, 0,
(RvInt32 *) &facRea, NULL);
if (status < 0)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"in wpcmEvCallFacility,get parm facrea: %d!\n", status);
ReleaseSemaphore(fileSem,1,NULL);
}*/
return -1;
}
if (facRea != cmReasonTypeCallForwarded
&& facRea != cmReasonTypeTransportedInformation)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"facility reason:%d\n", facRea);
ReleaseSemaphore(fileSem,1,NULL);
}*/
return 0;
}
*proceed = RV_FALSE;
status = cmCallGetParam(hsCall, cmParamAlternativeAddress, 0,
(RvInt32 *) &size, (char *) &altaddr);
altalias.string = (char *) malloc(sizeof(char)*250);
if(status < 0)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Get alt ip address error, try to get the alias\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
size = sizeof(cmAlias);
status = cmCallGetParam(hsCall, cmParamAlternativeAliasAddress, 0,
(RvInt32 *) &size, (char *) &altalias);
}
/* Make sure the application processes this facility message,
only if it has an alternate address or alias in it. */
if (status < 0)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"in wpcmEvCallFacility,get parm error: %d!\n", status);
ReleaseSemaphore(fileSem,1,NULL);
}
*/
free(altalias.string);
return -1;
}
callIndex = wPGetCallIndex(hsCall);
if (callIndex == -1)
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"in wpcmEvCallFacility,get call Index error: %x!\n", hsCall);
ReleaseSemaphore(fileSem,1,NULL);
}
*/
free(altalias.string);
return -1;
}
if (cmReasonTypeCallForwarded == facRea) /* Recevied forward/transfer request */
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Call forward message recevied\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
msg.msgId = WP_CALL_FORWARD_RCVD;
msg.baseInfo.callIndex = callIndex;
if (size == sizeof(cmAlias))
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Forward address type: E.164\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
strncpy(msg.d.CallForwardInfo.ForwardToNumber, altalias.string,39);
msg.d.CallForwardInfo.ForwardToNumber[39]='\0';
msg.d.CallForwardInfo.ForwardToAddrType = REROUTE_TYPE_E164;
/*msg.d.CallForwardInfo.ForwardToAddrType = altalias.type;*/
msg.d.CallForwardInfo.ForwardToAddrLen = altalias.length;
}
else if (size == sizeof(cmTransportAddress))
{
unsigned char ip[4];
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Forward address type: IPv4\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
ip[0] = altaddr.ip >> 24;
ip[1] = (altaddr.ip >> 16) & 0xFF;
ip[2] = (altaddr.ip >> 8) & 0xFF;
ip[3] = altaddr.ip & 0xFF;
sprintf(msg.d.CallForwardInfo.ForwardToNumber,
"%u.%u.%u.%u", ip[3], ip[2], ip[1], ip[0]);
msg.d.CallForwardInfo.ForwardToAddrType = REROUTE_TYPE_IPADDR;
}
else
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"remote addr size error, return!\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
free(altalias.string);
return -1;
}
}
else
{
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"in wpcmEvCallFacility, FacilityReason:%d!\n", facRea);
ReleaseSemaphore(fileSem,1,NULL);
}
*/
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"add embranchment if you want to process!\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
free(altalias.string);
return 0;
}
(*wpForwardCycleFunc)(callIndex, msg.d.CallForwardInfo.ForwardToNumber,
&msg.d.CallForwardInfo.hasCycle);
if (msg.d.CallForwardInfo.hasCycle == RV_FALSE)
{
/* We do the forward processing */
processForwarding(callIndex, altaddr.ip, altalias.string,
msg.d.CallForwardInfo.ForwardToAddrType);
}
free(altalias.string);
wpSendMsgToApp(&msg);
return 0;
}
void wpSendRegister(WrapperMsg* msg)
{
int status;
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"start register...\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
status = cmRegister(hApp);
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"register return %d!\n", status);
ReleaseSemaphore(fileSem,1,NULL);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -