Kaynağa Gözat

scratchpad removed, textops changed to skip the first line

Jiri Kuthan 22 yıl önce
ebeveyn
işleme
049f64c292
28 değiştirilmiş dosya ile 585 ekleme ve 119 silme
  1. 13 1
      action.c
  2. 3 0
      cfg.lex
  3. 6 0
      cfg.y
  4. 22 1
      comp_defs.h
  5. 4 0
      config.h
  6. 6 4
      data_lump.h
  7. 67 1
      fifo_server.c
  8. 4 0
      fifo_server.h
  9. 4 0
      globals.h
  10. 6 0
      main.c
  11. 8 0
      modules/tm/sip_msg.c
  12. 26 6
      modules/tm/t_lookup.c
  13. 6 1
      modules/tm/uac.c
  14. 124 9
      msg_translator.c
  15. 56 20
      parser/msg_parser.c
  16. 6 1
      parser/msg_parser.h
  17. 19 6
      parser/parse_fline.c
  18. 1 0
      parser/parse_fline.h
  19. 3 0
      parser/parse_hostport.c
  20. 2 2
      parser/parse_uri.c
  21. 65 63
      parser/parse_via.c
  22. 10 0
      receive.c
  23. 83 0
      route.c
  24. 5 0
      route_struct.c
  25. 2 1
      route_struct.h
  26. 6 1
      tcp_conn.h
  27. 5 1
      udp_server.c
  28. 23 1
      ut.h

+ 13 - 1
action.c

@@ -23,10 +23,14 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * ---------
+ * 2003-01-29 removed scratchpad (jiri)
  */
  */
 
 
 
 
-
+#include "comp_defs.h"
 
 
 #include "action.h"
 #include "action.h"
 #include "config.h"
 #include "config.h"
@@ -180,7 +184,11 @@ int do_action(struct action* a, struct sip_msg* msg)
 					/*udp*/
 					/*udp*/
 					send_sock=get_send_socket(to, PROTO_UDP);
 					send_sock=get_send_socket(to, PROTO_UDP);
 					if (send_sock!=0){
 					if (send_sock!=0){
+#ifdef SCRATCH
 						ret=udp_send(send_sock, msg->orig, msg->len, to);
 						ret=udp_send(send_sock, msg->orig, msg->len, to);
+#else
+						ret=udp_send(send_sock, msg->buf, msg->len, to);
+#endif
 					}else{
 					}else{
 						ret=-1;
 						ret=-1;
 					}
 					}
@@ -188,7 +196,11 @@ int do_action(struct action* a, struct sip_msg* msg)
 #ifdef USE_TCP
 #ifdef USE_TCP
 					else{
 					else{
 					/*tcp*/
 					/*tcp*/
+#ifdef SCRATCH
 					ret=tcp_send(msg->orig, msg->len, to, 0);
 					ret=tcp_send(msg->orig, msg->len, to, 0);
+#else
+					ret=tcp_send(msg->buf, msg->len, to, 0);
+#endif
 				}
 				}
 #endif
 #endif
 			}
 			}

+ 3 - 0
cfg.lex

@@ -28,6 +28,7 @@
  *
  *
  * History:
  * History:
  * -------
  * -------
+ * 2001-01-29 src_port added (jiri)
  * 2001-01-23 mhomed added (jiri)
  * 2001-01-23 mhomed added (jiri)
  */
  */
 
 
@@ -106,6 +107,7 @@ MAX_LEN			"max_len"
 METHOD	method
 METHOD	method
 URI		uri
 URI		uri
 SRCIP	src_ip
 SRCIP	src_ip
+SRCPORT	src_port
 DSTIP	dst_ip
 DSTIP	dst_ip
 MYSELF	myself
 MYSELF	myself
 /* operators */
 /* operators */
@@ -218,6 +220,7 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
+<INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
 
 

+ 6 - 0
cfg.y

@@ -28,6 +28,7 @@
  *
  *
  * History:
  * History:
  * ---------
  * ---------
+ * 2003-01-29 src_port added (jiri)
  * 2003-01-23 mhomed added (jiri)
  * 2003-01-23 mhomed added (jiri)
  */
  */
 
 
@@ -123,6 +124,7 @@ struct id_list* lst_tmp;
 %token METHOD
 %token METHOD
 %token URI
 %token URI
 %token SRCIP
 %token SRCIP
+%token SRCPORT
 %token DSTIP
 %token DSTIP
 %token MYSELF
 %token MYSELF
 
 
@@ -524,6 +526,10 @@ exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST,
 		| URI error	{ $$=0; yyerror("invalid operator,"
 		| URI error	{ $$=0; yyerror("invalid operator,"
 				  					" == or =~ expected");
 				  					" == or =~ expected");
 					}
 					}
+		| SRCPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
+												SRCPORT_O, (void *) $3 ); }
+		| SRCPORT EQUAL_T error { $$=0; yyerror("number expected"); }
+		| SRCPORT error { $$=0; yyerror("equation operator expected"); }
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
 												SRCIP_O, $3);
 												SRCIP_O, $3);
 								}
 								}

+ 22 - 1
comp_defs.h

@@ -25,7 +25,13 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
 
 
-/* compatibility defs for emergency roll-back if things do not work */
+/* compatibility defs for emergency roll-back if things do not work ;
+ * if that happens:
+ * a) define PRESERVE_ZT (affects most of parser)
+ * b) define DONT_REMOVE_ZT (affects first line)
+ * c) define SCRATCH
+ * d) undefine REMOVE_ALL_ZT (affects via)
+ */
 
 
 
 
 #ifndef _COMP_DEFS_H
 #ifndef _COMP_DEFS_H
@@ -37,6 +43,15 @@
  */
  */
 #undef PRESERVE_ZT
 #undef PRESERVE_ZT
 
 
+/* go one step further and remove ZT from first line too */
+#undef DONT_REMOVE_ZT
+
+/* make it all -- move ZT away (Via) */
+#define REMOVE_ALL_ZT
+
+/* don't use scratchpad  anymore */
+#undef SCRATCH
+
 
 
 /* ------------------------------------------------------ */
 /* ------------------------------------------------------ */
 /* don't touch this -- that's helper macros depending on
 /* don't touch this -- that's helper macros depending on
@@ -47,4 +62,10 @@
 #	define SET_ZT(_ch)
 #	define SET_ZT(_ch)
 #endif
 #endif
 
 
+#ifdef REMOVE_ALL_ZT
+#	define VIA_ZT(_ch)
+#else
+#	define VIA_ZT(ch) (_ch)='\0'
+#endif
+
 #endif
 #endif

+ 4 - 0
config.h

@@ -159,4 +159,8 @@
 #define MAX_BRANCH_PARAM_LEN  (MCOOKIE_LEN+48)
 #define MAX_BRANCH_PARAM_LEN  (MCOOKIE_LEN+48)
 
 
 
 
+/* maximum path length */
+#define PATH_MAX_GUESS	1024
+
+
 #endif
 #endif

+ 6 - 4
data_lump.h

@@ -25,6 +25,8 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * 2003-01-29 s/int/enum ... more convenient for gdb (jiri)
  */
  */
 
 
 
 
@@ -32,12 +34,12 @@
 #define data_lump_h
 #define data_lump_h
 
 
 
 
-enum { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
-enum { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
+enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
+enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
 
 
 struct lump{
 struct lump{
 	int type; /* VIA, OTHER, UNSPEC(=0), ... */
 	int type; /* VIA, OTHER, UNSPEC(=0), ... */
-	int op;   /* DEL, ADD, NOP, UNSPEC(=0) */
+	enum lump_op op;   /* DEL, ADD, NOP, UNSPEC(=0) */
 	
 	
 	union{
 	union{
 		int offset; /* used for DEL, MODIFY */
 		int offset; /* used for DEL, MODIFY */
@@ -53,7 +55,7 @@ struct lump{
 	
 	
 	struct lump* next;
 	struct lump* next;
 
 
-	int flags; /* additional hints for use from TM's shmem */
+	enum lump_flag flags; /* additional hints for use from TM's shmem */
 };
 };
 
 
 /*
 /*

+ 67 - 1
fifo_server.c

@@ -50,9 +50,14 @@
  *
  *
  * File test/transaction.fifo illustrates example of use
  * File test/transaction.fifo illustrates example of use
  * of t_uac command (part of TM module).
  * of t_uac command (part of TM module).
+ *
+ * History:
+ * --------
+ * 2003-01-29 new built-in fifo commands: arg and pwd (jiri)
  */
  */
 
 
 
 
+#include <limits.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <unistd.h>
@@ -574,10 +579,63 @@ static int print_version_cmd( FILE *stream, char *response_file )
 	if (response_file) {
 	if (response_file) {
 		fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
 		fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
 	} else {
 	} else {
-		LOG(L_ERR, "ERROR: no file for print_version_cmd\n");
+		LOG(L_ERR, "ERROR: no file for %s\n", "print_version_cmd" );
+	}
+	return 1;
+}
+
+static int pwd_cmd( FILE *stream, char *response_file )
+{
+	char *cwd_buf;
+	int max_len;
+
+	if (!response_file) {
+		LOG(L_ERR, "ERROR: no file for %s\n", "pwd_cmd" );
+		return 1;
+	}
+
+	max_len=pathmax();
+	cwd_buf=pkg_malloc(max_len);
+	if (!cwd_buf) {
+		LOG(L_ERR, "ERROR: pwd_cmd: no cwd pkg mem\n");
+		fifo_reply(response_file, "500 no memory\n");
+		return 1;
+	}
+
+	if (getcwd(cwd_buf, max_len)) {
+		fifo_reply(response_file, "200 ok\n%s\n", cwd_buf );
+	} else {
+		fifo_reply(response_file, "500 getcwd failed\n" );
+	}
+
+	pkg_free(cwd_buf);
+	return 1;
+}
+
+static int arg_cmd( FILE *stream, char *response_file )
+{
+	FILE *reply_pipe;
+	int p;
+
+	if (response_file==0 || *response_file==0 ) {
+		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
+		return -1;
+	}
+	reply_pipe=open_reply_pipe(response_file);
+	if (reply_pipe==NULL) {
+		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
+			response_file );
+		return -1;
 	}
 	}
+
+	fputs( "200 ok\n", reply_pipe);
+	for (p=0; p<my_argc;p++) 
+			fprintf( reply_pipe, "%s\n", my_argv[p] );
+			
+	fclose(reply_pipe);
 	return 1;
 	return 1;
 }
 }
+
 	
 	
 
 
 /* diagnostic and hello-world FIFO command */
 /* diagnostic and hello-world FIFO command */
@@ -688,6 +746,14 @@ int register_core_fifo()
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_VERSION);
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_VERSION);
 		return -1;
 		return -1;
 	}
 	}
