浏览代码

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 14 年之前
父节点
当前提交
5afd88dd70
共有 2 个文件被更改,包括 12 次插入3 次删除
  1. 5 2
      cfg/cfg_select.c
  2. 7 1
      select_core.h

+ 5 - 2
cfg/cfg_select.c

@@ -149,8 +149,8 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
 		/* fixup call */
 
 		/* two parameters are mandatory, group name and variable name */
-		if (s->n != 3) {
-			LOG(L_ERR, "ERROR: select_cfg_var(): two parameters are expected\n");
+		if (s->n < 3) {
+			LOG(L_ERR, "ERROR: select_cfg_var(): At least two parameters are expected\n");
 			return -1;
 		}
 
@@ -240,6 +240,9 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
 	return 0;
 }
 
+/* fake function to eat the first parameter of @cfg_get */
+ABSTRACT_F(select_cfg_var1)
+
 /* fix-up function for read_cfg_var()
  *
  * return value:

+ 7 - 1
select_core.h

@@ -215,6 +215,7 @@ SELECT_F(select_identity)
 SELECT_F(select_identity_info)
 
 SELECT_F(select_cfg_var)
+SELECT_F(select_cfg_var1)
 SELECT_F(cfg_selected_inst)
 
 static select_row_t select_core[] = {
@@ -410,9 +411,14 @@ static select_row_t select_core[] = {
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("identity"), select_identity, 0},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("identity_info"), select_identity_info, 0},
 
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cfg_get"), select_cfg_var, CONSUME_ALL | FIXUP_CALL },
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cfg_get"), select_cfg_var1, SEL_PARAM_EXPECTED | CONSUME_NEXT_STR},
+	{ select_cfg_var1, SEL_PARAM_STR, STR_NULL, select_cfg_var, FIXUP_CALL },
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cfg_selected"), cfg_selected_inst, CONSUME_NEXT_STR | FIXUP_CALL },
 
+	{ select_cfg_var, SEL_PARAM_STR, STR_STATIC_INIT("nameaddr"), select_any_nameaddr, NESTED | CONSUME_NEXT_STR},
+	{ select_cfg_var, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_any_uri, NESTED | CONSUME_NEXT_STR},
+	{ select_cfg_var, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_anyheader_params, NESTED},
+
 	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
 };