diff --git a/doc/index.rst b/doc/index.rst index 47527df9548322e2eedf762c829cbeee5eb6bbb6..0cefc69db8e63be5f2dafd58daca0fa575021a3d 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -7,7 +7,7 @@ The project provides both a resolver library and a small daemon. Modular architecture of the library keeps the core tiny and efficient, and provides a state-machine like API for extensions. .. toctree:: - :maxdepth: 4 + :maxdepth: 2 build lib diff --git a/doc/lib.rst b/doc/lib.rst index e61cb206624d8f3f01d7af27443879fdabb0425c..c89712bd4548a74d7015d6154d9eb93b5ae7b7ba 100644 --- a/doc/lib.rst +++ b/doc/lib.rst @@ -5,25 +5,48 @@ API reference ============= -.. doxygengroup:: resolution - :project: libkresolve +.. contents:: + :depth: 1 + :local: .. _lib_api_rplan: +Name resolution +--------------- + +.. doxygengroup:: resolution + :project: libkresolve + .. doxygengroup:: rplan :project: libkresolve +.. _lib_api_cache: + +Cache +----- + .. doxygengroup:: cache :project: libkresolve +.. _lib_api_nameservers: + +Nameservers +----------- + .. doxygengroup:: nameservers :project: libkresolve .. _lib_api_modules: +Modules +------- + .. doxygengroup:: modules :project: libkresolve +Utilities +--------- + .. doxygengroup:: utils :project: libkresolve diff --git a/lib/README.rst b/lib/README.rst index 7af22e49201e25cfb159ca445d544498be1a322e..4b8bf299355b02ff450afdf0c12d1ffcbcc892bc 100644 --- a/lib/README.rst +++ b/lib/README.rst @@ -15,31 +15,6 @@ Library layout :local: The library as described provides basic services for name resolution, which should cover the usage. -The following part is for those who are planning to hack on the library or develop modules, to give -you an idea about the API and the library layout. - -Name resolution ---------------- - -.. _lib_rplan: - -Resolution plan ---------------- - -.. _lib_cache: - -Cache ------ - -.. _lib_nameservers: - -Nameservers ------------ - -Utilities -~~~~~~~~~ - -.. warning:: Work in progress. Resolving a name ---------------- @@ -64,9 +39,9 @@ the :c:func:`iterate_layer`, and the :c:func:`itercache_layer`. The library offers following services: -- :ref:`Cache <lib_cache>` - MVCC cache interface for retrieving/storing resource records. -- :ref:`Resolution plan <lib_rplan>` - Query resolution plan, a list of partial queries (with hierarchy) sent in order to satisfy original query. This contains information about the queries, nameserver choice, timing information, answer and its class. -- :ref:`Nameservers <lib_nameservers>` - Reputation database of nameservers, this serves as an aid for nameserver choice. +- :ref:`Cache <lib_api_cache>` - MVCC cache interface for retrieving/storing resource records. +- :ref:`Resolution plan <lib_api_rplan>` - Query resolution plan, a list of partial queries (with hierarchy) sent in order to satisfy original query. This contains information about the queries, nameserver choice, timing information, answer and its class. +- :ref:`Nameservers <lib_api_nameservers>` - Reputation database of nameservers, this serves as an aid for nameserver choice. A processing layer is going to be called by the query resolution driver for each query, so you're going to work with :ref:`struct kr_layer_param <lib_api_rplan>` as your per-query context. This structure contains pointers to diff --git a/lib/generic/README.rst b/lib/generic/README.rst index 04b3194e434afbce92ffbd5f1a917dd98a8e60ea..3bb1e18cf12680995110d864fad406cd49d9b282 100644 --- a/lib/generic/README.rst +++ b/lib/generic/README.rst @@ -6,18 +6,33 @@ such thing for C. It's either bloated, has poor interface, null-checking is abse doesn't allow custom allocation scheme. BSD-licensed (or compatible) code is allowed here, as long as it comes with a test case in `tests/test_generics.c`. -Data structures -~~~~~~~~~~~~~~~ +* array_ - a set of simple macros to make working with dynamic arrays easier. +* map_ - a `Crit-bit tree`_ key-value map implementation (public domain) that comes with tests. +* set_ - set abstraction implemented on top of ``map``. +* pack_ - length-prefixed list of objects (i.e. array-list). -* ``array`` - a set of simple macros to make working with dynamic arrays easier. -* ``set`` - a `Crit-bit tree`_ simple implementation (public domain) that comes with tests. -* ``map`` - key-value map implemented on top of ``set``. -* ``pack`` - length-prefixed list of objects (i.e. array-list). +array +~~~~~ -API reference and examples -~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. doxygenfile:: array.h + :project: libkresolve + +map +~~~ + +.. doxygenfile:: map.h + :project: libkresolve + +set +~~~ + +.. doxygenfile:: set.h + :project: libkresolve + +pack +~~~~ -.. doxygengroup:: generics +.. doxygenfile:: pack.h :project: libkresolve .. _`Crit-bit tree`: http://cr.yp.to/critbit.html diff --git a/lib/generic/array.h b/lib/generic/array.h index 96dcf19f0ffd8fa343a0e812e365db58b5fd5892..eb844fff94851b4dd0f41b137bc7c82313c65bb3 100644 --- a/lib/generic/array.h +++ b/lib/generic/array.h @@ -15,18 +15,21 @@ */ /** - * Generics - simple dynamic array. * - * \note The C has no generics, so it is implemented mostly using macros. + * @file array.h + * @brief A set of simple macros to make working with dynamic arrays easier. + * + * @note The C has no generics, so it is implemented mostly using macros. * Be aware of that, as direct usage of the macros in the evaluating macros - * may lead to different expectations, i.e. + * may lead to different expectations: * + * # Undefined behaviour * MIN(array_push(arr, val), other) * - * May evaluate the code twice, leading to unexpected behaviour. - * This is a price to pay for absence of proper generics. + * May evaluate the code twice, leading to unexpected behaviour. + * This is a price to pay for the absence of proper generics. * - * Example usage: + * Example usage: * * array_t(const char*) arr; * array_init(arr); diff --git a/lib/generic/map.h b/lib/generic/map.h index 96ce01714709a8b9b783d80f9e6a73d2a944ef39..a9413a3240e593f5e901002464fdc096e008f1cb 100644 --- a/lib/generic/map.h +++ b/lib/generic/map.h @@ -4,11 +4,13 @@ */ /** - * Generics - A Crit-bit tree 'map' implementation. * - * @warning If the user provides a custom allocator, it must return addresses aligned to 2B boundary. + * @file map.h + * @brief A Crit-bit tree key-value map implementation. * - * Example usage: + * @warning If the user provides a custom allocator, it must return addresses aligned to 2B boundary. + * + * Example usage: * * map_t map = map_make(); * diff --git a/lib/generic/pack.h b/lib/generic/pack.h index 171b7f1d3ca6286a40c2c043f88e0e9173798899..49f9a0c3088cd93495ae5ffcefef7f670b80cb32 100644 --- a/lib/generic/pack.h +++ b/lib/generic/pack.h @@ -15,34 +15,35 @@ */ /** - * Generics - array of lenght-prefixed packed objects + * @file pack.h + * @brief A length-prefixed list of objects, also an array list. * * Each object is prefixed by item length, unlike array this structure * permits variable-length data. It is also equivallent to forward-only list * backed by an array. * - * @note Maximum object size is 2^16 bytes, @see pack_objlen_t + * @note Maximum object size is 2^16 bytes, see ::pack_objlen_t * * Example usage: * - * pack_t pack; - * pack_init(pack); + * pack_t pack; + * pack_init(pack); * - * // Reserve 2 objects, 6 bytes total - * pack_reserve(pack, 2, 4 + 2); - * - * // Push 2 objects - * pack_obj_push(pack, U8("jedi"), 4) - * pack_obj_push(pack, U8("\xbe\xef"), 2); + * // Reserve 2 objects, 6 bytes total + * pack_reserve(pack, 2, 4 + 2); + * + * // Push 2 objects + * pack_obj_push(pack, U8("jedi"), 4) + * pack_obj_push(pack, U8("\xbe\xef"), 2); * - * // Iterate length-value pairs - * uint8_t *it = pack_head(pack); - * while (it != pack_tail(pack)) { - * uint8_t *val = pack_obj_val(it); - * it = pack_obj_next(it); - * } + * // Iterate length-value pairs + * uint8_t *it = pack_head(pack); + * while (it != pack_tail(pack)) { + * uint8_t *val = pack_obj_val(it); + * it = pack_obj_next(it); + * } * - * pack_clear(pack); + * pack_clear(pack); * * \addtogroup generics * @{ @@ -52,6 +53,10 @@ #include <string.h> #include "array.h" +#ifdef __cplusplus +extern "C" { +#endif + /** Packed object length type. */ typedef uint16_t pack_objlen_t; @@ -115,4 +120,10 @@ static inline int pack_obj_push(pack_t *pack, const uint8_t *obj, pack_objlen_t memcpy(endp + sizeof(len), obj, len); pack->len += packed_len; return 0; -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif + +/** @} */ diff --git a/lib/generic/set.h b/lib/generic/set.h index 39427b408bd5c76dab728d93c798a67cd4e6d763..26a3d36a08056494fdf8f3553159738ac692e9f8 100644 --- a/lib/generic/set.h +++ b/lib/generic/set.h @@ -1,9 +1,26 @@ +/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + /** - * Generics - A Crit-bit set implementation. + * @file set.h + * @brief A set abstraction implemented on top of map. * - * @note The API is based on @fn map.h, see it for more examples. + * @note The API is based on map.h, see it for more examples. * - * Example usage: + * Example usage: * * set_t set = set_make(); * @@ -83,4 +100,4 @@ typedef int (set_walk_cb)(const char *, void *); } #endif -/** @} */ \ No newline at end of file +/** @} */ diff --git a/lib/rplan.h b/lib/rplan.h index 8008dfd25bd06c2d16527dfc8332ac9f77720391..74ff9a96fab3e4d65b8d607becfddb66f52c5260 100644 --- a/lib/rplan.h +++ b/lib/rplan.h @@ -30,7 +30,7 @@ #include "lib/cache.h" #include "lib/zonecut.h" -/* Query flags */ +/** Query flags */ enum kr_query_flag { QUERY_NO_MINIMIZE = 1 << 0, /**< Don't minimize QNAME. */ QUERY_TCP = 1 << 1 /**< Use TCP for this query. */