1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading options.conf and filling structure **
10 \*****************************************************************************/
18 #include "extension.h"
21 struct options options = {
22 "/usr/local/lcr/log", /* log file */
23 0x0000, /* debug mode */
25 "0", /* national prefix */
26 "00", /* international prefix */
27 "tones_american", /* directory of tones */
28 "", /* directories of tones to fetch */
29 "", /* dummy caller id */
30 0, /* use tones by dsp.o */
31 0, /* by default use priority 0 */
32 "lcr@your.machine", /* source mail adress */
33 "/var/tmp", /* path of lock files */
34 0700 /* rights of lcr admin socket */
37 char options_error[256];
41 * read options from options.conf
43 int read_options(void)
53 SPRINT(filename, "%s/options.conf", CONFIG_DATA);
55 if (!(fp=fopen(filename,"r")))
57 SPRINT(options_error, "Cannot open %s\n",filename);
62 while((fgets(buffer,sizeof(buffer),fp)))
65 buffer[sizeof(buffer)-1]=0;
66 if (buffer[0]) buffer[strlen(buffer)-1]=0;
69 while(*p <= 32) /* skip spaces */
75 if (*p==0 || *p=='#') /* ignore comments and empty line */
79 i=0; /* read option */
82 if (i+1 >= sizeof(option))
84 SPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line);
91 while(*p <= 32) /* skip spaces */
99 if (*p!=0 && *p!='#') /* param */
101 i=0; /* read param */
104 if (i+1 >= sizeof(param))
106 SPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line);
114 /* at this point we have option and param */
117 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if"))
119 SPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
122 if (!strcmp(option,"debug"))
126 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
129 options.deb = strtol(param, NULL, 0);
132 if (!strcmp(option,"log"))
136 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
139 SCPY(options.log, param);
142 if (!strcmp(option,"alaw"))
147 if (!strcmp(option,"ulaw"))
152 if (!strcmp(option,"tones_dir"))
156 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
159 if (param[strlen(param)-1] == '/')
160 param[strlen(param)-1]=0;
161 SCPY(options.tones_dir, param);
164 if (!strcmp(option,"fetch_tones"))
168 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
171 if (param[strlen(param)-1] == '/')
172 param[strlen(param)-1]=0;
173 SCPY(options.fetch_tones, param);
176 if (!strcmp(option,"extensions_dir"))
180 if (!strcmp(option,"national"))
182 SCPY(options.national, param);
185 if (!strcmp(option,"international"))
187 SCPY(options.international, param);
190 if (!strcmp(option,"dummyid"))
192 SCPY(options.dummyid, param);
195 if (!strcmp(option,"dsptones"))
197 if (!strcasecmp(param, "american"))
198 options.dsptones = DSP_AMERICAN;
199 else if (!strcasecmp(param, "german"))
200 options.dsptones = DSP_GERMAN;
201 else if (!strcasecmp(param, "oldgerman"))
202 options.dsptones = DSP_OLDGERMAN;
203 else if (!strcasecmp(param, "none"))
204 options.dsptones = DSP_NONE;
206 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
211 if (!strcmp(option,"schedule"))
213 options.schedule = atoi(param);
214 if (options.schedule < 0)
216 SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
219 if (options.schedule > 99)
221 SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
226 if (!strcmp(option,"email"))
230 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
233 SCPY(options.email, param);
236 if (!strcmp(option,"lock"))
240 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
243 if (param[strlen(param)-1] == '/')
244 param[strlen(param)-1]=0;
245 SCPY(options.lock, param);
248 if (!strcmp(option,"socketrights"))
250 options.socketrights = strtol(param, NULL, 0);
253 SPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
259 if (!options.dsptones)
261 SPRINT(options_error, "Error in %s (line %d): option 'dsptones' missing.\n", filename);
265 if (!options.tones_dir[0])
267 SPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);