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 0, /* dtmf detection on */
35 "", /* dummy caller id */
36 0, /* use tones by dsp.o */
37 0, /* by default use priority 0 */
38 "pbx@jolly.de" /* source mail adress */
43 * read options from options.conf
45 int read_options(void)
55 SPRINT(filename, "%s/options.conf", INSTALL_DATA);
57 if (!(fp=fopen(filename,"r")))
59 PERROR("Cannot open %s\n",filename);
64 while((fgets(buffer,sizeof(buffer),fp)))
67 buffer[sizeof(buffer)-1]=0;
68 if (buffer[0]) buffer[strlen(buffer)-1]=0;
71 while(*p <= 32) /* skip spaces */
77 if (*p==0 || *p=='#') /* ignore comments and empty line */
81 i=0; /* read option */
84 if (i+1 >= sizeof(option))
86 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
93 while(*p <= 32) /* skip spaces */
101 if (*p!=0 && *p!='#') /* param */
103 i=0; /* read param */
106 if (i+1 >= sizeof(param))
108 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
116 /* at this point we have option and param */
119 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
121 PERROR_RUNTIME("Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
124 if (!strcmp(option,"debug"))
128 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
131 options.deb = strtol(param, NULL, 0);
133 PDEBUG(DEBUG_CONFIG, "debugging: 0x%x\n", options.deb);
135 if (!strcmp(option,"log"))
139 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
142 SCPY(options.log, param);
144 PDEBUG(DEBUG_CONFIG, "log file: %s\n", options.log);
146 if (!strcmp(option,"port"))
148 i = strtol(param, NULL, 0);
149 if (i < 1 || i > sizeof(options.ports))
151 PERROR_RUNTIME("Error in %s (line %d): port number %s out of range.\n", filename, line, option);
154 options.ports[i] |= FLAG_PORT_USE;
156 PDEBUG(DEBUG_CONFIG, "adding interface: %d (param=%s)\n", i, param);
157 if (strstr(param, "ptp"))
159 options.ports[i] |= FLAG_PORT_PTP;
160 PDEBUG(DEBUG_CONFIG, " -> interface shall be ptp\n");
164 if (!strcmp(option,"ptp"))
168 PDEBUG(DEBUG_CONFIG, "ptp layer-2 watch and keep established.\n");
171 if (!strcmp(option,"alaw"))
175 PDEBUG(DEBUG_CONFIG, "isdn audio type: alaw\n");
177 if (!strcmp(option,"ulaw"))
181 PDEBUG(DEBUG_CONFIG, "isdn audio type: ulaw\n");
183 if (!strcmp(option,"tones_dir"))
187 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
190 if (param[strlen(param)-1] == '/')
191 param[strlen(param)-1]=0;
192 SCPY(options.tones_dir, param);
194 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
196 if (!strcmp(option,"fetch_tones"))
200 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
203 if (param[strlen(param)-1] == '/')
204 param[strlen(param)-1]=0;
205 SCPY(options.fetch_tones, param);
207 PDEBUG(DEBUG_CONFIG, "directories of tones to fetch: %s\n",param);
209 if (!strcmp(option,"extensions_dir"))
213 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
216 if (param[strlen(param)-1] == '/')
217 param[strlen(param)-1]=0;
218 SCPY(options.extensions_dir, param);
220 PDEBUG(DEBUG_CONFIG, "directory of extensions: %s\n",param);
222 if (!strcmp(option,"national"))
224 SCPY(options.national, param);
226 PDEBUG(DEBUG_CONFIG, "national dial prefix: %s\n", param);
228 if (!strcmp(option,"international"))
230 SCPY(options.international, param);
232 PDEBUG(DEBUG_CONFIG, "inernational dial prefix: %s\n", param);
234 if (!strcmp(option,"nodtmf"))
238 PDEBUG(DEBUG_CONFIG, "disable dtmf detection\n");
240 if (!strcmp(option,"dummyid"))
242 SCPY(options.dummyid, param);
244 PDEBUG(DEBUG_CONFIG, "dummy caller id\n", param);
246 if (!strcmp(option,"dsptones"))
248 if (!strcasecmp(param, "american"))
249 options.dsptones = DSP_AMERICAN;
250 else if (!strcasecmp(param, "german"))
251 options.dsptones = DSP_GERMAN;
252 else if (!strcasecmp(param, "oldgerman"))
253 options.dsptones = DSP_OLDGERMAN;
254 else if (!strcasecmp(param, "none"))
255 options.dsptones = DSP_NONE;
257 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
261 PDEBUG(DEBUG_CONFIG, "dsp tones = %d\n", options.dsptones);
263 if (!strcmp(option,"schedule"))
265 options.schedule = atoi(param);
266 if (options.schedule < 0)
268 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
271 if (options.schedule > 99)
273 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
278 PDEBUG(DEBUG_CONFIG, "use real time scheduler priority: %d\n", atoi(param));
280 PDEBUG(DEBUG_CONFIG, "don't use real time scheduler\n");
282 if (!strcmp(option,"email"))
286 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
289 SCPY(options.email, param);
291 PDEBUG(DEBUG_CONFIG, "source mail address of pbx: %s\n", param);
294 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
300 if (!options.dsptones)
302 PERROR_RUNTIME("Error in %s (line %d): option 'dsptones' missing.\n", filename);
306 if (!options.tones_dir[0])
308 PERROR_RUNTIME("Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);