Browse code

fixed bug due to assumption that 'str' is the same as 'struct iovec' (used by writev). this occurs only on 64 bit machines.

Raphael Coeffic authored on 29/08/2005 13:52:24
Showing 1 changed files
... ...
@@ -87,7 +87,12 @@ int tm_unix_tx_timeout = 2; /* Default is 2 seconds */
87 87
 #define TWRITE_PARAMS          20
88 88
 #define TWRITE_VERSION_S       "0.3"
89 89
 #define TWRITE_VERSION_LEN     (sizeof(TWRITE_VERSION_S)-1)
90
-#define eol_line(_i_)          ( lines_eol[2*(_i_)] )
90
+
91
+#define eol_line_s(_i_)        ( iov_lines_eol[2*(_i_)].iov_base )
92
+#define eol_line_len(_i_)      ( iov_lines_eol[2*(_i_)].iov_len )
93
+
94
+#define eol_line(_i_,_s_)      { eol_line_s(_i_) = (_s_).s; \
95
+                                 eol_line_len(_i_) = (_s_).len; }
91 96
 
92 97
 #define IDBUF_LEN              128
93 98
 #define ROUTE_BUFFER_MAX       512
... ...
@@ -118,8 +123,8 @@ int tm_unix_tx_timeout = 2; /* Default is 2 seconds */
118 123
 		append_chr(s,'>');len++;\
119 124
 	} while(0)
120 125
 
121
-static str   lines_eol[2*TWRITE_PARAMS];
122
-static str   eol={"\n",1};
126
+static struct iovec iov_lines_eol[2*TWRITE_PARAMS];
127
+static struct iovec eol={"\n",1};
123 128
 
124 129
 static int sock;
125 130
 
... ...
@@ -506,14 +511,14 @@ int init_twrite_lines()
506 511
 
507 512
 	/* init the line table */
508 513
 	for(i=0;i<TWRITE_PARAMS;i++) {
509
-		lines_eol[2*i].s = 0;
510
-		lines_eol[2*i].len = 0;
511
-		lines_eol[2*i+1] = eol;
514
+		iov_lines_eol[2*i].iov_base = 0;
515
+		iov_lines_eol[2*i].iov_len = 0;
516
+		iov_lines_eol[2*i+1] = eol;
512 517
 	}
513 518
 
514 519
 	/* first line is the version - fill it now */
515
-	eol_line(0).s   = TWRITE_VERSION_S;
516
-	eol_line(0).len = TWRITE_VERSION_LEN;
520
+	eol_line_s(0)   = TWRITE_VERSION_S;
521
+	eol_line_len(0) = TWRITE_VERSION_LEN;
517 522
 
518 523
 	return 0;
519 524
 }
... ...
@@ -538,7 +543,7 @@ static int inline write_to_fifo(char *fifo, int cnt )
538 543
 
539 544
 	/* write now (unbuffered straight-down write) */
540 545
 repeat:
