Browse code

cfg framework: @cfg_get supports nested calls

@cfg_get.<group>.<variable> makes use of the already implemented
nested select functions to parse the returned value. The following
nested calls are supported:

- @cfg.get.<group>.<variable>.nameaddr...
- @cfg.get.<group>.<variable>.uri...
- @cfg.get.<group>.<variable>.params...

Credits go to Tomas Mandys

Miklos Tirpak authored on 31/01/2011 16:36:59
Showing 2 changed files
... ...
@@ -149,8 +149,8 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
149 149
 		/* fixup call */
150 150
 
151 151
 		/* two parameters are mandatory, group name and variable name */
152
-		if (s->n != 3) {
153
-			LOG(L_ERR, "ERROR: select_cfg_var(): two parameters are expected\n");
152
+		if (s->n < 3) {
153
+			LOG(L_ERR, "ERROR: select_cfg_var(): At least two parameters are expected\n");
154 154
 			return -1;
155 155
 		}
156 156
 
... ...
@@ -240,6 +240,9 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
240 240
 	return 0;
241 241
 }
242 242
 
243
+/* fake function to eat the first parameter of @cfg_get */
244
+ABSTRACT_F(select_cfg_var1)
245
+
243 246
 /* fix-up function for read_cfg_var()
244 247
  *
245 248
  * return value:
... ...
@@ -215,6 +215,7 @@ SELECT_F(select_identity)
215 215
 SELECT_F(select_identity_info)
216 216
 
217 217
 SELECT_F(select_cfg_var)
218
+SELECT_F(select_cfg_var1)
218 219
 SELECT_F(cfg_selected_inst)
219 220
 
220 221
 static select_row_t select_core[] = {
... ...
@@ -410,9 +411,14 @@ static select_row_t select_core[] = {
410 410
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("identity"), select_identity, 0},
411 411
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("identity_info"), select_identity_info, 0},
412 412
 
413
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cfg_get"), select_cfg_var, CONSUME_ALL | FIXUP_CALL },
413
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cfg_get"), select_cfg_var1, SEL_PARAM_EXPECTED | CONSUME_NEXT_STR},
414
+	{ select_cfg_var1, SEL_PARAM_STR, STR_NULL, select_cfg_var, FIXUP_CALL },
414 415
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cfg_selected"), cfg_selected_inst, CONSUME_NEXT_STR | FIXUP_CALL },
415 416
 
417
+	{ select_cfg_var, SEL_PARAM_STR, STR_STATIC_INIT("nameaddr"), select_any_nameaddr, NESTED | CONSUME_NEXT_STR},
418
+	{ select_cfg_var, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_any_uri, NESTED | CONSUME_NEXT_STR},
419
+	{ select_cfg_var, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_anyheader_params, NESTED},
420
+
416 421
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
417 422
 };
418 423