- Added WS_MAX_RECV_FRAME_SZ, if a received frame exceeds this limit (10
MiB), error out. This is a DoS prevention measure.
- Also redid the unmasking code in get_ws_frame(), to avoid assumptions
about the size of an unsigned int and some casting, and avoid
memcpy(), just use the mask bytes from the buffer that are already there
to unmask.
get_ws_frame:
- had potentially unaligned access; fixed.
- was not reading the full 8 bytes in the 64-bit case (was using the
incorrect htons); fixed.
make_ws_frame:
- wasn't writing the length in the 8-byte case.
Also switched both functions to use size_t rather than int where
appropriate.
Replace evws_send with evws_send_text, and introduce new API -
evws_send_binary, that can be used to send binary frames.
But note, that this commit breaks the ABI compatibility, but it should be OK,
since there was only alpha release with evws_send, and nobody should rely on
this, and I hope nobody does (we decided to go this way to avoid supporting
deprecated API).
* http: fix typo
* ws: fix comile error
On CentOS:
CC ws.lo
ws.c: In function 'get_ws_frame':
ws.c:244:3: error: 'for' loop initial declarations are only allowed in C99 mode
for (int i = 0; i < payload_len; i++) {
^
ws.c:244:3: note: use option -std=c99 or -std=gnu99 to compile your code
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.
Implementation was inspired by modified Libevent source code in ipush project
[1].
[1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable
Also, WebSocket-based chat server was added as a sample.