Browse code

scratchpad removed, textops changed to skip the first line

Jiri Kuthan authored on 29/01/2003 19:24:10
Showing 28 changed files
... ...
@@ -23,10 +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-29 removed scratchpad (jiri)
26 30
  */
27 31
 
28 32
 
29
-
33
+#include "comp_defs.h"
30 34
 
31 35
 #include "action.h"
32 36
 #include "config.h"
... ...
@@ -180,7 +184,11 @@ int do_action(struct action* a, struct sip_msg* msg)
180 180
 					/*udp*/
181 181
 					send_sock=get_send_socket(to, PROTO_UDP);
182 182
 					if (send_sock!=0){
183
+#ifdef SCRATCH
183 184
 						ret=udp_send(send_sock, msg->orig, msg->len, to);
185
+#else
186
+						ret=udp_send(send_sock, msg->buf, msg->len, to);
187
+#endif
184 188
 					}else{
185 189
 						ret=-1;
186 190
 					}
... ...
@@ -188,7 +196,11 @@ int do_action(struct action* a, struct sip_msg* msg)
188 188
 #ifdef USE_TCP
189 189
 					else{
190 190
 					/*tcp*/
191
+#ifdef SCRATCH
191 192
 					ret=tcp_send(msg->orig, msg->len, to, 0);
193
+#else
194
+					ret=tcp_send(msg->buf, msg->len, to, 0);
195
+#endif
192 196
 				}
193 197
 #endif
194 198
 			}
... ...
@@ -28,6 +28,7 @@
28 28
  *
29 29
  * History:
30 30
  * -------
31
+ * 2001-01-29 src_port added (jiri)
31 32
  * 2001-01-23 mhomed added (jiri)
32 33
  */
33 34
 
... ...
@@ -106,6 +107,7 @@ MAX_LEN			"max_len"
106 106
 METHOD	method
107 107
 URI		uri
108 108
 SRCIP	src_ip
109
+SRCPORT	src_port
109 110
 DSTIP	dst_ip
110 111
 MYSELF	myself
111 112
 /* operators */
... ...
@@ -218,6 +220,7 @@ EAT_ABLE	[\ \t\b\r]
218 218
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
219 219
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
220 220
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
221
+<INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
221 222
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
222 223
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
223 224
 
... ...
@@ -28,6 +28,7 @@
28 28
  *
29 29
  * History:
30 30
  * ---------
31
+ * 2003-01-29 src_port added (jiri)
31 32
  * 2003-01-23 mhomed added (jiri)
32 33
  */
33 34
 
... ...
@@ -123,6 +124,7 @@ struct id_list* lst_tmp;
123 123
 %token METHOD
124 124
 %token URI
125 125
 %token SRCIP
126
+%token SRCPORT
126 127
 %token DSTIP
127 128
 %token MYSELF
128 129
 
... ...
@@ -524,6 +526,10 @@ exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST,
524 524
 		| URI error	{ $$=0; yyerror("invalid operator,"
525 525
 				  					" == or =~ expected");
526 526
 					}
527
+		| SRCPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
528
+												SRCPORT_O, (void *) $3 ); }
529
+		| SRCPORT EQUAL_T error { $$=0; yyerror("number expected"); }
530
+		| SRCPORT error { $$=0; yyerror("equation operator expected"); }
527 531
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
528 532
 												SRCIP_O, $3);
529 533
 								}
... ...
@@ -25,7 +25,13 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
-/* compatibility defs for emergency roll-back if things do not work */
28
+/* compatibility defs for emergency roll-back if things do not work ;
29
+ * if that happens:
30
+ * a) define PRESERVE_ZT (affects most of parser)
31
+ * b) define DONT_REMOVE_ZT (affects first line)
32
+ * c) define SCRATCH
33
+ * d) undefine REMOVE_ALL_ZT (affects via)
34
+ */
29 35
 
30 36
 
31 37
 #ifndef _COMP_DEFS_H
... ...
@@ -37,6 +43,15 @@
37 37
  */
38 38
 #undef PRESERVE_ZT
39 39
 
40
+/* go one step further and remove ZT from first line too */
41
+#undef DONT_REMOVE_ZT
42
+
43
+/* make it all -- move ZT away (Via) */
44
+#define REMOVE_ALL_ZT
45
+
46
+/* don't use scratchpad  anymore */
47
+#undef SCRATCH
48
+
40 49
 
41 50
 /* ------------------------------------------------------ */
42 51
 /* don't touch this -- that's helper macros depending on
... ...
@@ -47,4 +62,10 @@
47 47
 #	define SET_ZT(_ch)
48 48
 #endif
49 49
 
50
+#ifdef REMOVE_ALL_ZT
51
+#	define VIA_ZT(_ch)
52
+#else
53
+#	define VIA_ZT(ch) (_ch)='\0'
54
+#endif
55
+
50 56
 #endif
... ...
@@ -159,4 +159,8 @@
159 159
 #define MAX_BRANCH_PARAM_LEN  (MCOOKIE_LEN+48)
160 160
 
161 161
 
162
+/* maximum path length */
163
+#define PATH_MAX_GUESS	1024
164
+
165
+
162 166
 #endif
... ...
@@ -25,6 +25,8 @@
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
+ * 2003-01-29 s/int/enum ... more convenient for gdb (jiri)
28 30
  */
29 31
 
30 32
 
... ...
@@ -32,12 +34,12 @@
32 32
 #define data_lump_h
33 33
 
34 34
 
35
-enum { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
36
-enum { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
35
+enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
36
+enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
37 37
 
38 38
 struct lump{
39 39
 	int type; /* VIA, OTHER, UNSPEC(=0), ... */
40
-	int op;   /* DEL, ADD, NOP, UNSPEC(=0) */
40
+	enum lump_op op;   /* DEL, ADD, NOP, UNSPEC(=0) */
41 41
 	
42 42
 	union{
43 43
 		int offset; /* used for DEL, MODIFY */
... ...
@@ -53,7 +55,7 @@ struct lump{
53 53
 	
54 54
 	struct lump* next;
55 55
 
56
-	int flags; /* additional hints for use from TM's shmem */
56
+	enum lump_flag flags; /* additional hints for use from TM's shmem */
57 57
 };
58 58
 
59 59
 /*
... ...
@@ -50,9 +50,14 @@
50 50
  *
51 51
  * File test/transaction.fifo illustrates example of use
52 52
  * of t_uac command (part of TM module).
53
+ *
54
+ * History:
55
+ * --------
56
+ * 2003-01-29 new built-in fifo commands: arg and pwd (jiri)
53 57
  */
54 58
 
55 59
 
60
+#include <limits.h>
56 61
 #include <stdlib.h>
57 62
 #include <sys/types.h>
58 63
 #include <unistd.h>
... ...
@@ -574,10 +579,63 @@ static int print_version_cmd( FILE *stream, char *response_file )
574 574
 	if (response_file) {
575 575
 		fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
576 576
 	} else {
577
-		LOG(L_ERR, "ERROR: no file for print_version_cmd\n");
577
+		LOG(L_ERR, "ERROR: no file for %s\n", "print_version_cmd" );
578
+	}
579
+	return 1;
580
+}
581
+
582
+static int pwd_cmd( FILE *stream, char *response_file )
583
+{
584
+	char *cwd_buf;
585
+	int max_len;
586
+
587
+	if (!response_file) {
588
+		LOG(L_ERR, "ERROR: no file for %s\n", "pwd_cmd" );
589
+		return 1;
590
+	}
591
+
592
+	max_len=pathmax();
593
+	cwd_buf=pkg_malloc(max_len);
594
+	if (!cwd_buf) {
595
+		LOG(L_ERR, "ERROR: pwd_cmd: no cwd pkg mem\n");
596
+		fifo_reply(response_file, "500 no memory\n");
597
+		return 1;
598
+	}
599
+
600
+	if (getcwd(cwd_buf, max_len)) {
601
+		fifo_reply(response_file, "200 ok\n%s\n", cwd_buf );
602
+	} else {
603
+		fifo_reply(response_file, "500 getcwd failed\n" );
604
+	}
605
+
606
+	pkg_free(cwd_buf);
607
+	return 1;
608
+}
609
+
610
+static int arg_cmd( FILE *stream, char *response_file )
611
+{
612
+	FILE *reply_pipe;
613
+	int p;
614
+
615
+	if (response_file==0 || *response_file==0 ) {
616
+		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
617
+		return -1;
618
+	}
619
+	reply_pipe=open_reply_pipe(response_file);
620
+	if (reply_pipe==NULL) {
621
+		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
622
+			response_file );
623
+		return -1;
578 624
 	}
625
+
626
+	fputs( "200 ok\n", reply_pipe);
627
+	for (p=0; p<my_argc;p++) 
628
+			fprintf( reply_pipe, "%s\n", my_argv[p] );
629
+			
630
+	fclose(reply_pipe);
579 631
 	return 1;
580 632
 }
633
+
581 634
 	
582 635
 
583 636
 /* diagnostic and hello-world FIFO command */
... ...
@@ -688,6 +746,14 @@ int register_core_fifo()
688 688
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_VERSION);
689 689
 		return -1;
690 690
 	}
