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

📄 gatestate.c

📁 dialogic voip 测试代码
💻 C
📖 第 1 页 / 共 4 页
字号:
						  chanInfoPSTN[channel].callsOffered++;
					      /* Send accept call to pstn */
					      if (gc_AcceptCall(Session[channel].pstnParams.currentCRN, 0, EV_ASYNC)<0) {
					          printGCError("gc_AcceptCall",channel,Session[channel].LogFile,_logLevel); 
	                          return (FUNCFAIL);  
						  }else{

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"gc_AcceptCall was sent to PSTN on channel %d\n", channel));

						  }	

                          						  
						  /* Fill gcParmBlk structure */
		                  for(infoCount = 0; infoCount < (CFGParm.maxTxCoders); infoCount++) {
							  if (gc_util_insert_parm_ref(&gcParmBlk,GCSET_CHAN_CAPABILITY, IPPARM_LOCAL_CAPABILITY,
	            	             sizeof(IP_CAPABILITY),(&(CFGParm.Coder[infoCount]))) < 0){
								  printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel); 
							  }
						  }
		                    /* Insert the User to User Information */
		                 if (gc_util_insert_parm_ref(&gcParmBlk,IPSET_CALLINFO, IPPARM_USERUSER_INFO,

	            									 (unsigned char)(strlen(CFGParm.IPT_UUI)+1),

													 (&(CFGParm.IPT_UUI))) < 0){

							 printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel); 

						 }

						    /* Insert the display */

						 if (gc_util_insert_parm_ref(&gcParmBlk,IPSET_CALLINFO, IPPARM_DISPLAY,

	            									 (unsigned char)(strlen(CFGParm.display)+1),

													 (&(CFGParm.display))) < 0){

							 printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel); 

						 }

                             /* Insert the phone list */

						 if (gc_util_insert_parm_ref(&gcParmBlk,IPSET_CALLINFO, IPPARM_PHONELIST,

	            									 (unsigned char)(strlen(CFGParm.phoneList)+1),

													 (&(CFGParm.phoneList))) < 0){

							 printGCError("gc_util_insert_parm_ref",channel,Session[channel].LogFile,_logLevel); 

						 }



						 if (gc_SetUserInfo(GCTGT_GCLIB_CHAN,Session[channel].ipParams.linedev,gcParmBlk,GC_SINGLECALL)<0) {
			                  printGCError("gc_SetUserInfo",channel,Session[channel].LogFile,_logLevel ); 
	                          return (FUNCFAIL);  
						 }

                          gc_util_delete_parm_blk(gcParmBlk); 

					      /* Send make call to IP */
					      if (ipMakeCall(channel) == FUNCFAIL){
                              return (FUNCFAIL);  
						  }else{

							  chanInfoIP[channel].callsMake++;

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Making Call to IP on channel %d\n", channel));

						  }	

					      
					      gateUpdate(&(Session[channel]),PSTN_OFFERED);
					  }
					  
				  }
				  break;
				  	          
		  }/* end switch(compKey) */
		  break;
		 
		default:
		  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in gateNull from %s\n",
               gateEventStr(event),event,channel,gateKeyStr(compKey)));
          break;

   } /* end switch(event) */


   return (FUNCSUCCESS);

} /* Function gateNull */


