Module: sip-router
Branch: jason.penton/kamailio_ims_extensions
Commit: a7c15341c5e0b4303842b3e3dc457dddbb541e4a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a7c1534…
Author: Jason Penton <jason.penton(a)gmail.com>
Committer: Jason Penton <jason.penton(a)gmail.com>
Date: Thu Oct 20 09:21:40 2011 +0200
rr: added possibility to add custom user to record route header
- Added AVP to be set before calling record route to allow for custom user
in record route headers. This is required in IMS instances, for example
mo@... for mobile originating route
---
modules_k/rr/doc/rr_admin.xml | 18 ++++++++++++++++++
modules_k/rr/record.c | 36 +++++++++++++++++++++++++++++++++++-
modules_k/rr/record.h | 4 +++-
modules_k/rr/rr_mod.c | 17 ++++++++++++++++-
4 files changed, 72 insertions(+), 3 deletions(-)
diff --git a/modules_k/rr/doc/rr_admin.xml b/modules_k/rr/doc/rr_admin.xml
index 8eb248e..d4906bf 100644
--- a/modules_k/rr/doc/rr_admin.xml
+++ b/modules_k/rr/doc/rr_admin.xml
@@ -212,6 +212,24 @@ modparam("rr", "add_username", 1)
</programlisting>
</example>
</section>
+
+ <section>
+ <title><varname>custom_user_avp</varname> (string)</title>
+ <para>
+ AVP to populate for custom user of record_route. If not set,
+ default URI user is used
+ </para>
+ <example>
+ <title>Set <varname>add_username</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("rr", "custom_user_avp", "$avp(i:20")
+$avp(i:20)="my_custom_user";
+record_route();
+...
+</programlisting>
+ </example>
+ </section>
<section>
<title><varname>enable_socket_mismatch_warning</varname>
(integer)</title>
diff --git a/modules_k/rr/record.c b/modules_k/rr/record.c
index 629c38a..525a7e7 100644
--- a/modules_k/rr/record.c
+++ b/modules_k/rr/record.c
@@ -74,6 +74,37 @@
static char rr_param_buf_ptr[RR_PARAM_BUF_SIZE];
static str rr_param_buf = {rr_param_buf_ptr,0};
static unsigned int rr_param_msg;
+static pv_spec_t *custom_user_avp; /*!< AVP for custom_user setting */
+
+
+void init_custom_user(pv_spec_t *custom_user_avp_p)
+{
+ custom_user_avp = custom_user_avp_p;
+}
+
+/*!
+ * \brief Return the custom_user for a record route
+ * \param req SIP message
+ * \param custom_user to be returned
+ * \return <0 for failure
+ */
+inline static int get_custom_user(struct sip_msg *req, str *custom_user)
+{
+ pv_value_t pv_val;
+
+ if( custom_user_avp ) {
+ if ( pv_get_spec_value( req, custom_user_avp, &pv_val)==0 &&
+ pv_val.flags&PV_VAL_STR && pv_val.rs.len>0 ) {
+ custom_user->s = pv_val.rs.s;
+ custom_user->len = pv_val.rs.len;
+ return 0;
+ }
+ LM_DBG("invalid AVP value, using default user from RURI\n");
+ }
+
+ return -1;
+
+}
/*!
@@ -281,14 +312,17 @@ int record_route(struct sip_msg* _m, str *params)
str user;
struct to_body* from = NULL;
str* tag;
-
+
user.len = 0;
if (add_username) {
+ /* check if there is a custom user set */
+ if (get_custom_user(_m, &user) < 0) {
if (get_username(_m, &user) < 0) {
LM_ERR("failed to extract username\n");
return -1;
}
+ }
}
if (append_fromtag) {
diff --git a/modules_k/rr/record.h b/modules_k/rr/record.h
index f1ec944..0a96d24 100644
--- a/modules_k/rr/record.h
+++ b/modules_k/rr/record.h
@@ -31,7 +31,7 @@
#include "../../parser/msg_parser.h"
#include "../../str.h"
-
+#include "../../pvar.h"
/*!
* \brief Insert a new Record-Route header field with lr parameter
@@ -66,5 +66,7 @@ int record_route_preset(struct sip_msg* _m, str* _data);
*/
int add_rr_param(struct sip_msg* msg, str* rr_param);
+void init_custom_user(pv_spec_t *custom_user_avp);
+
#endif /* RECORD_H */
diff --git a/modules_k/rr/rr_mod.c b/modules_k/rr/rr_mod.c
index 3e23eab..e2cc3f6 100644
--- a/modules_k/rr/rr_mod.c
+++ b/modules_k/rr/rr_mod.c
@@ -56,7 +56,9 @@ int append_fromtag = 1; /*!< append from tag by default */
int enable_double_rr = 1; /*!< enable using of 2 RR by default */
int enable_full_lr = 0; /*!< compatibilty mode disabled by default */
int add_username = 0; /*!< do not add username by default */
- int enable_socket_mismatch_warning = 1; /*!< enable socket mismatch warning */
+int enable_socket_mismatch_warning = 1; /*!< enable socket mismatch warning */
+static str custom_user_spec = {NULL, 0};
+pv_spec_t custom_user_avp;
static unsigned int last_rr_msg;
@@ -112,6 +114,7 @@ static param_export_t params[] ={
#endif
{"add_username", INT_PARAM, &add_username},
{"enable_socket_mismatch_warning",INT_PARAM,&enable_socket_mismatch_warning},
+ { "custom_user_avp", STR_PARAM, &custom_user_spec.s},
{0, 0, 0 }
};
@@ -156,6 +159,18 @@ static int mod_init(void)
i_user.len = 0;
}
#endif
+
+ if (custom_user_spec.s) {
+ custom_user_spec.len = strlen(custom_user_spec.s);
+ if ( pv_parse_spec(&custom_user_spec, &custom_user_avp)==0
+ && (custom_user_avp.type!=PVT_AVP)){
+ LM_ERR("malformed or non AVP custom_user "
+ "AVP definition in '%.*s'\n",
custom_user_spec.len,custom_user_spec.s);
+ return -1;
+ }
+ }
+
+ init_custom_user(custom_user_spec.s?&custom_user_avp:0);
return 0;
}