Jelajahi Sumber

- moved 0-term to udp_rcv_loop & tcp_read_req (save & restore the 0 term char)

Andrei Pelinescu-Onciul 22 tahun lalu
induk
melakukan
8fc80c33bb
5 mengubah file dengan 24 tambahan dan 6 penghapusan
  1. 1 1
      Makefile.defs
  2. 1 0
      TODO
  3. 6 3
      receive.c
  4. 13 0
      tcp_read.c
  5. 3 2
      udp_server.c

+ 1 - 1
Makefile.defs

@@ -8,7 +8,7 @@
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   11
-EXTRAVERSION = pre6-tcp2
+EXTRAVERSION = pre6-tcp3
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 1 - 0
TODO

@@ -70,4 +70,5 @@ x generic locking lib
 - convert tm to use new locking lib
 - tcp disable nagle & other socket stuff (close()?)
 - force add rport (setflag(rport)???)
+- kill all the fprintf
 

+ 6 - 3
receive.c

@@ -29,6 +29,8 @@
  * 2003-01-29 transport-independent message zero-termination in
  *            receive_msg (jiri)
  * 2003-02-07 undoed jiri's zero term. changes (they break tcp) (andrei)
+ * 2003-02-10 moved zero-term in the calling functions (udp_receive &
+ *            tcp_read_req)
  */
 
 
@@ -56,6 +58,10 @@
 
 unsigned int msg_no=0;
 
+
+/* WARNING: buf must be 0 terminated (buf[len]=0) or some things might 
+ * break (e.g.: modules/textops)
+ */
 int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) 
 {
 	struct sip_msg* msg;
@@ -92,9 +98,6 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 		goto error01;
 	}
 	memcpy(msg->orig, buf, len);
-	/* WARNING: zero term removed! */
-	/* msg->orig[len]=0; */ /* null terminate it,good for using str* functions
-						 on it*/
 #endif
 	
 	if (parse_msg(buf,len, msg)!=0){

+ 13 - 0
tcp_read.c

@@ -24,6 +24,12 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ * 2002-12-??  created by andrei.
+ * 2003-02-10  zero term before calling receive_msg & undo afterwards (andrei)
+ */
 
 #ifdef USE_TCP
 
@@ -351,6 +357,7 @@ int tcp_read_req(struct tcp_connection* con)
 	long size;
 	struct tcp_req* req;
 	int s;
+	char c;
 		
 		resp=CONN_RELEASE;
 		s=con->fd;
@@ -409,10 +416,16 @@ again:
 					req->start, (int)(req->parsed-req->start));
 			bind_address=sendipv4; /*&tcp_info[con->sock_idx];*/
 			con->rcv.proto_reserved1=con->id; /* copy the id */
+			c=*req->parsed; /* ugly hack: zero term the msg & save the
+							   previous char, req->parsed should be ok
+							   because we always alloc BUF_SIZE+1 */
+			*req->parsed=0;
 			if (receive_msg(req->start, req->parsed-req->start, &con->rcv)<0){
+				*req->parsed=c;
 				resp=CONN_ERROR;
 				goto end_req;
 			}
+			*req->parsed=c;
 			
 			/* prepare for next request */
 			size=req->pos-req->parsed;

+ 3 - 2
udp_server.c

@@ -27,6 +27,7 @@
  * History
  * --------
  * 2003-01-28 packet zero-termination moved to receive_msg (jiri)
+ * 2003-02-10 undoed the above changes (andrei)
  */
 
 
@@ -317,8 +318,8 @@ int udp_rcv_loop()
 				continue; /* goto skip;*/
 			else goto error;
 		}
-		/*debugging, make print* msg work */
-		/* buf[len+1]=0; */ /* zero-termination moved to receive_msg */
+		/* we must 0-term the messages, receive_msg expects it */
+		buf[len+1]=0; /* no need to save the previous char */
 
 #ifndef NO_ZERO_CHECKS
 		if (len==0) {