From: Vladimír Čunát Date: Tue, 29 Nov 2016 15:43:58 +0000 (+0100) Subject: hints: allow hints.get() to list all hints X-Git-Tag: v1.2.0-rc1~67^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccba5cd3202ba5bb8b6416dd13f1e92a5560aa62;p=thirdparty%2Fknot-resolver.git hints: allow hints.get() to list all hints --- diff --git a/lib/zonecut.h b/lib/zonecut.h index 98432a571..90d7747ae 100644 --- a/lib/zonecut.h +++ b/lib/zonecut.h @@ -32,7 +32,7 @@ struct kr_zonecut { knot_rrset_t* key; /**< Zone cut DNSKEY. */ knot_rrset_t* trust_anchor; /**< Current trust anchor. */ struct kr_zonecut *parent; /**< Parent zone cut. */ - map_t nsset; /**< Map of nameserver => address_set. */ + map_t nsset; /**< Map of nameserver => address_set. */ knot_mm_t *pool; /**< Memory pool. */ }; diff --git a/modules/hints/README.rst b/modules/hints/README.rst index e96c74b34..71f2e8eeb 100644 --- a/modules/hints/README.rst +++ b/modules/hints/README.rst @@ -39,6 +39,7 @@ Properties :return: ``{ result: [address1, address2, ...] }`` Return list of address record matching given name. + If no hostname is specified, all hints are returned in the table format used by ``hints.root()``. .. function:: hints.set(pair) @@ -56,14 +57,14 @@ Properties .. function:: hints.root() - :return: ``{ ['a.root-servers.net'] = { '1.2.3.4', '5.6.7.8', ...}, ... }`` + :return: ``{ ['a.root-servers.net.'] = { '1.2.3.4', '5.6.7.8', ...}, ... }`` .. tip:: If no parameters are passed, returns current root hints set. .. function:: hints.root(root_hints) :param table root_hints: new set of root hints i.e. ``{['name'] = 'addr', ...}`` - :return: ``{ ['a.root-servers.net'] = { '1.2.3.4', '5.6.7.8', ...}, ... }`` + :return: ``{ ['a.root-servers.net.'] = { '1.2.3.4', '5.6.7.8', ...}, ... }`` Replace current root hints and return the current table of root hints. diff --git a/modules/hints/hints.c b/modules/hints/hints.c index 28341138c..cae6b1532 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -394,8 +394,9 @@ static JsonNode *pack_addrs(pack_t *pack) return root; } +static char* pack_hints(struct kr_zonecut *hints); /** - * Retrieve address hint for given name. + * Retrieve address hints, either for given name or for all names. * * Input: name * Output: { address1, address2, ... } @@ -403,6 +404,11 @@ static JsonNode *pack_addrs(pack_t *pack) static char* hint_get(void *env, struct kr_module *module, const char *args) { struct kr_zonecut *hints = module->data; + + if (!args) { + return pack_hints(hints); + } + knot_dname_t key[KNOT_DNAME_MAXLEN]; pack_t *pack = NULL; if (knot_dname_from_str(key, args, sizeof(key))) { @@ -435,6 +441,17 @@ static int pack_hint(const char *k, void *v, void *baton) return kr_ok(); } +/** @internal Pack all hints into serialized JSON. */ +static char* pack_hints(struct kr_zonecut *hints) { + char *result = NULL; + JsonNode *root_node = json_mkobject(); + if (map_walk(&hints->nsset, pack_hint, root_node) == 0) { + result = json_encode(root_node); + } + json_delete(root_node); + return result; +} + static void unpack_hint(struct kr_zonecut *root_hints, JsonNode *table, const char *name) { JsonNode *node = NULL; @@ -467,13 +484,7 @@ static char* hint_root(void *env, struct kr_module *module, const char *args) json_delete(root_node); } /* Return current root hints */ - char *result = NULL; - JsonNode *root_node = json_mkobject(); - if (map_walk(&root_hints->nsset, pack_hint, root_node) == 0) { - result = json_encode(root_node); - } - json_delete(root_node); - return result; + return pack_hints(root_hints); } /*