1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-09-04 12:42:09 +03:00

Preserve the current mask flag and opcode for websocket_data callback.

This commit is contained in:
William Greathouse
2013-10-13 13:40:42 -04:00
parent 46a44f12f3
commit 52d2ddbd47

View File

@@ -4366,6 +4366,7 @@ static void read_websocket(struct mg_connection *conn)
dynamically allocated buffer if it is too large. */
char mem[4096];
char *data = mem;
unsigned char mop; /* mask and opcode */
/* Loop continuously, reading messages from the socket, invoking the
callback, and waiting repeatedly until an error occurs. */
@@ -4412,6 +4413,7 @@ static void read_websocket(struct mg_connection *conn)
data and advance the queue by moving the memory in place. */
assert(body_len >= header_len);
if (data_len + header_len > body_len) {
mop = buf[0]; /* current mask and opcode */
/* Overflow case */
len = body_len - header_len;
memcpy(data, buf + header_len, len);
@@ -4419,6 +4421,7 @@ static void read_websocket(struct mg_connection *conn)
pull(NULL, conn, data + len, (int)(data_len - len));
conn->data_len = 0;
} else {
mop = buf[0]; /* current mask and opcode, overwritten by memmove() */
/* Length of the message being read at the front of the
queue */
len = data_len + header_len;
@@ -4444,7 +4447,7 @@ static void read_websocket(struct mg_connection *conn)
/* Exit the loop if callback signalled to exit,
or "connection close" opcode received. */
if ((conn->ctx->callbacks.websocket_data != NULL &&
!conn->ctx->callbacks.websocket_data(conn, buf[0], data, data_len)) ||
!conn->ctx->callbacks.websocket_data(conn, mop, data, data_len)) ||
(buf[0] & 0xf) == WEBSOCKET_OPCODE_CONNECTION_CLOSE) { /* Opcode == 8, connection close */
break;
}