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 184
 					/*udp*/
181 185
 					send_sock=get_send_socket(to, PROTO_UDP);
182 186
 					if (send_sock!=0){
187
+#ifdef SCRATCH
183 188
 						ret=udp_send(send_sock, msg->orig, msg->len, to);
189
+#else
190
+						ret=udp_send(send_sock, msg->buf, msg->len, to);
191
+#endif
184 192
 					}else{
185 193
 						ret=-1;
186 194
 					}
... ...
@@ -188,7 +196,11 @@ int do_action(struct action* a, struct sip_msg* msg)
188 196
 #ifdef USE_TCP
189 197
 					else{
190 198
 					/*tcp*/
199
+#ifdef SCRATCH
191 200
 					ret=tcp_send(msg->orig, msg->len, to, 0);
201
+#else
202
+					ret=tcp_send(msg->buf, msg->len, to, 0);
203
+#endif
192 204
 				}
193 205
 #endif
194 206
 			}
... ...
@@ -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 107
 METHOD	method
107 108
 URI		uri
108 109
 SRCIP	src_ip
110
+SRCPORT	src_port
109 111
 DSTIP	dst_ip
110 112
 MYSELF	myself
111 113
 /* operators */
... ...
@@ -218,6 +220,7 @@ EAT_ABLE	[\ \t\b\r]
218 220
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
219 221
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
220 222
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
223
+<INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
221 224
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
222 225
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
223 226
 
... ...
@@ -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 124
 %token METHOD
124 125
 %token URI
125 126
 %token SRCIP
127
+%token SRCPORT
126 128
 %token DSTIP
127 129
 %token MYSELF
128 130
 
... ...
@@ -524,6 +526,10 @@ exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST,
524 526
 		| URI error	{ $$=0; yyerror("invalid operator,"
525 527
 				  					" == or =~ expected");
526 528
 					}
529
+		| SRCPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
530
+												SRCPORT_O, (void *) $3 ); }
531
+		| SRCPORT EQUAL_T error { $$=0; yyerror("number expected"); }
532
+		| SRCPORT error { $$=0; yyerror("equation operator expected"); }
527 533
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
528 534
 												SRCIP_O, $3);
529 535
 								}
... ...
@@ -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 43
  */
38 44
 #undef PRESERVE_ZT
39 45
 
46
+/* go one step further and remove ZT from first line too */
47
+#undef DONT_REMOVE_ZT
48
+
49
+/* make it all -- move ZT away (Via) */
50
+#define REMOVE_ALL_ZT
51
+
52
+/* don't use scratchpad  anymore */
53
+#undef SCRATCH
54
+
40 55
 
41 56
 /* ------------------------------------------------------ */
42 57
 /* don't touch this -- that's helper macros depending on
... ...
@@ -47,4 +62,10 @@
47 62
 #	define SET_ZT(_ch)
48 63
 #endif
49 64
 
65
+#ifdef REMOVE_ALL_ZT
66
+#	define VIA_ZT(_ch)
67
+#else
68
+#	define VIA_ZT(ch) (_ch)='\0'
69
+#endif
70
+
50 71
 #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 34
 #define data_lump_h
33 35
 
34 36
 
35
-enum { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
36
-enum { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
37
+enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
38
+enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
37 39
 
38 40
 struct lump{
39 41
 	int type; /* VIA, OTHER, UNSPEC(=0), ... */
40
-	int op;   /* DEL, ADD, NOP, UNSPEC(=0) */
42
+	enum lump_op op;   /* DEL, ADD, NOP, UNSPEC(=0) */
41 43
 	
42 44
 	union{
43 45
 		int offset; /* used for DEL, MODIFY */
... ...
@@ -53,7 +55,7 @@ struct lump{
53 55
 	
54 56
 	struct lump* next;
55 57
 
56
-	int flags; /* additional hints for use from TM's shmem */
58
+	enum lump_flag flags; /* additional hints for use from TM's shmem */
57 59
 };
58 60
 
59 61
 /*
... ...
@@ -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 579
 	if (response_file) {
575 580
 		fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
576 581
 	} else {
577
-		LOG(L_ERR, "ERROR: no file for print_version_cmd\n");
582
+		LOG(L_ERR, "ERROR: no file for %s\n", "print_version_cmd" );
583
+	}
584
+	return 1;
585
+}
586
+
587
+static int pwd_cmd( FILE *stream, char *response_file )
588
+{
589
+	char *cwd_buf;
590
+	int max_len;
591
+
592
+	if (!response_file) {
593
+		LOG(L_ERR, "ERROR: no file for %s\n", "pwd_cmd" );
594
+		return 1;
595
+	}
596
+
597
+	max_len=pathmax();
598
+	cwd_buf=pkg_malloc(max_len);
599
+	if (!cwd_buf) {
600
+		LOG(L_ERR, "ERROR: pwd_cmd: no cwd pkg mem\n");
601
+		fifo_reply(response_file, "500 no memory\n");
602
+		return 1;
603
+	}
604
+
605
+	if (getcwd(cwd_buf, max_len)) {
606
+		fifo_reply(response_file, "200 ok\n%s\n", cwd_buf );
607
+	} else {
608
+		fifo_reply(response_file, "500 getcwd failed\n" );
609
+	}
610
+
611
+	pkg_free(cwd_buf);
612
+	return 1;
613
+}
614
+
615
+static int arg_cmd( FILE *stream, char *response_file )
616
+{
617
+	FILE *reply_pipe;
618
+	int p;
619
+
620
+	if (response_file==0 || *response_file==0 ) {
621
+		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
622
+		return -1;
623
+	}
624
+	reply_pipe=open_reply_pipe(response_file);
625
+	if (reply_pipe==NULL) {
626
+		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
627
+			response_file );
628
+		return -1;
578 629
 	}
630
+
631
+	fputs( "200 ok\n", reply_pipe);
632
+	for (p=0; p<my_argc;p++) 
633
+			fprintf( reply_pipe, "%s\n", my_argv[p] );
634
+			
635
+	fclose(reply_pipe);
579 636
 	return 1;
580 637
 }
638
+
581 639
 	
582 640
 
583 641
 /* diagnostic and hello-world FIFO command */
... ...
@@ -688,6 +746,14 @@ int register_core_fifo()
688 746
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_VERSION);
689 747
 		return -1;
