[sr-dev] git:master: rr: use sips to build RR headers of R-URI has sips
Daniel-Constantin Mierla
miconda at gmail.com
Sat Mar 23 10:46:19 CET 2013
Module: sip-router
Branch: master
Commit: 1826a5f4e3a981e30956da61e11ea551aae0b714
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1826a5f4e3a981e30956da61e11ea551aae0b714
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at 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
---
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 f4a7810..e2beb19 100644
--- a/modules/rr/record.c
+++ b/modules/rr/record.c
@@ -43,8 +43,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)
@@ -78,6 +81,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;
@@ -187,13 +199,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);
@@ -216,21 +238,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;
@@ -311,6 +333,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;
@@ -345,6 +368,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);
@@ -358,7 +383,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;
}
@@ -372,7 +397,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;
}
@@ -401,7 +426,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;
@@ -432,7 +469,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;
@@ -456,8 +493,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);
@@ -508,13 +545,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;
@@ -546,8 +593,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);
@@ -625,6 +672,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;
@@ -649,6 +697,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);
@@ -663,7 +713,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;
}
@@ -678,7 +728,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;
}
More information about the sr-dev
mailing list