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".
fix issuing null extension header if none supported

Josh realized that with new Chrome, because we don't support the type of
compression extension yet we returned a null extension header.

This patch fixes that by deferring issuing the extension header until we
find we have something to say.

tested OK on google-chrome 19.0.1081.2-129295

Reported-by: Josh Roberson <josh@asteriasgi.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
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.

Signed-off-by: Nick Dowell <nick@nickdowell.com>
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>
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.

Signed-off-by: Yonathan Yusim <yonathan@boxee.tv>
Signed-off-by: Andy Green <andy@warmcat.com>
fix onopen browser context patch

Signed-off-by: Andy Green <andy.green@linaro.org>
style cleaning

Signed-off-by: Andy Green <andy.green@linaro.org>
autoconf introduce enable mingw and adapt compiler options

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
mingw hide some missing includes

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
mingw add in missing poll defs

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
mingw gettimeofday avoid missing include

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
change DATADIR to INSTALL_DATADIR solve mingw conflict

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
remove duplicated netdb include from client handshake

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
mingw add zlib paths

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>
doc add explanation missing from per context provate data

Signed-off-by: Andy Green <andy.green@linaro.org>
mingw add win32helper to lib and fix extpoll

Based on work from Radu Sorici <soriciradu@gmail.com>

Signed-off-by: Andy Green <andy.green@linaro.org>