+	if (register_fifo_cmd(pwd_cmd, FIFO_PWD, 0)<0) {
+		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PWD);
+		return -1;
+	}
+	if (register_fifo_cmd(arg_cmd, FIFO_ARG, 0)<0) {
+		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_ARG);
+		return -1;
+	}
 	if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) {
 	if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) {
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_WHICH);
 		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_WHICH);
 		return -1;
 		return -1;

+ 4 - 0
fifo_server.h

@@ -45,6 +45,10 @@
 #define FIFO_WHICH "which"
 #define FIFO_WHICH "which"
 /* print server's process table */
 /* print server's process table */
 #define FIFO_PS "ps"
 #define FIFO_PS "ps"
+/* print server's command line arguments */
+#define FIFO_ARG "arg"
+/* print server's working directory */
+#define FIFO_PWD "pwd"
 
 
 #define MAX_CTIME_LEN 128
 #define MAX_CTIME_LEN 128
 
 

+ 4 - 0
globals.h

@@ -116,4 +116,8 @@ extern int memlog;
 /* looking up outbound interface ? */
 /* looking up outbound interface ? */
 extern int mhomed;
 extern int mhomed;
 
 
+/* command-line arguments */
+extern int my_argc;
+extern char **my_argv;
+
 #endif
 #endif

+ 6 - 0
main.c

@@ -26,6 +26,7 @@
  *
  *
  * History:
  * History:
  * -------
  * -------
+ * 2002-01-29 argc/argv globalized via my_{argc|argv} (jiri)
  * 2001-01-23 mhomed added (jiri)
  * 2001-01-23 mhomed added (jiri)
  *
  *
  */
  */
@@ -323,6 +324,10 @@ int cfg_errors=0;
 /* shared memory (in MB) */
 /* shared memory (in MB) */
 unsigned int shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
 unsigned int shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
 
 
+/* export command-line to anywhere else */
+int my_argc;
+char **my_argv;
+
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
 		    (normally it shouldn't  be bigger  than 3) */
 		    (normally it shouldn't  be bigger  than 3) */
 
 
@@ -1059,6 +1064,7 @@ int main(int argc, char** argv)
 	/*init*/
 	/*init*/
 	port_no_str_len=0;
 	port_no_str_len=0;
 	ret=-1;
 	ret=-1;
+	my_argc=argc; my_argv=argv;
 	
 	
 	/* added by jku: add exit handler */
 	/* added by jku: add exit handler */
 	if (signal(SIGINT, sig_usr) == SIG_ERR ) {
 	if (signal(SIGINT, sig_usr) == SIG_ERR ) {

+ 8 - 0
modules/tm/sip_msg.c

@@ -37,6 +37,7 @@
  *
  *
  * History:
  * History:
  * --------
  * --------
+ * 2003-01-29 - scratchpad removed (jiri)
  * 2003-01-23 - msg_cloner clones msg->from->parsed too (janakj)
  * 2003-01-23 - msg_cloner clones msg->from->parsed too (janakj)
  */
  */
 
 
@@ -276,10 +277,17 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
 		p += ROUND4(org_msg->new_uri.len);
 		p += ROUND4(org_msg->new_uri.len);
 	}
 	}
 	/* message buffers(org and scratch pad) */
 	/* message buffers(org and scratch pad) */
+#ifdef SCRATCH
 	memcpy( p , org_msg->orig , org_msg->len);
 	memcpy( p , org_msg->orig , org_msg->len);
 	/* ZT to be safer */
 	/* ZT to be safer */
 	*(p+org_msg->len)=0;
 	*(p+org_msg->len)=0;
 	new_msg->orig = new_msg->buf = p;
 	new_msg->orig = new_msg->buf = p;
+#else
+	memcpy( p , org_msg->buf, org_msg->len);
+	/* ZT to be safer */
+	*(p+org_msg->len)=0;
+	new_msg->buf = p;
+#endif
 	p += ROUND4(new_msg->len+1);
 	p += ROUND4(new_msg->len+1);
 	/* unparsed and eoh pointer */
 	/* unparsed and eoh pointer */
 	new_msg->unparsed = translate_pointer(new_msg->buf ,org_msg->buf,
 	new_msg->unparsed = translate_pointer(new_msg->buf ,org_msg->buf,

+ 26 - 6
modules/tm/t_lookup.c

@@ -51,6 +51,7 @@
  *
  *
  * History:
  * History:
  * ----------
  * ----------
+ * 2003-01-28 scratchpad removed (jiri)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  * 2003-01-23 options for disabling r-uri matching introduced (jiri)
  * 2003-01-23 options for disabling r-uri matching introduced (jiri)
  */
  */
@@ -75,26 +76,45 @@
 #include "t_hooks.h"
 #include "t_hooks.h"
 #include "t_lookup.h"
 #include "t_lookup.h"
 
 
+#define EQ_VIA_LEN(_via)\
+	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
+	  	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
+
+
 
 
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
+#define EQ_REQ_URI_LEN\
+	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
+
+#ifdef SCRATCH
 #define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
 #define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->_hf->body.s), \
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->_hf->body.s), \
 	p_msg->_hf->body.len)==0)
 	p_msg->_hf->body.len)==0)
-#define EQ_REQ_URI_LEN\
-	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
 #define EQ_REQ_URI_STR\
 #define EQ_REQ_URI_STR\
 	( memcmp( t_msg->first_line.u.request.uri.s,\
 	( memcmp( t_msg->first_line.u.request.uri.s,\
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->first_line.u.request.uri.s),\
 	translate_pointer(p_msg->orig,p_msg->buf,p_msg->first_line.u.request.uri.s),\
 	p_msg->first_line.u.request.uri.len)==0)
 	p_msg->first_line.u.request.uri.len)==0)
-#define EQ_VIA_LEN(_via)\
-	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
-	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
-
 #define EQ_VIA_STR(_via)\
 #define EQ_VIA_STR(_via)\
 	( memcmp( t_msg->_via->name.s,\
 	( memcmp( t_msg->_via->name.s,\
 	 translate_pointer(p_msg->orig,p_msg->buf,p_msg->_via->name.s),\
 	 translate_pointer(p_msg->orig,p_msg->buf,p_msg->_via->name.s),\
 	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
 	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
 	)==0 )
 	)==0 )
+#else /* SCRATCH */
+#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
+	p_msg->_hf->body.s, \
+	p_msg->_hf->body.len)==0)
+#define EQ_REQ_URI_STR\
+	( memcmp( t_msg->first_line.u.request.uri.s,\
+	p_msg->first_line.u.request.uri.s,\
+	p_msg->first_line.u.request.uri.len)==0)
+#define EQ_VIA_STR(_via)\
+	( memcmp( t_msg->_via->name.s,\
+	 p_msg->_via->name.s,\
+	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
+	)==0 )
+#endif /* SCRATCH */
+
+
 
 
 #ifdef PRESERVE_ZT
 #ifdef PRESERVE_ZT
 #define HF_LEN(_hf) ((_hf)->body.s+(_hf)->body.len-(_hf)->name.s)
 #define HF_LEN(_hf) ((_hf)->body.s+(_hf)->body.len-(_hf)->name.s)

+ 6 - 1
modules/tm/uac.c

@@ -44,11 +44,13 @@
  *
  *
  * History:
  * History:
  * --------
  * --------
+ * 2003-01-29 scratchpad removed (jiri)
  * 2003-01-27 fifo:t_uac_dlg completed (jiri)
  * 2003-01-27 fifo:t_uac_dlg completed (jiri)
  * 2003-01-23 t_uac_dlg now uses get_out_socket (jiri)
  * 2003-01-23 t_uac_dlg now uses get_out_socket (jiri)
  */
  */
 
 
 
 
+#include "../../comp_defs.h"
 #include "defs.h"
 #include "defs.h"
 
 
 
 
@@ -1051,7 +1053,10 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
 	/* use SIP parser to look at what is in the FIFO request */
 	/* use SIP parser to look at what is in the FIFO request */
 	memset(&faked_msg, 0, sizeof(struct sip_msg));
 	memset(&faked_msg, 0, sizeof(struct sip_msg));
 	faked_msg.len=header.len; 
 	faked_msg.len=header.len; 
-	faked_msg.buf=faked_msg.orig=faked_msg.unparsed=header_buf;
+	faked_msg.buf=faked_msg.unparsed=header_buf;
+#ifdef SCRATCH
+	faked_msg.orig=faked_msg.buf;
+#endif
 	if (parse_headers(&faked_msg, HDR_EOH, 0)==-1 ) {
 	if (parse_headers(&faked_msg, HDR_EOH, 0)==-1 ) {
 			DBG("DEBUG: fifo_uac: parse_headers failed\n");
 			DBG("DEBUG: fifo_uac: parse_headers failed\n");
 			fifo_uac_error(response_file, 400, "HFs unparseable");
 			fifo_uac_error(response_file, 400, "HFs unparseable");

+ 124 - 9
msg_translator.c

@@ -36,6 +36,7 @@
  *             modified via_builder params (andrei)
  *             modified via_builder params (andrei)
  * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
  * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
+ * 2003-01-29 scrathcpad removed (jiri)
  *
  *
  */
  */
 
 
@@ -69,19 +70,25 @@
 		(_dest) += (_len) ;\
 		(_dest) += (_len) ;\
 	}while(0);
 	}while(0);
 
 
+#ifdef SCRATCH
 #define append_str_trans(_dest,_src,_len,_msg) \
 #define append_str_trans(_dest,_src,_len,_msg) \
 	append_str( (_dest), (_msg)->orig+((_src)-(_msg)->buf) , (_len) );
 	append_str( (_dest), (_msg)->orig+((_src)-(_msg)->buf) , (_len) );
+#else
+#define append_str_trans(_dest,_src,_len,_msg) \
+	append_str( (_dest), (_src), (_len) );
+#endif
 
 
 extern char version[];
 extern char version[];
 extern int version_len;
 extern int version_len;
 
 
 
 
 
 
