diff options
author | Stefan Fritsch <sf@sfritsch.de> | 2015-08-02 00:19:16 +0200 |
---|---|---|
committer | Stefan Fritsch <sf@sfritsch.de> | 2015-08-02 00:19:16 +0200 |
commit | 48802c25dc82a8b13ac351c0c2137ef748256bbd (patch) | |
tree | dcaa03f7f34153303fe5afbc9c99dbb8c44b22b3 /modules/lua/lua_request.c | |
parent | 080d5e16db802902200a9ce5b6c40f8f1fdc1f73 (diff) | |
download | apache2-48802c25dc82a8b13ac351c0c2137ef748256bbd.tar.gz |
Imported Upstream version 2.4.16
Diffstat (limited to 'modules/lua/lua_request.c')
-rw-r--r-- | modules/lua/lua_request.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 6dc6b9f5..4f8d39af 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -2229,6 +2229,7 @@ static int lua_websocket_read(lua_State *L) { apr_socket_t *sock; apr_status_t rv; + int do_read = 1; int n = 0; apr_size_t len = 1; apr_size_t plen = 0; @@ -2246,6 +2247,8 @@ static int lua_websocket_read(lua_State *L) mask_bytes = apr_pcalloc(r->pool, 4); sock = ap_get_conn_socket(r->connection); + while (do_read) { + do_read = 0; /* Get opcode and FIN bit */ if (plaintext) { rv = apr_socket_recv(sock, &byte, &len); @@ -2254,9 +2257,12 @@ static int lua_websocket_read(lua_State *L) rv = lua_websocket_readbytes(r->connection, &byte, 1); } if (rv == APR_SUCCESS) { - unsigned char fin, opcode, mask, payload; - fin = byte >> 7; - opcode = (byte << 4) >> 4; + unsigned char ubyte, fin, opcode, mask, payload; + ubyte = (unsigned char)byte; + /* fin bit is the first bit */ + fin = ubyte >> (CHAR_BIT - 1); + /* opcode is the last four bits (there's 3 reserved bits we don't care about) */ + opcode = ubyte & 0xf; /* Get the payload length and mask bit */ if (plaintext) { @@ -2266,14 +2272,18 @@ static int lua_websocket_read(lua_State *L) rv = lua_websocket_readbytes(r->connection, &byte, 1); } if (rv == APR_SUCCESS) { - mask = byte >> 7; - payload = byte - 128; + ubyte = (unsigned char)byte; + /* Mask is the first bit */ + mask = ubyte >> (CHAR_BIT - 1); + /* Payload is the last 7 bits */ + payload = ubyte & 0x7f; plen = payload; /* Extended payload? */ if (payload == 126) { len = 2; if (plaintext) { + /* XXX: apr_socket_recv does not receive len bits, only up to len bits! */ rv = apr_socket_recv(sock, (char*) &payload_short, &len); } else { @@ -2372,10 +2382,11 @@ static int lua_websocket_read(lua_State *L) frame[0] = 0x8A; frame[1] = 0; apr_socket_send(sock, frame, &plen); /* Pong! */ - lua_websocket_read(L); /* read the next frame instead */ + do_read = 1; } } } + } return 0; } |