Browse code

- "body_lump" changes reverted, sorry.

Jan Janak authored on 15/10/2003 08:47:56
Showing 6 changed files
... ...
@@ -1454,8 +1454,6 @@ struct sip_msg {
1454 1454
 		
1455 1455
     struct lump* add_rm;         /* used for all the forwarded 
1456 1456
                                   * requests */
1457
-    struct lump* body_lumps;     /* Lumps that modify message body
1458
-                                  * (update Content-Length */
1459 1457
     struct lump* repl_add_rm;    /* used for all the forwarded replies */
1460 1458
     struct lump_rpl *reply_lump; /* only for locally generated replies !!!*/
1461 1459
 
... ...
@@ -253,6 +253,7 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
253 253
 	struct via_param  *prm;
254 254
 	struct to_param   *to_prm,*new_to_prm;
255 255
 	struct sip_msg    *new_msg;
256
+	struct lump       *lump_chain, *lump_tmp, **lump_anchor, **lump_anchor2;
256 257
 	struct lump_rpl   *rpl_lump, **rpl_lump_anchor;
257 258
 	char              *p,*foo;
258 259
 
... ...
@@ -339,30 +340,24 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
339 339
 	}/*for all headers*/
340 340
 
341 341
 	/* length of the data lump structures */
342
-#define LUMP_LIST_LEN(len, list) \
343
-do { \
344
-        struct lump* lump_tmp; \
345
-	while ((list)) \
346
-	{ \
347
-		(len) += lump_len((list)); \
348
-		lump_tmp = (list)->before; \
349
-		while ( lump_tmp ) \
350
-		{ \
351
-			(len) += lump_len( lump_tmp ); \
352
-			lump_tmp = lump_tmp->before; \
353
-		} \
354
-		lump_tmp = (list)->after; \
355
-		while ( lump_tmp ) \
356
-		{ \
357
-			(len) += lump_len( lump_tmp ); \
358
-			lump_tmp = lump_tmp->after; \
359
-		} \
360
-		(list) = (list)->next; \
361
-	} \
362
-} while(0);
363
-
364
-	LUMP_LIST_LEN(len, org_msg->add_rm);
365
-	LUMP_LIST_LEN(len, org_msg->body_lumps);
342
+	lump_chain = org_msg->add_rm;
343
+	while (lump_chain)
344
+	{
345
+		len += lump_len( lump_chain );
346
+		lump_tmp = lump_chain->before;
347
+		while ( lump_tmp )
348
+		{
349
+			len += lump_len( lump_tmp );
350
+			lump_tmp = lump_tmp->before;
351
+		}
352
+		lump_tmp = lump_chain->after;
353
+		while ( lump_tmp )
354
+		{
355
+			len += lump_len( lump_tmp );
356
+			lump_tmp = lump_tmp->after;
357
+		}
358
+		lump_chain = lump_chain->next;
359
+	}
366 360
 
367 361
 	/*length of reply lump structures*/
368 362
 	for(rpl_lump=org_msg->reply_lump;rpl_lump;rpl_lump=rpl_lump->next)
... ...
@@ -381,7 +376,6 @@ do { \
381 381
 	memcpy( new_msg , org_msg , sizeof(struct sip_msg) );
382 382
 	p += ROUND4(sizeof(struct sip_msg));
383 383
 	new_msg->add_rm = 0;
384
-	new_msg->body_lumps = 0;
385 384
 	/* new_uri */
386 385
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
387 386
 	{
... ...
@@ -635,42 +629,33 @@ do { \
635 635
 		new_msg->last_header = last_hdr;
636 636
 	}
637 637
 
638
-
639
-	     /* clonning data lump */
640
-#define CLONE_LUMP_LIST(anchor, list) \
641
-{ \
642
-        struct lump* lump_tmp, *l; \
643
-        struct lump** lump_anchor2, **a; \
644
-        a = anchor; \
645
-        l = list; \
646
-	while (l) \
647
-	{ \
648
-		lump_clone( (*a) , l , p ); \
649
-		/*before list*/ \
650
-		lump_tmp = l->before; \
651
-		lump_anchor2 = &((*a)->before); \
652
-		while ( lump_tmp ) \
653
-		{ \
654
-			lump_clone( (*lump_anchor2) , lump_tmp , p ); \
655
-			lump_anchor2 = &((*lump_anchor2)->before); \
656
-			lump_tmp = lump_tmp->before; \
657
-		} \
658
-		/*after list*/ \
659
-		lump_tmp = l->after; \
660
-		lump_anchor2 = &((*a)->after); \
661
-		while ( lump_tmp ) \
662
-		{ \
663
-			lump_clone( (*lump_anchor2) , lump_tmp , p ); \
664
-			lump_anchor2 = &((*lump_anchor2)->after); \
665
-			lump_tmp = lump_tmp->after; \
666
-		} \
667
-		a = &((*a)->next); \
668
-		l = l->next; \
669
-	} \
670
-}
671
-
672
-        CLONE_LUMP_LIST(&(new_msg->add_rm), org_msg->add_rm);
673
-        CLONE_LUMP_LIST(&(new_msg->body_lumps), org_msg->body_lumps);
638
+	/* clonning data lump */
639
+		lump_chain = org_msg->add_rm;
640
+		lump_anchor = &(new_msg->add_rm);
641
+	while (lump_chain)
642
+	{
643
+		lump_clone( (*lump_anchor) , lump_chain , p );
644
+		/*before list*/
645
+		lump_tmp = lump_chain->before;
646
+		lump_anchor2 = &((*lump_anchor)->before);
647
+		while ( lump_tmp )
648
+		{
649
+			lump_clone( (*lump_anchor2) , lump_tmp , p );
650
+			lump_anchor2 = &((*lump_anchor2)->before);
651
+			lump_tmp = lump_tmp->before;
652
+		}
653
+		/*after list*/
654
+		lump_tmp = lump_chain->after;
655
+		lump_anchor2 = &((*lump_anchor)->after);
656
+		while ( lump_tmp )
657
+		{
658
+			lump_clone( (*lump_anchor2) , lump_tmp , p );
659
+			lump_anchor2 = &((*lump_anchor2)->after);
660
+			lump_tmp = lump_tmp->after;
661
+		}
662
+		lump_anchor = &((*lump_anchor)->next);
663
+		lump_chain = lump_chain->next;
664
+	}
674 665
 
675 666
 	/*cloning reply lump structures*/
676 667
 	rpl_lump_anchor = &(new_msg->reply_lump);
... ...
@@ -688,6 +673,11 @@ do { \
688 688
 	}
689 689
 
690 690
 	clone_authorized_hooks(new_msg, org_msg);
691
-	
691
+
692 692
 	return new_msg;
693 693
 }
694
+
695
+
696
+
697
+
698
+
... ...
@@ -413,7 +413,6 @@ static int faked_env(struct sip_msg *fake,
413 413
 	/* set items, which will be duped to pkg_mem, to zero, so that
414 414
 	 * "restore" called on error does not free the original items */
415 415
 	fake->add_rm=0;
416
-	fake->body_lumps = 0;
417 416
 	fake->new_uri.s=0; fake->new_uri.len=0; 
418 417
 
419 418
 	/* remember we are back in request processing, but process
... ...
@@ -460,21 +459,12 @@ static int faked_env(struct sip_msg *fake,
460 460
 			goto restore;
461 461
 		}
462 462
 	}
463
-	
464
-	if (shmem_msg->body_lumps) {
465
-		fake->body_lumps=dup_lump_list(shmem_msg->body_lumps);
466
-		if (!fake->body_lumps) { /* non_empty->empty ... failure */
467
-			LOG(L_ERR, "ERROR: on_negative_reply: body lump dup failed\n");
468
-			goto restore;
469
-		}
470
-	}
471 463
 	/* success */
472 464
 	return 1;
473 465
 
474 466
 restore:
475 467
 	/* restore original environment and destroy faked message */
476 468
 	free_duped_lump_list(fake->add_rm);
477
-	free_duped_lump_list(fake->body_lumps);
478 469
 	if (fake->new_uri.s) pkg_free(fake->new_uri.s);
479 470
 	set_t(backup_t);
480 471
 	global_msg_id=backup_msgid;
... ...
@@ -394,7 +394,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
394 394
 
395 395
 
396 396
 
397
-char* clen_builder(struct sip_msg* msg, unsigned int *clen_len, int body_delta)
397
+char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
398 398
 {
399 399
 	char* buf;
400 400
 	int len;
... ...
@@ -408,10 +408,10 @@ char* clen_builder(struct sip_msg* msg, unsigned int *clen_len, int body_delta)
408 408
 	if (body==0){
409 409
 		ser_error=E_BAD_REQ;
410 410
 		LOG(L_ERR, "ERROR: clen_builder: no message body found"
411
-		    " (missing crlf?)");
411
+					" (missing crlf?)");
412 412
 		return 0;
413 413
 	}
414
-	value=msg->len-(int)(body-msg->buf) + body_delta;
414
+	value=msg->len-(int)(body-msg->buf);
415 415
 	value_s=int2str(value, &value_len);
416 416
 	DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
417 417
 		
