Browse code

If a CL header is present only adjust the value but do not touch the header name itself any more.

Nils Ohlmeier authored on 14/11/2006 17:18:35
Showing 1 changed files
... ...
@@ -397,7 +397,8 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
397 397
 
398 398
 
399 399
 
400
-char* clen_builder(struct sip_msg* msg, int *clen_len, int diff)
400
+char* clen_builder(	struct sip_msg* msg, int *clen_len, int diff, 
401
+					int body_only)
401 402
 {
402 403
 	char* buf;
403 404
 	int len;
... ...
@@ -418,16 +419,26 @@ char* clen_builder(struct sip_msg* msg, int *clen_len, int diff)
418 418
 	value_s=int2str(value, &value_len);
419 419
 	DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
420 420
 
421
-	len=CONTENT_LENGTH_LEN+value_len+CRLF_LEN;
421
+	if (body_only) {
422
+		len=value_len;
423
+	}
424
+	else {
425
+		len=CONTENT_LENGTH_LEN+value_len+CRLF_LEN;
426
+	}
422 427
 	buf=pkg_malloc(sizeof(char)*(len+1));
423 428
 	if (buf==0){
424 429
 		ser_error=E_OUT_OF_MEM;
425 430
 		LOG(L_ERR, "ERROR: clen_builder: out of memory\n");
426 431
 		return 0;
427 432
 	}
428
-	memcpy(buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
429
-	memcpy(buf+CONTENT_LENGTH_LEN, value_s, value_len);
430
-	memcpy(buf+CONTENT_LENGTH_LEN+value_len, CRLF, CRLF_LEN);
433
+	if (body_only) {
434
+		memcpy(buf, value_s, value_len);
435
+	}
436
+	else {
437
+		memcpy(buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
438
+		memcpy(buf+CONTENT_LENGTH_LEN, value_s, value_len);
439
+		memcpy(buf+CONTENT_LENGTH_LEN+value_len, CRLF, CRLF_LEN);
440
+	}
431 441
 	buf[len]=0; /* null terminate it */
432 442
 	*clen_len=len;
433 443
 	return buf;
... ...
@@ -1308,7 +1319,7 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1308 1308
 {
1309 1309
 	struct lump* anchor;
1310 1310
 	char* clen_buf;
1311
-	int clen_len;
1311
+	int clen_len, body_only;
1312 1312
 
1313 1313
 	/* Calculate message length difference caused by lumps modifying message
1314 1314
 	 * body, from this point on the message body must not be modified. Zero
... ...
@@ -1317,6 +1328,7 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1317 1317
 
1318 1318
 	clen_buf = 0;
1319 1319
 	anchor=0;
1320
+	body_only=1;
1320 1321
 
1321 1322
 	/* check to see if we need to add clen */
1322 1323
 #ifdef USE_TCP
... ...
@@ -1340,6 +1352,7 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1340 1340
 				LOG(L_ERR, "adjust_clen: cannot set clen anchor\n");
1341 1341
 				goto error;
1342 1342
 			}
1343
+			body_only=0;
1343 1344
 		}
1344 1345
 	}
1345 1346
 #endif
... ...
@@ -1368,13 +1381,14 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1368 1368
 					LOG(L_ERR, "adjust_clen: cannot set clen anchor\n");
1369 1369
 					goto error;
1370 1370
 				}
1371
+				body_only=0;
1371 1372
 			}else{
1372
-				DBG("add_clen: UDP packet with no clen => not adding one \n");
1373
+				DBG("adjust_clen: UDP packet with no clen => not adding one \n");
1373 1374
 			}
1374 1375
 		}else{
1375 1376
 			/* Content-Length has been found, remove it */
1376
-			anchor = del_lump(	msg, msg->content_length->name.s - msg->buf,
1377
-								msg->content_length->len, HDR_CONTENTLENGTH_T);
1377
+			anchor = del_lump(	msg, msg->content_length->body.s - msg->buf,
1378
+								msg->content_length->body.len, HDR_CONTENTLENGTH_T);
1378 1379
 			if (anchor==0) {
1379 1380
 				LOG(L_ERR, "adjust_clen: Can't remove original"
1380 1381
 							" Content-Length\n");
... ...
@@ -1384,7 +1398,7 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1384 1384
 	}
1385 1385
 
1386 1386
 	if (anchor){
1387
-		clen_buf = clen_builder(msg, &clen_len, body_delta);
1387
+		clen_buf = clen_builder(msg, &clen_len, body_delta, body_only);
1388 1388
 		if (!clen_buf) goto error;
1389 1389
 		if (insert_new_lump_after(anchor, clen_buf, clen_len,
1390 1390
 					HDR_CONTENTLENGTH_T) == 0)