Module: sip-router
Branch: 4.0
Commit: 5ab5edc4bba76f7a46d243fb7b9ce329b31835b6
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5ab5edc…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sat Mar 23 10:44:31 2013 +0100
rr: use sips to build RR headers of R-URI has sips
- reported by Hugh James, FS#277
(cherry picked from commit 1826a5f4e3a981e30956da61e11ea551aae0b714)
---
modules/rr/record.c | 94 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 72 insertions(+), 22 deletions(-)
diff --git a/modules/rr/record.c b/modules/rr/record.c
index 784ec90..0779200 100644
--- a/modules/rr/record.c
+++ b/modules/rr/record.c
@@ -44,8 +44,11 @@
#include "rr_mod.h"
-#define RR_PREFIX "Record-Route: <sip:"
-#define RR_PREFIX_LEN (sizeof(RR_PREFIX)-1)
+#define RR_PREFIX_SIP "Record-Route: <sip:"
+#define RR_PREFIX_SIP_LEN (sizeof(RR_PREFIX_SIP)-1)
+
+#define RR_PREFIX_SIPS "Record-Route: <sip:"
+#define RR_PREFIX_SIPS_LEN (sizeof(RR_PREFIX_SIPS)-1)
#define RR_LR ";lr"
#define RR_LR_LEN (sizeof(RR_LR)-1)
@@ -79,6 +82,15 @@ static unsigned int rr_param_msg;
static pv_spec_t *custom_user_avp; /*!< AVP for custom_user setting */
+inline static int rr_is_sips(sip_msg_t *_m)
+{
+ if(parse_sip_msg_uri(_m)<0)
+ return 0;
+ if(_m->parsed_uri.type==SIPS_URI_T)
+ return 1;
+ return 0;
+}
+
void init_custom_user(pv_spec_t *custom_user_avp_p)
{
custom_user_avp = custom_user_avp_p;
@@ -188,13 +200,23 @@ static inline struct lump *insert_rr_param_lump(struct lump
*before,
* \return 0 on success, negative on failure
*/
static inline int build_rr(struct lump* _l, struct lump* _l2, str* user,
- str *tag, str *params, int _inbound, int _use_ob)
+ str *tag, str *params, int _inbound, int _use_ob, int _sips)
{
char* prefix, *suffix, *term, *r2;
int suffix_len, prefix_len;
char *p;
+ char *rr_prefix;
+ int rr_prefix_len;
+
+ if(_sips==0) {
+ rr_prefix = RR_PREFIX_SIP;
+ rr_prefix_len = RR_PREFIX_SIP_LEN;
+ } else {
+ rr_prefix = RR_PREFIX_SIPS;
+ rr_prefix_len = RR_PREFIX_SIPS_LEN;
+ }
- prefix_len = RR_PREFIX_LEN + (user->len ? (user->len + 1) : 0);
+ prefix_len = rr_prefix_len + (user->len ? (user->len + 1) : 0);
if (enable_full_lr) {
suffix_len = RR_LR_FULL_LEN + (params?params->len:0) +
((tag && tag->len) ? (RR_FROMTAG_LEN + tag->len) : 0);
@@ -217,21 +239,21 @@ static inline int build_rr(struct lump* _l, struct lump* _l2, str*
user,
return -3;
}
- memcpy(prefix, RR_PREFIX, RR_PREFIX_LEN);
+ memcpy(prefix, rr_prefix, rr_prefix_len);
if (user->len) {
- memcpy(prefix + RR_PREFIX_LEN, user->s, user->len);
+ memcpy(prefix + rr_prefix_len, user->s, user->len);
#ifdef ENABLE_USER_CHECK
/* don't add the ignored user into a RR */
if(i_user.len && i_user.len == user->len &&
!strncmp(i_user.s, user->s, i_user.len))
{
- if(prefix[RR_PREFIX_LEN]=='x')
- prefix[RR_PREFIX_LEN]='y';
+ if(prefix[rr_prefix_len]=='x')
+ prefix[rr_prefix_len]='y';
else
- prefix[RR_PREFIX_LEN]='x';
+ prefix[rr_prefix_len]='x';
}
#endif
- prefix[RR_PREFIX_LEN + user->len] = '@';
+ prefix[rr_prefix_len + user->len] = '@';
}
p = suffix;
@@ -357,6 +379,7 @@ int record_route(struct sip_msg* _m, str *params)
struct to_body* from = NULL;
str* tag;
int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0;
+ int sips;
user.len = 0;
@@ -396,6 +419,8 @@ int record_route(struct sip_msg* _m, str *params)
rr_param_buf.len = 0;
}
+ sips = rr_is_sips(_m);
+
if (enable_double_rr && !use_ob) {
l = anchor_lump(_m, _m->headers->name.s - _m->buf,0,HDR_RECORDROUTE_T);
l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0);
@@ -409,7 +434,7 @@ int record_route(struct sip_msg* _m, str *params)
LM_ERR("failed to insert conditional lump\n");
return -6;
}
- if (build_rr(l, l2, &user, tag, params, OUTBOUND, 0) < 0) {
+ if (build_rr(l, l2, &user, tag, params, OUTBOUND, 0, sips) < 0) {
LM_ERR("failed to insert outbound Record-Route\n");
return -7;
}
@@ -423,7 +448,7 @@ int record_route(struct sip_msg* _m, str *params)
}
if (build_rr(l, l2, &user, tag, params, use_ob ? OUTBOUND : INBOUND,
- use_ob) < 0) {
+ use_ob, sips) < 0) {
LM_ERR("failed to insert inbound Record-Route\n");
return -4;
}
@@ -452,7 +477,19 @@ int record_route_preset(struct sip_msg* _m, str* _data)
char* hdr, *p;
int hdr_len;
int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0;
-
+ char *rr_prefix;
+ int rr_prefix_len;
+ int sips;
+
+ sips = rr_is_sips(_m);
+ if(sips==0) {
+ rr_prefix = RR_PREFIX_SIP;
+ rr_prefix_len = RR_PREFIX_SIP_LEN;
+ } else {
+ rr_prefix = RR_PREFIX_SIPS;
+ rr_prefix_len = RR_PREFIX_SIPS_LEN;
+ }
+
from = 0;
user.len = 0;
user.s = 0;
@@ -488,7 +525,7 @@ int record_route_preset(struct sip_msg* _m, str* _data)
return -3;
}
- hdr_len = RR_PREFIX_LEN;
+ hdr_len = rr_prefix_len;
if (user.len)
hdr_len += user.len + 1; /* @ */
hdr_len += _data->len;
@@ -512,8 +549,8 @@ int record_route_preset(struct sip_msg* _m, str* _data)
}
p = hdr;
- memcpy(p, RR_PREFIX, RR_PREFIX_LEN);
- p += RR_PREFIX_LEN;
+ memcpy(p, rr_prefix, rr_prefix_len);
+ p += rr_prefix_len;
if (user.len) {
memcpy(p, user.s, user.len);
@@ -564,13 +601,23 @@ int record_route_preset(struct sip_msg* _m, str* _data)
#define RR_TRANS_LEN 11
#define RR_TRANS ";transport="
static inline int build_advertised_rr(struct lump* _l, struct lump* _l2, str *_data,
- str* user, str *tag, int _inbound, int _use_ob)
+ str* user, str *tag, int _inbound, int _use_ob, int _sips)
{
char *p;
char *hdr, *trans, *r2, *suffix, *term;
int hdr_len, suffix_len;
+ char *rr_prefix;
+ int rr_prefix_len;
- hdr_len = RR_PREFIX_LEN;
+ if(_sips==0) {
+ rr_prefix = RR_PREFIX_SIP;
+ rr_prefix_len = RR_PREFIX_SIP_LEN;
+ } else {
+ rr_prefix = RR_PREFIX_SIPS;
+ rr_prefix_len = RR_PREFIX_SIPS_LEN;
+ }
+
+ hdr_len = rr_prefix_len;
if (user && user->len)
hdr_len += user->len + 1; /* @ */
hdr_len += _data->len;
@@ -602,8 +649,8 @@ static inline int build_advertised_rr(struct lump* _l, struct lump*
_l2, str *_d
}
p = hdr;
- memcpy(p, RR_PREFIX, RR_PREFIX_LEN);
- p += RR_PREFIX_LEN;
+ memcpy(p, rr_prefix, rr_prefix_len);
+ p += rr_prefix_len;
if (user->len) {
memcpy(p, user->s, user->len);
@@ -681,6 +728,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data)
struct lump* l;
struct lump* l2;
int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0;
+ int sips;
user.len = 0;
user.s = 0;
@@ -710,6 +758,8 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data)
tag = &((struct to_body*)_m->from->parsed)->tag_value;
}
+ sips = rr_is_sips(_m);
+
if (enable_double_rr && !use_ob) {
l = anchor_lump(_m, _m->headers->name.s - _m->buf,0,HDR_RECORDROUTE_T);
l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0);
@@ -724,7 +774,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data)
return -4;
}
if (build_advertised_rr(l, l2, _data, &user, tag, OUTBOUND,
- 0) < 0) {
+ 0, sips) < 0) {
LM_ERR("failed to insert outbound Record-Route\n");
return -5;
}
@@ -739,7 +789,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data)
if (build_advertised_rr(l, l2, _data, &user, tag,
use_ob ? OUTBOUND: INBOUND,
- use_ob) < 0) {
+ use_ob, sips) < 0) {
LM_ERR("failed to insert outbound Record-Route\n");
return -7;
}