Browse code

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.

Miklos Tirpak authored on 29/09/2010 14:40:30
Showing 3 changed files
... ...
@@ -1632,6 +1632,16 @@ cfg_var:
1632 1632
 	| cfg_var_id DOT cfg_var_id EQUAL error { 
1633 1633
 		yyerror("number or string expected"); 
1634 1634
 	}
1635
+	| cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL NUMBER {
1636
+		if (cfg_ginst_var_int($1, $3, $6, $8)) {
1637
+			yyerror("variable cannot be added to the group instance");
1638
+		}
1639
+	}
1640
+	| cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL STRING {
1641
+		if (cfg_ginst_var_string($1, $3, $6, $8)) {
1642
+			yyerror("variable cannot be added to the group instance");
1643
+		}
1644
+	}
1635 1645
 	;
1636 1646
 
1637 1647
 module_stm:
... ...
@@ -227,6 +227,56 @@ int cfg_declare_str(char *group_name, char *var_name, char *val, char *descr)
227 227
 	return 0;
228 228
 }
229 229
 
230
+/* Add a varibale to a group instance with integer type.
231
+ * The group instance is created if it does not exist.
232
+ * wrapper function for new_add_var()
233
+ */
234
+int cfg_ginst_var_int(char *group_name, unsigned int group_id, char *var_name,
235
+			int val)
236
+{
237
+	str	gname, vname;
238
+
239
+	gname.s = group_name;
240
+	gname.len = strlen(group_name);
241
+	vname.s = var_name;
242
+	vname.len = strlen(var_name);
243
+
244
+	return new_add_var(&gname, group_id, &vname,
245
+			(void *)(long)val, CFG_VAR_INT);
246
+}
247
+
248
+/* Add a varibale to a group instance with string type.
249
+ * The group instance is created if it does not exist.
250
+ * wrapper function for new_add_var()
251
+ */
252
+int cfg_ginst_var_string(char *group_name, unsigned int group_id, char *var_name,
253
+			char *val)
254
+{
255
+	str	gname, vname;
256
+
257
+	gname.s = group_name;
258
+	gname.len = strlen(group_name);
259
+	vname.s = var_name;
260
+	vname.len = strlen(var_name);
261
+
262
+	return new_add_var(&gname, group_id, &vname,
263
+			(void *)val, CFG_VAR_STRING);
264
+}
265
+
266
+/* Create a new group instance.
267
+ * wrapper function for new_add_var()
268
+ */
269
+int cfg_new_ginst(char *group_name, unsigned int group_id)
270
+{
271
+	str	gname;
272
+
273
+	gname.s = group_name;
274
+	gname.len = strlen(group_name);
275
+
276
+	return new_add_var(&gname, group_id, NULL /* var */,
277
+			NULL /* val */, 0 /* type */);
278
+}
279
+
230 280
 /* returns the handle of a cfg group */
231 281
 void **cfg_get_handle(char *gname)
232 282
 {
... ...
@@ -87,6 +87,25 @@ int cfg_declare_int(char *group_name, char *var_name,
87 87
 /* declares a single variable with str type */
88 88
 int cfg_declare_str(char *group_name, char *var_name, char *val, char *descr);
89 89
 
90
+/* Add a varibale to a group instance with integer 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_int(char *group_name, unsigned int group_id, char *var_name,
95
+			int val);
96
+
97
+/* Add a varibale to a group instance with string type.
98
+ * The group instance is created if it does not exist.
99
+ * wrapper function for new_add_var()
100
+ */
101
+int cfg_ginst_var_string(char *group_name, unsigned int group_id, char *var_name,
102
+			char *val);
103
+
104
+/* Create a new group instance.
105
+ * wrapper function for new_add_var()
106
+ */
107
+int cfg_new_ginst(char *group_name, unsigned int group_id);
108
+
90 109
 /* returns the handle of a cfg group */
91 110
 void **cfg_get_handle(char *gname);
92 111