691
+	if (register_fifo_cmd(pwd_cmd, FIFO_PWD, 0)<0) {
692
+		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PWD);
693
+		return -1;
694
+	}
695
+	if (register_fifo_cmd(arg_cmd, FIFO_ARG, 0)<0) {
696
+		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_ARG);
697
+		return -1;
698
+	}
691 699
 	if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) {
692 700
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_WHICH);
693 701
 		return -1;
... ...
@@ -45,6 +45,10 @@
45 45
 #define FIFO_WHICH "which"
46 46
 /* print server's process table */
47 47
 #define FIFO_PS "ps"
48
+/* print server's command line arguments */
49
+#define FIFO_ARG "arg"
50
+/* print server's working directory */
51
+#define FIFO_PWD "pwd"
48 52
 
49 53
 #define MAX_CTIME_LEN 128
50 54
 
... ...
@@ -116,4 +116,8 @@ extern int memlog;
116 116
 /* looking up outbound interface ? */
117 117
 extern int mhomed;
118 118
 
119
+/* command-line arguments */
120
+extern int my_argc;
121
+extern char **my_argv;
122
+
119 123
 #endif
... ...
@@ -26,6 +26,7 @@
26 26
  *
27 27
  * History:
28 28
  * -------
29
+ * 2002-01-29 argc/argv globalized via my_{argc|argv} (jiri)
29 30
  * 2001-01-23 mhomed added (jiri)
30 31
  *
31 32
  */
... ...
@@ -323,6 +324,10 @@ int cfg_errors=0;
323 323
 /* shared memory (in MB) */
324 324
 unsigned int shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
325 325
 
326
+/* export command-line to anywhere else */
327
+int my_argc;
328
+char **my_argv;
329
+
326 330
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
327 331
 		    (normally it shouldn't  be bigger  than 3) */
328 332
 
... ...
@@ -1059,6 +1064,7 @@ int main(int argc, char** argv)
1059 1059
 	/*init*/
1060 1060
 	port_no_str_len=0;
1061 1061
 	ret=-1;
1062
+	my_argc=argc; my_argv=argv;
1062 1063
 	
1063 1064
 	/* added by jku: add exit handler */
1064 1065
 	if (signal(SIGINT, sig_usr) == SIG_ERR ) {
... ...
@@ -37,6 +37,7 @@
37 37
  *
38 38
  * History:
39 39
  * --------
40
+ * 2003-01-29 - scratchpad removed (jiri)
40 41
  * 2003-01-23 - msg_cloner clones msg->from->parsed too (janakj)
41 42
  */
42 43
 
... ...
@@ -276,10 +277,17 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
276 276
 		p += ROUND4(org_msg->new_uri.len);
277 277
 	}
278 278
 	/* message buffers(org and scratch pad) */
279
+#ifdef SCRATCH
279 280
 	memcpy( p , org_msg->orig , org_msg->len);
280 281
 	/* ZT to be safer */
281 282
 	*(p+org_msg->len)=0;
282 283
 	new_msg->orig = new_msg->buf = p;
284
+#else
285
+	memcpy( p , org_msg->buf, org_msg->len);
286
+	/* ZT to be safer */
287
+	*(p+org_msg->len)=0;
288
+	new_msg->buf = p;
289
+#endif
283 290
 	p += ROUND4(new_msg->len+1);
284 291
 	/* unparsed and eoh pointer */
285 292
 	new_msg->unparsed = translate_pointer(new_msg->buf ,org_msg->buf,
... ...
@@ -51,6 +51,7 @@
51 51
  *
52 52
  * History:
53 53
  * ----------
54
+ * 2003-01-28 scratchpad removed (jiri)
54 55
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
55 56
  * 2003-01-23 options for disabling r-uri matching introduced (jiri)
56 57
  */
... ...
@@ -75,26 +76,45 @@
75 75
 #include "t_hooks.h"
76 76
 #include "t_lookup.h"
77 77
 
78
+#define EQ_VIA_LEN(_via)\
79
+	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
80
+	  	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
81
+
82
+
78 83
 
79 84
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
85
+#define EQ_REQ_URI_LEN\
86
+	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
87
+
88
+#ifdef SCRATCH
80 89
 #define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
81 90
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->_hf->body.s), \
82 91
 	p_msg->_hf->body.len)==0)
83
-#define EQ_REQ_URI_LEN\
84
-	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
85 92
 #define EQ_REQ_URI_STR\
86 93
 	( memcmp( t_msg->first_line.u.request.uri.s,\
87 94
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->first_line.u.request.uri.s),\
88 95
 	p_msg->first_line.u.request.uri.len)==0)
89
-#define EQ_VIA_LEN(_via)\
90
-	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
91
-	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
92
-
93 96
 #define EQ_VIA_STR(_via)\
94 97
 	( memcmp( t_msg->_via->name.s,\
95 98
 	 translate_pointer(p_msg->orig,p_msg->buf,p_msg->_via->name.s),\
96 99
 	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
97 100
 	)==0 )
101
+#else /* SCRATCH */
102
+#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
103
+	p_msg->_hf->body.s, \
104
+	p_msg->_hf->body.len)==0)
105
+#define EQ_REQ_URI_STR\
106
+	( memcmp( t_msg->first_line.u.request.uri.s,\
107
+	p_msg->first_line.u.request.uri.s,\
108
+	p_msg->first_line.u.request.uri.len)==0)
109
+#define EQ_VIA_STR(_via)\
110
+	( memcmp( t_msg->_via->name.s,\
111
+	 p_msg->_via->name.s,\
112
+	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
113
+	)==0 )
114
+#endif /* SCRATCH */
115
+
116
+
98 117
 
99 118
 #ifdef PRESERVE_ZT
