[sr-dev] git:master: cfg framework: @cfg_get supports nested calls

Miklos Tirpak miklos at iptel.org
Mon Jan 31 17:40:44 CET 2011


Module: sip-router
Branch: master
Commit: 5afd88dd704ff40b3662157d7ea8217e1332b1b5
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5afd88dd704ff40b3662157d7ea8217e1332b1b5

Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date:   Mon Jan 31 17:36:59 2011 +0100

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

---

 cfg/cfg_select.c |    7 +++++--
 select_core.h    |    8 +++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/cfg/cfg_select.c b/cfg/cfg_select.c
index cb0a2f1..e68f9dc 100644
--- a/cfg/cfg_select.c
+++ b/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:
diff --git a/select_core.h b/select_core.h
index 8cec775..b1a8114 100644
--- a/select_core.h
+++ b/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}
 };
 




More information about the sr-dev mailing list