[sr-dev] git:pd/websocket: core: tidied up websocket frame length code
Peter Dunkley
peter.dunkley at crocodile-rcs.com
Sun Jun 17 01:44:46 CEST 2012
Module: sip-router
Branch: pd/websocket
Commit: 62691a52ffd48e4dc674027cfe9b984620a55b88
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=62691a52ffd48e4dc674027cfe9b984620a55b88
Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date: Sun Jun 17 00:43:44 2012 +0100
core: tidied up websocket frame length code
---
tcp_read.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/tcp_read.c b/tcp_read.c
index ccb5481..187e9a1 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -1019,7 +1019,7 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
{
int bytes, pos, mask_present;
- unsigned long len;
+ unsigned int len;
char *p;
struct tcp_req *r;
@@ -1079,9 +1079,9 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
if (bytes < pos + 2)
goto skip;
- len = 0;
- len |= (p[pos++] & 0xff) << 8;
- len |= (p[pos++] & 0xff) << 0;
+ len = ((p[pos + 0] & 0xff) << 8)
+ | ((p[pos + 1] & 0xff) << 0);
+ pos += 2;
}
else if (len == 127)
{
@@ -1091,12 +1091,11 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
/* Only decoding the last four bytes of the length...
This limits the size of WebSocket messages that can be
handled to 2^32 - which should be plenty for SIP! */
- len = 0;
- pos += 4;
- len |= (p[pos++] & 0xff) << 24;
- len |= (p[pos++] & 0xff) << 16;
- len |= (p[pos++] & 0xff) << 8;
- len |= (p[pos++] & 0xff) << 0;
+ len = ((p[pos + 4] & 0xff) << 24)
+ | ((p[pos + 5] & 0xff) << 16)
+ | ((p[pos + 6] & 0xff) << 8)
+ | ((p[pos + 7] & 0xff) << 0);
+ pos += 8;
}
/* Skip mask */
More information about the sr-dev
mailing list