1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading options.conf and filling structure **
10 \*****************************************************************************/
17 struct options options = {
18 "/usr/local/pbx/log", /* log file */
19 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
20 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
21 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
22 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
23 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
24 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
25 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
26 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
27 0x0000, /* debug mode */
29 "0", /* national prefix */
30 "00", /* international prefix */
31 "tones_american", /* directory of tones */
32 "", /* directories of tones to fetch */
33 "extensions", /* directory of extensions */
34 "", /* h323 endpoint name */
35 0, /* h323 ringconnect */
36 0,4, 0,2, 0, 0, 0, 0,4, 0,4, 0,64, /* h323 codecs to use */
37 0,"",1720, /* allow incoming h323 calls */
38 0,"", /* register with h323 gatekeeper */
39 5060, 5, /* SIP port, maxqueue */
40 0, /* dtmf detection on */
41 "", /* dummy caller id */
42 0, /* inband patterns on external calls */
43 0, /* use tones by dsp.o */
44 0, /* by default use priority 0 */
45 "pbx@jolly.de" /* source mail adress */
50 * read options from options.conf
52 int read_options(void)
65 SPRINT(filename, "%s/options.conf", INSTALL_DATA);
67 if (!(fp=fopen(filename,"r")))
69 PERROR("Cannot open %s\n",filename);
74 while((fgets(buffer,sizeof(buffer),fp)))
77 buffer[sizeof(buffer)-1]=0;
78 if (buffer[0]) buffer[strlen(buffer)-1]=0;
81 while(*p <= 32) /* skip spaces */
87 if (*p==0 || *p=='#') /* ignore comments and empty line */
91 i=0; /* read option */
94 if (i+1 >= sizeof(option))
96 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
103 while(*p <= 32) /* skip spaces */
111 if (*p!=0 && *p!='#') /* param */
113 i=0; /* read param */
116 if (i+1 >= sizeof(param))
118 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
126 /* at this point we have option and param */
129 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
131 PERROR_RUNTIME("Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
134 if (!strcmp(option,"debug"))
138 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
141 options.deb = strtol(param, NULL, 0);
143 PDEBUG(DEBUG_CONFIG, "debugging: 0x%x\n", options.deb);
145 if (!strcmp(option,"log"))
149 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
152 SCPY(options.log, param);
154 PDEBUG(DEBUG_CONFIG, "log file: %s\n", options.log);
156 if (!strcmp(option,"port"))
158 i = strtol(param, NULL, 0);
159 if (i < 1 || i > sizeof(options.ports))
161 PERROR_RUNTIME("Error in %s (line %d): port number %s out of range.\n", filename, line, option);
164 options.ports[i] |= FLAG_PORT_USE;
166 PDEBUG(DEBUG_CONFIG, "adding interface: %d (param=%s)\n", i, param);
167 if (strstr(param, "ptp"))
169 options.ports[i] |= FLAG_PORT_PTP;
170 PDEBUG(DEBUG_CONFIG, " -> interface shall be ptp\n");
174 if (!strcmp(option,"ptp"))
178 PDEBUG(DEBUG_CONFIG, "ptp layer-2 watch and keep established.\n");
181 if (!strcmp(option,"alaw"))
185 PDEBUG(DEBUG_CONFIG, "isdn audio type: alaw\n");
187 if (!strcmp(option,"ulaw"))
191 PDEBUG(DEBUG_CONFIG, "isdn audio type: ulaw\n");
193 if (!strcmp(option,"h323_name"))
196 SCPY(options.h323_name, param);
198 PDEBUG(DEBUG_CONFIG, "H323 endpoint name: '%s'\n", param);
201 if (!strcmp(option,"h323_ringconnect"))
204 options.h323_ringconnect = 1;
206 PDEBUG(DEBUG_CONFIG, "H323 ringconnect: enabled\n");
209 if (!strcmp(option,"h323_gsm"))
213 options.h323_gsm_pri = codecpri;
214 options.h323_gsm_opt = atoi(param);
215 if (atoi(param)<1 && atoi(param)>7)
217 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 1..7.\n",filename,line,option);
221 PDEBUG(DEBUG_CONFIG, "H323 codec to use: GSM, MicrosoftGSM priority %d\n", codecpri);
224 if (!strcmp(option,"h323_g726"))
228 options.h323_g726_pri = codecpri;
229 options.h323_g726_opt = atoi(param);
230 if (atoi(param)<2 && atoi(param)>5)
232 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 2..5.\n",filename,line,option);
236 PDEBUG(DEBUG_CONFIG, "H323 codec to use: G726 priority %d\n", codecpri);
239 if (!strcmp(option,"h323_g7231"))
243 options.h323_g7231_pri = codecpri;
245 PDEBUG(DEBUG_CONFIG, "H323 codec to use: G7231 priority %d\n", codecpri);
248 if (!strcmp(option,"h323_g729a"))
252 options.h323_g729a_pri = codecpri;
254 PDEBUG(DEBUG_CONFIG, "H323 codec to use: G729A priority %d\n", codecpri);
257 if (!strcmp(option,"h323_lpc10"))
261 options.h323_lpc10_pri = codecpri;
263 PDEBUG(DEBUG_CONFIG, "H323 codec to use: LPC-10 priority %d\n", codecpri);
266 if (!strcmp(option,"h323_speex"))
270 options.h323_speex_pri = codecpri;
271 options.h323_speex_opt = atoi(param);
272 if (atoi(param)<2 && atoi(param)>6)
274 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 2..6.\n",filename,line,option);
278 PDEBUG(DEBUG_CONFIG, "H323 codec to use: Speex priority %d\n", codecpri);
281 if (!strcmp(option,"h323_xspeex"))
285 options.h323_xspeex_pri = codecpri;
286 options.h323_xspeex_opt = atoi(param);
287 if (atoi(param)<2 && atoi(param)>6)
289 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 2..6.\n",filename,line,option);
293 PDEBUG(DEBUG_CONFIG, "H323 codec to use: XiphSpeex priority %d\n", codecpri);
296 if (!strcmp(option,"h323_law"))
300 options.h323_law_pri = codecpri;
301 options.h323_law_opt = atoi(param);
302 if (atoi(param)<10 && atoi(param)>240)
304 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 10..240.\n",filename,line,option);
308 PDEBUG(DEBUG_CONFIG, "H323 codec to use: Alaw, muLaw priority %d\n", codecpri);
311 if (!strcmp(option,"h323_icall"))
314 options.h323_icall = 1;
315 SCPY(options.h323_icall_prefix, param);
317 PDEBUG(DEBUG_CONFIG, "process incoming H323 call with prefix '%s'\n", param);
320 if (!strcmp(option,"h323_port"))
323 options.h323_port = atoi(param);
325 PDEBUG(DEBUG_CONFIG, "use port for incoming H323 calls: %d\n", atoi(param));
328 if (!strcmp(option,"sip_port"))
331 options.sip_port = atoi(param);
333 PDEBUG(DEBUG_CONFIG, "use port for incoming SIP calls: %d\n", atoi(param));
336 if (!strcmp(option,"sip_maxqueue"))
339 options.sip_maxqueue = atoi(param);
341 PDEBUG(DEBUG_CONFIG, "number of simultanious incoming sockets for SIP calls: %d\n", atoi(param));
344 if (!strcmp(option,"h323_gatekeeper"))
347 options.h323_gatekeeper = 1;
350 SCPY(options.h323_gatekeeper_host, param);
352 PDEBUG(DEBUG_CONFIG, "register with H323 gatekeeper (%s)\n", (param[0])?param:"automatically");
355 if (!strcmp(option,"tones_dir"))
359 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
362 if (param[strlen(param)-1] == '/')
363 param[strlen(param)-1]=0;
364 SCPY(options.tones_dir, param);
366 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
368 if (!strcmp(option,"fetch_tones"))
372 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
375 if (param[strlen(param)-1] == '/')
376 param[strlen(param)-1]=0;
377 SCPY(options.fetch_tones, param);
379 PDEBUG(DEBUG_CONFIG, "directories of tones to fetch: %s\n",param);
381 if (!strcmp(option,"extensions_dir"))
385 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
388 if (param[strlen(param)-1] == '/')
389 param[strlen(param)-1]=0;
390 SCPY(options.extensions_dir, param);
392 PDEBUG(DEBUG_CONFIG, "directory of extensions: %s\n",param);
394 if (!strcmp(option,"national"))
396 SCPY(options.national, param);
398 PDEBUG(DEBUG_CONFIG, "national dial prefix: %s\n", param);
400 if (!strcmp(option,"international"))
402 SCPY(options.international, param);
404 PDEBUG(DEBUG_CONFIG, "inernational dial prefix: %s\n", param);
406 if (!strcmp(option,"nodtmf"))
410 PDEBUG(DEBUG_CONFIG, "disable dtmf detection\n");
412 if (!strcmp(option,"dummyid"))
414 SCPY(options.dummyid, param);
416 PDEBUG(DEBUG_CONFIG, "dummy caller id\n", param);
418 if (!strcmp(option,"inbandpattern"))
420 if (!strcasecmp(param, "yes"))
421 options.inbandpattern = 1;
423 PDEBUG(DEBUG_CONFIG, "inband pattern = %s\n", (options.inbandpattern)?"yes":"no");
425 if (!strcmp(option,"dsptones"))
427 if (!strcasecmp(param, "american"))
428 options.dsptones = DSP_AMERICAN;
429 else if (!strcasecmp(param, "german"))
430 options.dsptones = DSP_GERMAN;
431 else if (!strcasecmp(param, "oldgerman"))
432 options.dsptones = DSP_OLDGERMAN;
433 else if (!strcasecmp(param, "none"))
434 options.dsptones = DSP_NONE;
436 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
440 PDEBUG(DEBUG_CONFIG, "dsp tones = %d\n", options.dsptones);
442 if (!strcmp(option,"schedule"))
444 options.schedule = atoi(param);
445 if (options.schedule < 0)
447 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
450 if (options.schedule > 99)
452 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
457 PDEBUG(DEBUG_CONFIG, "use real time scheduler priority: %d\n", atoi(param));
459 PDEBUG(DEBUG_CONFIG, "don't use real time scheduler\n");
461 if (!strcmp(option,"email"))
465 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
468 SCPY(options.email, param);
470 PDEBUG(DEBUG_CONFIG, "source mail address of pbx: %s\n", param);
473 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
479 if (!options.dsptones)
481 PERROR_RUNTIME("Error in %s (line %d): option 'dsptones' missing.\n", filename);
485 if (!options.tones_dir[0])
487 PERROR_RUNTIME("Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);