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

📄 gatestat.c

📁 ipt网关源码
💻 C
📖 第 1 页 / 共 5 页
字号:
           } 
		   break;


		/* Any drop whether from phone line or NetTSC is handled basically the same: */
      case TSC_EvtCallState_Type_Disconnected:
   
   	   gateTRACE(channel,(Session[channel].LogFile,"Got Call State Disconnected the reason is %d\n",
                    ((TSC_EvtCallState_t *)(pEvtData))->Reason));
   
      case DE_LCOFF:
      case DE_TONEON:
      case DIGITAL_ONHOOK:	 
           		
		 if(event != TSC_EvtCallState_Type_Disconnected) {
             Session[channel].waitOnHook = FALSE;
   	         gateTRACE(channel,(Session[channel].LogFile,"PSTN Disconnect on channel %d\n",
                        channel));
		 }

         /* Unlisten both sides */
         gateUnRoute(channel);

         /* Dropping call */
         Dm3TscDropCall(lpTsc,        /* pointer to DM3TSC structure */
                        /* Reason for dropping call */
      					   CallStateR_RemoteTermination);

         //呼叫终止后记录终止日期和时间,以备写入记费数据库
		 if (lpNetTsc->fIsInbound!=TRUE)  { //PSTN来话呼叫,记入用户原始记录表
            _strdate(tmpbuf);
			strcpy(uta[channel].end_date,tmpbuf);
			_strtime(tmpbuf);
			strcpy(uta[channel].end_time,tmpbuf);		  
		 }
		 else {  //IP来话记录,记入网关原始服务记录表中
			 _strdate(tmpbuf);
			strcpy(gsa[channel].end_date,tmpbuf);
			_strtime(tmpbuf);
			strcpy(gsa[channel].end_time,tmpbuf);		  

		 }

		   chanInfo[channel].callsDropped++;
		   gateUpdate(pCamelSession,GATE_WAIT_IDLE);
         break; 
   
      default:
         gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in WaitForDisconnect\n",
                   gateEventStr(event),event,channel));
         break;

   } /* end switch(event) */

   return (DM3SUCCESS);

} /* Function gateWaitForDisconnect */

/*****FUNCTION***************************************************
*        NAME : gateWaitForIdle
* DESCRIPTION : Gateway is waiting for idle state, 
*               then get information about the call and send release 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 gateWaitForIdle(LPDM3NetTSC  lpNetTsc, 
                       LONG         event,
					        void         *pEvtData)

{
   BOOL          rBool;
   UInt32        InfoArr[3];
   LPDM3TSC      lpTsc;
   GateSession   *pCamelSession;
   USHORT        channel;


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

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


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

	   /* Got idle state */
      case TSC_EvtCallState_Type_Idle:
   
		 chanInfo[channel].callsIdle++;
         /* Set array for get call info message */
         InfoArr[0] = CallInfo_RTCPInfo;
   	     InfoArr[1] = CallInfo_CallDurationTime;
         
          /* Get call information */
          Dm3TscGetCallInfo(lpTsc,2,InfoArr);
	      break;

	   case TSC_MsgGetCallInfoCmplt:
   
         /* Releasing call */
         rBool = Dm3TscReleaseCall(lpTsc,     /* poinet to DM3TSC structure */
                                  /* reason for releasing the 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(pCamelSession,GATE_WAIT_RELEASE);
         }
         break;
   
      case DIGITAL_OFFHOOK:
   
         Session[channel].waitOnHook = TRUE;

         break;

      case DIGITAL_ONHOOK:
   
         Session[channel].waitOnHook = FALSE;

         break;

      /* 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;
   
      default:
         //gateUpdate(pCamelSession,GATE_WAIT_RELEASE); //add by xuzq 98.6.12
         gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in WaitForIdle\n",
                   gateEventStr(event),event,channel));
   	   break;

   } /* end switch(event) */

   return (DM3SUCCESS);

} /* Function gateWaitForIdle */