+#ifndef REMOVE_ALL_ZT
 /* checks if ip is in host(name) and ?host(ip)=name?
 /* checks if ip is in host(name) and ?host(ip)=name?
  * ip must be in network byte order!
  * ip must be in network byte order!
  *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
  *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
  * return 0 if equal */
  * return 0 if equal */
-int check_address(struct ip_addr* ip, char *name, int resolver)
+static int check_address(struct ip_addr* ip, char *name, int resolver)
 {
 {
 	struct hostent* he;
 	struct hostent* he;
 	int i;
 	int i;
@@ -90,19 +97,22 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
 	/* maybe we are lucky and name it's an ip */
 	/* maybe we are lucky and name it's an ip */
 	s=ip_addr2a(ip);
 	s=ip_addr2a(ip);
 	if (s){
 	if (s){
-		DBG("check_address(%s, %s, %d)\n", s, name, resolver);
+		DBG("check_address(%s, %.*s, %d)\n", 
+			s, name->len, name->s, resolver);
+
 	#ifdef USE_IPV6
 	#ifdef USE_IPV6
 		if ((ip->af==AF_INET6) && (strcasecmp(name, s)==0))
 		if ((ip->af==AF_INET6) && (strcasecmp(name, s)==0))
 				return 0;
 				return 0;
 		else
 		else
 	#endif
 	#endif
-			if (strcmp(name, s)==0)
+
+			if (strcmp(name, s)==0) 
 				return 0;
 				return 0;
 	}else{
 	}else{
 		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
 		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
 		return -1;
 		return -1;
 	}
 	}
-		
+
 	if (resolver&DO_DNS){
 	if (resolver&DO_DNS){
 		DBG("check_address: doing dns lookup\n");
 		DBG("check_address: doing dns lookup\n");
 		/* try all names ips */
 		/* try all names ips */
@@ -127,6 +137,65 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
 	}
 	}
 	return -1;
 	return -1;
 }
 }
+#endif
+
+
+
+/* checks if ip is in host(name) and ?host(ip)=name?
+ * ip must be in network byte order!
+ *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
+ * return 0 if equal */
+static int check_via_address(struct ip_addr* ip, str *name, 
+				unsigned short port, int resolver)
+{
+	struct hostent* he;
+	int i;
+	char* s;
+
+	/* maybe we are lucky and name it's an ip */
+	s=ip_addr2a(ip);
+	if (s){
+		DBG("check_address(%s, %.*s, %d)\n", 
+			s, name->len, name->s, resolver);
+
+	#ifdef USE_IPV6
+		if ((ip->af==AF_INET6) && (strncasecmp(name->s, s, name->len)==0))
+			return 0;
+		else
+	#endif
+
+			if (strncmp(name->s, s, name->len)==0) 
+				return 0;
+	}else{
+		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
+		return -1;
+	}
+
+	if (port==0) port=SIP_PORT;
+	if (resolver&DO_DNS){
+		DBG("check_address: doing dns lookup\n");
+		/* try all names ips */
+		he=sip_resolvehost(name, &port);
+		if (he && ip->af==he->h_addrtype){
+			for(i=0;he && he->h_addr_list[i];i++){
+				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)
+					return 0;
+			}
+		}
+	}
+	if (resolver&DO_REV_DNS){
+		DBG("check_address: doing rev. dns lookup\n");
+		/* try reverse dns */
+		he=rev_resolvehost(ip);
+		if (he && (strncmp(he->h_name, name->s, name->len)==0))
+			return 0;
+		for (i=0; he && he->h_aliases[i];i++){
+			if (strncmp(he->h_aliases[i],name->s, name->len)==0)
+				return 0;
+		}
+	}
+	return -1;
+}
 
 
 
 
 static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
 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,
 	char* received_buf;
 	char* received_buf;
 	char* rport_buf;
 	char* rport_buf;
 	char* new_buf;
 	char* new_buf;
+#ifdef SCRATCH
 	char* orig;
 	char* orig;
+#endif
 	char* buf;
 	char* buf;
+#ifndef REMOVE_ALL_ZT
 	char  backup;
 	char  backup;
+#endif
 	unsigned int offset, s_offset, size;
 	unsigned int offset, s_offset, size;
 	struct lump* anchor;
 	struct lump* anchor;
 	int r;
 	int r;
@@ -483,7 +556,9 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	extra_params.len=0;
 	extra_params.len=0;
 	extra_params.s=0;
 	extra_params.s=0;
 	uri_len=0;
 	uri_len=0;
+#ifdef SCRATCH
 	orig=msg->orig;
 	orig=msg->orig;
+#endif
 	buf=msg->buf;
 	buf=msg->buf;
 	len=msg->len;
 	len=msg->len;
 	received_len=0;
 	received_len=0;
@@ -515,10 +590,15 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 		goto error00;
 		goto error00;
 	}
 	}
 	/* check if received needs to be added */
 	/* check if received needs to be added */
+#ifdef REMOVE_ALL_ZT
+	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
+		msg->via1->port, received_dns);
+#else
 	backup = msg->via1->host.s[msg->via1->host.len];
 	backup = msg->via1->host.s[msg->via1->host.len];
 	msg->via1->host.s[msg->via1->host.len] = 0;
 	msg->via1->host.s[msg->via1->host.len] = 0;
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
 	msg->via1->host.s[msg->via1->host.len] = backup;
 	msg->via1->host.s[msg->via1->host.len] = backup;
