Explorar el Código

pv: new config var - $sbranch(key)

- a static branch structure that can be used for config operations
- the key can be like for $branch(key)
- the static branch is not used for outbound routing, it is just a
  local container
Daniel-Constantin Mierla hace 10 años
padre
commit
0f8da1746e
Se han modificado 3 ficheros con 58 adiciones y 18 borrados
  1. 3 0
      modules/pv/pv.c
  2. 50 18
      modules/pv/pv_branch.c
  3. 5 0
      modules/pv/pv_branch.h

+ 3 - 0
modules/pv/pv.c

@@ -68,6 +68,9 @@ static pv_export_t mod_pvs[] = {
 	{ {"branch", sizeof("branch")-1}, /* branch attributes */
 		PVT_CONTEXT, pv_get_branchx, pv_set_branchx,
 		pv_parse_branchx_name, pv_parse_index, 0, 0 },
+	{ {"sbranch", sizeof("sbranch")-1}, /* static branch attributes */
+		PVT_CONTEXT, pv_get_sbranch, pv_set_sbranch,
+		pv_parse_branchx_name, 0, 0, 0 },
 	{ {"mi", (sizeof("mi")-1)}, /* message id */
 		PVT_OTHER, pv_get_msgid, 0,
 		0, 0, 0, 0},

+ 50 - 18
modules/pv/pv_branch.c

@@ -27,22 +27,27 @@
 #include "pv_core.h"
 #include "pv_branch.h"
 
-int pv_get_branchx(struct sip_msg *msg, pv_param_t *param,
-		pv_value_t *res)
+static branch_t _pv_sbranch = {0};
+
+int pv_get_branchx_helper(sip_msg_t *msg, pv_param_t *param,
+		pv_value_t *res, int btype)
 {
 	int idx = 0;
 	int idxf = 0;
 	branch_t *br;
 
-	/* get the index */
-	if(pv_get_spec_index(msg, param, &idx, &idxf)!=0)
-	{
-		LM_ERR("invalid index\n");
-		return pv_get_null(msg, param, res);
+	if(btype==1) {
+		br = &_pv_sbranch;
+	} else {
+		/* get the index */
+		if(pv_get_spec_index(msg, param, &idx, &idxf)!=0)
+		{
+			LM_ERR("invalid index\n");
+			return pv_get_null(msg, param, res);
+		}
+		br = get_sip_branch(idx);
 	}
 
-	br = get_sip_branch(idx);
-
 	/* branch(count) doesn't need a valid branch, everything else does */
 	if(br->len == 0 && ( param->pvn.u.isname.name.n != 5/* count*/ ))
 	{
@@ -88,8 +93,14 @@ int pv_get_branchx(struct sip_msg *msg, pv_param_t *param,
 	return 0;
 }
 
-int pv_set_branchx(struct sip_msg* msg, pv_param_t *param,
-		int op, pv_value_t *val)
+int pv_get_branchx(sip_msg_t *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	return pv_get_branchx_helper(msg, param, res, 0);
+}
+
+int pv_set_branchx_helper(sip_msg_t *msg, pv_param_t *param,
+		int op, pv_value_t *val, int btype)
 {
 	int idx = 0;
 	int idxf = 0;
@@ -105,15 +116,18 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param,
 		return -1;
 	}
 
-	/* get the index */
-	if(pv_get_spec_index(msg, param, &idx, &idxf)!=0)
-	{
-		LM_ERR("invalid index\n");
-		return -1;
+	if(btype==1) {
+		br = &_pv_sbranch;
+	} else {
+		/* get the index */
+		if(pv_get_spec_index(msg, param, &idx, &idxf)!=0)
+		{
+			LM_ERR("invalid index\n");
+			return -1;
+		}
+		br = get_sip_branch(idx);
 	}
 
-	br = get_sip_branch(idx);
-
 	if(br==NULL)
 	{
 		LM_DBG("no branch to operate on\n");
@@ -283,6 +297,12 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param,
 	return 0;
 }
 
+int pv_set_branchx(sip_msg_t *msg, pv_param_t *param,
+		int op, pv_value_t *val)
+{
+	return pv_set_branchx_helper(msg, param, op, val, 0);
+}
+
 int pv_parse_branchx_name(pv_spec_p sp, str *in)
 {
 	if(sp==NULL || in==NULL || in->len<=0)
@@ -339,6 +359,18 @@ error:
 	return -1;
 }
 
+int pv_get_sbranch(sip_msg_t *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	return pv_get_branchx_helper(msg, param, res, 1);
+}
+
+int pv_set_sbranch(sip_msg_t *msg, pv_param_t *param,
+		int op, pv_value_t *val)
+{
+	return pv_set_branchx_helper(msg, param, op, val, 1);
+}
+
 int pv_get_sndfrom(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 {

+ 5 - 0
modules/pv/pv_branch.h

@@ -29,6 +29,11 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param,
 		int op, pv_value_t *val);
 int pv_parse_branchx_name(pv_spec_p sp, str *in);
 
+int pv_get_sbranch(sip_msg_t *msg, pv_param_t *param,
+		pv_value_t *res);
+int pv_set_sbranch(sip_msg_t *msg, pv_param_t *param,
+		int op, pv_value_t *val);
+
 int pv_get_sndto(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 int pv_get_sndfrom(struct sip_msg *msg, pv_param_t *param,