Module: sip-router
Branch: tirpi/cfg_framework_multivalue
Commit: 9235f7d58df3ec883d4749de3b37bd493bc9bde2
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9235f7d…
Author: Miklos Tirpak <miklos(a)iptel.org>
Committer: Miklos Tirpak <miklos(a)iptel.org>
Date: Wed Sep 29 16:40:30 2010 +0200
cfg framework: group instance support in the script
Variables within group instances can be set from the script,
for example:
tm[2].reparse_invite = 0;
tm[2].default_reason = "New reason";
Any assignmnet within a group instance creates the entire instance if
it does not exist yet.
Note: does not work with core variables yet.
---
cfg.y | 10 ++++++++++
cfg/cfg.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
cfg/cfg.h | 19 +++++++++++++++++++
3 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/cfg.y b/cfg.y
index d98372d..c43792b 100644
--- a/cfg.y
+++ b/cfg.y
@@ -1632,6 +1632,16 @@ cfg_var:
| cfg_var_id DOT cfg_var_id EQUAL error {
yyerror("number or string expected");
}
+ | cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL NUMBER {
+ if (cfg_ginst_var_int($1, $3, $6, $8)) {
+ yyerror("variable cannot be added to the group instance");
+ }
+ }
+ | cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL STRING {
+ if (cfg_ginst_var_string($1, $3, $6, $8)) {
+ yyerror("variable cannot be added to the group instance");
+ }
+ }
;
module_stm:
diff --git a/cfg/cfg.c b/cfg/cfg.c
index 88a34b2..2d0f640 100644
--- a/cfg/cfg.c
+++ b/cfg/cfg.c
@@ -227,6 +227,56 @@ int cfg_declare_str(char *group_name, char *var_name, char *val, char
*descr)
return 0;
}
+/* Add a varibale to a group instance with integer type.
+ * 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)
+{
+ str gname, vname;
+
+ gname.s = group_name;
+ gname.len = strlen(group_name);
+ vname.s = var_name;
+ vname.len = strlen(var_name);
+
+ return new_add_var(&gname, group_id, &vname,
+ (void *)(long)val, CFG_VAR_INT);
+}
+
+/* Add a varibale to a group instance with string type.
+ * 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)
+{
+ str gname, vname;
+
+ gname.s = group_name;
+ gname.len = strlen(group_name);
+ vname.s = var_name;
+ vname.len = strlen(var_name);
+
+ return new_add_var(&gname, group_id, &vname,
+ (void *)val, CFG_VAR_STRING);
+}
+
+/* Create a new group instance.
+ * wrapper function for new_add_var()
+ */
+int cfg_new_ginst(char *group_name, unsigned int group_id)
+{
+ str gname;
+
+ gname.s = group_name;
+ gname.len = strlen(group_name);
+
+ return new_add_var(&gname, group_id, NULL /* var */,
+ NULL /* val */, 0 /* type */);
+}
+
/* returns the handle of a cfg group */
void **cfg_get_handle(char *gname)
{
diff --git a/cfg/cfg.h b/cfg/cfg.h
index 8691805..b196d26 100644
--- a/cfg/cfg.h
+++ b/cfg/cfg.h
@@ -87,6 +87,25 @@ int cfg_declare_int(char *group_name, char *var_name,
/* declares a single variable with str type */
int cfg_declare_str(char *group_name, char *var_name, char *val, char *descr);
+/* Add a varibale to a group instance with integer type.
+ * 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);
+
+/* Add a varibale to a group instance with string type.
+ * 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);
+
+/* Create a new group instance.
+ * wrapper function for new_add_var()
+ */
+int cfg_new_ginst(char *group_name, unsigned int group_id);
+
/* returns the handle of a cfg group */
void **cfg_get_handle(char *gname);