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 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2010 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * char_msg_val.h
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2010-02-10  moved from parser/msg_parser.h and added tag only mode
24
+ *              by default (andrei)
25
+*/
26
+/** compute the characteristic value of a message.
27
+ * @file
28
+ * @ingroup core
29
+ */
30
+/* Defines:
31
+ *  BRANCH_INCLUDE_FROMTO_BODY - if defined the old (pre 3.1) mode of
32
+ *   including the full from & to bodies will be used (instead of only the
33
+ *   tags).
34
+*/
35
+
36
+#ifndef __char_msg_val_h
37
+#define __char_msg_val_h
38
+
39
+#include "comp_defs.h"
40
+#include "compiler_opt.h"
41
+#include "str.h"
42
+#include "parser/msg_parser.h"
43
+#include "parser/parse_to.h"
44
+#include "parser/parse_from.h"
45
+#include "md5utils.h"
46
+
47
+/*! \brief calculate characteristic value of a message -- this value
48
+   is used to identify a transaction during the process of
49
+   reply matching
50
+ */
51
+inline static int char_msg_val( struct sip_msg *msg, char *cv )
52
+{
53
+	str src[8];
54
+
55
+	if (unlikely(!check_transaction_quadruple(msg))) {
56
+		LOG(L_ERR, "ERROR: can't calculate char_value due "
57
+			"to a parsing error\n");
58
+		memset( cv, '0', MD5_LEN );
59
+		return 0;
60
+	}
61
+
62
+#ifdef BRANCH_INCLUDE_FROMTO_BODY
63
+	/* use the from & to full bodies */
64
+	src[0]= msg->from->body;
65
+	src[1]= msg->to->body;
66
+#else
67
+	/* to body is automatically parsed (via check_transactionquadruple / 
68
+	   parse_header), but the from body has to be parsed manually */
69
+	if (msg->from->parsed==0){
70
+		/* parse from body */
71
+		if (unlikely(parse_from_header(msg) == -1)){
72
+			LOG(L_ERR, "error while parsing From header\n");
73
+			return 0;
74
+		}
75
+	}
76
+	/* use only the from & to tags */
77
+	src[0]=get_from(msg)->tag_value;
78
+	src[1]=get_to(msg)->tag_value;
79
+#endif
80
+	src[2]= msg->callid->body;
81
+	src[3]= msg->first_line.u.request.uri;
82
+	src[4]= get_cseq( msg )->number;
83
+
84
+	/* topmost Via is part of transaction key as well ! */
85
+	src[5]= msg->via1->host;
86
+	src[6]= msg->via1->port_str;
87
+	if (msg->via1->branch) {
88
+		src[7]= msg->via1->branch->value;
89
+		MD5StringArray ( cv, src, 8 );
90
+	} else {
91
+		MD5StringArray( cv, src, 7 );
92
+	}
93
+	return 1;
94
+}
95
+
96
+
97
+
98
+#endif /*__char_msg_val_h*/
99
+
100
+/* 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)