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

📄 gatepars.c

📁 ipt网关源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************************************
* 
* $ProjectName: X:\SIPROJ\VOIP\HOST\WIN_NT\DEMOS\VOIPGATE\PROJECT.PJ $
* $ProjectRevision: 1.4 $
* $Label$
* $Revision: 1.7 $ - $Date: 1997/08/17 10:58:48 $
* 
**********************************************************************************************/


/* The DEMO H files are needed in this order: */
#include "GateDbg.h"
#include "GateStrc.h"  
#include "parsFP.h"

BYTE stage = 0;            
int  line = 0;
long firstSession=1;
long lastSession=1;


      ///////////////////////////////////////////////////////
      ///                                                 ///
      ///      DEFINITION OF GLOBAL FUNCTIONS              ///
      ///                                                 ///
      ///////////////////////////////////////////////////////


/*****FUNCTION***************************************************
*        NAME : gateConfiguration
* DESCRIPTION : Static function to read .cfg file to fill in 
*                 Session
*       INPUT : config file name
*      OUTPUT : None
*     RETURNS : TRUE - success, FALSE - fail
*    CAUTIONS : None
****************************************************************/
BOOL gateConfiguration(char *cfgFile)
{
  /* see IPTpars.c for parsing routines */
   FILE *handler;
   int err;
   char buf1[IPT_MAX_STRING];

   line = 0;

   handler = fopen(cfgFile,"rt"); /* opens configuration file */

   if(handler == NULL) {
      /* cfg file not found */
      printf("\tCurrupted Configuration file or not exist: %s\n",cfgFile);
      return (DM3FAIL); 
   }

   while(TRUE) {
      /* Read configuration file line by line, and interpret line	 */
      line++;
      if(fgets( buf1, IPT_MAX_STRING, handler ) == NULL ) {
         if( feof(handler)) {
            break;
         } else {
            printf("\tError reading configuration file: line %d\n",line);

            return(DM3FAIL); 
         }
      }

      /* remark in configuration file */
      if((buf1[0] == '#') || (buf1[0] == '*') || (buf1[0] == ';')) {
         continue;
      }


      err = parse_line(buf1); /* Interpret line */

      if(err < 0) {
         /* Configuration line bad structure */
         fclose(handler);
         if(err == -1) {
            printf("\tIllegal command in configuration file: line %d",line);
         }
         printf("\n\tError with parsing of line:\n\t%s\n",buf1);
         return (DM3FAIL); 
      }

   } /* end while TRUE parsing lines */

   fclose(handler);
   if((stage != 0) ) {
      /* brackets not closed illegal file structure */
      printf("\tIllegal end of .cfg file. \n");
      return(DM3FAIL);
   }

   return(DM3SUCCESS);
} /* Function GetConfiguration */



      ///////////////////////////////////////////////////////
      ///                                                 ///
      ///      DECLARATION OF LOCAL FUNCTIONS             ///
      ///                                                 ///
      ///////////////////////////////////////////////////////


/*******************************************************************
 *       NAME : ut_aschex(msg)
 *DESCRIPTION : Utility to convert ascii hex characters to binary.
 *      INPUT : msg = Pointer to ascii string.
 *     OUTPUT : None.
 *    RETURNS : Binary value of msg.
 *   CAUTIONS : None.
 *******************************************************************/
static long ut_aschex(char *msg)
{
   long i=0;

   while(*msg != '\0') {
      i = (i<<4) + (*msg)-0x30;
      if(*msg>='a') {
         i -= 0x20;
      }
      if(*msg>='A') {
         i -= 7;
      }
      msg++;
   }
   return(i);
}

/*******************************************************************
 *       NAME : ut_aschex(msg)
 *DESCRIPTION : Utility to convert ascii characters to binary.
 *      INPUT : msg = Pointer to ascii string.
 *     OUTPUT : None.
 *    RETURNS : Binary value of msg.
 *   CAUTIONS : None.
 *******************************************************************/
static long ut_asnum(char *msg) 
{
   long i=0;

   while(*msg != '\0') {
      if((*msg < '0') || (*msg > '9')) {
         return(-1);
      }
      i = (i * 10) + (*msg)-0x30;
      msg++;
   }
   return(i);
}