... ...
@@ -499,7 +499,7 @@ static inline int lump_check_opt(	enum lump_conditions cond,
499 499
 
500 500
 /* computes the "unpacked" len of a lump list,
501 501
    code moved from build_req_from_req */
502
-static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct socket_info* send_sock)
502
+static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
503 503
 {
504 504
 	int s_offset;
505 505
 	int new_len;
... ...
@@ -672,7 +672,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct sock
672 672
 		send_port_str=&(send_sock->port_no_str);
673 673
 	
674 674
 	
675
-	for(t=lumps;t;t=t->next){
675
+	for(t=msg->add_rm;t;t=t->next){
676 676
 		/* skip if this is an OPT lump and the condition is not satisfied */
677 677
 		if ((t->op==LUMP_ADD_OPT) && !lump_check_opt(t->u.cond, msg, send_sock))
678 678
 			continue;
... ...
@@ -764,11 +764,10 @@ skip_after:
764 764
 	code moved form build_req_from_req  */
765 765
 
766 766
 static inline void process_lumps(	struct sip_msg* msg,	
767
-					struct lump* lumps,
768
-					char* new_buf, 
769
-					unsigned int* new_buf_offs, 
770
-					unsigned int* orig_offs,
771
-					struct socket_info* send_sock)
767
+									char* new_buf, 
768
+									unsigned int* new_buf_offs, 
769
+									unsigned int* orig_offs,
770
+									struct socket_info* send_sock)
772 771
 {
773 772
 	struct lump *t;
774 773
 	struct lump *r;
... ...
@@ -1028,7 +1027,7 @@ static inline void process_lumps(	struct sip_msg* msg,
1028 1028
 	offset=*new_buf_offs;
1029 1029
 	s_offset=*orig_offs;
1030 1030
 	
1031
-	for (t=lumps;t;t=t->next){
1031
+	for (t=msg->add_rm;t;t=t->next){
1032 1032
 		switch(t->op){
1033 1033
 			case LUMP_ADD:
1034 1034
 			case LUMP_ADD_SUBST:
... ...
@@ -1185,101 +1184,12 @@ skip_nop_after:
1185 1185
 }
1186 1186
 
1187 1187
 
1188
-/*
1189
- * Adjust/insert Content-Length if necesarry
1190
- */
1191
-static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1192
-{
1193
-	struct lump* anchor;
1194
-	char* clen_buf;
1195
-	int clen_len;
1196
-	
1197
-	     /* Calculate message length difference caused by 
1198
-	      * lumps modifying message body, from this point on
1199
-	      * the message body must not be modified. Zero value
1200
-	      * indicates that the body hasn't been modified
1201
-	      */
1202
-	clen_buf = 0;
1203
-
1204
-	if (body_delta) {
1205
-		     /* The body has been changed, try to find
1206
-		      * existing Content-Length
1207
-		      */
1208
-		if (parse_headers(msg, HDR_CONTENTLENGTH, 0) == -1) {
1209
-			LOG(L_ERR, "adjust_clen: Error parsing content-length\n");
1210
-			goto error;
1211
-		}
1212
-
1213
-		anchor = 0;
1214
-		if (msg->content_length) {
1215
-			     /* Content-Length has been found,
1216
-			      * remove it
1217
-			      */
1218
-			anchor = del_lump(&msg->add_rm, msg->content_length->name.s - msg->buf, 
1219
-					  msg->content_length->len, HDR_CONTENTLENGTH);
1220
-			if (!anchor) {
1221
-				LOG(L_ERR, "build_req_from_sip_req: Can't remove original Content-Length\n");
1222
-				goto error;
1223
-			}
1224
-		}
1225
-
1226
-		if (proto == PROTO_UDP) {
1227
-			     /* Protocol is UDP and Content-Length has
1228
-			      * been removed, insert new value
1229
-			      */
1230
-			if (anchor) {
1231
-				clen_buf = clen_builder(msg, &clen_len, body_delta);
1232
-				if (!clen_buf) goto error;
1233
-				if (insert_new_lump_after(anchor, clen_buf, clen_len, HDR_CONTENTLENGTH) == 0) goto error;
1234
-			}
1235
-		} else {
1236
-			     /* Protocol is not UDP, insert new Content-Length,
1237
-			      * no matter if Content-Length has been removed or not
1238
-			      */
1239
-			if (!anchor) {
1240
-				     /* Create anchor */
1241
-				     /* msg->unparsed should point just before the final crlf,
1242
-				      * parse_headers is called from clen_builder */
1243
-				anchor = anchor_lump(&(msg->add_rm), msg->unparsed - msg->buf, 0, HDR_CONTENTLENGTH);
1244
-				if (!anchor) goto error;
1245
-			}
1246
-
1247
-			clen_buf = clen_builder(msg, &clen_len, body_delta);
1248
-			if (!clen_buf) goto error;
1249
-			if (insert_new_lump_after(anchor, clen_buf, clen_len, HDR_CONTENTLENGTH) == 0) goto error;
1250
-		}
1251
-	} else {
1252
-#ifdef USE_TCP
1253
-		if (proto == PROTO_TCP
1254
-#ifdef USE_TLS
1255
-		    || proto == PROTO_TLS
1256
-#endif
1257
-		    ) {
1258
-			anchor = anchor_lump(&(msg->add_rm), msg->unparsed - msg->buf, 0, HDR_CONTENTLENGTH);
1259
-			if (!anchor) goto error;
1260
-			
1261
-			clen_buf = clen_builder(msg, &clen_len, body_delta);
1262
-			if (!clen_buf) goto error;
1263
-			if (insert_new_lump_after(anchor, clen_buf, clen_len, HDR_CONTENTLENGTH) == 0) goto error;
1264
-		}
1265
-#endif
1266
-	}
1267
-
1268
-	return 0;
1269
-
1270
- error:
1271
-	if (clen_buf) pkg_free(clen_buf);
1272
-	return -1;
1273
-}
1274
-
1275
-
1276
-
1277 1188
 
1278 1189
 char * build_req_buf_from_sip_req( struct sip_msg* msg,
1279 1190
 								unsigned int *returned_len,
1280 1191
 								struct socket_info* send_sock, int proto)
1281
-{	
1282
-	unsigned int len, new_len, received_len, rport_len, uri_len, via_len, body_delta;
1192
+{
1193
+	unsigned int len, new_len, received_len, rport_len, uri_len, via_len;
1283 1194
 	char* line_buf;
1284 1195
 	char* received_buf;
1285 1196
 	char* rport_buf;
... ...
@@ -1291,16 +1201,18 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1291 1291
 	str branch;
1292 1292
 	str extra_params;
1293 1293
 	struct hostport hp;
1294
-	char* clen_buf;
1295
-	unsigned int clen_len;
1296 1294
 	
1297 1295
 #ifdef USE_TCP
1298 1296
 	char* id_buf;
1299 1297
 	unsigned int id_len;
1298
+	char* clen_buf;
1299
+	unsigned int clen_len;
1300 1300
 	
1301 1301
 	
1302 1302
 	id_buf=0;
1303 1303
 	id_len=0;
1304
+	clen_buf=0;
1305
+	clen_len=0;
1304 1306
 #endif
1305 1307
 	via_insert_param=0;
1306 1308
 	extra_params.len=0;
... ...
@@ -1314,8 +1226,6 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1314 1314
 	received_buf=0;
1315 1315
 	rport_buf=0;
1316 1316
 	line_buf=0;
1317
-	clen_buf=0;
1318
-	clen_len=0;
1319 1317
 
1320 1318
 	
1321 1319
 #ifdef USE_TCP
... ...
@@ -1336,16 +1246,31 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1336 1336
 		extra_params.s=id_buf;
1337 1337
 		extra_params.len=id_len;
1338 1338
 	}
1339
+	/* if sending proto == tcp, check if Content-Length needs to be added*/
1340
+	if (proto==PROTO_TCP
1341
+#ifdef USE_TLS
1342
+			|| proto==PROTO_TLS
1339 1343
 #endif
1340
-	     /* Calculate messsage body difference and adjust
1341
-	      * Content-Length
1342
-	      */
1343
-	body_delta = lumps_len(msg, msg->body_lumps, send_sock);
1344
-        if (adjust_clen(msg, body_delta, proto) < 0) {
1345
-		LOG(L_ERR, "ERROR: build_req_buf_from sip_req: Error while adjusting Contact-Length\n");
1346
-		goto error00;
1344
+			){
1345
+		DBG("build_req_from_req: checking for clen; proto=%d,"
1346
+			" rcv->proto=%d\n", proto, msg->rcv.proto);
1347
+		/* first of all parse content-length */
1348
+		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
1349
+			LOG(L_ERR, "build_req_buf_from_sip_req:"
1350
+							" error parsing content-length\n");
1351
+			goto skip_clen;
1352
+		}
1353
+		if (msg->content_length==0){
1354
+			/* we need to add it */
1355
+			if ((clen_buf=clen_builder(msg, &clen_len))==0){
1356
+				LOG(L_ERR, "build_req_buf_from_sip_req:" 
1357
+								" clen_builder failed\n");
1358
+				goto skip_clen;
1359
+			}
1360
+		}
1347 1361
 	}
1348
-
1362
+skip_clen:
1363
+#endif
1349 1364
 	branch.s=msg->add_to_branch_s;
1350 1365
 	branch.len=msg->add_to_branch_len;
1351 1366
 	set_hostport(&hp, msg);
... ...
@@ -1435,9 +1360,22 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1435 1435
 			goto error03; /* free rport_buf */
1436 1436
 			
1437 1437
 	}
1438
+#ifdef USE_TCP
1439
+	/* if clen needs to be added, add it */
1440
+	if (clen_len){
1441
+		/* msg->unparsed should point just before the final crlf,
1442
+		 * parse_headers is called from clen_builder */
1443
+		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0,
1444
+							 HDR_CONTENTLENGTH);
1445
+		if (anchor==0) goto error04; /* free clen_buf */
1446
+		if (insert_new_lump_after(anchor, clen_buf, clen_len,
1447
+					HDR_CONTENTLENGTH)==0)
1448
+			goto error04; /* free clen_buf*/
1449
+	}
1450
+#endif
1438 1451
 
1439 1452
 	/* compute new msg len and fix overlapping zones*/
1440
-	new_len=len+body_delta+lumps_len(msg, msg->add_rm, send_sock);
1453
+	new_len=len+lumps_len(msg, send_sock);
1441 1454
 #ifdef XL_DEBUG
1442 1455
 	LOG(L_ERR, "DEBUG: new_len(%d)=len(%d)+lumps_len\n", new_len, len);
1443 1456
 #endif
... ...
@@ -1467,8 +1405,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1467 1467
 	}
1468 1468
 	new_buf[new_len]=0;
1469 1469
 	/* copy msg adding/removing lumps */
1470
-	process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, send_sock);
1471
-	process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset, send_sock);
1470
+	process_lumps(msg, new_buf, &offset, &s_offset, send_sock);
1472 1471
 	/* copy the rest of the message */
1473 1472
 	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
1474 1473
 	new_buf[new_len]=0;
... ...
@@ -1494,6 +1431,10 @@ error02:
1494 1494
 	if (received_buf) pkg_free(received_buf);
1495 1495
 error03:
1496 1496
 	if (rport_buf) pkg_free(rport_buf);
1497
+#ifdef USE_TCP
1498
+error04:
1499
+	if (clen_buf) pkg_free(clen_buf);
1500
+#endif
1497 1501
 error00:
1498 1502
 #ifdef USE_TCP
1499 1503
 	if (id_buf) pkg_free(id_buf);
... ...
@@ -1507,16 +1448,22 @@ error00:
1507 1507
 char * build_res_buf_from_sip_res( struct sip_msg* msg,
1508 1508
 				unsigned int *returned_len)
1509 1509
 {
1510
-	unsigned int new_len, via_len, body_delta;
1510
+	unsigned int new_len, via_len;
1511 1511
 	char* new_buf;
1512 1512
 	unsigned offset, s_offset, via_offset;
1513 1513
 	char* buf;
1514 1514
 	unsigned int len;
1515
-
1515
+#ifdef USE_TCP
1516
+	struct lump* anchor;
1517
+	char* clen_buf;
1518
+	unsigned int clen_len;
1519
+	
1520
+	clen_buf=0;
1521
+	clen_len=0;
1522
+#endif
1516 1523
 	buf=msg->buf;
1517 1524
 	len=msg->len;
1518 1525
 	new_buf=0;
1519
-
1520 1526
 	/* we must remove the first via */
1521 1527
 	if (msg->via1->next) {
1522 1528
 		via_len=msg->via1->bsize;
... ...
@@ -1526,23 +1473,57 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
1526 1526
 		via_offset=msg->h_via1->name.s-buf;
1527 1527
 	}
1528 1528
 
1529
-	     /* Calculate messsage body difference and adjust
1530
-	      * Content-Length
1531
-	      */
1532
-	body_delta = lumps_len(msg, msg->body_lumps, 0);
1533
-        if (adjust_clen(msg, body_delta, (msg->via2 ? msg->via2->proto : PROTO_UDP)) < 0) {
1534
-		LOG(L_ERR, "ERROR: build_req_buf_from sip_req: Error while adjusting Contact-Length\n");
1535
-		goto error;
1536
-	}
1529
+#ifdef USE_TCP
1537 1530
 
1531
+	/* if sending proto == tcp, check if Content-Length needs to be added*/
1532
+	if (msg->via2 && ((msg->via2->proto==PROTO_TCP)
1533
+#ifdef USE_TLS
1534
+				|| (msg->via2->proto==PROTO_TLS)
1535
+#endif
1536
+				)){
1537
+		DBG("build_res_from_sip_res: checking content-length for \n%.*s\n",
1538
+				(int)msg->len, msg->buf);
1539
+		/* first of all parse content-length */
1540
+		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
1541
+			LOG(L_ERR, "build_res_buf_from_sip_res:"
1542
+							" error parsing content-length\n");
1543
+			goto skip_clen;
1544
+		}
1545
+		if (msg->content_length==0){
1546
+			DBG("build_res_from_sip_res: no content_length hdr found\n");
1547
+			/* we need to add it */
1548
+			if ((clen_buf=clen_builder(msg, &clen_len))==0){
1549
+				LOG(L_ERR, "build_res_buf_from_sip_res:" 
1550
+								" clen_builder failed\n");
1551
+				goto skip_clen;
1552
+			}
1553
+		}
1554
+	}
1555
+skip_clen:
1556
+#endif
1557
+	
1538 1558
 	/* remove the first via*/
1539 1559
 	if (del_lump( &(msg->add_rm), via_offset, via_len, HDR_VIA)==0){
1540 1560
 		LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
1541 1561
 					"via\n");
1542 1562
 		goto error;
1543 1563
 	}
1544
-
1545
-	new_len=len+body_delta+lumps_len(msg, msg->add_rm, 0); /*FIXME: we don't know the send sock */
1564
+#ifdef USE_TCP
1565
+	/* if clen needs to be added, add it */
1566
+	if (clen_len){
1567
+		/* msg->unparsed should point just before the final crlf,
1568
+		 * parse_headers is called from clen_builder */
1569
+		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0, 
1570
+							HDR_CONTENTLENGTH);
1571
+		DBG("build_res_from_sip_res: adding content-length: %.*s\n",
1572
+				(int)clen_len, clen_buf);
1573
+		if (anchor==0) goto error_clen; /* free clen_buf*/
1574
+		if (insert_new_lump_after(anchor, clen_buf, clen_len,
1575
+					HDR_CONTENTLENGTH)==0)
1576
+			goto error_clen; /* free clen_buf*/
1577
+	}
1578
+#endif
1579
+	new_len=len+lumps_len(msg, 0); /*FIXME: we don't know the send sock */
1546 1580
 	
