1 /* 2 * Copyright (C) 2007 iptelorg GmbH 3 * 4 * This file is part of Kamailio, a free SIP server. 5 * 6 * Kamailio is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version 10 * 11 * Kamailio is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 22 #ifndef _CFG_H 23 #define _CFG_H 24 25 #include "../str.h" 26 27 /* variable type */ 28 #define CFG_VAR_UNSET 0U 29 #define CFG_VAR_INT 1U 30 #define CFG_VAR_STRING 2U 31 #define CFG_VAR_STR 3U 32 #define CFG_VAR_POINTER 4U 33 34 /*! \brief number of bits required for the variable type */ 35 #define CFG_INPUT_SHIFT 3 36 37 /*! \brief input types */ 38 #define CFG_INPUT_INT (CFG_VAR_INT << CFG_INPUT_SHIFT) 39 #define CFG_INPUT_STRING (CFG_VAR_STRING << CFG_INPUT_SHIFT) 40 #define CFG_INPUT_STR (CFG_VAR_STR << CFG_INPUT_SHIFT) 41 42 #define CFG_VAR_MASK(x) ((x)&((1U<<CFG_INPUT_SHIFT)-1)) 43 #define CFG_INPUT_MASK(x) ((x)&((1U<<(2*CFG_INPUT_SHIFT))-(1U<<CFG_INPUT_SHIFT))) 44 45 #define CFG_ATOMIC (1U<<(2*CFG_INPUT_SHIFT)) /*!< atomic change is allowed */ 46 #define CFG_READONLY (1U<<(2*CFG_INPUT_SHIFT+1)) /*!< variable is read-only */ 47 #define CFG_CB_ONLY_ONCE (1U<<(2*CFG_INPUT_SHIFT+2)) /*!< per-child process callback needs to be called only once */ 48 49 typedef int (*cfg_on_change)(void *, str *, str *, void **); 50 typedef void (*cfg_on_set_child)(str *, str *); 51 52 /*! \brief structrure to be used by the module interface */ 53 typedef struct _cfg_def { 54 char *name; 55 unsigned int type; 56 int min; 57 int max; 58 cfg_on_change on_change_cb; 59 cfg_on_set_child on_set_child_cb; 60 char *descr; 61 } cfg_def_t; 62 63 /*! \brief declares a new cfg group 64 * handler is set to the memory area where the variables are stored 65 * return value is -1 on error 66 */ 67 int cfg_declare(char *group_name, cfg_def_t *def, void *values, int def_size, 68 void **handler); 69 70 #define cfg_sizeof(gname) \ 71 sizeof(struct cfg_group_##gname) 72 73 #define cfg_get(gname, handle, var) \ 74 ((struct cfg_group_##gname *)handle)->var 75 76 /*! \brief declares a single variable with integer type */ 77 int cfg_declare_int(char *group_name, char *var_name, 78 int val, int min, int max, char *descr); 79 80 /*! \brief declares a single variable with str type */ 81 int cfg_declare_str(char *group_name, char *var_name, char *val, char *descr); 82 83 /*! \brief Add a variable to a group instance with integer type. 84 * The group instance is created if it does not exist. 85 * wrapper function for new_add_var() 86 */ 87 int cfg_ginst_var_int(char *group_name, unsigned int group_id, char *var_name, 88 int val); 89 90 /*! \brief Add a variable to a group instance with string type. 91 * The group instance is created if it does not exist. 92 * wrapper function for new_add_var() 93 */ 94 int cfg_ginst_var_string(char *group_name, unsigned int group_id, char *var_name, 95 char *val); 96 97 /*! \brief Create a new group instance. 98 * wrapper function for new_add_var() 99 */ 100 int cfg_new_ginst(char *group_name, unsigned int group_id); 101 102 /*! \brief returns the handle of a cfg group */ 103 void **cfg_get_handle(char *gname); 104 105 #endif /* _CFG_H */ 106