⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsd_cfg.c

📁 GSM猫管理程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/*SMS Server Tools 3Copyright (C) Keijo Kasvihttp://smstools3.kekekasvi.com/Based on SMS Server Tools 2 from Stefan Fringshttp://www.meinemullemaus.de/This program is free software unless you got it under another license directlyfrom the author. You can redistribute it and/or modify it under the terms ofthe GNU General Public License as published by the Free Software Foundation.Either version 2 of the License, or (at your option) any later version.*/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <syslog.h>#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>#include <stdarg.h>#include <errno.h>#include <ctype.h>#include <grp.h>#include "extras.h"#include "cfgfile.h"#include "smsd_cfg.h"#include "stats.h"#include "version.h"#include "blacklist.h"#include "whitelist.h"#include "alarm.h"#include "logging.h"int conf_ask = 0;char *yesno_error = "Invalid %s value in config file: %s\n";#define strcpy2(dest, value) copyvalue(dest, sizeof(dest) -1, value, name)char *tb_sprintf(char* format, ...){  va_list argp;  va_start(argp, format);  vsnprintf(tb, sizeof(tb), format, argp);  va_end(argp);  return tb;}void startuperror(char* format, ...){  va_list argp;  char text[2048];  va_start(argp, format);  vsnprintf(text, sizeof(text), format, argp);  va_end(argp);  // Perhaps more safe way than passing a null pointer to realloc:  if (!startup_err_str)  {    startup_err_str = (char *)malloc(strlen(text) +1);    if (startup_err_str)      *startup_err_str = 0;  }  else    startup_err_str = (char *)realloc((void *)startup_err_str, strlen(startup_err_str) + strlen(text) +1);  if (startup_err_str)  {    strcat(startup_err_str, text);    startup_err_count++;  }}// Helper function for copying to prevent buffer overflows:char *copyvalue(char *dest, int maxlen, char *value, char *keyword){  if (strlen(value) > maxlen)  {    if (keyword)      startuperror("Too long value in config file for \"%s\" (%s)\n", keyword, value);    else      startuperror("Too long value in config file (%s)\n", value);    return NULL;  }  strcpy(dest, value);  return dest;}int set_level(char *section, char *name, char *value){  int result = 0;  char *p;  int i;  if ((p = malloc(strlen(value) +1)))  {    strcpy(p, value);    for (i = 0; p[i]; i++)      p[i] = toupper(p[i]);    if ((result = atoi(value)) < 1)    {      if (strstr(p, "DEBUG"))        result = 7;      else if (strstr(p, "INFO"))        result = 6;      else if (strstr(p, "NOTICE"))        result = 5;      else if (strstr(p, "WARNING"))        result = 4;      else if (strstr(p, "ERROR"))        result = 3;      else if (strstr(p, "CRITICAL"))        result = 2;    }    free(p);  }  if (result < 1)    startuperror("Invalid value for %s %s in config file: %s\n", section, name, value);  return result;}void initcfg(){  int i;  int j;  autosplit=3;  receive_before_send=0;  store_received_pdu=1;  store_sent_pdu = 1;  validity_period=255;  delaytime=10;  blocktime=60*60;  blockafter = 3;  errorsleeptime=10;  blacklist[0]=0;  whitelist[0]=0;  eventhandler[0]=0;  checkhandler[0]=0;  alarmhandler[0]=0;  logfile[0]=0;  loglevel=-1;  // Will be changed after reading the cfg file if stil -1  alarmlevel=LOG_WARNING;  strcpy(d_spool,"/var/spool/sms/outgoing");  strcpy(d_incoming,"/var/spool/sms/incoming");  *d_report = 0;  *d_phonecalls = 0;  *d_saved = 0;  strcpy(d_checked,"/var/spool/sms/checked");  d_failed[0]=0;  d_sent[0]=0;  d_stats[0]=0;  stats_interval=60*60;  stats_no_zeroes=0;  decode_unicode_text=0;  internal_combine=0;  keep_filename = 1;  store_original_filename = 1;  regular_run[0] = 0;  regular_run_interval = 5 * 60;  admin_to[0] = 0;  filename_preview = 0;  incoming_utf8 = 0;  outgoing_utf8 = 1;  log_charconv = 0;  message_count = 0;  username[0] = 0;  groupname[0] = 0;  strcpy(infofile, "/var/run/smsd.working");  strcpy(pidfile, "/var/run/smsd.pid");  terminal = 0;  os_cygwin = 0;  for (i=0; i<PROVIDER; i++)  {    queues[i].name[0]=0;    queues[i].directory[0]=0;    for (j=0; j<NUMS; j++)      queues[i].numbers[j][0]=0;  }  for (i=0; i<DEVICES; i++)  {    devices[i].name[0]=0;    devices[i].device[0]=0;    devices[i].identity[0] = 0;    //devices[i].identity_header[0] = 0;    devices[i].incoming=0;    devices[i].outgoing=1;    devices[i].pin[0]=0;    devices[i].pinsleeptime=0;    devices[i].smsc[0]=0;    devices[i].baudrate=19200;    devices[i].send_delay=1;    devices[i].cs_convert=1;    devices[i].initstring[0]=0;    devices[i].initstring2[0]=0;    devices[i].eventhandler[0]=0;    devices[i].report=0;    devices[i].phonecalls=0;    devices[i].rtscts=1;    devices[i].read_memory_start=1;    strcpy(devices[i].mode,"new");    // Assigned queue name is never a directory name:    //strcpy(devices[i].queues[0],d_checked);    //for (j=1; j<PROVIDER; j++)    for (j=0; j<PROVIDER; j++)      devices[i].queues[j][0]=0;    devices[i].primary_memory[0]=0;    devices[i].secondary_memory[0]=0;    devices[i].secondary_memory_max=-1;    devices[i].pdu_from_file[0]=0;    devices[i].sending_disabled=0;    devices[i].modem_disabled=0;    devices[i].decode_unicode_text=-1;    devices[i].internal_combine=-1;    devices[i].pre_init = 1;    devices[i].check_network=1;    devices[i].admin_to[0]=0;    devices[i].message_limit=0;    devices[i].message_count_clear=0;    devices[i].keep_open = 1; // 0;    devices[i].dev_rr[0] = 0;    devices[i].dev_rr_interval = 5 * 60;    devices[i].dev_rr_cmdfile[0] = 0;    devices[i].dev_rr_cmd[0] = 0;    devices[i].dev_rr_logfile[0] = 0;    devices[i].dev_rr_loglevel = LOG_NOTICE;    devices[i].dev_rr_statfile[0] = 0;  }  startup_err_str = NULL;  startup_err_count = 0;  *language_file = 0;  translate_incoming = 1;  *yes_chars = 0;  *no_chars = 0;  strcpy(yes_word, "yes");  strcpy(no_word, "no");  strcpy(datetime_format, DATETIME_DEFAULT);}char *ask_value(char *section, char *name, char *value){  int m;  char tmp[PATH_MAX];  int i;  int n;  if (*value == '?')  {    while (*value && strchr("? \t", *value))      strcpy(value, value +1);    if (!conf_ask)    {      getsubparam_delim(value, 1, tmp, sizeof(tmp), '|');      strcpy(value, tmp);    }    else    {      conf_ask++;      while (1)      {        printf("Value for \"%s %s\" (Enter for the first value, 0 to exit):\n",               (section && *section)? section : "global", name);        m = 0;        while (getsubparam_delim(value, m +1, tmp, sizeof(tmp), '|'))          printf("%i) %s\n", ++m, tmp);        printf("%i) Other\n", ++m);        printf("Select 1 to %i: ", m);        fflush(stdout);        if ((n = read(STDIN_FILENO, tmp, sizeof(tmp) -1)) > 0)          tmp[n] = 0;        else          *tmp = 0;        cut_ctrl(tmp);        cutspaces(tmp);        if (!(*tmp))          strcpy(tmp, "1");        if (strcmp("0", tmp) == 0)        {          printf("Exiting...\n");          fflush(stdout);          exit(0);        }        i = atoi(tmp);        if (i < 1 || i > m)        {          printf("Invalid selection.\n");          fflush(stdout);          sleep(1);          continue;        }                if (i != m)          getsubparam_delim(value, i, tmp, sizeof(tmp), '|');        else        {          printf("Enter value: ");          fflush(stdout);          if ((n = read(STDIN_FILENO, tmp, sizeof(tmp) -1)) > 0)            tmp[n] = 0;          else            *tmp = 0;          cut_ctrl(tmp);          cutspaces(tmp);          if (!(*tmp))          {            printf("Empty value is not enough.\n");            fflush(stdout);            sleep(1);            continue;          }        }        strcpy(value, tmp);        break;      }    }  }  return value;}int readcfg(){  FILE* File;  char devices_list[256];  char name[32];  char value[PATH_MAX];  char tmp[PATH_MAX];  char device_name[32];  int result;  int j, q;  char *p;  int device;  *devices_list = 0;  File=fopen(configfile,"r");  if (File)  {    /* read global parameter */    // 3.1beta7: all errors are reported, not just the first one.    //result=my_getline(File,name,sizeof(name),value,sizeof(value));    //while (result==1)    while ((result = my_getline(File, name, sizeof(name), value, sizeof(value))) != 0)    {      if (result == -1)      {        startuperror("Syntax Error in config file: %s\n", value);        continue;      }      if (strcasecmp(name,"devices")==0)        strcpy2(devices_list, ask_value(0, name, value));      else      if (strcasecmp(name,"spool")==0)        strcpy2(d_spool, ask_value(0, name, value));      else      if (strcasecmp(name,"outgoing")==0)        strcpy2(d_spool, ask_value(0, name, value));      else      if (strcasecmp(name,"stats")==0)        strcpy2(d_stats, ask_value(0, name, value));      else      if (strcasecmp(name,"failed")==0)        strcpy2(d_failed, ask_value(0, name, value));      else      if (strcasecmp(name,"incoming")==0)        strcpy2(d_incoming, ask_value(0, name, value));      else      if (strcasecmp(name,"report")==0)        strcpy2(d_report, ask_value(0, name, value));      else      if (strcasecmp(name,"phonecalls")==0)        strcpy2(d_phonecalls, ask_value(0, name, value));      else      if (strcasecmp(name,"saved")==0)        strcpy2(d_saved, ask_value(0, name, value));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -