1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading options.conf and filling structure **
10 \*****************************************************************************/
18 #include "extension.h"
23 struct options options = {
24 LOG_DIR "/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/run", /* 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) */
38 0, /* use polling of main loop */
39 "/root", /* OTP directory */
42 char options_error[256];
46 * read options from options.conf
48 int read_options(char *options_error)
58 SPRINT(filename, "%s/options.conf", CONFIG_DATA);
60 if (!(fp=fopen(filename,"r"))) {
61 UPRINT(options_error, "Cannot open %s\n",filename);
66 while((fgets(buffer,sizeof(buffer),fp))) {
68 buffer[sizeof(buffer)-1]=0;
69 if (buffer[0]) buffer[strlen(buffer)-1]=0;
72 while(*p <= 32) { /* skip spaces */
77 if (*p==0 || *p=='#') /* ignore comments and empty line */
81 i=0; /* read option */
83 if (i+1 >= sizeof(option)) {
84 UPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line);
91 while(*p <= 32) { /* skip spaces */
98 if (*p!=0 && *p!='#') { /* param */
101 if (i+1 >= sizeof(param)) {
102 UPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line);
110 /* at this point we have option and param */
113 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if")) {
114 UPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
117 if (!strcmp(option,"debug")) {
119 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
122 options.deb = strtol(param, NULL, 0);
125 if (!strcmp(option,"log")) {
127 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
130 SCPY(options.log, param);
133 if (!strcmp(option,"alaw")) {
137 if (!strcmp(option,"ulaw")) {
141 if (!strcmp(option,"tones_dir")) {
143 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
146 if (param[strlen(param)-1] == '/')
147 param[strlen(param)-1]=0;
148 SCPY(options.tones_dir, param);
151 if (!strcmp(option,"fetch_tones")) {
153 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
156 if (param[strlen(param)-1] == '/')
157 param[strlen(param)-1]=0;
158 SCPY(options.fetch_tones, param);
161 if (!strcmp(option,"extensions_dir")) {
164 if (!strcmp(option,"national")) {
165 SCPY(options.national, param);
168 if (!strcmp(option,"international")) {
169 SCPY(options.international, param);
172 if (!strcmp(option,"dummyid")) {
173 SCPY(options.dummyid, param);
176 if (!strcmp(option,"dsptones")) {
177 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);
180 if (!strcmp(option,"schedule")) {
181 options.schedule = atoi(param);
182 if (options.schedule < 0) {
183 UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
186 if (options.schedule > 99) {
187 UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
192 if (!strcmp(option,"email")) {
194 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
197 SCPY(options.email, param);
200 if (!strcmp(option,"lock")) {
202 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
205 if (param[strlen(param)-1] == '/')
206 param[strlen(param)-1]=0;
207 SCPY(options.lock, param);
210 if (!strcmp(option,"socketuser")) {
211 char * endptr = NULL;
212 options.socketuser = strtol(param, &endptr, 10);
213 if (*endptr != '\0') {
214 struct passwd * pwd = getpwnam(param);
216 UPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param);
219 options.socketuser = pwd->pw_uid;
222 if (!strcmp(option,"socketgroup")) {
223 char * endptr = NULL;
224 options.socketgroup = strtol(param, &endptr, 10);
225 if (*endptr != '\0') {
226 struct group * grp = getgrnam(param);
228 UPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param);
231 options.socketgroup = grp->gr_gid;
234 if (!strcmp(option,"socketrights")) {
235 options.socketrights = strtol(param, NULL, 0);
237 if (!strcmp(option,"polling")) {
240 if (!strcmp(option,"otp-dir")) {
242 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
245 SCPY(options.otp_dir, param);
247 UPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
252 if (!options.tones_dir[0]) {
253 UPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename,line);