Browse code

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 authored on 27/04/2009 11:04:04
Showing 2 changed files
... ...
@@ -35,6 +35,7 @@
35 35
 #include "ut.h"
36 36
 #include "dprint.h"
37 37
 #include "hashes.h"
38
+#include "route.h"
38 39
 #include "pvar.h"
39 40
 
40 41
 #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)
920 921
 	return ret;
921 922
 }
922 923
 
924
+int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
925
+		pv_value_t *value)
926
+{
927
+	if(sp==NULL || !pv_is_w(sp))
928
+		return 0; /* no op */
929
+	if(pv_alter_context(sp) && is_route_type(LOCAL_ROUTE))
930
+		return 0; /* no op */
931
+	return sp->setf(msg, &sp->pvp, op, value);
932
+}
933
+
923 934
 /**
924 935
  *
925 936
  */
... ...
@@ -134,6 +134,9 @@ typedef int (*pv_parse_name_f)(pv_spec_p sp, str *in);
134 134
 typedef int (*pv_parse_index_f)(pv_spec_p sp, str *in);
135 135
 typedef int (*pv_init_param_f)(pv_spec_p sp, int param);
136 136
 
137
+#define pv_alter_context(pv)	((pv)->type==PVT_CONTEXT \
138
+									|| (pv)->type==PVT_BRANCH)
139
+
137 140
 /*! \brief
138 141
  * PV spec format:
139 142
  * - $class_name
... ...
@@ -166,6 +169,8 @@ typedef struct _pv_elem
166 169
 char* pv_parse_spec2(str *in, pv_spec_p sp, int silent);
167 170
 #define pv_parse_spec(in, sp) pv_parse_spec2((in), (sp), 0)
168 171
 int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
172
+int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
173
+		pv_value_t *value);
169 174
 int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
170 175
 int pv_elem_free_all(pv_elem_p log);
171 176
 void pv_value_destroy(pv_value_t *val);