Browse code

core: tidied up websocket frame length code

Peter Dunkley authored on 16/06/2012 23:43:44
Showing 1 changed files
... ...
@@ -1019,7 +1019,7 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
1019 1019
 static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1020 1020
 {
1021 1021
 	int bytes, pos, mask_present;
1022
-	unsigned long len;
1022
+	unsigned int len;
1023 1023
 	char *p;
1024 1024
 	struct tcp_req *r;
1025 1025
 
... ...
@@ -1079,9 +1079,9 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1079 1079
 		if (bytes < pos + 2)
1080 1080
 			goto skip;
1081 1081
 
1082
-		len = 0;
1083
-		len |= (p[pos++] & 0xff) <<  8;
1084
-		len |= (p[pos++] & 0xff) <<  0;
1082
+		len =	  ((p[pos + 0] & 0xff) <<  8)
1083
+			| ((p[pos + 1] & 0xff) <<  0);
1084
+		pos += 2;
1085 1085
 	}
1086 1086
 	else if (len == 127)
1087 1087
 	{
... ...
@@ -1091,12 +1091,11 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1091 1091
 		/* Only decoding the last four bytes of the length...
1092 1092
 		   This limits the size of WebSocket messages that can be
1093 1093
 		   handled to 2^32 - which should be plenty for SIP! */
1094
-		len = 0;
1095
-		pos += 4;
1096
-		len |= (p[pos++] & 0xff) << 24;
1097
-		len |= (p[pos++] & 0xff) << 16;
1098
-		len |= (p[pos++] & 0xff) <<  8;
1099
-		len |= (p[pos++] & 0xff) <<  0;
1094
+		len =	  ((p[pos + 4] & 0xff) << 24)
1095
+			| ((p[pos + 5] & 0xff) << 16)
1096
+			| ((p[pos + 6] & 0xff) <<  8)
1097
+			| ((p[pos + 7] & 0xff) <<  0);
1098
+		pos += 8;
1100 1099
 	}
1101 1100
 
1102 1101
 	/* Skip mask */