100 119
 #define HF_LEN(_hf) ((_hf)->body.s+(_hf)->body.len-(_hf)->name.s)
... ...
@@ -44,11 +44,13 @@
44 44
  *
45 45
  * History:
46 46
  * --------
47
+ * 2003-01-29 scratchpad removed (jiri)
47 48
  * 2003-01-27 fifo:t_uac_dlg completed (jiri)
48 49
  * 2003-01-23 t_uac_dlg now uses get_out_socket (jiri)
49 50
  */
50 51
 
51 52
 
53
+#include "../../comp_defs.h"
52 54
 #include "defs.h"
53 55
 
54 56
 
... ...
@@ -1051,7 +1053,10 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
1051 1051
 	/* use SIP parser to look at what is in the FIFO request */
1052 1052
 	memset(&faked_msg, 0, sizeof(struct sip_msg));
1053 1053
 	faked_msg.len=header.len; 
1054
-	faked_msg.buf=faked_msg.orig=faked_msg.unparsed=header_buf;
1054
+	faked_msg.buf=faked_msg.unparsed=header_buf;
1055
+#ifdef SCRATCH
1056
+	faked_msg.orig=faked_msg.buf;
1057
+#endif
1055 1058
 	if (parse_headers(&faked_msg, HDR_EOH, 0)==-1 ) {
1056 1059
 			DBG("DEBUG: fifo_uac: parse_headers failed\n");
1057 1060
 			fifo_uac_error(response_file, 400, "HFs unparseable");
... ...
@@ -36,6 +36,7 @@
36 36
  *             modified via_builder params (andrei)
37 37
  * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
38 38
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
39
+ * 2003-01-29 scrathcpad removed (jiri)
39 40
  *
40 41
  */
41 42
 
... ...
@@ -69,19 +70,25 @@
69 69
 		(_dest) += (_len) ;\
70 70
 	}while(0);
71 71
 
72
+#ifdef SCRATCH
72 73
 #define append_str_trans(_dest,_src,_len,_msg) \
73 74
 	append_str( (_dest), (_msg)->orig+((_src)-(_msg)->buf) , (_len) );
75
+#else
76
+#define append_str_trans(_dest,_src,_len,_msg) \
77
+	append_str( (_dest), (_src), (_len) );
78
+#endif
74 79
 
75 80
 extern char version[];
76 81
 extern int version_len;
77 82
 
78 83
 
79 84
 
85
+#ifndef REMOVE_ALL_ZT
80 86
 /* checks if ip is in host(name) and ?host(ip)=name?
81 87
  * ip must be in network byte order!
82 88
  *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
83 89
  * return 0 if equal */
84
-int check_address(struct ip_addr* ip, char *name, int resolver)
90
+static int check_address(struct ip_addr* ip, char *name, int resolver)
85 91
 {
86 92
 	struct hostent* he;
87 93
 	int i;
... ...
@@ -90,19 +97,22 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
90 90
 	/* maybe we are lucky and name it's an ip */
91 91
 	s=ip_addr2a(ip);
92 92
 	if (s){
93
-		DBG("check_address(%s, %s, %d)\n", s, name, resolver);
93
+		DBG("check_address(%s, %.*s, %d)\n", 
94
+			s, name->len, name->s, resolver);
95
+
94 96
 	#ifdef USE_IPV6
95 97
 		if ((ip->af==AF_INET6) && (strcasecmp(name, s)==0))
96 98
 				return 0;
97 99
 		else
98 100
 	#endif
99
-			if (strcmp(name, s)==0)
101
+
102
+			if (strcmp(name, s)==0) 
100 103
 				return 0;
101 104
 	}else{
102 105
 		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
103 106
 		return -1;
104 107
 	}
105
-		
108
+
106 109
 	if (resolver&DO_DNS){
107 110
 		DBG("check_address: doing dns lookup\n");
108 111
 		/* try all names ips */
... ...
@@ -127,6 +137,65 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
127 127
 	}
128 128
 	return -1;
129 129
 }
130
+#endif
131
+
132
+
133
+
134
+/* checks if ip is in host(name) and ?host(ip)=name?
135
+ * ip must be in network byte order!
136
+ *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
137
+ * return 0 if equal */
138
+static int check_via_address(struct ip_addr* ip, str *name, 
139
+				unsigned short port, int resolver)
140
+{
141
+	struct hostent* he;
142
+	int i;
143
+	char* s;
144
+
145
+	/* maybe we are lucky and name it's an ip */
146
+	s=ip_addr2a(ip);
147
+	if (s){
148
+		DBG("check_address(%s, %.*s, %d)\n", 
149
+			s, name->len, name->s, resolver);
150
+
151
+	#ifdef USE_IPV6
152
+		if ((ip->af==AF_INET6) && (strncasecmp(name->s, s, name->len)==0))
153
+			return 0;
154
+		else
155
+	#endif
156
+
157
+			if (strncmp(name->s, s, name->len)==0) 
158
+				return 0;
159
+	}else{
160
+		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
161
+		return -1;
162
+	}
163
+
164
+	if (port==0) port=SIP_PORT;
165
+	if (resolver&DO_DNS){
166
+		DBG("check_address: doing dns lookup\n");
167
+		/* try all names ips */
168
+		he=sip_resolvehost(name, &port);
169
+		if (he && ip->af==he->h_addrtype){
170
+			for(i=0;he && he->h_addr_list[i];i++){
171
+				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)
172
+					return 0;
173
+			}
174
+		}
175
+	}
176
+	if (resolver&DO_REV_DNS){
177
+		DBG("check_address: doing rev. dns lookup\n");
178
+		/* try reverse dns */
179
+		he=rev_resolvehost(ip);
180
+		if (he && (strncmp(he->h_name, name->s, name->len)==0))
181
+			return 0;
182
+		for (i=0; he && he->h_aliases[i];i++){
183
+			if (strncmp(he->h_aliases[i],name->s, name->len)==0)
184
+				return 0;
185
+		}
186
+	}
187
+	return -1;
188
+}
130 189
 
131 190
 
132 191
 static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
... ...
@@ -463,9 +532,13 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
463 463
 	char* received_buf;
464 464
 	char* rport_buf;
465 465
 	char* new_buf;
466
+#ifdef SCRATCH
466 467
 	char* orig;
468
+#endif
467 469
 	char* buf;
470
+#ifndef REMOVE_ALL_ZT
468 471
 	char  backup;
472
+#endif
469 473
 	unsigned int offset, s_offset, size;
470 474
 	struct lump* anchor;
471 475
 	int r;
... ...
@@ -483,7 +556,9 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
483 483
 	extra_params.len=0;
484 484
 	extra_params.s=0;
485 485
 	uri_len=0;
486
+#ifdef SCRATCH
486 487
 	orig=msg->orig;
488
+#endif
487 489
 	buf=msg->buf;
488 490
 	len=msg->len;
489 491
 	received_len=0;
... ...
@@ -515,10 +590,15 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
515 515
 		goto error00;
516 516
 	}
517 517
 	/* check if received needs to be added */
518
+#ifdef REMOVE_ALL_ZT
519
+	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
520
+		msg->via1->port, received_dns);
521
+#else
518 522
 	backup = msg->via1->host.s[msg->via1->host.len];
519 523
 	msg->via1->host.s[msg->via1->host.len] = 0;
520 524
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
521 525
 	msg->via1->host.s[msg->via1->host.len] = backup;
