1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading options.conf and filling structure **
10 \*****************************************************************************/
14 struct options options = {
15 "/usr/local/lcr/log", /* log file */
16 {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,
17 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,
18 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,
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 0x0000, /* debug mode */
26 "0", /* national prefix */
27 "00", /* international prefix */
28 "tones_american", /* directory of tones */
29 "", /* directories of tones to fetch */
30 "extensions", /* directory of extensions */
31 "", /* dummy caller id */
32 0, /* use tones by dsp.o */
33 0, /* by default use priority 0 */
34 "lcr@your.machine" /* source mail adress */
39 * read options from options.conf
41 int read_options(void)
51 SPRINT(filename, "%s/options.conf", INSTALL_DATA);
53 if (!(fp=fopen(filename,"r")))
55 PERROR("Cannot open %s\n",filename);
60 while((fgets(buffer,sizeof(buffer),fp)))
63 buffer[sizeof(buffer)-1]=0;
64 if (buffer[0]) buffer[strlen(buffer)-1]=0;
67 while(*p <= 32) /* skip spaces */
73 if (*p==0 || *p=='#') /* ignore comments and empty line */
77 i=0; /* read option */
80 if (i+1 >= sizeof(option))
82 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
89 while(*p <= 32) /* skip spaces */
97 if (*p!=0 && *p!='#') /* param */
102 if (i+1 >= sizeof(param))
104 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
112 /* at this point we have option and param */
115 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
117 PERROR_RUNTIME("Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
120 if (!strcmp(option,"debug"))
124 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
127 options.deb = strtol(param, NULL, 0);
129 PDEBUG(DEBUG_CONFIG, "debugging: 0x%x\n", options.deb);
131 if (!strcmp(option,"log"))
135 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
138 SCPY(options.log, param);
140 PDEBUG(DEBUG_CONFIG, "log file: %s\n", options.log);
142 if (!strcmp(option,"port"))
144 i = strtol(param, NULL, 0);
145 if (i < 1 || i > sizeof(options.ports))
147 PERROR_RUNTIME("Error in %s (line %d): port number %s out of range.\n", filename, line, option);
150 options.ports[i] |= FLAG_PORT_USE;
152 PDEBUG(DEBUG_CONFIG, "adding interface: %d (param=%s)\n", i, param);
153 if (strstr(param, "ptp"))
155 options.ports[i] |= FLAG_PORT_PTP;
156 PDEBUG(DEBUG_CONFIG, " -> interface shall be ptp\n");
160 if (!strcmp(option,"ptp"))
164 PDEBUG(DEBUG_CONFIG, "ptp layer-2 watch and keep established.\n");
167 if (!strcmp(option,"alaw"))
171 PDEBUG(DEBUG_CONFIG, "isdn audio type: alaw\n");
173 if (!strcmp(option,"ulaw"))
177 PDEBUG(DEBUG_CONFIG, "isdn audio type: ulaw\n");
179 if (!strcmp(option,"tones_dir"))
183 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
186 if (param[strlen(param)-1] == '/')
187 param[strlen(param)-1]=0;
188 SCPY(options.tones_dir, param);
190 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
192 if (!strcmp(option,"fetch_tones"))
196 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
199 if (param[strlen(param)-1] == '/')
200 param[strlen(param)-1]=0;
201 SCPY(options.fetch_tones, param);
203 PDEBUG(DEBUG_CONFIG, "directories of tones to fetch: %s\n",param);
205 if (!strcmp(option,"extensions_dir"))
209 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
212 if (param[strlen(param)-1] == '/')
213 param[strlen(param)-1]=0;
214 SCPY(options.extensions_dir, param);
216 PDEBUG(DEBUG_CONFIG, "directory of extensions: %s\n",param);
218 if (!strcmp(option,"national"))
220 SCPY(options.national, param);
222 PDEBUG(DEBUG_CONFIG, "national dial prefix: %s\n", param);
224 if (!strcmp(option,"international"))
226 SCPY(options.international, param);
228 PDEBUG(DEBUG_CONFIG, "inernational dial prefix: %s\n", param);
230 if (!strcmp(option,"dummyid"))
232 SCPY(options.dummyid, param);
234 PDEBUG(DEBUG_CONFIG, "dummy caller id\n", param);
236 if (!strcmp(option,"dsptones"))
238 if (!strcasecmp(param, "american"))
239 options.dsptones = DSP_AMERICAN;
240 else if (!strcasecmp(param, "german"))
241 options.dsptones = DSP_GERMAN;
242 else if (!strcasecmp(param, "oldgerman"))
243 options.dsptones = DSP_OLDGERMAN;
244 else if (!strcasecmp(param, "none"))
245 options.dsptones = DSP_NONE;
247 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
251 PDEBUG(DEBUG_CONFIG, "dsp tones = %d\n", options.dsptones);
253 if (!strcmp(option,"schedule"))
255 options.schedule = atoi(param);
256 if (options.schedule < 0)
258 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
261 if (options.schedule > 99)
263 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
268 PDEBUG(DEBUG_CONFIG, "use real time scheduler priority: %d\n", atoi(param));
270 PDEBUG(DEBUG_CONFIG, "don't use real time scheduler\n");
272 if (!strcmp(option,"email"))
276 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
279 SCPY(options.email, param);
281 PDEBUG(DEBUG_CONFIG, "source mail address of pbx: %s\n", param);
284 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
290 if (!options.dsptones)
292 PERROR_RUNTIME("Error in %s (line %d): option 'dsptones' missing.\n", filename);
296 if (!options.tones_dir[0])
298 PERROR_RUNTIME("Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);