Browse code

generating Contact header field value in redirects moved from SL to core (dset) for generality

Jiri Kuthan authored on 15/08/2002 10:05:36
Showing 3 changed files
... ...
@@ -85,3 +85,59 @@ int append_branch( struct sip_msg *msg, char *uri, int uri_len )
85 85
 	nr_branches++;
86 86
 	return 1;
87 87
 }
88
+
89
+
90
+
91
+char *create_dset( struct sip_msg *msg, int *len ) 
92
+{
93
+	int cnt;
94
+	str uri;
95
+	char *p;
96
+	int i;
97
+	static char dset[MAX_REDIRECTION_LEN];
98
+
99
+	if (msg->new_uri.s) {
100
+		cnt=1;
101
+		*len=msg->new_uri.len;
102
+	} else {
103
+		cnt=0;
104
+		*len=0;
105
+	}
106
+
107
+	init_branch_iterator();
108
+	while ((uri.s=next_branch(&uri.len))) {
109
+		cnt++;
110
+		*len+=uri.len;
111
+	}
112
+
113
+	if (cnt==0) return 0;	
114
+
115
+	*len+=CONTACT_LEN+CRLF_LEN+(cnt-1)*CONTACT_DELIM_LEN;
116
+
117
+	if (*len+1>MAX_REDIRECTION_LEN) {
118
+		LOG(L_ERR, "ERROR: redirection buffer length exceed\n");
119
+		return 0;
120
+	}
121
+
122
+	memcpy(dset, CONTACT, CONTACT_LEN );
123
+	p=dset+CONTACT_LEN;
124
+	if (msg->new_uri.s) {
125
+		memcpy(p, msg->new_uri.s, msg->new_uri.len);
126
+		p+=msg->new_uri.len;
127
+		i=1;
128
+	} else i=0;
129
+
130
+	init_branch_iterator();
131
+	while ((uri.s=next_branch(&uri.len))) {
132
+		if (i) {
133
+			memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN );
134
+			p+=2;
135
+		}
136
+		memcpy(p, uri.s, uri.len);
137
+		p+=uri.len;
138
+		i++;
139
+	}
140
+	memcpy(p, CRLF " ", CRLF_LEN+1);
141
+	return dset;
142
+}
143
+
... ...
@@ -7,6 +7,13 @@
7 7
 
8 8
 #include "config.h"
9 9
 
10
+#define CONTACT "Contact: "
11
+#define CONTACT_LEN 9
12
+#define CONTACT_DELIM ", "
13
+#define CONTACT_DELIM_LEN 2
14
+
15
+char *create_dset( struct sip_msg *msg, int *len );
16
+
10 17
 struct branch
11 18
 {
12 19
 	char uri[MAX_URI_SIZE];
... ...
@@ -339,7 +339,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
339 339
 			lowest_ret=branch_ret;
340 340
 	}
341 341
 
342
-	init_branch_iterator(p_msg);
342
+	init_branch_iterator();
343 343
 	while((current_uri.s=next_branch( &current_uri.len))) {
344 344
 		branch_ret=add_uac( t, p_msg, &current_uri, proxy );
345 345
 		/* pick some of the errors in case things go wrong;