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

📄 gatestat.bak.txt

📁 ipt网关源码
💻 TXT
📖 第 1 页 / 共 3 页
字号:
/**********************************************************************************************
* 
* $ProjectName: X:\SIPROJ\VOIP\HOST\WIN_NT\DEMOS\VOIPGATE\PROJECT.PJ $
* $ProjectRevision: 1.1 $
* $Label$
* $Revision: 1.5 $ - $Date: 1997/07/14 14:53:59 $
* 
**********************************************************************************************/

#define  _GATESTATE_C

#include <dm3tsc.h>
#include <dm3ntsc.h>

/* The DEMO H files are needed in this order: */
#include "GateDbg.h"
#include "PstnFP.h"             
#include "NTscClst.h"
#include "main.h"             
#include "GateStrc.h"             
#include "gateVars.h"


/*****FUNCTION **********************************************
*        NAME : gateUpdate 
* DESCRIPTION : Update Session state and state machine function
*       INPUT : GateSession * pCamelsession   -  Channel to update information 
*               USHORT newState  -  New state to update channel to
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None.
****************************************************************/
void gateUpdate(GateSession * pCamelsession, 
                USHORT newState)

{
   pCamelsession->sessionState = newState;
   pCamelsession->stateFxn = gateFunctionList[newState];

} /* Function gateUpdate */


