From bd4b8fe0503ff199f96593b12c522b2949bc1c57 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 15 Feb 2001 18:53:03 +0000 Subject: [PATCH] provide functions to access map names and lists --- lib/isccfg/include/isccfg/cfg.h | 59 ++++++++++++++++- lib/isccfg/parser.c | 108 ++++++++++++++++++++------------ 2 files changed, 126 insertions(+), 41 deletions(-) diff --git a/lib/isccfg/include/isccfg/cfg.h b/lib/isccfg/include/isccfg/cfg.h index 2a2c001564..1a874d1bf1 100644 --- a/lib/isccfg/include/isccfg/cfg.h +++ b/lib/isccfg/include/isccfg/cfg.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: cfg.h,v 1.2 2001/02/15 05:14:16 gson Exp $ */ +/* $Id: cfg.h,v 1.3 2001/02/15 18:53:03 gson Exp $ */ #ifndef DNS_CFG_H #define DNS_CFG_H 1 @@ -63,6 +63,11 @@ typedef struct cfg_type cfg_type_t; */ typedef struct cfg_obj cfg_obj_t; +/* + * A configuration object list element. + */ +typedef struct cfg_listelt cfg_listelt_t; + /*** *** Functions ***/ @@ -119,6 +124,18 @@ cfg_map_get(cfg_obj_t *mapobj, const char* name, cfg_obj_t **obj); * ISC_R_NOTFOUND - name not found in map */ +cfg_obj_t * +cfg_map_getname(cfg_obj_t *mapobj); +/* + * Get the name of a named map object, like a server "key" clause. + * + * Requires: + * 'mapobj' ponts to a valid configuraration object of a map type. + * + * Returns: + * A pointer to a configuration object naming the map object, + * or NULL if the map object does not have a name. + */ isc_uint32_t cfg_obj_asuint32(cfg_obj_t *obj); @@ -145,6 +162,46 @@ cfg_obj_asstring(cfg_obj_t *obj); * A pointer to a null terminated string. */ +cfg_listelt_t * +cfg_list_first(cfg_obj_t *obj); +/* + * Returns the first list element in a configuration object of a list type. + * + * Requires: + * 'obj' points to a valid configuration object of a list type. + * + * Returns: + * A pointer to a cfg_listelt_t representing the first list element, + * or NULL if the list is empty. + */ + +cfg_listelt_t * +cfg_list_next(cfg_listelt_t *elt); +/* + * Returns the next element of a list of configuration objects. + * + * Requires: + * 'elt' points to cfg_listelt_t obtained from cfg_list_first() or + * a previous call to cfg_list_next(). + * + * Returns: + * A pointer to a cfg_listelt_t representing the next element, + * or NULL if there are no more elements. + */ + +cfg_obj_t * +cfg_listelt_value(cfg_listelt_t *elt); +/* + * Returns the configuration object associated with cfg_listelt_t. + * + * Requires: + * 'elt' points to cfg_listelt_t obtained from cfg_list_first() or + * cfg_list_next(). + * + * Returns: + * A non-NULL pointer to a configuration object. + */ + void cfg_print(cfg_obj_t *obj, void (*f)(void *closure, const char *text, int textlen), diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index 000b8a08e7..70657a0c87 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: parser.c,v 1.2 2001/02/15 05:14:15 gson Exp $ */ +/* $Id: parser.c,v 1.3 2001/02/15 18:53:02 gson Exp $ */ #include @@ -83,7 +83,6 @@ typedef struct cfg_clausedef cfg_clausedef_t; typedef struct cfg_printer cfg_printer_t; -typedef struct cfg_listelt cfg_listelt_t; typedef ISC_LIST(cfg_listelt_t) cfg_list_t; typedef struct cfg_map cfg_map_t; typedef struct cfg_rep cfg_rep_t; @@ -1316,6 +1315,12 @@ cfg_map_get(cfg_obj_t *mapobj, const char* name, cfg_obj_t **obj) { return (ISC_R_SUCCESS); } +cfg_obj_t * +cfg_map_getname(cfg_obj_t *mapobj) { + REQUIRE(mapobj != NULL && mapobj->type->rep == &cfg_rep_map); + return (mapobj->value.map.id); +} + /* * void */ @@ -1600,10 +1605,43 @@ static cfg_type_t cfg_type_optional_keyref = { /* - * Parse a homogeneous list whose elements are of type 'elttype' - * and where each element is terminated by a semicolon. + * Lists. */ +static isc_result_t +create_list(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **obj) { + isc_result_t result; + CHECK(create_cfgobj(pctx, type, obj)); + ISC_LIST_INIT((*obj)->value.list); + cleanup: + return (result); +} + +static isc_result_t +create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) { + cfg_listelt_t *elt; + elt = isc_mem_get(pctx->mctx, sizeof(*elt)); + if (elt == NULL) + return (ISC_R_NOMEMORY); + elt->obj = NULL; + ISC_LINK_INIT(elt, link); + *eltp = elt; + return (ISC_R_SUCCESS); +} + +static void +free_list(cfg_parser_t *pctx, cfg_obj_t *obj) { + cfg_listelt_t *elt, *next; + for (elt = ISC_LIST_HEAD(obj->value.list); + elt != NULL; + elt = next) + { + next = ISC_LIST_NEXT(elt, link); + cfg_obj_destroy(pctx, &elt->obj); + isc_mem_put(pctx->mctx, elt, sizeof(*elt)); + } +} + static isc_result_t parse_list_elt(cfg_parser_t *pctx, cfg_type_t *elttype, cfg_listelt_t **ret) { @@ -1627,7 +1665,10 @@ parse_list_elt(cfg_parser_t *pctx, cfg_type_t *elttype, cfg_listelt_t **ret) return (result); } - +/* + * Parse a homogeneous list whose elements are of type 'elttype' + * and where each element is terminated by a semicolon. + */ static isc_result_t parse_list(cfg_parser_t *pctx, cfg_type_t *listtype, cfg_obj_t **ret) { @@ -1734,6 +1775,28 @@ print_spacelist(cfg_printer_t *pctx, cfg_obj_t *obj) { } } +cfg_listelt_t * +cfg_list_first(cfg_obj_t *obj) { + REQUIRE(obj != NULL && obj->type->rep == &cfg_rep_list); + return (ISC_LIST_HEAD(obj->value.list)); +} + +cfg_listelt_t * +cfg_list_next(cfg_listelt_t *elt) { + REQUIRE(elt != NULL); + return (ISC_LIST_NEXT(elt, link)); +} + +cfg_obj_t * +cfg_listelt_value(cfg_listelt_t *elt) { + REQUIRE(elt != NULL); + return (elt->obj); +} + +/* + * Maps. + */ + static void print_mapbody(cfg_printer_t *pctx, cfg_obj_t *obj) { isc_result_t result = ISC_R_SUCCESS; @@ -3026,41 +3089,6 @@ free_map(cfg_parser_t *pctx, cfg_obj_t *obj) { isc_symtab_destroy(&obj->value.map.symtab); } -static isc_result_t -create_list(cfg_parser_t *pctx, cfg_type_t *type, cfg_obj_t **obj) { - isc_result_t result; - CHECK(create_cfgobj(pctx, type, obj)); - ISC_LIST_INIT((*obj)->value.list); - cleanup: - return (result); -} - -static isc_result_t -create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) { - cfg_listelt_t *elt; - elt = isc_mem_get(pctx->mctx, sizeof(*elt)); - if (elt == NULL) - return (ISC_R_NOMEMORY); - elt->obj = NULL; - ISC_LINK_INIT(elt, link); - *eltp = elt; - return (ISC_R_SUCCESS); -} - - -static void -free_list(cfg_parser_t *pctx, cfg_obj_t *obj) { - cfg_listelt_t *elt, *next; - for (elt = ISC_LIST_HEAD(obj->value.list); - elt != NULL; - elt = next) - { - next = ISC_LIST_NEXT(elt, link); - cfg_obj_destroy(pctx, &elt->obj); - isc_mem_put(pctx->mctx, elt, sizeof(*elt)); - } -} - /* * Destroy 'obj', a configuration object created in 'pctx'. */