/*****FUNCTION***************************************************
*        NAME : gateWaitForRelease
* DESCRIPTION : Waiting for null, then set pstn on-hook
*               and reset data structure
*       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 gateWaitForRelease(LPDM3NetTSC  lpNetTsc, 
                          LONG         event,
					           void         *pEvtData)

{

   LPDM3TSC       lpTsc;
   GateSession    *pCamelSession;
   USHORT         channel;
   BOOL           rBool;  


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


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

  
   switch(event) {
   
      case DIGITAL_OFFHOOK:
   
         Session[channel].waitOnHook = TRUE;

         break;

      case DIGITAL_ONHOOK:
   
         Session[channel].waitOnHook = FALSE;

         break;

	   /* Got null event */
      case TSC_EvtCallState_Type_Null:

		   //将本次呼叫的数据结构集中存入数据库
   if (lpNetTsc->fIsInbound!=TRUE) {  //PSTN来话呼叫
       if (uta[channel].duration_time!=0) {  //通话时间为零的不记录
	    //SQL语句的数据库操作
		/* printf("INSERT INTO user_time_account VALUES ('%s','%s','%s','%s','%s','%s','%s','%s',%d,%d,%d)",
					 uta[channel].user_id,		uta[channel].caller_num,
					 uta[channel].called_num,	uta[channel].ip_address,
					 uta[channel].start_date,	uta[channel].start_time,
					 uta[channel].end_date,		uta[channel].end_time,
					 uta[channel].duration_time,uta[channel].recv_pktnum,
					 uta[channel].send_pktnum);*/


	    dbfcmd(dbproc,"INSERT INTO user_time_account VALUES ('%s','%s','%s','%s','%.8s','%.8s','%.8s','%.8s',%d,%d,%d)",
					 uta[channel].user_id,		uta[channel].caller_num,
					 uta[channel].called_num,	uta[channel].ip_address,
					 uta[channel].start_date,	uta[channel].start_time,
					 uta[channel].end_date,		uta[channel].end_time,
					 uta[channel].duration_time,uta[channel].recv_pktnum,
					 uta[channel].send_pktnum);

	   // Send the command to SQL server and start execution
		dbsqlexec(dbproc);

		        while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
				{
					if (return_code == FAIL)
					printf("One of the insert statements FAILed.\n");
				}
		}

   }
   else{  //IP来话呼叫
   if (gsa[channel].duration_time!=0) {  //通话时间为零的不记录
	   //SQL语句的数据库操作
	  dbfcmd(dbproc,"INSERT INTO gateway_service_account VALUES ('%s','%s','%s','%.8s','%.8s','%.8s','%.8s',%d,%d,%d)",
					 gsa[channel].ip_address,	gsa[channel].gateway_code,
					 gsa[channel].called_num,	gsa[channel].start_date,	
					 gsa[channel].start_time,	gsa[channel].end_date,		
					 gsa[channel].end_time,     gsa[channel].duration_time,
					 gsa[channel].recv_pktnum,  gsa[channel].send_pktnum);

       // Send the command to SQL server and start execution
		dbsqlexec(dbproc);

				while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
				{
					if (return_code == FAIL)
					printf("One of the insert statements FAILed.\n");
				}

          }
   }


   

          if( lpTsc->fBusy) {
			  // add by xuzq 98.6.16
			  lpTsc->fBusy=FALSE;
          //使用同步停止通道
	      if (dx_stopch(channel, EV_SYNC)==-1) {
          	  printf("Error in stop channel %d !\n",channel);     	  
		  }
             /* Set PSTN on-hook */
			    rBool = pstnOnHook(channel);
			    if(rBool==DM3FAIL) {
				    gateFATAL(channel,(Session[channel].LogFile,"\tError setting on hook for channel %d in Wait For Disconnect\n",
							channel));
			    }  
		    }

		  
		    
       
   
         break;

	  case DX_ONHOOK:  //改为异步挂机,要检测挂机信号

		  chanInfo[channel].callsNull++;
	

			if(((frontEnd == GATE_LEGACY_T1) || (frontEnd == GATE_LEGACY_E1)) 
				  && (Session[channel].waitOnHook == TRUE) ) {
					  if((pstnState(channel) == TRUE)) {
						  gateUpdate(pCamelSession,PSTN_RELEASE);
						  return(DM3SUCCESS);
					  }
			  }		
				  /* Reset session */
          IPTResetSession(channel,FALSE);  //此函数就将通道状态转至Gate_Wait_for_call
		  // add by xuzq 98.6.16
          //使用同步停止通道
	      //if (dx_stopch(channel, EV_SYNC)==-1) {
          //	  printf("Error in stop channel %d !\n",channel);
     	  
		  //}
		  break;
	
	 // case TM_USRSTOP:
	 // case CR_STOPD:
	
          
      /* 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;
   
      default:
   
         gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in WaitForRelease\n",
                   gateEventStr(event), event,channel));
   

   	  break;
   
   } /* end switch(event) */

   return (DM3SUCCESS);

} /* Function gateWaitForRelease */

/*****FUNCTION***************************************************
*        NAME : gatePstnRelease
* DESCRIPTION : Waiting for on hook from PSTN:
*
*       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 gatePstnRelease(LPDM3NetTSC  lpNetTsc, 
                          LONG         event,
					           void         *pEvtData)

{
   BOOL            rBool;
   LPDM3TSC        lpTsc;
   GateSession     *pCamelSession;
   USHORT          channel;;


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


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

   switch(event) {

      case DIGITAL_ONHOOK:

          /* Reset session */

⌨️ 快捷键说明

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