1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading options.conf and filling structure **
10 \*****************************************************************************/
18 #include "extension.h"
23 struct options options = {
24 "/usr/local/lcr/log", /* log file */
25 0x0000, /* debug mode */
27 "0", /* national prefix */
28 "00", /* international prefix */
29 "tones_american", /* directory of tones */
30 "", /* directories of tones to fetch */
31 "", /* dummy caller id */
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 */
36 -1, /* socket user (-1= no change) */
37 -1, /* socket group (-1= no change) */
39 1, /* use polling of main loop */
40 "mISDN_l1loop.1", /* GSM/Asterisk side */
41 "mISDN_l1loop.2", /* LCR side */
44 char options_error[256];
48 * read options from options.conf
50 int read_options(char *options_error)
60 SPRINT(filename, "%s/options.conf", CONFIG_DATA);
62 if (!(fp=fopen(filename,"r"))) {
63 UPRINT(options_error, "Cannot open %s\n",filename);
68 while((fgets(buffer,sizeof(buffer),fp))) {
70 buffer[sizeof(buffer)-1]=0;
71 if (buffer[0]) buffer[strlen(buffer)-1]=0;
74 while(*p <= 32) { /* skip spaces */
79 if (*p==0 || *p=='#') /* ignore comments and empty line */
83 i=0; /* read option */
85 if (i+1 >= sizeof(option)) {
86 UPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line);
93 while(*p <= 32) { /* skip spaces */
100 if (*p!=0 && *p!='#') { /* param */
101 i=0; /* read param */
103 if (i+1 >= sizeof(param)) {
104 UPRINT(options_error, "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")) {
116 UPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
119 if (!strcmp(option,"debug")) {
121 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
124 options.deb = strtol(param, NULL, 0);
127 if (!strcmp(option,"log")) {
129 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
132 SCPY(options.log, param);
135 if (!strcmp(option,"alaw")) {
139 if (!strcmp(option,"ulaw")) {
143 if (!strcmp(option,"tones_dir")) {
145 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
148 if (param[strlen(param)-1] == '/')
149 param[strlen(param)-1]=0;
150 SCPY(options.tones_dir, param);
153 if (!strcmp(option,"fetch_tones")) {
155 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
158 if (param[strlen(param)-1] == '/')
159 param[strlen(param)-1]=0;
160 SCPY(options.fetch_tones, param);
163 if (!strcmp(option,"extensions_dir")) {
166 if (!strcmp(option,"national")) {
167 SCPY(options.national, param);
170 if (!strcmp(option,"international")) {
171 SCPY(options.international, param);
174 if (!strcmp(option,"dummyid")) {
175 SCPY(options.dummyid, param);
178 if (!strcmp(option,"dsptones")) {
179 UPRINT(options_error, "Error in %s (line %d): parameter 'dsptones' is obsolete. Just define the tones (american,german,oldgerman) at 'tones_dir' option.\n",filename,line);
182 if (!strcmp(option,"schedule")) {
183 options.schedule = atoi(param);
184 if (options.schedule < 0) {
185 UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
188 if (options.schedule > 99) {
189 UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
194 if (!strcmp(option,"email")) {
196 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
199 SCPY(options.email, param);
202 if (!strcmp(option,"lock")) {
204 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
207 if (param[strlen(param)-1] == '/')
208 param[strlen(param)-1]=0;
209 SCPY(options.lock, param);
212 if (!strcmp(option,"socketuser")) {
213 char * endptr = NULL;
214 options.socketuser = strtol(param, &endptr, 10);
215 if (*endptr != '\0') {
216 struct passwd * pwd = getpwnam(param);
218 UPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param);
221 options.socketuser = pwd->pw_uid;
224 if (!strcmp(option,"socketgroup")) {
225 char * endptr = NULL;
226 options.socketgroup = strtol(param, &endptr, 10);
227 if (*endptr != '\0') {
228 struct group * grp = getgrnam(param);
230 UPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param);
233 options.socketgroup = grp->gr_gid;
236 if (!strcmp(option,"socketrights")) {
237 options.socketrights = strtol(param, NULL, 0);
239 if (!strcmp(option,"gsm")) {
242 if (!strcmp(option,"polling")) {
245 if (!strcmp(option,"loopback-ext")) {
247 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
250 SCPY(options.loopback_ext, param);
253 if (!strcmp(option,"loopback-lcr")) {
255 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
258 SCPY(options.loopback_lcr, param);
261 UPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
266 if (!options.tones_dir[0]) {
267 UPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename,line);