📄 smsd_cfg.c
字号:
} else if (strcasecmp(name,"rtscts")==0) { if ((devices[device].rtscts = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"primary_memory")==0) { strcpy(value, ask_value(device_name, name, value)); while ((p = strchr(value,'\"'))) strcpy(p, p+1); strcpy2(devices[device].primary_memory,value); } else if (strcasecmp(name,"secondary_memory")==0) { strcpy(value, ask_value(device_name, name, value)); while ((p = strchr(value,'\"'))) strcpy(p, p+1); strcpy2(devices[device].secondary_memory,value); } else if (strcasecmp(name,"secondary_memory_max")==0) devices[device].secondary_memory_max=atoi(ask_value(device_name, name, value)); else if (strcasecmp(name,"pdu_from_file")==0) strcpy2(devices[device].pdu_from_file, ask_value(device_name, name, value)); else if (strcasecmp(name,"sending_disabled")==0) { if ((devices[device].sending_disabled = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"modem_disabled")==0) { if ((devices[device].modem_disabled = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"decode_unicode_text")==0) { if ((devices[device].decode_unicode_text = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"internal_combine")==0) { if ((devices[device].internal_combine = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"pre_init")==0) { if ((devices[device].pre_init = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"admin_to")==0) strcpy2(devices[device].admin_to, ask_value(device_name, name, value)); else if (strcasecmp(name,"message_limit")==0) devices[device].message_limit=atoi(ask_value(device_name, name, value)); else if (strcasecmp(name,"message_count_clear")==0) devices[device].message_count_clear=atoi(ask_value(device_name, name, value)) *60; else if (strcasecmp(name,"keep_open")==0) { if ((devices[device].keep_open = yesno_check(ask_value(device_name, name, value))) == -1) startuperror(yesno_error, name, value); } else if (strcasecmp(name,"regular_run")==0) strcpy2(devices[device].dev_rr, ask_value(device_name, name, value)); else if (strcasecmp(name,"regular_run_interval")==0) { if ((devices[device].dev_rr_interval = atoi(strcpy(value, ask_value(device_name, name, value)))) <= 0) startuperror("Invalid regular_run_interval for %s in config file: %s\n", device_name, value); } else if (strcasecmp(name,"regular_run_cmdfile")==0) strcpy2(devices[device].dev_rr_cmdfile, ask_value(device_name, name, value)); else if (strcasecmp(name,"regular_run_cmd")==0) { strcpy(value, ask_value(device_name, name, value)); // If not empty, buffer is terminated with double-zero. if (*value) { p = devices[device].dev_rr_cmd; while (*p) p = strchr(p, 0) +1; if (strlen(value) <= SIZE_RR_CMD -2 -(p - devices[device].dev_rr_cmd)) { strcpy(p, value); *(p +strlen(value) +1) = 0; } else startuperror("Not enough space for %s regular_run_cmd value: %s\n", device_name, value); } } else if (strcasecmp(name,"regular_run_logfile")==0) strcpy2(devices[device].dev_rr_logfile, ask_value(device_name, name, value)); else if (strcasecmp(name,"regular_run_loglevel")==0) { strcpy(value, ask_value(device_name, name, value)); devices[device].dev_rr_loglevel = set_level(devices[device].name, name, value); } else if (strcasecmp(name,"regular_run_statfile")==0) strcpy2(devices[device].dev_rr_statfile, ask_value(device_name, name, value)); else startuperror("Unknown variable in config file for modem %s: %s\n", device_name, name); //result=my_getline(File,name,sizeof(name),value,sizeof(value)); } //if (result==-1) // startuperror("Syntax Error in config file: %s\n",value); // 3.1beta7: Later this message is logged and setting is cleared. if (devices[device].report == 1 && !devices[device].incoming && devices[device].outgoing) fprintf(stderr,"Warning: Cannot receive status reports because receiving is disabled on modem %s\n", device_name); } } else break; } } fclose(File); set_alarmhandler(alarmhandler,alarmlevel); // if loglevel is unset, then set it depending on if we use syslog or a logfile if (loglevel==-1) { if (logfile[0]==0) loglevel=LOG_DEBUG; else loglevel=LOG_WARNING; } if (conf_ask > 1) { printf("Smsd will now try to start.\n"); fflush(stdout); } } else { fprintf(stderr,"Cannot open config file for read.\n"); return 0; } return 1;}int getqueue(char* name, char* directory) // Name can also be a phone number{ int i; int j;#ifdef DEBUGMSG printf("!! getqueue(name=%s,... )\n",name);#endif // If no queues are defined, then directory is always d_checked if (queues[0].name[0]==0) { strcpy(directory,d_checked);#ifdef DEBUGMSG printf("!! Returns -2, no queues, directory=%s\n",directory);#endif return -2; } // Short number is also accepted as a number: // 3.1beta4: A number can probably start with # or *: //if (is_number(name) || (*name == 's' && is_number(name +1))) if (isdigit(*name) || (*name && strchr("#*", *name)) || (strlen(name) > 1 && *name == 's' && isdigit(*(name +1)))) {#ifdef DEBUGMSG printf("!! Searching by number\n");#endif i=0; while (queues[i].name[0] && (i<PROVIDER)) { j=0; while (queues[i].numbers[j][0] && (j<NUMS)) { if (!strncmp(queues[i].numbers[j],name,strlen(queues[i].numbers[j]))) { strcpy(directory,queues[i].directory);#ifdef DEBUGMSG printf("!! Returns %i, directory=%s\n",i,directory);#endif return i; } j++; } i++; } } else {#ifdef DEBUGMSG printf("!! Searching by name\n");#endif i=0; while (queues[i].name[0] && (i<PROVIDER)) { if (!strcmp(name,queues[i].name)) { strcpy(directory,queues[i].directory);#ifdef DEBUGMSG printf("!! Returns %i, directory=%s\n",i,directory);#endif return i; } i++; } } /* not found */ directory[0]=0;#ifdef DEBUGMSG printf("!! Returns -1, not found, name=%s, directory=%s\n", name, directory);#endif return -1;}int getdevice(char* name){ int i=0; while (devices[i].name[0] && (i<DEVICES)) { if (!strcmp(name,devices[i].name)) return i; i++; } return -1;}void help(){ printf("smsd spools incoming and outgoing sms.\n\n"); printf("Usage:\n"); printf(" smsd [options]\n\n"); printf("Options:\n"); printf(" -a ask config settings\n"); printf(" -cx set config file to x\n"); printf(" -ix set infofile to x\n"); printf(" -px set pidfile to x\n"); printf(" -lx set logfile to x\n"); printf(" -ux set username to x\n"); printf(" -gx set groupname to x\n"); printf(" -h this help\n");#ifndef NOSTATS printf(" -s display status monitor\n");#endif printf(" -t run smsd in terminal\n"); printf(" -C Communicate with device\n\n"); printf(" -V print copyright and version\n\n"); printf("All other options are set by the file /etc/smsd.conf.\n\n"); printf("Output is written to stdout, errors are written to stderr.\n\n"); exit(0);}void parsearguments(int argc,char** argv){ int result; strcpy(configfile,"/etc/smsd.conf"); printstatus=0; arg_infofile[0] = 0; arg_pidfile[0] = 0; arg_username[0] = 0; arg_groupname[0] = 0; arg_logfile[0] = 0; arg_terminal = 0; communicate[0] = 0; do { result=getopt(argc,argv,"asthc:Vi:p:l:u:g:C:"); switch (result) { case 'a': conf_ask = 1; break; case 'h': help(); break; case 'c': copyvalue(configfile, sizeof(configfile) -1, optarg, "configfile commandline argument"); break; case 's': #ifndef NOSTATS printstatus=1; break;#else printf("Status monitor is not included in this compilation.\n"); exit(0);#endif case 't': arg_terminal = 1; break; case 'V': printf("Version %s, Copyright (c) Keijo Kasvi, %s@%s.%s, http://smstools3.kekekasvi.com\n", smsd_version,"smstools3","kekekasvi","com"); printf("Based on SMS Server Tools 2 from Stefan Frings, %s@%s.%s, http://www.meinemullemaus.de\n", "smstools","meinemullemaus","de"); exit(0); case 'i': copyvalue(arg_infofile, sizeof(arg_infofile) -1, optarg, "infofile commandline argument"); break; case 'p': copyvalue(arg_pidfile, sizeof(arg_pidfile) -1, optarg, "pidfile commandline argument"); break; case 'l': copyvalue(arg_logfile, sizeof(arg_logfile) -1, optarg, "logfile commandline argument"); break; case 'u': copyvalue(arg_username, sizeof(arg_username) -1, optarg, "username commandline argument"); break; case 'g': copyvalue(arg_groupname, sizeof(arg_groupname) -1, optarg, "groupname commandline argument"); break; case 'C': copyvalue(communicate, sizeof(communicate) -1, optarg, "Communicate commandline argument"); break; } } while (result>0);}int check_directory(char *dir){ int result = 0; char fname[PATH_MAX]; int fd; DIR* dirdata; if (dir && *dir) { if (!(dirdata = opendir(dir))) result = 2; else { closedir(dirdata); strcpy(fname, dir); if (fname[strlen(fname) -1] != '/') strcat(fname, "/"); strcat(fname, "test.XXXXXX"); if ((fd = mkstemp(fname)) == -1) result = 3; else { close(fd); unlink(fname); } } } else result = 1; return result;}void remove_lockfiles(char *dir){ DIR* dirdata; struct dirent* ent; struct stat statbuf; char tmpname[PATH_MAX]; if (dir && *dir) { if ((dirdata = opendir(dir))) { while ((ent = readdir(dirdata))) { sprintf(tmpname, "%s%s%s", dir, (dir[strlen(dir) -1] != '/')? "/" : "", ent->d_name); stat(tmpname, &statbuf); if (S_ISDIR(statbuf.st_mode) == 0) if (strcmp(tmpname +strlen(tmpname) -5, ".LOCK") == 0) if (unlink(tmpname) != 0) startuperror("Cannot unlink file %s: %s\n", tmpname, strerror(errno)); } closedir(dirdata); } }}void wrlogfile(int *result, char* format, ...){ va_list argp; char text[2048]; va_start(argp, format); vsnprintf(text, sizeof(text), format, argp); va_end(argp); fprintf(stderr, "%s\n", text); writelogfile(LOG_CRIT, "smsd", "%s", text);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -