Browse code

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

Andrei Pelinescu-Onciul authored on 10/02/2003 15:49:40
Showing 5 changed files
... ...
@@ -8,7 +8,7 @@
8 8
 VERSION = 0
9 9
 PATCHLEVEL = 8
10 10
 SUBLEVEL =   11
11
-EXTRAVERSION = pre6-tcp2
11
+EXTRAVERSION = pre6-tcp3
12 12
 
13 13
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
14 14
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -70,4 +70,5 @@ x generic locking lib
70 70
 - convert tm to use new locking lib
71 71
 - tcp disable nagle & other socket stuff (close()?)
72 72
 - force add rport (setflag(rport)???)
73
+- kill all the fprintf
73 74
 
... ...
@@ -29,6 +29,8 @@
29 29
  * 2003-01-29 transport-independent message zero-termination in
30 30
  *            receive_msg (jiri)
31 31
  * 2003-02-07 undoed jiri's zero term. changes (they break tcp) (andrei)
32
+ * 2003-02-10 moved zero-term in the calling functions (udp_receive &
33
+ *            tcp_read_req)
32 34
  */
33 35
 
34 36
 
... ...
@@ -56,6 +58,10 @@
56 56
 
57 57
 unsigned int msg_no=0;
58 58
 
59
+
60
+/* WARNING: buf must be 0 terminated (buf[len]=0) or some things might 
61
+ * break (e.g.: modules/textops)
62
+ */
59 63
 int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) 
60 64
 {
61 65
 	struct sip_msg* msg;
... ...
@@ -92,9 +98,6 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
92 92
 		goto error01;
93 93
 	}
94 94
 	memcpy(msg->orig, buf, len);
95
-	/* WARNING: zero term removed! */
96
-	/* msg->orig[len]=0; */ /* null terminate it,good for using str* functions
97
-						 on it*/
98 95
 #endif
99 96
 	
100 97
 	if (parse_msg(buf,len, msg)!=0){
... ...
@@ -24,6 +24,12 @@
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 26
  */
27
+/*
28
+ * History:
29
+ * --------
30
+ * 2002-12-??  created by andrei.
31
+ * 2003-02-10  zero term before calling receive_msg & undo afterwards (andrei)
32
+ */
27 33
 
28 34
 #ifdef USE_TCP
29 35
 
... ...
@@ -351,6 +357,7 @@ int tcp_read_req(struct tcp_connection* con)
351 351
 	long size;
352 352
 	struct tcp_req* req;
353 353
 	int s;
354
+	char c;
354 355
 		
355 356
 		resp=CONN_RELEASE;
356 357
 		s=con->fd;
... ...
@@ -409,10 +416,16 @@ again:
409 409
 					req->start, (int)(req->parsed-req->start));
410 410
 			bind_address=sendipv4; /*&tcp_info[con->sock_idx];*/
411 411
 			con->rcv.proto_reserved1=con->id; /* copy the id */
412
+			c=*req->parsed; /* ugly hack: zero term the msg & save the
413
+							   previous char, req->parsed should be ok
414
+							   because we always alloc BUF_SIZE+1 */
415
+			*req->parsed=0;
412 416
 			if (receive_msg(req->start, req->parsed-req->start, &con->rcv)<0){
417
+				*req->parsed=c;
413 418
 				resp=CONN_ERROR;
414 419
 				goto end_req;
415 420
 			}
421
+			*req->parsed=c;
416 422
 			
417 423
 			/* prepare for next request */
418 424
 			size=req->pos-req->parsed;
... ...
@@ -27,6 +27,7 @@
27 27
  * History
28 28
  * --------
29 29
  * 2003-01-28 packet zero-termination moved to receive_msg (jiri)
30
+ * 2003-02-10 undoed the above changes (andrei)
30 31
  */
31 32
 
32 33
 
... ...
@@ -317,8 +318,8 @@ int udp_rcv_loop()
317 317
 				continue; /* goto skip;*/
318 318
 			else goto error;
319 319
 		}
320
-		/*debugging, make print* msg work */
321
-		/* buf[len+1]=0; */ /* zero-termination moved to receive_msg */
320
+		/* we must 0-term the messages, receive_msg expects it */
321
+		buf[len+1]=0; /* no need to save the previous char */
322 322
 
323 323
 #ifndef NO_ZERO_CHECKS
324 324
 		if (len==0) {