526
+#endif
522 527
 	if (r!=0){
523 528
 		if ((received_buf=received_builder(msg,&received_len))==0){
524 529
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
... ...
@@ -591,7 +671,11 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
591 591
 	if (msg->new_uri.s){
592 592
 		/* copy message up to uri */
593 593
 		size=msg->first_line.u.request.uri.s-buf;
594
+#ifdef SCRATCH
594 595
 		memcpy(new_buf, orig, size);
596
+#else
597
+		memcpy(new_buf, buf, size);
598
+#endif
595 599
 		offset+=size;
596 600
 		s_offset+=size;
597 601
 		/* add our uri */
... ...
@@ -600,10 +684,17 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
600 600
 		s_offset+=msg->first_line.u.request.uri.len; /* skip original uri */
601 601
 	}
602 602
 	new_buf[new_len]=0;
603
+#ifdef SCRATCH
603 604
 	/* copy msg adding/removing lumps */
604 605
 	process_lumps(msg->add_rm, new_buf, &offset, orig, &s_offset);
605 606
 	/* copy the rest of the message */
606 607
 	memcpy(new_buf+offset, orig+s_offset, len-s_offset);
608
+#else
609
+	/* copy msg adding/removing lumps */
610
+	process_lumps(msg->add_rm, new_buf, &offset, buf, &s_offset);
611
+	/* copy the rest of the message */
612
+	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
613
+#endif
607 614
 	new_buf[new_len]=0;
608 615
 
609 616
 #ifdef DBG_MSG_QA
... ...
@@ -637,11 +728,15 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
637 637
 	unsigned int new_len, via_len;
638 638
 	char* new_buf;
639 639
 	unsigned offset, s_offset, via_offset;
640
+#ifdef SCRATCH
640 641
 	char* orig;
642
+#endif
641 643
 	char* buf;
642 644
 	unsigned int len;
643 645
 
646
+#ifdef SCRATCH
644 647
 	orig=msg->orig;
648
+#endif
645 649
 	buf=msg->buf;
646 650
 	len=msg->len;
647 651
 	new_buf=0;
... ...
@@ -685,9 +780,21 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
685 685
 	}
686 686
 	new_buf[new_len]=0; /* debug: print the message */
687 687
 	offset=s_offset=0;
688
-	process_lumps(msg->repl_add_rm, new_buf, &offset, orig, &s_offset);
688
+	process_lumps(msg->repl_add_rm, new_buf, &offset, 
689
+#ifdef SCRATCH
690
+		orig, 
691
+#else
692
+		buf,
693
+#endif
694
+		&s_offset);
689 695
 	/* copy the rest of the message */
690
-	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
696
+	memcpy(new_buf+offset,
697
+#ifdef SCRATCH
698
+		orig+s_offset, 
699
+#else
700
+		buf+s_offset, 
701
+#endif
702
+		len-s_offset);
691 703
 	 /* send it! */
692 704
 	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
693 705
 			s_offset, offset,
... ...
@@ -721,6 +828,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
721 721
 	unsigned int      delete_len;
722 722
 	char              *warning;
723 723
 	unsigned int      warning_len;
724
+	unsigned int	  text_len;
724 725
 	int r;
725 726
 #ifndef PRESERVE_ZT
726 727
 	char *after_body;
... ...
@@ -736,6 +844,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
736 736
 	/* make -Wall happy */
737 737
 	warning=0;
738 738
 
739
+	text_len=strlen(text);
740
+
739 741
 	/* force parsing all headers -- we want to return all
740 742
 	Via's in the reply and they may be scattered down to the
741 743
 	end of header (non-block Vias are a really poor property
... ...
@@ -749,7 +859,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
749 749
 	/* check if received needs to be added */
750 750
 	backup = msg->via1->host.s[msg->via1->host.len];
751 751
 	msg->via1->host.s[msg->via1->host.len] = 0;
752
+#ifdef REMOVE_ALL_ZT
753
+	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
754
+		msg->via1->port, received_dns);
755
+#else
752 756
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
757
+#endif
753 758
 	msg->via1->host.s[msg->via1->host.len] = backup;
754 759
 	if (r!=0) {
755 760
 		if ((received_buf=received_builder(msg,&received_len))==0) {
... ...
@@ -772,7 +887,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
772 772
 	len = 0;
773 773
 	/* first line */
774 774
 	len += SIP_VERSION_LEN + 1/*space*/ + 3/*code*/ + 1/*space*/ +
775
-		strlen(text) + CRLF_LEN/*new line*/;
775
+		text_len + CRLF_LEN/*new line*/;
776 776
 	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
777 777
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next ) {
778 778
 		if (hdr->type==HDR_TO) {
... ...
@@ -843,8 +958,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
843 843
 		*(p+i) = '0' + foo - ( foo/10 )*10;
844 844
 	p += 3;
845 845
 	*(p++) = ' ' ;
846
-	memcpy( p , text , strlen(text) );
847
-	p += strlen(text);
846
+	memcpy( p , text , text_len );
847
+	p += text_len;
848 848
 	memcpy( p, CRLF, CRLF_LEN );
849 849
 	p+=CRLF_LEN;
850 850
 	/* headers*/
... ...
@@ -29,6 +29,7 @@
29 29
  *
30 30
  * History:
31 31
  * ---------
32
+ * 2003-01-29 scrathcpad removed (jiri)
32 33
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
33 34
  */
34 35
 
... ...
@@ -404,8 +405,10 @@ int parse_headers(struct sip_msg* msg, int flags, int next)
404 404
 			msg->last_header=hf;
405 405
 		}
406 406
 #ifdef EXTRA_DEBUG
407
-		DBG("header field type %d, name=<%s>, body=<%s>\n",
408
-			hf->type, hf->name.s, hf->body.s);
407
+		DBG("header field type %d, name=<%.*s>, body=<%.*s>\n",
408
+			hf->type, 
409
+			hf->name.len, hf->name.s, 
410
+			hf->body.len, hf->body.s);
409 411
 #endif
410 412
 		tmp=rest;
411 413
 	}
... ...
@@ -454,16 +457,22 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
454 454
 			break;
455 455
 		case SIP_REQUEST:
456 456
 			DBG("SIP Request:\n");
457
-			DBG(" method:  <%s>\n",fl->u.request.method.s);
458
-			DBG(" uri:     <%s>\n",fl->u.request.uri.s);
459
-			DBG(" version: <%s>\n",fl->u.request.version.s);
457
+			DBG(" method:  <%.*s>\n",fl->u.request.method.len,
458
+				fl->u.request.method.s);
459
+			DBG(" uri:     <%.*s>\n",fl->u.request.uri.len,
460
+				fl->u.request.uri.s);
461
+			DBG(" version: <%.*s>\n",fl->u.request.version.len,
462
+				fl->u.request.version.s);
460 463
 			flags=HDR_VIA;
461 464
 			break;
462 465
 		case SIP_REPLY:
463 466
 			DBG("SIP Reply  (status):\n");
464
-			DBG(" version: <%s>\n",fl->u.reply.version.s);
465
-			DBG(" status:  <%s>\n",fl->u.reply.status.s);
466
-			DBG(" reason:  <%s>\n",fl->u.reply.reason.s);
467
+			DBG(" version: <%.*s>\n",fl->u.reply.version.len,
468
+					fl->u.reply.version.s);
469
+			DBG(" status:  <%.*s>\n", fl->u.reply.status.len,
470
+					fl->u.reply.status.s);
471
+			DBG(" reason:  <%.*s>\n", fl->u.reply.reason.len,
472
+					fl->u.reply.reason.s);
467 473
 			/* flags=HDR_VIA | HDR_VIA2; */
468 474
 			/* we don't try to parse VIA2 for local messages; -Jiri */
469 475
 			flags=HDR_VIA;
... ...
@@ -481,21 +490,42 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
481 481
 #ifdef EXTRA_DEBUG
482 482
 	/* dump parsed data */
483 483
 	if (msg->via1){
484
-		DBG(" first  via: <%s/%s/%s> <%s:%s(%d)>",
485
-			msg->via1->name.s, msg->via1->version.s,
486
-			msg->via1->transport.s, msg->via1->host.s,
487
-			msg->via1->port_str.s, msg->via1->port);
488
-		if (msg->via1->params.s)  DBG(";<%s>", msg->via1->params.s);
489
-		if (msg->via1->comment.s) DBG(" <%s>", msg->via1->comment.s);
484
+		DBG(" first  via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
485
+			msg->via1->name.len, 
486
+			msg->via1->name.s, 
487
+			msg->via1->version.len,
488
+			msg->via1->version.s,
489
+			msg->via1->transport.len 
490
+			msg->via1->transport.s, 
491
+			msg->via1->host.len,
492
+			msg->via1->host.s,
493
+			msg->via1->port_str.len, 
494
+			msg->via1->port_str.s, 
495
+			msg->via1->port);
496
+		if (msg->via1->params.s)  DBG(";<%.*s>", 
497
+				msg->via1->params.len, msg->via1->params.s);
498
+		if (msg->via1->comment.s) 
499
+				DBG(" <%.*s>", 
500
+					msg->via1->comment.len, msg->via1->comment.s);
490 501
 		DBG ("\n");
491 502
 	}
492 503
 	if (msg->via2){
493
-		DBG(" first  via: <%s/%s/%s> <%s:%s(%d)>",
494
-			msg->via2->name.s, msg->via2->version.s,
495
-			msg->via2->transport.s, msg->via2->host.s,
496
-			msg->via2->port_str.s, msg->via2->port);
497
-		if (msg->via2->params.s)  DBG(";<%s>", msg->via2->params.s);
498
-		if (msg->via2->comment.s) DBG(" <%s>", msg->via2->comment.s);
504
+		DBG(" first  via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
505
+			msg->via2->name.len, 
506
+			msg->via2->name.s, 
507
+			msg->via2->version.len,
508
+			msg->via2->version.s,
509
+			msg->via2->transport.len, 
510
+			msg->via2->transport.s, 
511
+			msg->via2->host.len,
512
+			msg->via2->host.s,
513
+			msg->via2->port_str.len, 
514
+			msg->via2->port_str.s, 
515
+			msg->via2->port);
516
+		if (msg->via2->params.s)  DBG(";<%.*s>", 
517
+				msg->via2->params.len, msg->via2->params.s);
518
+		if (msg->via2->comment.s) DBG(" <%.*s>", 
519
+				msg->via2->comment.len, msg->via2->comment.s);
499 520
 		DBG ("\n");
500 521
 	}
501 522
 #endif
... ...
@@ -509,7 +539,11 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
509 509
 	
510 510
 error:
511 511
 	/* more debugging, msg->orig is/should be null terminated*/
512
+#ifdef SCRATCH
512 513
 	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->orig);
