29 |
#include <fcntl.h> |
#include <fcntl.h> |
30 |
#include <errno.h> |
#include <errno.h> |
31 |
#include <unistd.h> |
#include <unistd.h> |
32 |
|
#include <stdlib.h> |
33 |
|
#include <ctype.h> |
34 |
|
|
35 |
#include <radiusd.h> |
#include <radiusd.h> |
36 |
#include <obstack1.h> |
#include <obstack1.h> |
37 |
#include <cfg.h> |
#include <cfg.h> |
54 |
static void _cfg_run_begin(struct cfg_stmt *stmt, void *up_data); |
static void _cfg_run_begin(struct cfg_stmt *stmt, void *up_data); |
55 |
|
|
56 |
static int yylex(); |
static int yylex(); |
57 |
|
static int yyerror(char *s); |
58 |
|
|
59 |
static char *typestr[] = { |
static char *typestr[] = { |
60 |
"integer", |
"integer", |
61 |
"boolean", |
"boolean", |
298 |
|
|
299 |
%% |
%% |
300 |
|
|
301 |
static void skipws(); |
static void |
|
static void skipline(); |
|
|
static void skipstmt(); |
|
|
static int isword(int c); |
|
|
static char *copy_alpha(); |
|
|
static char *copy_string(); |
|
|
static int copy_digit(); |
|
|
|
|
|
static void putback(char *tok, int length); |
|
|
|
|
|
|
|
|
#define ismath(c) (strchr("=!+-/*.", c)!=NULL) |
|
|
|
|
|
int |
|
|
yylex() |
|
|
{ |
|
|
again: |
|
|
skipws(); |
|
|
|
|
|
if (*curp == '#') { |
|
|
skipline(); |
|
|
goto again; |
|
|
} |
|
|
if (*curp == '/' && curp[1] == '*') { |
|
|
int keep_line = cfg_line_num; |
|
|
|
|
|
curp += 2; |
|
|
do { |
|
|
while (*curp != '*') { |
|
|
if (*curp == 0) { |
|
|
radlog(L_ERR, |
|
|
_("%s:%d: unexpected EOF in comment started at line %d"), |
|
|
cfg_filename, cfg_line_num, keep_line); |
|
|
return 0; |
|
|
} else if (*curp == '\n') |
|
|
cfg_line_num++; |
|
|
++curp; |
|
|
} |
|
|
} while (*++curp != '/'); |
|
|
++curp; |
|
|
goto again; |
|
|
} |
|
|
|
|
|
if (*curp == 0) |
|
|
return 0; |
|
|
|
|
|
if (isalpha(*curp)) { |
|
|
yylval.string = copy_alpha(); |
|
|
return keyword(); |
|
|
} |
|
|
|
|
|
if (*curp == '\"') { |
|
|
yylval.string = copy_string(); |
|
|
return T_STRING; |
|
|
} |
|
|
|
|
|
if (isdigit(*curp)) { |
|
|
if (copy_digit()) { |
|
|
/* IP address */ |
|
|
yylval.ipaddr = ip_strtoip(yylval.string); |
|
|
return T_IPADDR; |
|
|
} |
|
|
yylval.number = strtol(yylval.string, NULL, 0); |
|
|
return T_NUMBER; |
|
|
} |
|
|
|
|
|
if (*curp == ';') { |
|
|
curp++; |
|
|
return T_EOL; |
|
|
} |
|
|
|
|
|
if (ismath(*curp)) { |
|
|
yylval.number = *curp++; |
|
|
return T_PUNCT; |
|
|
} |
|
|
return *curp++; |
|
|
} |
|
|
|
|
|
void |
|
|
putback(char *tok, int length) |
|
|
{ |
|
|
if (length > curp - buffer) { |
|
|
radlog(L_CRIT, |
|
|
_("INTERNAL ERROR parsing %s near %d: out of putback space"), |
|
|
cfg_filename, cfg_line_num); |
|
|
return; |
|
|
} |
|
|
while (length--) |
|
|
*--curp = tok[length]; |
|
|
} |
|
|
|
|
|
void |
|
302 |
skipws() |
skipws() |
303 |
{ |
{ |
304 |
while (*curp && isspace(*curp)) { |
while (*curp && isspace(*curp)) { |
308 |
} |
} |
309 |
} |
} |
310 |
|
|
311 |
void |
static void |
312 |
skipline() |
skipline() |
313 |
{ |
{ |
314 |
while (*curp && *curp != '\n') |
while (*curp && *curp != '\n') |
315 |
curp++; |
curp++; |
316 |
} |
} |
317 |
|
|
318 |
int |
static int |
319 |
isword(int c) |
isword(int c) |
320 |
{ |
{ |
321 |
return isalnum(c) || c == '_' || c == '-'; |
return isalnum(c) || c == '_' || c == '-'; |
322 |
} |
} |
323 |
|
|
324 |
char * |
static char * |
325 |
copy_alpha() |
copy_alpha() |
326 |
{ |
{ |
327 |
do { |
do { |
332 |
return obstack_finish(&cfg_obstack); |
return obstack_finish(&cfg_obstack); |
333 |
} |
} |
334 |
|
|
335 |
char * |
static char * |
336 |
copy_string() |
copy_string() |
337 |
{ |
{ |
338 |
int quote = *curp++; |
int quote = *curp++; |
349 |
return obstack_finish(&cfg_obstack); |
return obstack_finish(&cfg_obstack); |
350 |
} |
} |
351 |
|
|
352 |
int |
static int |
353 |
copy_digit() |
copy_digit() |
354 |
{ |
{ |
355 |
int dot = 0; |
int dot = 0; |
378 |
{ "off", 0 }, |
{ "off", 0 }, |
379 |
{ "yes", 1 }, |
{ "yes", 1 }, |
380 |
{ "no", 0 }, |
{ "no", 0 }, |
381 |
0 |
{ 0 } |
382 |
}; |
}; |
383 |
|
|
384 |
int |
static int |
385 |
keyword() |
keyword() |
386 |
{ |
{ |
387 |
int tok; |
int tok; |
393 |
return T_WORD; |
return T_WORD; |
394 |
} |
} |
395 |
|
|
396 |
|
#define ismath(c) (strchr("=!+-/*.", c)!=NULL) |
397 |
|
|
398 |
|
static int |
399 |
|
yylex() |
400 |
|
{ |
401 |
|
again: |
402 |
|
skipws(); |
403 |
|
|
404 |
int |
if (*curp == '#') { |
405 |
|
skipline(); |
406 |
|
goto again; |
407 |
|
} |
408 |
|
if (*curp == '/' && curp[1] == '*') { |
409 |
|
int keep_line = cfg_line_num; |
410 |
|
|
411 |
|
curp += 2; |
412 |
|
do { |
413 |
|
while (*curp != '*') { |
414 |
|
if (*curp == 0) { |
415 |
|
radlog(L_ERR, |
416 |
|
_("%s:%d: unexpected EOF in comment started at line %d"), |
417 |
|
cfg_filename, cfg_line_num, keep_line); |
418 |
|
return 0; |
419 |
|
} else if (*curp == '\n') |
420 |
|
cfg_line_num++; |
421 |
|
++curp; |
422 |
|
} |
423 |
|
} while (*++curp != '/'); |
424 |
|
++curp; |
425 |
|
goto again; |
426 |
|
} |
427 |
|
|
428 |
|
if (*curp == 0) |
429 |
|
return 0; |
430 |
|
|
431 |
|
if (isalpha(*curp)) { |
432 |
|
yylval.string = copy_alpha(); |
433 |
|
return keyword(); |
434 |
|
} |
435 |
|
|
436 |
|
if (*curp == '\"') { |
437 |
|
yylval.string = copy_string(); |
438 |
|
return T_STRING; |
439 |
|
} |
440 |
|
|
441 |
|
if (isdigit(*curp)) { |
442 |
|
if (copy_digit()) { |
443 |
|
/* IP address */ |
444 |
|
yylval.ipaddr = ip_strtoip(yylval.string); |
445 |
|
return T_IPADDR; |
446 |
|
} |
447 |
|
yylval.number = strtol(yylval.string, NULL, 0); |
448 |
|
return T_NUMBER; |
449 |
|
} |
450 |
|
|
451 |
|
if (*curp == ';') { |
452 |
|
curp++; |
453 |
|
return T_EOL; |
454 |
|
} |
455 |
|
|
456 |
|
if (ismath(*curp)) { |
457 |
|
yylval.number = *curp++; |
458 |
|
return T_PUNCT; |
459 |
|
} |
460 |
|
return *curp++; |
461 |
|
} |
462 |
|
|
463 |
|
static int |
464 |
yyerror(char *s) |
yyerror(char *s) |
465 |
{ |
{ |
466 |
radlog(L_ERR, "%s:%d: %s", cfg_filename, cfg_line_num, s); |
radlog(L_ERR, "%s:%d: %s", cfg_filename, cfg_line_num, s); |
558 |
LIST * |
LIST * |
559 |
_cfg_vlist_create(cfg_value_t *val) |
_cfg_vlist_create(cfg_value_t *val) |
560 |
{ |
{ |
|
cfg_value_t *vp; |
|
561 |
LIST *vlist = list_create(); |
LIST *vlist = list_create(); |
562 |
LIST **lp = cfg_malloc(sizeof(*lp), _cfg_vlist_destroy); |
LIST **lp = cfg_malloc(sizeof(*lp), _cfg_vlist_destroy); |
563 |
*lp = vlist; |
*lp = vlist; |