Browse code

- fixed uninitialized bookmark when no totag presented

Tomas Mandys authored on 26/10/2005 23:06:37
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * $Id$
3 3
  *
4 4
  *
... ...
@@ -21,15 +21,15 @@
21 21
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 22
  * GNU General Public License for more details.
23 23
  *
24
- * You should have received a copy of the GNU General Public License 
25
- * along with this program; if not, write to the Free Software 
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program; if not, write to the Free Software
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
- * 
27
+ *
28 28
  *
29 29
  * History:
30 30
  * --------
31 31
  * 2003-01-20  bug_fix: use of return value of snprintf aligned to C99 (jiri)
32
- * 2003-01-23  added rport patches, contributed by 
32
+ * 2003-01-23  added rport patches, contributed by
33 33
  *              Maxim Sobolev <sobomax@FreeBSD.org> and heavily modified by me
34 34
  *              (andrei)
35 35
  * 2003-01-24  added i param to via of outgoing requests (used by tcp),
... ...
@@ -44,7 +44,7 @@
44 44
  * 2003-03-18  killed the build_warning snprintf (andrei)
45 45
  * 2003-03-31  added subst lump support (andrei)
46 46
  * 2003-04-01  added opt (conditional) lump support (andrei)
47
- * 2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
47
+ * 2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL
48 48
  *              => ip:port;transport=proto (andrei)
49 49
  * 2003-04-12  added FL_FORCE_RPORT support (andrei)
50 50
  * 2003-04-13  updated warning builder -- fixed (andrei)
... ...
@@ -70,33 +70,33 @@
70 70
  *   if no received was present and received is added too)
71 71
  * local replies:
72 72
  *    (see also sl_send_reply)
73
- *  - rport and received are added in mostly the same way as for requests, but 
74
- *    in the reverse order (first rport and then received). See also 
73
+ *  - rport and received are added in mostly the same way as for requests, but
74
+ *    in the reverse order (first rport and then received). See also
75 75
  *    limitations.
76 76
  *  - if reply_to_via is set (default off) the local reply will be sent to
77 77
  *    the address in via (received is ignored since it was not set by us). The
78 78
  *    destination port is either the message source port if via contains rport
79 79
  *    or the FL_FORCE_RPORT flag is set or the port from the via. If either
80 80
  *    port or rport are present a normal dns lookup (instead of a srv lookup)
81
- *    is performed on the address. If no port is present and a srv lookup is 
81
+ *    is performed on the address. If no port is present and a srv lookup is
82 82
  *    performed the port is taken from the srv lookup. If the srv lookup failed
83 83
  *    or it was not performed, the port is set to the default sip port (5060).
84 84
  *  - if reply_to_via is off (default) the local reply is sent to the message
85
- *    source ip address. The destination port is set to the source port if 
85
+ *    source ip address. The destination port is set to the source port if
86 86
  *    rport is present or FL_FORCE_RPORT flag is set, to the via port or to
87 87
  *    the default sip port (5060) if neither rport or via port are present.
88 88
  * "normal" replies:
89 89
  *  - if received is present the message is sent to the received address else
90
- *    if no port is present (neither a normal via port or rport) a dns srv 
91
- *    lookup is performed on the host part and the reply is sent to the 
92
- *    resulting ip. If a port is present or the host part is an ip address 
90
+ *    if no port is present (neither a normal via port or rport) a dns srv
91
+ *    lookup is performed on the host part and the reply is sent to the
92
+ *    resulting ip. If a port is present or the host part is an ip address
93 93
  *    the dns lookup will be a "normal" one (A or AAAA).
94 94
  *  - if rport is present, it's value will be used as the destination port
95 95
  *   (and this will also disable srv lookups)
96 96
  *  - if no port is present the destination port will be taken from the srv
97 97
  *    lookup. If the srv lookup fails or is not performed (e.g. ip address
98 98
  *    in host) the destination port will be set to the default sip port (5060).
99
- *  
99
+ *
100 100
  * Known limitations:
