/[imapfilter]/imapfilter/file.c
ViewVC logotype

Diff of /imapfilter/file.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by lefcha, Thu Aug 23 19:13:15 2001 UTC revision 1.7 by lefcha, Fri Aug 24 17:42:49 2001 UTC
# Line 47  int read_config(char *cfg) Line 47  int read_config(char *cfg)
47      fp = fopen(cfg, "r");      fp = fopen(cfg, "r");
48    
49      if (!fp) {      if (!fp) {
50          fprintf(stderr, "imapfilter: Could not open config file %s; %s\n",          fprintf(stderr, "imapfilter: opening config file %s; %s\n",
51                  cfg, strerror(errno));                  cfg, strerror(errno));
52          return FAILURE;          return FAILURE;
53      }      }
# Line 68  int parse_config(FILE * fp) Line 68  int parse_config(FILE * fp)
68      int i;      int i;
69      unsigned int row = 0;      unsigned int row = 0;
70      char line[LINE_MAX];      char line[LINE_MAX];
71      regex_t comreg[5];      regex_t compexp[5];
72      regmatch_t match[4];      regmatch_t match[4];
73      const char *reg[5] = {      const char *reg[5] = {
74          "^[[:blank:]]*(SERVER|PORT|USERNAME|PASSWORD|LOGFILE)[[:blank:]]*=[[:blank:]]*([[:graph:]]*)[[:blank:]]*",          "^[[:blank:]]*(SERVER|PORT|USERNAME|PASSWORD|LOGFILE)[[:blank:]]*=[[:blank:]]*([[:graph:]]*)[[:blank:]]*",
# Line 79  int parse_config(FILE * fp) Line 79  int parse_config(FILE * fp)
79      };      };
80    
81      for (i = 0; i < 5; i++)      for (i = 0; i < 5; i++)
82          regcomp(&comreg[i], reg[i], REG_EXTENDED);          regcomp(&compexp[i], reg[i], REG_EXTENDED);
83    
84      while (fgets(line, LINE_MAX - 1, fp)) {      while (fgets(line, LINE_MAX - 1, fp)) {
85          row++;          row++;
86          if (!regexec(&comreg[0], line, 3, match, 0)) {          if (!regexec(&compexp[0], line, 3, match, 0)) {
87              set_account(line, match);              set_account(line, match);
88              continue;              continue;
89          } else if (!regexec(&comreg[1], line, 4, match, 0)) {          } else if (!regexec(&compexp[1], line, 4, match, 0)) {
90              standard_filter(line, match);              standard_filter(line, match);
91              continue;              continue;
92          } else if (!regexec(&comreg[2], line, 4, match, 0)) {          } else if (!regexec(&compexp[2], line, 4, match, 0)) {
93              custom_filter(line, match);              custom_filter(line, match);
94              continue;              continue;
95          } else if (!regexec(&comreg[3], line, 3, match, 0)) {          } else if (!regexec(&compexp[3], line, 3, match, 0)) {
96              set_limits(line, match);              set_limits(line, match);
97              continue;              continue;
98          } else if (!regexec(&comreg[4], line, 1, match, 0))          } else if (!regexec(&compexp[4], line, 1, match, 0))
99              continue;              continue;
100          else {          else {
101              fprintf(stderr,              fprintf(stderr,
# Line 159  void set_account(char *line, regmatch_t Line 159  void set_account(char *line, regmatch_t
159          strncpy(accounts[acccnt]->server, line + match[2].rm_so, s);          strncpy(accounts[acccnt]->server, line + match[2].rm_so, s);
160          accounts[acccnt]->server[s] = 0;          accounts[acccnt]->server[s] = 0;
161  #ifdef DEBUG  #ifdef DEBUG
162  printf("debug: account setting SERVER: '%s'\n", accounts[acccnt]->server);          printf("debug: account setting SERVER: '%s'\n",
163                   accounts[acccnt]->server);
164  #endif  #endif
165      } else if (acccnt >= 0) {      } else if (acccnt >= 0) {
166          if (!strncmp(line + match[1].rm_so, "PORT", 4)) {          if (!strncmp(line + match[1].rm_so, "PORT", 4)) {
# Line 168  printf("debug: account setting SERVER: ' Line 169  printf("debug: account setting SERVER: '
169              port[s] = 0;              port[s] = 0;
170              accounts[acccnt]->port = strtoul(port, NULL, 0);              accounts[acccnt]->port = strtoul(port, NULL, 0);
171  #ifdef DEBUG  #ifdef DEBUG
172  printf("debug: account setting PORT: '%d'\n", accounts[acccnt]->port);              printf("debug: account setting PORT: '%d'\n",
173  #endif                           accounts[acccnt]->port);
174    #endif
175          } else if (!strncmp(line + match[1].rm_so, "USERNAME", 8)) {          } else if (!strncmp(line + match[1].rm_so, "USERNAME", 8)) {
176              s = min((match[2].rm_eo - match[2].rm_so), USERNAME_MAX - 1);              s = min((match[2].rm_eo - match[2].rm_so), USERNAME_MAX - 1);
177              strncpy(accounts[acccnt]->username, line + match[2].rm_so, s);              strncpy(accounts[acccnt]->username, line + match[2].rm_so, s);
178              accounts[acccnt]->username[s] = 0;              accounts[acccnt]->username[s] = 0;
179  #ifdef DEBUG  #ifdef DEBUG
180  printf("debug: account setting USERNAME: '%s'\n", accounts[acccnt]->username);              printf("debug: account setting USERNAME: '%s'\n",
181  #endif                           accounts[acccnt]->username);
182    #endif
183          } else if (!strncmp(line + match[1].rm_so, "PASSWORD", 8)) {          } else if (!strncmp(line + match[1].rm_so, "PASSWORD", 8)) {
184              s = min((match[2].rm_eo - match[2].rm_so), PASSWORD_MAX - 1);              s = min((match[2].rm_eo - match[2].rm_so), PASSWORD_MAX - 1);
185              strncpy(accounts[acccnt]->password, line + match[2].rm_so, s);              strncpy(accounts[acccnt]->password, line + match[2].rm_so, s);
186              accounts[acccnt]->password[s] = 0;              accounts[acccnt]->password[s] = 0;
187  #ifdef DEBUG  #ifdef DEBUG
188  printf("debug: account setting PASSWORD: '%s'\n", accounts[acccnt]->password);              printf("debug: account setting PASSWORD: '%s'\n",
189                       accounts[acccnt]->password);
190  #endif  #endif
191          } else if (!strncmp(line + match[1].rm_so, "LOGFILE", 7)) {          } else if (!strncmp(line + match[1].rm_so, "LOGFILE", 7)) {
192              s = min((match[2].rm_eo - match[2].rm_so), PATH_MAX - 1);              s = min((match[2].rm_eo - match[2].rm_so), PATH_MAX - 1);

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26