* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: parser.c,v 1.24 2001/02/26 19:15:11 gson Exp $ */
+/* $Id: parser.c,v 1.25 2001/02/26 22:37:32 gson Exp $ */
#include <config.h>
static void
print_bracketed_list(cfg_printer_t *pctx, cfg_obj_t *obj);
+static isc_result_t
+parse_keyvalue(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **ret);
+
static isc_result_t
parse_optional_keyvalue(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **ret);
static void
-print_optional_keyvalue(cfg_printer_t *pctx, cfg_obj_t *obj);
+print_keyvalue(cfg_printer_t *pctx, cfg_obj_t *obj);
static isc_result_t
parse_symtab_elt(cfg_parser_t *pctx, const char *name,
static cfg_type_t cfg_type_optional_wild_class = {
"optional_wild_class", parse_optional_keyvalue,
- print_optional_keyvalue, &cfg_rep_string, &wild_class_kw
+ print_keyvalue, &cfg_rep_string, &wild_class_kw
};
static keyword_type_t wild_type_kw = { "type", &cfg_type_ustring };
static cfg_type_t cfg_type_optional_wild_type = {
"optional_wild_type", parse_optional_keyvalue,
- print_optional_keyvalue, &cfg_rep_string, &wild_type_kw
+ print_keyvalue, &cfg_rep_string, &wild_type_kw
};
static keyword_type_t wild_name_kw = { "name", &cfg_type_qstring };
static cfg_type_t cfg_type_optional_wild_name = {
"optional_wild_name", parse_optional_keyvalue,
- print_optional_keyvalue, &cfg_rep_string, &wild_name_kw
+ print_keyvalue, &cfg_rep_string, &wild_name_kw
};
/*
static keyword_type_t port_kw = { "port", &cfg_type_uint32 };
static cfg_type_t cfg_type_optional_port = {
- "optional_port", parse_optional_keyvalue, print_optional_keyvalue,
+ "optional_port", parse_optional_keyvalue, print_keyvalue,
&cfg_rep_uint32, &port_kw
};
* optional_keyvalue
*/
static isc_result_t
-parse_optional_keyvalue(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **ret) {
+parse_maybe_optional_keyvalue(cfg_parser_t *pctx, cfg_type_t *type,
+ isc_boolean_t optional, cfg_obj_t **ret)
+{
isc_result_t result;
cfg_obj_t *obj = NULL;
keyword_type_t *kw = type->of;
CHECK(kw->type->parse(pctx, kw->type, &obj));
obj->type = type; /* XXX kludge */
} else {
- CHECK(parse_void(pctx, NULL, &obj));
+ if (optional) {
+ CHECK(parse_void(pctx, NULL, &obj));
+ } else {
+ parser_error(pctx, LOG_NEAR, "expected '%s'",
+ kw->name);
+ result = ISC_R_UNEXPECTEDTOKEN;
+ goto cleanup;
+ }
}
*ret = obj;
cleanup:
return (result);
}
+static isc_result_t
+parse_keyvalue(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **ret) {
+ return (parse_maybe_optional_keyvalue(pctx, type, ISC_FALSE, ret));
+}
+
+static isc_result_t
+parse_optional_keyvalue(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **ret) {
+ return (parse_maybe_optional_keyvalue(pctx, type, ISC_TRUE, ret));
+}
+
static void
-print_optional_keyvalue(cfg_printer_t *pctx, cfg_obj_t *obj) {
+print_keyvalue(cfg_printer_t *pctx, cfg_obj_t *obj) {
keyword_type_t *kw = obj->type->of;
print(pctx, kw->name, strlen(kw->name));
print(pctx, " ", 1);
"boolean_or_string", parse_boolean_or_ustring, NULL, NULL, NULL };
static keyword_type_t key_kw = { "key", &cfg_type_astring };
+
+static cfg_type_t cfg_type_keyref = {
+ "keyref", parse_keyvalue, print_keyvalue,
+ &cfg_rep_string, &key_kw
+};
+
static cfg_type_t cfg_type_optional_keyref = {
- "optional_keyref", parse_optional_keyvalue, print_optional_keyvalue,
+ "optional_keyref", parse_optional_keyvalue, print_keyvalue,
&cfg_rep_string, &key_kw
};
pctx->token.type == isc_tokentype_qstring) {
if (pctx->token.type == isc_tokentype_string &&
(strcasecmp(pctx->token.value.as_pointer, "key") == 0)) {
- CHECK(parse(pctx, &cfg_type_optional_keyref, ret));
- /* It's not really optional. */
- INSIST((*ret)->type != &cfg_type_void);
+ CHECK(parse(pctx, &cfg_type_keyref, ret));
} else {
if (looking_at_netaddr(pctx, V4OK|V4PREFIXOK|V6OK)) {
CHECK(parse_netprefix(pctx, NULL, ret));
*/
static cfg_tuplefielddef_t negated_fields[] = {
- { "acl", &cfg_type_addrmatchelt, 0 },
+ { "value", &cfg_type_addrmatchelt, 0 },
{ NULL, NULL, 0 }
};
*/
static keyword_type_t debug_kw = { "debug", &cfg_type_uint32 };
-static cfg_type_t cfg_type_optional_debuglevel = {
- "optional_debuglevel", parse_optional_keyvalue,
- print_optional_keyvalue, &cfg_rep_uint32, &debug_kw
+static cfg_type_t cfg_type_debuglevel = {
+ "debuglevel", parse_keyvalue,
+ print_keyvalue, &cfg_rep_uint32, &debug_kw
};
static isc_result_t
CHECK(cfg_peektoken(pctx, 0));
if (pctx->token.type == isc_tokentype_string &&
strcasecmp(pctx->token.value.as_pointer, "debug") == 0) {
- CHECK(parse(pctx, &cfg_type_optional_debuglevel, ret));
- /* It's not really optional. */
+ CHECK(parse(pctx, &cfg_type_debuglevel, ret));
INSIST((*ret)->type != &cfg_type_void);
} else {
CHECK(parse(pctx, &cfg_type_astring, ret));
isc_symtab_destroy(&obj->value.map.symtab);
}
+isc_boolean_t
+cfg_obj_istype(cfg_obj_t *obj, cfg_type_t *type) {
+ return (ISC_TF(obj->type == type));
+}
+
/*
* Destroy 'obj', a configuration object created in 'pctx'.
*/