1b7579f77SDag-Erling Smørgrav /* 2b7579f77SDag-Erling Smørgrav * services/modstack.h - stack of modules 3b7579f77SDag-Erling Smørgrav * 4b7579f77SDag-Erling Smørgrav * Copyright (c) 2007, NLnet Labs. All rights reserved. 5b7579f77SDag-Erling Smørgrav * 6b7579f77SDag-Erling Smørgrav * This software is open source. 7b7579f77SDag-Erling Smørgrav * 8b7579f77SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 9b7579f77SDag-Erling Smørgrav * modification, are permitted provided that the following conditions 10b7579f77SDag-Erling Smørgrav * are met: 11b7579f77SDag-Erling Smørgrav * 12b7579f77SDag-Erling Smørgrav * Redistributions of source code must retain the above copyright notice, 13b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer. 14b7579f77SDag-Erling Smørgrav * 15b7579f77SDag-Erling Smørgrav * Redistributions in binary form must reproduce the above copyright notice, 16b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer in the documentation 17b7579f77SDag-Erling Smørgrav * and/or other materials provided with the distribution. 18b7579f77SDag-Erling Smørgrav * 19b7579f77SDag-Erling Smørgrav * Neither the name of the NLNET LABS nor the names of its contributors may 20b7579f77SDag-Erling Smørgrav * be used to endorse or promote products derived from this software without 21b7579f77SDag-Erling Smørgrav * specific prior written permission. 22b7579f77SDag-Erling Smørgrav * 23b7579f77SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24*17d15b25SDag-Erling Smørgrav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25*17d15b25SDag-Erling Smørgrav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26*17d15b25SDag-Erling Smørgrav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27*17d15b25SDag-Erling Smørgrav * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28*17d15b25SDag-Erling Smørgrav * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29*17d15b25SDag-Erling Smørgrav * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30*17d15b25SDag-Erling Smørgrav * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31*17d15b25SDag-Erling Smørgrav * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32*17d15b25SDag-Erling Smørgrav * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33*17d15b25SDag-Erling Smørgrav * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34b7579f77SDag-Erling Smørgrav */ 35b7579f77SDag-Erling Smørgrav 36b7579f77SDag-Erling Smørgrav /** 37b7579f77SDag-Erling Smørgrav * \file 38b7579f77SDag-Erling Smørgrav * 39b7579f77SDag-Erling Smørgrav * This file contains functions to help maintain a stack of modules. 40b7579f77SDag-Erling Smørgrav */ 41b7579f77SDag-Erling Smørgrav 42b7579f77SDag-Erling Smørgrav #ifndef SERVICES_MODSTACK_H 43b7579f77SDag-Erling Smørgrav #define SERVICES_MODSTACK_H 44b7579f77SDag-Erling Smørgrav struct module_func_block; 45b7579f77SDag-Erling Smørgrav struct module_env; 46b7579f77SDag-Erling Smørgrav 47b7579f77SDag-Erling Smørgrav /** 48b7579f77SDag-Erling Smørgrav * Stack of modules. 49b7579f77SDag-Erling Smørgrav */ 50b7579f77SDag-Erling Smørgrav struct module_stack { 51b7579f77SDag-Erling Smørgrav /** the number of modules */ 52b7579f77SDag-Erling Smørgrav int num; 53b7579f77SDag-Erling Smørgrav /** the module callbacks, array of num_modules length (ref only) */ 54b7579f77SDag-Erling Smørgrav struct module_func_block** mod; 55b7579f77SDag-Erling Smørgrav }; 56b7579f77SDag-Erling Smørgrav 57b7579f77SDag-Erling Smørgrav /** 58b7579f77SDag-Erling Smørgrav * Init a stack of modules 59b7579f77SDag-Erling Smørgrav * @param stack: initialised as empty. 60b7579f77SDag-Erling Smørgrav */ 61b7579f77SDag-Erling Smørgrav void modstack_init(struct module_stack* stack); 62b7579f77SDag-Erling Smørgrav 63b7579f77SDag-Erling Smørgrav /** 64b7579f77SDag-Erling Smørgrav * Read config file module settings and set up the modfunc block 65b7579f77SDag-Erling Smørgrav * @param stack: the stack of modules (empty before call). 66b7579f77SDag-Erling Smørgrav * @param module_conf: string what modules to insert. 67b7579f77SDag-Erling Smørgrav * @return false on error 68b7579f77SDag-Erling Smørgrav */ 69b7579f77SDag-Erling Smørgrav int modstack_config(struct module_stack* stack, const char* module_conf); 70b7579f77SDag-Erling Smørgrav 71b7579f77SDag-Erling Smørgrav /** 72b7579f77SDag-Erling Smørgrav * Get funcblock for module name 73b7579f77SDag-Erling Smørgrav * @param str: string with module name. Advanced to next value on success. 74b7579f77SDag-Erling Smørgrav * The string is assumed whitespace separated list of module names. 75b7579f77SDag-Erling Smørgrav * @return funcblock or NULL on error. 76b7579f77SDag-Erling Smørgrav */ 77b7579f77SDag-Erling Smørgrav struct module_func_block* module_factory(const char** str); 78b7579f77SDag-Erling Smørgrav 79b7579f77SDag-Erling Smørgrav /** 80b7579f77SDag-Erling Smørgrav * Get list of modules available. 81b7579f77SDag-Erling Smørgrav * @return list of modules available. Static strings, ends with NULL. 82b7579f77SDag-Erling Smørgrav */ 83b7579f77SDag-Erling Smørgrav const char** module_list_avail(void); 84b7579f77SDag-Erling Smørgrav 85b7579f77SDag-Erling Smørgrav /** 86b7579f77SDag-Erling Smørgrav * Setup modules. Assigns ids and calls module_init. 87b7579f77SDag-Erling Smørgrav * @param stack: if not empty beforehand, it will be desetup()ed. 88b7579f77SDag-Erling Smørgrav * It is then modstack_configged(). 89b7579f77SDag-Erling Smørgrav * @param module_conf: string what modules to insert. 90b7579f77SDag-Erling Smørgrav * @param env: module environment which is inited by the modules. 91b7579f77SDag-Erling Smørgrav * environment should have a superalloc, cfg, 92b7579f77SDag-Erling Smørgrav * env.need_to_validate is set by the modules. 93b7579f77SDag-Erling Smørgrav * @return on false a module init failed. 94b7579f77SDag-Erling Smørgrav */ 95b7579f77SDag-Erling Smørgrav int modstack_setup(struct module_stack* stack, const char* module_conf, 96b7579f77SDag-Erling Smørgrav struct module_env* env); 97b7579f77SDag-Erling Smørgrav 98b7579f77SDag-Erling Smørgrav /** 99b7579f77SDag-Erling Smørgrav * Desetup the modules, deinit, delete. 100b7579f77SDag-Erling Smørgrav * @param stack: made empty. 101b7579f77SDag-Erling Smørgrav * @param env: module env for module deinit() calls. 102b7579f77SDag-Erling Smørgrav */ 103b7579f77SDag-Erling Smørgrav void modstack_desetup(struct module_stack* stack, struct module_env* env); 104b7579f77SDag-Erling Smørgrav 105b7579f77SDag-Erling Smørgrav /** 106b7579f77SDag-Erling Smørgrav * Find index of module by name. 107b7579f77SDag-Erling Smørgrav * @param stack: to look in 108b7579f77SDag-Erling Smørgrav * @param name: the name to look for 109b7579f77SDag-Erling Smørgrav * @return -1 on failure, otherwise index number. 110b7579f77SDag-Erling Smørgrav */ 111b7579f77SDag-Erling Smørgrav int modstack_find(struct module_stack* stack, const char* name); 112b7579f77SDag-Erling Smørgrav 113b7579f77SDag-Erling Smørgrav #endif /* SERVICES_MODSTACK_H */ 114