4 * Copyright (C) 2007 iptelorg GmbH
6 * This file is part of ser, a free SIP server.
8 * ser is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version
13 * For a license to use the ser software under conditions
14 * other than those described here, or to purchase support for this
15 * software, please contact iptel.org by e-mail at the following addresses:
18 * ser is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * 2007-12-03 Initial version (Miklos)
36 #include "../locking.h"
38 #include "cfg_struct.h"
40 /* linked list of variables with their new values */
41 typedef struct _cfg_changed_var {
44 struct _cfg_changed_var *next;
46 /* blob that contains the new value */
47 unsigned char new_val[1];
50 /* callback that is called when a new group is declared */
51 typedef void (*cfg_on_declare)(str *, cfg_def_t *);
53 /* linked list of registered contexts */
54 typedef struct _cfg_ctx {
55 /* variables that are already changed
56 but have not been committed yet */
57 cfg_changed_var_t *changed_first;
58 cfg_changed_var_t *changed_last;
59 /* lock potecting the the linked-list of
63 /* callback that is called when a new
64 group is registered */
65 cfg_on_declare on_declare_cb;
67 struct _cfg_ctx *next;
70 #define CFG_CTX_LOCK(ctx) lock_get(&(ctx)->lock)
71 #define CFG_CTX_UNLOCK(ctx) lock_release(&(ctx)->lock)
73 /* creates a new config context that is an interface to the
74 * cfg variables with write permission */
75 cfg_ctx_t *cfg_register_ctx(cfg_on_declare on_declare_cb);
77 /* free the memory allocated for the contexts */
78 void cfg_ctx_destroy(void);
80 /* set the value of a variable without the need of explicit commit */
81 int cfg_set_now(cfg_ctx_t *ctx, str *group_name, str *var_name,
82 void *val, unsigned int val_type);
83 int cfg_set_now_int(cfg_ctx_t *ctx, str *group_name, str *var_name, int val);
84 int cfg_set_now_string(cfg_ctx_t *ctx, str *group_name, str *var_name, char *val);
85 int cfg_set_now_str(cfg_ctx_t *ctx, str *group_name, str *var_name, str *val);
87 /* sets the value of a variable but does not commit the change */
88 int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
89 void *val, unsigned int val_type);
90 int cfg_set_delayed_int(cfg_ctx_t *ctx, str *group_name, str *var_name, int val);
91 int cfg_set_delayed_string(cfg_ctx_t *ctx, str *group_name, str *var_name, char *val);
92 int cfg_set_delayed_str(cfg_ctx_t *ctx, str *group_name, str *var_name, str *val);
94 /* commits the previously prepared changes within the context */
95 int cfg_commit(cfg_ctx_t *ctx);
97 /* drops the not yet committed changes within the context */
98 int cfg_rollback(cfg_ctx_t *ctx);
100 /* returns the value of a variable */
101 int cfg_get_by_name(cfg_ctx_t *ctx, str *group_name, str *var_name,
102 void **val, unsigned int *val_type);
104 /* returns the description of a variable */
105 int cfg_help(cfg_ctx_t *ctx, str *group_name, str *var_name,
106 char **ch, unsigned int *input_type);
108 /* notify the drivers about the new config definition */
109 void cfg_notify_drivers(char *group_name, int group_name_len, cfg_def_t *def);
111 /* initialize the handle for cfg_get_group_next() */
112 #define cfg_get_group_init(handle) \
113 (*(handle)) = (void *)cfg_group
115 /* returns the group name and the cfg structure definition,
116 * and moves the handle to the next group
121 * can be used as follows:
124 * cfg_get_group_init(&handle)
125 * while (cfg_get_group_next(&handle, &name, &def)) {
129 int cfg_get_group_next(void **h,
130 str *gname, cfg_def_t **def);
132 /* Initialize the handle for cfg_diff_next()
133 * WARNING: keeps the context lock held, do not forget
134 * to release it with cfg_diff_release()
136 int cfg_diff_init(cfg_ctx_t *ctx,
139 /* return the pending changes that have not been
141 * can be used as follows:
144 * if (cfg_diff_init(ctx, &handle)) return -1
145 * while (cfg_diff_next(&handle
146 * &group_name, &var_name,
152 * cfg_diff_release(ctx);
154 int cfg_diff_next(void **h,
155 str *gname, str *vname,
156 void **old_val, void **new_val,
157 unsigned int *val_type);
159 /* destroy the handle of cfg_diff_next() */
160 void cfg_diff_release(cfg_ctx_t *ctx);
162 #endif /* _CFG_CTX_H */