Browse Source

pv: added $_s(format) variable

- evaluate the format as a dynamic string

$var(x) = "sip:" + $rU + "@" + $fd;

is equivalent of:

$var(x) = $_s(sip:$rU@$fd);

- it can be more compact sometimes in config
Daniel-Constantin Mierla 12 years ago
parent
commit
28942a00bc
3 changed files with 48 additions and 0 deletions
  1. 2 0
      modules/pv/pv.c
  2. 41 0
      modules/pv/pv_core.c
  3. 5 0
      modules/pv/pv_core.h

+ 2 - 0
modules/pv/pv.c

@@ -63,6 +63,8 @@ static tr_export_t mod_trans[] = {
 };
 };
 
 
 static pv_export_t mod_pvs[] = {
 static pv_export_t mod_pvs[] = {
+	{ {"_s", (sizeof("_s")-1)}, PVT_OTHER, pv_get__s, 0,
+		pv_parse__s_name, 0, 0, 0 },
 	{ {"af", (sizeof("af")-1)}, PVT_OTHER, pv_get_af, 0,
 	{ {"af", (sizeof("af")-1)}, PVT_OTHER, pv_get_af, 0,
 		pv_parse_af_name, 0, 0, 0 },
 		pv_parse_af_name, 0, 0, 0 },
 	{ {"branch", sizeof("branch")-1}, /* branch attributes */
 	{ {"branch", sizeof("branch")-1}, /* branch attributes */

+ 41 - 0
modules/pv/pv_core.c

@@ -2898,3 +2898,44 @@ int pv_get_K(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
 			return pv_get_uintval(msg, param, res, AF_INET);
 			return pv_get_uintval(msg, param, res, AF_INET);
 	}
 	}
 }
 }
+
+/**
+ *
+ */
+int pv_parse__s_name(pv_spec_p sp, str *in)
+{
+	pv_elem_t *fmt = NULL;
+
+	if(in->s==NULL || in->len<=0)
+		return -1;
+	if(pv_parse_format(in, &fmt)<0 || fmt==NULL)
+	{
+		LM_ERR("wrong format[%.*s]\n", in->len, in->s);
+		return -1;
+	}
+	sp->pvp.pvn.u.dname = (void*)fmt;
+	sp->pvp.pvn.type = PV_NAME_OTHER;
+	return 0;
+}
+
+/**
+ *
+ */
+int pv_get__s(sip_msg_t *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	str sdata = {0};
+	pv_elem_t *fmt = NULL;
+	fmt = (pv_elem_t*)param->pvn.u.dname;
+
+	if(fmt==NULL)
+	{
+		return pv_get_null(msg, param, res);
+	}
+	if(pv_printf_s(msg, fmt, &sdata)!=0)
+	{
+		LM_ERR("cannot evaluate the string\n");
+		return -1;
+	}
+	return pv_get_strval(msg, param, res, &sdata);
+}

+ 5 - 0
modules/pv/pv_core.h

@@ -315,5 +315,10 @@ int pv_get_K(sip_msg_t *msg, pv_param_t *param,
 
 
 int pv_parse_flag_param(pv_spec_p sp, str *in);
 int pv_parse_flag_param(pv_spec_p sp, str *in);
 
 
+int pv_parse__s_name(pv_spec_p sp, str *in);
+
+int pv_get__s(sip_msg_t *msg, pv_param_t *param,
+		pv_value_t *res);
+
 #endif
 #endif