/[radius]/radius/lib/dict.c
ViewVC logotype

Diff of /radius/lib/dict.c

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

revision 1.14 by gray, Tue Jul 29 10:17:06 2003 UTC revision 1.15 by gray, Tue Oct 14 07:10:42 2003 UTC
# Line 76  dict_free() Line 76  dict_free()
76  }  }
77    
78  static int  static int
79  nfields(int fc, int minf, int maxf, char *file, int lineno)  nfields(int fc, int minf, int maxf, LOCUS *loc)
80  {  {
81          if (fc < minf) {          if (fc < minf) {
82                  radlog(L_ERR, "%s:%d: %s", file, lineno, _("too few fields"));                  radlog_loc(L_ERR, loc, "%s", _("too few fields"));
83                  return -1;                  return -1;
84          } else if (fc > maxf) {          } else if (fc > maxf) {
85                  radlog(L_ERR, "%s:%d: %s", file, lineno, _("too many fields"));                  radlog_loc(L_ERR, loc, "%s", _("too many fields"));
86                  return -1;                  return -1;
87          }          }
88          return 0;          return 0;
# Line 159  dict_register_parser(int attr, attr_pars Line 159  dict_register_parser(int attr, attr_pars
159  #define VENDOR_NAME  fv[1]  #define VENDOR_NAME  fv[1]
160  #define VENDOR_VALUE fv[2]  #define VENDOR_VALUE fv[2]
161    
162  static int _dict_include(int *, int, char **, char *, int);  static int _dict_include(int *, int, char **, LOCUS *);
163  static int _dict_attribute(int *, int, char **, char *, int);  static int _dict_attribute(int *, int, char **, LOCUS *);
164  static int _dict_value(int *, int, char **, char *, int);  static int _dict_value(int *, int, char **, LOCUS *);
165  static int _dict_vendor(int *, int, char **, char *, int);  static int _dict_vendor(int *, int, char **, LOCUS *);
166  static int parse_dict_entry(int *, int, char **, char *, int);  static int parse_dict_entry(void *, int, char **, LOCUS *);
167  static int parse_dict(char *name);  static int parse_dict(char *name);
168    
169  static struct keyword type_kw[] = {  static struct keyword type_kw[] = {
# Line 175  static struct keyword type_kw[] = { Line 175  static struct keyword type_kw[] = {
175    
176  /*ARGSUSED*/  /*ARGSUSED*/
177  int  int
178  _dict_include(int *errcnt, int fc, char **fv, char *file, int lineno)  _dict_include(int *errcnt, int fc, char **fv, LOCUS *loc)
179  {  {
180          if (nfields(fc, 2, 2, file, lineno))          if (nfields(fc, 2, 2, loc))
181                  return 0;                  return 0;
182          parse_dict(fv[1]);          parse_dict(fv[1]);
183          return 0;          return 0;
184  }  }
185    
186  int  int
187  parse_flags(char **ptr, int *flags, char *filename, int line)  parse_flags(char **ptr, int *flags, LOCUS *loc)
188  {  {
189          int i;          int i;
190          char *p;          char *p;
191                    
192          for (p = *ptr+1, i = 0; i < CF_MAX; i++) {          for (p = *ptr+1, i = 0; i < CF_MAX; i++) {
193                  if (*p == 0) {                  if (*p == 0) {
194                          radlog(L_ERR,                          radlog_loc(L_ERR, loc, _("missing ]"), *p);
                                _("%s:%d: missing ]"),  
                                filename, line, *p);  
195                          return 1;                          return 1;
196                  }                  }
197                  switch (*p++) {                  switch (*p++) {
# Line 208  parse_flags(char **ptr, int *flags, char Line 206  parse_flags(char **ptr, int *flags, char
206                          p--;                          p--;
207                          goto stop;                          goto stop;
208                  default:                  default:
209                          radlog(L_ERR,                          radlog_loc(L_ERR, loc,
210                                 _("%s:%d: invalid syntax flag %c"),                                     _("invalid syntax flag %c"),
211                                 filename, line, p[-1]);                                     p[-1]);
212                          return 1;                          return 1;
213                  }                  }
214                  switch (*p++) {                  switch (*p++) {
# Line 221  parse_flags(char **ptr, int *flags, char Line 219  parse_flags(char **ptr, int *flags, char
219                          *flags &= ~AF_RHS(i);                          *flags &= ~AF_RHS(i);
220                          break;                          break;
221                  default:                  default:
222                          radlog(L_ERR,                          radlog_loc(L_ERR, loc,
223                                 _("%s:%d: invalid syntax flag %c"),                                     _("invalid syntax flag %c"),
224                                 filename, line, p[-1]);                                     p[-1]);
225                          return 1;                          return 1;
226                  }                  }
227          }          }
# Line 235  parse_flags(char **ptr, int *flags, char Line 233  parse_flags(char **ptr, int *flags, char
233  }  }
234    
235  int  int
236  _dict_attribute(int *errcnt, int fc, char **fv, char *file, int lineno)  _dict_attribute(int *errcnt, int fc, char **fv, LOCUS *loc)
237  {  {
238          DICT_ATTR *attr;          DICT_ATTR *attr;
239          int type;          int type;
# Line 246  _dict_attribute(int *errcnt, int fc, cha Line 244  _dict_attribute(int *errcnt, int fc, cha
244          int prop  = AP_DEFAULT_ADD;          int prop  = AP_DEFAULT_ADD;
245          attr_parser_fp fp = NULL;          attr_parser_fp fp = NULL;
246                    
247          if (nfields(fc, 4, 6, file, lineno))          if (nfields(fc, 4, 6, loc))
248                  return 0;                  return 0;
249          /*          /*
250           * Validate all entries           * Validate all entries
# Line 254  _dict_attribute(int *errcnt, int fc, cha Line 252  _dict_attribute(int *errcnt, int fc, cha
252                    
253          value = strtol(ATTR_VALUE, &p, 0);          value = strtol(ATTR_VALUE, &p, 0);
254          if (*p) {          if (*p) {
255                  radlog(L_ERR,                  radlog_loc(L_ERR, loc,
256                         _("%s:%d: value not a number (near %s)"),                             _("value not a number (near %s)"),
257                         file, lineno, p);                             p);
258                  (*errcnt)++;                  (*errcnt)++;
259                  return 0;                  return 0;
260          }          }
# Line 265  _dict_attribute(int *errcnt, int fc, cha Line 263  _dict_attribute(int *errcnt, int fc, cha
263                  type = TYPE_STRING;                  type = TYPE_STRING;
264                  fp = dict_find_parser(value);                  fp = dict_find_parser(value);
265                  if (!fp) {                  if (!fp) {
266                          radlog(L_WARN,                          radlog_loc(L_WARN, loc,
267                         _("%s:%d: no parser registered for this attribute"),                                _("no parser registered for this attribute"));
                                file, lineno);  
268                          return 0;                          return 0;
269                  }                  }
270          } else          } else
271                  type = xlat_keyword(type_kw, ATTR_TYPE, TYPE_INVALID);                  type = xlat_keyword(type_kw, ATTR_TYPE, TYPE_INVALID);
272                    
273          if (type == TYPE_INVALID) {          if (type == TYPE_INVALID) {
274                  radlog(L_ERR,                  radlog_loc(L_ERR, loc,
275                         "%s:%d: %s",                             "%s",
276                         file, lineno,                             _("invalid type"));
                        _("invalid type"));  
277                  (*errcnt)++;                  (*errcnt)++;
278                  return 0;                  return 0;
279          }          }
280    
281          if (HAS_VENDOR(fc, fv)) {          if (HAS_VENDOR(fc, fv)) {
282                  if ((vendor = vendor_name_to_id(ATTR_VENDOR)) == 0) {                  if ((vendor = vendor_name_to_id(ATTR_VENDOR)) == 0) {
283                          radlog(L_ERR,                          radlog_loc(L_ERR, loc, _("unknown vendor"));
284                                 _("%s:%d: unknown vendor"),                          (*errcnt)++;
                                file, lineno);  
                         (*errcnt)++;  
285                          return 0;                          return 0;
286                  }                  }
287          }          }
# Line 309  _dict_attribute(int *errcnt, int fc, cha Line 303  _dict_attribute(int *errcnt, int fc, cha
303                                          |AF_RHS(CF_HUNTGROUPS);                                          |AF_RHS(CF_HUNTGROUPS);
304                                  break;                                  break;
305                          case '[':                          case '[':
306                                  if (parse_flags(&p, &flags, file, lineno)) {                                  if (parse_flags(&p, &flags, loc)) {
307                                          while (*++p);                                          while (*++p);
308                                          --p;                                          --p;
309                                          ++(*errcnt);                                          ++(*errcnt);
# Line 345  _dict_attribute(int *errcnt, int fc, cha Line 339  _dict_attribute(int *errcnt, int fc, cha
339                                  prop |= AP_BINARY_STRING;                                  prop |= AP_BINARY_STRING;
340                                  break;                                  break;
341                          default:                          default:
342                                  radlog(L_ERR,                                  radlog_loc(L_ERR, loc,
343                                         _("%s:%d: invalid flag %c"),                                             _("invalid flag %c"),
344                                         file, lineno, *p);                                             *p);
345                                  (*errcnt)++;                                  (*errcnt)++;
346                                  return 0;                                  return 0;
347                          }                          }
# Line 369  _dict_attribute(int *errcnt, int fc, cha Line 363  _dict_attribute(int *errcnt, int fc, cha
363  }  }
364    
365  int  int
366  _dict_value(int *errcnt, int fc, char **fv, char *file, int lineno)  _dict_value(int *errcnt, int fc, char **fv, LOCUS *loc)
367  {  {
368          DICT_VALUE *dval;          DICT_VALUE *dval;
369          DICT_ATTR *attr;          DICT_ATTR *attr;
370          char *p;          char *p;
371          int value;          int value;
372                    
373          if (nfields(fc, 4, 4, file, lineno))          if (nfields(fc, 4, 4, loc))
374                  return 0;                  return 0;
375    
376          value = strtol(VALUE_NUM, &p, 0);          value = strtol(VALUE_NUM, &p, 0);
377          if (*p) {          if (*p) {
378                  radlog(L_ERR,                  radlog_loc(L_ERR, loc,
379                         _("%s:%d: value not a number (near %s)"),                             _("value not a number (near %s)"),
380                         file, lineno, p);                             p);
381                  (*errcnt)++;                  (*errcnt)++;
382                  return 0;                  return 0;
383          }          }
# Line 406  _dict_value(int *errcnt, int fc, char ** Line 400  _dict_value(int *errcnt, int fc, char **
400  }  }
401    
402  int  int
403  _dict_vendor(int *errcnt, int fc, char **fv, char *file, int lineno)  _dict_vendor(int *errcnt, int fc, char **fv, LOCUS *loc)
404  {  {
405          int value;          int value;
406          char *p;          char *p;
407    
408          if (nfields(fc, 3, 3, file, lineno))          if (nfields(fc, 3, 3, loc))
409                  return 0;                  return 0;
410    
411          value = strtol(VENDOR_VALUE, &p, 0);          value = strtol(VENDOR_VALUE, &p, 0);
412          if (*p) {          if (*p) {
413                  radlog(L_ERR,                  radlog_loc(L_ERR, loc,
414                         _("%s:%d: value not a number (near %s)"),                             _("value not a number (near %s)"),
415                         file, lineno, p);                             p);
416                  (*errcnt)++;                  (*errcnt)++;
417                  return 0;                  return 0;
418          }          }
# Line 447  static struct keyword dict_kw[] = { Line 441  static struct keyword dict_kw[] = {
441  };  };
442    
443  int  int
444  parse_dict_entry(int *errcnt, int fc, char **fv, char *file, int lineno)  parse_dict_entry(void *closure, int fc, char **fv, LOCUS *loc)
445  {  {
446            int *errcnt = closure;
447          switch (xlat_keyword(dict_kw, KEYWORD, -1)) {          switch (xlat_keyword(dict_kw, KEYWORD, -1)) {
448          case KW_INCLUDE:          case KW_INCLUDE:
449                  _dict_include(errcnt, fc, fv, file, lineno);                  _dict_include(errcnt, fc, fv, loc);
450                  break;                  break;
451          case KW_ATTRIBUTE:          case KW_ATTRIBUTE:
452                  _dict_attribute(errcnt, fc, fv, file, lineno);                  _dict_attribute(errcnt, fc, fv, loc);
453                  break;                  break;
454          case KW_VALUE:          case KW_VALUE:
455                  _dict_value(errcnt, fc, fv, file, lineno);                  _dict_value(errcnt, fc, fv, loc);
456                  break;                  break;
457          case KW_VENDOR:          case KW_VENDOR:
458                  _dict_vendor(errcnt, fc, fv, file, lineno);                  _dict_vendor(errcnt, fc, fv, loc);
459                  break;                  break;
460          default:          default:
461                  radlog(L_ERR,                  radlog_loc(L_ERR, loc, "%s", _("unknown keyword"));
                        "%s:%d: %s",  
                        file, lineno,  
                        _("unknown keyword"));  
462                  break;                  break;
463          }          }
464          return 0;          return 0;

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26