Browse code

parser changed to make body to point to body (w/o LWS), have a len encompassing the complete hf (name.s..CRLF) and not to put zero- terminators after header field names and cseq

Jiri Kuthan authored on 27/01/2003 21:19:48
Showing 22 changed files
... ...
@@ -24,12 +24,16 @@
24 24
  * You should have received a copy of the GNU General Public License 
25 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
+ *
28
+ * History:
29
+ * ---------
30
+ * 2003-01-27 t_uac deprecated (jiri)
27 31
  */
28 32
 
29 33
 
30 34
 #ifndef _TM_DEFS_H
31 35
 #define _TM_DEFS_H
32 36
 
33
-#undef DEPRECATE_OLD_STUFF
37
+#define DEPRECATE_OLD_STUFF
34 38
 
35 39
 #endif
... ...
@@ -51,7 +51,8 @@
51 51
  *
52 52
  * History:
53 53
  * ----------
54
- * 2003-01-23 options for disabling r-uri matching introduced
54
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
55
+ * 2003-01-23 options for disabling r-uri matching introduced (jiri)
55 56
  */
56 57
 
57 58
 
... ...
@@ -59,6 +60,7 @@
59 59
 
60 60
 
61 61
 #include <assert.h>
62
+#include "../../comp_defs.h"
62 63
 #include "../../dprint.h"
63 64
 #include "../../config.h"
64 65
 #include "../../parser/parser_f.h"
... ...
@@ -94,7 +96,11 @@
94 94
 	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
95 95
 	)==0 )
96 96
 
97
+#ifdef PRESERVE_ZT
97 98
 #define HF_LEN(_hf) ((_hf)->body.s+(_hf)->body.len-(_hf)->name.s)
99
+#else
100
+#define HF_LEN(_hf) ((_hf)->len)
101
+#endif
98 102
 
99 103
 /* should be request-uri matching used as a part of pre-3261 
100 104
  * transaction matching, as the standard wants us to do so
... ...
@@ -25,11 +25,17 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ *
30
+ * History:
31
+ * ----------
32
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 33
  */
29 34
 
30 35
 #include "defs.h"
31 36
 
32 37
 
38
+#include "../../comp_defs.h"
33 39
 #include "../../hash_func.h"
34 40
 #include "../../globals.h"
35 41
 #include "t_funcs.h"
... ...
@@ -95,18 +101,28 @@ char *build_local(struct cell *Trans,unsigned int branch,
95 95
 	}
96 96
 	*len+= via_len;
97 97
 	/*headers*/
98
+#ifdef PRESERVE_ZT
98 99
 	*len+=Trans->from.len+CRLF_LEN
99 100
 		+Trans->callid.len+CRLF_LEN
100 101
 		+to->len+CRLF_LEN
101 102
 		/* CSeq: 101 CANCEL */
102 103
 		+Trans->cseq_n.len+1+method_len+CRLF_LEN; 
104
+#else
105
+	*len+=Trans->from.len+Trans->callid.len+to->len+
106
+		+Trans->cseq_n.len+1+method_len+CRLF_LEN; 
107
+#endif
108
+
103 109
 
104 110
 	/* copy'n'paste Route headers */
105 111
 	if (!Trans->local) {
106 112
 		for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next )
107 113
 			 if (hdr->type==HDR_ROUTE)
114
+#ifdef PRESERVE_ZT
108 115
 				*len+=((hdr->body.s+hdr->body.len ) - hdr->name.s ) + 
109 116
 					CRLF_LEN ;
117
+#else
118
+				*len+=hdr->len;
119
+#endif
110 120
 	}
111 121
 
112 122
 	/* User Agent */
... ...
@@ -133,12 +149,18 @@ char *build_local(struct cell *Trans,unsigned int branch,
133 133
 	append_mem_block(p,via,via_len);
134 134
 
135 135
 	/*other headers*/
136
+#ifdef PRESERVE_ZT
136 137
 	append_str( p, Trans->from );
137 138
 	append_mem_block( p, CRLF, CRLF_LEN );
138 139
 	append_str( p, Trans->callid );
139 140
 	append_mem_block( p, CRLF, CRLF_LEN );
140 141
 	append_str( p, *to );
141 142
 	append_mem_block( p, CRLF, CRLF_LEN );
143
+#else
144
+	append_str( p, Trans->from );
145
+	append_str( p, Trans->callid );
146
+	append_str( p, *to );
147
+#endif
142 148
 	append_str( p, Trans->cseq_n );
143 149
 	append_mem_block( p, " ", 1 );
144 150
 	append_mem_block( p, method, method_len );
... ...
@@ -147,9 +169,13 @@ char *build_local(struct cell *Trans,unsigned int branch,
147 147
 	if (!Trans->local)  {
148 148
 		for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next )
149 149
 			if(hdr->type==HDR_ROUTE) {
150
+#ifdef PRESERVE_ZT
150 151
 				append_mem_block(p, hdr->name.s,
151 152
 					hdr->body.s+hdr->body.len-hdr->name.s );
152 153
 				append_mem_block(p, CRLF, CRLF_LEN );
154
+#else
155
+				append_mem_block(p, hdr->name.s, hdr->len );
156
+#endif
153 157
 			}
154 158
 	}
155 159
 
... ...
@@ -27,11 +27,13 @@
27 27
  *
28 28
  * History:
29 29
  * --------
30
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
30 31
  * 2003-01-19 faked lump list created in on_reply handlers
31 32
  */
32 33
 
33 34
 #include "defs.h"
34 35
 
36
+#include "../../comp_defs.h"
35 37
 
36 38
 #include "../../hash_func.h"
37 39
 #include "t_funcs.h"
... ...
@@ -106,8 +108,13 @@ static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch,
106 106
             "cannot generate a HBH ACK if key HFs in reply missing\n");
107 107
         return NULL;
108 108
     }
109
+#ifdef PRESERVE_ZT
109 110
 	to.len=rpl->to->body.s+rpl->to->body.len-rpl->to->name.s;
110 111
 	to.s=rpl->orig+(rpl->to->name.s-rpl->buf);
112
+#else
113
+	to.s=rpl->to->name.s;
114
+	to.len=rpl->to->len;
115
+#endif
111 116
     return build_local( trans, branch, ret_len,
112 117
         ACK, ACK_LEN, &to );
