## ## val - OSSP Value Library ## Copyright (c) 2002 Ralf S. Engelschall ## Copyright (c) 2002 The OSSP Project ## Copyright (c) 2002 Cable & Wireless Deutschland ## ## This file is part of OSSP val, a Value library which ## can be found at http://www.ossp.org/pkg/val/. ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## ## val.pod: library manual page ## =pod =head1 NAME B - Value Library =head1 SYNOPSIS =over 4 =item B C, C, C, C, C, C, C, C, C C, C, C, C, C, C, C. =item B C, C, C. =item B C, C, C, C, C, C, C, C, C, C. =back =head1 DESCRIPTION B is a flexible name to value mapping library for C variables. It allows one to access C variables through name strings, although the C language does neither provide such a dedicated facility nor an evaluation construct (which could be used to implement such a facility easily). In general, it is interesting whenever you need access to C variable symbols without having to know the actual address/reference. The typical use cases are in combination with flexible configuration parsing and supporting loosly-coupled DSO-based module architectures. =head1 STRUCTURED NAMES Whenever the APIs calls for a name it supports structured names where elements are separated by a dot. It is assumed that the leading elements are references to other C structures and only the very last element is a reference to an actual variable. =head1 API CONSTANTS =over 4 =item C The maximum length of a variable name. For structured variables this includes the concatenation of all elements within a path and their separating dots. =item CI Type of value when registering a variable using B() or querying for the type using B(). Most are self-explanatory, C is used to mount a C structure into an existing C structure to support structured names. C, C, C, C, C, C, C, C =item C, CI Return codes for every API function. Signals success, invalid argument passed to function, bad usage of a function, memoryusage reached C limit, error in internal hash function to be examined through C, internal error in storage as result from structure corruption, or system errors including out of memory. C, C, C, C, C, C. =back =head1 API DATA TYPES =over 4 =item C Handle created by B() and passed to all other functions to reference the the same group of variables. =item C Callback to be used B(). =item C Code returned by every function. See C C and CI. =back =head1 API FUNCTIONS =over 4 =item val_rc_t B(val_t **I); Creates an I and updates the given pointer to reference it. =item val_rc_t B(val_t *I); Destroys an I, freeing up memory. =item val_rc_t B(val_t *I, const char *I, int I, const char *I, void *I); Registers a variable I using I in I. An optional description or NULL can be passed through I which can be queried through B() and is also passed to the callback of B(). The value that belongs to the given I is expected to be found at I. Passing NULL as I will create an inline data store in I so it can only be access through B(), B() or after the actual storage address was queried using B(). =item val_rc_t B(val_t *I, const char *I); Unregisters a variable I in I. =item val_rc_t B(val_t *I, const char *I, int *I, char **I, void **I); Queries a variable I in I and returns it's type, description and storage address. All of I, I and I are optional and NULL can be passed in if this information is not needed. Passing NULL to all query result pointers just checks for existence of I. =item val_rc_t B(val_t *I, const char *I, ...); Sets the value of variable I in I to the data passed in as vararg. Unless the actual storage address was queried using B() this is mandatory for inline data. Usually not the value but a pointer to it is stored to the value can be modified without notice to the library. =item val_rc_t B(val_t *I, const char *I, ...); Gets the value of variable I in I and stores it whereever the passed vararg points to. =item val_rc_t B(val_t *I, const char *I, va_list I); Like B() but takes a C as input to allow recursive execution. Acutally, B() ist just a wrapper around B(). =item val_rc_t B(val_t *I, const char *I, va_list I); Like B() but takes a C as input to allow recursive execution. Acutally, B() ist just a wrapper around B(). =item val_rc_t B(val_t *I, const char *I, int I, val_cb_t I, void *I); Iterates through all elements of I, starting with I which can be either a data store or I reference, down to a given recursion I. When I is set to the empty string the search starts immediately at I. For every element, the callback I() is executed and a context I is passed to it along with other information described below. =item val_rc_t (*)(void *I, const char *I, int I, const char *I, void *I) Callback executed by B() for each element being processed. The context I input to B() is passed to the callback verbatim. The I is the structured name relative to the I passed to B(), I signals the type of value I points to and I is a text which was optionally passed to B(). =back =head1 SEE ALSO OSSP var. =head1 EXAMPLES =over 4 =item simple create, reg, get, destroy #include #include "val.h" int main(void) { val_rc_t rc; val_t *v; int example; int pullout; if ((rc = val_create(&v)) != VAL_OK) exit(-1); if ((rc = val_reg(v, "foo", VAL_TYPE_INT, "foo variable", (void *)&example)) != VAL_OK) exit(-1); example = 123; if ((rc = val_get(v, "foo", &pullout)) != VAL_OK) exit(-1); printf("pulled example and got %d\n", pullout); if ((rc = val_destroy(v)) != VAL_OK) exit(-1); return 0; } =item reg inline data, structured name, set #include #include "val.h" int main(void) { val_rc_t rc; val_t *v1, *v2; int pullout; if ((rc = val_create(&v1)) != VAL_OK) exit(-1); if ((rc = val_create(&v2)) != VAL_OK) exit(-1); if ((rc = val_reg(v1, "bar", VAL_TYPE_VAL, "child", (void *)&v2)) != VAL_OK) exit(-1); if ((rc = val_reg(v1, "bar.foo", VAL_TYPE_INT, "foo variable", NULL)) != VAL_OK) exit(-1); if ((rc = val_set(v2, "foo", 456)) != VAL_OK) exit(-1); if ((rc = val_get(v1, "bar.foo", &pullout)) != VAL_OK) exit(-1); printf("pulled example and got %d\n", pullout); if ((rc = val_destroy(v2)) != VAL_OK) exit(-1); if ((rc = val_destroy(v1)) != VAL_OK) exit(-1); return 0; } =back =head1 HISTORY B was invented in January 2002 by Thomas Lotterer and Ralf S. Engelschall for use inside the OSSP lmtp2nntp project. =head1 AUTHORS Thomas Lotterer Ralf S. Engelschall =cut