514
+#else
515
+	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->buf);
516
+#endif
513 517
 	return -1;
514 518
 }
515 519
 
... ...
@@ -535,7 +569,9 @@ void free_sip_msg(struct sip_msg* msg)
535 535
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
536 536
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
537 537
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
538
+#ifdef SCRATCH
538 539
 	pkg_free(msg->orig);
540
+#endif
539 541
 	/* don't free anymore -- now a pointer to a static buffer */
540 542
 #	ifdef DYN_BUF
541 543
 	pkg_free(msg->buf); 
... ...
@@ -23,12 +23,15 @@
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
+ * 2003-01-28 removed scratchpad (jiri)
26 28
  */
27 29
 
28 30
 
29 31
 #ifndef msg_parser_h
30 32
 #define msg_parser_h
31 33
 
34
+#include "../comp_defs.h"
32 35
 #include "../str.h"
33 36
 #include "../data_lump.h"
34 37
 #include "../flags.h"
... ...
@@ -119,8 +122,10 @@ struct sip_msg {
119 119
 	char* unparsed;   /* here we stopped parsing*/
120 120
 	
121 121
 	struct receive_info rcv; /* source & dest ip, ports, proto a.s.o*/
122
-	
122
+
123
+#ifdef SCRATCH	
123 124
 	char* orig;       /* original message copy */
125
+#endif
124 126
 	char* buf;        /* scratch pad, holds a modfied message,
125 127
 					   *  via, etc. point into it */
126 128
 	unsigned int len; /* message len (orig) */
... ...
@@ -26,9 +26,14 @@
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-28: removed 0-terminators from first line (jiri)
29 33
  */
30 34
 
31 35
 
36
+#include "../comp_defs.h"
32 37
 #include "../dprint.h"
33 38
 #include "msg_parser.h"
34 39
 #include "parser_f.h"
... ...
@@ -56,7 +61,7 @@ enum { START,
56 56
 };
57 57
 
58 58
 
59
-
59
+#ifdef _CURRENTLY_UNUSED
60 60
 char* parse_fline(char* buffer, char* end, struct msg_start* fl)
61 61
 {
62 62
 	char* tmp;
... ...
@@ -1120,6 +1125,7 @@ char* parse_fline(char* buffer, char* end, struct msg_start* fl)
1120 1120
 		}
1121 1121
 	}
1122 1122
 skip:
1123
+	fl->len=tmp-buf;
1123 1124
 	if (fl->type==SIP_REPLY){
1124 1125
 		fl->u.reply.statuscode=stat;
1125 1126
 		/* fl->u.reply.statusclass=stat/100; */
... ...
@@ -1132,7 +1138,7 @@ error:
1132 1132
 	return tmp;
1133 1133
 }
1134 1134
 
1135
-
1135
+#endif /* currently unused */
1136 1136
 
1137 1137
 /* parses the first line, returns pointer to  next line  & fills fl;
1138 1138
    also  modifies buffer (to avoid extra copy ops) */
... ...
@@ -1212,7 +1218,9 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
1212 1212
 	   tmp points at space after; go ahead */
1213 1213
 
1214 1214
 	fl->u.request.method.s=buffer;  /* store ptr to first token */
1215
+#ifdef DONT_REMOVE_ZT
1215 1216
 	(*tmp)=0;			/* mark the 1st token end */
1217
+#endif
1216 1218
 	second=tmp+1;			/* jump to second token */
1217 1219
 	offset=second-buffer;
1218 1220
 
... ...
@@ -1229,15 +1237,17 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
1229 1229
 	if ((third==tmp)||(tmp>=end)){
1230 1230
 		goto error;
1231 1231
 	}
1232
+#ifdef DONT_REMOVE_ZT
1232 1233
 	*tmp=0; /* mark the end of the token */
1234
+#endif
1233 1235
 	fl->u.request.uri.s=second;
1234 1236
 	fl->u.request.uri.len=tmp-second;
1235 1237
 
1236 1238
 	/* jku: parse status code */