+#endif
 	if (r!=0){
 	if (r!=0){
 		if ((received_buf=received_builder(msg,&received_len))==0){
 		if ((received_buf=received_builder(msg,&received_len))==0){
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
 			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,
 	if (msg->new_uri.s){
 	if (msg->new_uri.s){
 		/* copy message up to uri */
 		/* copy message up to uri */
 		size=msg->first_line.u.request.uri.s-buf;
 		size=msg->first_line.u.request.uri.s-buf;
+#ifdef SCRATCH
 		memcpy(new_buf, orig, size);
 		memcpy(new_buf, orig, size);
+#else
+		memcpy(new_buf, buf, size);
+#endif
 		offset+=size;
 		offset+=size;
 		s_offset+=size;
 		s_offset+=size;
 		/* add our uri */
 		/* add our uri */
@@ -600,10 +684,17 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 		s_offset+=msg->first_line.u.request.uri.len; /* skip original uri */
 		s_offset+=msg->first_line.u.request.uri.len; /* skip original uri */
 	}
 	}
 	new_buf[new_len]=0;
 	new_buf[new_len]=0;
+#ifdef SCRATCH
 	/* copy msg adding/removing lumps */
 	/* copy msg adding/removing lumps */
 	process_lumps(msg->add_rm, new_buf, &offset, orig, &s_offset);
 	process_lumps(msg->add_rm, new_buf, &offset, orig, &s_offset);
 	/* copy the rest of the message */
 	/* copy the rest of the message */
 	memcpy(new_buf+offset, orig+s_offset, len-s_offset);
 	memcpy(new_buf+offset, orig+s_offset, len-s_offset);
+#else
+	/* copy msg adding/removing lumps */
+	process_lumps(msg->add_rm, new_buf, &offset, buf, &s_offset);
+	/* copy the rest of the message */
+	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
+#endif
 	new_buf[new_len]=0;
 	new_buf[new_len]=0;
 
 
 #ifdef DBG_MSG_QA
 #ifdef DBG_MSG_QA
@@ -637,11 +728,15 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
 	unsigned int new_len, via_len;
 	unsigned int new_len, via_len;
 	char* new_buf;
 	char* new_buf;
 	unsigned offset, s_offset, via_offset;
 	unsigned offset, s_offset, via_offset;
+#ifdef SCRATCH
 	char* orig;
 	char* orig;
+#endif
 	char* buf;
 	char* buf;
 	unsigned int len;
 	unsigned int len;
 
 
+#ifdef SCRATCH
 	orig=msg->orig;
 	orig=msg->orig;
+#endif
 	buf=msg->buf;
 	buf=msg->buf;
 	len=msg->len;
 	len=msg->len;
 	new_buf=0;
 	new_buf=0;
@@ -685,9 +780,21 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
 	}
 	}
 	new_buf[new_len]=0; /* debug: print the message */
 	new_buf[new_len]=0; /* debug: print the message */
 	offset=s_offset=0;
 	offset=s_offset=0;
-	process_lumps(msg->repl_add_rm, new_buf, &offset, orig, &s_offset);
+	process_lumps(msg->repl_add_rm, new_buf, &offset, 
+#ifdef SCRATCH
+		orig, 
+#else
+		buf,
+#endif
+		&s_offset);
 	/* copy the rest of the message */
 	/* copy the rest of the message */
-	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
+	memcpy(new_buf+offset,
+#ifdef SCRATCH
+		orig+s_offset, 
+#else
+		buf+s_offset, 
+#endif
+		len-s_offset);
 	 /* send it! */
 	 /* send it! */
 	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
 	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
 			s_offset, offset,
 			s_offset, offset,
@@ -721,6 +828,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 	unsigned int      delete_len;
 	unsigned int      delete_len;
 	char              *warning;
 	char              *warning;
 	unsigned int      warning_len;
 	unsigned int      warning_len;
+	unsigned int	  text_len;
 	int r;
 	int r;
 #ifndef PRESERVE_ZT
 #ifndef PRESERVE_ZT
 	char *after_body;
 	char *after_body;
@@ -736,6 +844,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 	/* make -Wall happy */
 	/* make -Wall happy */
 	warning=0;
 	warning=0;
 
 
+	text_len=strlen(text);
+
 	/* force parsing all headers -- we want to return all
 	/* force parsing all headers -- we want to return all
 	Via's in the reply and they may be scattered down to the
 	Via's in the reply and they may be scattered down to the
 	end of header (non-block Vias are a really poor property
 	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,
 	/* check if received needs to be added */
 	/* check if received needs to be added */
 	backup = msg->via1->host.s[msg->via1->host.len];
 	backup = msg->via1->host.s[msg->via1->host.len];
 	msg->via1->host.s[msg->via1->host.len] = 0;
 	msg->via1->host.s[msg->via1->host.len] = 0;
+#ifdef REMOVE_ALL_ZT
+	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
+		msg->via1->port, received_dns);
+#else
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
+#endif
 	msg->via1->host.s[msg->via1->host.len] = backup;
 	msg->via1->host.s[msg->via1->host.len] = backup;
 	if (r!=0) {
 	if (r!=0) {
 		if ((received_buf=received_builder(msg,&received_len))==0) {
 		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,
 	len = 0;
 	len = 0;
 	/* first line */
 	/* first line */
 	len += SIP_VERSION_LEN + 1/*space*/ + 3/*code*/ + 1/*space*/ +
 	len += SIP_VERSION_LEN + 1/*space*/ + 3/*code*/ + 1/*space*/ +
-		strlen(text) + CRLF_LEN/*new line*/;
+		text_len + CRLF_LEN/*new line*/;
 	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
 	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next ) {
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next ) {
 		if (hdr->type==HDR_TO) {
 		if (hdr->type==HDR_TO) {
@@ -843,8 +958,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 		*(p+i) = '0' + foo - ( foo/10 )*10;
 		*(p+i) = '0' + foo - ( foo/10 )*10;
 	p += 3;
 	p += 3;
 	*(p++) = ' ' ;
 	*(p++) = ' ' ;
-	memcpy( p , text , strlen(text) );
-	p += strlen(text);
+	memcpy( p , text , text_len );
+	p += text_len;
 	memcpy( p, CRLF, CRLF_LEN );
 	memcpy( p, CRLF, CRLF_LEN );
 	p+=CRLF_LEN;
 	p+=CRLF_LEN;
 	/* headers*/
 	/* headers*/

+ 56 - 20
parser/msg_parser.c

@@ -29,6 +29,7 @@
  *
  *
  * History:
  * History:
  * ---------
  * ---------
+ * 2003-01-29 scrathcpad removed (jiri)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  */
  */
 
 
@@ -404,8 +405,10 @@ int parse_headers(struct sip_msg* msg, int flags, int next)
 			msg->last_header=hf;
 			msg->last_header=hf;
 		}
 		}
 #ifdef EXTRA_DEBUG
 #ifdef EXTRA_DEBUG
-		DBG("header field type %d, name=<%s>, body=<%s>\n",
-			hf->type, hf->name.s, hf->body.s);
+		DBG("header field type %d, name=<%.*s>, body=<%.*s>\n",
+			hf->type, 
+			hf->name.len, hf->name.s, 
+			hf->body.len, hf->body.s);
 #endif
 #endif
 		tmp=rest;
 		tmp=rest;
 	}
 	}
@@ -454,16 +457,22 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 			break;
 			break;
 		case SIP_REQUEST:
 		case SIP_REQUEST:
 			DBG("SIP Request:\n");
 			DBG("SIP Request:\n");
-			DBG(" method:  <%s>\n",fl->u.request.method.s);
-			DBG(" uri:     <%s>\n",fl->u.request.uri.s);
-			DBG(" version: <%s>\n",fl->u.request.version.s);
+			DBG(" method:  <%.*s>\n",fl->u.request.method.len,
+				fl->u.request.method.s);
+			DBG(" uri:     <%.*s>\n",fl->u.request.uri.len,
+				fl->u.request.uri.s);
+			DBG(" version: <%.*s>\n",fl->u.request.version.len,
+				fl->u.request.version.s);
 			flags=HDR_VIA;
 			flags=HDR_VIA;
 			break;
 			break;
 		case SIP_REPLY:
 		case SIP_REPLY:
 			DBG("SIP Reply  (status):\n");
 			DBG("SIP Reply  (status):\n");
-			DBG(" version: <%s>\n",fl->u.reply.version.s);
-			DBG(" status:  <%s>\n",fl->u.reply.status.s);
-			DBG(" reason:  <%s>\n",fl->u.reply.reason.s);
+			DBG(" version: <%.*s>\n",fl->u.reply.version.len,
+					fl->u.reply.version.s);
+			DBG(" status:  <%.*s>\n", fl->u.reply.status.len,
+					fl->u.reply.status.s);
+			DBG(" reason:  <%.*s>\n", fl->u.reply.reason.len,
+					fl->u.reply.reason.s);
 			/* flags=HDR_VIA | HDR_VIA2; */
 			/* flags=HDR_VIA | HDR_VIA2; */
 			/* we don't try to parse VIA2 for local messages; -Jiri */
 			/* we don't try to parse VIA2 for local messages; -Jiri */
 			flags=HDR_VIA;
 			flags=HDR_VIA;
@@ -481,21 +490,42 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 #ifdef EXTRA_DEBUG
 #ifdef EXTRA_DEBUG
 	/* dump parsed data */
 	/* dump parsed data */
 	if (msg->via1){
 	if (msg->via1){
-		DBG(" first  via: <%s/%s/%s> <%s:%s(%d)>",
-			msg->via1->name.s, msg->via1->version.s,
-			msg->via1->transport.s, msg->via1->host.s,
-			msg->via1->port_str.s, msg->via1->port);
-		if (msg->via1->params.s)  DBG(";<%s>", msg->via1->params.s);
-		if (msg->via1->comment.s) DBG(" <%s>", msg->via1->comment.s);
+		DBG(" first  via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
+			msg->via1->name.len, 
+			msg->via1->name.s, 
+			msg->via1->version.len,
+			msg->via1->version.s,
+			msg->via1->transport.len 
+			msg->via1->transport.s, 
+			msg->via1->host.len,
+			msg->via1->host.s,
+			msg->via1->port_str.len, 
+			msg->via1->port_str.s, 
+			msg->via1->port);
+		if (msg->via1->params.s)  DBG(";<%.*s>", 
+				msg->via1->params.len, msg->via1->params.s);
+		if (msg->via1->comment.s) 
+				DBG(" <%.*s>", 
+					msg->via1->comment.len, msg->via1->comment.s);
 		DBG ("\n");
 		DBG ("\n");
 	}
 	}
 	if (msg->via2){
 	if (msg->via2){
-		DBG(" first  via: <%s/%s/%s> <%s:%s(%d)>",
-			msg->via2->name.s, msg->via2->version.s,
-			msg->via2->transport.s, msg->via2->host.s,
-			msg->via2->port_str.s, msg->via2->port);
-		if (msg->via2->params.s)  DBG(";<%s>", msg->via2->params.s);
-		if (msg->via2->comment.s) DBG(" <%s>", msg->via2->comment.s);
+		DBG(" first  via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
+			msg->via2->name.len, 
+			msg->via2->name.s, 
+			msg->via2->version.len,
+			msg->via2->version.s,
+			msg->via2->transport.len, 
+			msg->via2->transport.s, 
+			msg->via2->host.len,
+			msg->via2->host.s,
+			msg->via2->port_str.len, 
+			msg->via2->port_str.s, 
+			msg->via2->port);
+		if (msg->via2->params.s)  DBG(";<%.*s>", 
+				msg->via2->params.len, msg->via2->params.s);
+		if (msg->via2->comment.s) DBG(" <%.*s>", 
+				msg->via2->comment.len, msg->via2->comment.s);
 		DBG ("\n");
 		DBG ("\n");
 	}
 	}
 #endif
 #endif
@@ -509,7 +539,11 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 	
 	
 error:
 error:
 	/* more debugging, msg->orig is/should be null terminated*/
 	/* more debugging, msg->orig is/should be null terminated*/
+#ifdef SCRATCH
 	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->orig);
 	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->orig);
+#else
+	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->buf);
+#endif
 	return -1;
 	return -1;
 }
 }
 
 
@@ -535,7 +569,9 @@ void free_sip_msg(struct sip_msg* msg)
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
+#ifdef SCRATCH
 	pkg_free(msg->orig);
 	pkg_free(msg->orig);
+#endif
 	/* don't free anymore -- now a pointer to a static buffer */
 	/* don't free anymore -- now a pointer to a static buffer */
 #	ifdef DYN_BUF
 #	ifdef DYN_BUF
 	pkg_free(msg->buf); 
 	pkg_free(msg->buf); 

+ 6 - 1
parser/msg_parser.h

@@ -23,12 +23,15 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * 2003-01-28 removed scratchpad (jiri)
  */
  */
 
 
 
 
 #ifndef msg_parser_h
 #ifndef msg_parser_h
 #define msg_parser_h
 #define msg_parser_h
 
 
+#include "../comp_defs.h"
 #include "../str.h"
 #include "../str.h"
 #include "../data_lump.h"
 #include "../data_lump.h"
 #include "../flags.h"
 #include "../flags.h"
@@ -119,8 +122,10 @@ struct sip_msg {
 	char* unparsed;   /* here we stopped parsing*/
 	char* unparsed;   /* here we stopped parsing*/
 	
 	
 	struct receive_info rcv; /* source & dest ip, ports, proto a.s.o*/
 	struct receive_info rcv; /* source & dest ip, ports, proto a.s.o*/
-	
+
+#ifdef SCRATCH	
 	char* orig;       /* original message copy */
 	char* orig;       /* original message copy */
+#endif
 	char* buf;        /* scratch pad, holds a modfied message,
 	char* buf;        /* scratch pad, holds a modfied message,
 					   *  via, etc. point into it */
 					   *  via, etc. point into it */
 	unsigned int len; /* message len (orig) */
 	unsigned int len; /* message len (orig) */

+ 19 - 6
parser/parse_fline.c

@@ -26,9 +26,14 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * ---------
+ * 2003-01-28: removed 0-terminators from first line (jiri)
  */
  */
 
 
 
 
+#include "../comp_defs.h"
 #include "../dprint.h"
 #include "../dprint.h"
 #include "msg_parser.h"
 #include "msg_parser.h"
 #include "parser_f.h"
 #include "parser_f.h"
@@ -56,7 +61,7 @@ enum { START,
 };
 };
 
 
 
 
-
+#ifdef _CURRENTLY_UNUSED
 char* parse_fline(char* buffer, char* end, struct msg_start* fl)
 char* parse_fline(char* buffer, char* end, struct msg_start* fl)
 {
 {
 	char* tmp;
 	char* tmp;
@@ -1120,6 +1125,7 @@ char* parse_fline(char* buffer, char* end, struct msg_start* fl)
 		}
 		}
 	}
 	}
 skip:
 skip:
+	fl->len=tmp-buf;
 	if (fl->type==SIP_REPLY){
 	if (fl->type==SIP_REPLY){
 		fl->u.reply.statuscode=stat;
 		fl->u.reply.statuscode=stat;
 		/* fl->u.reply.statusclass=stat/100; */
 		/* fl->u.reply.statusclass=stat/100; */
@@ -1132,7 +1138,7 @@ error:
 	return tmp;
 	return tmp;
 }
 }
 
 
