4 * Copyright (C) 2008 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 * 2008-01-10 Initial version (Miklos)
33 #include "../select.h"
35 #include "cfg_struct.h"
36 #include "cfg_select.h"
38 int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
44 static char buf[INT2STR_MAX_LEN];
49 /* two parameters are mandatory, group name and variable name */
51 LOG(L_ERR, "ERROR: select_cfg_var(): two parameters are expected\n");
55 if ((s->params[1].type != SEL_PARAM_STR)
56 || (s->params[2].type != SEL_PARAM_STR)) {
57 LOG(L_ERR, "ERROR: select_cfg_var(): string parameters are expected\n");
61 /* look-up the group and the variable */
62 if (cfg_lookup_var(&s->params[1].v.s, &s->params[2].v.s, &group, &var)) {
63 LOG(L_ERR, "ERROR: select_cfg_var(): unknown variable\n");
67 if (var->def->on_change_cb) {
68 /* fixup function is defined -- safer to return an error
69 than an incorrect value */
70 LOG(L_ERR, "ERROR: select_cfg_var(): variable cannot be retrieved\n");
74 s->params[1].type = SEL_PARAM_PTR;
75 s->params[1].v.p = (void *)group;
77 s->params[2].type = SEL_PARAM_PTR;
78 s->params[2].v.p = (void *)var;
82 group = (cfg_group_t *)s->params[1].v.p;
83 var = (cfg_mapping_t *)s->params[2].v.p;
85 /* use the module's handle to access the variable, so the variables
86 are read from private memory */
87 p = *(group->handle) + var->offset;
89 switch (CFG_VAR_TYPE(var)) {
91 memcpy(&i, p, sizeof(int));
92 res->len = snprintf(buf, sizeof(buf)-1, "%d", i);
98 memcpy(&res->s, p, sizeof(char *));
99 res->len = strlen(res->s);
103 memcpy(res, p, sizeof(str));