1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading options.conf and filling structure **
10 \*****************************************************************************/
17 struct options options = {
18 "/usr/local/lcr/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 "", /* dummy caller id */
35 0, /* use tones by dsp.o */
36 0, /* by default use priority 0 */
37 "lcr@your.machine" /* source mail adress */
42 * read options from options.conf
44 int read_options(void)
54 SPRINT(filename, "%s/options.conf", INSTALL_DATA);
56 if (!(fp=fopen(filename,"r")))
58 PERROR("Cannot open %s\n",filename);
63 while((fgets(buffer,sizeof(buffer),fp)))
66 buffer[sizeof(buffer)-1]=0;
67 if (buffer[0]) buffer[strlen(buffer)-1]=0;
70 while(*p <= 32) /* skip spaces */
76 if (*p==0 || *p=='#') /* ignore comments and empty line */
80 i=0; /* read option */
83 if (i+1 >= sizeof(option))
85 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
92 while(*p <= 32) /* skip spaces */
100 if (*p!=0 && *p!='#') /* param */
102 i=0; /* read param */
105 if (i+1 >= sizeof(param))
107 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
115 /* at this point we have option and param */
118 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
120 PERROR_RUNTIME("Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
123 if (!strcmp(option,"debug"))
127 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
130 options.deb = strtol(param, NULL, 0);
132 PDEBUG(DEBUG_CONFIG, "debugging: 0x%x\n", options.deb);
134 if (!strcmp(option,"log"))
138 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
141 SCPY(options.log, param);
143 PDEBUG(DEBUG_CONFIG, "log file: %s\n", options.log);
145 if (!strcmp(option,"port"))
147 i = strtol(param, NULL, 0);
148 if (i < 1 || i > sizeof(options.ports))
150 PERROR_RUNTIME("Error in %s (line %d): port number %s out of range.\n", filename, line, option);
153 options.ports[i] |= FLAG_PORT_USE;
155 PDEBUG(DEBUG_CONFIG, "adding interface: %d (param=%s)\n", i, param);
156 if (strstr(param, "ptp"))
158 options.ports[i] |= FLAG_PORT_PTP;
159 PDEBUG(DEBUG_CONFIG, " -> interface shall be ptp\n");
163 if (!strcmp(option,"ptp"))
167 PDEBUG(DEBUG_CONFIG, "ptp layer-2 watch and keep established.\n");
170 if (!strcmp(option,"alaw"))
174 PDEBUG(DEBUG_CONFIG, "isdn audio type: alaw\n");
176 if (!strcmp(option,"ulaw"))
180 PDEBUG(DEBUG_CONFIG, "isdn audio type: ulaw\n");
182 if (!strcmp(option,"tones_dir"))
186 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
189 if (param[strlen(param)-1] == '/')
190 param[strlen(param)-1]=0;
191 SCPY(options.tones_dir, param);
193 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
195 if (!strcmp(option,"fetch_tones"))
199 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
202 if (param[strlen(param)-1] == '/')
203 param[strlen(param)-1]=0;
204 SCPY(options.fetch_tones, param);
206 PDEBUG(DEBUG_CONFIG, "directories of tones to fetch: %s\n",param);
208 if (!strcmp(option,"extensions_dir"))
212 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
215 if (param[strlen(param)-1] == '/')
216 param[strlen(param)-1]=0;
217 SCPY(options.extensions_dir, param);
219 PDEBUG(DEBUG_CONFIG, "directory of extensions: %s\n",param);
221 if (!strcmp(option,"national"))
223 SCPY(options.national, param);
225 PDEBUG(DEBUG_CONFIG, "national dial prefix: %s\n", param);
227 if (!strcmp(option,"international"))
229 SCPY(options.international, param);
231 PDEBUG(DEBUG_CONFIG, "inernational dial prefix: %s\n", param);
233 if (!strcmp(option,"dummyid"))
235 SCPY(options.dummyid, param);
237 PDEBUG(DEBUG_CONFIG, "dummy caller id\n", param);
239 if (!strcmp(option,"dsptones"))
241 if (!strcasecmp(param, "american"))
242 options.dsptones = DSP_AMERICAN;
243 else if (!strcasecmp(param, "german"))
244 options.dsptones = DSP_GERMAN;
245 else if (!strcasecmp(param, "oldgerman"))
246 options.dsptones = DSP_OLDGERMAN;
247 else if (!strcasecmp(param, "none"))
248 options.dsptones = DSP_NONE;
250 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
254 PDEBUG(DEBUG_CONFIG, "dsp tones = %d\n", options.dsptones);
256 if (!strcmp(option,"schedule"))
258 options.schedule = atoi(param);
259 if (options.schedule < 0)
261 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
264 if (options.schedule > 99)
266 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
271 PDEBUG(DEBUG_CONFIG, "use real time scheduler priority: %d\n", atoi(param));
273 PDEBUG(DEBUG_CONFIG, "don't use real time scheduler\n");
275 if (!strcmp(option,"email"))
279 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
282 SCPY(options.email, param);
284 PDEBUG(DEBUG_CONFIG, "source mail address of pbx: %s\n", param);
287 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
293 if (!options.dsptones)
295 PERROR_RUNTIME("Error in %s (line %d): option 'dsptones' missing.\n", filename);
299 if (!options.tones_dir[0])
301 PERROR_RUNTIME("Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);