690 748
 	}
749
+	if (register_fifo_cmd(pwd_cmd, FIFO_PWD, 0)<0) {
750
+		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PWD);
751
+		return -1;
752
+	}
753
+	if (register_fifo_cmd(arg_cmd, FIFO_ARG, 0)<0) {
754
+		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_ARG);
755
+		return -1;
756
+	}
691 757
 	if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) {
692 758
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_WHICH);
693 759
 		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 324
 /* shared memory (in MB) */
324 325
 unsigned int shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
325 326
 
327
+/* export command-line to anywhere else */
328
+int my_argc;
329
+char **my_argv;
330
+
326 331
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
327 332
 		    (normally it shouldn't  be bigger  than 3) */
328 333
 
... ...
@@ -1059,6 +1064,7 @@ int main(int argc, char** argv)
1059 1064
 	/*init*/
1060 1065
 	port_no_str_len=0;
1061 1066
 	ret=-1;
1067
+	my_argc=argc; my_argv=argv;
1062 1068
 	
1063 1069
 	/* added by jku: add exit handler */
1064 1070
 	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 277
 		p += ROUND4(org_msg->new_uri.len);
277 278
 	}
278 279
 	/* message buffers(org and scratch pad) */
280
+#ifdef SCRATCH
279 281
 	memcpy( p , org_msg->orig , org_msg->len);
280 282
 	/* ZT to be safer */
281 283
 	*(p+org_msg->len)=0;
282 284
 	new_msg->orig = new_msg->buf = p;
285
+#else
286
+	memcpy( p , org_msg->buf, org_msg->len);
287
+	/* ZT to be safer */
288
+	*(p+org_msg->len)=0;
289
+	new_msg->buf = p;
290
+#endif
283 291
 	p += ROUND4(new_msg->len+1);
284 292
 	/* unparsed and eoh pointer */
285 293
 	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 76
 #include "t_hooks.h"
76 77
 #include "t_lookup.h"
77 78
 
79
+#define EQ_VIA_LEN(_via)\
80
+	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
81
+	  	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
82
+
83
+
78 84
 
79 85
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
86
+#define EQ_REQ_URI_LEN\
87
+	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
88
+
89
+#ifdef SCRATCH
80 90
 #define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
81 91
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->_hf->body.s), \
82 92
 	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 93
 #define EQ_REQ_URI_STR\
86 94
 	( memcmp( t_msg->first_line.u.request.uri.s,\
87 95
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->first_line.u.request.uri.s),\
88 96
 	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 97
 #define EQ_VIA_STR(_via)\
94 98
 	( memcmp( t_msg->_via->name.s,\
95 99
 	 translate_pointer(p_msg->orig,p_msg->buf,p_msg->_via->name.s),\
96 100
 	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
97 101
 	)==0 )
102
+#else /* SCRATCH */
103
+#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
104
+	p_msg->_hf->body.s, \
105
+	p_msg->_hf->body.len)==0)
106
+#define EQ_REQ_URI_STR\
107
+	( memcmp( t_msg->first_line.u.request.uri.s,\
108
+	p_msg->first_line.u.request.uri.s,\
109
+	p_msg->first_line.u.request.uri.len)==0)
110
+#define EQ_VIA_STR(_via)\
111
+	( memcmp( t_msg->_via->name.s,\
112
+	 p_msg->_via->name.s,\
113
+	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
114
+	)==0 )
115
+#endif /* SCRATCH */
116
+
117
+
98 118
 
99 119
 #ifdef PRESERVE_ZT
100 120
 #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 1053
 	/* use SIP parser to look at what is in the FIFO request */
1052 1054
 	memset(&faked_msg, 0, sizeof(struct sip_msg));
1053 1055
 	faked_msg.len=header.len; 
1054
-	faked_msg.buf=faked_msg.orig=faked_msg.unparsed=header_buf;
1056
+	faked_msg.buf=faked_msg.unparsed=header_buf;
1057
+#ifdef SCRATCH
1058
+	faked_msg.orig=faked_msg.buf;
1059
+#endif
1055 1060
 	if (parse_headers(&faked_msg, HDR_EOH, 0)==-1 ) {
1056 1061
 			DBG("DEBUG: fifo_uac: parse_headers failed\n");
1057 1062
 			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 70
 		(_dest) += (_len) ;\
70 71
 	}while(0);
71 72
 
73
+#ifdef SCRATCH
72 74
 #define append_str_trans(_dest,_src,_len,_msg) \
73 75
 	append_str( (_dest), (_msg)->orig+((_src)-(_msg)->buf) , (_len) );
76
+#else
77
+#define append_str_trans(_dest,_src,_len,_msg) \
78
+	append_str( (_dest), (_src), (_len) );
79
+#endif
74 80
 
75 81
 extern char version[];
76 82
 extern int version_len;
77 83
 
78 84
 
79 85
 
86
+#ifndef REMOVE_ALL_ZT
80 87
 /* checks if ip is in host(name) and ?host(ip)=name?
81 88
  * ip must be in network byte order!
82 89
  *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
83 90
  * return 0 if equal */
84
-int check_address(struct ip_addr* ip, char *name, int resolver)
91
+static int check_address(struct ip_addr* ip, char *name, int resolver)
85 92
 {
86 93
 	struct hostent* he;
87 94
 	int i;
... ...
@@ -90,19 +97,22 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
90 97
 	/* maybe we are lucky and name it's an ip */
91 98
 	s=ip_addr2a(ip);
92 99
 	if (s){
93
-		DBG("check_address(%s, %s, %d)\n", s, name, resolver);
100
+		DBG("check_address(%s, %.*s, %d)\n", 
101
+			s, name->len, name->s, resolver);
102
+
94 103
 	#ifdef USE_IPV6
95 104
 		if ((ip->af==AF_INET6) && (strcasecmp(name, s)==0))
96 105
 				return 0;
97 106
 		else
98 107
 	#endif
99
-			if (strcmp(name, s)==0)
108
+
109
+			if (strcmp(name, s)==0) 
100 110
 				return 0;
101 111
 	}else{
102 112
 		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
103 113
 		return -1;
104 114
 	}
105
-		
115
+
106 116
 	if (resolver&DO_DNS){
107 117
 		DBG("check_address: doing dns lookup\n");
108 118
 		/* try all names ips */
... ...
@@ -127,6 +137,65 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
127 137
 	}
128 138
 	return -1;
129 139
 }