1547 1581
 	DBG(" old size: %d, new size: %d\n", len, new_len);
1548 1582
 	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging 
... ...
@@ -1553,8 +1534,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
1553 1553
 	}
1554 1554
 	new_buf[new_len]=0; /* debug: print the message */
1555 1555
 	offset=s_offset=0;
1556
-	process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/
1557
-	process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/
1556
+	process_lumps(msg, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/
1558 1557
 	/* copy the rest of the message */
1559 1558
 	memcpy(new_buf+offset,
1560 1559
 		buf+s_offset, 
... ...
@@ -1565,6 +1545,10 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
1565 1565
 
1566 1566
 	*returned_len=new_len;
1567 1567
 	return new_buf;
1568
+#ifdef USE_TCP
1569
+error_clen:
1570
+	if (clen_buf) pkg_free(clen_buf);
1571
+#endif
1568 1572
 error:
1569 1573
 	*returned_len=0;
1570 1574
 	return 0;
... ...
@@ -588,7 +588,6 @@ void free_sip_msg(struct sip_msg* msg)
588 588
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
589 589
 	if (msg->headers)     free_hdr_field_lst(msg->headers);
590 590
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
591
-	if (msg->body_lumps)  free_lump_list(msg->body_lumps);
592 591
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
593 592
 	/* don't free anymore -- now a pointer to a static buffer */
594 593
 #	ifdef DYN_BUF
... ...
@@ -212,7 +212,6 @@ struct sip_msg {
212 212
 	struct sip_uri parsed_orig_ruri;
213 213
 	
214 214
 	struct lump* add_rm;       /* used for all the forwarded requests/replies */
215
-	struct lump* body_lumps;   /* Lumps that modify message body (they update Contact-Length) */
216 215
 	struct lump_rpl *reply_lump; /* only for localy generated replies !!!*/
217 216
 
218 217
 	/* str add_to_branch;