2
0
Эх сурвалжийг харах

core: pv - added wrapper to set function

- wrapper for PV set function that takes in consideration cases of
  altering the msg context
Daniel-Constantin Mierla 16 жил өмнө
parent
commit
858146a991
2 өөрчлөгдсөн 16 нэмэгдсэн , 0 устгасан
  1. 11 0
      pvapi.c
  2. 5 0
      pvar.h

+ 11 - 0
pvapi.c

@@ -35,6 +35,7 @@
 #include "ut.h"
 #include "dprint.h"
 #include "hashes.h"
+#include "route.h"
 #include "pvar.h"
 
 #define is_in_str(p, in) (p<in->s+in->len && *p)
@@ -920,6 +921,16 @@ int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value)
 	return ret;
 }
 
+int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
+		pv_value_t *value)
+{
+	if(sp==NULL || !pv_is_w(sp))
+		return 0; /* no op */
+	if(pv_alter_context(sp) && is_route_type(LOCAL_ROUTE))
+		return 0; /* no op */
+	return sp->setf(msg, &sp->pvp, op, value);
+}
+
 /**
  *
  */

+ 5 - 0
pvar.h

@@ -134,6 +134,9 @@ typedef int (*pv_parse_name_f)(pv_spec_p sp, str *in);
 typedef int (*pv_parse_index_f)(pv_spec_p sp, str *in);
 typedef int (*pv_init_param_f)(pv_spec_p sp, int param);
 
+#define pv_alter_context(pv)	((pv)->type==PVT_CONTEXT \
+									|| (pv)->type==PVT_BRANCH)
+
 /*! \brief
  * PV spec format:
  * - $class_name
@@ -166,6 +169,8 @@ typedef struct _pv_elem
 char* pv_parse_spec2(str *in, pv_spec_p sp, int silent);
 #define pv_parse_spec(in, sp) pv_parse_spec2((in), (sp), 0)
 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
+int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
+		pv_value_t *value);
 int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
 int pv_elem_free_all(pv_elem_p log);
 void pv_value_destroy(pv_value_t *val);