101 101
  * - when locally replying to a message, rport and received will be appended to
102 102
  *   the via header parameters (for forwarded requests they are inserted at the
... ...
@@ -153,7 +153,7 @@ extern int version_len;
153 153
  * ip must be in network byte order!
154 154
  *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
155 155
  * return 0 if equal */
156
-static int check_via_address(struct ip_addr* ip, str *name, 
156
+static int check_via_address(struct ip_addr* ip, str *name,
157 157
 				unsigned short port, int resolver)
158 158
 {
159 159
 	struct hostent* he;
... ...
@@ -164,7 +164,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
164 164
 	/* maybe we are lucky and name it's an ip */
165 165
 	s=ip_addr2a(ip);
166 166
 	if (s){
167
-		DBG("check_via_address(%s, %.*s, %d)\n", 
167
+		DBG("check_via_address(%s, %.*s, %d)\n",
168 168
 			s, name->len, name->s, resolver);
169 169
 		len=strlen(s);
170 170
 
... ...
@@ -182,7 +182,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
182 182
 		else
183 183
 	#endif
184 184
 
185
-			if (strncmp(name->s, s, name->len)==0) 
185
+			if (strncmp(name->s, s, name->len)==0)
186 186
 				return 0;
187 187
 	}else{
188 188
 		LOG(L_CRIT, "check_via_address: BUG: could not convert ip address\n");
... ...
@@ -244,29 +244,29 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
244 244
 			memcpy(buf+clen, (string), l); \
245 245
 			clen+=l; \
246 246
 		}while(0)
247
-	
247
+
248 248
 #define str_lenpair_print(string, string_len, string2, string2_len) \
249 249
 		do{ \
250 250
 			str_print(string, string_len); \
251 251
 			str_print(string2, string2_len);\
252 252
 		}while(0)
253
-	
253
+
254 254
 #define str_pair_print( string, string2, string2_len) \
255 255
 		str_lenpair_print((string), strlen((string)), (string2), (string2_len))
256
-		
256
+
257 257
 #define str_int_print(string, intval)\
258 258
 		do{\
259 259
 			t=int2str((intval), &print_len); \
260 260
 			str_pair_print(string, t, print_len);\
261 261
 		} while(0)
262
-		
262
+
263 263
 #define str_ipaddr_print(string, ipaddr_val)\
264 264
 		do{\
265 265
 			t=ip_addr2a((ipaddr_val)); \
266 266
 			print_len=strlen(t); \
267 267
 			str_pair_print(string, t, print_len);\
268 268
 		} while(0)
269
-	
269
+
270 270
 	clen=0;
271 271
 	str_lenpair_print(WARNING, WARNING_LEN,
272 272
 						msg->rcv.bind_address->name.s,
... ...
@@ -274,7 +274,7 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
274 274
 	str_lenpair_print(":", 1, msg->rcv.bind_address->port_no_str.s,
275 275
 						msg->rcv.bind_address->port_no_str.len);
276 276
 	str_print(WARNING_PHRASE, WARNING_PHRASE_LEN);
277
-	
277
+
278 278
 	/*adding out_uri*/
279 279
 	if (msg->new_uri.s)
280 280
 		foo=&(msg->new_uri);
... ...
@@ -293,8 +293,8 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
293 293
 	str_int_print("=", via_cnt);
294 294
 	if (clen<MAX_WARNING_LEN){ buf[clen]='"'; clen++; }
295 295
 	else goto error_overflow;
296
-		
297
-		
296
+
297
+
298 298
 	*returned_len=clen;
299 299
 	return buf;
300 300
 error_overflow:
... ...
@@ -327,7 +327,7 @@ char* received_builder(struct sip_msg *msg, unsigned int *received_len)
327 327
 		return 0; /* error*/
328 328
 	tmp_len=strlen(tmp);
329 329
 	len=RECEIVED_LEN+tmp_len;
330
-	
330
+
331 331
 	memcpy(buf+RECEIVED_LEN, tmp, tmp_len);
332 332
 	buf[len]=0; /*null terminate it */
333 333
 
... ...
@@ -343,7 +343,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
343 343
 	char* tmp;
344 344
 	int tmp_len;
345 345
 	int len;
346
-	
346
+
347 347
 	tmp_len=0;
348 348
 	tmp=int2str(msg->rcv.src_port, &tmp_len);
349 349
 	len=RPORT_LEN+tmp_len;
... ...
@@ -356,7 +356,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
356 356
 	memcpy(buf, RPORT, RPORT_LEN);
357 357
 	memcpy(buf+RPORT_LEN, tmp, tmp_len);
358 358
 	buf[len]=0; /*null terminate it*/
359
-	
359
+
360 360
 	*rport_len=len;
361 361
 	return buf;
362 362
 }
... ...
@@ -370,7 +370,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
370 370
 	char revhex[sizeof(int)*2];
371 371
 	char* p;
372 372
 	int size;
373
-	
373
+
374 374
 	size=sizeof(int)*2;
375 375
 	p=&revhex[0];
376 376
 	if (int2reverse_hex(&p, &size, msg->rcv.proto_reserved1)==-1){
... ...
@@ -378,7 +378,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
378 378
 		return 0;
379 379
 	}
380 380
 	value_len=p-&revhex[0];
381
-	len=ID_PARAM_LEN+value_len; 
381
+	len=ID_PARAM_LEN+value_len;
382 382
 	buf=pkg_malloc(sizeof(char)*(len+1));/* place for ending \0 */
383 383
 	if (buf==0){
384 384
 		ser_error=E_OUT_OF_MEM;
... ...
@@ -402,8 +402,8 @@ char* clen_builder(struct sip_msg* msg, int *clen_len, int diff)
402 402
 	char* value_s;
403 403
 	int value_len;
404 404
 	char* body;
405
-	
406
-	
405
+
406
+
407 407
 	body=get_body(msg);
408 408
 	if (body==0){
409 409
 		ser_error=E_BAD_REQ;
... ...
@@ -414,7 +414,7 @@ char* clen_builder(struct sip_msg* msg, int *clen_len, int diff)
414 414
 	value=msg->len-(int)(body-msg->buf)+diff;
415 415
 	value_s=int2str(value, &value_len);
416 416
 	DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
417
-		
417
+
418 418
 	len=CONTENT_LENGTH_LEN+value_len+CRLF_LEN;
419 419
 	buf=pkg_malloc(sizeof(char)*(len+1));
420 420
 	if (buf==0){
... ...
@@ -432,7 +432,7 @@ char* clen_builder(struct sip_msg* msg, int *clen_len, int diff)
432 432
 
433 433
 
434 434
 
435
-/* checks if a lump opt condition 
435
+/* checks if a lump opt condition
436 436
  * returns 1 if cond is true, 0 if false */
437 437
 static inline int lump_check_opt(	enum lump_conditions cond,
438 438
 									struct sip_msg* msg,
... ...
@@ -457,7 +457,7 @@ static inline int lump_check_opt(	enum lump_conditions cond,
457 457
 				port=msg->rcv.dst_port; \
458 458
 				proto=msg->rcv.proto; \
459 459
 			} \
460
-			
460
+
461 461
 	switch(cond){
462 462
 		case COND_FALSE:
463 463
 			return 0;
... ...
@@ -658,7 +658,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct sock
658 658
 				LOG(L_CRIT, "BUG: unknown subst type %d\n", \
659 659
 						(subst_l)->u.subst); \
660 660
 		}
661
-	
661
+
662 662
 	s_offset=0;
663 663
 	new_len=0;
664 664
 	/* init send_address_str & send_port_str */
... ...
@@ -670,8 +670,8 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct sock
670 670
 		send_port_str=&(msg->set_global_address);
671 671
 	else
672 672
 		send_port_str=&(send_sock->port_no_str);
673
-	
674
-	
673
+
674
+
675 675
 	for(t=lumps;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))
... ...
@@ -685,7 +685,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct sock
685 685
 					SUBST_LUMP_LEN(r);
686 686
 					break;
687 687
 				case LUMP_ADD_OPT:
688
-					/* skip if this is an OPT lump and the condition is 
688
+					/* skip if this is an OPT lump and the condition is
689 689
 					 * not satisfied */
690 690
 					if (!lump_check_opt(r->u.cond, msg, send_sock))
691 691
 						goto skip_before;
... ...
@@ -741,7 +741,7 @@ skip_before:
741 741
 					SUBST_LUMP_LEN(r);
742 742
 					break;
743 743
 				case LUMP_ADD_OPT:
744
-					/* skip if this is an OPT lump and the condition is 
744
+					/* skip if this is an OPT lump and the condition is
745 745
 					 * not satisfied */
746 746
 					if (!lump_check_opt(r->u.cond, msg, send_sock))
747 747
 						goto skip_after;
... ...
@@ -765,8 +765,8 @@ skip_after:
765 765
 
766 766
 static inline void process_lumps(	struct sip_msg* msg,
767 767
 					                                struct lump* lumps,
768
-									char* new_buf, 
769
-									unsigned int* new_buf_offs, 
768
+									char* new_buf,
769
+									unsigned int* new_buf_offs,
770 770
 									unsigned int* orig_offs,
771 771
 									struct socket_info* send_sock)
772 772
 {
... ...
@@ -1012,7 +1012,7 @@ static inline void process_lumps(	struct sip_msg* msg,
1012 1012
 							(subst_l)->u.subst); \
1013 1013
 	} \
1014 1014
  \
1015
-	
1015
+
1016 1016
 	/* init send_address_str & send_port_str */
1017 1017
 	if (msg->set_global_address.len)
1018 1018
 		send_address_str=&(msg->set_global_address);
... ...
@@ -1022,21 +1022,21 @@ static inline void process_lumps(	struct sip_msg* msg,
1022 1022
 		send_port_str=&(msg->set_global_address);
1023 1023
 	else
1024 1024
 		send_port_str=&(send_sock->port_no_str);
1025
-	
1026
-	
1025
+
1026
+
1027 1027
 	orig=msg->buf;
1028 1028
 	offset=*new_buf_offs;
1029 1029
 	s_offset=*orig_offs;
1030
-	
1030
+
1031 1031
 	for (t=lumps;t;t=t->next){
1032 1032
 		switch(t->op){
1033 1033
 			case LUMP_ADD:
1034 1034
 			case LUMP_ADD_SUBST:
1035 1035
 			case LUMP_ADD_OPT:
1036
-				/* skip if this is an OPT lump and the condition is 
1036
+				/* skip if this is an OPT lump and the condition is
1037 1037
 				 * not satisfied */
1038 1038
 				if ((t->op==LUMP_ADD_OPT) &&
1039
-						(!lump_check_opt(t->u.cond, msg, send_sock))) 
1039
+						(!lump_check_opt(t->u.cond, msg, send_sock)))
1040 1040
 					continue;
1041 1041
 				/* just add it here! */
1042 1042
 				/* process before  */
... ...
@@ -1051,7 +1051,7 @@ static inline void process_lumps(	struct sip_msg* msg,
1051 1051
 							SUBST_LUMP(r);
1052 1052
 							break;
1053 1053
 						case LUMP_ADD_OPT:
1054
-							/* skip if this is an OPT lump and the condition is 
1054
+							/* skip if this is an OPT lump and the condition is
1055 1055
 					 		* not satisfied */
1056 1056
 							if (!lump_check_opt(r->u.cond, msg, send_sock))
1057 1057
 								goto skip_before;
... ...
@@ -1075,7 +1075,7 @@ skip_before:
1075 1075
 					case LUMP_ADD_OPT:
1076 1076
 						/* do nothing, it's only a condition */
1077 1077
 						break;
1078
-					default: 
1078
+					default:
1079 1079
 						/* should not ever get here */
1080 1080
 						LOG(L_CRIT, "BUG: process_lumps: unhandled data lump "
1081 1081
 								" op %d\n", t->op);
... ...
@@ -1092,7 +1092,7 @@ skip_before:
1092 1092
 							SUBST_LUMP(r);
1093 1093
 							break;
1094 1094
 						case LUMP_ADD_OPT:
1095
-							/* skip if this is an OPT lump and the condition is 
1095
+							/* skip if this is an OPT lump and the condition is
1096 1096
 					 		* not satisfied */
1097 1097
 							if (!lump_check_opt(r->u.cond, msg, send_sock))
1098 1098
 								goto skip_after;
... ...
@@ -1133,7 +1133,7 @@ skip_after:
1133 1133
 							SUBST_LUMP(r);
1134 1134
 							break;
1135 1135
 						case LUMP_ADD_OPT:
1136
-							/* skip if this is an OPT lump and the condition is 
1136
+							/* skip if this is an OPT lump and the condition is
1137 1137
 					 		* not satisfied */
1138 1138
 							if (!lump_check_opt(r->u.cond, msg, send_sock))
1139 1139
 								goto skip_nop_before;
... ...
@@ -1162,9 +1162,9 @@ skip_nop_before:
1162 1162
 							SUBST_LUMP(r);
1163 1163
 							break;
1164 1164
 						case LUMP_ADD_OPT:
1165
-							/* skip if this is an OPT lump and the condition is 
1165
+							/* skip if this is an OPT lump and the condition is
1166 1166
 					 		* not satisfied */
1167
-							if (!lump_check_opt(r->u.cond, msg, send_sock)) 
1167
+							if (!lump_check_opt(r->u.cond, msg, send_sock))
1168 1168
 								goto skip_nop_after;
1169 1169
 							break;
1170 1170
 						default:
... ...
@@ -1201,7 +1201,7 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1201 1201
 
1202 1202
 	clen_buf = 0;
1203 1203
 	anchor=0;
1204
-	
1204
+
1205 1205
 	/* check to see if we need to add clen */
1206 1206
 #ifdef USE_TCP
1207 1207
 	if (proto == PROTO_TCP
... ...
@@ -1227,14 +1227,14 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1227 1227
 		}
1228 1228
 	}
1229 1229
 #endif
1230
-	
1231
-	
1230
+
1231
+
1232 1232
 	if ((anchor==0) && body_delta){
1233 1233
 		if (parse_headers(msg, HDR_CONTENTLENGTH_F, 0) == -1) {
1234 1234
 			LOG(L_ERR, "adjust_clen: Error parsing Content-Length\n");
1235 1235
 			goto error;
1236 1236
 		}
1237
-		
1237
+
1238 1238
 		/* The body has been changed, try to find
1239 1239
 		 * existing Content-Length
1240 1240
 		 */
... ...
@@ -1266,7 +1266,7 @@ static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
1266 1266
 			}
1267 1267
 		}
1268 1268
 	}
1269
-	
1269
+
1270 1270
 	if (anchor){
1271 1271
 		clen_buf = clen_builder(msg, &clen_len, body_delta);
1272 1272
 		if (!clen_buf) goto error;
... ...
@@ -1303,8 +1303,8 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1303 1303
 #ifdef USE_TCP
1304 1304
 	char* id_buf;
1305 1305
 	unsigned int id_len;
1306
-	
1307
-	
1306
+
1307
+
1308 1308
 	id_buf=0;
1309 1309
 	id_len=0;
1310 1310
 #endif
... ...
@@ -1320,7 +1320,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1320 1320
 	received_buf=0;
1321 1321
 	rport_buf=0;
1322 1322
 	line_buf=0;
1323
-	
1323
+
1324 1324
 #ifdef USE_TCP
1325 1325
 	/* add id if tcp */
1326 1326
 	if (msg->rcv.proto==PROTO_TCP
... ...
@@ -1360,14 +1360,14 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1360 1360
 		goto error00;
1361 1361
 	}
1362 1362
 	/* check if received needs to be added */
1363
-	if ( received_test(msg) ) { 
1363
+	if ( received_test(msg) ) {
1364 1364
 		if ((received_buf=received_builder(msg,&received_len))==0){
1365 1365
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
1366 1366
 							" received_builder failed\n");
1367 1367
 			goto error01;  /* free also line_buf */
1368 1368
 		}
1369 1369
 	}
1370
-	
1370
+
1371 1371
 	/* check if rport needs to be updated:
1372 1372
 	 *  - if FL_FORCE_RPORT is set add it (and del. any previous version)
1373 1373
 	 *  - if via already contains an rport add it and overwrite the previous
... ...
@@ -1407,7 +1407,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1407 1407
 		#endif
1408 1408
 #endif
1409 1409
 	}
1410
-	/* if received needs to be added, add anchor after host and add it, or 
1410
+	/* if received needs to be added, add anchor after host and add it, or
1411 1411
 	 * overwrite the previous one if already present */
1412 1412
 	if (received_len){
1413 1413
 		if (msg->via1->received){ /* received already present => overwrite it*/
... ...
@@ -1437,7 +1437,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1437 1437
 		if (insert_new_lump_after(via_insert_param, rport_buf, rport_len,
1438 1438
 									HDR_VIA_T) ==0 )
1439 1439
 			goto error03; /* free rport_buf */
1440
-			
1440
+
1441 1441
 	}
1442 1442
 
1443 1443
 	/* compute new msg len and fix overlapping zones*/
... ...
@@ -1549,9 +1549,9 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
1549 1549
 
1550 1550
 	new_len=len+body_delta+lumps_len(msg, msg->add_rm, 0); /*FIXME: we don't
1551 1551
 														know the send sock */
1552
-	
1552
+
1553 1553
 	DBG(" old size: %d, new size: %d\n", len, new_len);
1554
-	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging 
1554
+	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging
1555 1555
 											 (\0 to print it )*/
1556 1556
 	if (new_buf==0){
1557 1557
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_res: out of mem\n");
... ...
@@ -1564,7 +1564,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
1564 1564
 	process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset, 0);
1565 1565
 	/* copy the rest of the message */
1566 1566
 	memcpy(new_buf+offset,
1567
-		buf+s_offset, 
1567
+		buf+s_offset,
1568 1568
 		len-s_offset);
1569 1569
 	 /* send it! */
1570 1570
 	DBG("build_res_from_sip_res: copied size: orig:%d, new: %d, rest: %d"
... ...
@@ -1604,12 +1604,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1604 1604
 	buf=0;
1605 1605
 	received_buf=rport_buf=warning_buf=content_len_buf=0;
1606 1606
 	received_len=rport_len=warning_len=content_len_len=0;
1607
-	
1607
+
1608 1608
 	text_len=strlen(text);
1609 1609
 
1610 1610
 	to_tag.s=0;  /* fixes gcc 4.0 warning */
1611 1611
 	to_tag.len=0;
1612
-	
1612
+
1613 1613
 	/* force parsing all headers -- we want to return all
1614 1614
 	Via's in the reply and they may be scattered down to the
1615 1615
 	end of header (non-block Vias are a really poor property
... ...
@@ -1639,7 +1639,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1639 1639
 							" rport_builder failed\n");
1640 1640
 			goto error01; /* free everything */
1641 1641
 		}
1642
-		if (msg->via1->rport) 
1642
+		if (msg->via1->rport)
1643 1643
 			len -= msg->via1->rport->size+1; /* include ';' */
1644 1644
 	}
1645 1645
 
... ...
@@ -1743,19 +1743,19 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1743 1743
 							append_str(p, rport_buf, rport_len);
1744 1744
 							/* copy the rest of the via */
1745 1745
 							append_str_trans(p, msg->via1->rport->start+
1746
-												msg->via1->rport->size, 
1746
+												msg->via1->rport->size,
1747 1747
 												hdr->body.s+hdr->body.len-
1748 1748
 												msg->via1->rport->start-
1749 1749
 												msg->via1->rport->size, msg);
1750 1750
 						}else{ /* just append the new one */
1751 1751
 							/* normal whole via copy */
1752
-							append_str_trans( p, hdr->name.s , 
1752
+							append_str_trans( p, hdr->name.s ,
1753 1753
 								(hdr->body.s+hdr->body.len)-hdr->name.s, msg);
1754 1754
 							append_str(p, rport_buf, rport_len);
1755 1755
 						}
1756 1756
 					}else{
1757 1757
 						/* normal whole via copy */
1758
-						append_str_trans( p, hdr->name.s , 
1758
+						append_str_trans( p, hdr->name.s ,
1759 1759
 								(hdr->body.s+hdr->body.len)-hdr->name.s, msg);
1760 1760
 					}
1761 1761
 					if (received_buf)
... ...
@@ -1791,7 +1791,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1791 1791
 						bmark->to_tag_val.s=p;
1792 1792
 						bmark->to_tag_val.len=new_tag->len;
1793 1793
 						append_str( p, new_tag->s,new_tag->len);
1794
-						append_str( p, after_body, 
1794
+						append_str( p, after_body,
1795 1795
 										hdr->name.s+hdr->len-after_body);
1796 1796
 					}
1797 1797
 					break;
... ...
@@ -1801,7 +1801,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1801 1801
 					bmark->to_tag_val.s=p+(totags-hdr->name.s);
1802 1802
 					bmark->to_tag_val.len=
1803 1803
 							((struct to_body*)(hdr->parsed))->tag_value.len;
1804
-				};
1804
+				}
1805
+				else {
1806
+					bmark->to_tag_val.len = 0;
1807
+					bmark->to_tag_val.s = p+(hdr->body.s+hdr->body.len-hdr->name.s);
1808
+				}
1809
+				/* no break */
1805 1810
 			case HDR_FROM_T:
1806 1811
 			case HDR_CALLID_T:
1807 1812
 			case HDR_CSEQ_T:
... ...
@@ -1921,11 +1926,11 @@ int branch_builder( unsigned int hash_index,
1921 1921
 
1922 1922
 	*len=MAX_BRANCH_PARAM_LEN-size;
1923 1923
 	return size;
1924
-		
1924
+
1925 1925
 }
1926 1926
 
1927 1927
 
1928
-char* via_builder( unsigned int *len, 
1928
+char* via_builder( unsigned int *len,
1929 1929
 	struct socket_info* send_sock,
1930 1930
 	str* branch, str* extra_params, int proto, struct hostport* hp)
1931 1931
 {
... ...
@@ -1934,7 +1939,7 @@ char* via_builder( unsigned int *len,
1934 1934
 	int max_len;
1935 1935
 	str* address_str; /* address displayed in via */
1936 1936
 	str* port_str; /* port no displayed in via */
1937
-	
1937
+
1938 1938
 	/* use pre-set address in via or the outbound socket one */
1939 1939
 	if ( hp && hp->host->len)
1940 1940
 		address_str=hp->host;
... ...
@@ -1962,7 +1967,7 @@ char* via_builder( unsigned int *len,
1962 1962
 
1963 1963
 	via_len=MY_VIA_LEN+address_str->len; /*space included in MY_VIA*/
1964 1964
 
1965
-	memcpy(line_buf, MY_VIA, MY_VIA_LEN); 
1965
+	memcpy(line_buf, MY_VIA, MY_VIA_LEN);
1966 1966
 	if (proto==PROTO_UDP){
1967 1967
 		/* do nothing */
1968 1968
 	}else if (proto==PROTO_TCP){
... ...
@@ -2003,7 +2008,7 @@ char* via_builder( unsigned int *len,
2003 2003
 		memcpy(line_buf+via_len, extra_params->s, extra_params->len);
2004 2004
 		via_len+=extra_params->len;
2005 2005
 	}
2006
-	
2006
+
2007 2007
 	memcpy(line_buf+via_len, CRLF, CRLF_LEN);
2008 2008
 	via_len+=CRLF_LEN;
2009 2009
 	line_buf[via_len]=0; /* null terminate the string*/