Don't care for the human-readable part of "HTTP/1.1
 101" reply

While the protocol specification gives example of the
human-readable message associated with a 101-code reply,
nowhere does it actually enforce it. Ws4py gevent middleware
is known to have a message other than "Switching Protocols".
handle unsupported protocol correctly

Hi Andy,

First off, thanks for libwebsockets :-)

I've encountered a crash when a client connects to a libwebsockets server
but speicifies an unsupported protocol (Sec-WebSocket-Protocol).
handshake.c should probably be checking that wsi->protocol->name is not
null before doing a strcmp with it...
Attached is a patch for your consideration.

Cheers!
Nick

Signed-off-by: Nick Dowell <nick@nickdowell.com>
map wsorigin on to origin at an early point and stop dupe header mem leaks

Carlo wrote

''I'm interested to use the libwebsockets server (C based) with a Java
websocket client. I was able to implement a Java websocket client based
on JWebSocket library that works fine with the libwebsockets server, but
I was obliged to patch the libwebsockets server in order to reach my
goal. In particular I patched the handshake_00() function because
JWebSocket library uses hixie 76 version. The problem was that the
JWebSocket library sends only WSI_TOKEN_SWORIGIN token instead
WSI_TOKEN_ORIGIN token. For this reason the handshake_00 failed because
the token length of WSI_TOKEN_ORIGIN was 0. I have written a patch in
order to control if at least one of the two tokens (WSI_TOKEN_SWORIGIN
and WSI_TOKEN_ORIGIN) is defined. I have attached into the e-mail the
patch. Probably it can be written better, but in any case I think that
this problem should be fixed for client/server compatibility.''

I found a simpler approach which is convert WSORIGIN processing to
go into ORIGIN token at the earliest point, then everything else can
stay the same.

I also noticed we would leak on duplicated headers and fixed that.

Reported-by: Carlo PARATA <carlo.parata@st.com>
Signed-off-by: Andy Green <andy@warmcat.com>
fix heap corruption if HTTP callback calls libwebsocket_close_and_free_session

Signed-off-by: Nick Dowell <nick@nickdowell.com>
close connection if socket recv() fails.

This prevents a problem observed on Windows whereby a client that
disconnects before fully establishing the WebSocket would cause the
server to use 100% CPU since recv() would continually return -1 for that
socket.
make duplicate headers append instead of get ignored

The code to prevent memory leaks caused by reallocating a wsi->utf8_token
was also causing wsi->parser_state to not be updated, preventing the
handshake from completing.

This patch changes the logic to append to previous allocation which is
correct behaviour actually.

Signed-off-by: Nick Dowell <nick@nickdowell.com>
Signed-off-by: Andy Green <andy@warmcat.com>
use ssize_t instead of size_t for return values of read/recv/SSL_read

Signed-off-by: Tobias Maier <tobias.maier@netplace.com>
ssize_t needs help on windows

ssize_t is needed, but absent in Windows.

This patch typedefs it to an int in that case as recommended by Tobias.
allow message processing from onopen browser context

Found an issue in libwebsockets - if a server sends a message within its "onopen" context then the message is getting swallowed and not passed to calling client (means LWS_CALLBACK_CLIENT_RECEIVE is never getting called).
I've fixed the bug - pls find attached patch.
remove duplicated netdb include from client handshake

Based on work from Radu Sorici <soriciradu@gmail.com>
doc add explanation missing from per context provate data

Signed-off-by: Andy Green <andy.green@linaro.org>
reduce debug spew
android toolchain SHA1 endian fix

Android toolchain needs an extra include if it's not to confuse
SHA-1 code probably with incorrect endian-ness from missing /bits/
start migration to getnameinfo

Signed-off-by: Andy Green <andy.green@linaro.org>
improve callback prototypes to use single definition

Not sure all compilers can hack this, but give it a try
set connection callback before connection completed to allow early messages
introduce LWS_CALLBACK_CLIENT_CONNECTION_ERROR

Signed-off-by: David Brooks <dave@bcs.co.nz>
Signed-off-by: Andy Green <andy@warmcat.com>
--
openssl allow connect multiple packets for SSL_connect

Ken found over the internet with real delays, SSL_connect can
fail to work.  This patch adapts his workaround to stay in the
connect state until we either run out of time for the connect
or succeed.
Initialize c_callback when protocol is found.
Updated docs.