113 118
 }
... ...
@@ -265,7 +265,7 @@ struct module_exports exports= {
265 265
 #ifndef DEPRECATE_OLD_STUFF
266 266
 	1+
267 267
 #endif
268
-	11,      /* Number of module paramers */
268
+	10,      /* Number of module paramers */
269 269
 
270 270
 	mod_init, /* module initialization function */
271 271
 	(response_function) t_on_reply,
... ...
@@ -44,6 +44,7 @@
44 44
  *
45 45
  * History:
46 46
  * --------
47
+ * 2003-01-27 fifo:t_uac_dlg completed (jiri)
47 48
  * 2003-01-23 t_uac_dlg now uses get_out_socket (jiri)
48 49
  */
49 50
 
... ...
@@ -80,6 +81,12 @@
80 80
 #include "t_msgbuilder.h"
81 81
 #include "uac.h"
82 82
 
83
+/* header fields which are explicitely processed and are not copied
84
+ * from FIFO line-by-line
85
+ */
86
+#define skip_hf(_hf) (((_hf)->type==HDR_FROM) || ((_hf)->type==HDR_TO) \
87
+	|| ((_hf)->type==HDR_CALLID) || ((_hf)->type==HDR_CSEQ))
88
+
83 89
 /* Call-ID has the following form: <callid_nr>-<pid>@<ip>
84 90
  * callid_nr is initialized as a random number and continually
85 91
  * increases; -<pid>@<ip> is kept in callid_suffix
... ...
@@ -97,6 +104,11 @@
97 97
 /* length of FROM tags */
98 98
 #define FROM_TAG_LEN (MD5_LEN +1 /* - */ + CRC16_LEN)
99 99
 
100
+struct str_list {
101
+	str s;
102
+	struct str_list *next;
103
+};
104
+
100 105
 static unsigned long callid_nr;
101 106
 static char *callid_suffix;
102 107
 static int callid_suffix_len;
... ...
@@ -330,6 +342,34 @@ done:
330 330
 }
331 331
 #endif
332 332
 
333
+static struct socket_info *uri2sock( str *uri, union sockaddr_union *to_su )
334
+{
335
+	struct proxy_l *proxy;
336
+	struct socket_info* send_sock;
337
+
338
+	proxy = uri2proxy(uri);
339
+	if (proxy == 0) {
340
+		ser_error = E_BAD_ADDRESS;
341
+		LOG(L_ERR, "ERROR: uri2sock: Can't create a dst proxy\n");
342
+		return 0;
343
+	}
344
+
345
+	hostent2su(to_su, &proxy->host, proxy->addr_idx, 
346
+			(proxy->port) ? htons(proxy->port) : htons(SIP_PORT));
347
+	send_sock=get_out_socket(to_su, PROTO_UDP);
348
+	if (send_sock == 0) {
349
+		LOG(L_ERR, "ERROR: uri2sock: no corresponding socket for af %d\n", 
350
+						to_su->s.sa_family );
351
+		ser_error = E_NO_SOCKET;
352
+	}
353
+
354
+
355
+	free_proxy(proxy);
356
+	free(proxy);
357
+	return send_sock;
358
+}
359
+	
360
+
333 361
 
334 362
 /*
335 363
  * Send a request within a dialog
... ...
@@ -404,11 +444,10 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
404 404
 	unsigned int req_len;
405 405
 	char *buf;
406 406
 	struct cell *new_cell;
407
-	struct proxy_l *proxy;
408
-	union sockaddr_union to_su;
409 407
 	struct socket_info* send_sock;
410 408
 	struct retr_buf *request;
411 409
 	str callid_s, ftag, tmp;
410
+	union sockaddr_union to_su;
412 411
 
413 412
 	/* make -Wall shut up */
414 413
 	ret=0;
... ...
@@ -423,22 +462,13 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
423 423
 		goto done;
424 424
 	}
425 425
 
