Module: sip-router
Branch: master
Commit: f9afe8b64410f66b39513e6bfcedf3ffc71c16a8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f9afe8b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Aug 12 16:00:35 2010 +0200
pv: allow From header attributes to be updated with assignment
- same as for To header attributes
- writable PVs: $fu, $fU, $fd and $fn
---
modules_k/pv/pv.c | 14 +++++++-------
modules_k/pv/pv_core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
modules_k/pv/pv_core.h | 12 ++++++++++++
3 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index dece906..2a79578 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -178,13 +178,13 @@ static pv_export_t mod_pvs[] = {
PVT_OTHER, pv_get_errinfo_attr, 0,
0, 0, pv_init_iname, 4},
{{"fd", (sizeof("fd")-1)}, /* */
- PVT_OTHER, pv_get_from_attr, 0,
+ PVT_OTHER, pv_get_from_attr, pv_set_from_domain,
0, 0, pv_init_iname, 3},
{{"from.domain", (sizeof("from.domain")-1)}, /* */
- PVT_OTHER, pv_get_from_attr, 0,
+ PVT_OTHER, pv_get_from_attr, pv_set_from_domain,
0, 0, pv_init_iname, 3},
{{"fn", (sizeof("fn")-1)}, /* */
- PVT_OTHER, pv_get_from_attr, 0,
+ PVT_OTHER, pv_get_from_attr, pv_set_from_display,
0, 0, pv_init_iname, 5},
{{"fs", (sizeof("fs")-1)}, /* */
PVT_OTHER, pv_get_force_sock, pv_set_force_sock,
@@ -193,16 +193,16 @@ static pv_export_t mod_pvs[] = {
PVT_OTHER, pv_get_from_attr, 0,
0, 0, pv_init_iname, 4},
{{"fu", (sizeof("fu")-1)}, /* */
- PVT_FROM, pv_get_from_attr, 0,
+ PVT_FROM, pv_get_from_attr, pv_set_from_uri,
0, 0, pv_init_iname, 1},
{{"from", (sizeof("from")-1)}, /* */
- PVT_FROM, pv_get_from_attr, 0,
+ PVT_FROM, pv_get_from_attr, pv_set_from_uri,
0, 0, pv_init_iname, 1},
{{"fU", (sizeof("fU")-1)}, /* */
- PVT_OTHER, pv_get_from_attr, 0,
+ PVT_OTHER, pv_get_from_attr, pv_set_from_username,
0, 0, pv_init_iname, 2},
{{"from.user", (sizeof("from.user")-1)}, /* */
- PVT_OTHER, pv_get_from_attr, 0,
+ PVT_OTHER, pv_get_from_attr, pv_set_from_username,
0, 0, pv_init_iname, 2},
{{"mb", (sizeof("mb")-1)}, /* */
PVT_OTHER, pv_get_msg_buf, 0,
diff --git a/modules_k/pv/pv_core.c b/modules_k/pv/pv_core.c
index d434d70..b69df2a 100644
--- a/modules_k/pv/pv_core.c
+++ b/modules_k/pv/pv_core.c
@@ -2203,7 +2203,7 @@ int pv_set_to_attr(struct sip_msg* msg, pv_param_t *param,
return -1;
}
if(parse_to_uri(msg)==NULL) {
- LM_ERR("cannot parse To header\n");
+ LM_ERR("cannot parse To header URI\n");
return -1;
}
return pv_set_xto_attr(msg, param, op, val, get_to(msg), type);
@@ -2233,6 +2233,49 @@ int pv_set_to_display(struct sip_msg* msg, pv_param_t *param,
return pv_set_to_attr(msg, param, op, val, 3);
}
+int pv_set_from_attr(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val, int type)
+{
+ if(msg==NULL)
+ return -1;
+
+ if(parse_from_header(msg)<0)
+ {
+ LM_ERR("failed to parse From header\n");
+ return -1;
+ }
+ if(parse_from_uri(msg)==NULL)
+ {
+ LM_ERR("cannot parse From header URI\n");
+ return -1;
+ }
+ return pv_set_xto_attr(msg, param, op, val, get_from(msg), type);
+}
+
+int pv_set_from_uri(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val)
+{
+ return pv_set_from_attr(msg, param, op, val, 0);
+}
+
+int pv_set_from_username(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val)
+{
+ return pv_set_from_attr(msg, param, op, val, 1);
+}
+
+int pv_set_from_domain(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val)
+{
+ return pv_set_from_attr(msg, param, op, val, 2);
+}
+
+int pv_set_from_display(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val)
+{
+ return pv_set_from_attr(msg, param, op, val, 3);
+}
+
/********* end PV set functions *********/
int pv_parse_scriptvar_name(pv_spec_p sp, str *in)
diff --git a/modules_k/pv/pv_core.h b/modules_k/pv/pv_core.h
index 418632a..a3c8a60 100644
--- a/modules_k/pv/pv_core.h
+++ b/modules_k/pv/pv_core.h
@@ -244,6 +244,18 @@ int pv_set_to_domain(struct sip_msg* msg, pv_param_t *param,
int pv_set_to_display(struct sip_msg* msg, pv_param_t *param,
int op, pv_value_t *val);
+int pv_set_from_uri(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val);
+
+int pv_set_from_username(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val);
+
+int pv_set_from_domain(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val);
+
+int pv_set_from_display(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val);
+
/********* end PV set functions *********/
int pv_parse_scriptvar_name(pv_spec_p sp, str *in);