/*****FUNCTION***************************************************
*        NAME : gateWaitForDetectCmplt
* DESCRIPTION : Waiting for detect event complete, 
*               so the application will be ready to take a call
*       INPUT : LPDM3NetTSC  lpNetTsc   -  pointer to NetTsc structure
*               LONG         event      -  the recieved event
*  				 void         *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
USHORT gateWaitForDetectCmplt(LPDM3NetTSC  lpNetTsc, 
                              LONG         event,
					               void         *pEvtData)

{

   LPDM3TSC       lpTsc;
   GateSession    *pCamelSession;
   USHORT         channel;


   pCamelSession = (GateSession *)(lpNetTsc->lpUserInfo);
   channel = pCamelSession->sessionNumber;
   lpTsc = NETTSC_GET_DM3TSC(lpNetTsc);


   gateTRACE(channel,(Session[channel].LogFile,"In GATE_WAIT_DETECT_CMPLT on channel %d\n\t got Event %s (0x%x)\n", 
             channel,gateEventStr(event), event));

   switch(event) {
   
      /* Case of Exit Notification */
      case TSC_EvtChanState_Type_OutOfService:
   
          gateTRACE(channel,(Session[channel].LogFile,"Channel %d OutOfService.\n",channel));
          gateExit(CHAN_OUT_OF_SERVICE,channel);
          break;
   
      /* The expected event, so now it is possible to take a call */
      case Std_MsgDetectxEvtsCmplt:
		    gateUpdate(pCamelSession,GATE_WAIT_CALL);
          break;
   
      default:
   
          gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in gateWaitForDetectCmplt\n",
                   gateEventStr(event), event,channel));
   
   	    return(DM3SUCCESS);
   
   } /* end switch(event) */

   return (DM3SUCCESS);

} /* Function gateWaitForDetectCmplt */

  
/*****FUNCTION***************************************************
*        NAME : gateWaitForCall
* DESCRIPTION : The function waits for a call: 
*                    *  If it comes from the NetTSC (offering call):
*                                Get call information, after GetCallInfoCmplt
*                                recieved send MsgAnswerCall and move to new state. 
*                    *  If it comes from the phone line (make call):
*                                Route DM3 to D/xxx and D/xxx to DM3
*                                Send MsgMakeCall, move to new state 
*                                after makeCallCmplt is recieved.
*       INPUT : LPDM3NetTSC  lpNetTsc   -  pointer to NetTsc structure
*               LONG         event      -  the recieved event
*  				 void         *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
USHORT gateWaitForCall(LPDM3NetTSC  lpNetTsc, 
                       LONG         event,
					        void         *pEvtData)
{
   BOOL            rBool;   
   USHORT          infoCount;
   UInt32          InfoArr[MAX_CODER_CAPABILITY+7];
   KVDESC          KV_Info[MAX_CODER_CAPABILITY+7];
   char            srcAddr[128];           
   char            destAddr[128]; 
   LPDM3TSC        lpTsc;
   CallParameters  CFGParm;
   CallParameters  *lpCallParm;
   GateSession     *lpCamelSession;
   USHORT          channel;;


   lpCamelSession = (GateSession *)(lpNetTsc->lpUserInfo);
   channel = lpCamelSession->sessionNumber;
   lpTsc = NETTSC_GET_DM3TSC(lpNetTsc);
   lpCallParm = NETTSC_GET_CALLPARM(lpNetTsc);
   CFGParm = lpCamelSession->ConfigFileParm;

   gateTRACE(channel,(Session[channel].LogFile,"In WAIT_FOR_CALL on channel %d\n\t got event %s (0x%x)\n", 
               channel,gateEventStr(event), event));


   /* Switch on event */
   switch(event) {

      /* Case of Exit Notification */
      case TSC_EvtChanState_Type_OutOfService:
   
          gateTRACE(channel,(Session[channel].LogFile,"Channel %d OutOfService.\n",channel));
          gateExit(CHAN_OUT_OF_SERVICE,channel);
          break;
   
		  /* Case of Offering from LAN  */
      case TSC_EvtCallState_Type_Offered: 
   
		 chanInfo[channel].callsOffered++;

          /* Check if "busy" or the user asked to quit the application,
             Then reject the call */
          if( lpTsc->fBusy ) {

             rBool = Dm3TscRejectCall(lpTsc,      /* pointer to DM3TSC structure */
                                      /* reason for rejecting the call */
                                      TSC_MsgRejectCall_Reason_Busy);   

             if(rBool==DM3FAIL) {
                gateFATAL(channel,(Session[channel].LogFile,"\tError rejecting Call channel %d\n", channel));
                return(DM3FAIL);
             } 
      		 gateTRACE(channel,(Session[channel].LogFile,"\tRejecting call on channel %d\n",channel));
		     chanInfo[channel].callsRejected++;
   		    gateUpdate(lpCamelSession,GATE_WAIT_IDLE);
   		    return(DM3SUCCESS);
   
          } 
   
      	 /* Set busy */
      	 lpTsc->fBusy = TRUE;
      
		    /*
           * Get call information 
          */

          /* Set array for get call info message */
      	 InfoArr[0] = CallInfo_PhoneList;      /* Local extention to call */
		 InfoArr[1] = CallInfo_CallerId;       /* Who's calling - Computer IP */
          InfoArr[2] = CallInfo_Display;        /* Who's calling - Caller name */
		    InfoArr[3] = CallInfo_UUI;		      /* User to User Information */
		    Dm3TscGetCallInfo(lpTsc,     /* pointer to DM3TSC structure */
                            4,         /* number for call information elements */
                            InfoArr);  /* the information elements */
          gateTRACE(channel,(Session[channel].LogFile,"\tGetting call information on channel %d\n",channel));
          break; /* End of net Offering case */

      /* Got call information, now send answer call */
      case TSC_MsgGetCallInfoCmplt :

      		 /* Update the local phone number to call, 
                according the information recieved */
             if(strcmp(lpCallParm->phoneList,"\0") != 0) {
      			strcpy(lpCallParm->localPhoneNumber,lpCallParm->phoneList);
      		 } 
			    else {
      			strcpy(lpCallParm->localPhoneNumber,CFGParm.localPhoneNumber);
      		 }

		       /* 
              * Answer the call 
             */
      
             /* Prepare the KVSet for answering the call */
             for(infoCount = 0; infoCount < (CFGParm.maxTxCoders); infoCount++) {
   				 KV_Info[infoCount].unKeyId  = TSC_KVSet_Key_CallInfo;
   				 KV_Info[infoCount].unId = CallInfo_TxCoder;
   				 KV_Info[infoCount].unLength  = sizeof(NetTSC_Coder_t);
      		    KV_Info[infoCount].lpData = &((void)(CFGParm.TxCoder[infoCount]));
			    }

             KV_Info[infoCount].unKeyId = TSC_KVSet_Key_NULL;
				 KV_Info[infoCount].unLength  = 0;
             infoCount++;

      
			    rBool = Dm3TscAnswerCall(lpTsc,       /* pointer to DM3TSC structure */
                                      2,           /* number to rings */
                                      KV_Info,     /* KV-Set array */
                                      infoCount);  /* number of KV-Set elements */

      		 if(rBool==DM3FAIL) {
      			 gateFATAL(channel,(Session[channel].LogFile,"\tError MsgAnswerCall on channel %d\n", channel));
      		 } 
             else {
                gateTRACE(channel,(Session[channel].LogFile,"\tAnswering call on channel %d\n",channel));
		          gateUpdate(lpCamelSession,GATE_WAIT_CONNECT);
             }
      

   
          break; /* End of TSC_MsgGetCallInfoCmplt case */
   
      /* ...._Idle can happen if the originator decided to
		  hang up before we got CallInfoCmplt*/
      case TSC_EvtCallState_Type_Idle:

		  chanInfo[channel].callsIdle++;
          /* Releasing call */
          rBool = Dm3TscReleaseCall(lpTsc,     /* pointer to DM3TSC structure */
                                    /* reason for releasing call */
                                  TSC_MsgRejectCall_Reason_Busy);
          if(rBool==DM3FAIL) {
             gateFATAL(channel,(Session[channel].LogFile,"\tError releasing Call channel %d \n", channel));
             return(DM3FAIL);
         
          } 
          else {
             gateTRACE(channel,(Session[channel].LogFile,"Releasing call on channel %d.\n",channel));
		       gateUpdate(lpCamelSession,GATE_WAIT_RELEASE);
          }
		    return(DM3SUCCESS);

		    break; /* End of TSC_EvtCallState_Type_Idle case */

      /* Got a telephone ring incoming */
      case DE_RINGS:
      case DIGITAL_OFFHOOK:  

  
          /* Check if "busy" */
          if(lpTsc->fBusy==TRUE) {
             gateTRACE(channel,(Session[channel].LogFile,"\tBusy on incoming rings of channel %d\n",channel));
             return (DM3FAIL);
          } 

          /* Set the channel "busy" and sign the call as outgoing call */
          lpTsc->fBusy=TRUE;
          lpNetTsc->fIsInbound = FALSE;
          Session[channel].waitOnHook = TRUE;

          /* Route the channels */
          rBool = gateRoute(channel);
          if(rBool !=DM3SUCCESS) {
             gateFATAL(channel,(Session[channel].LogFile,"Error routing on channel %d\n",channel));
          } 
         
          /* Go off hook */
          if(pstnOffHook(channel) == DM3FAIL)  {
               gateFATAL(channel,(Session[channel].LogFile,"\tError setting line on channel %d\n"));
          }
 
         /* 
          * Make NetTSC call 
         */

         /* Set array of information to make call */
         for(infoCount = 0; infoCount < (CFGParm.maxTxCoders); infoCount++) {
             KV_Info[infoCount].unKeyId  = TSC_KVSet_Key_CallInfo;
             KV_Info[infoCount].unId = CallInfo_TxCoder;
             KV_Info[infoCount].unLength  = sizeof(NetTSC_Coder_t);
             KV_Info[infoCount].lpData = &((void)(CFGParm.TxCoder[infoCount]));
         }

         KV_Info[infoCount].unKeyId  = TSC_KVSet_Key_CallInfo;
         KV_Info[infoCount].unId = CallInfo_Display;
         KV_Info[infoCount].unLength  = strlen(CFGParm.display)+1;
         KV_Info[infoCount].lpData = ((void *)CFGParm.display);
         infoCount++;

         KV_Info[infoCount].unKeyId  = TSC_KVSet_Key_CallInfo;
         KV_Info[infoCount].unId = CallInfo_PhoneList;
         KV_Info[infoCount].unLength  = strlen(CFGParm.phoneList)+1;
         KV_Info[infoCount].lpData = ((void *)CFGParm.phoneList);
         infoCount++;

         KV_Info[infoCount].unKeyId  = TSC_KVSet_Key_CallInfo;
         KV_Info[infoCount].unId = CallInfo_UUI;
         KV_Info[infoCount].unLength  = strlen(CFGParm.IPT_UUI)+1;
         KV_Info[infoCount].lpData = (void *)CFGParm.IPT_UUI;
         infoCount++;


         KV_Info[infoCount].unKeyId = TSC_KVSet_Key_NULL;
         KV_Info[infoCount].unLength  = 0;
         infoCount++;


         /* Set source address of call */
         strcpy(srcAddr,"TA:");
         strcat(srcAddr,CFGParm.srcAddr);
         strcat(srcAddr,":1720");
         
         /* Set destination address of call : i.e. destination a computer on other end
            start with the basic TSC make call structure */
         strcpy(destAddr,"TA:");
         strcat(destAddr,CFGParm.destAddr);
         strcat(destAddr,":1720");     /* Add Port id */
        

         rBool = Dm3TscMakeCall(lpTsc,        /* pointer to DM3TSC structure */
                                destAddr,     /* destination IP address */
                                srcAddr,      /* source IP address */
                                FALSE,        /* set for call progress */
                                KV_Info,      /* array of KV-Set */
                                infoCount);   /* number of KV-Set elements */

         if(rBool==DM3FAIL) {
            gateFATAL(channel,(Session[channel].LogFile,"\tError making call on channel %d\n"));
            return(DM3FAIL);
         }
		 chanInfo[channel].callsMade++;
         gateTRACE(channel,(Session[channel].LogFile,"\tMaking call on channel %d\n",channel));
		 gateUpdate(lpCamelSession,GATE_WAIT_CONNECT);
         break; /* End DE_RING case */
   
   default:

        gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in WaitForCall\n",
                  gateEventStr(event),event,channel));
        break;

   } /* end switch(event) */

⌨️ 快捷键说明

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