426
-	proxy = uri2proxy((dst) ? (dst) : ruri);
427
-	if (proxy == 0) {
428
-		ser_error = ret = E_BAD_ADDRESS;
429
-		LOG(L_ERR, "ERROR: t_uac_dlg: Can't create a dst proxy\n");
430
-		goto done;
426
+	send_sock=uri2sock( dst? dst: ruri, &to_su );
427
+	if (send_sock==0) {
428
+		LOG(L_ERR, "ERROR: t_uac_dlg: no socket found\n");
429
+		goto error00;
431 430
 	}
432 431
 
433 432
 	branch=0;
434
-	hostent2su(&to_su, &proxy->host, proxy->addr_idx, (proxy->port) ? htons(proxy->port) : htons(SIP_PORT));
435
-	send_sock=get_out_socket(&to_su, PROTO_UDP);
436
-	if (send_sock == 0) {
437
-		LOG(L_ERR, "ERROR: t_uac_dlg: no corresponding listening socket for af %d\n", to_su.s.sa_family );
438
-		ret = E_NO_SOCKET;
439
-		goto error00;
440
-	}
441
-	
442 433
 	     /* No Call-ID given, calculate it */
443 434
 	if (cid == 0) {
444 435
 		callid_nr++;
... ...
@@ -513,8 +543,10 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
513 513
 	request->buffer_len = req_len;
514 514
 	new_cell->nr_of_outgoings++;
515 515
 
516
+/*
516 517
 	proxy->tx++;
517 518
 	proxy->tx_bytes += req_len;
519
+*/
518 520
 
519 521
 	if (SEND_BUFFER(request) == -1) {
520 522
 		if (dst) {
... ...
@@ -523,8 +555,10 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
523 523
 			tmp = *ruri;
524 524
 		}
525 525
 		LOG(L_ERR, "ERROR: t_uac: UAC sending to \'%.*s\' failed\n", tmp.len, tmp.s);
526
+/*
526 527
 		proxy->errors++;
527 528
 		proxy->ok = 0;
529
+*/
528 530
 	}
529 531
 	
530 532
 	start_retr(request);
... ...
@@ -539,8 +573,10 @@ error01:
539 539
 	free_cell(new_cell);
540 540
 
541 541
 error00:
542
+/*
542 543
 	free_proxy(proxy);
543 544
 	free(proxy);
545
+*/
544 546
 
545 547
 done: 
546 548
 	/* if we did not install cbp, release it now */
... ...
@@ -574,14 +610,16 @@ static void fifo_callback( struct cell *t, struct sip_msg *msg,
574 574
 	DBG("DEBUG: fifo_callback sucesssfuly completed\n");
575 575
 }	
576 576
 
577
+#ifndef DEPRECATE_OLD_STUFF
578
+
577 579
 /* to be obsoleted in favor of fifo_uac_from */
578 580
 int fifo_uac( FILE *stream, char *response_file ) 
579 581
 {
580
-	char method[MAX_METHOD];
582
+	str sm, sh, sb, sd; /* method, header, body, dst(outbound) */
583
+	char method[MAX_METHOD]; /* read buffers for these ... */
581 584
 	char header[MAX_HEADER];
582 585
 	char body[MAX_BODY];
583 586
 	char dst[MAX_DST];
584
-	str sm, sh, sb, sd;
585 587
 	char *shmem_file;
586 588
 	int fn_len;
587 589
 	int ret;
... ...
@@ -652,7 +690,6 @@ int fifo_uac( FILE *stream, char *response_file )
652 652
 	return 1;
653 653
 }
654 654
 
655
-#ifndef DEPRECATE_OLD_STUFF
656 655
 
657 656
 /* syntax:
658 657
 
... ...
@@ -762,6 +799,123 @@ int fifo_uac_from( FILE *stream, char *response_file )
762 762
 
763 763
 #endif
764 764
 
765
+static struct str_list *new_str(char *s, int len, struct str_list **last, int *total)
766
+{
767
+	struct str_list *new;
768
+	new=pkg_malloc(sizeof(struct str_list));
769
+	if (!new) {
770
+		LOG(L_ERR, "ERROR: get_hfblock: not enough mem\n");
771
+		return 0;
772
+	}
773
+	new->s.s=s;
774
+	new->s.len=len;
775
+	new->next=0;
776
+
777
+	(*last)->next=new;
778
+	*last=new;
779
+	*total+=len;
780
+
781
+	return new;
782
+}
783
+
784
+
785
+static char *get_hfblock(str *uri, struct hdr_field *hf, int *l) 
786
+{
787
+	struct str_list sl, *last, *new, *i, *foo;
788
+	int hf_avail, frag_len, total_len;
789
+	char *begin, *needle, *dst, *ret, *d;
790
+	str *sock_name, *portname;
791
+	union sockaddr_union to_su;
792
+	struct socket_info* send_sock;
793
+
794
+	ret=0; /* pesimist: assume failure */
795
+	total_len=0;
796
+	last=&sl;
797
+	last->next=0;
798
+	portname=sock_name=0;
799
+
800
+	for (; hf; hf=hf->next) {
801
+		if (skip_hf(hf)) continue;
802
+
803
+		begin=needle=hf->name.s; 
804
+		hf_avail=hf->len;
805
+
806
+		/* substitution loop */
807
+		while(hf_avail) {
808
+			d=memchr(needle, SUBST_CHAR, hf_avail);
809
+			if (!d || d+1>=needle+hf_avail) { /* nothing to substitute */
810
+				new=new_str(begin, hf_avail, &last, &total_len); 
811
+				if (!new) goto error;
812
+				break;
813
+			} else {
814
+				frag_len=d-begin;
815
+				d++; /* d not at the second substitution char */
816
+				switch(*d) {
817
+					case SUBST_CHAR:	/* double SUBST_CHAR: IP */
818
+						/* string before substitute */
819
+						new=new_str(begin, frag_len, &last, &total_len); 
820
+						if (!new) goto error;
821
+						/* substitute */
822
+						if (!sock_name) {
823
+							send_sock=uri2sock( uri, &to_su );
824
+							if (!send_sock) {
825
+								LOG(L_ERR, "ERROR: get_hf_block: send_sock failed\n");
826
+								goto error;
827
+							}
828
+							sock_name=&send_sock->address_str;
829
+							portname=&send_sock->port_no_str;
830
+						}
831
+						new=new_str(sock_name->s, sock_name->len,
832
+								&last, &total_len );
833
+						if (!new) goto error;
834
+						new=new_str(portname->s, portname->len,
835
+								&last, &total_len );
836
+						if (!new) goto error;
837
+						/* keep going ... */
838
+						begin=needle=d+1;hf_avail-=frag_len+2;
839
+						continue;
840
+					default:
841
+						/* no valid substitution char -- keep going */
842
+						hf_avail-=frag_len+1;
843
+						needle=d;
844
+				}
845
+			} /* possible substitute */
846
+		} /* substitution loop */
847
+		/* proceed to next header */
848
+		/* new=new_str(CRLF, CRLF_LEN, &last, &total_len );
849
+		if (!new) goto error; */
850
+		DBG("DEBUG: get_hf_block: one more hf processed\n");
851
+	} /* header loop */
852
+
853
+
854
+	/* construct a single header block now */
855
+	ret=pkg_malloc(total_len);
856
+	if (!ret) {
857
+		LOG(L_ERR, "ERROR: get_hf_block no pkg mem for hf block\n");
858
+		goto error;
859
+	}
860
+	i=sl.next;
861
+	dst=ret;
862
+	while(i) {
863
+		foo=i;
864
+		i=i->next;
865
+		memcpy(dst, foo->s.s, foo->s.len);
866
+		dst+=foo->s.len;
867
+		pkg_free(foo);
868
+	}
869
+	*l=total_len;
870
+	return ret;
871
+
872
+error:
873
+	i=sl.next;
874
+	while(i) {
875
+		foo=i;
876
+		i=i->next;
877
+		pkg_free(foo);
878
+	}
879
+	*l=0;
880
+	return 0;
881
+}
765 882
 
766 883
 static void fifo_uac_error(char *reply_fifo, int code, char *msg)
767 884
 {
... ...
@@ -784,6 +938,37 @@ static void fifo_uac_error(char *reply_fifo, int code, char *msg)
784 784
 	[body] 
785 785
 	.EOL
786 786
 
787
+
788
+	there is also the possibility to have server placed its
789
+    hostname:portnumber in header fields -- just put double
790
+	exclamation mark in any of the optional header fields
791
+	(i.e., any but From/To/CallID,CSeq), they will be 
792
+	substituted hn:pn
793
+
794
+Example:
795
+
796
+sc fifo t_uac_dlg MESSAGE sip:joe@192.168.2.1 \
797
+	. \ # no outbound proxy
798
+	'From:sender@iptel.org;tagd=123'  \ # no to-tag -> ephemeral
799
+	'To:sender@iptel.org' \
800
+	'Foo: sip:user@!! '  \ # expansion here
801
+	'CSEQ: 11 MESSAGE   ' \
802
+	. \ # EoH
803
+	.	# empty body
804
+---
805
+U 192.168.2.16:5060 -> 192.168.2.1:5060
806
+MESSAGE sip:joe@192.168.2.1 SIP/2.0..
807
+Via: SIP/2.0/UDP 192.168.2.16;branch=z9hG4bK760c.922ea6a1.0..
808
+To: sender@iptel.org..
809
+From: sender@iptel.org;tagd=123;tag=5405e669bc2980663aed2624dc31396f-fa77..
810
+CSeq: 11 MESSAGE..
811
+Call-ID: e863bf56-22255@192.168.2.16..
812
+Content-Length: 0..
813
+User-Agent: Sip EXpress router (0.8.11pre4-tcp1-locking (i386/linux))..
814
+Foo: sip:user@192.168.2.16:5060..
815
+..
816
+
817
+
787 818
 */
788 819
 
789 820
 int fifo_uac_dlg( FILE *stream, char *response_file ) 
... ...
@@ -794,6 +979,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
794 794
 	char header_buf[MAX_HEADER]; 
795 795
 	char body_buf[MAX_BODY]; 
796 796
 	str method, ruri, outbound, header, body;
797
+	str hfb; /* header field block */
797 798
 	struct sip_uri parsed_ruri, parsed_outbound;
798 799
 	str dummy_empty;
799 800
 	int fromtag;
... ...
@@ -925,7 +1111,12 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
925 925
 		}
926 926
 	}
927 927
 
928
-
928
+	hfb.s=get_hfblock(outbound.len ? &outbound : &ruri, 
929
+					faked_msg.headers, &hfb.len);
930
+	if (!hfb.s) {
931
+		fifo_uac_error(response_file, 500, "no mem for hf block");
932
+		goto error;
933
+	}
929 934
 
930 935
 
931 936
 	DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
... ...
@@ -935,7 +1126,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
935 935
 		shmem_file=shm_malloc(fn_len);
936 936
 		if (shmem_file==0) {
937 937
 			fifo_uac_error(response_file, 500, "no shmem");
938
-			goto error;
938
+			goto error01;
939 939
 		}
940 940
 		memcpy(shmem_file, response_file, fn_len );
941 941
 	} else {
... ...
@@ -959,7 +1150,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
959 959
 		faked_msg.callid ?
960 960
 			&faked_msg.callid->body:
961 961
 			0,
962
-		0, 						/* headers -- TBD */
962
+		&hfb, 						/* headers -- TBD */
963 963
 		&body,
964 964
 		fifo_callback, shmem_file );
965 965
 
... ...
@@ -980,6 +1171,9 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
980 980
 		}
981 981
 	}
982 982
 
983
+error01:
984
+	pkg_free(hfb.s);
985
+
983 986
 error:
984 987
 	/* free_sip_msg(&faked_msg); */
985 988
 	if (faked_msg.headers) free_hdr_field_lst(faked_msg.headers);
... ...
@@ -37,6 +37,8 @@
37 37
 #include "config.h"
38 38
 #include "t_dlg.h"
39 39
 
40
+/* substitution character for FIFO UAC */
41
+#define SUBST_CHAR '!'
40 42
 #ifdef _DEPRECATED
41 43
 /* number of random digits in beginning of a string --
42 44
    please multiples of 2 */
... ...
@@ -35,6 +35,7 @@
35 35
  * 2003-01-24 added i param to via of outgoing requests (used by tcp),
36 36
  *             modified via_builder params (andrei)
37 37
  * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
38
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
38 39
  *
39 40
  */
40 41
 
... ...
@@ -47,6 +48,7 @@
47 47
 #include <stdio.h>
48 48
 #include <stdlib.h>
49 49
 
50
+#include "comp_defs.h"
50 51
 #include "msg_translator.h"
51 52
 #include "globals.h"
52 53
 #include "error.h"
... ...
@@ -61,17 +63,14 @@
61 61
 #include "pt.h"
62 62
 
63 63
 
64
-#define append_str(_dest,_src,_len,_msg) \
64
+#define append_str(_dest,_src,_len) \
65 65
 	do{\
66 66
 		memcpy( (_dest) , (_src) , (_len) );\
67 67
 		(_dest) += (_len) ;\
68 68
 	}while(0);
69 69
 
70 70
 #define append_str_trans(_dest,_src,_len,_msg) \
71
-	do{\
72
-		memcpy( (_dest) , (_msg)->orig+((_src)-(_msg)->buf) , (_len) );\
73
-		(_dest) += (_len) ;\
74
-	}while(0);
71
+	append_str( (_dest), (_msg)->orig+((_src)-(_msg)->buf) , (_len) );
75 72
 
76 73
 extern char version[];
77 74
 extern int version_len;
... ...
@@ -647,6 +646,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
647 647
 	len=msg->len;
648 648
 	new_buf=0;
649 649
 	/* we must remove the first via */
650
+#ifdef PRESERVE_ZT
650 651
 	via_len=msg->via1->bsize;
651 652
 	via_offset=msg->via1->hdr.s-buf;
652 653
 	DBG("via len: %d, initial via offset: %d\n", via_len, via_offset);
... ...
@@ -659,6 +659,15 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
659 659
 		/* add hdr size ("Via:")*/
660 660
 		via_len+=msg->via1->hdr.len+1;
661 661
 	}
662
+#else
663
+	if (msg->via1->next) {
664
+		via_len=msg->via1->bsize;
665
+		via_offset=msg->h_via1->body.s-buf;
666
+	} else {
667
+		via_len=msg->h_via1->len;
668
+		via_offset=msg->h_via1->name.s-buf;
669
+	}
670
+#endif
662 671
 	/* remove the first via*/
663 672
 	if (del_lump( &(msg->repl_add_rm), via_offset, via_len, HDR_VIA)==0){
664 673
 		LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
... ...
@@ -713,6 +722,9 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
713 713
 	char              *warning;
714 714
 	unsigned int      warning_len;
715 715
 	int r;
716
+#ifndef PRESERVE_ZT
717
+	char *after_body;
718
+#endif
716 719
 	str to_tag;
717 720
 
718 721
 	received_buf=0;
... ...
@@ -772,6 +784,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
772 772
 				else
773 773
 					len+=new_tag_len+TOTAG_TOKEN_LEN/*";tag="*/;
774 774
 			}
775
+#ifndef PRESERVE_ZT
776
+			else {
777
+				len+=hdr->len;
778
+				continue;
779
+			}
780
+#endif
775 781
 		} else if (hdr->type==HDR_VIA) {
776 782
 				if (hdr==msg->h_via1) len += received_len+rport_len;
777 783
 		} else if (hdr->type==HDR_RECORDROUTE) {
... ...
@@ -782,7 +800,11 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
782 782
 					|| hdr->type==HDR_CSEQ)) {
783 783
 			continue;
784 784
 		}
785
+#ifdef PRESERVE_ZT
785 786
 		len += ((hdr->body.s+hdr->body.len )-hdr->name.s )+CRLF_LEN;
787
+#else
788
+		len += hdr->len;
789
+#endif
786 790
 	}
787 791
 	len-=delete_len;
788 792
 	/*lumps length*/
... ...
@@ -829,26 +851,6 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
829 829
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
830 830
 		switch (hdr->type)
831 831
 		{
832
-			case HDR_TO:
833
-				if (new_tag){
834
-					if (to_tag.s ) {
835
-						append_str_trans( p, hdr->name.s ,
836
-							to_tag.s-hdr->name.s,msg);
837
-						append_str( p, new_tag,new_tag_len,msg);
838
-						append_str_trans( p,to_tag.s+to_tag.len,
839
-							((hdr->body.s+hdr->body.len )-
840
-							(to_tag.s+to_tag.len)),msg);
841
-						append_str( p, CRLF,CRLF_LEN,msg);
842
-					}else{
843
-						append_str_trans( p, hdr->name.s ,
844
-							((hdr->body.s+hdr->body.len )-hdr->name.s ),
845
-							msg);
846
-						append_str( p, TOTAG_TOKEN,TOTAG_TOKEN_LEN,msg);
847
-						append_str( p, new_tag,new_tag_len,msg);
848
-						append_str( p, CRLF,CRLF_LEN,msg);
849
-					}
850
-					break;
851
-				}
852 832
 			case HDR_VIA:
853 833
 				if (hdr==msg->h_via1){
854 834
 					if (rport_buf){
... ...
@@ -856,7 +858,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
856 856
 						append_str_trans( p, hdr->name.s ,
857 857
 							msg->via1->rport->start-hdr->name.s-1,msg);
858 858
 						/* copy new rport */
859
-						append_str(p, rport_buf, rport_len, msg);
859
+						append_str(p, rport_buf, rport_len);
860 860
 						/* copy the rest of the via */
861 861
 						append_str_trans(p, msg->via1->rport->start+
862 862
 											msg->via1->rport->size, 
... ...
@@ -866,26 +868,72 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
866 866
 					}else{
867 867
 						/* normal whole via copy */
868 868
 						append_str_trans( p, hdr->name.s ,
869
-							((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
869
+							((hdr->body.s+hdr->body.len )-hdr->name.s ), msg);
870 870
 					}
871 871
 					if (received_buf)
872
-						append_str( p, received_buf, received_len, msg);
872
+						append_str( p, received_buf, received_len);
873 873
 				}else{
874 874
 					/* normal whole via copy */
875 875
 					append_str_trans( p, hdr->name.s ,
876 876
 						((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
877 877
 				}
878
-				append_str( p, CRLF,CRLF_LEN,msg);
878
+				append_str( p, CRLF,CRLF_LEN);
879 879
 				break;
880 880
 			case HDR_RECORDROUTE:
881 881
 				/* RR only for 1xx and 2xx replies */
882 882
 				if (code<180 || code>=300) break;
883
+			case HDR_TO:
884
+				if (new_tag){
885
+					if (to_tag.s ) { /* replacement */
886
+#ifdef PRESERVE_ZT
887
+						/* before to-tag */
888
+						append_str_trans( p, hdr->name.s ,
889
+							to_tag.s-hdr->name.s,msg);
890
+						/* to tag replacement */
891
+						append_str( p, new_tag,new_tag_len);
892
+						/* the rest after to-tag */
893
+						append_str_trans( p,to_tag.s+to_tag.len,
894
+							((hdr->body.s+hdr->body.len )-
895
+							(to_tag.s+to_tag.len)),msg);
896
+						append_str( p, CRLF,CRLF_LEN);
897
+#else
898
+						/* before to-tag */
899
+						append_str( p, hdr->name.s, to_tag.s-hdr->name.s);
900
+						/* to tag replacement */
901
+						append_str( p, new_tag,new_tag_len);
902
+						/* the rest after to-tag */
903
+						append_str( p, to_tag.s+to_tag.len,
904
+							hdr->name.s+hdr->len-(to_tag.s+to_tag.len));
905
+#endif
906
+					}else{ /* adding a new to-tag */
907
+#ifdef PRESERVE_ZT
908
+						append_str_trans( p, hdr->name.s ,
909
+							((hdr->body.s+hdr->body.len )-hdr->name.s ),
910
+							msg);
911
+						append_str( p, TOTAG_TOKEN,TOTAG_TOKEN_LEN);
912
+						append_str( p, new_tag,new_tag_len);
913
+						append_str( p, CRLF,CRLF_LEN);
914
+#else
915
+						after_body=hdr->body.s+hdr->body.len;
916
+						append_str( p, hdr->name.s, after_body-hdr->name.s);
917
+						append_str(p, TOTAG_TOKEN, TOTAG_TOKEN_LEN);
918
+						append_str( p, new_tag,new_tag_len);
919
+						append_str( p, after_body, 
920
+										hdr->name.s+hdr->len-after_body);
921
+#endif
922
+					}
923
+					break;
924
+				} /* no new to-tag -- proceed to 1:1 copying  */
883 925
 			case HDR_FROM:
884 926
 			case HDR_CALLID:
885 927
 			case HDR_CSEQ:
928
+#ifdef PRESERVE_ZT
886 929
 					append_str_trans( p, hdr->name.s ,
887 930
 						((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
888
-					append_str( p, CRLF,CRLF_LEN,msg);
931
+					append_str( p, CRLF,CRLF_LEN);
932
+#else
933
+					append_str(p, hdr->name.s, hdr->len);
934
+#endif
889 935
 		} /* for switch */
890 936
 	/*lumps*/
891 937
 	for(lump=msg->reply_lump;lump;lump=lump->next)
... ...
@@ -25,19 +25,24 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * ----------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
31 35
 #ifndef CASE_CALL_H
32 36
 #define CASE_CALL_H
33 37
 
38
+#include "../comp_defs.h"
34 39
 
35 40
 #define ID_CASE                      \
36 41
      switch(LOWER_DWORD(val)) {      \
37 42
      case __id1_:                    \
38 43
 	     hdr->type = HDR_CALLID; \
39 44
 	     hdr->name.len = 7;      \
40
-	     *(p + 3) = '\0';        \
45
+	     SET_ZT(*(p + 3));        \
41 46
 	     return (p + 4);         \
42 47
 	                             \
43 48
      case __id2_:                    \
... ...
@@ -25,19 +25,24 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * ----------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
31 35
 #ifndef CASE_CONT_H
32 36
 #define CASE_CONT_H
33 37
 
38
+#include "../comp_defs.h"
34 39
 
35 40
 #define TH_CASE                                        \
36 41
         switch(LOWER_DWORD(val)) {                     \
37 42
         case _th12_:                                   \
38 43
                 hdr->type = HDR_CONTENTLENGTH;         \
39 44
                 hdr->name.len = 14;                    \
40
-                *(p + 3) = '\0';                       \
45
+                SET_ZT(*(p + 3));                       \
41 46
                 return (p + 4);                        \
42 47
         }                                              \
43 48
                                                        \
... ...
@@ -71,7 +76,7 @@
71 71
         case _act1_:                     \
72 72
 	        hdr->type = HDR_CONTACT; \
73 73
 	        hdr->name.len = 7;       \
74
-	        *(p + 3) = '\0';         \
74
+	        SET_ZT(*(p + 3));      \
75 75
 	        return (p + 4);          \
76 76
 	                                 \
77 77
         case _act2_:                     \
... ...
@@ -86,7 +91,6 @@
86 86
                 goto other;              \
87 87
         }                         
88 88
 
89
-
90 89
 #define cont_CASE      \
91 90
      p += 4;           \
92 91
      val = READ(p);    \
... ...
@@ -25,19 +25,24 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * ---------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
31 35
 #ifndef CASE_EXPI_H
32 36
 #define CASE_EXPI_H
33 37
 
38
+#include "../comp_defs.h"
34 39
 
35 40
 #define EXPI_RES_CASE                    \
36 41
         switch(LOWER_DWORD(val)) {       \
37 42
         case _res1_:                     \
38 43
 		hdr->type = HDR_EXPIRES; \
39 44
 		hdr->name.len = 7;       \
40
-                *(p + 3) = '\0';         \
45
+		SET_ZT(*(p + 3));          \
41 46
 		return (p + 4);          \
42 47
                                          \
43 48
         case _res2_:                     \
... ...
@@ -25,19 +25,24 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * --------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
31 35
 #ifndef CASE_PROX_H
32 36
 #define CASE_PROX_H
33 37
 
38
+#include "../comp_defs.h"
34 39
 
35 40
 #define ION_CASE                           \
36 41
         switch(LOWER_DWORD(val)) {         \
37 42
         case _ion1_:                       \
38 43
 	        hdr->type = HDR_PROXYAUTH; \
39 44
 	        hdr->name.len = 19;        \
40
-                *(p + 3) = '\0';           \
45
+            SET_ZT(*(p + 3));          \
41 46
 	        return (p + 4);            \
42 47
                                            \
43 48
         case _ion2_:                       \
... ...
@@ -46,6 +51,9 @@
46 46
 	        goto dc_end;               \
47 47
         }
48 48
 
49
+#define IZAT_CASE                  \
50
+        switch(LOWER_DWORD(val)) { \
51
+
49 52
 
50 53
 #define IZAT_CASE                  \
51 54
         switch(LOWER_DWORD(val)) { \
... ...
@@ -25,19 +25,25 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * -------------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
31 35
 #ifndef CASE_REQU_H
32 36
 #define CASE_REQU_H
33 37
 
38
+#include "../comp_defs.h"
39
+
34 40
 
35 41
 #define IRE_CASE                         \
36 42
         switch(LOWER_DWORD(val)) {       \
37 43
         case _ire1_:                     \
38 44
                 hdr->type = HDR_REQUIRE; \
39 45
                 hdr->name.len = 7;       \
40
-                *(p + 3) = '\0';         \
46
+                SET_ZT(*(p + 3));        \
41 47
                 return (p + 4);          \
42 48
                                          \
43 49
         case _ire2_:                     \
... ...
@@ -25,17 +25,22 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * ---------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
31 35
 #ifndef CASE_TO_H
32 36
 #define CASE_TO_H
33 37
 
38
+#include "../comp_defs.h"
34 39
 
35 40
 #define to12_CASE           \
36 41
         hdr->type = HDR_TO; \
37 42
         hdr->name.len = 2;  \
38
-        *(p + 2) = '\0';    \
43
+        SET_ZT(*(p + 2));    \
39 44
         return (p + 4);
40 45
 
41 46
 
... ...
@@ -25,19 +25,23 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 31
  */
29 32
 
30 33
 
31 34
 #ifndef CASE_UNSU_H
32 35
 #define CASE_UNSU_H
33 36
 
37
+#include "../comp_defs.h"
34 38
 
35 39
 #define TED_CASE                             \
36 40
         switch(LOWER_DWORD(val)) {           \
37 41
         case _ted1_:                         \
38 42
                 hdr->type = HDR_UNSUPPORTED; \
39 43
                 hdr->name.len = 11;          \
40
-                *(p + 3) = '\0';             \
44
+                SET_ZT(*(p + 3));            \
41 45
 	        return (p + 4);              \
42 46
                                              \
43 47
         case _ted2_:                         \
... ...
@@ -31,14 +31,14 @@
31 31
 #ifndef CASE_VIA_H
32 32
 #define CASE_VIA_H
33 33
 
34
+#include "../comp_defs.h"
34 35
 
35 36
 #define via1_CASE            \
36 37
         hdr->type = HDR_VIA; \
37 38
         hdr->name.len = 3;   \
38
-        *(p + 3) = '\0';     \
39
+        SET_ZT(*(p + 3));     \
39 40
         return (p + 4)        
40 41
 
41
-
42 42
 #define via2_CASE            \
43 43
         hdr->type = HDR_VIA; \
44 44
         p += 4;              \
... ...
@@ -23,6 +23,10 @@
23 23
  * You should have received a copy of the GNU General Public License 
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ *
27
+ * History:
28
+ * ---------
29
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
26 30
  */
27 31
 
28 32
 
... ...
@@ -30,6 +34,7 @@
30 30
 #define HF_H
31 31
 
32 32
 #include "../str.h"
33
+#include "../comp_defs.h"
33 34
 
34 35
 
35 36
 /* Header types and flags */
... ...
@@ -68,6 +73,9 @@ struct hdr_field {
68 68
 	int type;                /* Header field type */
69 69
 	str name;                /* Header field name */
70 70
 	str body;                /* Header field body */
71
+#ifndef PRESERVE_ZT
72
+	int len;				 /* length from body until EoHF (incl. CRLF) */
73
+#endif
71 74
 	void* parsed;            /* Parsed data structures */
72 75
 	struct hdr_field* next;  /* Next header field in the list */
73 76
 };
... ...
@@ -26,12 +26,17 @@
26 26
  * You should have received a copy of the GNU General Public License 
27 27
  * along with this program; if not, write to the Free Software 
28 28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
+ *
30
+ * History:
31
+ * ---------
32
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
29 33
  */
30 34
 
31 35
 
32 36
 #include <string.h>
33 37
 #include <stdlib.h>
34 38
 
39
+#include "../comp_defs.h"
35 40
 #include "msg_parser.h"
36 41
 #include "parser_f.h"
37 42
 #include "../ut.h"
... ...
@@ -79,6 +84,22 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
79 79
 		LOG(L_ERR, "ERROR: get_hdr_field: bad header\n");
80 80
 		goto error;
81 81
 	}
82
+
83
+#ifndef PRESERVE_ZT
84
+	/* eliminate leading whitespace */
85
+	tmp=eat_lws_end(tmp, end);
86
+	if (tmp>=end) {
87
+		LOG(L_ERR, "ERROR: get_hdr_field: HF empty\n");
88
+		goto error;
89
+	}
90
+#else
91
+	;
92
+#endif
93
+
94
+	/* if header-field well-known, parse it, find its end otherwise ;
95
+	 * after leaving the hdr->type switch, tmp should be set to the
96
+	 * next header field
97
+	 */
82 98
 	switch(hdr->type){
83 99
 		case HDR_VIA:
84 100
 			/* keep number of vias parsed -- we want to report it in
... ...
@@ -118,8 +139,10 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
118 118
 			}
119 119
 			hdr->parsed=cseq_b;
120 120
 			hdr->body.len=tmp-hdr->body.s;
121
-			DBG("get_hdr_field: cseq <%s>: <%s> <%s>\n",
122
-					hdr->name.s, cseq_b->number.s, cseq_b->method.s);
121
+			DBG("get_hdr_field: cseq <%.*s>: <%.*s> <%.*s>\n",
122
+					hdr->name.len, hdr->name.s, 
123
+					cseq_b->number.len, cseq_b->number.s, 
124
+					cseq_b->method.len, cseq_b->method.s);
123 125
 			break;
124 126
 		case HDR_TO:
125 127
 			to_b=pkg_malloc(sizeof(struct to_body));
... ...
@@ -137,8 +160,9 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
137 137
 			}
138 138
 			hdr->parsed=to_b;
139 139
 			hdr->body.len=tmp-hdr->body.s;
140
-			DBG("DEBUG: get_hdr_field: <%s> [%d]; uri=[%.*s] \n",
141
-				hdr->name.s, hdr->body.len, to_b->uri.len,to_b->uri.s);
140
+			DBG("DEBUG: get_hdr_field: <%.*s> [%d]; uri=[%.*s] \n",
141
+				hdr->name.len, hdr->name.s, 
142
+				hdr->body.len, to_b->uri.len,to_b->uri.s);
142 143
 			DBG("DEBUG: to body [%.*s]\n",to_b->body.len,to_b->body.s);
143 144
 			break;
144 145
 		case HDR_CONTENTLENGTH:
... ...
@@ -188,7 +212,11 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
188 188
 				}
189 189
 				tmp=match;
190 190
 			}while( match<end &&( (*match==' ')||(*match=='\t') ) );
191
+#ifdef PRESERVE_ZT
191 192
 			*(match-1)=0; /*null terminate*/
193
+#else
194
+			tmp=match;
195
+#endif
192 196
 			hdr->body.len=match-hdr->body.s;
193 197
 			break;
194 198
 		default:
... ...
@@ -198,10 +226,16 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
198 198
 	}
199 199
 	/* jku: if \r covered by current length, shrink it */
200 200
 	trim_r( hdr->body );
201
+#ifndef PRESERVE_ZT
202
+	hdr->len=tmp-hdr->name.s;
203
+#endif
201 204
 	return tmp;
202 205
 error:
203 206
 	DBG("get_hdr_field: error exit\n");
204 207
 	hdr->type=HDR_ERROR;
208
+#ifndef PRESERVE_ZT
209
+	hdr->len=tmp-hdr->name.s;
210
+#endif
205 211
 	return tmp;
206 212
 }
207 213
 
... ...
@@ -23,9 +23,14 @@
23 23
  * You should have received a copy of the GNU General Public License 
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ * 
27
+ * History:
28
+ * --------
29
+ * 2003-01-22 zero-termination in CSeq eliminated (jiri)
26 30
  */
27 31
 
28 32
 
33
+#include "../comp_defs.h"
29 34
 #include "parse_cseq.h"
30 35
 #include "parser_f.h"  /* eat_space_end and so on */
31 36
 #include "../dprint.h"
... ...
@@ -40,21 +45,32 @@
40 40
 char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
41 41
 {
42 42
 	char *t, *m, *m_end;
43
+#ifdef PRESERVE_ZT
43 44
 	char c;
45
+#endif
44 46
 	
45 47
 	cb->error=PARSE_ERROR;
48
+#ifdef PRESERVE_ZT /* already called in calling function */
46 49
 	t=eat_space_end(buf, end);
47 50
 	if (t>=end) goto error;
51
+#else
52
+	t=buf;
53
+#endif
48 54
 	
49 55
 	cb->number.s=t;
50 56
 	t=eat_token_end(t, end);
51 57
 	if (t>=end) goto error;
58
+	cb->number.len=t-cb->number.s;
59
+
52 60
 	m=eat_space_end(t, end);
53 61
 	m_end=eat_token_end(m, end);
54
-	*t=0; /*null terminate it*/
55
-	cb->number.len=t-cb->number.s;
62
+	SET_ZT(*t);
56 63
 
57
-	if (m_end>=end) goto error;
64
+	if (m_end>=end) {
65
+			LOG(L_ERR, "ERROR: parse_cseq: "
66
+						"method terminated unexpectedly\n");
67
+			goto error;
68
+	}
58 69
 	if (m_end==m){
59 70
 		/* null method*/
60 71
 		LOG(L_ERR,  "ERROR:parse_cseq: no method found\n");
... ...
@@ -62,9 +78,11 @@ char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
62 62
 	}
63 63
 	cb->method.s=m;
64 64
 	t=m_end;
65
+	cb->method.len=t-cb->method.s;
66
+
67
+#ifdef PRESERVE_ZT
65 68
 	c=*t;
66 69
 	*t=0; /*null terminate it*/
67
-	cb->method.len=t-cb->method.s;
68 70
 	t++;
69 71
 	/*check if the header ends here*/
70 72
 	if (c=='\n') goto check_continue;
... ...
@@ -80,9 +98,28 @@ char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
80 80
 check_continue:
81 81
 		;
82 82
 	}while( (t<end) && ((*t==' ')||(*t=='\t')) );
83
-
84 83
 	cb->error=PARSE_OK;
85 84
 	return t;
85
+#else
86
+	/* there may be trailing LWS 
87
+	 * (it was not my idea to put it in SIP; -jiri )
88
+	 */
89
+	t=eat_lws_end(t, end);
90
+	/*check if the header ends here*/
91
+	if (t>=end) {
92
+		LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
93
+		goto error;
94
+	}
95
+	if (*t=='\r' && t+1<end && *(t+1)=='\n') {
96
+			cb->error=PARSE_OK;
97
+			return t+2;
98
+	}
99
+	if (*t=='\n') {
100
+			cb->error=PARSE_OK;
101
+			return t+1;
102
+	}
103
+	LOG(L_ERR, "ERROR: CSeq EoL expected\n");
104
+#endif
86 105
 error:
87 106
 	LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
88 107
 	return t;
... ...
@@ -25,9 +25,14 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ *
29
+ * History:
30
+ * --------
31
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
28 32
  */
29 33
 
30 34
 
35
+#include "../comp_defs.h"
31 36
 #include "parse_hname2.h"
32 37
 #include "keys.h"
33 38
 #include "../ut.h"  /* q_memchr */
... ...
@@ -109,7 +114,7 @@ static inline char* skip_ws(char* p, unsigned int size)
109 109
         case ':':                  \
110 110
 	        hdr->type = id;    \
111 111
 	        hdr->name.len = 1; \
112
-	        *(p + 1) = '\0';   \
112
+	        SET_ZT(*(p + 1));   \
113 113
 	        return (p + 2);    \
114 114
         }                            
115 115
 
... ...
@@ -145,7 +150,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
145 145
 			case ':':                   
146 146
 				hdr->type = HDR_TO; 
147 147
 				hdr->name.len = 1;  
148
-				*(p + 1) = '\0'; 
148
+				SET_ZT(*(p+1));
149 149
 				return (p + 2);     
150 150
 			}                           
151 151
 			break;
... ...
@@ -169,7 +174,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
169 169
 	        goto other;
170 170
 	} else {
171 171
 		hdr->name.len = p - hdr->name.s;
172
-		*p = '\0';
172
+		SET_ZT(*p);
173 173
 		return (p + 1);
174 174
 	}
175 175
 
... ...
@@ -183,7 +188,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
183 183
 		return 0;
184 184
 	} else {
185 185
 		hdr->type = HDR_OTHER;
186
-		*p = '\0';
186
+		SET_ZT(*p);
187 187
 		hdr->name.len = p - hdr->name.s;
188 188
 		return (p + 1);
189 189
 	}
... ...
@@ -26,6 +26,10 @@
26 26
  * You should have received a copy of the GNU General Public License 
27 27
  * along with this program; if not, write to the Free Software 
28 28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
+ *
30
+ * History:
31
+ * ---------
32
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
29 33
  */
30 34
 
31 35
 
... ...
@@ -29,16 +29,32 @@
29 29
 #ifndef parser_f_h
30 30
 #define parser_f_h
31 31
 
32
+#include "../comp_defs.h"
33
+
32 34
 char* eat_line(char* buffer, unsigned int len);
33 35
 
34 36
 /* turn the most frequently called functions into inline functions */
35 37
 
36
-
37 38
 inline static char* eat_space_end(char* p, char* pend)
38 39
 {
39 40
 	for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
40 41
 	return p;
41 42
 }
43
+#ifndef PRESERVE_ZT
44
+#define SP(_c) ((_c)=='\t' || (_c)==' ')
45
+inline static char* eat_lws_end(char* p, char* pend)
46
+{
47
+	while(p<pend) {
48
+		if (SP(*p)) p++;
49
+		/* btw--I really dislike line folding; -jiri */
50
+		else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
51
+		else if (*p=='\r' && p+2<pend && *(p+1)=='\n' 
52
+					&& SP(*(p+2))) p+=3;
53
+		else break; /* no whitespace encountered */
54
+	}
55
+	return p;
56
+}
57
+#endif
42 58
 
43 59
 
44 60