Răsfoiți Sursa

- added body_lumps (jan patches + some changes)
- anchor_lump & del_lump compare the offset with msg->eoh and
add the lump to add_rm or body_lumps, so make sure to parse_headers(HDR_EOH)
if you lumps might modify the body.
- changed all the {anchor,del}_lump calls

Andrei Pelinescu-Onciul 22 ani în urmă
părinte
comite
4c37101e0f
11 a modificat fișierele cu 385 adăugiri și 256 ștergeri
  1. 1 1
      Makefile.defs
  2. 2 0
      TODO
  3. 29 4
      data_lump.c
  4. 4 82
      data_lump.h
  5. 127 0
      lump_struct.h
  6. 61 46
      modules/tm/sip_msg.c
  7. 11 0
      modules/tm/t_reply.c
  8. 2 2
      modules/tm/test.c
  9. 145 120
      msg_translator.c
  10. 1 0
      parser/msg_parser.c
  11. 2 1
      parser/msg_parser.h

+ 1 - 1
Makefile.defs

@@ -43,7 +43,7 @@ export makefile_defs
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL =   12
 SUBLEVEL =   12
-EXTRAVERSION = dev-19
+EXTRAVERSION = dev-20-lumps
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 2 - 0
TODO

@@ -2,6 +2,8 @@ $Id$
 
 
 ( - todo, x - done)
 ( - todo, x - done)
 
 
+- alias support fot tcp/tls port numbers
+- warning builder set_advertised address support
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
 x update AUTHORS, debian/copyright, ser.8, ser.cfg.5 from stable
 x update AUTHORS, debian/copyright, ser.8, ser.cfg.5 from stable
 x update Makefile*  from stable
 x update Makefile*  from stable

+ 29 - 4
data_lump.c

@@ -27,8 +27,11 @@
  * History:
  * History:
  * --------
  * --------
  *  2003-01-19  support for duplication lump lists added (jiri)
  *  2003-01-19  support for duplication lump lists added (jiri)
- *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
+ *  2003-03-31  added subst lumps --they expand in ip addr, port a.s.o (andrei)
  *  2003-04-01  added conditional lump suport functions (andrei)
  *  2003-04-01  added conditional lump suport functions (andrei)
+ *  2003-10-20  anchor_lump & del_lump will automatically choose the lump list
+ *              based on  msg->eoh comparisons (andrei)
+ *  
  */
  */
 
 
 
 
