📄 gatemain.c
字号:
/**********************************************************************************************
*
* $ProjectName: X:/SIPROJ/VOIP/HOST/WIN_NT/DEMOS/Samples.rel5/Dm3/Iplink/project.pj $
* $ProjectRevision: 1.5 $
* $Label$
* $Revision: 1.7 $ - $Date: 2001/10/21 13:21:20 $
*
**********************************************************************************************/
#define _GATEMAIN_C
#include "main.h"
#include <pdl.h>
#include "gatestrc.h"
#include "gatedefs.h"
#include "gatevars.h"
#include <libdbg.h>
#include "gatepstn.h"
#include "gateip.h"
#include "gatepars.h"
#include "gatestate.h"
#include "time.h"
#include "incfile.h"
#include "gateway_r4.ver"
#include "util.ver"
#include "pdl.ver"
char cfgFile[80]; /* file name for configuration file */
FILE *ChanInfoFile; /* file for printing all channels information */
/*****FUNCTION***************************************************
* NAME : getChannel
* DESCRIPTION : Gets the active channel to send message to
* INPUT : None
* OUTPUT : None
* RETURNS : int - Channel number
* CAUTIONS : None
****************************************************************/
int getChannel()
{
char chan[10];
char ch;
char channel[80];
int count = 0;
int bCorrectInput = 1;
char temp[80];
printf("activeChannel = %d.\n",activeChannel);
printf("%s","Would you like to change the active channel?(y-YES,n-NO)\n");
scanf("%s",chan);
ch = chan[0];
switch(ch) {
/* The user would like to change the active channel */
case 'y':
case 'Y':
printf("%s","Enter the active channel you want.\n");
scanf("%s",channel);
while(bCorrectInput) {
if( (channel[count] < '0') || (channel[count] > '9') ) {
bCorrectInput = 0;
}
else {
count++;
}
}
if(count > 0) {
strncpy(temp,channel, count);
return(atoi(temp));
}
break;
/* The user wouldn't like to change the active channel,
default is activeChannel = the last channel which entered connected state */
case'n':
case'N':
default:
break;
}
return(activeChannel);
} /* Function getChannel */
/*****FUNCTION***************************************************
* NAME : SendUIIMsg
* DESCRIPTION : A convenient function to send UII Message (H.245).
* INPUT : channel
* OUTPUT : None
* RETURNS : 0 - success, 1 - fail
* CAUTIONS : Only works if PrmDtmfXferMode set to 1 in fcd file.
****************************************************************/
int SendUIIMsg(unsigned int channel)
{
GC_PARM_BLKP gcParmBlk = NULL;
if (gc_util_insert_parm_val(&gcParmBlk, IPSET_MSG_H245, IPPARM_MSGTYPE,
sizeof(int), IP_MSGTYPE_H245_INDICATION) <0 ){
printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_util_insert_parm_ref(&gcParmBlk, IPSET_USERINPUTINDICATION,
IPPARM_UII_ALPHANUMERIC,
(unsigned char)(strlen(Session[channel].ConfigFileParm.UII.Val)+1),
(void*)(Session[channel].ConfigFileParm.UII.Val))<0 ){
printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_Extension(GCTGT_GCLIB_CRN,
Session[channel].ipParams.currentCRN,
IPEXTID_SENDMSG,
gcParmBlk,NULL,EV_ASYNC)<0){
printGCError("gc_Extention",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}else{
gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\tUII message(H.245) was sent on channel %d \n",channel));
}
gc_util_delete_parm_blk(gcParmBlk);
return FUNCSUCCESS;
} /* End of SendUIIMsg function */
/*****FUNCTION***************************************************
* NAME : SendNonStdCmdMsg
* DESCRIPTION : A convenient function to send Nonstandard Command
* Message (H.245).
* INPUT : channel
* OUTPUT : None
* RETURNS : 0 - success, 1 - fail
* CAUTIONS :
****************************************************************/
int SendNonStdCmdMsg(unsigned int channel)
{
GC_PARM_BLKP gcParmBlk = NULL;
if (gc_util_insert_parm_val(&gcParmBlk, IPSET_MSG_H245, IPPARM_MSGTYPE,
sizeof(int), IP_MSGTYPE_H245_COMMAND) <0 ){
printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_util_insert_parm_ref(&gcParmBlk, IPSET_NONSTANDARDDATA,
IPPARM_NONSTANDARDDATA_OBJID,
(unsigned char)(strlen(Session[channel].ConfigFileParm.NonStdCmd.ObjId) +1),
(void*)Session[channel].ConfigFileParm.NonStdCmd.ObjId) <0 ){
printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_util_insert_parm_ref(&gcParmBlk, IPSET_NONSTANDARDDATA,
IPPARM_NONSTANDARDDATA_DATA,
(unsigned char)(strlen(Session[channel].ConfigFileParm.NonStdCmd.Val)+1),
(void*)(Session[channel].ConfigFileParm.NonStdCmd.Val)) <0 ){
printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_Extension(GCTGT_GCLIB_CRN,
Session[channel].ipParams.currentCRN,
IPEXTID_SENDMSG,
gcParmBlk,NULL,EV_ASYNC)<0){
printGCError("gc_Extention",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}else{
gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\tNonstandard Command message(H.245) was sent on channel %d \n",channel));
}
gc_util_delete_parm_blk(gcParmBlk);
return FUNCSUCCESS;
} /* End of SendNonStdCmdMsg function */
/*****FUNCTION***************************************************
* NAME : SendFacilityMsg
* DESCRIPTION : A convenient function to send Q931 Facility message.
* INPUT : channel
* OUTPUT : None
* RETURNS : 0 - success, 1 - fail
* CAUTIONS :
****************************************************************/
int SendFacilityMsg(unsigned int channel)
{
GC_PARM_BLKP gcParmBlk = NULL;
if (gc_util_insert_parm_val(&gcParmBlk, IPSET_MSG_Q931, IPPARM_MSGTYPE,
sizeof(int), IP_MSGTYPE_Q931_FACILITY) <0 ){
printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_util_insert_parm_ref(&gcParmBlk, IPSET_NONSTANDARDDATA,
IPPARM_NONSTANDARDDATA_OBJID,
(unsigned char)(strlen(Session[channel].ConfigFileParm.Q931Facility.ObjId) +1),
(void*)Session[channel].ConfigFileParm.Q931Facility.ObjId) <0 ){
printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_util_insert_parm_ref(&gcParmBlk, IPSET_NONSTANDARDDATA,
IPPARM_NONSTANDARDDATA_DATA,
(unsigned char)(strlen(Session[channel].ConfigFileParm.Q931Facility.Data)+1),
(void*)(Session[channel].ConfigFileParm.Q931Facility.Data)) <0 ){
printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}
if (gc_Extension(GCTGT_GCLIB_CRN,
Session[channel].ipParams.currentCRN,
IPEXTID_SENDMSG,
gcParmBlk,NULL,EV_ASYNC)<0){
printGCError("gc_Extention",channel,Session[channel].LogFile,_logLevel);
return (FUNCFAIL);
}else{
gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\tFacility message(Q931) was sent on channel %d \n",channel));
}
gc_util_delete_parm_blk(gcParmBlk);
return FUNCSUCCESS;
} /* End of SendFacilityMsg function */
/*****FUNCTION***************************************************
* NAME : waitForKey
* DESCRIPTION : Thread waiting for key: q , ctrl+c to end application
* u - to send user input indication
* n - to send non standard command
* c - get channel information
* f - send Q931 Facility information
* d - change debug level on runtime
* INPUT : None
* OUTPUT : None
* RETURNS : unsigned long '0' - success
* CAUTIONS : getch() func disable detection of
* interrupts from the keyboard
****************************************************************/
unsigned long waitForKey()
{
char chan[10];
char ch;
unsigned short channel = 0;
while(!quitFlag) { /* quitFlag is a global variable which indicates that
the user wants to end the application */
scanf("%s",chan);
ch = chan[0];
switch(ch) {
case 'c':
case 'C':
printChanInfo("ChInIP.txt",chanInfoIP);
printChanInfo("ChInPSTN.txt",chanInfoPSTN);
break;
case 'd':
case 'D':
/* change debug level on runtime */
ChangeDebugLevel(&_logLevel);
break;
case 3: /* The ascii code of Ctrl+c */
case 'q':
case 'Q':
PDLsr_putevt(Session[1].ipParams.linedev);
break;
case 'u':
case 'U':
channel = getChannel();
/* Check if valid channel value */
if( (channel <= 0) || (channel > gateChannels) ) {
break;
}
/* Sends UII only in IP_CONNECTED or GATE_CONNECTED state */
if((Session[channel].sessionState == IP_CONNECTED)
|| (Session[channel].sessionState == GATE_CONNECTED)){
activeChannel = channel;
if (SendUIIMsg(channel) != 0){
if (_logLevel !=0){
printf("\nERROR: Unable to send User Input Indication on channel %d \n\tReason: Function failed\n",channel);
}
gateERROR(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnable to send User Input Indication on channel %d \n\tReason: Function failed.\n",channel));
}else{
chanInfoIP[channel].UII_Msg++;
}
}else{
if (_logLevel !=0){
printf("\nERROR: Unable to send user input indication on channel %d \n\tReason: is not in connected state\n",channel);
}
gateERROR(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnable to send user input indication on channel %d \n\tReason: is not in connected state.\n",channel));
}
break;
case 'n':
case 'N':
channel = getChannel();
/* Check if valid channel value */
if( (channel <= 0) || (channel > gateChannels) ) {
break;
}
/* Sends Non Standard Command, only in IP_CONNECTED or GATE_CONNECTED state */
if((Session[channel].sessionState == IP_CONNECTED)
|| (Session[channel].sessionState == GATE_CONNECTED)){
activeChannel = channel;
if (SendNonStdCmdMsg(channel) != 0){
if (_logLevel !=0){
printf("\nERROR: Unable to send Nonstandard Command on channel %d \n\tReason: Function failed\n",channel);
}
gateERROR(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnable to send Nonstandard Command on channel %d \n\tReason: Function failed.\n",channel));
}else{
chanInfoIP[channel].NonStdCmd_Msg++;
}
}else{
if (_logLevel !=0){
printf("\nERROR: Unable to send Nonstandard Command on channel %d \n\tReason: is not in connected state\n",channel);
}
gateERROR(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnable to send Nonstandard Command on channel %d \n\tReason: is not in connected state.\n",channel));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -