• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/bind9-45.101/bind9/lib/isccfg/

Lines Matching refs:pctx

49 #define TOKEN_STRING(pctx) (pctx->token.value.as_textregion.base)
59 do { if ((obj) != NULL) cfg_obj_destroy(pctx, &(obj)); } while (0)
67 free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj);
70 parse_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
73 print_list(cfg_printer_t *pctx, const cfg_obj_t *obj);
76 free_list(cfg_parser_t *pctx, cfg_obj_t *obj);
79 create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp);
82 create_string(cfg_parser_t *pctx, const char *contents, const cfg_type_t *type,
86 free_string(cfg_parser_t *pctx, cfg_obj_t *obj);
89 create_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **objp);
92 free_map(cfg_parser_t *pctx, cfg_obj_t *obj);
95 parse_symtab_elt(cfg_parser_t *pctx, const char *name,
100 free_noop(cfg_parser_t *pctx, cfg_obj_t *obj);
103 cfg_getstringtoken(cfg_parser_t *pctx);
106 parser_complain(cfg_parser_t *pctx, isc_boolean_t is_warning,
139 cfg_print_obj(cfg_printer_t *pctx, const cfg_obj_t *obj) {
140 obj->type->print(pctx, obj);
144 cfg_print_chars(cfg_printer_t *pctx, const char *text, int len) {
145 pctx->f(pctx->closure, text, len);
149 print_open(cfg_printer_t *pctx) {
150 cfg_print_chars(pctx, "{\n", 2);
151 pctx->indent++;
155 print_indent(cfg_printer_t *pctx) {
156 int indent = pctx->indent;
158 cfg_print_chars(pctx, "\t", 1);
164 print_close(cfg_printer_t *pctx) {
165 pctx->indent--;
166 print_indent(pctx);
167 cfg_print_chars(pctx, "}", 1);
171 cfg_parse_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
174 result = type->parse(pctx, type, ret);
186 cfg_printer_t pctx;
187 pctx.f = f;
188 pctx.closure = closure;
189 pctx.indent = 0;
190 obj->type->print(&pctx, obj);
197 cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
208 CHECK(cfg_create_obj(pctx, type, &obj));
209 obj->value.tuple = isc_mem_get(pctx->mctx,
222 isc_mem_put(pctx->mctx, obj, sizeof(*obj));
227 cfg_parse_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
235 CHECK(cfg_create_tuple(pctx, type, &obj));
237 CHECK(cfg_parse_obj(pctx, f->type, &obj->value.tuple[i]));
248 cfg_print_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj) {
257 cfg_print_chars(pctx, " ", 1);
258 cfg_print_obj(pctx, fieldobj);
264 cfg_doc_tuple(cfg_printer_t *pctx, const cfg_type_t *type) {
271 cfg_print_chars(pctx, " ", 1);
272 cfg_doc_obj(pctx, f->type);
278 free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj) {
291 isc_mem_put(pctx->mctx, obj->value.tuple,
337 cfg_parse_special(cfg_parser_t *pctx, int special) {
339 CHECK(cfg_gettoken(pctx, 0));
340 if (pctx->token.type == isc_tokentype_special &&
341 pctx->token.value.as_char == special)
344 cfg_parser_error(pctx, CFG_LOG_NEAR, "'%c' expected", special);
358 parse_semicolon(cfg_parser_t *pctx) {
360 CHECK(cfg_gettoken(pctx, 0));
361 if (pctx->token.type == isc_tokentype_special &&
362 pctx->token.value.as_char == ';')
365 cfg_parser_error(pctx, CFG_LOG_BEFORE, "missing ';'");
366 cfg_ungettoken(pctx);
375 parse_eof(cfg_parser_t *pctx) {
377 CHECK(cfg_gettoken(pctx, 0));
379 if (pctx->token.type == isc_tokentype_eof)
382 cfg_parser_error(pctx, CFG_LOG_NEAR, "syntax error");
388 /* A list of files, used internally for pctx->files. */
398 cfg_parser_t *pctx;
404 pctx = isc_mem_get(mctx, sizeof(*pctx));
405 if (pctx == NULL)
408 result = isc_refcount_init(&pctx->references, 1);
410 isc_mem_put(mctx, pctx, sizeof(*pctx));
414 pctx->mctx = mctx;
415 pctx->lctx = lctx;
416 pctx->lexer = NULL;
417 pctx->seen_eof = ISC_FALSE;
418 pctx->ungotten = ISC_FALSE;
419 pctx->errors = 0;
420 pctx->warnings = 0;
421 pctx->open_files = NULL;
422 pctx->closed_files = NULL;
423 pctx->line = 0;
424 pctx->callback = NULL;
425 pctx->callbackarg = NULL;
426 pctx->token.type = isc_tokentype_unknown;
427 pctx->flags = 0;
437 CHECK(isc_lex_create(pctx->mctx, 1024, &pctx->lexer));
439 isc_lex_setspecials(pctx->lexer, specials);
440 isc_lex_setcomments(pctx->lexer, (ISC_LEXCOMMENT_C |
444 CHECK(cfg_create_list(pctx, &cfg_type_filelist, &pctx->open_files));
445 CHECK(cfg_create_list(pctx, &cfg_type_filelist, &pctx->closed_files));
447 *ret = pctx;
451 if (pctx->lexer != NULL)
452 isc_lex_destroy(&pctx->lexer);
453 CLEANUP_OBJ(pctx->open_files);
454 CLEANUP_OBJ(pctx->closed_files);
455 isc_mem_put(mctx, pctx, sizeof(*pctx));
460 parser_openfile(cfg_parser_t *pctx, const char *filename) {
465 result = isc_lex_openfile(pctx->lexer, filename);
467 cfg_parser_error(pctx, 0, "open: %s: %s",
472 CHECK(create_string(pctx, filename, &cfg_type_qstring, &stringobj));
473 CHECK(create_listelt(pctx, &elt));
475 ISC_LIST_APPEND(pctx->open_files->value.list, elt, link);
484 cfg_parser_setcallback(cfg_parser_t *pctx,
488 pctx->callback = callback;
489 pctx->callbackarg = arg;
493 * Parse a configuration using a pctx where a lexer has already
497 parse2(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
501 result = cfg_parse_obj(pctx, type, &obj);
503 if (pctx->errors != 0) {
512 cfg_parser_error(pctx, 0, "parsing failed");
516 CHECK(parse_eof(pctx));
527 cfg_parse_file(cfg_parser_t *pctx, const char *filename,
534 CHECK(parser_openfile(pctx, filename));
535 CHECK(parse2(pctx, type, ret));
542 cfg_parse_buffer(cfg_parser_t *pctx, isc_buffer_t *buffer,
547 CHECK(isc_lex_openbuffer(pctx->lexer, buffer));
548 CHECK(parse2(pctx, type, ret));
563 cfg_parser_t *pctx = *pctxp;
566 isc_refcount_decrement(&pctx->references, &refs);
568 isc_lex_destroy(&pctx->lexer);
574 CLEANUP_OBJ(pctx->open_files);
575 CLEANUP_OBJ(pctx->closed_files);
576 isc_mem_put(pctx->mctx, pctx, sizeof(*pctx));
585 cfg_parse_void(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
587 return (cfg_create_obj(pctx, &cfg_type_void, ret));
591 cfg_print_void(cfg_printer_t *pctx, const cfg_obj_t *obj) {
592 UNUSED(pctx);
597 cfg_doc_void(cfg_printer_t *pctx, const cfg_type_t *type) {
598 UNUSED(pctx);
617 cfg_parse_uint32(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
622 CHECK(cfg_gettoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
623 if (pctx->token.type != isc_tokentype_number) {
624 cfg_parser_error(pctx, CFG_LOG_NEAR, "expected number");
628 CHECK(cfg_create_obj(pctx, &cfg_type_uint32, &obj));
630 obj->value.uint32 = pctx->token.value.as_ulong;
637 cfg_print_cstr(cfg_printer_t *pctx, const char *s) {
638 cfg_print_chars(pctx, s, strlen(s));
642 cfg_print_rawuint(cfg_printer_t *pctx, unsigned int u) {
645 cfg_print_cstr(pctx, buf);
649 cfg_print_uint32(cfg_printer_t *pctx, const cfg_obj_t *obj) {
650 cfg_print_rawuint(pctx, obj->value.uint32);
687 cfg_print_uint64(cfg_printer_t *pctx, const cfg_obj_t *obj) {
691 cfg_print_cstr(pctx, buf);
706 create_string(cfg_parser_t *pctx, const char *contents, const cfg_type_t *type,
713 CHECK(cfg_create_obj(pctx, type, &obj));
716 obj->value.string.base = isc_mem_get(pctx->mctx, len + 1);
718 isc_mem_put(pctx->mctx, obj, sizeof(*obj));
730 cfg_create_string(cfg_parser_t *pctx, const char *contents, const cfg_type_t *type,
733 return create_string(pctx, contents, type, ret);
737 cfg_parse_qstring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
741 CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
742 if (pctx->token.type != isc_tokentype_qstring) {
743 cfg_parser_error(pctx, CFG_LOG_NEAR, "expected quoted string");
746 return (create_string(pctx,
747 TOKEN_STRING(pctx),
755 parse_ustring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
759 CHECK(cfg_gettoken(pctx, 0));
760 if (pctx->token.type != isc_tokentype_string) {
761 cfg_parser_error(pctx, CFG_LOG_NEAR, "expected unquoted string");
764 return (create_string(pctx,
765 TOKEN_STRING(pctx),
773 cfg_parse_astring(cfg_parser_t *pctx, const cfg_type_t *type,
779 CHECK(cfg_getstringtoken(pctx));
780 return (create_string(pctx,
781 TOKEN_STRING(pctx),
799 check_enum(cfg_parser_t *pctx, cfg_obj_t *obj, const char *const *enums) {
803 cfg_parser_error(pctx, 0, "'%s' unexpected", s);
808 cfg_parse_enum(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
811 CHECK(parse_ustring(pctx, NULL, &obj));
812 CHECK(check_enum(pctx, obj, type->of));
821 cfg_doc_enum(cfg_printer_t *pctx, const cfg_type_t *type) {
823 cfg_print_chars(pctx, "( ", 2);
825 cfg_print_cstr(pctx, *p);
827 cfg_print_chars(pctx, " | ", 3);
829 cfg_print_chars(pctx, " )", 2);
833 cfg_print_ustring(cfg_printer_t *pctx, const cfg_obj_t *obj) {
834 cfg_print_chars(pctx, obj->value.string.base, obj->value.string.length);
838 print_qstring(cfg_printer_t *pctx, const cfg_obj_t *obj) {
839 cfg_print_chars(pctx, "\"", 1);
840 cfg_print_ustring(pctx, obj);
841 cfg_print_chars(pctx, "\"", 1);
845 free_string(cfg_parser_t *pctx, cfg_obj_t *obj) {
846 isc_mem_put(pctx->mctx, obj->value.string.base,
897 cfg_parse_boolean(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
904 result = cfg_gettoken(pctx, 0);
908 if (pctx->token.type != isc_tokentype_string)
911 if ((strcasecmp(TOKEN_STRING(pctx), "true") == 0) ||
912 (strcasecmp(TOKEN_STRING(pctx), "yes") == 0) ||
913 (strcmp(TOKEN_STRING(pctx), "1") == 0)) {
915 } else if ((strcasecmp(TOKEN_STRING(pctx), "false") == 0) ||
916 (strcasecmp(TOKEN_STRING(pctx), "no") == 0) ||
917 (strcmp(TOKEN_STRING(pctx), "0") == 0)) {
923 CHECK(cfg_create_obj(pctx, &cfg_type_boolean, &obj));
929 cfg_parser_error(pctx, CFG_LOG_NEAR, "boolean expected");
937 cfg_print_boolean(cfg_printer_t *pctx, const cfg_obj_t *obj) {
939 cfg_print_chars(pctx, "yes", 3);
941 cfg_print_chars(pctx, "no", 2);
954 cfg_create_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **obj) {
956 CHECK(cfg_create_obj(pctx, type, obj));
963 create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) {
965 elt = isc_mem_get(pctx->mctx, sizeof(*elt));
975 cfg_create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp)
977 return create_listelt(pctx, eltp);
981 free_list_elt(cfg_parser_t *pctx, cfg_listelt_t *elt) {
983 cfg_obj_destroy(pctx, &elt->obj);
984 isc_mem_put(pctx->mctx, elt, sizeof(*elt));
988 cfg_destroy_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp)
990 free_list_elt(pctx, *eltp);
995 free_list(cfg_parser_t *pctx, cfg_obj_t *obj) {
1002 free_list_elt(pctx, elt);
1007 cfg_parse_listelt(cfg_parser_t *pctx, const cfg_type_t *elttype,
1014 CHECK(create_listelt(pctx, &elt));
1016 result = cfg_parse_obj(pctx, elttype, &value);
1026 isc_mem_put(pctx->mctx, elt, sizeof(*elt));
1035 parse_list(cfg_parser_t *pctx, const cfg_type_t *listtype, cfg_obj_t **ret)
1042 CHECK(cfg_create_list(pctx, listtype, &listobj));
1045 CHECK(cfg_peektoken(pctx, 0));
1046 if (pctx->token.type == isc_tokentype_special &&
1047 pctx->token.value.as_char == /*{*/ '}')
1049 CHECK(cfg_parse_listelt(pctx, listof, &elt));
1050 CHECK(parse_semicolon(pctx));
1059 free_list_elt(pctx, elt);
1065 print_list(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1072 print_indent(pctx);
1073 cfg_print_obj(pctx, elt->obj);
1074 cfg_print_chars(pctx, ";\n", 2);
1079 cfg_parse_bracketed_list(cfg_parser_t *pctx, const cfg_type_t *type,
1083 CHECK(cfg_parse_special(pctx, '{'));
1084 CHECK(parse_list(pctx, type, ret));
1085 CHECK(cfg_parse_special(pctx, '}'));
1091 cfg_print_bracketed_list(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1092 print_open(pctx);
1093 print_list(pctx, obj);
1094 print_close(pctx);
1098 cfg_doc_bracketed_list(cfg_printer_t *pctx, const cfg_type_t *type) {
1099 cfg_print_chars(pctx, "{ ", 2);
1100 cfg_doc_obj(pctx, type->of);
1101 cfg_print_chars(pctx, "; ... }", 7);
1110 cfg_parse_spacelist(cfg_parser_t *pctx, const cfg_type_t *listtype,
1117 CHECK(cfg_create_list(pctx, listtype, &listobj));
1122 CHECK(cfg_peektoken(pctx, 0));
1123 if (pctx->token.type == isc_tokentype_special &&
1124 pctx->token.value.as_char == ';')
1126 CHECK(cfg_parse_listelt(pctx, listof, &elt));
1138 cfg_print_spacelist(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1145 cfg_print_obj(pctx, elt->obj);
1147 cfg_print_chars(pctx, " ", 1);
1212 cfg_create_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1218 result = create_map(pctx, type, &mapobj);
1347 cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
1360 CHECK(create_map(pctx, type, &obj));
1371 CHECK(cfg_gettoken(pctx, 0));
1373 if (pctx->token.type != isc_tokentype_string) {
1374 cfg_ungettoken(pctx);
1382 if (strcasecmp(TOKEN_STRING(pctx), "include") == 0) {
1388 CHECK(cfg_parse_obj(pctx, &cfg_type_qstring, &includename));
1389 CHECK(parse_semicolon(pctx));
1390 CHECK(parser_openfile(pctx, includename->
1392 cfg_obj_destroy(pctx, &includename);
1401 if (strcasecmp(TOKEN_STRING(pctx),
1408 cfg_parser_error(pctx, CFG_LOG_NOPREP, "unknown option");
1413 CHECK(cfg_parse_obj(pctx, &cfg_type_unsupported, &eltobj));
1414 cfg_obj_destroy(pctx, &eltobj);
1415 CHECK(parse_semicolon(pctx));
1423 cfg_parser_warning(pctx, 0, "option '%s' is obsolete",
1426 cfg_parser_warning(pctx, 0, "option '%s' is "
1429 cfg_parser_warning(pctx, 0, "option '%s' is "
1433 cfg_parser_warning(pctx, 0, "option '%s' is not "
1453 CHECK(cfg_create_list(pctx,
1463 cfg_parser_error(pctx, CFG_LOG_NEAR,
1466 isc_mem_put(pctx->mctx, list,
1476 CHECK(cfg_parse_listelt(pctx, clause->type, &elt));
1477 CHECK(parse_semicolon(pctx));
1486 CHECK(parse_symtab_elt(pctx, clause->name,
1490 CHECK(parse_semicolon(pctx));
1492 cfg_parser_error(pctx, CFG_LOG_NEAR, "'%s' redefined",
1497 cfg_parser_error(pctx, CFG_LOG_NEAR,
1517 parse_symtab_elt(cfg_parser_t *pctx, const char *name,
1525 CHECK(cfg_parse_obj(pctx, elttype, &obj));
1527 if (callback && pctx->callback != NULL)
1528 CHECK(pctx->callback(name, obj, pctx->callbackarg));
1545 cfg_parse_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1547 CHECK(cfg_parse_special(pctx, '{'));
1548 CHECK(cfg_parse_mapbody(pctx, type, ret));
1549 CHECK(cfg_parse_special(pctx, '}'));
1558 parse_any_named_map(cfg_parser_t *pctx, cfg_type_t *nametype, const cfg_type_t *type,
1565 CHECK(cfg_parse_obj(pctx, nametype, &idobj));
1566 CHECK(cfg_parse_map(pctx, type, &mapobj));
1580 cfg_parse_named_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1581 return (parse_any_named_map(pctx, &cfg_type_astring, type, ret));
1589 cfg_parse_addressed_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1590 return (parse_any_named_map(pctx, &cfg_type_netaddr, type, ret));
1598 cfg_parse_netprefix_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1599 return (parse_any_named_map(pctx, &cfg_type_netprefix, type, ret));
1603 cfg_print_mapbody(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1629 print_indent(pctx);
1630 cfg_print_cstr(pctx, clause->name);
1631 cfg_print_chars(pctx, " ", 1);
1632 cfg_print_obj(pctx, elt->obj);
1633 cfg_print_chars(pctx, ";\n", 2);
1637 print_indent(pctx);
1638 cfg_print_cstr(pctx, clause->name);
1639 cfg_print_chars(pctx, " ", 1);
1640 cfg_print_obj(pctx, obj);
1641 cfg_print_chars(pctx, ";\n", 2);
1653 cfg_doc_mapbody(cfg_printer_t *pctx, const cfg_type_t *type) {
1661 cfg_print_cstr(pctx, clause->name);
1662 cfg_print_chars(pctx, " ", 1);
1663 cfg_doc_obj(pctx, clause->type);
1664 cfg_print_chars(pctx, ";", 1);
1666 cfg_print_chars(pctx, "\n\n", 2);
1685 cfg_print_map(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1687 cfg_print_obj(pctx, obj->value.map.id);
1688 cfg_print_chars(pctx, " ", 1);
1690 print_open(pctx);
1691 cfg_print_mapbody(pctx, obj);
1692 print_close(pctx);
1696 print_clause_flags(cfg_printer_t *pctx, unsigned int flags) {
1702 cfg_print_chars(pctx, " // ", 4);
1704 cfg_print_chars(pctx, ", ", 2);
1705 cfg_print_cstr(pctx, p->text);
1712 cfg_doc_map(cfg_printer_t *pctx, const cfg_type_t *type) {
1717 cfg_doc_obj(pctx, &cfg_type_astring);
1718 cfg_print_chars(pctx, " ", 1);
1720 cfg_doc_obj(pctx, &cfg_type_netaddr);
1721 cfg_print_chars(pctx, " ", 1);
1723 cfg_doc_obj(pctx, &cfg_type_netprefix);
1724 cfg_print_chars(pctx, " ", 1);
1727 print_open(pctx);
1733 print_indent(pctx);
1734 cfg_print_cstr(pctx, clause->name);
1736 cfg_print_chars(pctx, " ", 1);
1737 cfg_doc_obj(pctx, clause->type);
1738 cfg_print_chars(pctx, ";", 1);
1739 print_clause_flags(pctx, clause->flags);
1740 cfg_print_chars(pctx, "\n", 1);
1743 print_close(pctx);
1780 parse_token(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1787 CHECK(cfg_create_obj(pctx, &cfg_type_token, &obj));
1788 CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
1789 if (pctx->token.type == isc_tokentype_eof) {
1790 cfg_ungettoken(pctx);
1795 isc_lex_getlasttokentext(pctx->lexer, &pctx->token, &r);
1797 obj->value.string.base = isc_mem_get(pctx->mctx, r.length + 1);
1810 isc_mem_put(pctx->mctx, obj, sizeof(*obj));
1825 parse_unsupported(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1830 CHECK(cfg_create_list(pctx, type, &listobj));
1835 CHECK(cfg_peektoken(pctx, 0));
1836 if (pctx->token.type == isc_tokentype_special) {
1837 if (pctx->token.value.as_char == '{')
1839 else if (pctx->token.value.as_char == '}')
1841 else if (pctx->token.value.as_char == ';')
1845 if (pctx->token.type == isc_tokentype_eof || braces < 0) {
1846 cfg_parser_error(pctx, CFG_LOG_NEAR, "unexpected token");
1851 CHECK(cfg_parse_listelt(pctx, &cfg_type_token, &elt));
1878 token_addr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) {
1883 if (pctx->token.type != isc_tokentype_string)
1886 s = TOKEN_STRING(pctx);
1955 cfg_parse_rawaddr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) {
1960 CHECK(cfg_gettoken(pctx, 0));
1961 result = token_addr(pctx, flags, na);
1968 cfg_parser_error(pctx, CFG_LOG_NEAR,
1972 cfg_parser_error(pctx, CFG_LOG_NEAR,
1976 cfg_parser_error(pctx, CFG_LOG_NEAR,
1985 cfg_lookingat_netaddr(cfg_parser_t *pctx, unsigned int flags) {
1988 result = token_addr(pctx, flags, &na_dummy);
1993 cfg_parse_rawport(cfg_parser_t *pctx, unsigned int flags, in_port_t *port) {
1996 CHECK(cfg_gettoken(pctx, ISC_LEXOPT_NUMBER));
1999 pctx->token.type == isc_tokentype_string &&
2000 strcmp(TOKEN_STRING(pctx), "*") == 0) {
2004 if (pctx->token.type != isc_tokentype_number) {
2005 cfg_parser_error(pctx, CFG_LOG_NEAR,
2009 if (pctx->token.value.as_ulong >= 65536U) {
2010 cfg_parser_error(pctx, CFG_LOG_NEAR,
2014 *port = (in_port_t)(pctx->token.value.as_ulong);
2021 cfg_print_rawaddr(cfg_printer_t *pctx, const isc_netaddr_t *na) {
2029 cfg_print_chars(pctx, isc_buffer_base(&buf), isc_buffer_usedlength(&buf));
2041 parse_netaddr(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2047 CHECK(cfg_create_obj(pctx, type, &obj));
2048 CHECK(cfg_parse_rawaddr(pctx, flags, &netaddr));
2058 cfg_doc_netaddr(cfg_printer_t *pctx, const cfg_type_t *type) {
2062 cfg_print_chars(pctx, "( ", 2);
2064 cfg_print_cstr(pctx, "<ipv4_address>");
2069 cfg_print_chars(pctx, " | ", 3);
2070 cfg_print_cstr(pctx, "<ipv6_address>");
2075 cfg_print_chars(pctx, " | ", 3);
2076 cfg_print_chars(pctx, "*", 1);
2081 cfg_print_chars(pctx, " )", 2);
2112 cfg_parse_netprefix(cfg_parser_t *pctx, const cfg_type_t *type,
2121 CHECK(cfg_parse_rawaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V4PREFIXOK |
2134 CHECK(cfg_peektoken(pctx, 0));
2135 if (pctx->token.type == isc_tokentype_special &&
2136 pctx->token.value.as_char == '/') {
2137 CHECK(cfg_gettoken(pctx, 0)); /* read "/" */
2138 CHECK(cfg_gettoken(pctx, ISC_LEXOPT_NUMBER));
2139 if (pctx->token.type != isc_tokentype_number) {
2140 cfg_parser_error(pctx, CFG_LOG_NEAR,
2144 prefixlen = pctx->token.value.as_ulong;
2146 cfg_parser_error(pctx, CFG_LOG_NOPREP,
2153 CHECK(cfg_create_obj(pctx, &cfg_type_netprefix, &obj));
2159 cfg_parser_error(pctx, CFG_LOG_NEAR, "expected network prefix");
2164 print_netprefix(cfg_printer_t *pctx, const cfg_obj_t *obj) {
2167 cfg_print_rawaddr(pctx, &p->address);
2168 cfg_print_chars(pctx, "/", 1);
2169 cfg_print_rawuint(pctx, p->prefixlen);
2196 parse_sockaddrsub(cfg_parser_t *pctx, const cfg_type_t *type,
2204 CHECK(cfg_create_obj(pctx, type, &obj));
2205 CHECK(cfg_parse_rawaddr(pctx, flags, &netaddr));
2206 CHECK(cfg_peektoken(pctx, 0));
2207 if (pctx->token.type == isc_tokentype_string &&
2208 strcasecmp(TOKEN_STRING(pctx), "port") == 0) {
2209 CHECK(cfg_gettoken(pctx, 0)); /* read "port" */
2210 CHECK(cfg_parse_rawport(pctx, flags, &port));
2228 cfg_parse_sockaddr(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2230 return (parse_sockaddrsub(pctx, &cfg_type_sockaddr, *flagp, ret));
2234 cfg_print_sockaddr(cfg_printer_t *pctx, const cfg_obj_t *obj) {
2241 cfg_print_cstr(pctx, buf);
2244 cfg_print_chars(pctx, " port ", 6);
2245 cfg_print_rawuint(pctx, port);
2250 cfg_doc_sockaddr(cfg_printer_t *pctx, const cfg_type_t *type) {
2253 cfg_print_chars(pctx, "( ", 2);
2255 cfg_print_cstr(pctx, "<ipv4_address>");
2260 cfg_print_chars(pctx, " | ", 3);
2261 cfg_print_cstr(pctx, "<ipv6_address>");
2266 cfg_print_chars(pctx, " | ", 3);
2267 cfg_print_chars(pctx, "*", 1);
2271 cfg_print_chars(pctx, " ) ", 3);
2273 cfg_print_cstr(pctx, "[ port ( <integer> | * ) ]");
2275 cfg_print_cstr(pctx, "[ port <integer> ]");
2292 cfg_gettoken(cfg_parser_t *pctx, int options) {
2295 if (pctx->seen_eof)
2301 pctx->token.type = isc_tokentype_unknown;
2302 result = isc_lex_gettoken(pctx->lexer, options, &pctx->token);
2303 pctx->ungotten = ISC_FALSE;
2304 pctx->line = isc_lex_getsourceline(pctx->lexer);
2308 if (pctx->token.type == isc_tokentype_eof) {
2309 result = isc_lex_close(pctx->lexer);
2313 if (isc_lex_getsourcename(pctx->lexer) != NULL) {
2318 elt = ISC_LIST_TAIL(pctx->open_files->
2321 ISC_LIST_UNLINK(pctx->open_files->
2323 ISC_LIST_APPEND(pctx->closed_files->
2327 pctx->seen_eof = ISC_TRUE;
2333 cfg_parser_error(pctx, CFG_LOG_NEAR, "token too big");
2337 cfg_parser_error(pctx, 0, "%s",
2342 cfg_parser_error(pctx, CFG_LOG_NEAR, "%s",
2350 cfg_ungettoken(cfg_parser_t *pctx) {
2351 if (pctx->seen_eof)
2353 isc_lex_ungettoken(pctx->lexer, &pctx->token);
2354 pctx->ungotten = ISC_TRUE;
2358 cfg_peektoken(cfg_parser_t *pctx, int options) {
2360 CHECK(cfg_gettoken(pctx, options));
2361 cfg_ungettoken(pctx);
2371 cfg_getstringtoken(cfg_parser_t *pctx) {
2374 result = cfg_gettoken(pctx, CFG_LEXOPT_QSTRING);
2378 if (pctx->token.type != isc_tokentype_string &&
2379 pctx->token.type != isc_tokentype_qstring) {
2380 cfg_parser_error(pctx, CFG_LOG_NEAR, "expected string");
2387 cfg_parser_error(cfg_parser_t *pctx, unsigned int flags, const char *fmt, ...) {
2390 parser_complain(pctx, ISC_FALSE, flags, fmt, args);
2392 pctx->errors++;
2396 cfg_parser_warning(cfg_parser_t *pctx, unsigned int flags, const char *fmt, ...) {
2399 parser_complain(pctx, ISC_TRUE, flags, fmt, args);
2401 pctx->warnings++;
2407 have_current_file(cfg_parser_t *pctx) {
2409 if (pctx->open_files == NULL)
2412 elt = ISC_LIST_TAIL(pctx->open_files->value.list);
2420 current_file(cfg_parser_t *pctx) {
2425 if (!have_current_file(pctx))
2428 elt = ISC_LIST_TAIL(pctx->open_files->value.list);
2438 parser_complain(cfg_parser_t *pctx, isc_boolean_t is_warning,
2453 if (have_current_file(pctx))
2455 current_file(pctx), pctx->line);
2465 if (pctx->ungotten)
2466 (void)cfg_gettoken(pctx, 0);
2468 if (pctx->token.type == isc_tokentype_eof) {
2470 } else if (pctx->token.type == isc_tokentype_unknown) {
2474 isc_lex_getlasttokentext(pctx->lexer,
2475 &pctx->token, &r);
2494 isc_log_write(pctx->lctx, CAT, MOD, level,
2528 cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2532 obj = isc_mem_get(pctx->mctx, sizeof(cfg_obj_t));
2536 obj->file = current_file(pctx);
2537 obj->line = pctx->line;
2540 isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
2553 cfg_parser_t *pctx = (cfg_parser_t *)userarg;
2558 cfg_obj_destroy(pctx, &obj);
2563 create_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2568 CHECK(cfg_create_obj(pctx, type, &obj));
2569 CHECK(isc_symtab_create(pctx->mctx, 5, /* XXX */
2571 pctx, ISC_FALSE, &symtab));
2580 isc_mem_put(pctx->mctx, obj, sizeof(*obj));
2585 free_map(cfg_parser_t *pctx, cfg_obj_t *obj) {
2596 * Destroy 'obj', a configuration object created in 'pctx'.
2599 cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **objp) {
2605 obj->type->rep->free(pctx, obj);
2607 isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
2621 free_noop(cfg_parser_t *pctx, cfg_obj_t *obj) {
2622 UNUSED(pctx);
2627 cfg_doc_obj(cfg_printer_t *pctx, const cfg_type_t *type) {
2628 type->doc(pctx, type);
2632 cfg_doc_terminal(cfg_printer_t *pctx, const cfg_type_t *type) {
2633 cfg_print_chars(pctx, "<", 1);
2634 cfg_print_cstr(pctx, type->name);
2635 cfg_print_chars(pctx, ">", 1);
2643 cfg_printer_t pctx;
2644 pctx.f = f;
2645 pctx.closure = closure;
2646 pctx.indent = 0;
2647 cfg_doc_obj(&pctx, type);