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 0x0000, /* debug mode */
18 "0", /* national prefix */
19 "00", /* international prefix */
20 "tones_american", /* directory of tones */
21 "", /* directories of tones to fetch */
22 "extensions", /* directory of extensions */
23 "", /* dummy caller id */
24 0, /* use tones by dsp.o */
25 0, /* by default use priority 0 */
26 "lcr@your.machine" /* source mail adress */
31 * read options from options.conf
33 int read_options(void)
43 SPRINT(filename, "%s/options.conf", INSTALL_DATA);
45 if (!(fp=fopen(filename,"r")))
47 PERROR("Cannot open %s\n",filename);
52 while((fgets(buffer,sizeof(buffer),fp)))
55 buffer[sizeof(buffer)-1]=0;
56 if (buffer[0]) buffer[strlen(buffer)-1]=0;
59 while(*p <= 32) /* skip spaces */
65 if (*p==0 || *p=='#') /* ignore comments and empty line */
69 i=0; /* read option */
72 if (i+1 >= sizeof(option))
74 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
81 while(*p <= 32) /* skip spaces */
89 if (*p!=0 && *p!='#') /* param */
94 if (i+1 >= sizeof(param))
96 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
104 /* at this point we have option and param */
107 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
109 PERROR_RUNTIME("Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
112 if (!strcmp(option,"debug"))
116 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
119 options.deb = strtol(param, NULL, 0);
121 PDEBUG(DEBUG_CONFIG, "debugging: 0x%x\n", options.deb);
123 if (!strcmp(option,"log"))
127 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
130 SCPY(options.log, param);
132 PDEBUG(DEBUG_CONFIG, "log file: %s\n", options.log);
134 if (!strcmp(option,"alaw"))
138 PDEBUG(DEBUG_CONFIG, "isdn audio type: alaw\n");
140 if (!strcmp(option,"ulaw"))
144 PDEBUG(DEBUG_CONFIG, "isdn audio type: ulaw\n");
146 if (!strcmp(option,"tones_dir"))
150 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
153 if (param[strlen(param)-1] == '/')
154 param[strlen(param)-1]=0;
155 SCPY(options.tones_dir, param);
157 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
159 if (!strcmp(option,"fetch_tones"))
163 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
166 if (param[strlen(param)-1] == '/')
167 param[strlen(param)-1]=0;
168 SCPY(options.fetch_tones, param);
170 PDEBUG(DEBUG_CONFIG, "directories of tones to fetch: %s\n",param);
172 if (!strcmp(option,"extensions_dir"))
176 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
179 if (param[strlen(param)-1] == '/')
180 param[strlen(param)-1]=0;
181 SCPY(options.extensions_dir, param);
183 PDEBUG(DEBUG_CONFIG, "directory of extensions: %s\n",param);
185 if (!strcmp(option,"national"))
187 SCPY(options.national, param);
189 PDEBUG(DEBUG_CONFIG, "national dial prefix: %s\n", param);
191 if (!strcmp(option,"international"))
193 SCPY(options.international, param);
195 PDEBUG(DEBUG_CONFIG, "inernational dial prefix: %s\n", param);
197 if (!strcmp(option,"dummyid"))
199 SCPY(options.dummyid, param);
201 PDEBUG(DEBUG_CONFIG, "dummy caller id\n", param);
203 if (!strcmp(option,"dsptones"))
205 if (!strcasecmp(param, "american"))
206 options.dsptones = DSP_AMERICAN;
207 else if (!strcasecmp(param, "german"))
208 options.dsptones = DSP_GERMAN;
209 else if (!strcasecmp(param, "oldgerman"))
210 options.dsptones = DSP_OLDGERMAN;
211 else if (!strcasecmp(param, "none"))
212 options.dsptones = DSP_NONE;
214 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
218 PDEBUG(DEBUG_CONFIG, "dsp tones = %d\n", options.dsptones);
220 if (!strcmp(option,"schedule"))
222 options.schedule = atoi(param);
223 if (options.schedule < 0)
225 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
228 if (options.schedule > 99)
230 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
235 PDEBUG(DEBUG_CONFIG, "use real time scheduler priority: %d\n", atoi(param));
237 PDEBUG(DEBUG_CONFIG, "don't use real time scheduler\n");
239 if (!strcmp(option,"email"))
243 PERROR_RUNTIME("Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
246 SCPY(options.email, param);
248 PDEBUG(DEBUG_CONFIG, "source mail address of pbx: %s\n", param);
251 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
257 if (!options.dsptones)
259 PERROR_RUNTIME("Error in %s (line %d): option 'dsptones' missing.\n", filename);
263 if (!options.tones_dir[0])
265 PERROR_RUNTIME("Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);