1237 1239
 	if (fl->type==SIP_REPLY) {
1238 1240
 		if (fl->u.request.uri.len!=3) {
1239
-			LOG(L_INFO, "ERROR:parse_first_line: len(status code)!=3: %s\n",
1240
-				second );
1241
+			LOG(L_INFO, "ERROR:parse_first_line: len(status code)!=3: %.*s\n",
1242
+				fl->u.request.uri.len, second );
1241 1243
 			goto error;
1242 1244
 		}
1243 1245
 		s1=*second; s2=*(second+1);s3=*(second+2);
... ...
@@ -1246,8 +1256,8 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
1246 1246
 		    s3>='0' && s3<='9' ) {
1247 1247
 			fl->u.reply.statuscode=(s1-'0')*100+10*(s2-'0')+(s3-'0');
1248 1248
 		} else {
1249
-			LOG(L_INFO, "ERROR:parse_first_line: status_code non-numerical: %s\n",
1250
-				second );
1249
+			LOG(L_INFO, "ERROR:parse_first_line: status_code non-numerical: %.*s\n",
1250
+				fl->u.request.uri.len, second );
1251 1251
 			goto error;
1252 1252
 		}
1253 1253
 	}
... ...
@@ -1277,9 +1287,12 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
1277 1277
 	if (nl>=end){ /* no crlf in packet or only 1 line > invalid */
1278 1278
 		goto error;
1279 1279
 	}
1280
+#ifdef DONT_REMOVE_ZT
1280 1281
 	*tmp=0;
1282
+#endif
1281 1283
 	fl->u.request.version.s=third;
1282 1284
 	fl->u.request.version.len=tmp-third;
1285
+	fl->len=nl-buffer;
1283 1286
 
1284 1287
 	return nl;
1285 1288
 
... ...
@@ -55,6 +55,7 @@
55 55
 
56 56
 struct msg_start {
57 57
 	int type;                         /* Type of the Message - Request/Response */
58
+	int len; 						/* length including delimiter */
58 59
 	union {
59 60
 		struct {
60 61
 			str method;       /* Method string */
... ...
@@ -25,6 +25,7 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#ifdef _OBSOLETED
28 29
 
29 30
 #include "parse_hostport.h"
30 31
 #include <string.h>    /* strlen */
... ...
@@ -54,3 +55,5 @@ char* parse_hostport(char* buf, str* host, short int* port)
54 54
 
55 55
 	return host->s;
56 56
 }
57
+
58
+#endif
... ...
@@ -163,8 +163,8 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
163 163
 	err=0;
164 164
 	if (uri->port.s) uri->port_no=str2s(uri->port.s, uri->port.len, &err);
165 165
 	if (err){
166
-		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %s\n",
167
-				uri->port.s);
166
+		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %.*s\n",
167
+				uri->port.len, uri->port.s);
168 168
 		ser_error=ret=E_BAD_URI;
169 169
 		return ret;
170 170
 	}
... ...
@@ -39,10 +39,12 @@
39 39
  *               by andrei
40 40
  *  2003-01-27  modified parse_via to set new via_param->start member and
41 41
  *               via->params.s (andrei)
42
+ *  2003-01-28  zero-terminations replaced with VIA_ZT (jiri)
42 43
  */
43 44
 
44 45
 
45 46
 
47
+#include "../comp_defs.h"
46 48
 #include <stdlib.h>
47 49
 #include <string.h>
48 50
 #include "../dprint.h"
... ...
@@ -127,7 +129,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
127 127
 			case '\t':
