Module: sip-router
Branch: master
Commit: c37c22b4af29fed88c5655a5405876ffc640e5b2
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c37c22b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Aug 20 12:57:01 2009 +0300
core: support to add rport parameter to local via hdr
- new cfg function - add_local_rport() - to add rport parameter to local
via header (rfc3581)
---
action.c | 4 ++++
cfg.lex | 3 +++
cfg.y | 3 +++
msg_translator.c | 25 +++++++++++++++++++++----
parser/msg_parser.h | 1 +
route_struct.h | 1 +
6 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/action.c b/action.c
index 848ec59..8e21ee6 100644
--- a/action.c
+++ b/action.c
@@ -1129,6 +1129,10 @@ match_cleanup:
msg->msg_flags|=FL_FORCE_RPORT;
ret=1; /* continue processing */
break;
+ case ADD_LOCAL_RPORT_T:
+ msg->msg_flags|=FL_ADD_LOCAL_RPORT;
+ ret=1; /* continue processing */
+ break;
case UDP_MTU_TRY_PROTO_T:
msg->msg_flags|= (unsigned int)a->val[0].u.number & FL_MTU_FB_MASK;
ret=1; /* continue processing */
diff --git a/cfg.lex b/cfg.lex
index e15c71b..ebe2b6d 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -166,6 +166,7 @@ ROUTE_SEND onsend_route
ROUTE_EVENT event_route
EXEC exec
FORCE_RPORT "force_rport"|"add_rport"
+ADD_LOCAL_RPORT "add_local_rport"
FORCE_TCP_ALIAS "force_tcp_alias"|"add_tcp_alias"
UDP_MTU "udp_mtu"
UDP_MTU_TRY_PROTO "udp_mtu_try_proto"
@@ -534,6 +535,8 @@ EAT_ABLE [\ \t\b\r]
<INITIAL>{SET_USERPHONE} { count(); yylval.strval=yytext;
return SET_USERPHONE; }
<INITIAL>{FORCE_RPORT} { count(); yylval.strval=yytext; return FORCE_RPORT; }
+<INITIAL>{ADD_LOCAL_RPORT} { count(); yylval.strval=yytext;
+ return ADD_LOCAL_RPORT; }
<INITIAL>{FORCE_TCP_ALIAS} { count(); yylval.strval=yytext;
return FORCE_TCP_ALIAS; }
<INITIAL>{UDP_MTU} { count(); yylval.strval=yytext; return UDP_MTU; }
diff --git a/cfg.y b/cfg.y
index 8a240c6..6950d88 100644
--- a/cfg.y
+++ b/cfg.y
@@ -295,6 +295,7 @@ static int case_check_default(struct case_stms* stms);
%token SET_URI
%token REVERT_URI
%token FORCE_RPORT
+%token ADD_LOCAL_RPORT
%token FORCE_TCP_ALIAS
%token UDP_MTU
%token UDP_MTU_TRY_PROTO
@@ -2886,6 +2887,8 @@ cmd:
| REVERT_URI { $$=mk_action(REVERT_URI_T, 0); }
| FORCE_RPORT LPAREN RPAREN { $$=mk_action(FORCE_RPORT_T, 0); }
| FORCE_RPORT {$$=mk_action(FORCE_RPORT_T, 0); }
+ | ADD_LOCAL_RPORT LPAREN RPAREN { $$=mk_action(ADD_LOCAL_RPORT_T, 0); }
+ | ADD_LOCAL_RPORT {$$=mk_action(ADD_LOCAL_RPORT_T, 0); }
| FORCE_TCP_ALIAS LPAREN NUMBER RPAREN {
#ifdef USE_TCP
$$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
diff --git a/msg_translator.c b/msg_translator.c
index b6273b0..e486579 100644
--- a/msg_translator.c
+++ b/msg_translator.c
@@ -2382,14 +2382,31 @@ char* create_via_hf( unsigned int *len,
}
#endif /* USE_TCP || USE_SCTP */
+ /* test and add rport parameter to local via - rfc3581 */
+ if(msg->msg_flags&FL_ADD_LOCAL_RPORT) {
+ /* params so far + ';rport' + '\0' */
+ via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
+ if(via==0) {
+ LM_ERR("building local rport via param failed\n");
+ if (extra_params.s) pkg_free(extra_params.s);
+ return 0;
+ }
+ if(extra_params.len!=0) {
+ memcpy(via, extra_params.s, extra_params.len);
+ pkg_free(extra_params.s);
+ }
+ memcpy(via + extra_params.len, RPORT, RPORT_LEN-1);
+ extra_params.s = via;
+ extra_params.len += RPORT_LEN-1;
+ extra_params.s[extra_params.len]='\0';
+ }
+
set_hostport(&hp, msg);
via = via_builder( len, send_info, branch,
extra_params.len?&extra_params:0, &hp);
-#if defined USE_TCP || defined USE_SCTP
- /* we do not need id_buf any more, the id is already in the new via header */
- if (id_buf) pkg_free(id_buf);
-#endif
+ /* we do not need extra_params any more, already in the new via header */
+ if (extra_params.s) pkg_free(extra_params.s);
return via;
}
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index a811b61..1ce00bb 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -109,6 +109,7 @@ enum request_method {
#define FL_MTU_TCP_FB (1 << 8)
#define FL_MTU_TLS_FB (1 << 9)
#define FL_MTU_SCTP_FB (1 << 10)
+#define FL_ADD_LOCAL_RPORT (1 << 11) /* add 'rport' to local via hdr */
/* WARNING: Value (1 << 29) is temporarily reserved for use in kamailio acc
* module (flag FL_REQ_UPSTREAM)! */
diff --git a/route_struct.h b/route_struct.h
index 090388c..9274340 100644
--- a/route_struct.h
+++ b/route_struct.h
@@ -97,6 +97,7 @@ enum action_type{
FORWARD_SCTP_T,
SEND_TCP_T,
FORCE_RPORT_T,
+ ADD_LOCAL_RPORT_T,
SET_ADV_ADDR_T,
SET_ADV_PORT_T,
FORCE_TCP_ALIAS_T,