cfg/cfg.h
a903fdab
 /*
  * Copyright (C) 2007 iptelorg GmbH
  *
1fff03a2
  * This file is part of Kamailio, a free SIP server.
a903fdab
  *
1fff03a2
  * Kamailio is free software; you can redistribute it and/or modify
a903fdab
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
1fff03a2
  * Kamailio is distributed in the hope that it will be useful,
a903fdab
  * 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, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
a903fdab
  *
  */
 
 #ifndef _CFG_H
 #define _CFG_H
 
 #include "../str.h"
 
0d96457b
 /* variable type */
7d7264e2
 #define CFG_VAR_UNSET		0U
a903fdab
 #define CFG_VAR_INT		1U
 #define CFG_VAR_STRING		2U
 #define CFG_VAR_STR		3U
 #define CFG_VAR_POINTER		4U
 
709acbb7
 /*! \brief number of bits required for the variable type */
e5cba078
 #define CFG_INPUT_SHIFT		3
 
709acbb7
 /*! \brief input types */
e5cba078
 #define CFG_INPUT_INT		(CFG_VAR_INT << CFG_INPUT_SHIFT)
 #define CFG_INPUT_STRING	(CFG_VAR_STRING << CFG_INPUT_SHIFT)
 #define CFG_INPUT_STR		(CFG_VAR_STR << CFG_INPUT_SHIFT)
a903fdab
 
0d96457b
 #define CFG_VAR_MASK(x)		((x)&((1U<<CFG_INPUT_SHIFT)-1))
 #define CFG_INPUT_MASK(x)	((x)&((1U<<(2*CFG_INPUT_SHIFT))-(1U<<CFG_INPUT_SHIFT)))
 
709acbb7
 #define CFG_ATOMIC		(1U<<(2*CFG_INPUT_SHIFT))	/*!< atomic change is allowed */
 #define CFG_READONLY		(1U<<(2*CFG_INPUT_SHIFT+1))	/*!< variable is read-only */
 #define CFG_CB_ONLY_ONCE	(1U<<(2*CFG_INPUT_SHIFT+2))	/*!< per-child process callback needs to be called only once */
a903fdab
 
33bfeb9d
 typedef int (*cfg_on_change)(void *, str *, str *, void **);
 typedef void (*cfg_on_set_child)(str *, str *);
a903fdab
 
709acbb7
 /*! \brief structrure to be used by the module interface */
a903fdab
 typedef struct _cfg_def {
 	char	*name;
 	unsigned int	type;
 	int	min;
 	int	max;
709acbb7
 	cfg_on_change		on_change_cb;
a903fdab
 	cfg_on_set_child	on_set_child_cb;
 	char	*descr;
 } cfg_def_t;
 
709acbb7
 /*! \brief declares a new cfg group
a903fdab
  * handler is set to the memory area where the variables are stored
  * return value is -1 on error
  */
 int cfg_declare(char *group_name, cfg_def_t *def, void *values, int def_size,
 			void **handler);
 
b7cfc0a8
 #define cfg_sizeof(gname) \
a903fdab
 	sizeof(struct cfg_group_##gname)
 
 #define cfg_get(gname, handle, var) \
 	((struct cfg_group_##gname *)handle)->var
 
709acbb7
 /*! \brief declares a single variable with integer type */
c092bd34
 int cfg_declare_int(char *group_name, char *var_name,
 		int val, int min, int max, char *descr);
140137c9
 
709acbb7
 /*! \brief declares a single variable with str type */
140137c9
 int cfg_declare_str(char *group_name, char *var_name, char *val, char *descr);
 
709acbb7
 /*! \brief Add a variable to a group instance with integer type.
9235f7d5
  * The group instance is created if it does not exist.
  * wrapper function for new_add_var()
  */
 int cfg_ginst_var_int(char *group_name, unsigned int group_id, char *var_name,
 			int val);
 
709acbb7
 /*! \brief Add a variable to a group instance with string type.
9235f7d5
  * The group instance is created if it does not exist.
  * wrapper function for new_add_var()
  */
 int cfg_ginst_var_string(char *group_name, unsigned int group_id, char *var_name,
 			char *val);
 
709acbb7
 /*! \brief Create a new group instance.
9235f7d5
  * wrapper function for new_add_var()
  */
 int cfg_new_ginst(char *group_name, unsigned int group_id);
 
709acbb7
 /*! \brief returns the handle of a cfg group */
dac83b83
 void **cfg_get_handle(char *gname);
 
a903fdab
 #endif /* _CFG_H */