-
+#endif /* currently unused */
 
 
 /* parses the first line, returns pointer to  next line  & fills fl;
 /* parses the first line, returns pointer to  next line  & fills fl;
    also  modifies buffer (to avoid extra copy ops) */
    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)
 	   tmp points at space after; go ahead */
 	   tmp points at space after; go ahead */
 
 
 	fl->u.request.method.s=buffer;  /* store ptr to first token */
 	fl->u.request.method.s=buffer;  /* store ptr to first token */
+#ifdef DONT_REMOVE_ZT
 	(*tmp)=0;			/* mark the 1st token end */
 	(*tmp)=0;			/* mark the 1st token end */
+#endif
 	second=tmp+1;			/* jump to second token */
 	second=tmp+1;			/* jump to second token */
 	offset=second-buffer;
 	offset=second-buffer;
 
 
@@ -1229,15 +1237,17 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 	if ((third==tmp)||(tmp>=end)){
 	if ((third==tmp)||(tmp>=end)){
 		goto error;
 		goto error;
 	}
 	}
+#ifdef DONT_REMOVE_ZT
 	*tmp=0; /* mark the end of the token */
 	*tmp=0; /* mark the end of the token */
+#endif
 	fl->u.request.uri.s=second;
 	fl->u.request.uri.s=second;
 	fl->u.request.uri.len=tmp-second;
 	fl->u.request.uri.len=tmp-second;
 
 
 	/* jku: parse status code */
 	/* jku: parse status code */
 	if (fl->type==SIP_REPLY) {
 	if (fl->type==SIP_REPLY) {
 		if (fl->u.request.uri.len!=3) {
 		if (fl->u.request.uri.len!=3) {
-			LOG(L_INFO, "ERROR:parse_first_line: len(status code)!=3: %s\n",
-				second );
+			LOG(L_INFO, "ERROR:parse_first_line: len(status code)!=3: %.*s\n",
+				fl->u.request.uri.len, second );
 			goto error;
 			goto error;
 		}
 		}
 		s1=*second; s2=*(second+1);s3=*(second+2);
 		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)
 		    s3>='0' && s3<='9' ) {
 		    s3>='0' && s3<='9' ) {
 			fl->u.reply.statuscode=(s1-'0')*100+10*(s2-'0')+(s3-'0');
 			fl->u.reply.statuscode=(s1-'0')*100+10*(s2-'0')+(s3-'0');
 		} else {
 		} else {
-			LOG(L_INFO, "ERROR:parse_first_line: status_code non-numerical: %s\n",
-				second );
+			LOG(L_INFO, "ERROR:parse_first_line: status_code non-numerical: %.*s\n",
+				fl->u.request.uri.len, second );
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
@@ -1277,9 +1287,12 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 	if (nl>=end){ /* no crlf in packet or only 1 line > invalid */
 	if (nl>=end){ /* no crlf in packet or only 1 line > invalid */
 		goto error;
 		goto error;
 	}
 	}
+#ifdef DONT_REMOVE_ZT
 	*tmp=0;
 	*tmp=0;
+#endif
 	fl->u.request.version.s=third;
 	fl->u.request.version.s=third;
 	fl->u.request.version.len=tmp-third;
 	fl->u.request.version.len=tmp-third;
+	fl->len=nl-buffer;
 
 
 	return nl;
 	return nl;
 
 

+ 1 - 0
parser/parse_fline.h

@@ -55,6 +55,7 @@
 
 
 struct msg_start {
 struct msg_start {
 	int type;                         /* Type of the Message - Request/Response */
 	int type;                         /* Type of the Message - Request/Response */
+	int len; 						/* length including delimiter */
 	union {
 	union {
 		struct {
 		struct {
 			str method;       /* Method string */
 			str method;       /* Method string */

+ 3 - 0
parser/parse_hostport.c

@@ -25,6 +25,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
 
 
+#ifdef _OBSOLETED
 
 
 #include "parse_hostport.h"
 #include "parse_hostport.h"
 #include <string.h>    /* strlen */
 #include <string.h>    /* strlen */
@@ -54,3 +55,5 @@ char* parse_hostport(char* buf, str* host, short int* port)
 
 
 	return host->s;
 	return host->s;
 }
 }
+
+#endif

+ 2 - 2
parser/parse_uri.c

@@ -163,8 +163,8 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 	err=0;
 	err=0;
 	if (uri->port.s) uri->port_no=str2s(uri->port.s, uri->port.len, &err);
 	if (uri->port.s) uri->port_no=str2s(uri->port.s, uri->port.len, &err);
 	if (err){
 	if (err){
-		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %s\n",
-				uri->port.s);
+		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %.*s\n",
+				uri->port.len, uri->port.s);
 		ser_error=ret=E_BAD_URI;
 		ser_error=ret=E_BAD_URI;
 		return ret;
 		return ret;
 	}
 	}

+ 65 - 63
parser/parse_via.c

@@ -39,10 +39,12 @@
  *               by andrei
  *               by andrei
  *  2003-01-27  modified parse_via to set new via_param->start member and
  *  2003-01-27  modified parse_via to set new via_param->start member and
  *               via->params.s (andrei)
  *               via->params.s (andrei)
+ *  2003-01-28  zero-terminations replaced with VIA_ZT (jiri)
  */
  */
 
 
 
 
 
 
+#include "../comp_defs.h"
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 #include "../dprint.h"
 #include "../dprint.h"
@@ -127,7 +129,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 			case '\t':
 			case '\t':
 				switch(state){
 				switch(state){
 					case FIN_HIDDEN:
 					case FIN_HIDDEN:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=L_PARAM;
 						state=L_PARAM;
@@ -138,7 +140,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 					case FIN_RECEIVED:
 					case FIN_RECEIVED:
 					case FIN_RPORT:
 					case FIN_RPORT:
 					case FIN_I:
 					case FIN_I:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=L_VALUE;
 						state=L_VALUE;
@@ -152,7 +154,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						break;
 						break;
 					case GEN_PARAM:
 					case GEN_PARAM:
 					default:
 					default:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=GEN_PARAM;
 						param->type=GEN_PARAM;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=L_VALUE;
 						state=L_VALUE;
@@ -163,7 +165,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 			case '\n':
 			case '\n':
 				switch(state){
 				switch(state){
 					case FIN_HIDDEN:
 					case FIN_HIDDEN:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						param->size=tmp-param->start; 
 						param->size=tmp-param->start; 
@@ -176,7 +178,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 					case FIN_RECEIVED:
 					case FIN_RECEIVED:
 					case FIN_I:
 					case FIN_I:
 					case FIN_RPORT:
 					case FIN_RPORT:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						param->size=tmp-param->start; 
 						param->size=tmp-param->start; 
@@ -196,7 +198,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						break;
 						break;
 					case GEN_PARAM:
 					case GEN_PARAM:
 					default:
 					default:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=GEN_PARAM;
 						param->type=GEN_PARAM;
 						saved_state=L_VALUE;
 						saved_state=L_VALUE;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
@@ -208,7 +210,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 			case '\r':
 			case '\r':
 				switch(state){
 				switch(state){
 					case FIN_HIDDEN:
 					case FIN_HIDDEN:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						param->size=tmp-param->start; 
 						param->size=tmp-param->start; 
@@ -221,7 +223,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 					case FIN_RECEIVED:
 					case FIN_RECEIVED:
 					case FIN_I:
 					case FIN_I:
 					case FIN_RPORT:
 					case FIN_RPORT:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						param->size=tmp-param->start; 
 						param->size=tmp-param->start; 
@@ -238,7 +240,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						goto end_via;
 						goto end_via;
 					case GEN_PARAM:
 					case GEN_PARAM:
 					default:
 					default:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=GEN_PARAM;
 						param->type=GEN_PARAM;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						param->size=tmp-param->start; 
 						param->size=tmp-param->start; 
@@ -256,7 +258,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 					case FIN_RECEIVED:
 					case FIN_RECEIVED:
 					case FIN_RPORT:
 					case FIN_RPORT:
 					case FIN_I:
 					case FIN_I:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=F_VALUE;
 						state=F_VALUE;
@@ -273,7 +275,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						goto end_via;
 						goto end_via;
 					case GEN_PARAM:
 					case GEN_PARAM:
 					default:
 					default:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=GEN_PARAM;
 						param->type=GEN_PARAM;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=F_VALUE;
 						state=F_VALUE;
@@ -284,7 +286,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 				switch(state){
 				switch(state){
 					case FIN_HIDDEN:
 					case FIN_HIDDEN:
 					case FIN_RPORT: /* rport can appear w/o a value */
 					case FIN_RPORT: /* rport can appear w/o a value */
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=F_PARAM;
 						state=F_PARAM;
@@ -304,7 +306,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						goto end_via;
 						goto end_via;
 					case GEN_PARAM:
 					case GEN_PARAM:
 					default:
 					default:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=GEN_PARAM;
 						param->type=GEN_PARAM;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=F_PARAM;
 						state=F_PARAM;
@@ -315,7 +317,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 				switch(state){
 				switch(state){
 					case FIN_HIDDEN:
 					case FIN_HIDDEN:
 					case FIN_RPORT:
 					case FIN_RPORT:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=state;
 						param->type=state;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=F_VIA;
 						state=F_VIA;
@@ -336,7 +338,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						goto end_via;
 						goto end_via;
 					case GEN_PARAM:
 					case GEN_PARAM:
 					default:
 					default:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->type=GEN_PARAM;
 						param->type=GEN_PARAM;
 						param->name.len=tmp-param->name.s;
 						param->name.len=tmp-param->name.s;
 						state=F_VIA;
 						state=F_VIA;
@@ -719,7 +721,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 					case F_VALUE: /*eat space*/
 					case F_VALUE: /*eat space*/
 						break; 
 						break; 
 					case P_VALUE:
 					case P_VALUE:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						state=L_PARAM;
 						state=L_PARAM;
 						param->value.len=tmp-param->value.s;
 						param->value.len=tmp-param->value.s;
 						goto endofvalue;
 						goto endofvalue;
@@ -746,7 +748,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						state=F_LF;
 						state=F_LF;
 						break;
 						break;
 					case P_VALUE:
 					case P_VALUE:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						saved_state=L_PARAM;
 						saved_state=L_PARAM;
 						state=F_LF;
 						state=F_LF;
 						param->value.len=tmp-param->value.s;
 						param->value.len=tmp-param->value.s;
@@ -774,7 +776,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						state=F_CR;
 						state=F_CR;
 						break;
 						break;
 					case P_VALUE:
 					case P_VALUE:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->value.len=tmp-param->value.s;
 						param->value.len=tmp-param->value.s;
 						saved_state=L_PARAM;
 						saved_state=L_PARAM;
 						state=F_CR;
 						state=F_CR;
@@ -812,12 +814,12 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 			case ';':
 			case ';':
 				switch(state){
 				switch(state){
 					case P_VALUE:
 					case P_VALUE:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->value.len=tmp-param->value.s;
 						param->value.len=tmp-param->value.s;
 						state=F_PARAM;
 						state=F_PARAM;
 						goto endofvalue;
 						goto endofvalue;
 					case F_VALUE:
 					case F_VALUE:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->value.len=0;
 						param->value.len=0;
 						state=F_PARAM;
 						state=F_PARAM;
 						goto endofvalue;
 						goto endofvalue;
@@ -845,7 +847,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 			case ',':
 			case ',':
 				switch(state){
 				switch(state){
 					case P_VALUE:
 					case P_VALUE:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						param->value.len=tmp-param->value.s;
 						param->value.len=tmp-param->value.s;
 						state=F_VIA;
 						state=F_VIA;
 						goto endofvalue;
 						goto endofvalue;
@@ -876,7 +878,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 						param->value.s=tmp+1;
 						param->value.s=tmp+1;
 						break;
 						break;
 					case P_STRING:
 					case P_STRING:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						state=L_PARAM;
 						state=L_PARAM;
 						param->value.len=tmp-param->value.s;
 						param->value.len=tmp-param->value.s;
 						goto endofvalue;
 						goto endofvalue;
@@ -924,8 +926,8 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
 normal_exit:
 normal_exit:
 	*pstate=state;
 	*pstate=state;
 	*psaved_state=saved_state;
 	*psaved_state=saved_state;
-	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type,
-			param->name.s, param->value.s, state);
+	DBG("Found param type %d, <%.*s> = <%.*s>; state=%d\n", param->type,
+			param->name.len, param->name.s, param->value.len, param->value.s, state);
 	return tmp;
 	return tmp;
 	
 	
  end_via:
  end_via:
@@ -941,8 +943,8 @@ normal_exit:
 	}
 	}
 	*pstate=state;
 	*pstate=state;
 	*psaved_state=saved_state;
 	*psaved_state=saved_state;
-	DBG("Error on  param type %d, <%s>, state=%d, saved_state=%d\n",
-		param->type, param->name.s, state, saved_state);
+	DBG("Error on  param type %d, <%.*s>, state=%d, saved_state=%d\n",
+		param->type, param->name.len, param->name.s, state, saved_state);
 
 
  error:
  error:
 	LOG(L_ERR, "error: parse_via_param\n");
 	LOG(L_ERR, "error: parse_via_param\n");
@@ -982,24 +984,24 @@ parse_again:
 					case F_PROTO:
 					case F_PROTO:
 						break;
 						break;
 					case FIN_UDP:
 					case FIN_UDP:
-						*tmp=0;  /* finished proto parsing */
+						VIA_ZT(*tmp); /* finished proto parsing */
 						vb->transport.len=tmp-vb->transport.s;
 						vb->transport.len=tmp-vb->transport.s;
 						vb->proto=PROTO_UDP;
 						vb->proto=PROTO_UDP;
 						state=F_HOST; /* start looking for host*/
 						state=F_HOST; /* start looking for host*/
 						goto main_via;
 						goto main_via;
 					case FIN_TCP:
 					case FIN_TCP:
-						*tmp=0;  /* finished proto parsing */
+						VIA_ZT(*tmp); /* finished proto parsing */
 						vb->transport.len=tmp-vb->transport.s;
 						vb->transport.len=tmp-vb->transport.s;
 						vb->proto=PROTO_TCP;
 						vb->proto=PROTO_TCP;
 						state=F_HOST; /* start looking for host*/
 						state=F_HOST; /* start looking for host*/
 						goto main_via;
 						goto main_via;
 					case FIN_SIP:
 					case FIN_SIP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=L_VER;
 						state=L_VER;
 						break;
 						break;
 					case FIN_VER:
 					case FIN_VER:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->version.len=tmp-vb->version.s;
 						vb->version.len=tmp-vb->version.s;
 						state=L_PROTO;
 						state=L_PROTO;
 						break;
 						break;
@@ -1025,27 +1027,27 @@ parse_again:
 						state=F_LF;
 						state=F_LF;
 						break;
 						break;
 					case FIN_UDP:
 					case FIN_UDP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->transport.len=tmp-vb->transport.s;
 						vb->transport.len=tmp-vb->transport.s;
 						vb->proto=PROTO_UDP;
 						vb->proto=PROTO_UDP;
 						state=F_LF;
 						state=F_LF;
 						saved_state=F_HOST; /* start looking for host*/
 						saved_state=F_HOST; /* start looking for host*/
 						goto main_via;
 						goto main_via;
 					case FIN_TCP:
 					case FIN_TCP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->transport.len=tmp-vb->transport.s;
 						vb->transport.len=tmp-vb->transport.s;
 						vb->proto=PROTO_TCP;
 						vb->proto=PROTO_TCP;
 						state=F_LF;
 						state=F_LF;
 						saved_state=F_HOST; /* start looking for host*/
 						saved_state=F_HOST; /* start looking for host*/
 						goto main_via;
 						goto main_via;
 					case FIN_SIP:
 					case FIN_SIP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=F_LF;
 						state=F_LF;
 						saved_state=L_VER;
 						saved_state=L_VER;
 						break;
 						break;
 					case FIN_VER:
 					case FIN_VER:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->version.len=tmp-vb->version.s;
 						vb->version.len=tmp-vb->version.s;
 						state=F_LF;
 						state=F_LF;
 						saved_state=L_PROTO;
 						saved_state=L_PROTO;
@@ -1074,27 +1076,27 @@ parse_again:
 						state=F_CR;
 						state=F_CR;
 						break;
 						break;
 					case FIN_UDP:
 					case FIN_UDP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->transport.len=tmp-vb->transport.s;
 						vb->transport.len=tmp-vb->transport.s;
 						vb->proto=PROTO_UDP;
 						vb->proto=PROTO_UDP;
 						state=F_CR;
 						state=F_CR;
 						saved_state=F_HOST;
 						saved_state=F_HOST;
 						goto main_via;
 						goto main_via;
 					case FIN_TCP:
 					case FIN_TCP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->transport.len=tmp-vb->transport.s;
 						vb->transport.len=tmp-vb->transport.s;
 						vb->proto=PROTO_TCP;
 						vb->proto=PROTO_TCP;
 						state=F_CR;
 						state=F_CR;
 						saved_state=F_HOST;
 						saved_state=F_HOST;
 						goto main_via;
 						goto main_via;
 					case FIN_SIP:
 					case FIN_SIP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=F_CR;
 						state=F_CR;
 						saved_state=L_VER;
 						saved_state=L_VER;
 						break;
 						break;
 					case FIN_VER:
 					case FIN_VER:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->version.len=tmp-vb->version.s;
 						vb->version.len=tmp-vb->version.s;
 						state=F_CR;
 						state=F_CR;
 						saved_state=L_PROTO;
 						saved_state=L_PROTO;
@@ -1114,12 +1116,12 @@ parse_again:
 			case '/':
 			case '/':
 				switch(state){
 				switch(state){
 					case FIN_SIP:
 					case FIN_SIP:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->name.len=tmp-vb->name.s;
 						vb->name.len=tmp-vb->name.s;
 						state=F_VER;
 						state=F_VER;
 						break;
 						break;
 					case FIN_VER:
 					case FIN_VER:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->version.len=tmp-vb->version.s;
 						vb->version.len=tmp-vb->version.s;
 						state=F_PROTO;
 						state=F_PROTO;
 						break;
 						break;
@@ -1292,7 +1294,7 @@ parse_again:
 					case F_HOST:/*eat the spaces*/
 					case F_HOST:/*eat the spaces*/
 						break;
 						break;
 					case P_HOST:
 					case P_HOST:
-						 *tmp=0;/*mark end of host*/
+						 VIA_ZT(*tmp);/*mark end of host*/
 						 vb->host.len=tmp-vb->host.s;
 						 vb->host.len=tmp-vb->host.s;
 						 state=L_PORT;
 						 state=L_PORT;
 						 break;
 						 break;
@@ -1300,7 +1302,7 @@ parse_again:
 					case F_PORT:
 					case F_PORT:
 						break;
 						break;
 					case P_PORT:
 					case P_PORT:
-						*tmp=0; /*end of port */
+						VIA_ZT(*tmp); /*end of port */
 						vb->port_str.len=tmp-vb->port_str.s;
 						vb->port_str.len=tmp-vb->port_str.s;
 						state=L_PARAM;
 						state=L_PARAM;
 						break;
 						break;
@@ -1320,7 +1322,7 @@ parse_again:
 					case F_IP6HOST: /*eat the spaces*/
 					case F_IP6HOST: /*eat the spaces*/
 						break;
 						break;
 					case P_IP6HOST:
 					case P_IP6HOST:
-						*tmp=0; /*mark end of host*/
+						VIA_ZT(*tmp); /*mark end of host*/
 						vb->host.len=tmp-vb->host.s;
 						vb->host.len=tmp-vb->host.s;
 						state=L_PORT; 
 						state=L_PORT; 
 						break;
 						break;
@@ -1353,13 +1355,13 @@ parse_again:
 						state=F_LF;
 						state=F_LF;
 						break;
 						break;
 					case P_HOST:
 					case P_HOST:
-						 *tmp=0;/*mark end of host*/
+						 VIA_ZT(*tmp);/*mark end of host*/
 						 vb->host.len=tmp-vb->host.s;
 						 vb->host.len=tmp-vb->host.s;
 						 saved_state=L_PORT;
 						 saved_state=L_PORT;
 						 state=F_LF;
 						 state=F_LF;
 						 break;
 						 break;
 					case P_PORT:
 					case P_PORT:
-						*tmp=0; /*end of port */
+						VIA_ZT(*tmp); /*end of port */
 						vb->port_str.len=tmp-vb->port_str.s;
 						vb->port_str.len=tmp-vb->port_str.s;
 						saved_state=L_PARAM;
 						saved_state=L_PARAM;
 						state=F_LF;
 						state=F_LF;
@@ -1399,13 +1401,13 @@ parse_again:
 						state=F_CR;
 						state=F_CR;
 						break;
 						break;
 					case P_HOST:
 					case P_HOST:
-						 *tmp=0;/*mark end of host*/
+						 VIA_ZT(*tmp);/*mark end of host*/
 						 vb->host.len=tmp-vb->host.s;
 						 vb->host.len=tmp-vb->host.s;
 						 saved_state=L_PORT;
 						 saved_state=L_PORT;
 						 state=F_CR;
 						 state=F_CR;
 						 break;
 						 break;
 					case P_PORT:
 					case P_PORT:
-						*tmp=0; /*end of port */
+						VIA_ZT(*tmp); /*end of port */
 						vb->port_str.len=tmp-vb->port_str.s;
 						vb->port_str.len=tmp-vb->port_str.s;
 						saved_state=L_PARAM;
 						saved_state=L_PARAM;
 						state=F_CR;
 						state=F_CR;
@@ -1437,7 +1439,7 @@ parse_again:
 					case P_IP6HOST:
 					case P_IP6HOST:
 						break;
 						break;
 					case P_HOST:
 					case P_HOST:
-						*tmp=0; /*mark  end of host*/
+						VIA_ZT(*tmp); /*mark  end of host*/
 						vb->host.len=tmp-vb->host.s;
 						vb->host.len=tmp-vb->host.s;
 						state=F_PORT;
 						state=F_PORT;
 						break;
 						break;
@@ -1489,13 +1491,13 @@ parse_again:
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
 						goto error;
 						goto error;
 					case P_HOST:
 					case P_HOST:
-						*tmp=0;
+						VIA_ZT(*tmp);
 						vb->host.len=tmp-vb->host.s;
 						vb->host.len=tmp-vb->host.s;
 						state=F_PARAM;
 						state=F_PARAM;
 						param_start=tmp+1;
 						param_start=tmp+1;
 						break;
 						break;
 					case P_PORT:
 					case P_PORT:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->port_str.len=tmp-vb->port_str.s;
 						vb->port_str.len=tmp-vb->port_str.s;
 					case L_PORT:
 					case L_PORT:
 					case L_PARAM:
 					case L_PARAM:
@@ -1552,12 +1554,12 @@ parse_again:
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
 						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
 						goto error;
 						goto error;
 					case P_HOST:
 					case P_HOST:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->host.len=tmp-vb->host.s;
 						vb->host.len=tmp-vb->host.s;
 						state=F_VIA;
 						state=F_VIA;
 						break;
 						break;
 					case P_PORT:
 					case P_PORT:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->port_str.len=tmp-vb->port_str.s;
 						vb->port_str.len=tmp-vb->port_str.s;
 						state=F_VIA;
 						state=F_VIA;
 						break;
 						break;
@@ -1607,19 +1609,19 @@ parse_again:
 							*tmp, state);
 							*tmp, state);
 						goto  error;
 						goto  error;
 					case P_HOST:
 					case P_HOST:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->host.len=tmp-vb->host.s;
 						vb->host.len=tmp-vb->host.s;
 						state=F_COMMENT;
 						state=F_COMMENT;
 						c_nest++;
 						c_nest++;
 						break;
 						break;
 					case P_PORT:
 					case P_PORT:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->port_str.len=tmp-vb->port_str.s;
 						vb->port_str.len=tmp-vb->port_str.s;
 						state=F_COMMENT;
 						state=F_COMMENT;
 						c_nest++;
 						c_nest++;
 						break;
 						break;
 					case P_PARAM:
 					case P_PARAM:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->params.len=tmp-vb->params.s;
 						vb->params.len=tmp-vb->params.s;
 						state=F_COMMENT;
 						state=F_COMMENT;
 						c_nest++;
 						c_nest++;
@@ -1630,7 +1632,7 @@ parse_again:
 						state=F_COMMENT;
 						state=F_COMMENT;
 						vb->params.len=tmp-vb->params.s;
 						vb->params.len=tmp-vb->params.s;
 						c_nest++;
 						c_nest++;
-						*tmp=0;
+						VIA_ZT(*tmp);
 						break;
 						break;
 					case P_COMMENT:
 					case P_COMMENT:
 					case F_COMMENT:
 					case F_COMMENT:
@@ -1656,7 +1658,7 @@ parse_again:
 							c_nest--;
 							c_nest--;
 							if(c_nest==0){
 							if(c_nest==0){
 								state=L_VIA;
 								state=L_VIA;
-								*tmp=0;
+								VIA_ZT(*tmp);
 								vb->comment.len=tmp-vb->comment.s;
 								vb->comment.len=tmp-vb->comment.s;
 								break;
 								break;
 							}
 							}
@@ -1723,7 +1725,7 @@ parse_again:
 			case ']':
 			case ']':
 				switch(state){
 				switch(state){
 					case P_IP6HOST:
 					case P_IP6HOST:
-						*tmp=0; /*mark the end*/
+						VIA_ZT(*tmp); /*mark the end*/
 						vb->host.len=tmp-vb->host.s;
 						vb->host.len=tmp-vb->host.s;
 						state=L_PORT;
 						state=L_PORT;
 						break;
 						break;
@@ -1785,7 +1787,7 @@ parse_again:
 							case F_VIA:
 							case F_VIA:
 								vb->params.len=param->start+param->size
 								vb->params.len=param->start+param->size
 												-vb->params.s;
 												-vb->params.s;
-								*tmp=0;
+								VIA_ZT(*tmp);
 								break;
 								break;
 							case END_OF_HEADER:
 							case END_OF_HEADER:
 								vb->params.len=param->start+param->size
 								vb->params.len=param->start+param->size
@@ -1901,8 +1903,8 @@ endofpacket:
 	if (vb->port_str.s){
 	if (vb->port_str.s){
 		vb->port=str2s((unsigned char*)vb->port_str.s, vb->port_str.len, &err);
 		vb->port=str2s((unsigned char*)vb->port_str.s, vb->port_str.len, &err);
 		if (err){
 		if (err){
-					LOG(L_ERR, "ERROR: parse_via: invalid port number <%s>\n",
-						vb->port_str.s);
+					LOG(L_ERR, "ERROR: parse_via: invalid port number <%.*s>\n",
+						vb->port_str.len, vb->port_str.s);
 					goto error;
 					goto error;
 		}
 		}
 	}
 	}
@@ -1914,8 +1916,8 @@ nextvia:
 	if (vb->port_str.s){
 	if (vb->port_str.s){
 		vb->port=str2s((unsigned char*)vb->port_str.s, vb->port_str.len, &err);
 		vb->port=str2s((unsigned char*)vb->port_str.s, vb->port_str.len, &err);
 		if (err){
 		if (err){
-					LOG(L_ERR, "ERROR: parse_via: invalid port number <%s>\n",
-						vb->port_str.s);
+					LOG(L_ERR, "ERROR: parse_via: invalid port number <%.*s>\n",
+						vb->port_str.len, vb->port_str.s);
 					goto error;
 					goto error;
 		}
 		}
 	}
 	}

+ 10 - 0
receive.c

@@ -23,6 +23,11 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * ---------
+ * 2003-01-29 transport-independent message zero-termination in
+ *            receive_msg (jiri)
  */
  */
 
 
 
 
@@ -76,8 +81,10 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 	/* zero termination (termination of orig message bellow not that
 	/* zero termination (termination of orig message bellow not that
 	   useful as most of the work is done with scrath-pad; -jiri  */
 	   useful as most of the work is done with scrath-pad; -jiri  */
 	/* buf[len]=0; */ /* WARNING: zero term removed! */
 	/* buf[len]=0; */ /* WARNING: zero term removed! */
+	buf[len]=0; /* transport-independent zero-termination */
 	msg->rcv=*rcv_info;
 	msg->rcv=*rcv_info;
 	msg->id=msg_no;
 	msg->id=msg_no;
+#ifdef SCRATCH
 	/* make a copy of the message */
 	/* make a copy of the message */
 	msg->orig=(char*) pkg_malloc(len+1);
 	msg->orig=(char*) pkg_malloc(len+1);
 	if (msg->orig==0){
 	if (msg->orig==0){
@@ -88,6 +95,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 	/* WARNING: zero term removed! */
 	/* WARNING: zero term removed! */
 	/* msg->orig[len]=0; */ /* null terminate it,good for using str* functions
 	/* msg->orig[len]=0; */ /* null terminate it,good for using str* functions
 						 on it*/
 						 on it*/
+#endif
 	
 	
 	if (parse_msg(buf,len, msg)!=0){
 	if (parse_msg(buf,len, msg)!=0){
 		LOG(L_ERR, "ERROR: receive_msg: parse_msg failed\n");
 		LOG(L_ERR, "ERROR: receive_msg: parse_msg failed\n");
@@ -185,7 +193,9 @@ error:
 	exec_post_cb(msg);
 	exec_post_cb(msg);
 error02:
 error02:
 	free_sip_msg(msg);
 	free_sip_msg(msg);
+#ifdef SCRATCH
 error01:
 error01:
+#endif
 	pkg_free(msg);
 	pkg_free(msg);
 error00:
 error00:
 	STATS_RX_DROPS;
 	STATS_RX_DROPS;

+ 83 - 0
route.c

@@ -26,6 +26,10 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ * 2003-01-28 scratchpad removed, src_port introduced (jiri)
  */
  */
 
 
  
  
@@ -235,6 +239,64 @@ static int fix_actions(struct action* a)
 }
 }
 
 
 
 
+static int comp_port( int port, void *param, int op, int subtype )
+{
+	if (op!=EQUAL_OP) {
+		LOG(L_CRIT, "BUG: comp_port: '=' expected: %d\n", op );
+		return E_BUG;
+	}
+	if (subtype!=NUMBER_ST) {
+		LOG(L_CRIT, "BUG: comp_port: number expected: %d\n", subtype );
+		return E_BUG;
+	}
+	return port==(int)param;
+}
+
+/* eval_elem helping function, returns str op param */
+static int comp_strstr(str* str, void* param, int op, int subtype)
+{
+	int ret;
+	char backup;
+	
+	ret=-1;
+	if (op==EQUAL_OP){
+		if (subtype!=STRING_ST){
+			LOG(L_CRIT, "BUG: comp_str: bad type %d, "
+					"string expected\n", subtype);
+			goto error;
+		}
+		ret=(strncasecmp(str->s, (char*)param, str->len)==0);
+	}else if (op==MATCH_OP){
+		if (subtype!=RE_ST){
+			LOG(L_CRIT, "BUG: comp_str: bad type %d, "
+					" RE expected\n", subtype);
+			goto error;
+		}
+		/* this is really ugly -- we put a temporary zero-terminating
+		 * character in the original string; that's because regexps
+         * take 0-terminated strings and our messages are not
+         * zero-terminated; it should not hurt as long as this function
+		 * is applied to content of pkg mem, which is always the case
+		 * with calls from route{}; the same goes for fline in reply_route{};
+         *
+         * also, the received function should always give us an extra
+         * character, into which we can put the 0-terminator now;
+         * an alternative would be allocating a new piece of memory,
+         * which might be too slow
+         * -jiri
+         */
+		backup=str->s[str->len];str->s[str->len]=0;
+		ret=(regexec((regex_t*)param, str->s, 0, 0, 0)==0);
+		str->s[str->len]=backup;
+	}else{
+		LOG(L_CRIT, "BUG: comp_str: unknown op %d\n", op);
+		goto error;
+	}
+	return ret;
+	
+error:
+	return -1;
+}
 
 
 /* eval_elem helping function, returns str op param */
 /* eval_elem helping function, returns str op param */
 static int comp_str(char* str, void* param, int op, int subtype)
 static int comp_str(char* str, void* param, int op, int subtype)
@@ -337,8 +399,13 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 	}
 	}
 	switch(e->l.operand){
 	switch(e->l.operand){
 		case METHOD_O:
 		case METHOD_O:
+#ifdef DONT_REMOVE_ZT
 				ret=comp_str(msg->first_line.u.request.method.s, e->r.param,
 				ret=comp_str(msg->first_line.u.request.method.s, e->r.param,
 								e->op, e->subtype);
 								e->op, e->subtype);
+#else
+				ret=comp_strstr(&msg->first_line.u.request.method, e->r.param,
+								e->op, e->subtype);
+#endif
 				break;
 				break;
 		case URI_O:
 		case URI_O:
 				if(msg->new_uri.s){
 				if(msg->new_uri.s){
@@ -348,8 +415,13 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 									msg->parsed_uri.port_no?
 									msg->parsed_uri.port_no?
 									msg->parsed_uri.port_no:SIP_PORT);
 									msg->parsed_uri.port_no:SIP_PORT);
 					}else{
 					}else{
+#ifdef DONT_REMOVE_ZT
 						ret=comp_str(msg->new_uri.s, e->r.param,
 						ret=comp_str(msg->new_uri.s, e->r.param,
 										e->op, e->subtype);
 										e->op, e->subtype);
+#else
+						ret=comp_strstr(&msg->new_uri, e->r.param,
+										e->op, e->subtype);
+#endif
 					}
 					}
 				}else{
 				}else{
 					if (e->subtype==MYSELF_ST){
 					if (e->subtype==MYSELF_ST){
@@ -358,8 +430,13 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 									msg->parsed_uri.port_no?
 									msg->parsed_uri.port_no?
 									msg->parsed_uri.port_no:SIP_PORT);
 									msg->parsed_uri.port_no:SIP_PORT);
 					}else{
 					}else{
+#ifdef DONT_REMOVE_ZT
 						ret=comp_str(msg->first_line.u.request.uri.s,
 						ret=comp_str(msg->first_line.u.request.uri.s,
 										 e->r.param, e->op, e->subtype);
 										 e->r.param, e->op, e->subtype);
+#else
+						ret=comp_strstr(&msg->first_line.u.request.uri,
+										 e->r.param, e->op, e->subtype);
+#endif
 					}
 					}
 				}
 				}
 				break;
 				break;
@@ -377,6 +454,12 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 				if (ret<=0) ret=(ret==0)?EXPR_DROP:0;
 				if (ret<=0) ret=(ret==0)?EXPR_DROP:0;
 				else ret=1;
 				else ret=1;
 				break;
 				break;
+		case SRCPORT_O:
+				ret=comp_port(ntohs(msg->rcv.src_port), 
+					e->r.param, /* e.g., 5060 */
+					e->op, /* e.g. == */
+					e->subtype /* 5060 is number */);
+				break;
 		default:
 		default:
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
 							e->l.operand);
 							e->l.operand);

+ 5 - 0
route_struct.c

@@ -25,6 +25,8 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * 2003-01-29 src_port introduced (jiri)
  */
  */
 
 
 
 
@@ -143,6 +145,9 @@ void print_expr(struct expr* exp)
 			case SRCIP_O:
 			case SRCIP_O:
 				DBG("srcip");
 				DBG("srcip");
 				break;
 				break;
+			case SRCPORT_O:
+				DBG("srcport");
+				break;
 			case DSTIP_O:
 			case DSTIP_O:
 				DBG("dstip");
 				DBG("dstip");
 				break;
 				break;

+ 2 - 1
route_struct.h

@@ -46,7 +46,8 @@
 enum { EXP_T=1, ELEM_T };
 enum { EXP_T=1, ELEM_T };
 enum { AND_OP=1, OR_OP, NOT_OP };
 enum { AND_OP=1, OR_OP, NOT_OP };
 enum { EQUAL_OP=10, MATCH_OP, NO_OP };
 enum { EQUAL_OP=10, MATCH_OP, NO_OP };
-enum { METHOD_O=1, URI_O, SRCIP_O, DSTIP_O, DEFAULT_O, ACTION_O, NUMBER_O};
+enum { METHOD_O=1, URI_O, SRCIP_O, SRCPORT_O,
+	DSTIP_O, DEFAULT_O, ACTION_O, NUMBER_O};
 
 
 enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
 enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
 		SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T, 
 		SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T, 

+ 6 - 1
tcp_conn.h

@@ -23,6 +23,11 @@
  * You should have received a copy of the GNU General Public License
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *
+ * history:
+ * --------
+ * 2003-01-29 tcp buffer size ++-ed to allow for 0-terminator
  */
  */
 
 
 
 
@@ -57,7 +62,7 @@ enum conn_cmds { CONN_DESTROY=-3, CONN_ERROR=-2, CONN_EOF=-1, CONN_RELEASE,
 struct tcp_req{
 struct tcp_req{
 	struct tcp_req* next;
 	struct tcp_req* next;
 	/* sockaddr ? */
 	/* sockaddr ? */
-	char buf[TCP_BUF_SIZE]; /* bytes read so far*/
+	char buf[TCP_BUF_SIZE+1]; /* bytes read so far (+0-terminator)*/
 	char* start; /* where the message starts, after alll the empty lines are
 	char* start; /* where the message starts, after alll the empty lines are
 					skipped*/
 					skipped*/
 	char* pos; /* current position in buf */
 	char* pos; /* current position in buf */

+ 5 - 1
udp_server.c

@@ -23,6 +23,10 @@
  * You should have received a copy of the GNU General Public License 
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History
+ * --------
+ * 2003-01-28 packet zero-termination moved to receive_msg (jiri)
  */
  */
 
 
 
 
@@ -314,7 +318,7 @@ int udp_rcv_loop()
 			else goto error;
 			else goto error;
 		}
 		}
 		/*debugging, make print* msg work */
 		/*debugging, make print* msg work */
-		buf[len+1]=0;
+		/* buf[len+1]=0; */ /* zero-termination moved to receive_msg */
 
 
 #ifndef NO_ZERO_CHECKS
 #ifndef NO_ZERO_CHECKS
 		if (len==0) {
 		if (len==0) {

+ 23 - 1
ut.h

@@ -28,6 +28,8 @@
  *
  *
  * History
  * History
  * ------
  * ------
+ * 2003-01-29 pathmax added (jiri)
+ * 2003-01-28 scratchpad removed (jiri)
  * 2003-01-18 un_escape function introduced for convenience of code needing
  * 2003-01-18 un_escape function introduced for convenience of code needing
  *            the complex&slow feature of unescaping
  *            the complex&slow feature of unescaping
  */
  */
@@ -36,12 +38,14 @@
 #ifndef ut_h
 #ifndef ut_h
 #define ut_h
 #define ut_h
 
 
+#include "comp_defs.h"
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/time.h>
+#include <limits.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
-
+#include "config.h"
 #include "dprint.h"
 #include "dprint.h"
 #include "str.h"
 #include "str.h"
 
 
@@ -78,8 +82,10 @@ struct sip_msg;
 	((_via)->bsize-((_via)->name.s-\
 	((_via)->bsize-((_via)->name.s-\
 		((_via)->hdr.s+(_via)->hdr.len)))
 		((_via)->hdr.s+(_via)->hdr.len)))
 
 
+#ifdef SCRATCH
 #define via_s(_via,_p_msg) \
 #define via_s(_via,_p_msg) \
 	translate_pointer((_p_msg)->orig,(_p_msg)->buf,(_via)->name.s)
 	translate_pointer((_p_msg)->orig,(_p_msg)->buf,(_via)->name.s)
+#endif
 
 
 
 
 /* char to hex conversion table */
 /* char to hex conversion table */
@@ -253,6 +259,22 @@ inline static void sleep_us( unsigned int nusecs )
 	select(0, NULL, NULL, NULL, &tval );
 	select(0, NULL, NULL, NULL, &tval );
 }
 }
 
 
+
+/* portable determination of max_path */
+inline static int pathmax()
+{
+#ifdef PATH_MAX
+	static int pathmax=PATH_MAX;
+#else
+	static int pathmax=0;
+#endif
+	if (pathmax==0) { /* init */
+		pathmax=pathconf("/", _PC_PATH_MAX);
+		pathmax=(pathmax<=0)?PATH_MAX_GUESS:pathmax+1;
+	}
+	return pathmax;
+}
+
 inline static int hex2int(char hex_digit)
 inline static int hex2int(char hex_digit)
 {
 {
 	if (hex_digit>='0' && hex_digit<='9')
 	if (hex_digit>='0' && hex_digit<='9')