@@ -254,10 +257,15 @@ struct lump* insert_cond_lump_before(	struct lump* before,
 
 
 
 
 /* removes an already existing header/data lump */
 /* removes an already existing header/data lump */
-struct lump* del_lump(struct lump** list, int offset, int len, int type)
+/* WARNING: thist function adds the lump either to the msg->add_rm or
+ * msg->body_lumps list, depending on the offset being greater than msg->eoh,
+ * so msg->eoh must be parsed (parse with HDR_EOH) if you think your lump
+ *  might affect the body!! */
+struct lump* del_lump(struct sip_msg* msg, int offset, int len, int type)
 {
 {
 	struct lump* tmp;
 	struct lump* tmp;
 	struct lump* prev, *t;
 	struct lump* prev, *t;
+	struct lump** list;
 
 
 	tmp=pkg_malloc(sizeof(struct lump));
 	tmp=pkg_malloc(sizeof(struct lump));
 	if (tmp==0){
 	if (tmp==0){
@@ -270,6 +278,11 @@ struct lump* del_lump(struct lump** list, int offset, int len, int type)
 	tmp->u.offset=offset;
 	tmp->u.offset=offset;
 	tmp->len=len;
 	tmp->len=len;
 	prev=0;
 	prev=0;
+	/* check to see whether this might be a body lump */
+	if ((msg->eoh) && (offset> (int)(msg->eoh-msg->buf)))
+		list=&msg->body_lumps;
+	else
+		list=&msg->add_rm;
 	for (t=*list;t; prev=t, t=t->next){
 	for (t=*list;t; prev=t, t=t->next){
 		/* insert it sorted after offset */
 		/* insert it sorted after offset */
 		if (((t->op==LUMP_DEL)||(t->op==LUMP_NOP))&&(t->u.offset>offset))
 		if (((t->op==LUMP_DEL)||(t->op==LUMP_NOP))&&(t->u.offset>offset))
@@ -283,12 +296,18 @@ struct lump* del_lump(struct lump** list, int offset, int len, int type)
 
 
 
 
 
 
-/* add an anhor */
-struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
+/* add an anchor
+ * WARNING: thist function adds the lump either to the msg->add_rm or
+ * msg->body_lumps list, depending on the offset being greater than msg->eoh,
+ * so msg->eoh must be parsed (parse with HDR_EOH) if you think your lump
+ *  might affect the body!! */
+struct lump* anchor_lump(struct sip_msg* msg, int offset, int len, int type)
 {
 {
 	struct lump* tmp;
 	struct lump* tmp;
 	struct lump* prev, *t;
 	struct lump* prev, *t;
+	struct lump** list;
 
 
+	
 	tmp=pkg_malloc(sizeof(struct lump));
 	tmp=pkg_malloc(sizeof(struct lump));
 	if (tmp==0){
 	if (tmp==0){
 		ser_error=E_OUT_OF_MEM;
 		ser_error=E_OUT_OF_MEM;
@@ -301,6 +320,12 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
 	tmp->u.offset=offset;
 	tmp->u.offset=offset;
 	tmp->len=len;
 	tmp->len=len;
 	prev=0;
 	prev=0;
+	/* check to see whether this might be a body lump */
+	if ((msg->eoh) && (offset> (int)(msg->eoh-msg->buf)))
+		list=&msg->body_lumps;
+	else
+		list=&msg->add_rm;
+		
 	for (t=*list;t; prev=t, t=t->next){
 	for (t=*list;t; prev=t, t=t->next){
 		/* insert it sorted after offset */
 		/* insert it sorted after offset */
 		if (((t->op==LUMP_DEL)||(t->op==LUMP_NOP))&&(t->u.offset>offset))
 		if (((t->op==LUMP_DEL)||(t->op==LUMP_NOP))&&(t->u.offset>offset))

+ 4 - 82
data_lump.h

@@ -40,82 +40,8 @@
 #ifndef data_lump_h
 #ifndef data_lump_h
 #define data_lump_h
 #define data_lump_h
 
 
-
-enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT };
-enum lump_subst{ SUBST_NOP=0,                     /* do nothing */
-				 SUBST_RCV_IP,    SUBST_SND_IP,   /* add ip address */
-				 SUBST_RCV_PORT,  SUBST_SND_PORT, /* add port no */
-				 SUBST_RCV_PROTO, SUBST_SND_PROTO,/* add protocol(udp,tcp,tls)*/
-				 SUBST_RCV_ALL,   SUBST_SND_ALL   /*  ip:port;transport=proto */
-				};
-				/* Where:
-				   SND = sending, e.g the src ip of the outgoing message
-				   RCV = received e.g the dst ip of the original incoming msg,
-				    or the ip of the ser socket on which the msg was received
-				   For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060
-				    and transport=proto only if proto!=udp
-					*/
-
-enum lump_conditions {	COND_FALSE,         /* always false */
-						COND_TRUE,          /* always true */
-						COND_IF_DIFF_REALMS,/* true if RCV realm != SND realm */
-						COND_IF_DIFF_AF,    /* true if RCV af != SND af */
-						COND_IF_DIFF_PROTO, /* true if RCV proto != SND proto */
-						COND_IF_DIFF_PORT,  /* true if RCV port != SND port */
-						COND_IF_DIFF_IP,    /* true if RCV ip != SND ip */
-						COND_IF_RAND        /* 50-50 random prob.of being true*/
-						};
-						/* Where: 
-						   REALM= ip_addr:port:proto
-						   af   = address family (ipv4 or ipv6)
-						   proto = protocol (tcp, udp, tls)
-						*/
-
-enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
-
-struct lump{
-	int type; /* VIA, OTHER, UNSPEC(=0), ... */
-	enum lump_op op;   /* DEL, ADD, NOP, UNSPEC(=0) */
-	
-	union{
-		int offset; /* used for DEL, MODIFY */
-		enum lump_subst subst; /*what to subst: ip addr, port, proto*/
-		enum lump_conditions cond; /* condition for LUMP_ADD_OPT */
-		char * value; /* used for ADD */
-	}u;
-	int len; /* length of this header field */
-	
-	
-	struct lump* before; /* list of headers to be inserted in front of the
-								current one */
-	struct lump* after; /* list of headers to be inserted immediately after
-							  the current one */
-	
-	struct lump* next;
-
-	enum lump_flag flags; /* additional hints for use from TM's shmem */
-};
-
-/*
- * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC)
- * and/or their position (ADD). E.g.:
- *  - to delete header Z insert it in to the list according to its offset 
- *   and with op=DELETE
- * - if you want to add a new header X after a  header Y, insert Y in the list
- *   with op NOP and after it X (op ADD).
- * - if you want X before Y, insert X in Y's before list.
- * - if you want X to be the first header just put it first in hdr_lst.
- *  -if you want to replace Y with X, insert Y with op=DELETE and then X with
- *  op=ADD.
- * before and after must contain only ADD ops!
- * 
- * Difference between "after" & "next" when ADDing:
- * "after" forces the new header immediately after the current one while
- * "next" means another header can be inserted between them.
- * 
- */
-
-
+#include "lump_struct.h"
+#include "parser/msg_parser.h"
 
 
 /* adds a header to the end */
 /* adds a header to the end */
 struct lump* append_new_lump(struct lump** list, char* new_hdr,
 struct lump* append_new_lump(struct lump** list, char* new_hdr,
@@ -140,15 +66,11 @@ struct lump* insert_cond_lump_before(struct lump* after, enum lump_conditions c,
 									int type);
 									int type);
 
 
 /* removes an already existing header */
 /* removes an already existing header */
-struct lump* del_lump(struct lump** list, int offset, int len, int type);
+struct lump* del_lump(struct sip_msg* msg, int offset, int len, int type);
 /* set an anchor */
 /* set an anchor */
-struct lump* anchor_lump(struct lump** list, int offset, int len, int type);
+struct lump* anchor_lump(struct sip_msg* msg, int offset, int len, int type);
 
 
 
 
-/* frees the content of a lump struct */
-void free_lump(struct lump* l);
-/*frees an entire lump list, recursively */
-void free_lump_list(struct lump* lump_list);
 
 
 /* duplicates a lump list shallowly in pkg-mem */
 /* duplicates a lump list shallowly in pkg-mem */
 struct lump* dup_lump_list( struct lump *l );
 struct lump* dup_lump_list( struct lump *l );

+ 127 - 0
lump_struct.h

@@ -0,0 +1,127 @@
+/*
+ * $Id$
+ *
+ * adding/removing headers or any other data chunk from a message
+ *
+ * Copyright (C) 2001-2003 Fhg Fokus
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* History:
+ * --------
+ *  2003-01-29  s/int/enum ... more convenient for gdb (jiri)
+ *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
+ *  2003-04-01  added opt (condition) lumps (andrei)
+ *  2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
+ *              => ip:port;transport=proto (andrei)
+ *  2003-10-20  splitted from data_lump.h (andrei)
+ *
+ */
+
+
+#ifndef lump_struct_h
+#define lump_struct_h
+
+
+
+enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT };
+enum lump_subst{ SUBST_NOP=0,                     /* do nothing */
+				 SUBST_RCV_IP,    SUBST_SND_IP,   /* add ip address */
+				 SUBST_RCV_PORT,  SUBST_SND_PORT, /* add port no */
+				 SUBST_RCV_PROTO, SUBST_SND_PROTO,/* add protocol(udp,tcp,tls)*/
+				 SUBST_RCV_ALL,   SUBST_SND_ALL   /*  ip:port;transport=proto */
+				};
+				/* Where:
+				   SND = sending, e.g the src ip of the outgoing message
+				   RCV = received e.g the dst ip of the original incoming msg,
+				    or the ip of the ser socket on which the msg was received
+				   For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060
+				    and transport=proto only if proto!=udp
+					*/
+
+enum lump_conditions {	COND_FALSE,         /* always false */
+						COND_TRUE,          /* always true */
+						COND_IF_DIFF_REALMS,/* true if RCV realm != SND realm */
+						COND_IF_DIFF_AF,    /* true if RCV af != SND af */
+						COND_IF_DIFF_PROTO, /* true if RCV proto != SND proto */
+						COND_IF_DIFF_PORT,  /* true if RCV port != SND port */
+						COND_IF_DIFF_IP,    /* true if RCV ip != SND ip */
+						COND_IF_RAND        /* 50-50 random prob.of being true*/
+						};
+						/* Where: 
+						   REALM= ip_addr:port:proto
+						   af   = address family (ipv4 or ipv6)
+						   proto = protocol (tcp, udp, tls)
+						*/
+
+enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
+
+
+struct lump{
+	int type; /* VIA, OTHER, UNSPEC(=0), ... */
+	enum lump_op op;   /* DEL, ADD, NOP, UNSPEC(=0) */
+	
+	union{
+		int offset; /* used for DEL, MODIFY */
+		enum lump_subst subst; /*what to subst: ip addr, port, proto*/
+		enum lump_conditions cond; /* condition for LUMP_ADD_OPT */
+		char * value; /* used for ADD */
+	}u;
+	int len; /* length of this header field */
+	
+	
+	struct lump* before; /* list of headers to be inserted in front of the
+								current one */
+	struct lump* after; /* list of headers to be inserted immediately after
+							  the current one */
+	
+	struct lump* next;
+
+	enum lump_flag flags; /* additional hints for use from TM's shmem */
+};
+
+
+/*
+ * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC)
+ * and/or their position (ADD). E.g.:
+ *  - to delete header Z insert it in to the list according to its offset 
+ *   and with op=DELETE
+ * - if you want to add a new header X after a  header Y, insert Y in the list
+ *   with op NOP and after it X (op ADD).
+ * - if you want X before Y, insert X in Y's before list.
+ * - if you want X to be the first header just put it first in hdr_lst.
+ *  -if you want to replace Y with X, insert Y with op=DELETE and then X with
+ *  op=ADD.
+ * before and after must contain only ADD ops!
+ * 
+ * Difference between "after" & "next" when ADDing:
+ * "after" forces the new header immediately after the current one while
+ * "next" means another header can be inserted between them.
+ * 
+ */
+
+/* frees the content of a lump struct */
+void free_lump(struct lump* l);
+/*frees an entire lump list, recursively */
+void free_lump_list(struct lump* lump_list);
+
+#endif

+ 61 - 46
modules/tm/sip_msg.c

@@ -253,7 +253,6 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
 	struct via_param  *prm;
 	struct via_param  *prm;
 	struct to_param   *to_prm,*new_to_prm;
 	struct to_param   *to_prm,*new_to_prm;
 	struct sip_msg    *new_msg;
 	struct sip_msg    *new_msg;
-	struct lump       *lump_chain, *lump_tmp, **lump_anchor, **lump_anchor2;
 	struct lump_rpl   *rpl_lump, **rpl_lump_anchor;
 	struct lump_rpl   *rpl_lump, **rpl_lump_anchor;
 	char              *p,*foo;
 	char              *p,*foo;
 
 
@@ -340,25 +339,32 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
 	}/*for all headers*/
 	}/*for all headers*/
 
 
 	/* length of the data lump structures */
 	/* length of the data lump structures */
-	lump_chain = org_msg->add_rm;
-	while (lump_chain)
-	{
-		len += lump_len( lump_chain );
-		lump_tmp = lump_chain->before;
-		while ( lump_tmp )
-		{
-			len += lump_len( lump_tmp );
-			lump_tmp = lump_tmp->before;
-		}
-		lump_tmp = lump_chain->after;
-		while ( lump_tmp )
-		{
-			len += lump_len( lump_tmp );
-			lump_tmp = lump_tmp->after;
-		}
-		lump_chain = lump_chain->next;
-	}
-
+#define LUMP_LIST_LEN(len, list) \
+do { \
+        struct lump* tmp, *chain; \
+	chain = (list); \
+	while (chain) \
+	{ \
+		(len) += lump_len(chain); \
+		tmp = chain->before; \
+		while ( tmp ) \
+		{ \
+			(len) += lump_len( tmp ); \
+			tmp = tmp->before; \
+		} \
+		tmp = chain->after; \
+		while ( tmp ) \
+		{ \
+			(len) += lump_len( tmp ); \
+			tmp = tmp->after; \
+		} \
+		chain = chain->next; \
+	} \
+} while(0);
+
+	LUMP_LIST_LEN(len, org_msg->add_rm);
+	LUMP_LIST_LEN(len, org_msg->body_lumps);
+	
 	/*length of reply lump structures*/
 	/*length of reply lump structures*/
 	for(rpl_lump=org_msg->reply_lump;rpl_lump;rpl_lump=rpl_lump->next)
 	for(rpl_lump=org_msg->reply_lump;rpl_lump;rpl_lump=rpl_lump->next)
 			len+=ROUND4(sizeof(struct lump_rpl))+ROUND4(rpl_lump->text.len);
 			len+=ROUND4(sizeof(struct lump_rpl))+ROUND4(rpl_lump->text.len);
@@ -376,6 +382,7 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
 	memcpy( new_msg , org_msg , sizeof(struct sip_msg) );
 	memcpy( new_msg , org_msg , sizeof(struct sip_msg) );
 	p += ROUND4(sizeof(struct sip_msg));
 	p += ROUND4(sizeof(struct sip_msg));
 	new_msg->add_rm = 0;
 	new_msg->add_rm = 0;
+	new_msg->body_lumps = 0;
 	/* new_uri */
 	/* new_uri */
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
 	{
 	{
@@ -630,32 +637,40 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
 	}
 	}
 
 
 	/* clonning data lump */
 	/* clonning data lump */
-		lump_chain = org_msg->add_rm;
-		lump_anchor = &(new_msg->add_rm);
-	while (lump_chain)
-	{
-		lump_clone( (*lump_anchor) , lump_chain , p );
-		/*before list*/
-		lump_tmp = lump_chain->before;
-		lump_anchor2 = &((*lump_anchor)->before);
-		while ( lump_tmp )
-		{
-			lump_clone( (*lump_anchor2) , lump_tmp , p );
-			lump_anchor2 = &((*lump_anchor2)->before);
-			lump_tmp = lump_tmp->before;
-		}
-		/*after list*/
-		lump_tmp = lump_chain->after;
-		lump_anchor2 = &((*lump_anchor)->after);
-		while ( lump_tmp )
-		{
-			lump_clone( (*lump_anchor2) , lump_tmp , p );
-			lump_anchor2 = &((*lump_anchor2)->after);
-			lump_tmp = lump_tmp->after;
-		}
-		lump_anchor = &((*lump_anchor)->next);
-		lump_chain = lump_chain->next;
-	}
+#define CLONE_LUMP_LIST(anchor, list) \
+do { \
+        struct lump* lump_tmp, *l; \
+        struct lump** lump_anchor2, **a; \
+        a = (anchor); \
+        l = (list); \
+	while (l) \
+	{ \
+		lump_clone( (*a) , l , p ); \
+		/*before list*/ \
+		lump_tmp = l->before; \
+		lump_anchor2 = &((*a)->before); \
+		while ( lump_tmp ) \
+		{ \
+			lump_clone( (*lump_anchor2) , lump_tmp , p ); \
+			lump_anchor2 = &((*lump_anchor2)->before); \
+			lump_tmp = lump_tmp->before; \
+		} \
+		/*after list*/ \
+		lump_tmp = l->after; \
+		lump_anchor2 = &((*a)->after); \
+		while ( lump_tmp ) \
+		{ \
+			lump_clone( (*lump_anchor2) , lump_tmp , p ); \
+			lump_anchor2 = &((*lump_anchor2)->after); \
+			lump_tmp = lump_tmp->after; \
+		} \
+		a = &((*a)->next); \
+		l = l->next; \
+	} \
+} while(0)
+
+        CLONE_LUMP_LIST(&(new_msg->add_rm), org_msg->add_rm);
+        CLONE_LUMP_LIST(&(new_msg->body_lumps), org_msg->body_lumps);
 
 
 	/*cloning reply lump structures*/
 	/*cloning reply lump structures*/
 	rpl_lump_anchor = &(new_msg->reply_lump);
 	rpl_lump_anchor = &(new_msg->reply_lump);

+ 11 - 0
modules/tm/t_reply.c

@@ -413,6 +413,7 @@ static int faked_env(struct sip_msg *fake,
 	/* set items, which will be duped to pkg_mem, to zero, so that
 	/* set items, which will be duped to pkg_mem, to zero, so that
 	 * "restore" called on error does not free the original items */
 	 * "restore" called on error does not free the original items */
 	fake->add_rm=0;
 	fake->add_rm=0;
+	fake->body_lumps=0;
 	fake->new_uri.s=0; fake->new_uri.len=0; 
 	fake->new_uri.s=0; fake->new_uri.len=0; 
 
 
 	/* remember we are back in request processing, but process
 	/* remember we are back in request processing, but process
@@ -459,12 +460,22 @@ static int faked_env(struct sip_msg *fake,
 			goto restore;
 			goto restore;
 		}
 		}
 	}
 	}
+
+	if (shmem_msg->body_lumps) {
+		fake->body_lumps=dup_lump_list(shmem_msg->body_lumps);
+		if (!fake->body_lumps) { /* non_empty->empty ... failure */
+			LOG(L_ERR, "ERROR: on_negative_reply: lump dup failed\n");
+			goto restore;
+		}
+	}
+	
 	/* success */
 	/* success */
 	return 1;
 	return 1;
 
 
 restore:
 restore:
 	/* restore original environment and destroy faked message */
 	/* restore original environment and destroy faked message */
 	free_duped_lump_list(fake->add_rm);
 	free_duped_lump_list(fake->add_rm);
+	free_duped_lump_list(fake->body_lumps);
 	if (fake->new_uri.s) pkg_free(fake->new_uri.s);
 	if (fake->new_uri.s) pkg_free(fake->new_uri.s);
 	set_t(backup_t);
 	set_t(backup_t);
 	global_msg_id=backup_msgid;
 	global_msg_id=backup_msgid;

+ 2 - 2
modules/tm/test.c

@@ -36,6 +36,7 @@
 #include "../../parser/parser_f.h"
 #include "../../parser/parser_f.h"
 #include "../../ut.h"
 #include "../../ut.h"
 #include "../../timer.h"
 #include "../../timer.h"
+#include "../../data_lump.h"
 
 
 #include "t_hooks.h"
 #include "t_hooks.h"
 
 
@@ -53,8 +54,7 @@ int _test_insert_to_reply( struct sip_msg *msg, char *str )
     }
     }
     memcpy( buf, str, len );
     memcpy( buf, str, len );
 
 
-    anchor = anchor_lump(&msg->add_rm,
-        msg->headers->name.s - msg->buf, 0 , 0);
+    anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0);
     if (anchor == NULL) {
     if (anchor == NULL) {
         LOG(L_ERR, "_test_insert_to_reply: anchor_lump failed\n");
         LOG(L_ERR, "_test_insert_to_reply: anchor_lump failed\n");
         return 0;
         return 0;

+ 145 - 120
msg_translator.c

@@ -53,7 +53,8 @@
  *             build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
  *             build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
  *              position calculations ([] are part of host.s now) (andrei)
  *              position calculations ([] are part of host.s now) (andrei)
  * 2003-10-02  via+lump dst address/port can be set to preset values (andrei)
  * 2003-10-02  via+lump dst address/port can be set to preset values (andrei)
- * 2003-10-08 receive_test function-alized (jiri)
+ * 2003-10-08  receive_test function-alized (jiri)
+ * 2003-10-20  added body_lump list (sip_msg), adjust_clen (andrei & jan)
  *
  *
  */
  */
 /* Via special params:
 /* Via special params:
@@ -121,6 +122,7 @@
 #include "dprint.h"
 #include "dprint.h"
 #include "config.h"
 #include "config.h"
 #include "md5utils.h"
 #include "md5utils.h"
+#include "data_lump.h"
 #include "data_lump_rpl.h"
 #include "data_lump_rpl.h"
 #include "ip_addr.h"
 #include "ip_addr.h"
 #include "resolve.h"
 #include "resolve.h"
@@ -394,7 +396,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
 
 
 
 
 
 
-char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
+char* clen_builder(struct sip_msg* msg, unsigned int *clen_len, int diff)
 {
 {
 	char* buf;
 	char* buf;
 	int len;
 	int len;
@@ -411,7 +413,7 @@ char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
 					" (missing crlf?)");
 					" (missing crlf?)");
 		return 0;
 		return 0;
 	}
 	}
-	value=msg->len-(int)(body-msg->buf);
+	value=msg->len-(int)(body-msg->buf)+diff;
 	value_s=int2str(value, &value_len);
 	value_s=int2str(value, &value_len);
 	DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
 	DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
 		
 		
@@ -499,7 +501,7 @@ static inline int lump_check_opt(	enum lump_conditions cond,
 
 
 /* computes the "unpacked" len of a lump list,
 /* computes the "unpacked" len of a lump list,
    code moved from build_req_from_req */
    code moved from build_req_from_req */
-static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
+static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct socket_info* send_sock)
 {
 {
 	int s_offset;
 	int s_offset;
 	int new_len;
 	int new_len;
@@ -672,7 +674,7 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
 		send_port_str=&(send_sock->port_no_str);
 		send_port_str=&(send_sock->port_no_str);
 	
 	
 	
 	
-	for(t=msg->add_rm;t;t=t->next){
+	for(t=lumps;t;t=t->next){
 		/* skip if this is an OPT lump and the condition is not satisfied */
 		/* skip if this is an OPT lump and the condition is not satisfied */
 		if ((t->op==LUMP_ADD_OPT) && !lump_check_opt(t->u.cond, msg, send_sock))
 		if ((t->op==LUMP_ADD_OPT) && !lump_check_opt(t->u.cond, msg, send_sock))
 			continue;
 			continue;
@@ -763,7 +765,8 @@ skip_after:
 /* another helper functions, adds/Removes the lump,
 /* another helper functions, adds/Removes the lump,
 	code moved form build_req_from_req  */
 	code moved form build_req_from_req  */
 
 
-static inline void process_lumps(	struct sip_msg* msg,	
+static inline void process_lumps(	struct sip_msg* msg,
+					                                struct lump* lumps,
 									char* new_buf, 
 									char* new_buf, 
 									unsigned int* new_buf_offs, 
 									unsigned int* new_buf_offs, 
 									unsigned int* orig_offs,
 									unsigned int* orig_offs,
@@ -1027,7 +1030,7 @@ static inline void process_lumps(	struct sip_msg* msg,
 	offset=*new_buf_offs;
 	offset=*new_buf_offs;
 	s_offset=*orig_offs;
 	s_offset=*orig_offs;
 	
 	
-	for (t=msg->add_rm;t;t=t->next){
+	for (t=lumps;t;t=t->next){
 		switch(t->op){
 		switch(t->op){
 			case LUMP_ADD:
 			case LUMP_ADD:
 			case LUMP_ADD_SUBST:
 			case LUMP_ADD_SUBST:
@@ -1184,12 +1187,109 @@ skip_nop_after:
 }
 }
 
 
 
 
+/*
+ * Adjust/insert Content-Length if necesarry
+ */
+static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
+{
+	struct lump* anchor;
+	char* clen_buf;
+	int clen_len;
+
+	/* Calculate message length difference caused by lumps modifying message
+	 * body, from this point on the message body must not be modified. Zero
+	 * value indicates that the body hasn't been modified
+	*/
+
+	clen_buf = 0;
+	anchor=0;
+	
+	/* check to see if we need to add clen */
+#ifdef USE_TCP
+	if (proto == PROTO_TCP
+#ifdef USE_TLS
+	    || proto == PROTO_TLS
+#endif
+	    ) {
+		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
+			LOG(L_ERR, "adjust_clen: error parsing content-length\n");
+			goto error;
+		}
+		if (msg->content_length==0){
+			/* not present, we need to add it */
+			/* msg->unparsed should point just before the final crlf
+			 * - whole message was parsed by the above parse_headers
+			 *   which did not find content-length */
+			anchor=anchor_lump(msg, msg->unparsed-msg->buf, 0,
+												HDR_CONTENTLENGTH);
+			if (anchor==0){
+				LOG(L_ERR, "adjust_clen: cannot set clen anchor\n");
+				goto error;
+			}
+		}
+	}
+#endif
+	
+	
+	if ((anchor==0) && body_delta){
+		if (parse_headers(msg, HDR_CONTENTLENGTH, 0) == -1) {
+			LOG(L_ERR, "adjust_clen: Error parsing Content-Length\n");
+			goto error;
+		}
+		
+		/* The body has been changed, try to find
+		 * existing Content-Length
+		 */
+		/* no need for Content-Length if it's and UDP packet and
+		 * it hasn't Content-Lentgh already */
+		if ((msg->content_length==0)){
+		    /* content-length doesn't exist, append it */
+			/* msg->unparsed should point just before the final crlf
+			 * - whole message was parsed by the above parse_headers
+			 *   which did not find content-length */
+			if (proto!=PROTO_UDP){
+				anchor=anchor_lump(msg, msg->unparsed-msg->buf, 0,
+													HDR_CONTENTLENGTH);
+				if (anchor==0){
+					LOG(L_ERR, "adjust_clen: cannot set clen anchor\n");
+					goto error;
+				}
+			}else{
+				DBG("add_clen: UDP packet with no clen => not adding one \n");
+			}
+		}else{
+			/* Content-Length has been found, remove it */
+			anchor = del_lump(	msg, msg->content_length->name.s - msg->buf,
+								msg->content_length->len, HDR_CONTENTLENGTH);
+			if (anchor==0) {
+				LOG(L_ERR, "adjust_clen: Can't remove original"
+							" Content-Length\n");
+				goto error;
+			}
+		}
+	}
+	
+	if (anchor){
+		clen_buf = clen_builder(msg, &clen_len, body_delta);
+		if (!clen_buf) goto error;
+		if (insert_new_lump_after(anchor, clen_buf, clen_len,
+					HDR_CONTENTLENGTH) == 0)
+			goto error;
+	}
+
+	return 0;
+error:
+	if (clen_buf) pkg_free(clen_buf);
+	return -1;
+}
+
+
 
 
 char * build_req_buf_from_sip_req( struct sip_msg* msg,
 char * build_req_buf_from_sip_req( struct sip_msg* msg,
 								unsigned int *returned_len,
 								unsigned int *returned_len,
 								struct socket_info* send_sock, int proto)
 								struct socket_info* send_sock, int proto)
 {
 {
-	unsigned int len, new_len, received_len, rport_len, uri_len, via_len;
+	unsigned int len, new_len, received_len, rport_len, uri_len, via_len, body_delta;
 	char* line_buf;
 	char* line_buf;
 	char* received_buf;
 	char* received_buf;
 	char* rport_buf;
 	char* rport_buf;
@@ -1201,18 +1301,14 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	str branch;
 	str branch;
 	str extra_params;
 	str extra_params;
 	struct hostport hp;
 	struct hostport hp;
-	
+
 #ifdef USE_TCP
 #ifdef USE_TCP
 	char* id_buf;
 	char* id_buf;
 	unsigned int id_len;
 	unsigned int id_len;
-	char* clen_buf;
-	unsigned int clen_len;
 	
 	
 	
 	
 	id_buf=0;
 	id_buf=0;
 	id_len=0;
 	id_len=0;
-	clen_buf=0;
-	clen_len=0;
 #endif
 #endif
 	via_insert_param=0;
 	via_insert_param=0;
 	extra_params.len=0;
 	extra_params.len=0;
@@ -1226,7 +1322,6 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	received_buf=0;
 	received_buf=0;
 	rport_buf=0;
 	rport_buf=0;
 	line_buf=0;
 	line_buf=0;
-
 	
 	
 #ifdef USE_TCP
 #ifdef USE_TCP
 	/* add id if tcp */
 	/* add id if tcp */
@@ -1246,31 +1341,17 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 		extra_params.s=id_buf;
 		extra_params.s=id_buf;
 		extra_params.len=id_len;
 		extra_params.len=id_len;
 	}
 	}
-	/* if sending proto == tcp, check if Content-Length needs to be added*/
-	if (proto==PROTO_TCP
-#ifdef USE_TLS
-			|| proto==PROTO_TLS
 #endif
 #endif
-			){
-		DBG("build_req_from_req: checking for clen; proto=%d,"
-			" rcv->proto=%d\n", proto, msg->rcv.proto);
-		/* first of all parse content-length */
-		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
-			LOG(L_ERR, "build_req_buf_from_sip_req:"
-							" error parsing content-length\n");
-			goto skip_clen;
-		}
-		if (msg->content_length==0){
-			/* we need to add it */
-			if ((clen_buf=clen_builder(msg, &clen_len))==0){
-				LOG(L_ERR, "build_req_buf_from_sip_req:" 
-								" clen_builder failed\n");
-				goto skip_clen;
-			}
-		}
+	     /* Calculate message body difference and adjust
+	      * Content-Length
+	      */
+	body_delta = lumps_len(msg, msg->body_lumps, send_sock);
+	if (adjust_clen(msg, body_delta, proto) < 0) {
+		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: Error while adjusting"
+				" Content-Length\n");
+		goto error00;
 	}
 	}
-skip_clen:
-#endif
+
 	branch.s=msg->add_to_branch_s;
 	branch.s=msg->add_to_branch_s;
 	branch.len=msg->add_to_branch_len;
 	branch.len=msg->add_to_branch_len;
 	set_hostport(&hp, msg);
 	set_hostport(&hp, msg);
@@ -1306,7 +1387,7 @@ skip_clen:
 	/* add via header to the list */
 	/* add via header to the list */
 	/* try to add it before msg. 1st via */
 	/* try to add it before msg. 1st via */
 	/* add first via, as an anchor for second via*/
 	/* add first via, as an anchor for second via*/
-	anchor=anchor_lump(&(msg->add_rm), msg->via1->hdr.s-buf, 0, HDR_VIA);
+	anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA);
 	if (anchor==0) goto error01;
 	if (anchor==0) goto error01;
 	if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)
 	if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)
 		goto error01;
 		goto error01;
@@ -1332,11 +1413,11 @@ skip_clen:
 	 * overwrite the previous one if already present */
 	 * overwrite the previous one if already present */
 	if (received_len){
 	if (received_len){
 		if (msg->via1->received){ /* received already present => overwrite it*/
 		if (msg->via1->received){ /* received already present => overwrite it*/
-			via_insert_param=del_lump(&(msg->add_rm),
+			via_insert_param=del_lump(msg,
 								msg->via1->received->start-buf-1, /*;*/
 								msg->via1->received->start-buf-1, /*;*/
 								msg->via1->received->size+1, /*;*/ HDR_VIA);
 								msg->via1->received->size+1, /*;*/ HDR_VIA);
 		}else if (via_insert_param==0){ /* receive not present, ok */
 		}else if (via_insert_param==0){ /* receive not present, ok */
-			via_insert_param=anchor_lump(&(msg->add_rm),
+			via_insert_param=anchor_lump(msg,
 										msg->via1->hdr.s-buf+size,0, HDR_VIA);
 										msg->via1->hdr.s-buf+size,0, HDR_VIA);
 		}
 		}
 		if (via_insert_param==0) goto error02; /* free received_buf */
 		if (via_insert_param==0) goto error02; /* free received_buf */
@@ -1346,12 +1427,12 @@ skip_clen:
 	/* if rport needs to be updated, delete it if present and add it's value */
 	/* if rport needs to be updated, delete it if present and add it's value */
 	if (rport_len){
 	if (rport_len){
 		if (msg->via1->rport){ /* rport already present */
 		if (msg->via1->rport){ /* rport already present */
-			via_insert_param=del_lump(&(msg->add_rm),
+			via_insert_param=del_lump(msg,
 								msg->via1->rport->start-buf-1, /*';'*/
 								msg->via1->rport->start-buf-1, /*';'*/
 								msg->via1->rport->size+1 /* ; */, HDR_VIA);
 								msg->via1->rport->size+1 /* ; */, HDR_VIA);
 		}else if (via_insert_param==0){ /*force rport, no rport present */
 		}else if (via_insert_param==0){ /*force rport, no rport present */
 			/* no rport, add it */
 			/* no rport, add it */
-			via_insert_param=anchor_lump(&(msg->add_rm),
+			via_insert_param=anchor_lump(msg,
 										msg->via1->hdr.s-buf+size,0, HDR_VIA);
 										msg->via1->hdr.s-buf+size,0, HDR_VIA);
 		}
 		}
 		if (via_insert_param==0) goto error03; /* free rport_buf */
 		if (via_insert_param==0) goto error03; /* free rport_buf */
@@ -1360,22 +1441,9 @@ skip_clen:
 			goto error03; /* free rport_buf */
 			goto error03; /* free rport_buf */
 			
 			
 	}
 	}
-#ifdef USE_TCP
-	/* if clen needs to be added, add it */
-	if (clen_len){
-		/* msg->unparsed should point just before the final crlf,
-		 * parse_headers is called from clen_builder */
-		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0,
-							 HDR_CONTENTLENGTH);
-		if (anchor==0) goto error04; /* free clen_buf */
-		if (insert_new_lump_after(anchor, clen_buf, clen_len,
-					HDR_CONTENTLENGTH)==0)
-			goto error04; /* free clen_buf*/
-	}
-#endif
 
 
 	/* compute new msg len and fix overlapping zones*/
 	/* compute new msg len and fix overlapping zones*/
-	new_len=len+lumps_len(msg, send_sock);
+	new_len=len+body_delta+lumps_len(msg, msg->add_rm, send_sock);
 #ifdef XL_DEBUG
 #ifdef XL_DEBUG
 	LOG(L_ERR, "DEBUG: new_len(%d)=len(%d)+lumps_len\n", new_len, len);
 	LOG(L_ERR, "DEBUG: new_len(%d)=len(%d)+lumps_len\n", new_len, len);
 #endif
 #endif
@@ -1405,7 +1473,8 @@ skip_clen:
 	}
 	}
 	new_buf[new_len]=0;
 	new_buf[new_len]=0;
 	/* copy msg adding/removing lumps */
 	/* copy msg adding/removing lumps */
-	process_lumps(msg, new_buf, &offset, &s_offset, send_sock);
+	process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, send_sock);
+	process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset,send_sock);
 	/* copy the rest of the message */
 	/* copy the rest of the message */
 	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
 	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
 	new_buf[new_len]=0;
 	new_buf[new_len]=0;
@@ -1431,10 +1500,6 @@ error02:
 	if (received_buf) pkg_free(received_buf);
 	if (received_buf) pkg_free(received_buf);
 error03:
 error03:
 	if (rport_buf) pkg_free(rport_buf);
 	if (rport_buf) pkg_free(rport_buf);
-#ifdef USE_TCP
-error04:
-	if (clen_buf) pkg_free(clen_buf);
-#endif
 error00:
 error00:
 #ifdef USE_TCP
 #ifdef USE_TCP
 	if (id_buf) pkg_free(id_buf);
 	if (id_buf) pkg_free(id_buf);
@@ -1448,19 +1513,12 @@ error00:
 char * build_res_buf_from_sip_res( struct sip_msg* msg,
 char * build_res_buf_from_sip_res( struct sip_msg* msg,
 				unsigned int *returned_len)
 				unsigned int *returned_len)
 {
 {
-	unsigned int new_len, via_len;
+	unsigned int new_len, via_len, body_delta;
 	char* new_buf;
 	char* new_buf;
 	unsigned offset, s_offset, via_offset;
 	unsigned offset, s_offset, via_offset;
 	char* buf;
 	char* buf;
 	unsigned int len;
 	unsigned int len;
-#ifdef USE_TCP
-	struct lump* anchor;
-	char* clen_buf;
-	unsigned int clen_len;
-	
-	clen_buf=0;
-	clen_len=0;
-#endif
+
 	buf=msg->buf;
 	buf=msg->buf;
 	len=msg->len;
 	len=msg->len;
 	new_buf=0;
 	new_buf=0;
@@ -1473,57 +1531,26 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
 		via_offset=msg->h_via1->name.s-buf;
 		via_offset=msg->h_via1->name.s-buf;
 	}
 	}
 
 
-#ifdef USE_TCP
-
-	/* if sending proto == tcp, check if Content-Length needs to be added*/
-	if (msg->via2 && ((msg->via2->proto==PROTO_TCP)
-#ifdef USE_TLS
-				|| (msg->via2->proto==PROTO_TLS)
-#endif
-				)){
-		DBG("build_res_from_sip_res: checking content-length for \n%.*s\n",
-				(int)msg->len, msg->buf);
-		/* first of all parse content-length */
-		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
-			LOG(L_ERR, "build_res_buf_from_sip_res:"
-							" error parsing content-length\n");
-			goto skip_clen;
-		}
-		if (msg->content_length==0){
-			DBG("build_res_from_sip_res: no content_length hdr found\n");
-			/* we need to add it */
-			if ((clen_buf=clen_builder(msg, &clen_len))==0){
-				LOG(L_ERR, "build_res_buf_from_sip_res:" 
-								" clen_builder failed\n");
-				goto skip_clen;
-			}
-		}
+	     /* Calculate message body difference and adjust
+	      * Content-Length
+	      */
+	body_delta = lumps_len(msg, msg->body_lumps, 0);
+	if (adjust_clen(msg, body_delta, (msg->via2? msg->via2->proto:PROTO_UDP))
+			< 0) {
+		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: Error while adjusting"
+				" Content-Length\n");
+		goto error;
 	}
 	}
-skip_clen:
-#endif
-	
+
 	/* remove the first via*/
 	/* remove the first via*/
-	if (del_lump( &(msg->add_rm), via_offset, via_len, HDR_VIA)==0){
+	if (del_lump( msg, via_offset, via_len, HDR_VIA)==0){
 		LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
 		LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
 					"via\n");
 					"via\n");
 		goto error;
 		goto error;
 	}
 	}
-#ifdef USE_TCP
-	/* if clen needs to be added, add it */
-	if (clen_len){
-		/* msg->unparsed should point just before the final crlf,
-		 * parse_headers is called from clen_builder */
-		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0, 
-							HDR_CONTENTLENGTH);
-		DBG("build_res_from_sip_res: adding content-length: %.*s\n",
-				(int)clen_len, clen_buf);
-		if (anchor==0) goto error_clen; /* free clen_buf*/
-		if (insert_new_lump_after(anchor, clen_buf, clen_len,
-					HDR_CONTENTLENGTH)==0)
-			goto error_clen; /* free clen_buf*/
-	}
-#endif
-	new_len=len+lumps_len(msg, 0); /*FIXME: we don't know the send sock */
+
+	new_len=len+body_delta+lumps_len(msg, msg->add_rm, 0); /*FIXME: we don't
+														know the send sock */
 	
 	
 	DBG(" old size: %d, new size: %d\n", len, new_len);
 	DBG(" old size: %d, new size: %d\n", len, new_len);
 	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging 
 	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging 
@@ -1534,7 +1561,9 @@ skip_clen:
 	}
 	}
 	new_buf[new_len]=0; /* debug: print the message */
 	new_buf[new_len]=0; /* debug: print the message */
 	offset=s_offset=0;
 	offset=s_offset=0;
