Browse code

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).

Andrei Pelinescu-Onciul authored on 10/02/2010 20:30:11
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,101 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2010 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/*
19
+ * char_msg_val.h
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-02-10  moved from parser/msg_parser.h and added tag only mode
25
+ *              by default (andrei)
26
+*/
27
+/** compute the characteristic value of a message.
28
+ * @file
29
+ * @ingroup core
30
+ */
31
+/* Defines:
32
+ *  BRANCH_INCLUDE_FROMTO_BODY - if defined the old (pre 3.1) mode of
33
+ *   including the full from & to bodies will be used (instead of only the
34
+ *   tags).
35
+*/
36
+
37
+#ifndef __char_msg_val_h
38
+#define __char_msg_val_h
39
+
40
+#include "comp_defs.h"
41
+#include "compiler_opt.h"
42
+#include "str.h"
43
+#include "parser/msg_parser.h"
44
+#include "parser/parse_to.h"
45
+#include "parser/parse_from.h"
46
+#include "md5utils.h"
47
+
48
+/*! \brief calculate characteristic value of a message -- this value
49
+   is used to identify a transaction during the process of
50
+   reply matching
51
+ */
52
+inline static int char_msg_val( struct sip_msg *msg, char *cv )
53
+{
54
+	str src[8];
55
+
56
+	if (unlikely(!check_transaction_quadruple(msg))) {
57
+		LOG(L_ERR, "ERROR: can't calculate char_value due "
58
+			"to a parsing error\n");
59
+		memset( cv, '0', MD5_LEN );
60
+		return 0;
61
+	}
62
+
63
+#ifdef BRANCH_INCLUDE_FROMTO_BODY
64
+	/* use the from & to full bodies */
65
+	src[0]= msg->from->body;
66
+	src[1]= msg->to->body;
67
+#else
68
+	/* to body is automatically parsed (via check_transactionquadruple / 
69
+	   parse_header), but the from body has to be parsed manually */
70
+	if (msg->from->parsed==0){
71
+		/* parse from body */
72
+		if (unlikely(parse_from_header(msg) == -1)){
73
+			LOG(L_ERR, "error while parsing From header\n");
74
+			return 0;
75
+		}
76
+	}
77
+	/* use only the from & to tags */
78
+	src[0]=get_from(msg)->tag_value;
79
+	src[1]=get_to(msg)->tag_value;
80
+#endif
81
+	src[2]= msg->callid->body;
82
+	src[3]= msg->first_line.u.request.uri;
83
+	src[4]= get_cseq( msg )->number;
84
+
85
+	/* topmost Via is part of transaction key as well ! */
86
+	src[5]= msg->via1->host;
87
+	src[6]= msg->via1->port_str;
88
+	if (msg->via1->branch) {
89
+		src[7]= msg->via1->branch->value;
90
+		MD5StringArray ( cv, src, 8 );
91
+	} else {
92
+		MD5StringArray( cv, src, 7 );
93
+	}
94
+	return 1;
95
+}
96
+
97
+
98
+
99
+#endif /*__char_msg_val_h*/
100
+
101
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -78,6 +78,7 @@
78 78
 #include "hash_func.h"
79 79
 #include "config.h"
80 80
 #include "parser/msg_parser.h"
81
+#include "char_msg_val.h"
81 82
 #include "route.h"
82 83
 #include "events.h"
83 84
 #include "dprint.h"
... ...
@@ -59,6 +59,7 @@
59 59
 #include "../../ut.h"
60 60
 #include "../../globals.h"
61 61
 #include "../../error.h"
62
+#include "../../char_msg_val.h"
62 63
 #include "defs.h"
63 64
 #include "t_reply.h"
64 65
 #include "t_cancel.h"
... ...
@@ -49,6 +49,7 @@
49 49
 #include "../../mem/mem.h"
50 50
 #include "../../dprint.h"
51 51
 #include "../../md5utils.h"
52
+#include "../../char_msg_val.h"
52 53
 #include "exec_hf.h"
53 54
 
54 55
 /* should be environment variables set by header fields ? */
... ...
@@ -57,6 +57,7 @@
57 57
 #include "../../mem/mem.h"
58 58
 #include "../../dprint.h"
59 59
 #include "../../md5utils.h"
60
+#include "../../char_msg_val.h"
60 61
 #include "exec_hf.h"
61 62
 
62 63
 /* should be environment variables set by header fields ? */
... ...
@@ -398,40 +398,6 @@ inline static int check_transaction_quadruple( struct sip_msg* msg )
398 398
 
399 399
 
400 400
 
401
-/*! \brief calculate characteristic value of a message -- this value
402
-   is used to identify a transaction during the process of
403
-   reply matching
404
- */
405
-inline static int char_msg_val( struct sip_msg *msg, char *cv )
406
-{
407
-	str src[8];
408
-
409
-	if (!check_transaction_quadruple(msg)) {
410
-		LOG(L_ERR, "ERROR: can't calculate char_value due "
411
-			"to a parsing error\n");
412
-		memset( cv, '0', MD5_LEN );
413
-		return 0;
414
-	}
415
-
416
-	src[0]= msg->from->body;
417
-	src[1]= msg->to->body;
418
-	src[2]= msg->callid->body;
419
-	src[3]= msg->first_line.u.request.uri;
420
-	src[4]= get_cseq( msg )->number;
421
-
422
-	/* topmost Via is part of transaction key as well ! */
423
-	src[5]= msg->via1->host;
424
-	src[6]= msg->via1->port_str;
425
-	if (msg->via1->branch) {
426
-		src[7]= msg->via1->branch->value;
427
-		MD5StringArray ( cv, src, 8 );
428
-	} else {
429
-		MD5StringArray( cv, src, 7 );
430
-	}
431
-	return 1;
432
-}
433
-
434
-
435 401
 /*! \brief returns a pointer to the begining of the msg's body
436 402
  */
437 403
 inline static char* get_body(struct sip_msg *msg)