Преглед на файлове

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

Jiri Kuthan преди 23 години
родител
ревизия
2a78db5c1e
променени са 3 файла, в които са добавени 64 реда и са изтрити 1 реда
  1. 56 0
      dset.c
  2. 7 0
      dset.h
  3. 1 1
      modules/tm/t_fwd.c

+ 56 - 0
dset.c

@@ -85,3 +85,59 @@ int append_branch( struct sip_msg *msg, char *uri, int uri_len )
 	nr_branches++;
 	return 1;
 }
+
+
+
+char *create_dset( struct sip_msg *msg, int *len ) 
+{
+	int cnt;
+	str uri;
+	char *p;
+	int i;
+	static char dset[MAX_REDIRECTION_LEN];
+
+	if (msg->new_uri.s) {
+		cnt=1;
+		*len=msg->new_uri.len;
+	} else {
+		cnt=0;
+		*len=0;
+	}
+
+	init_branch_iterator();
+	while ((uri.s=next_branch(&uri.len))) {
+		cnt++;
+		*len+=uri.len;
+	}
+
+	if (cnt==0) return 0;	
+
+	*len+=CONTACT_LEN+CRLF_LEN+(cnt-1)*CONTACT_DELIM_LEN;
+
+	if (*len+1>MAX_REDIRECTION_LEN) {
+		LOG(L_ERR, "ERROR: redirection buffer length exceed\n");
+		return 0;
+	}
+
+	memcpy(dset, CONTACT, CONTACT_LEN );
+	p=dset+CONTACT_LEN;
+	if (msg->new_uri.s) {
+		memcpy(p, msg->new_uri.s, msg->new_uri.len);
+		p+=msg->new_uri.len;
+		i=1;
+	} else i=0;
+
+	init_branch_iterator();
+	while ((uri.s=next_branch(&uri.len))) {
+		if (i) {
+			memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN );
+			p+=2;
+		}
+		memcpy(p, uri.s, uri.len);
+		p+=uri.len;
+		i++;
+	}
+	memcpy(p, CRLF " ", CRLF_LEN+1);
+	return dset;
+}
+

+ 7 - 0
dset.h

@@ -7,6 +7,13 @@
 
 #include "config.h"
 
+#define CONTACT "Contact: "
+#define CONTACT_LEN 9
+#define CONTACT_DELIM ", "
+#define CONTACT_DELIM_LEN 2
+
+char *create_dset( struct sip_msg *msg, int *len );
+
 struct branch
 {
 	char uri[MAX_URI_SIZE];

+ 1 - 1
modules/tm/t_fwd.c

@@ -339,7 +339,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
 			lowest_ret=branch_ret;
 	}
 
-	init_branch_iterator(p_msg);
+	init_branch_iterator();
 	while((current_uri.s=next_branch( &current_uri.len))) {
 		branch_ret=add_uac( t, p_msg, &current_uri, proxy );
 		/* pick some of the errors in case things go wrong;