-	process_lumps(msg, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/
+	/*FIXME: no send sock*/
+	process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, 0);/*FIXME:*/
+	process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset, 0);
 	/* copy the rest of the message */
 	/* copy the rest of the message */
 	memcpy(new_buf+offset,
 	memcpy(new_buf+offset,
 		buf+s_offset, 
 		buf+s_offset, 
@@ -1545,10 +1574,6 @@ skip_clen:
 
 
 	*returned_len=new_len;
 	*returned_len=new_len;
 	return new_buf;
 	return new_buf;
-#ifdef USE_TCP
-error_clen:
-	if (clen_buf) pkg_free(clen_buf);
-#endif
 error:
 error:
 	*returned_len=0;
 	*returned_len=0;
 	return 0;
 	return 0;

+ 1 - 0
parser/msg_parser.c

@@ -588,6 +588,7 @@ void free_sip_msg(struct sip_msg* msg)
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
 	if (msg->headers)     free_hdr_field_lst(msg->headers);
 	if (msg->headers)     free_hdr_field_lst(msg->headers);
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
+	if (msg->body_lumps)  free_lump_list(msg->body_lumps);
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
 	/* don't free anymore -- now a pointer to a static buffer */
 	/* don't free anymore -- now a pointer to a static buffer */
 #	ifdef DYN_BUF
 #	ifdef DYN_BUF

+ 2 - 1
parser/msg_parser.h

@@ -43,7 +43,7 @@
 
 
 #include "../comp_defs.h"
 #include "../comp_defs.h"
 #include "../str.h"
 #include "../str.h"
-#include "../data_lump.h"
+#include "../lump_struct.h"
 #include "../flags.h"
 #include "../flags.h"
 #include "../ip_addr.h"
 #include "../ip_addr.h"
 #include "../md5utils.h"
 #include "../md5utils.h"
@@ -212,6 +212,7 @@ struct sip_msg {
 	struct sip_uri parsed_orig_ruri;
 	struct sip_uri parsed_orig_ruri;
 	
 	
 	struct lump* add_rm;       /* used for all the forwarded requests/replies */
 	struct lump* add_rm;       /* used for all the forwarded requests/replies */
+	struct lump* body_lumps;     /* Lumps that update Content-Length */
 	struct lump_rpl *reply_lump; /* only for localy generated replies !!!*/
 	struct lump_rpl *reply_lump; /* only for localy generated replies !!!*/
 
 
 	/* str add_to_branch; 
 	/* str add_to_branch;