140
+#endif
141
+
142
+
143
+
144
+/* checks if ip is in host(name) and ?host(ip)=name?
145
+ * ip must be in network byte order!
146
+ *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
147
+ * return 0 if equal */
148
+static int check_via_address(struct ip_addr* ip, str *name, 
149
+				unsigned short port, int resolver)
150
+{
151
+	struct hostent* he;
152
+	int i;
153
+	char* s;
154
+
155
+	/* maybe we are lucky and name it's an ip */
156
+	s=ip_addr2a(ip);
157
+	if (s){
158
+		DBG("check_address(%s, %.*s, %d)\n", 
159
+			s, name->len, name->s, resolver);
160
+
161
+	#ifdef USE_IPV6
162
+		if ((ip->af==AF_INET6) && (strncasecmp(name->s, s, name->len)==0))
163
+			return 0;
164
+		else
165
+	#endif
166
+
167
+			if (strncmp(name->s, s, name->len)==0) 
168
+				return 0;
169
+	}else{
170
+		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
171
+		return -1;
172
+	}
173
+
174
+	if (port==0) port=SIP_PORT;
175
+	if (resolver&DO_DNS){
176
+		DBG("check_address: doing dns lookup\n");
177
+		/* try all names ips */
178
+		he=sip_resolvehost(name, &port);
179
+		if (he && ip->af==he->h_addrtype){
180
+			for(i=0;he && he->h_addr_list[i];i++){
181
+				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)
182
+					return 0;
183
+			}
184
+		}
185
+	}
186
+	if (resolver&DO_REV_DNS){
187
+		DBG("check_address: doing rev. dns lookup\n");
188
+		/* try reverse dns */
189
+		he=rev_resolvehost(ip);
190
+		if (he && (strncmp(he->h_name, name->s, name->len)==0))
191
+			return 0;
192
+		for (i=0; he && he->h_aliases[i];i++){
193
+			if (strncmp(he->h_aliases[i],name->s, name->len)==0)
194
+				return 0;
195
+		}
196
+	}
197
+	return -1;
198
+}
130 199
 
131 200
 
132 201
 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 532
 	char* received_buf;
464 533
 	char* rport_buf;
465 534
 	char* new_buf;
535
+#ifdef SCRATCH
466 536
 	char* orig;
537
+#endif
467 538
 	char* buf;
539
+#ifndef REMOVE_ALL_ZT
468 540
 	char  backup;
541
+#endif
469 542
 	unsigned int offset, s_offset, size;
470 543
 	struct lump* anchor;
471 544
 	int r;
... ...
@@ -483,7 +556,9 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
483 556
 	extra_params.len=0;
484 557
 	extra_params.s=0;
485 558
 	uri_len=0;
559
+#ifdef SCRATCH
486 560
 	orig=msg->orig;
561
+#endif
487 562
 	buf=msg->buf;
488 563
 	len=msg->len;
489 564
 	received_len=0;
... ...
@@ -515,10 +590,15 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
515 590
 		goto error00;
516 591
 	}
517 592
 	/* check if received needs to be added */
593
+#ifdef REMOVE_ALL_ZT
594
+	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
595
+		msg->via1->port, received_dns);
596
+#else
518 597
 	backup = msg->via1->host.s[msg->via1->host.len];
519 598
 	msg->via1->host.s[msg->via1->host.len] = 0;
520 599
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
521 600
 	msg->via1->host.s[msg->via1->host.len] = backup;
601
+#endif
522 602
 	if (r!=0){
523 603
 		if ((received_buf=received_builder(msg,&received_len))==0){
524 604
 			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 671
 	if (msg->new_uri.s){
592 672
 		/* copy message up to uri */
593 673
 		size=msg->first_line.u.request.uri.s-buf;
674
+#ifdef SCRATCH
594 675
 		memcpy(new_buf, orig, size);
676
+#else
677
+		memcpy(new_buf, buf, size);
678
+#endif
595 679
 		offset+=size;
596 680
 		s_offset+=size;
597 681
 		/* add our uri */
... ...
@@ -600,10 +684,17 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
600 684
 		s_offset+=msg->first_line.u.request.uri.len; /* skip original uri */
601 685
 	}
602 686
 	new_buf[new_len]=0;
687
+#ifdef SCRATCH
603 688
 	/* copy msg adding/removing lumps */
604 689
 	process_lumps(msg->add_rm, new_buf, &offset, orig, &s_offset);
605 690
 	/* copy the rest of the message */
606 691
 	memcpy(new_buf+offset, orig+s_offset, len-s_offset);
692
+#else
693
+	/* copy msg adding/removing lumps */
694
+	process_lumps(msg->add_rm, new_buf, &offset, buf, &s_offset);
695
+	/* copy the rest of the message */
696
+	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
697
+#endif
607 698
 	new_buf[new_len]=0;
608 699
 
609 700
 #ifdef DBG_MSG_QA
... ...
@@ -637,11 +728,15 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
637 728
 	unsigned int new_len, via_len;
638 729
 	char* new_buf;
639 730
 	unsigned offset, s_offset, via_offset;
731
+#ifdef SCRATCH
640 732
 	char* orig;
733
+#endif
641 734
 	char* buf;
642 735
 	unsigned int len;
643 736
 
737
+#ifdef SCRATCH
644 738
 	orig=msg->orig;
739
+#endif
645 740
 	buf=msg->buf;
646 741
 	len=msg->len;
647 742
 	new_buf=0;
... ...
@@ -685,9 +780,21 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
685 780
 	}
686 781
 	new_buf[new_len]=0; /* debug: print the message */
687 782
 	offset=s_offset=0;
688
-	process_lumps(msg->repl_add_rm, new_buf, &offset, orig, &s_offset);
783
+	process_lumps(msg->repl_add_rm, new_buf, &offset, 
784
+#ifdef SCRATCH
785
+		orig, 
786
+#else
787
+		buf,
788
+#endif
789
+		&s_offset);
689 790
 	/* copy the rest of the message */
690
-	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
791
+	memcpy(new_buf+offset,
792
+#ifdef SCRATCH
793
+		orig+s_offset, 
794
+#else
795
+		buf+s_offset, 
796
+#endif
797
+		len-s_offset);
691 798
 	 /* send it! */
692 799
 	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
693 800
 			s_offset, offset,
... ...
@@ -721,6 +828,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
721 828
 	unsigned int      delete_len;
722 829
 	char              *warning;
723 830
 	unsigned int      warning_len;
831
+	unsigned int	  text_len;
724 832
 	int r;
725 833
 #ifndef PRESERVE_ZT
726 834
 	char *after_body;
... ...
@@ -736,6 +844,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
736 844
 	/* make -Wall happy */
737 845
 	warning=0;
738 846
 
847
+	text_len=strlen(text);
848
+
739 849
 	/* force parsing all headers -- we want to return all
740 850
 	Via's in the reply and they may be scattered down to the
741 851
 	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 859
 	/* check if received needs to be added */
750 860
 	backup = msg->via1->host.s[msg->via1->host.len];
751 861
 	msg->via1->host.s[msg->via1->host.len] = 0;
862
+#ifdef REMOVE_ALL_ZT
863
+	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
864
+		msg->via1->port, received_dns);
865
+#else
752 866
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
867
+#endif
753 868
 	msg->via1->host.s[msg->via1->host.len] = backup;
754 869
 	if (r!=0) {
755 870
 		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 887
 	len = 0;
773 888
 	/* first line */
774 889
 	len += SIP_VERSION_LEN + 1/*space*/ + 3/*code*/ + 1/*space*/ +
775
-		strlen(text) + CRLF_LEN/*new line*/;
890
+		text_len + CRLF_LEN/*new line*/;
776 891
 	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
777 892
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next ) {
778 893
 		if (hdr->type==HDR_TO) {
... ...
@@ -843,8 +958,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
843 958
 		*(p+i) = '0' + foo - ( foo/10 )*10;
844 959
 	p += 3;
845 960
 	*(p++) = ' ' ;
846
-	memcpy( p , text , strlen(text) );
847
-	p += strlen(text);
961
+	memcpy( p , text , text_len );
962
+	p += text_len;
848 963
 	memcpy( p, CRLF, CRLF_LEN );
849 964
 	p+=CRLF_LEN;
850 965
 	/* 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 405
 			msg->last_header=hf;
405 406
 		}
406 407
 #ifdef EXTRA_DEBUG
407
-		DBG("header field type %d, name=<%s>, body=<%s>\n",
408
-			hf->type, hf->name.s, hf->body.s);
408
+		DBG("header field type %d, name=<%.*s>, body=<%.*s>\n",
409
+			hf->type, 
410
+			hf->name.len, hf->name.s, 
411
+			hf->body.len, hf->body.s);
409 412
 #endif
410 413
 		tmp=rest;
411 414
 	}
... ...
@@ -454,16 +457,22 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
454 457
 			break;
455 458
 		case SIP_REQUEST:
456 459
 			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);
460
+			DBG(" method:  <%.*s>\n",fl->u.request.method.len,
461
+				fl->u.request.method.s);
462
+			DBG(" uri:     <%.*s>\n",fl->u.request.uri.len,
463
+				fl->u.request.uri.s);
464
+			DBG(" version: <%.*s>\n",fl->u.request.version.len,
465
+				fl->u.request.version.s);
460 466
 			flags=HDR_VIA;
461 467
 			break;
462 468
 		case SIP_REPLY:
463 469
 			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);
470
+			DBG(" version: <%.*s>\n",fl->u.reply.version.len,
471
+					fl->u.reply.version.s);
472
+			DBG(" status:  <%.*s>\n", fl->u.reply.status.len,
473
+					fl->u.reply.status.s);
474
+			DBG(" reason:  <%.*s>\n", fl->u.reply.reason.len,
475
+					fl->u.reply.reason.s);
467 476
 			/* flags=HDR_VIA | HDR_VIA2; */
468 477
 			/* we don't try to parse VIA2 for local messages; -Jiri */
469 478
 			flags=HDR_VIA;
... ...
@@ -481,21 +490,42 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
481 490
 #ifdef EXTRA_DEBUG
482 491
 	/* dump parsed data */
483 492
 	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);
493
+		DBG(" first  via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
494
+			msg->via1->name.len, 
495
+			msg->via1->name.s, 
496
+			msg->via1->version.len,
497
+			msg->via1->version.s,
498
+			msg->via1->transport.len 
499
+			msg->via1->transport.s, 
500
+			msg->via1->host.len,
501
+			msg->via1->host.s,
502
+			msg->via1->port_str.len, 
503
+			msg->via1->port_str.s, 
504
+			msg->via1->port);
505
+		if (msg->via1->params.s)  DBG(";<%.*s>", 
506
+				msg->via1->params.len, msg->via1->params.s);
507
+		if (msg->via1->comment.s) 
508
+				DBG(" <%.*s>", 
509
+					msg->via1->comment.len, msg->via1->comment.s);
490 510
 		DBG ("\n");
491 511
 	}
492 512
 	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);
513
+		DBG(" first  via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
514
+			msg->via2->name.len, 
515
+			msg->via2->name.s, 
516
+			msg->via2->version.len,
517
+			msg->via2->version.s,
518
+			msg->via2->transport.len, 
519
+			msg->via2->transport.s, 
520
+			msg->via2->host.len,
521
+			msg->via2->host.s,
522
+			msg->via2->port_str.len, 
523
+			msg->via2->port_str.s, 
524
+			msg->via2->port);
525
+		if (msg->via2->params.s)  DBG(";<%.*s>", 
526
+				msg->via2->params.len, msg->via2->params.s);
527
+		if (msg->via2->comment.s) DBG(" <%.*s>", 
528
+				msg->via2->comment.len, msg->via2->comment.s);
499 529
 		DBG ("\n");
500 530
 	}
501 531
 #endif
... ...
@@ -509,7 +539,11 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
509 539
 	
510 540
 error:
511 541
 	/* more debugging, msg->orig is/should be null terminated*/
542
+#ifdef SCRATCH
512 543
 	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->orig);
544
+#else
545
+	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->buf);
546
+#endif
513 547
 	return -1;
514 548
 }
515 549
 
... ...
@@ -535,7 +569,9 @@ void free_sip_msg(struct sip_msg* msg)
535 569
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
536 570
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
537 571
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
572
+#ifdef SCRATCH
538 573
 	pkg_free(msg->orig);
574
+#endif
539 575
 	/* don't free anymore -- now a pointer to a static buffer */
540 576
 #	ifdef DYN_BUF
541 577
 	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 122
 	char* unparsed;   /* here we stopped parsing*/
120 123
 	
121 124
 	struct receive_info rcv; /* source & dest ip, ports, proto a.s.o*/
122
-	
125
+
126
+#ifdef SCRATCH	
123 127
 	char* orig;       /* original message copy */
128
+#endif
124 129
 	char* buf;        /* scratch pad, holds a modfied message,
125 130
 					   *  via, etc. point into it */
126 131
 	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 61
 };
57 62
 
58 63
 
59
-
64
+#ifdef _CURRENTLY_UNUSED
60 65
 char* parse_fline(char* buffer, char* end, struct msg_start* fl)
61 66
 {
62 67
 	char* tmp;
... ...
@@ -1120,6 +1125,7 @@ char* parse_fline(char* buffer, char* end, struct msg_start* fl)
1120 1125
 		}
1121 1126
 	}
1122 1127
 skip:
1128
+	fl->len=tmp-buf;
1123 1129
 	if (fl->type==SIP_REPLY){
1124 1130
 		fl->u.reply.statuscode=stat;
1125 1131
 		/* fl->u.reply.statusclass=stat/100; */
... ...
@@ -1132,7 +1138,7 @@ error:
1132 1138
 	return tmp;
1133 1139
 }
1134 1140
 
1135
-
1141
+#endif /* currently unused */
1136 1142
 
1137 1143
 /* parses the first line, returns pointer to  next line  & fills fl;
1138 1144
    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 1218
 	   tmp points at space after; go ahead */
1213 1219
 
1214 1220
 	fl->u.request.method.s=buffer;  /* store ptr to first token */
1221
+#ifdef DONT_REMOVE_ZT
1215 1222
 	(*tmp)=0;			/* mark the 1st token end */
1223
+#endif
1216 1224
 	second=tmp+1;			/* jump to second token */
1217 1225
 	offset=second-buffer;
1218 1226
 
... ...
@@ -1229,15 +1237,17 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
1229 1237
 	if ((third==tmp)||(tmp>=end)){
1230 1238
 		goto error;
1231 1239
 	}
1240
+#ifdef DONT_REMOVE_ZT
1232 1241
 	*tmp=0; /* mark the end of the token */
1242
+#endif
1233 1243
 	fl->u.request.uri.s=second;
1234 1244
 	fl->u.request.uri.len=tmp-second;
1235 1245
 
1236 1246
 	/* jku: parse status code */
1237 1247
 	if (fl->type==SIP_REPLY) {
1238 1248
 		if (fl->u.request.uri.len!=3) {
1239
-			LOG(L_INFO, "ERROR:parse_first_line: len(status code)!=3: %s\n",
1240
-				second );
1249
+			LOG(L_INFO, "ERROR:parse_first_line: len(status code)!=3: %.*s\n",
1250
+				fl->u.request.uri.len, second );
1241 1251
 			goto error;
1242 1252
 		}
1243 1253
 		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 1256
 		    s3>='0' && s3<='9' ) {
1247 1257
 			fl->u.reply.statuscode=(s1-'0')*100+10*(s2-'0')+(s3-'0');
1248 1258
 		} else {
1249
-			LOG(L_INFO, "ERROR:parse_first_line: status_code non-numerical: %s\n",
1250
-				second );
1259
+			LOG(L_INFO, "ERROR:parse_first_line: status_code non-numerical: %.*s\n",
1260
+				fl->u.request.uri.len, second );
1251 1261
 			goto error;
1252 1262
 		}
1253 1263
 	}
... ...
@@ -1277,9 +1287,12 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
1277 1287
 	if (nl>=end){ /* no crlf in packet or only 1 line > invalid */
1278 1288
 		goto error;
1279 1289
 	}
1290
+#ifdef DONT_REMOVE_ZT
1280 1291
 	*tmp=0;
1292
+#endif
1281 1293
 	fl->u.request.version.s=third;
1282 1294
 	fl->u.request.version.len=tmp-third;
1295
+	fl->len=nl-buffer;
1283 1296
 
1284 1297
 	return nl;
1285 1298
 
... ...
@@ -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 55
 
55 56
 	return host->s;
56 57
 }
58
+
59
+#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 129
 			case '\t':
