[sr-dev] git:master: core: include only from/to tags when computing via branch value

Andrei Pelinescu-Onciul andrei at iptel.org
Wed Feb 10 22:09:02 CET 2010


Module: sip-router
Branch: master
Commit: 817b9c5cf1133cd9fe59624167b1af1da7461529
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=817b9c5cf1133cd9fe59624167b1af1da7461529

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Wed Feb 10 21:30:11 2010 +0100

core: include only from/to tags when computing via branch value

- use only the to & from tags when computing the via branch value
  in syn_branch==0 mode. This should improve interoperability with
  broken implementations that don't keep the from & to headers
  unchanged. Defining BRANCH_INCLUDE_FROMTO_BODY will revert to
  the old behaviour.
- moved char_msg_val from parser/msg_parser.h to its own file
 (it has nothing to do with parsing).

---

 char_msg_val.h           |  101 ++++++++++++++++++++++++++++++++++++++++++++++
 forward.c                |    1 +
 modules/tm/h_table.c     |    1 +
 modules_k/exec/exec_hf.c |    1 +
 modules_s/exec/exec_hf.c |    1 +
 parser/msg_parser.h      |   34 ---------------
 6 files changed, 105 insertions(+), 34 deletions(-)

diff --git a/char_msg_val.h b/char_msg_val.h
new file mode 100644
index 0000000..9e20918
--- /dev/null
+++ b/char_msg_val.h
@@ -0,0 +1,101 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2010 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * char_msg_val.h
+ */
+/*
+ * History:
+ * --------
+ *  2010-02-10  moved from parser/msg_parser.h and added tag only mode
+ *              by default (andrei)
+*/
+/** compute the characteristic value of a message.
+ * @file
+ * @ingroup core
+ */
+/* Defines:
+ *  BRANCH_INCLUDE_FROMTO_BODY - if defined the old (pre 3.1) mode of
+ *   including the full from & to bodies will be used (instead of only the
+ *   tags).
+*/
+
+#ifndef __char_msg_val_h
+#define __char_msg_val_h
+
+#include "comp_defs.h"
+#include "compiler_opt.h"
+#include "str.h"
+#include "parser/msg_parser.h"
+#include "parser/parse_to.h"
+#include "parser/parse_from.h"
+#include "md5utils.h"
+
+/*! \brief calculate characteristic value of a message -- this value
+   is used to identify a transaction during the process of
+   reply matching
+ */
+inline static int char_msg_val( struct sip_msg *msg, char *cv )
+{
+	str src[8];
+
+	if (unlikely(!check_transaction_quadruple(msg))) {
+		LOG(L_ERR, "ERROR: can't calculate char_value due "
+			"to a parsing error\n");
+		memset( cv, '0', MD5_LEN );
+		return 0;
+	}
+
+#ifdef BRANCH_INCLUDE_FROMTO_BODY
+	/* use the from & to full bodies */
+	src[0]= msg->from->body;
+	src[1]= msg->to->body;
+#else
+	/* to body is automatically parsed (via check_transactionquadruple / 
+	   parse_header), but the from body has to be parsed manually */
+	if (msg->from->parsed==0){
+		/* parse from body */
+		if (unlikely(parse_from_header(msg) == -1)){
+			LOG(L_ERR, "error while parsing From header\n");
+			return 0;
+		}
+	}
+	/* use only the from & to tags */
+	src[0]=get_from(msg)->tag_value;
+	src[1]=get_to(msg)->tag_value;
+#endif
+	src[2]= msg->callid->body;
+	src[3]= msg->first_line.u.request.uri;
+	src[4]= get_cseq( msg )->number;
+
+	/* topmost Via is part of transaction key as well ! */
+	src[5]= msg->via1->host;
+	src[6]= msg->via1->port_str;
+	if (msg->via1->branch) {
+		src[7]= msg->via1->branch->value;
+		MD5StringArray ( cv, src, 8 );
+	} else {
+		MD5StringArray( cv, src, 7 );
+	}
+	return 1;
+}
+
+
+
+#endif /*__char_msg_val_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
diff --git a/forward.c b/forward.c
index 0971027..4b58f71 100644
--- a/forward.c
+++ b/forward.c
@@ -78,6 +78,7 @@
 #include "hash_func.h"
 #include "config.h"
 #include "parser/msg_parser.h"
+#include "char_msg_val.h"
 #include "route.h"
 #include "events.h"
 #include "dprint.h"
diff --git a/modules/tm/h_table.c b/modules/tm/h_table.c
index 2f18336..c860005 100644
--- a/modules/tm/h_table.c
+++ b/modules/tm/h_table.c
@@ -59,6 +59,7 @@
 #include "../../ut.h"
 #include "../../globals.h"
 #include "../../error.h"
+#include "../../char_msg_val.h"
 #include "defs.h"
 #include "t_reply.h"
 #include "t_cancel.h"
diff --git a/modules_k/exec/exec_hf.c b/modules_k/exec/exec_hf.c
index 58d10d5..37eaf27 100644
--- a/modules_k/exec/exec_hf.c
+++ b/modules_k/exec/exec_hf.c
@@ -49,6 +49,7 @@
 #include "../../mem/mem.h"
 #include "../../dprint.h"
 #include "../../md5utils.h"
+#include "../../char_msg_val.h"
 #include "exec_hf.h"
 
 /* should be environment variables set by header fields ? */
diff --git a/modules_s/exec/exec_hf.c b/modules_s/exec/exec_hf.c
index f354190..b977834 100644
--- a/modules_s/exec/exec_hf.c
+++ b/modules_s/exec/exec_hf.c
@@ -57,6 +57,7 @@
 #include "../../mem/mem.h"
 #include "../../dprint.h"
 #include "../../md5utils.h"
+#include "../../char_msg_val.h"
 #include "exec_hf.h"
 
 /* should be environment variables set by header fields ? */
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index c092f51..ca08284 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -398,40 +398,6 @@ inline static int check_transaction_quadruple( struct sip_msg* msg )
 
 
 
-/*! \brief calculate characteristic value of a message -- this value
-   is used to identify a transaction during the process of
-   reply matching
- */
-inline static int char_msg_val( struct sip_msg *msg, char *cv )
-{
-	str src[8];
-
-	if (!check_transaction_quadruple(msg)) {
-		LOG(L_ERR, "ERROR: can't calculate char_value due "
-			"to a parsing error\n");
-		memset( cv, '0', MD5_LEN );
-		return 0;
-	}
-
-	src[0]= msg->from->body;
-	src[1]= msg->to->body;
-	src[2]= msg->callid->body;
-	src[3]= msg->first_line.u.request.uri;
-	src[4]= get_cseq( msg )->number;
-
-	/* topmost Via is part of transaction key as well ! */
-	src[5]= msg->via1->host;
-	src[6]= msg->via1->port_str;
-	if (msg->via1->branch) {
-		src[7]= msg->via1->branch->value;
-		MD5StringArray ( cv, src, 8 );
-	} else {
-		MD5StringArray( cv, src, 7 );
-	}
-	return 1;
-}
-
-
 /*! \brief returns a pointer to the begining of the msg's body
  */
 inline static char* get_body(struct sip_msg *msg)




More information about the sr-dev mailing list