1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** parse h323 gateway config file **
10 \*****************************************************************************/
17 /* parse h323_gateway.conf
19 * searches for the given ip and returns the extension or NULL if not found
21 char *parse_h323gateway(char *ip, char *opt, int opt_size)
28 static char host_ip[32], extension[32], option[64];
31 SPRINT(filename, "%s/h323_gateway.conf", INSTALL_DATA);
33 if (!(fp = fopen(filename, "r")))
35 PERROR("Cannot open h323 gateway map: \"%s\"\n", filename);
40 while((fgets(buffer, sizeof(buffer), fp)))
43 buffer[sizeof(buffer)-1] = '\0';
44 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
47 while(*p <= 32) /* skip spaces */
53 if (*p==0 || *p=='#') /* ignore comments and empty line */
60 i=0; /* read host ip */
63 if (i+1 >= sizeof(host_ip))
65 PERROR_RUNTIME("Error in %s (line %d): ip too long.\n",filename,line);
72 while(*p <= 32) /* skip spaces */
79 if (*p!=0 && *p!='#') /* extension */
81 i=0; /* read extension */
84 if (i+1 >= sizeof(extension))
86 PERROR_RUNTIME("Error in %s (line %d): extension too long.\n",filename,line);
89 extension[i+1] = '\0';
90 extension[i++] = *p++;
92 while(*p <= 32) /* skip spaces */
100 if (*p!=0 && *p!='#') /* option */
102 i=0; /* read option */
105 if (i+1 >= sizeof(option))
107 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
116 if (!!strcasecmp(ip, host_ip))
119 if (extension[0] == '\0')
123 break; /* found entry */
130 UNCPY(opt, option, opt_size-1);
131 opt[opt_size-1] = '\0';