128 130
 				switch(state){
129 131
 					case FIN_HIDDEN:
130
-						*tmp=0;
132
+						VIA_ZT(*tmp);
131 133
 						param->type=state;
132 134
 						param->name.len=tmp-param->name.s;
133 135
 						state=L_PARAM;
... ...
@@ -138,7 +140,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
138 140
 					case FIN_RECEIVED:
139 141
 					case FIN_RPORT:
140 142
 					case FIN_I:
141
-						*tmp=0;
143
+						VIA_ZT(*tmp);
142 144
 						param->type=state;
143 145
 						param->name.len=tmp-param->name.s;
144 146
 						state=L_VALUE;
... ...
@@ -152,7 +154,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
152 154
 						break;
153 155
 					case GEN_PARAM:
154 156
 					default:
155
-						*tmp=0;
157
+						VIA_ZT(*tmp);
156 158
 						param->type=GEN_PARAM;
157 159
 						param->name.len=tmp-param->name.s;
158 160
 						state=L_VALUE;
... ...
@@ -163,7 +165,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
163 165
 			case '\n':
164 166
 				switch(state){
165 167
 					case FIN_HIDDEN:
166
-						*tmp=0;
168
+						VIA_ZT(*tmp);
167 169
 						param->type=state;
168 170
 						param->name.len=tmp-param->name.s;
169 171
 						param->size=tmp-param->start; 
... ...
@@ -176,7 +178,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
176 178
 					case FIN_RECEIVED:
177 179
 					case FIN_I:
178 180
 					case FIN_RPORT:
179
-						*tmp=0;
181
+						VIA_ZT(*tmp);
180 182
 						param->type=state;
181 183
 						param->name.len=tmp-param->name.s;
182 184
 						param->size=tmp-param->start; 
... ...
@@ -196,7 +198,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
196 198
 						break;
197 199
 					case GEN_PARAM:
198 200
 					default:
199
-						*tmp=0;
201
+						VIA_ZT(*tmp);
200 202
 						param->type=GEN_PARAM;
201 203
 						saved_state=L_VALUE;
202 204
 						param->name.len=tmp-param->name.s;
... ...
@@ -208,7 +210,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
208 210
 			case '\r':
209 211
 				switch(state){
210 212
 					case FIN_HIDDEN:
211
-						*tmp=0;
213
+						VIA_ZT(*tmp);
212 214
 						param->type=state;
213 215
 						param->name.len=tmp-param->name.s;
214 216
 						param->size=tmp-param->start; 
... ...
@@ -221,7 +223,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
221 223
 					case FIN_RECEIVED:
222 224
 					case FIN_I:
223 225
 					case FIN_RPORT:
224
-						*tmp=0;
226
+						VIA_ZT(*tmp);
225 227
 						param->type=state;
226 228
 						param->name.len=tmp-param->name.s;
227 229
 						param->size=tmp-param->start; 
... ...
@@ -238,7 +240,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
238 240
 						goto end_via;
239 241
 					case GEN_PARAM:
240 242
 					default:
241
-						*tmp=0;
243
+						VIA_ZT(*tmp);
242 244
 						param->type=GEN_PARAM;
243 245
 						param->name.len=tmp-param->name.s;
244 246
 						param->size=tmp-param->start; 
... ...
@@ -256,7 +258,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
256 258
 					case FIN_RECEIVED:
257 259
 					case FIN_RPORT:
258 260
 					case FIN_I:
259
-						*tmp=0;
261
+						VIA_ZT(*tmp);
260 262
 						param->type=state;
261 263
 						param->name.len=tmp-param->name.s;
262 264
 						state=F_VALUE;
... ...
@@ -273,7 +275,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
273 275
 						goto end_via;
274 276
 					case GEN_PARAM:
275 277
 					default:
276
-						*tmp=0;
278
+						VIA_ZT(*tmp);
277 279
 						param->type=GEN_PARAM;
278 280
 						param->name.len=tmp-param->name.s;
279 281
 						state=F_VALUE;
... ...
@@ -284,7 +286,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
284 286
 				switch(state){
285 287
 					case FIN_HIDDEN:
286 288
 					case FIN_RPORT: /* rport can appear w/o a value */
287
-						*tmp=0;
289
+						VIA_ZT(*tmp);
288 290
 						param->type=state;
289 291
 						param->name.len=tmp-param->name.s;
290 292
 						state=F_PARAM;
... ...
@@ -304,7 +306,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
304 306
 						goto end_via;
305 307
 					case GEN_PARAM:
306 308
 					default:
307
-						*tmp=0;
309
+						VIA_ZT(*tmp);
308 310
 						param->type=GEN_PARAM;
309 311
 						param->name.len=tmp-param->name.s;
310 312
 						state=F_PARAM;
... ...
@@ -315,7 +317,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
315 317
 				switch(state){
316 318
 					case FIN_HIDDEN:
317 319
 					case FIN_RPORT:
318
-						*tmp=0;
320
+						VIA_ZT(*tmp);
319 321
 						param->type=state;
320 322
 						param->name.len=tmp-param->name.s;
321 323
 						state=F_VIA;
... ...
@@ -336,7 +338,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
336 338
 						goto end_via;
337 339
 					case GEN_PARAM:
338 340
 					default:
339
-						*tmp=0;
341
+						VIA_ZT(*tmp);
340 342
 						param->type=GEN_PARAM;
341 343
 						param->name.len=tmp-param->name.s;
342 344
 						state=F_VIA;
... ...
@@ -719,7 +721,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
719 721
 					case F_VALUE: /*eat space*/
720 722
 						break; 
721 723
 					case P_VALUE:
722
-						*tmp=0;
724
+						VIA_ZT(*tmp);
723 725
 						state=L_PARAM;
724 726
 						param->value.len=tmp-param->value.s;
725 727
 						goto endofvalue;
... ...
@@ -746,7 +748,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
746 748
 						state=F_LF;
747 749
 						break;
748 750
 					case P_VALUE:
749
-						*tmp=0;
751
+						VIA_ZT(*tmp);
750 752
 						saved_state=L_PARAM;
751 753
 						state=F_LF;
752 754
 						param->value.len=tmp-param->value.s;
... ...
@@ -774,7 +776,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
774 776
 						state=F_CR;
775 777
 						break;
776 778
 					case P_VALUE:
777
-						*tmp=0;
779
+						VIA_ZT(*tmp);
778 780
 						param->value.len=tmp-param->value.s;
779 781
 						saved_state=L_PARAM;
780 782
 						state=F_CR;
... ...
@@ -812,12 +814,12 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
812 814
 			case ';':
813 815
 				switch(state){
814 816
 					case P_VALUE:
815
-						*tmp=0;
817
+						VIA_ZT(*tmp);
816 818
 						param->value.len=tmp-param->value.s;
817 819
 						state=F_PARAM;
818 820
 						goto endofvalue;
819 821
 					case F_VALUE:
820
-						*tmp=0;
822
+						VIA_ZT(*tmp);
821 823
 						param->value.len=0;
822 824
 						state=F_PARAM;
823 825
 						goto endofvalue;
... ...
@@ -845,7 +847,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
845 847
 			case ',':
846 848
 				switch(state){
847 849
 					case P_VALUE:
848
-						*tmp=0;
850
+						VIA_ZT(*tmp);
849 851
 						param->value.len=tmp-param->value.s;
850 852
 						state=F_VIA;
851 853
 						goto endofvalue;
... ...
@@ -876,7 +878,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
876 878
 						param->value.s=tmp+1;
877 879
 						break;
878 880
 					case P_STRING:
879
-						*tmp=0;
881
+						VIA_ZT(*tmp);
880 882
 						state=L_PARAM;
881 883
 						param->value.len=tmp-param->value.s;
882 884
 						goto endofvalue;
... ...
@@ -924,8 +926,8 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
924 926
 normal_exit:
925 927
 	*pstate=state;
926 928
 	*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);
929
+	DBG("Found param type %d, <%.*s> = <%.*s>; state=%d\n", param->type,
930
+			param->name.len, param->name.s, param->value.len, param->value.s, state);
929 931
 	return tmp;
930 932
 	
931 933
  end_via:
... ...
@@ -941,8 +943,8 @@ normal_exit:
941 943
 	}
942 944
 	*pstate=state;
943 945
 	*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);
946
+	DBG("Error on  param type %d, <%.*s>, state=%d, saved_state=%d\n",
947
+		param->type, param->name.len, param->name.s, state, saved_state);
946 948
 
947 949
  error:
948 950
 	LOG(L_ERR, "error: parse_via_param\n");
... ...
@@ -982,24 +984,24 @@ parse_again:
982 984
 					case F_PROTO:
983 985
 						break;
984 986
 					case FIN_UDP:
985
-						*tmp=0;  /* finished proto parsing */
987
+						VIA_ZT(*tmp); /* finished proto parsing */
986 988
 						vb->transport.len=tmp-vb->transport.s;
987 989
 						vb->proto=PROTO_UDP;
988 990
 						state=F_HOST; /* start looking for host*/
989 991
 						goto main_via;
990 992
 					case FIN_TCP:
991
-						*tmp=0;  /* finished proto parsing */
993
+						VIA_ZT(*tmp); /* finished proto parsing */
992 994
 						vb->transport.len=tmp-vb->transport.s;
993 995
 						vb->proto=PROTO_TCP;
994 996
 						state=F_HOST; /* start looking for host*/
995 997
 						goto main_via;
996 998
 					case FIN_SIP:
997
-						*tmp=0;
999
+						VIA_ZT(*tmp);
998 1000
 						vb->name.len=tmp-vb->name.s;
999 1001
 						state=L_VER;
1000 1002
 						break;
1001 1003
 					case FIN_VER:
1002
-						*tmp=0;
1004
+						VIA_ZT(*tmp);
1003 1005
 						vb->version.len=tmp-vb->version.s;
1004 1006
 						state=L_PROTO;
1005 1007
 						break;
... ...
@@ -1025,27 +1027,27 @@ parse_again:
1025 1027
 						state=F_LF;
1026 1028
 						break;
1027 1029
 					case FIN_UDP:
1028
-						*tmp=0;
1030
+						VIA_ZT(*tmp);
1029 1031
 						vb->transport.len=tmp-vb->transport.s;
1030 1032
 						vb->proto=PROTO_UDP;
1031 1033
 						state=F_LF;
1032 1034
 						saved_state=F_HOST; /* start looking for host*/
1033 1035
 						goto main_via;
1034 1036
 					case FIN_TCP:
1035
-						*tmp=0;
1037
+						VIA_ZT(*tmp);
1036 1038
 						vb->transport.len=tmp-vb->transport.s;
1037 1039
 						vb->proto=PROTO_TCP;
1038 1040
 						state=F_LF;
1039 1041
 						saved_state=F_HOST; /* start looking for host*/
1040 1042
 						goto main_via;
1041 1043
 					case FIN_SIP:
1042
-						*tmp=0;
1044
+						VIA_ZT(*tmp);
1043 1045
 						vb->name.len=tmp-vb->name.s;
1044 1046
 						state=F_LF;
1045 1047
 						saved_state=L_VER;
1046 1048
 						break;
1047 1049
 					case FIN_VER:
1048
-						*tmp=0;
1050
+						VIA_ZT(*tmp);
1049 1051
 						vb->version.len=tmp-vb->version.s;
1050 1052
 						state=F_LF;
1051 1053
 						saved_state=L_PROTO;
... ...
@@ -1074,27 +1076,27 @@ parse_again:
1074 1076
 						state=F_CR;
1075 1077
 						break;
1076 1078
 					case FIN_UDP:
1077
-						*tmp=0;
1079
+						VIA_ZT(*tmp);
1078 1080
 						vb->transport.len=tmp-vb->transport.s;
1079 1081
 						vb->proto=PROTO_UDP;
1080 1082
 						state=F_CR;
1081 1083
 						saved_state=F_HOST;
1082 1084
 						goto main_via;
1083 1085
 					case FIN_TCP:
1084
-						*tmp=0;
1086
+						VIA_ZT(*tmp);
1085 1087
 						vb->transport.len=tmp-vb->transport.s;
1086 1088
 						vb->proto=PROTO_TCP;
1087 1089
 						state=F_CR;
1088 1090
 						saved_state=F_HOST;
1089 1091
 						goto main_via;
1090 1092
 					case FIN_SIP:
1091
-						*tmp=0;
1093
+						VIA_ZT(*tmp);
1092 1094
 						vb->name.len=tmp-vb->name.s;
1093 1095
 						state=F_CR;
1094 1096
 						saved_state=L_VER;
1095 1097
 						break;
1096 1098
 					case FIN_VER:
1097
-						*tmp=0;
1099
+						VIA_ZT(*tmp);
1098 1100
 						vb->version.len=tmp-vb->version.s;
1099 1101
 						state=F_CR;
1100 1102
 						saved_state=L_PROTO;
... ...
@@ -1114,12 +1116,12 @@ parse_again:
1114 1116
 			case '/':
1115 1117
 				switch(state){
1116 1118
 					case FIN_SIP:
1117
-						*tmp=0;
1119
+						VIA_ZT(*tmp);
1118 1120
 						vb->name.len=tmp-vb->name.s;
1119 1121
 						state=F_VER;
1120 1122
 						break;
1121 1123
 					case FIN_VER:
1122
-						*tmp=0;
1124
+						VIA_ZT(*tmp);
1123 1125
 						vb->version.len=tmp-vb->version.s;
1124 1126
 						state=F_PROTO;
1125 1127
 						break;
... ...
@@ -1292,7 +1294,7 @@ parse_again:
1292 1294
 					case F_HOST:/*eat the spaces*/
1293 1295
 						break;
1294 1296
 					case P_HOST:
1295
-						 *tmp=0;/*mark end of host*/
1297
+						 VIA_ZT(*tmp);/*mark end of host*/
1296 1298
 						 vb->host.len=tmp-vb->host.s;
1297 1299
 						 state=L_PORT;
1298 1300
 						 break;
... ...
@@ -1300,7 +1302,7 @@ parse_again:
1300 1302
 					case F_PORT:
1301 1303
 						break;
1302 1304
 					case P_PORT:
1303
-						*tmp=0; /*end of port */
1305
+						VIA_ZT(*tmp); /*end of port */
1304 1306
 						vb->port_str.len=tmp-vb->port_str.s;
1305 1307
 						state=L_PARAM;
1306 1308
 						break;
... ...
@@ -1320,7 +1322,7 @@ parse_again:
1320 1322
 					case F_IP6HOST: /*eat the spaces*/
1321 1323
 						break;
1322 1324
 					case P_IP6HOST:
1323
-						*tmp=0; /*mark end of host*/
1325
+						VIA_ZT(*tmp); /*mark end of host*/
1324 1326
 						vb->host.len=tmp-vb->host.s;
1325 1327
 						state=L_PORT; 
1326 1328
 						break;
... ...
@@ -1353,13 +1355,13 @@ parse_again:
1353 1355
 						state=F_LF;
1354 1356
 						break;
1355 1357
 					case P_HOST:
1356
-						 *tmp=0;/*mark end of host*/
1358
+						 VIA_ZT(*tmp);/*mark end of host*/
1357 1359
 						 vb->host.len=tmp-vb->host.s;
1358 1360
 						 saved_state=L_PORT;
1359 1361
 						 state=F_LF;
1360 1362
 						 break;
1361 1363
 					case P_PORT:
1362
-						*tmp=0; /*end of port */
1364
+						VIA_ZT(*tmp); /*end of port */
1363 1365
 						vb->port_str.len=tmp-vb->port_str.s;
1364 1366
 						saved_state=L_PARAM;
1365 1367
 						state=F_LF;
... ...
@@ -1399,13 +1401,13 @@ parse_again:
1399 1401
 						state=F_CR;
1400 1402
 						break;
1401 1403
 					case P_HOST:
1402
-						 *tmp=0;/*mark end of host*/
1404
+						 VIA_ZT(*tmp);/*mark end of host*/
1403 1405
 						 vb->host.len=tmp-vb->host.s;
1404 1406
 						 saved_state=L_PORT;
1405 1407
 						 state=F_CR;
1406 1408
 						 break;
1407 1409
 					case P_PORT:
1408
-						*tmp=0; /*end of port */
1410
+						VIA_ZT(*tmp); /*end of port */
1409 1411
 						vb->port_str.len=tmp-vb->port_str.s;
1410 1412
 						saved_state=L_PARAM;
1411 1413
 						state=F_CR;
... ...
@@ -1437,7 +1439,7 @@ parse_again:
1437 1439
 					case P_IP6HOST:
1438 1440
 						break;
1439 1441
 					case P_HOST:
1440
-						*tmp=0; /*mark  end of host*/
1442
+						VIA_ZT(*tmp); /*mark  end of host*/
1441 1443
 						vb->host.len=tmp-vb->host.s;
1442 1444
 						state=F_PORT;
1443 1445
 						break;
... ...
@@ -1489,13 +1491,13 @@ parse_again:
1489 1491
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1490 1492
 						goto error;
1491 1493
 					case P_HOST:
1492
-						*tmp=0;
1494
+						VIA_ZT(*tmp);
1493 1495
 						vb->host.len=tmp-vb->host.s;
1494 1496
 						state=F_PARAM;
1495 1497
 						param_start=tmp+1;
1496 1498
 						break;
1497 1499
 					case P_PORT:
1498
-						*tmp=0; /*mark the end*/
1500
+						VIA_ZT(*tmp); /*mark the end*/
1499 1501
 						vb->port_str.len=tmp-vb->port_str.s;
1500 1502
 					case L_PORT:
1501 1503
 					case L_PARAM:
... ...
@@ -1552,12 +1554,12 @@ parse_again:
1552 1554
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1553 1555
 						goto error;
1554 1556
 					case P_HOST:
1555
-						*tmp=0; /*mark the end*/
1557
+						VIA_ZT(*tmp); /*mark the end*/
1556 1558
 						vb->host.len=tmp-vb->host.s;
1557 1559
 						state=F_VIA;
1558 1560
 						break;
1559 1561
 					case P_PORT:
1560
-						*tmp=0; /*mark the end*/
1562
+						VIA_ZT(*tmp); /*mark the end*/
1561 1563
 						vb->port_str.len=tmp-vb->port_str.s;
1562 1564
 						state=F_VIA;
1563 1565
 						break;
... ...
@@ -1607,19 +1609,19 @@ parse_again:
1607 1609
 							*tmp, state);
1608 1610
 						goto  error;
1609