/****************************************************************
*        NAME : skip
* DESCRIPTION : Gets line of data file, and converts text to numbers 
*               Input line may be of the form:
*               TITLE = 5 7 aaaa
*               Skip() deals only with second half of line (5 7 aaaa etc.)
*
*               If looking for string only vnum is 0 and *n is useless
*               If looking for value vnum is 1 and *name is useless
*
*       INPUT : Data line, array of integers which will be returned,
*               expected number of variables in text, string to be returned. 
*      OUTPUT : 
*     RETURNS : Number of elements found in line.
*    CAUTIONS : 
****************************************************************/
static int skip(BOOL equal,char *p,long *n,int vnum,char *name) 
{

   char p2[IPT_MAX_STRING]; /* maximum 30 chars to get */
   int i;
   int j=-1;

   /* Check if using = sign */
   if(equal) {
      /* move to right of = sign */
      while((*p) && (*p != '=')) {
         p++;
      }
      if((*p == '\0') || (*p == '\n') || (*p == '\r')) {
         /* empty line */
         return(0);
      }
      p++;
   }

   /* catch vnum number of values */
   for(j = 0; j < vnum; j++) {

      /* skip white space */
      while((*p) && ((*p == ' ') || (*p == '\t') || (*p == '-'))) {
         p++;
      }
      if((*p == '\0') || (*p == '\n') || (*p == '\r')) {
         return(j);
      }

      /* start collecting */
      i = 0;
      while((*p) && (*p != '-') && (*p != '\r') && (*p != '\n')) {
         p2[i] = *p;
         i++;
         p++;
      }

      /* add ascii zero */
      p2[i] = '\0';

      /* convert */
      if((p2[0] == '0') && (p2[1] == 'x')) {   /* hexa value */
         n[j] = ut_aschex((char *)(&(p2[2])));
      } else {
         n[j] = ut_asnum((char *)(&(p2[0])));


      }
   }

   /* return appropriate values */
   if(!equal) {
      return(j);
   }


   while((*p) && (*p == ' ')) {
      p++;
   }

   if((*p == '\0') || (*p == '\n') || (*p == '\r')) {
      return(j);
   }


   /* build return string "name" */
   while((*p) &&  (*p != '\r') && (*p != '\n') ) {
      *name = *p;
      name++;
      p++;
   }

   *name = '\0';
   j++;

   return(j);
}


/****************************************************************
*        NAME : parse_line
* DESCRIPTION : Parses input line and interprets it. 
*               Way of parsing & interpreting determined according
*               to structure of input line as may be seen in 
*               configuration file ( .cfg ).
*       INPUT : Input line using *p pointer
*      OUTPUT : 
*     RETURNS : less than zero on error
*    CAUTIONS : 
****************************************************************/
static int parse_line(char *p)  
{
   int rc;                        /* return code */
   SHORT maxCoders = 0;           /* max Tx coders */
   long ans[PARSE_MAX_NUM];       /* the value to right of = sign */
   char lname[PARSE_MAX_STRING];  /* the string to right of = sign */
   int ii;                        /* counter for maxCoders */
   int index;                     /* counter for session number */
 
   while((*p) && ((*p == ' ') || (*p == '\t'))) {
      p++;
   }
   if((*p == '\0') || (*p == '\n')) {
      /* empty line */
      return(0);
   }

   if((*p == '#') || (*p == '*') || (*p == ';')) {
      /* Remark line */
      return(0);
   }

   if( (stage == 1) || (stage == 3) ){   /* Should be '{'  */
      /* After channel declaration "{" is expected */
      if(*p == '{') {
         stage++;
         return(0);
      } else {
         printf("\nSyntax Error, '{' is expected;\n (line %d) - %s\n",line,p);
         return(-2);
      }
   } 


   p = _strlwr(p);

   /* next stage == 2  */
   if(stage == 2) {

      /* Get Calling Address   
         only the first 4 letters must match here */
      if(strncmp(p,"destination",4) == 0) {
         /* get this call string */
         if((rc = skip(TRUE,p,(long *)ans,0,(char *)lname)) != 1) {

            printf("\tIllegal configuration line %d:\n\t%s\n",line,p);

            return(-1);
         }
         for(index = firstSession; index <= lastSession; index++) {
			 strcpy(Session[index].ConfigFileParm.destAddr,lname);
		 }

         return (0);         
      }


	   /* Also get coder if there is one */

⌨️ 快捷键说明

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