[sr-dev] git:master: tm: add Max-Forwards header to local requests if not given as parameter
Daniel-Constantin Mierla
miconda at gmail.com
Thu Feb 21 11:27:14 CET 2013
Module: sip-router
Branch: master
Commit: 77f99fc7c0252c5fa71ad5939f048742592f1d43
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=77f99fc7c0252c5fa71ad5939f048742592f1d43
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Thu Feb 21 11:25:39 2013 +0100
tm: add Max-Forwards header to local requests if not given as parameter
- add the header to local generated CANCEL and ACK
- based on a patch by Morten Tryfoss
---
modules/tm/t_msgbuilder.c | 8 +++++++-
modules/tm/t_msgbuilder.h | 3 +++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/modules/tm/t_msgbuilder.c b/modules/tm/t_msgbuilder.c
index 340f99a..ffdcb7b 100644
--- a/modules/tm/t_msgbuilder.c
+++ b/modules/tm/t_msgbuilder.c
@@ -152,7 +152,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
*len+= via_len;
/*headers*/
*len+=Trans->from.len+Trans->callid.len+to->len+
- +Trans->cseq_n.len+1+method_len+CRLF_LEN;
+ +Trans->cseq_n.len+1+method_len+CRLF_LEN+MAXFWD_HEADER_LEN;
/* copy'n'paste Route headers */
@@ -226,6 +226,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
append_str( p, Trans->cseq_n.s, Trans->cseq_n.len );
append_str( p, " ", 1 );
append_str( p, method, method_len );
+ append_str( p, MAXFWD_HEADER, MAXFWD_HEADER_LEN );
append_str( p, CRLF, CRLF_LEN );
if (!is_local(Trans)) {
@@ -1516,6 +1517,7 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, int bra
*len += CALLID_LEN + dialog->id.call_id.len + CRLF_LEN; /* Call-ID */
*len += CSEQ_LEN + cseq.len + 1 + method->len + CRLF_LEN; /* CSeq */
*len += calculate_routeset_length(dialog); /* Route set */
+ *len += MAXFWD_HEADER_LEN; /* Max-forwards */
*len += CONTENT_LENGTH_LEN + content_length.len + CRLF_LEN; /* Content-
Length */
*len += (server_signature ? (user_agent_hdr.len + CRLF_LEN) : 0); /* Signature */
@@ -1539,6 +1541,10 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, int bra
w = print_callid(w, dialog, t); /* Call-ID */
w = print_routeset(w, dialog); /* Route set */
+ if(headers==NULL || headers->len<15
+ || strnstr(headers->s, "Max-Forwards:", headers->len)==NULL)
+ memapp(w, MAXFWD_HEADER, MAXFWD_HEADER_LEN); /* Max-forwards */
+
/* Content-Length */
memapp(w, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
memapp(w, content_length.s, content_length.len);
diff --git a/modules/tm/t_msgbuilder.h b/modules/tm/t_msgbuilder.h
index f090528..7694fda 100644
--- a/modules/tm/t_msgbuilder.h
+++ b/modules/tm/t_msgbuilder.h
@@ -52,6 +52,9 @@
#define FROMTAG_LEN (sizeof(FROMTAG)-1)
#define TOTAG ";tag="
#define TOTAG_LEN (sizeof(TOTAG)-1)
+#define MAXFWD_VALUE "70"
+#define MAXFWD_HEADER "Max-Forwards: " MAXFWD_VALUE CRLF
+#define MAXFWD_HEADER_LEN (sizeof(MAXFWD_HEADER) - 1)
char *build_local(struct cell *Trans, unsigned int branch,
More information about the sr-dev
mailing list