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, /* use tones by dsp.o */
43 0, /* by default use priority 0 */
44 "pbx@jolly.de" /* source mail adress */
49 * read options from options.conf
51 int read_options(void)
64 SPRINT(filename, "%s/options.conf", INSTALL_DATA);
66 if (!(fp=fopen(filename,"r")))
68 PERROR("Cannot open %s\n",filename);
73 while((fgets(buffer,sizeof(buffer),fp)))
76 buffer[sizeof(buffer)-1]=0;
77 if (buffer[0]) buffer[strlen(buffer)-1]=0;
80 while(*p <= 32) /* skip spaces */
86 if (*p==0 || *p=='#') /* ignore comments and empty line */
90 i=0; /* read option */
93 if (i+1 >= sizeof(option))
95 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
102 while(*p <= 32) /* skip spaces */
110 if (*p!=0 && *p!='#') /* param */
112 i=0; /* read param */
115 if (i+1 >= sizeof(param))
117 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
125 /* at this point we have option and param */
128 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
130 PERROR_RUNTIME("Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
133 if (!strcmp(option,"debug"))
137 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
140 options.deb = strtol(param, NULL, 0);
142 PDEBUG(DEBUG_CONFIG, "debugging: 0x%x\n", options.deb);
144 if (!strcmp(option,"log"))
148 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
151 SCPY(options.log, param);
153 PDEBUG(DEBUG_CONFIG, "log file: %s\n", options.log);
155 if (!strcmp(option,"port"))
157 i = strtol(param, NULL, 0);
158 if (i < 1 || i > sizeof(options.ports))
160 PERROR_RUNTIME("Error in %s (line %d): port number %s out of range.\n", filename, line, option);
163 options.ports[i] |= FLAG_PORT_USE;
165 PDEBUG(DEBUG_CONFIG, "adding interface: %d (param=%s)\n", i, param);
166 if (strstr(param, "ptp"))
168 options.ports[i] |= FLAG_PORT_PTP;
169 PDEBUG(DEBUG_CONFIG, " -> interface shall be ptp\n");
173 if (!strcmp(option,"ptp"))
177 PDEBUG(DEBUG_CONFIG, "ptp layer-2 watch and keep established.\n");
180 if (!strcmp(option,"alaw"))
184 PDEBUG(DEBUG_CONFIG, "isdn audio type: alaw\n");
186 if (!strcmp(option,"ulaw"))
190 PDEBUG(DEBUG_CONFIG, "isdn audio type: ulaw\n");
192 if (!strcmp(option,"h323_name"))
195 SCPY(options.h323_name, param);
197 PDEBUG(DEBUG_CONFIG, "H323 endpoint name: '%s'\n", param);
200 if (!strcmp(option,"h323_ringconnect"))
203 options.h323_ringconnect = 1;
205 PDEBUG(DEBUG_CONFIG, "H323 ringconnect: enabled\n");
208 if (!strcmp(option,"h323_gsm"))
212 options.h323_gsm_pri = codecpri;
213 options.h323_gsm_opt = atoi(param);
214 if (atoi(param)<1 && atoi(param)>7)
216 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 1..7.\n",filename,line,option);
220 PDEBUG(DEBUG_CONFIG, "H323 codec to use: GSM, MicrosoftGSM priority %d\n", codecpri);
223 if (!strcmp(option,"h323_g726"))
227 options.h323_g726_pri = codecpri;
228 options.h323_g726_opt = atoi(param);
229 if (atoi(param)<2 && atoi(param)>5)
231 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 2..5.\n",filename,line,option);
235 PDEBUG(DEBUG_CONFIG, "H323 codec to use: G726 priority %d\n", codecpri);
238 if (!strcmp(option,"h323_g7231"))
242 options.h323_g7231_pri = codecpri;
244 PDEBUG(DEBUG_CONFIG, "H323 codec to use: G7231 priority %d\n", codecpri);
247 if (!strcmp(option,"h323_g729a"))
251 options.h323_g729a_pri = codecpri;
253 PDEBUG(DEBUG_CONFIG, "H323 codec to use: G729A priority %d\n", codecpri);
256 if (!strcmp(option,"h323_lpc10"))
260 options.h323_lpc10_pri = codecpri;
262 PDEBUG(DEBUG_CONFIG, "H323 codec to use: LPC-10 priority %d\n", codecpri);
265 if (!strcmp(option,"h323_speex"))
269 options.h323_speex_pri = codecpri;
270 options.h323_speex_opt = atoi(param);
271 if (atoi(param)<2 && atoi(param)>6)
273 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 2..6.\n",filename,line,option);
277 PDEBUG(DEBUG_CONFIG, "H323 codec to use: Speex priority %d\n", codecpri);
280 if (!strcmp(option,"h323_xspeex"))
284 options.h323_xspeex_pri = codecpri;
285 options.h323_xspeex_opt = atoi(param);
286 if (atoi(param)<2 && atoi(param)>6)
288 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 2..6.\n",filename,line,option);
292 PDEBUG(DEBUG_CONFIG, "H323 codec to use: XiphSpeex priority %d\n", codecpri);
295 if (!strcmp(option,"h323_law"))
299 options.h323_law_pri = codecpri;
300 options.h323_law_opt = atoi(param);
301 if (atoi(param)<10 && atoi(param)>240)
303 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be in range 10..240.\n",filename,line,option);
307 PDEBUG(DEBUG_CONFIG, "H323 codec to use: Alaw, muLaw priority %d\n", codecpri);
310 if (!strcmp(option,"h323_icall"))
313 options.h323_icall = 1;
314 SCPY(options.h323_icall_prefix, param);
316 PDEBUG(DEBUG_CONFIG, "process incoming H323 call with prefix '%s'\n", param);
319 if (!strcmp(option,"h323_port"))
322 options.h323_port = atoi(param);
324 PDEBUG(DEBUG_CONFIG, "use port for incoming H323 calls: %d\n", atoi(param));
327 if (!strcmp(option,"sip_port"))
330 options.sip_port = atoi(param);
332 PDEBUG(DEBUG_CONFIG, "use port for incoming SIP calls: %d\n", atoi(param));
335 if (!strcmp(option,"sip_maxqueue"))
338 options.sip_maxqueue = atoi(param);
340 PDEBUG(DEBUG_CONFIG, "number of simultanious incoming sockets for SIP calls: %d\n", atoi(param));
343 if (!strcmp(option,"h323_gatekeeper"))
346 options.h323_gatekeeper = 1;
349 SCPY(options.h323_gatekeeper_host, param);
351 PDEBUG(DEBUG_CONFIG, "register with H323 gatekeeper (%s)\n", (param[0])?param:"automatically");
354 if (!strcmp(option,"tones_dir"))
358 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
361 if (param[strlen(param)-1] == '/')
362 param[strlen(param)-1]=0;
363 SCPY(options.tones_dir, param);
365 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
367 if (!strcmp(option,"fetch_tones"))
371 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
374 if (param[strlen(param)-1] == '/')
375 param[strlen(param)-1]=0;
376 SCPY(options.fetch_tones, param);
378 PDEBUG(DEBUG_CONFIG, "directories of tones to fetch: %s\n",param);
380 if (!strcmp(option,"extensions_dir"))
384 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
387 if (param[strlen(param)-1] == '/')
388 param[strlen(param)-1]=0;
389 SCPY(options.extensions_dir, param);
391 PDEBUG(DEBUG_CONFIG, "directory of extensions: %s\n",param);
393 if (!strcmp(option,"national"))
395 SCPY(options.national, param);
397 PDEBUG(DEBUG_CONFIG, "national dial prefix: %s\n", param);
399 if (!strcmp(option,"international"))
401 SCPY(options.international, param);
403 PDEBUG(DEBUG_CONFIG, "inernational dial prefix: %s\n", param);
405 if (!strcmp(option,"nodtmf"))
409 PDEBUG(DEBUG_CONFIG, "disable dtmf detection\n");
411 if (!strcmp(option,"dummyid"))
413 SCPY(options.dummyid, param);
415 PDEBUG(DEBUG_CONFIG, "dummy caller id\n", param);
417 if (!strcmp(option,"dsptones"))
419 if (!strcasecmp(param, "american"))
420 options.dsptones = DSP_AMERICAN;
421 else if (!strcasecmp(param, "german"))
422 options.dsptones = DSP_GERMAN;
423 else if (!strcasecmp(param, "oldgerman"))
424 options.dsptones = DSP_OLDGERMAN;
425 else if (!strcasecmp(param, "none"))
426 options.dsptones = DSP_NONE;
428 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
432 PDEBUG(DEBUG_CONFIG, "dsp tones = %d\n", options.dsptones);
434 if (!strcmp(option,"schedule"))
436 options.schedule = atoi(param);
437 if (options.schedule < 0)
439 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
442 if (options.schedule > 99)
444 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
449 PDEBUG(DEBUG_CONFIG, "use real time scheduler priority: %d\n", atoi(param));
451 PDEBUG(DEBUG_CONFIG, "don't use real time scheduler\n");
453 if (!strcmp(option,"email"))
457 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
460 SCPY(options.email, param);
462 PDEBUG(DEBUG_CONFIG, "source mail address of pbx: %s\n", param);
465 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
471 if (!options.dsptones)
473 PERROR_RUNTIME("Error in %s (line %d): option 'dsptones' missing.\n", filename);
477 if (!options.tones_dir[0])
479 PERROR_RUNTIME("Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);