Server handshake reply might not come in one packet as pointed out by
Pavel Borzenkov. This replaces his fix with one directly in the packet
state machine.
Signed-off-by: Andy Green <andy@warmcat.com>
Since 'shift' has unsigned integer type,
the following code may lead to infinite cycle
and segfault:
while (shift >= 0) {
if (shift)
buf[0 - pre + n] =
((len >> shift) & 127) | 0x80;
else
buf[0 - pre + n] =
((len >> shift) & 127);
n++;
shift -= 7;
}
Change type to signed integer.
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@auriga.com>
While performing handshake recv() is called only once.
It may return only part of the data and handshake
will fail. This patch modifies libwebsocket_service_fd()
to ensure that there is not data left in the socket.
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@auriga.com>
For the IETF revision 00 send 'Upgrade: WebSocket' header
instead of 'Upgrade: websocket' as described in the IETF standard.
Some servers (for example, phpdaemon) are case-sensitive.
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@auriga.com>
Patrick McManus from Mozilla pointed out that the spec requires a specific kind
of zlib compression, which is raw. You can select that by using a funny api in
zlib. Mozilla are correcting their compression to this, pywebsockets already did
it right in the first place, libwebsockets should now work OK with those.
Signed-off-by: Andy Green <andy@warmcat.com>
you have your makefiles set up to treat warnings as errors, and my gcc
4.4.5 (64 bit) compiler generates 3 warnings that need fixing:
(that sprintf() one is a real bug.. if ext_name contains formatting
characters you are looking at a potential segv).
Signed-off-by: Patrick McManus <mcmanus@ducksong.com>
Ago noticed that some Windows clients experience small packets
from the server being aggregated and set after a long delay
(200-300ms).
He found that TCP_NODELAY on the socket solved this, I tested it
and it didn't have any noticable bad effect, so I implemented it
for all sockets, client and server.
Thans Ago for debugging this and notifying the cause.
Reported-by: Ago Allikmaa <maxorator@gmail.com>
Signed-off-by: Andy Green <andy@warmcat.com>
Notice that the naming is changed, the notification to a server that it can write to
the client is now called LWS_CALLBACK_SERVER_WRITEABLE, and the notification to a client
that it can write to a server is LWS_CALLBACK_CLIENT_WRITEABLE.
Signed-off-by: Andy Green <andy@warmcat.com>
Extensions might be caching stuff that we should spill before a controlled close.
It's not allowed to send anything on the wire after the close request, so we need
to make the extensions spill just before.
Signed-off-by: Andy Green <andy@warmcat.com>
... this afternoon I was just doing a little
interoperability testing around close... in my test-server I added
libwebsocket_close_and_free_session(this, wsi, LWS_CLOSE_STATUS_NORMAL);
in order to generate a server driven close.. I hope that was the right
way to go about it. In any event, in generated an invalid websocket
frame - I think you want this patch, or something like it:
Signed-off-by: \"Pat McManus @Mozilla\" <mcmanus@ducksong.com>
This goes through the extentsions the client requested, selects the ones
that we support at the server, and then further calls back to the appropriate
protocol callback in user code to check it's OK to actually use that
extension in this context. If it is (callback unhandled == it is) then
it's added to the list of extensions sent back to the client.
Accepted extensions are also added to the connection's active extension
list and the private "user" memory allocation for the extension context is
done and bound to the connection.
Signed-off-by: Andy Green <andy@warmcat.com>
This adds win32 build compatability to libwebsockets.
The patch is from Peter Hinz, Andy Green has cleaned it up a bit and
possibly broken win32 compatability since I can't test it, so there
may be followup patches. It compiles fine under Linux after this
patch anyway.
Much of the patch is changing a reserved keyword for Visual C compiler
"this" to "context", but there is no real C99 support in the MSFT
compiler even though it is 2011 so C99 style array declarations
have been mangled back into "ancient C" style.
Some windows-isms are also added like closesocket() but these are
quite localized. Win32 random is just using C library random() call
at the moment vs Linux /dev/urandom. canonical hostname detection is
broken in win32 at the moment.
Signed-off-by: Peter Hinz <cerebusrc@gmail.com>
Signed-off-by: Andy Green <andy@warmcat.com>
This adds a callback to protocols[0] which happens when the
Client HTTP handshake packet is being composed. After all the
headers for the websocket handshake to the server have been
added, the callback is called with a pointer to a char *
that allows extra headers to be added. See the comments in
libwebsocket.h or the api documentation for example code.
Signed-off-by: Andy Green <andy@warmcat.com>
This adds 76/00 client support to libwebsockets. It's still shipped
by browsers and more importantly still the only version supported by
server stuff like socket.io.
Signed-off-by: Andy Green <andy@warmcat.com>
Thanks to Christopher Baker for pointing out that when we close a session,
if the close is coming before a protocol was negotiated for the connection
or when the protocol was otherwise left at NULL, we'll blow a segfault.
This implements his proposed fix.
Reported-by: Christopher Baker <me@christopherbaker.net>
Signed-off-by: Andy Green <andy@warmcat.com>