541
-	if (writev(fd_fifo, (struct iovec*)lines_eol, 2*cnt)<0) {
546
+	if (writev(fd_fifo, iov_lines_eol, 2*cnt)<0) {
542 547
 		if (errno!=EINTR) {
543 548
 			LOG(L_ERR, "ERROR:tm:write_to_fifo: writev failed: %s\n",
544 549
 				strerror(errno));
... ...
@@ -842,7 +847,7 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi)
842 847
 	append_chr(s,'.');
843 848
 	append.len = s-append.s;
844 849
 
845
-	eol_line(1).s = s = cmd_buf;
850
+	eol_line_s(1) = s = cmd_buf;
846 851
 	if(twi->action.len+12 >= CMD_BUFFER_MAX){
847 852
 		LOG(L_ERR,"assemble_msg: buffer overflow while "
848 853
 		    "copying command name\n");
... ...
@@ -850,31 +855,31 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi)
850 855
 	}
851 856
 	append_str(s,"sip_request.",12);
852 857
 	append_str(s,twi->action.s,twi->action.len);
853
-	eol_line(1).len = s-eol_line(1).s;
858
+	eol_line_len(1) = s - (char*)eol_line_s(1);
854 859
 
855
-	eol_line(2)=REQ_LINE(msg).method;     /* method type */
856
-	eol_line(3)=msg->parsed_uri.user;     /* user from r-uri */
857
-	eol_line(4)=msg->parsed_uri.host;     /* domain */
860
+	eol_line(2,REQ_LINE(msg).method);     /* method type */
861
+	eol_line(3,msg->parsed_uri.user);     /* user from r-uri */
862
+	eol_line(4,msg->parsed_uri.host);     /* domain */
858 863
 
859
-	eol_line(5)=msg->rcv.bind_address->address_str; /* dst ip */
864
+	eol_line(5,msg->rcv.bind_address->address_str); /* dst ip */
860 865
 
861
-	eol_line(6)=msg->rcv.dst_port==SIP_PORT ?
862
-			empty_param : msg->rcv.bind_address->port_no_str; /* port */
866
+	eol_line(6,msg->rcv.dst_port==SIP_PORT ?
867
+			empty_param : msg->rcv.bind_address->port_no_str); /* port */
863 868
 
864 869
 	/* r_uri ('Contact:' for next requests) */
865
-	eol_line(7)=msg->first_line.u.request.uri;
870
+	eol_line(7,msg->first_line.u.request.uri);
866 871
 
867 872
 	/* r_uri for subsequent requests */
868
-	eol_line(8)=str_uri.len?str_uri:empty_param;
873
+	eol_line(8,str_uri.len?str_uri:empty_param);
869 874
 
870
-	eol_line(9)=get_from(msg)->body;		/* from */
871
-	eol_line(10)=msg->to->body;			/* to */
872
-	eol_line(11)=msg->callid->body;		/* callid */
873
-	eol_line(12)=get_from(msg)->tag_value;	/* from tag */
874
-	eol_line(13)=get_to(msg)->tag_value;	/* to tag */
875
-	eol_line(14)=get_cseq(msg)->number;	/* cseq number */
875
+	eol_line(9,get_from(msg)->body);		/* from */
876
+	eol_line(10,msg->to->body);			/* to */
877
+	eol_line(11,msg->callid->body);		/* callid */
878
+	eol_line(12,get_from(msg)->tag_value);	/* from tag */
879
+	eol_line(13,get_to(msg)->tag_value);	/* to tag */
880
+	eol_line(14,get_cseq(msg)->number);	/* cseq number */
876 881
 
877
-	eol_line(15).s=id_buf;       /* hash:label */
882
+	eol_line_s(15)=id_buf;       /* hash:label */
878 883
 	s = int2str(hash_index, &l);
879 884
 	if (l+1>=IDBUF_LEN) {
880 885
 		LOG(L_ERR, "assemble_msg: too big hash\n");
... ...
@@ -882,19 +887,19 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi)
882 887
 	}
883 888
 	memcpy(id_buf, s, l);
884 889
 	id_buf[l]=':';
885
-	eol_line(15).len=l+1;
890
+	eol_line_len(15)=l+1;
886 891
 	s = int2str(label, &l);
887
-	if (l+1+eol_line(15).len>=IDBUF_LEN) {
892
+	if (l+1+eol_line_len(15)>=IDBUF_LEN) {
888 893
 		LOG(L_ERR, "assemble_msg: too big label\n");
889 894
 		goto error;
890 895
 	}
891
-	memcpy(id_buf+eol_line(15).len, s, l);
892
-	eol_line(15).len+=l;
896
+	memcpy(id_buf+eol_line_len(15), s, l);
897
+	eol_line_len(15) += l;
893 898
 
894
-	eol_line(16) = route.len ? route : empty_param;
895
-	eol_line(17) = next_hop;
896
-	eol_line(18) = append;
897
-	eol_line(19) = body;
899
+	eol_line(16, route.len ? route : empty_param );
900
+	eol_line(17, next_hop );
901
+	eol_line(18, append );
902
+	eol_line(19, body );
898 903
 
899 904
 	/* success */
900 905
 	return 1;
... ...
@@ -947,7 +952,7 @@ static int write_to_unixsock(char* sockname, int cnt)
947 952
 		return -1;
948 953
 	}
949 954
 
950
-	if (tsend_dgram_ev(sock, (struct iovec*)lines_eol, 2 * cnt, tm_unix_tx_timeout * 1000) < 0) {
955
+	if (tsend_dgram_ev(sock, iov_lines_eol, 2 * cnt, tm_unix_tx_timeout * 1000) < 0) {
951 956
 		LOG(L_ERR, "write_to_unixsock: writev failed: %s\n", strerror(errno));
952 957
 		return -1;
953 958
 	}