/*****FUNCTION***************************************************
*        NAME : gateIPOffered
* DESCRIPTION : The function waits for answered from ip,
*				after getting Offer from IP.
*       INPUT : unsigned int         channel  -  channel which got the event
*               COMP_KEY       compKey  -  name of the component
*                                          that got the event
*               long         event      -  the recieved event
*  				 void        *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
unsigned short gateIPOffered(unsigned int channel, COMP_KEY compKey, long event,void * EvtData)
{
   
   char            destAddr[128];
   unsigned short          infoCount;
   CallParameters  CFGParm;
   SC_TSINFO       tsInfo;
   unsigned long           tsArray[1];
   GC_PARM_BLKP    gcParmBlk = NULL;

 
  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"In IP_OFFERED State on channel (0x%x)\n\t got event %s (0x%x) from %s\n", 
             channel,gateEventStr(event), event, gateKeyStr(compKey)));

  

  CFGParm = Session[channel].ConfigFileParm; 

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

	  

   

      case GCEV_DETECTED:
      case GCEV_OFFERED:
		  chanInfoPSTN[channel].callsOffered++;
          
		   /* We get into IPOffered state only if the PSTN.currentCRN == 0, so in this case when OFFERED/DETECTED event 
		     arrives , the PSTN.currentCRN will be updated in the pstnGetEvent function */ 
		  Session[channel].pstnParams.glareCRN = Session[channel].pstnParams.currentCRN;
		 
		  /* ip have already gotten offered, drop the calls */
		  if (gc_DropCall(Session[channel].pstnParams.glareCRN, GC_NORMAL_CLEARING, EV_ASYNC)<0){
			  printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	          return (FUNCFAIL);  
		  }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(glareCRN) to PSTN on channel %d\n", channel));

		  }

		  
		  if (gc_DropCall(Session[channel].ipParams.currentCRN, GC_CALL_REJECTED, EV_ASYNC)<0){
			  printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	          return (FUNCFAIL);  
		  }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to IP on channel %d\n", channel));

		  }


		  Session[channel].NumOfDropExpected = 2;
          chanInfoPSTN[channel].callsRejected++;
		  gateUpdate(&(Session[channel]),GATE_DROP);
		  break;

	  case GCEV_PROCEEDING:
		  break;
     
	  /* Got call information, now send answer call */
      case GCEV_EXTENSION:

		  
          /* Fill gcParmBlk structure */
		  for(infoCount = 0; infoCount < (CFGParm.maxTxCoders); infoCount++) {
			  if (gc_util_insert_parm_ref(&gcParmBlk,GCSET_CHAN_CAPABILITY, IPPARM_LOCAL_CAPABILITY,
	            	sizeof(IP_CAPABILITY),(&(CFGParm.Coder[infoCount]))) < 0){
			     printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 
				 return (FUNCFAIL); 
				 break;
			  }
		  }
		            
		  if (gc_SetUserInfo(GCTGT_GCLIB_CRN,Session[channel].ipParams.currentCRN,gcParmBlk,GC_SINGLECALL)<0) {
			 printGCError("gc_SetUserInfo",channel,Session[channel].LogFile,_logLevel ); 
	         return (FUNCFAIL);  
		 }

         gc_util_delete_parm_blk(gcParmBlk); 

		 if (gc_AnswerCall(Session[channel].ipParams.currentCRN, 0, EV_ASYNC)<0) {
			 printGCError("gc_AnswerCall",channel,Session[channel].LogFile,_logLevel ); 
	         return (FUNCFAIL);  
		 }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Answering Call to IP on channel %d\n", channel));

		 }
		 break; 
      
	  /* Got disconnected from ip or taskfail, drop the call */  
	  case GCEV_DISCONNECTED:
	  case GCEV_TASKFAIL:
		  /* drop ip call */
		  if (gc_DropCall(Session[channel].ipParams.currentCRN, GC_NORMAL_CLEARING, EV_ASYNC)<0){
			  printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
			  return (FUNCFAIL);  
		  }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to IP on channel %d\n", channel));

		  }


		  Session[channel].NumOfDropExpected = 1;
		  chanInfoIP[channel].callsFailed++;
		  gateUpdate(&(Session[channel]),GATE_DROP);
		  break;

	  /* Got GCEV_ANSWERED from ip, send makecall to pstn */  
	  case GCEV_ANSWERED:
		  chanInfoIP[channel].callsConnected++;

		  /* Set the timeslot */
          tsArray[0] = Session[channel].pstnParams.TxTSlot;

          /* Set SC structure to point to timeslot */
          tsInfo.sc_tsarrayp = tsArray;
          tsInfo.sc_numts = 1;

		  /* Listen to pstn */
		  if(gc_Listen(Session[channel].ipParams.linedev,
                              &tsInfo,EV_SYNC) == -1) {
			  gateFATAL(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tError in gc_Listen on channel %d\n",channel));
			  return (FUNCFAIL);
          }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Make IP listen to PSTN on channel %d\n", channel));

		  }
		  
          if (Dialing == -1){ /* User didn't use the "-p" option (Pstn Dialing)*/
			  if (frontEnd == GATE_LEGACY_ANALOG) {
				  if (DnisEnable){
					  strcpy(destAddr,Session[channel].DNIS);
				  }
				  else{ /* DNIS is not enabled */
					  strcpy(destAddr,Session[channel].ConfigFileParm.localPhoneNumber);
				  }
			  }
		      else{  /*frontEnd is DIGITAL-T1 or DIGITAL-E1 */
			      strcpy(destAddr,"");
			  }       
		  }else{     /* User used the "-p0" option */
		 	  if (Dialing == 0){
			      strcpy(destAddr,"");
			  }else{  /* User used the "-p1" option */
			      strcpy(destAddr,Session[channel].ConfigFileParm.localPhoneNumber);
			  }
		  }		  
		  		 
           /* Making Call to PSTN */
		  if (gc_MakeCall(Session[channel].pstnParams.linedev,
			                   &(Session[channel].pstnParams.currentCRN),
		    	               destAddr,
				               NULL,
							   30,
							   EV_ASYNC)<0) {
			  printGCError("gc_MakeCall",channel,Session[channel].LogFile,_logLevel); 
			  return (FUNCFAIL);  
		  }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Making Call to PSTN on channel %d\n", channel));

		  }


		  chanInfoPSTN[channel].callsMake++;
		  gateUpdate(&(Session[channel]),IP_CONNECTED);	
	      break;
		 
      default:
         gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in gateIPOffered from %s \n",
                   gateEventStr(event),event,channel,gateKeyStr(compKey)));
         break;

	}
   
   return (FUNCSUCCESS);
} /* End of Function gateIPOffered */


/*****FUNCTION***************************************************
*        NAME : gatePSTNOffered
* DESCRIPTION : The function waits for connected from ip,
*               after getting Offer from PSTN.
*       INPUT : unsigned int         channel  -  channel which got the event
*               COMP_KEY       compKey  -  name of the component
*                                          that got the event
*               long         event      -  the recieved event
*  				 void        *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
unsigned short gatePSTNOffered(unsigned int channel, COMP_KEY compKey, long event,void * EvtData)
{
   int            rBool;
   SC_TSINFO       tsInfo;
   unsigned long           tsArray[1];
   GC_PARM_BLKP    gcParmBlk = NULL;
      
   gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"In PSTN_OFFERED State on channel (0x%x)\n\t got event %s (0x%x) from %s\n", 
             channel,gateEventStr(event), event, gateKeyStr(compKey)));


   /* Switch on event */
   switch(event) {
       
	  /* Got offered from ip */
      case GCEV_OFFERED:
		  chanInfoIP[channel].callsOffered++;
		  
		  /* We get into PSTNOffered state only if the IP.currentCRN == 0, so in this case when OFFERED event 
		     arrives , the IP.currentCRN will be updated in the ipGetEvent function */ 
		  Session[channel].ipParams.glareCRN = Session[channel].ipParams.currentCRN;

⌨️ 快捷键说明

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