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 1, /* use polling of main loop */
41 char options_error[256];
45 * read options from options.conf
47 int read_options(char *options_error)
57 SPRINT(filename, "%s/options.conf", CONFIG_DATA);
59 if (!(fp=fopen(filename,"r"))) {
60 UPRINT(options_error, "Cannot open %s\n",filename);
65 while((fgets(buffer,sizeof(buffer),fp))) {
67 buffer[sizeof(buffer)-1]=0;
68 if (buffer[0]) buffer[strlen(buffer)-1]=0;
71 while(*p <= 32) { /* skip spaces */
76 if (*p==0 || *p=='#') /* ignore comments and empty line */
80 i=0; /* read option */
82 if (i+1 >= sizeof(option)) {
83 UPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line);
90 while(*p <= 32) { /* skip spaces */
97 if (*p!=0 && *p!='#') { /* param */
100 if (i+1 >= sizeof(param)) {
101 UPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line);
109 /* at this point we have option and param */
112 if (!strcmp(option,"nt_if") || !strcmp(option,"te_if")) {
113 UPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option);
116 if (!strcmp(option,"debug")) {
118 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
121 options.deb = strtol(param, NULL, 0);
124 if (!strcmp(option,"log")) {
126 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
129 SCPY(options.log, param);
132 if (!strcmp(option,"alaw")) {
136 if (!strcmp(option,"ulaw")) {
140 if (!strcmp(option,"tones_dir")) {
142 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
145 if (param[strlen(param)-1] == '/')
146 param[strlen(param)-1]=0;
147 SCPY(options.tones_dir, param);
150 if (!strcmp(option,"fetch_tones")) {
152 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
155 if (param[strlen(param)-1] == '/')
156 param[strlen(param)-1]=0;
157 SCPY(options.fetch_tones, param);
160 if (!strcmp(option,"extensions_dir")) {
163 if (!strcmp(option,"national")) {
164 SCPY(options.national, param);
167 if (!strcmp(option,"international")) {
168 SCPY(options.international, param);
171 if (!strcmp(option,"dummyid")) {
172 SCPY(options.dummyid, param);
175 if (!strcmp(option,"dsptones")) {
176 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);
179 if (!strcmp(option,"schedule")) {
180 options.schedule = atoi(param);
181 if (options.schedule < 0) {
182 UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option);
185 if (options.schedule > 99) {
186 UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option);
191 if (!strcmp(option,"email")) {
193 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option);
196 SCPY(options.email, param);
199 if (!strcmp(option,"lock")) {
201 UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
204 if (param[strlen(param)-1] == '/')
205 param[strlen(param)-1]=0;
206 SCPY(options.lock, param);
209 if (!strcmp(option,"socketuser")) {
210 char * endptr = NULL;
211 options.socketuser = strtol(param, &endptr, 10);
212 if (*endptr != '\0') {
213 struct passwd * pwd = getpwnam(param);
215 UPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param);
218 options.socketuser = pwd->pw_uid;
221 if (!strcmp(option,"socketgroup")) {
222 char * endptr = NULL;
223 options.socketgroup = strtol(param, &endptr, 10);
224 if (*endptr != '\0') {
225 struct group * grp = getgrnam(param);
227 UPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param);
230 options.socketgroup = grp->gr_gid;
233 if (!strcmp(option,"socketrights")) {
234 options.socketrights = strtol(param, NULL, 0);
236 if (!strcmp(option,"polling")) {
239 UPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
244 if (!options.tones_dir[0]) {
245 UPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename,line);