128 128
 				switch(state){
129 129
 					case FIN_HIDDEN:
130
-						*tmp=0;
130
+						VIA_ZT(*tmp);
131 131
 						param->type=state;
132 132
 						param->name.len=tmp-param->name.s;
133 133
 						state=L_PARAM;
... ...
@@ -138,7 +140,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
138 138
 					case FIN_RECEIVED:
139 139
 					case FIN_RPORT:
140 140
 					case FIN_I:
141
-						*tmp=0;
141
+						VIA_ZT(*tmp);
142 142
 						param->type=state;
143 143
 						param->name.len=tmp-param->name.s;
144 144
 						state=L_VALUE;
... ...
@@ -152,7 +154,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
152 152
 						break;
153 153
 					case GEN_PARAM:
154 154
 					default:
155
-						*tmp=0;
155
+						VIA_ZT(*tmp);
156 156
 						param->type=GEN_PARAM;
157 157
 						param->name.len=tmp-param->name.s;
158 158
 						state=L_VALUE;
... ...
@@ -163,7 +165,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
163 163
 			case '\n':
164 164
 				switch(state){
165 165
 					case FIN_HIDDEN:
166
-						*tmp=0;
166
+						VIA_ZT(*tmp);
167 167
 						param->type=state;
168 168
 						param->name.len=tmp-param->name.s;
169 169
 						param->size=tmp-param->start; 
... ...
@@ -176,7 +178,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
176 176
 					case FIN_RECEIVED:
177 177
 					case FIN_I:
178 178
 					case FIN_RPORT:
179
-						*tmp=0;
179
+						VIA_ZT(*tmp);
180 180
 						param->type=state;
181 181
 						param->name.len=tmp-param->name.s;
182 182
 						param->size=tmp-param->start; 
... ...
@@ -196,7 +198,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
196 196
 						break;
197 197
 					case GEN_PARAM:
198 198
 					default:
199
-						*tmp=0;
199
+						VIA_ZT(*tmp);
200 200
 						param->type=GEN_PARAM;
201 201
 						saved_state=L_VALUE;
202 202
 						param->name.len=tmp-param->name.s;
... ...
@@ -208,7 +210,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
208 208
 			case '\r':
209 209
 				switch(state){
210 210
 					case FIN_HIDDEN:
211
-						*tmp=0;
211
+						VIA_ZT(*tmp);
212 212
 						param->type=state;
213 213
 						param->name.len=tmp-param->name.s;
214 214
 						param->size=tmp-param->start; 
... ...
@@ -221,7 +223,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
221 221
 					case FIN_RECEIVED:
222 222
 					case FIN_I:
223 223
 					case FIN_RPORT:
224
-						*tmp=0;
224
+						VIA_ZT(*tmp);
225 225
 						param->type=state;
226 226
 						param->name.len=tmp-param->name.s;
227 227
 						param->size=tmp-param->start; 
... ...
@@ -238,7 +240,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
238 238
 						goto end_via;
239 239
 					case GEN_PARAM:
240 240
 					default:
241
-						*tmp=0;
241
+						VIA_ZT(*tmp);
242 242
 						param->type=GEN_PARAM;
243 243
 						param->name.len=tmp-param->name.s;
244 244
 						param->size=tmp-param->start; 
... ...
@@ -256,7 +258,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
256 256
 					case FIN_RECEIVED:
257 257
 					case FIN_RPORT:
258 258
 					case FIN_I:
259
-						*tmp=0;
259
+						VIA_ZT(*tmp);
260 260
 						param->type=state;
261 261
 						param->name.len=tmp-param->name.s;
262 262
 						state=F_VALUE;
... ...
@@ -273,7 +275,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
273 273
 						goto end_via;
274 274
 					case GEN_PARAM:
275 275
 					default:
276
-						*tmp=0;
276
+						VIA_ZT(*tmp);
277 277
 						param->type=GEN_PARAM;
278 278
 						param->name.len=tmp-param->name.s;
279 279
 						state=F_VALUE;
... ...
@@ -284,7 +286,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
284 284
 				switch(state){
285 285
 					case FIN_HIDDEN:
286 286
 					case FIN_RPORT: /* rport can appear w/o a value */
287
-						*tmp=0;
287
+						VIA_ZT(*tmp);
288 288
 						param->type=state;
289 289
 						param->name.len=tmp-param->name.s;
290 290
 						state=F_PARAM;
... ...
@@ -304,7 +306,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
304 304
 						goto end_via;
305 305
 					case GEN_PARAM:
306 306
 					default:
307
-						*tmp=0;
307
+						VIA_ZT(*tmp);
308 308
 						param->type=GEN_PARAM;
309 309
 						param->name.len=tmp-param->name.s;
310 310
 						state=F_PARAM;
... ...
@@ -315,7 +317,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
315 315
 				switch(state){
316 316
 					case FIN_HIDDEN:
317 317
 					case FIN_RPORT:
318
-						*tmp=0;
318
+						VIA_ZT(*tmp);
319 319
 						param->type=state;
320 320
 						param->name.len=tmp-param->name.s;
321 321
 						state=F_VIA;
... ...
@@ -336,7 +338,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
336 336
 						goto end_via;
337 337
 					case GEN_PARAM:
338 338
 					default:
339
-						*tmp=0;
339
+						VIA_ZT(*tmp);
340 340
 						param->type=GEN_PARAM;
341 341
 						param->name.len=tmp-param->name.s;
342 342
 						state=F_VIA;
... ...
@@ -719,7 +721,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
719 719
 					case F_VALUE: /*eat space*/
720 720
 						break; 
721 721
 					case P_VALUE:
722
-						*tmp=0;
722
+						VIA_ZT(*tmp);
723 723
 						state=L_PARAM;
724 724
 						param->value.len=tmp-param->value.s;
725 725
 						goto endofvalue;
... ...
@@ -746,7 +748,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
746 746
 						state=F_LF;
747 747
 						break;
748 748
 					case P_VALUE:
749
-						*tmp=0;
749
+						VIA_ZT(*tmp);
750 750
 						saved_state=L_PARAM;
751 751
 						state=F_LF;
752 752
 						param->value.len=tmp-param->value.s;
... ...
@@ -774,7 +776,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
774 774
 						state=F_CR;
775 775
 						break;
776 776
 					case P_VALUE:
777
-						*tmp=0;
777
+						VIA_ZT(*tmp);
778 778
 						param->value.len=tmp-param->value.s;
779 779
 						saved_state=L_PARAM;
780 780
 						state=F_CR;
... ...
@@ -812,12 +814,12 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
812 812
 			case ';':
813 813
 				switch(state){
814 814
 					case P_VALUE:
815
-						*tmp=0;
815
+						VIA_ZT(*tmp);
816 816
 						param->value.len=tmp-param->value.s;
817 817
 						state=F_PARAM;
818 818
 						goto endofvalue;
819 819
 					case F_VALUE:
820
-						*tmp=0;
820
+						VIA_ZT(*tmp);
821 821
 						param->value.len=0;
822 822
 						state=F_PARAM;
823 823
 						goto endofvalue;
... ...
@@ -845,7 +847,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
845 845
 			case ',':
846 846
 				switch(state){
847 847
 					case P_VALUE:
848
-						*tmp=0;
848
+						VIA_ZT(*tmp);
849 849
 						param->value.len=tmp-param->value.s;
850 850
 						state=F_VIA;
851 851
 						goto endofvalue;
... ...
@@ -876,7 +878,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
876 876
 						param->value.s=tmp+1;
877 877
 						break;
878 878
 					case P_STRING:
879
-						*tmp=0;
879
+						VIA_ZT(*tmp);
880 880
 						state=L_PARAM;
881 881
 						param->value.len=tmp-param->value.s;
882 882
 						goto endofvalue;
... ...
@@ -924,8 +926,8 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
924 924
 normal_exit:
925 925
 	*pstate=state;
926 926
 	*psaved_state=saved_state;
927
-	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type,
928
-			param->name.s, param->value.s, state);
927
+	DBG("Found param type %d, <%.*s> = <%.*s>; state=%d\n", param->type,
928
+			param->name.len, param->name.s, param->value.len, param->value.s, state);
929 929
 	return tmp;
930 930
 	
931 931
  end_via:
... ...
@@ -941,8 +943,8 @@ normal_exit:
941 941
 	}
942 942
 	*pstate=state;
943 943
 	*psaved_state=saved_state;
944
-	DBG("Error on  param type %d, <%s>, state=%d, saved_state=%d\n",
945
-		param->type, param->name.s, state, saved_state);
944
+	DBG("Error on  param type %d, <%.*s>, state=%d, saved_state=%d\n",
945
+		param->type, param->name.len, param->name.s, state, saved_state);
946 946
 
947 947
  error:
948 948
 	LOG(L_ERR, "error: parse_via_param\n");
... ...
@@ -982,24 +984,24 @@ parse_again:
982 982
 					case F_PROTO:
983 983
 						break;
984 984
 					case FIN_UDP:
985
-						*tmp=0;  /* finished proto parsing */
985
+						VIA_ZT(*tmp); /* finished proto parsing */
986 986
 						vb->transport.len=tmp-vb->transport.s;
987 987
 						vb->proto=PROTO_UDP;
988 988
 						state=F_HOST; /* start looking for host*/
989 989
 						goto main_via;
990 990
 					case FIN_TCP:
991
-						*tmp=0;  /* finished proto parsing */
991
+						VIA_ZT(*tmp); /* finished proto parsing */
992 992
 						vb->transport.len=tmp-vb->transport.s;
993 993
 						vb->proto=PROTO_TCP;
994 994
 						state=F_HOST; /* start looking for host*/
995 995
 						goto main_via;
996 996
 					case FIN_SIP:
997
-						*tmp=0;
997
+						VIA_ZT(*tmp);
998 998
 						vb->name.len=tmp-vb->name.s;
999 999
 						state=L_VER;
1000 1000
 						break;
1001 1001
 					case FIN_VER:
1002
-						*tmp=0;
1002
+						VIA_ZT(*tmp);
1003 1003
 						vb->version.len=tmp-vb->version.s;
1004 1004
 						state=L_PROTO;
1005 1005
 						break;
... ...
@@ -1025,27 +1027,27 @@ parse_again:
1025 1025
 						state=F_LF;
1026 1026
 						break;
1027 1027
 					case FIN_UDP:
1028
-						*tmp=0;
1028
+						VIA_ZT(*tmp);
1029 1029
 						vb->transport.len=tmp-vb->transport.s;
1030 1030
 						vb->proto=PROTO_UDP;
1031 1031
 						state=F_LF;
1032 1032
 						saved_state=F_HOST; /* start looking for host*/
1033 1033
 						goto main_via;
1034 1034
 					case FIN_TCP:
1035
-						*tmp=0;
1035
+						VIA_ZT(*tmp);
1036 1036
 						vb->transport.len=tmp-vb->transport.s;
1037 1037
 						vb->proto=PROTO_TCP;
1038 1038
 						state=F_LF;
1039 1039
 						saved_state=F_HOST; /* start looking for host*/
1040 1040
 						goto main_via;
1041 1041
 					case FIN_SIP:
1042
-						*tmp=0;
1042
+						VIA_ZT(*tmp);
1043 1043
 						vb->name.len=tmp-vb->name.s;
1044 1044
 						state=F_LF;
1045 1045
 						saved_state=L_VER;
1046 1046
 						break;
1047 1047
 					case FIN_VER:
1048
-						*tmp=0;
1048
+						VIA_ZT(*tmp);
1049 1049
 						vb->version.len=tmp-vb->version.s;
1050 1050
 						state=F_LF;
1051 1051
 						saved_state=L_PROTO;
... ...
@@ -1074,27 +1076,27 @@ parse_again:
1074 1074
 						state=F_CR;
1075 1075
 						break;
1076 1076
 					case FIN_UDP:
1077
-						*tmp=0;
1077
+						VIA_ZT(*tmp);
1078 1078
 						vb->transport.len=tmp-vb->transport.s;
1079 1079
 						vb->proto=PROTO_UDP;
1080 1080
 						state=F_CR;
1081 1081
 						saved_state=F_HOST;
1082 1082
 						goto main_via;
1083 1083
 					case FIN_TCP:
1084
-						*tmp=0;
1084
+						VIA_ZT(*tmp);
1085 1085
 						vb->transport.len=tmp-vb->transport.s;
1086 1086
 						vb->proto=PROTO_TCP;
1087 1087
 						state=F_CR;
1088 1088
 						saved_state=F_HOST;
1089 1089
 						goto main_via;
1090 1090
 					case FIN_SIP:
1091
-						*tmp=0;
1091
+						VIA_ZT(*tmp);
1092 1092
 						vb->name.len=tmp-vb->name.s;
1093 1093
 						state=F_CR;
1094 1094
 						saved_state=L_VER;
1095 1095
 						break;
1096 1096
 					case FIN_VER:
1097
-						*tmp=0;
1097
+						VIA_ZT(*tmp);
1098 1098
 						vb->version.len=tmp-vb->version.s;
1099 1099
 						state=F_CR;
1100 1100
 						saved_state=L_PROTO;
... ...
@@ -1114,12 +1116,12 @@ parse_again:
1114 1114
 			case '/':
1115 1115
 				switch(state){
1116 1116
 					case FIN_SIP:
1117
-						*tmp=0;
1117
+						VIA_ZT(*tmp);
1118 1118
 						vb->name.len=tmp-vb->name.s;
1119 1119
 						state=F_VER;
1120 1120
 						break;
1121 1121
 					case FIN_VER:
1122
-						*tmp=0;
1122
+						VIA_ZT(*tmp);
1123 1123
 						vb->version.len=tmp-vb->version.s;
1124 1124
 						state=F_PROTO;
1125 1125
 						break;
... ...
@@ -1292,7 +1294,7 @@ parse_again:
1292 1292
 					case F_HOST:/*eat the spaces*/
1293 1293
 						break;
1294 1294
 					case P_HOST:
1295
-						 *tmp=0;/*mark end of host*/
1295
+						 VIA_ZT(*tmp);/*mark end of host*/
1296 1296
 						 vb->host.len=tmp-vb->host.s;
1297 1297
 						 state=L_PORT;
1298 1298
 						 break;
... ...
@@ -1300,7 +1302,7 @@ parse_again:
1300 1300
 					case F_PORT:
1301 1301
 						break;
1302 1302
 					case P_PORT:
1303
-						*tmp=0; /*end of port */
1303
+						VIA_ZT(*tmp); /*end of port */
1304 1304
 						vb->port_str.len=tmp-vb->port_str.s;
1305 1305
 						state=L_PARAM;
1306 1306
 						break;
... ...
@@ -1320,7 +1322,7 @@ parse_again:
1320 1320
 					case F_IP6HOST: /*eat the spaces*/
1321 1321
 						break;
1322 1322
 					case P_IP6HOST:
1323
-						*tmp=0; /*mark end of host*/
1323
+						VIA_ZT(*tmp); /*mark end of host*/
1324 1324
 						vb->host.len=tmp-vb->host.s;
1325 1325
 						state=L_PORT; 
1326 1326
 						break;
... ...
@@ -1353,13 +1355,13 @@ parse_again:
1353 1353
 						state=F_LF;
1354 1354
 						break;
1355 1355
 					case P_HOST:
1356
-						 *tmp=0;/*mark end of host*/
1356
+						 VIA_ZT(*tmp);/*mark end of host*/
1357 1357
 						 vb->host.len=tmp-vb->host.s;
1358 1358
 						 saved_state=L_PORT;
1359 1359
 						 state=F_LF;
1360 1360
 						 break;
1361 1361
 					case P_PORT:
1362
-						*tmp=0; /*end of port */
1362
+						VIA_ZT(*tmp); /*end of port */
1363 1363
 						vb->port_str.len=tmp-vb->port_str.s;
1364 1364
 						saved_state=L_PARAM;
1365 1365
 						state=F_LF;
... ...
@@ -1399,13 +1401,13 @@ parse_again:
1399 1399
 						state=F_CR;
1400 1400
 						break;
1401 1401
 					case P_HOST:
1402
-						 *tmp=0;/*mark end of host*/
1402
+						 VIA_ZT(*tmp);/*mark end of host*/
1403 1403
 						 vb->host.len=tmp-vb->host.s;
1404 1404
 						 saved_state=L_PORT;
1405 1405
 						 state=F_CR;
1406 1406
 						 break;
1407 1407
 					case P_PORT:
1408
-						*tmp=0; /*end of port */
1408
+						VIA_ZT(*tmp); /*end of port */
1409 1409
 						vb->port_str.len=tmp-vb->port_str.s;
1410 1410
 						saved_state=L_PARAM;
1411 1411
 						state=F_CR;
... ...
@@ -1437,7 +1439,7 @@ parse_again:
1437 1437
 					case P_IP6HOST:
1438 1438
 						break;
1439 1439
 					case P_HOST:
1440
-						*tmp=0; /*mark  end of host*/
1440
+						VIA_ZT(*tmp); /*mark  end of host*/
1441 1441
 						vb->host.len=tmp-vb->host.s;
1442 1442
 						state=F_PORT;
1443 1443
 						break;
... ...
@@ -1489,13 +1491,13 @@ parse_again:
1489 1489
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1490 1490
 						goto error;
1491 1491
 					case P_HOST:
1492
-						*tmp=0;
1492
+						VIA_ZT(*tmp);
1493 1493
 						vb->host.len=tmp-vb->host.s;
1494 1494
 						state=F_PARAM;
1495 1495
 						param_start=tmp+1;
1496 1496
 						break;
1497 1497
 					case P_PORT:
1498
-						*tmp=0; /*mark the end*/
1498
+						VIA_ZT(*tmp); /*mark the end*/
1499 1499
 						vb->port_str.len=tmp-vb->port_str.s;
1500 1500
 					case L_PORT:
1501 1501
 					case L_PARAM:
... ...
@@ -1552,12 +1554,12 @@ parse_again:
1552 1552
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1553 1553
 						goto error;
1554 1554
 					case P_HOST:
1555
-						*tmp=0; /*mark the end*/
1555
+						VIA_ZT(*tmp); /*mark the end*/
1556 1556
 						vb->host.len=tmp-vb->host.s;
1557 1557
 						state=F_VIA;
1558 1558
 						break;
1559 1559
 					case P_PORT:
1560
-						*tmp=0; /*mark the end*/
1560
+						VIA_ZT(*tmp); /*mark the end*/
1561 1561
 						vb->port_str.len=tmp-vb->port_str.s;
1562 1562
 						state=F_VIA;
1563 1563
 						break;
... ...
@@ -1607,19 +1609,19 @@ parse_again:
1607 1607
 							*tmp, state);
1608 1608
 						goto  error;
1609 1609
 					case P_HOST:
1610