X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=options.c;h=88f64246fe932a027736e617ffc787e75168f908;hp=160a8a87c584dd1f70dbc2bfba0d2c5346558aa9;hb=882882e0e2f6c451c4b9a5aa8209aa60352049c9;hpb=26c7e0d22ead805ce333ea4248c7311c1eda5de0 diff --git a/options.c b/options.c index 160a8a8..88f6424 100644 --- a/options.c +++ b/options.c @@ -9,14 +9,16 @@ ** ** \*****************************************************************************/ -#include "stdio.h" -#include "string.h" -#include "stdarg.h" -#include "unistd.h" -#include "stdlib.h" +#include +#include +#include +#include +#include #include "macro.h" #include "extension.h" #include "options.h" +#include +#include struct options options = { "/usr/local/lcr/log", /* log file */ @@ -27,11 +29,14 @@ struct options options = { "tones_american", /* directory of tones */ "", /* directories of tones to fetch */ "", /* dummy caller id */ - 0, /* use tones by dsp.o */ 0, /* by default use priority 0 */ "lcr@your.machine", /* source mail adress */ "/var/tmp", /* path of lock files */ - 0700 /* rights of lcr admin socket */ + 0700, /* rights of lcr admin socket */ + -1, /* socket user (-1= no change) */ + -1, /* socket group (-1= no change) */ + 0, /* enable gsm */ + 1 /* use polling of main loop */ }; char options_error[256]; @@ -40,7 +45,7 @@ char options_error[256]; * * read options from options.conf */ -int read_options(void) +int read_options(char *options_error) { FILE *fp=NULL; char filename[128]; @@ -52,22 +57,19 @@ int read_options(void) SPRINT(filename, "%s/options.conf", CONFIG_DATA); - if (!(fp=fopen(filename,"r"))) - { - SPRINT(options_error, "Cannot open %s\n",filename); + if (!(fp=fopen(filename,"r"))) { + UPRINT(options_error, "Cannot open %s\n",filename); return(0); } line=0; - while((fgets(buffer,sizeof(buffer),fp))) - { + while((fgets(buffer,sizeof(buffer),fp))) { line++; buffer[sizeof(buffer)-1]=0; if (buffer[0]) buffer[strlen(buffer)-1]=0; p=buffer; - while(*p <= 32) /* skip spaces */ - { + while(*p <= 32) { /* skip spaces */ if (*p == 0) break; p++; @@ -77,33 +79,27 @@ int read_options(void) option[0]=0; i=0; /* read option */ - while(*p > 32) - { - if (i+1 >= sizeof(option)) - { - SPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line); + while(*p > 32) { + if (i+1 >= sizeof(option)) { + UPRINT(options_error, "Error in %s (line %d): option too long.\n",filename,line); goto error; } option[i+1] = '\0'; option[i++] = *p++; } - while(*p <= 32) /* skip spaces */ - { + while(*p <= 32) { /* skip spaces */ if (*p == 0) break; p++; } param[0]=0; - if (*p!=0 && *p!='#') /* param */ - { + if (*p!=0 && *p!='#') { /* param */ i=0; /* read param */ - while(*p > 31) - { - if (i+1 >= sizeof(param)) - { - SPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line); + while(*p > 31) { + if (i+1 >= sizeof(param)) { + UPRINT(options_error, "Error in %s (line %d): param too long.\n",filename,line); goto error; } param[i+1] = '\0'; @@ -114,46 +110,37 @@ int read_options(void) /* at this point we have option and param */ /* check option */ - if (!strcmp(option,"nt_if") || !strcmp(option,"te_if")) - { - SPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option); + if (!strcmp(option,"nt_if") || !strcmp(option,"te_if")) { + UPRINT(options_error, "Error in %s (line %d): obsolete option %s. Use multiple 'port' options to define ports to use.\n",filename,line,option); goto error; } else - if (!strcmp(option,"debug")) - { - if (param[0]==0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + if (!strcmp(option,"debug")) { + if (param[0]==0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } options.deb = strtol(param, NULL, 0); } else - if (!strcmp(option,"log")) - { - if (param[0]==0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); + if (!strcmp(option,"log")) { + if (param[0]==0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option); goto error; } SCPY(options.log, param); } else - if (!strcmp(option,"alaw")) - { + if (!strcmp(option,"alaw")) { options.law = 'a'; } else - if (!strcmp(option,"ulaw")) - { + if (!strcmp(option,"ulaw")) { options.law = 'u'; } else - if (!strcmp(option,"tones_dir")) - { - if (param[0]==0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + if (!strcmp(option,"tones_dir")) { + if (param[0]==0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } if (param[strlen(param)-1] == '/') @@ -161,11 +148,9 @@ int read_options(void) SCPY(options.tones_dir, param); } else - if (!strcmp(option,"fetch_tones")) - { - if (param[0]==0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + if (!strcmp(option,"fetch_tones")) { + if (param[0]==0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } if (param[strlen(param)-1] == '/') @@ -173,71 +158,48 @@ int read_options(void) SCPY(options.fetch_tones, param); } else - if (!strcmp(option,"extensions_dir")) - { + if (!strcmp(option,"extensions_dir")) { // obsolete } else - if (!strcmp(option,"national")) - { + if (!strcmp(option,"national")) { SCPY(options.national, param); } else - if (!strcmp(option,"international")) - { + if (!strcmp(option,"international")) { SCPY(options.international, param); } else - if (!strcmp(option,"dummyid")) - { + if (!strcmp(option,"dummyid")) { SCPY(options.dummyid, param); } else - if (!strcmp(option,"dsptones")) - { - if (!strcasecmp(param, "american")) - options.dsptones = DSP_AMERICAN; - else if (!strcasecmp(param, "german")) - options.dsptones = DSP_GERMAN; - else if (!strcasecmp(param, "oldgerman")) - options.dsptones = DSP_OLDGERMAN; - else if (!strcasecmp(param, "none")) - options.dsptones = DSP_NONE; - else { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); - goto error; - } - + if (!strcmp(option,"dsptones")) { + 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); + goto error; } else - if (!strcmp(option,"schedule")) - { + if (!strcmp(option,"schedule")) { options.schedule = atoi(param); - if (options.schedule < 0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option); + if (options.schedule < 0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be at least '0'.\n", filename,line,option); goto error; } - if (options.schedule > 99) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option); + if (options.schedule > 99) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s must be '99' or less.\n", filename,line,option); goto error; } } else - if (!strcmp(option,"email")) - { - if (param[0]==0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option); + if (!strcmp(option,"email")) { + if (param[0]==0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n", filename,line,option); goto error; } SCPY(options.email, param); } else - if (!strcmp(option,"lock")) - { - if (param[0]==0) - { - SPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); + if (!strcmp(option,"lock")) { + if (param[0]==0) { + UPRINT(options_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option); goto error; } if (param[strlen(param)-1] == '/') @@ -245,26 +207,46 @@ int read_options(void) SCPY(options.lock, param); } else - if (!strcmp(option,"socketrights")) - { + if (!strcmp(option,"socketuser")) { + char * endptr = NULL; + options.socketuser = strtol(param, &endptr, 10); + if (*endptr != '\0') { + struct passwd * pwd = getpwnam(param); + if (pwd == NULL) { + UPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param); + goto error; + } + options.socketuser = pwd->pw_uid; + } + } else + if (!strcmp(option,"socketgroup")) { + char * endptr = NULL; + options.socketgroup = strtol(param, &endptr, 10); + if (*endptr != '\0') { + struct group * grp = getgrnam(param); + if (grp == NULL) { + UPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param); + goto error; + } + options.socketgroup = grp->gr_gid; + } + } else + if (!strcmp(option,"socketrights")) { options.socketrights = strtol(param, NULL, 0); } else - { - SPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option); + if (!strcmp(option,"gsm")) { + options.gsm = 1; + } else + if (!strcmp(option,"polling")) { + options.polling = 1; + } else { + UPRINT(options_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option); goto error; } } -#if 0 - if (!options.dsptones) - { - SPRINT(options_error, "Error in %s (line %d): option 'dsptones' missing.\n", filename); - goto error; - } -#endif - if (!options.tones_dir[0]) - { - SPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename); + if (!options.tones_dir[0]) { + UPRINT(options_error, "Error in %s (line %d): option 'tones_dir' with parameter missing.\n", filename,line); goto error; } if (fp) fclose(fp);