Browse code

tags generation moved to core

Jiri Kuthan authored on 21/10/2002 20:30:15
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,81 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * - utility for generating to-tags
4
+ *   in SER, to-tags consist of two parts: a fixed part
5
+ *   which is bound to server instance and variable part
6
+ *   which is bound to request -- that helps to recognize,
7
+ *   who generated the to-tag in loops through the same
8
+ *   server -- in such cases, fixed part is constant, but
9
+ *   the variable part varies because it depends on 
10
+ *   via
11
+ *   
12
+ * Copyright (C) 2001-2003 Fhg Fokus
13
+ *
14
+ * This file is part of ser, a free SIP server.
15
+ *
16
+ * ser is free software; you can redistribute it and/or modify
17
+ * it under the terms of the GNU General Public License as published by
18
+ * the Free Software Foundation; either version 2 of the License, or
19
+ * (at your option) any later version
20
+ *
21
+ * For a license to use the ser software under conditions
22
+ * other than those described here, or to purchase support for this
23
+ * software, please contact iptel.org by e-mail at the following addresses:
24
+ *    info@iptel.org
25
+ *
26
+ * ser is distributed in the hope that it will be useful,
27
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
+ * GNU General Public License for more details.
30
+ *
31
+ * You should have received a copy of the GNU General Public License 
32
+ * along with this program; if not, write to the Free Software 
33
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
+ */
35
+
36
+
37
+#ifndef _TAGS_H
38
+#define _TAGS_H
39
+
40
+#include "parser/msg_parser.h"
41
+#include "crc.h"
42
+#include "str.h"
43
+
44
+#define TOTAG_LEN (MD5_LEN+CRC16_LEN+1)
45
+
46
+/* generate variable part of to-tag for a request;
47
+ * it will have length of CRC16_LEN, sufficiently
48
+ * long buffer must be passed to the fucntion */
49
+static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
50
+{
51
+	int ss_nr;
52
+	str suffix_source[3];
53
+
54
+	ss_nr=2;
55
+	suffix_source[0]=msg->via1->host;
56
+	suffix_source[1]=msg->via1->port_str;
57
+	if (msg->via1->branch)
58
+		suffix_source[ss_nr++]=msg->via1->branch->value;
59
+        crcitt_string_array( tag_suffix, suffix_source, ss_nr );
60
+}
61
+
62
+static inline init_tags( char *tag, char **suffix, 
63
+		char *signature, char separator )
64
+{
65
+	str src[3];
66
+
67
+	src[0].s=signature; src[0].len=strlen(signature);
68
+	src[1].s=sock_info[0].address_str.s;
69
+	src[1].len=sock_info[0].address_str.len;
70
+	src[2].s=sock_info[0].port_no_str.s;
71
+	src[2].len=sock_info[0].port_no_str.len;
72
+
73
+	MDStringArray( tag, src, 3 );
74
+
75
+	tag[MD5_LEN]=separator;
76
+	*suffix=tag+MD5_LEN+1;
77
+}
78
+
79
+
80
+#endif