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 "extensions", /* directory of extensions */
30 "", /* dummy caller id */
31 0, /* use tones by dsp.o */
32 0, /* by default use priority 0 */
33 "lcr@your.machine", /* source mail adress */
34 "/var/tmp", /* path of lock files */
35 0700 /* rights of lcr admin socket */
38 char options_error[256];
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 SPRINT(options_error, "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 SPRINT(options_error, "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 SPRINT(options_error, "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 SPRINT(options_error, "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 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
130 options.deb = strtol(param, NULL, 0);
133 if (!strcmp(option,"log"))
137 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
140 SCPY(options.log, param);
143 if (!strcmp(option,"alaw"))
148 if (!strcmp(option,"ulaw"))
153 if (!strcmp(option,"tones_dir"))
157 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
160 if (param[strlen(param)-1] == '/')
161 param[strlen(param)-1]=0;
162 SCPY(options.tones_dir, param);
165 if (!strcmp(option,"fetch_tones"))
169 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
172 if (param[strlen(param)-1] == '/')
173 param[strlen(param)-1]=0;
174 SCPY(options.fetch_tones, param);
177 if (!strcmp(option,"extensions_dir"))
181 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
184 if (param[strlen(param)-1] == '/')
185 param[strlen(param)-1]=0;
186 SCPY(options.extensions_dir, param);
189 if (!strcmp(option,"national"))
191 SCPY(options.national, param);
194 if (!strcmp(option,"international"))
196 SCPY(options.international, param);
199 if (!strcmp(option,"dummyid"))
201 SCPY(options.dummyid, param);
204 if (!strcmp(option,"dsptones"))
206 if (!strcasecmp(param, "american"))
207 options.dsptones = DSP_AMERICAN;
208 else if (!strcasecmp(param, "german"))
209 options.dsptones = DSP_GERMAN;
210 else if (!strcasecmp(param, "oldgerman"))
211 options.dsptones = DSP_OLDGERMAN;
212 else if (!strcasecmp(param, "none"))
213 options.dsptones = DSP_NONE;
215 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
220 if (!strcmp(option,"schedule"))
222 options.schedule = atoi(param);
223 if (options.schedule < 0)
225 SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
228 if (options.schedule > 99)
230 SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
235 if (!strcmp(option,"email"))
239 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
242 SCPY(options.email, param);
245 if (!strcmp(option,"lock"))
249 SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
252 if (param[strlen(param)-1] == '/')
253 param[strlen(param)-1]=0;
254 SCPY(options.lock, param);
257 if (!strcmp(option,"socketrights"))
259 options.socketrights = strtol(param, NULL, 0);
262 SPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
268 if (!options.dsptones)
270 SPRINT(options_error, "Error in %s (line %d): option 'dsptones' missing.\n", filename);
274 if (!options.tones_dir[0])
276 SPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename);