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