Commit graph

1060 commits

Author SHA1 Message Date
Andy Green
19895bcfd4 introduce LWS_CALLBACK_FILTER_HTTP_CONNECTION
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-09 11:59:56 +08:00
Andy Green
6cd8880f23 add cookie example to test server
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-09 11:48:42 +08:00
Andy Green
7900256c8a allow other headers in http send file
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-09 11:40:38 +08:00
Andy Green
84fd949e05 make ah available in http callback properly
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-09 11:40:32 +08:00
Andy Green
cc13c6f187 improve minilex use external parsing header
Clean up minilex
Move the header output to stdout
Introduce lexfile.h as the header output
Use lexfile.h in both minilex itself and lws
Add the following header support

       "Accept:",
       "If-Modified-Since:",
       "Accept-Encoding:",
       "Accept-Language:",
       "Pragma:",
       "Cache-Control:",
       "Authorization:",
       "Cookie:",
       "Content-Type:",
       "Date:",
       "Range:",
       "Referer:"

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-09 10:09:09 +08:00
Graham Newton
7ee4f890a3 windows workaround unsigned fd in emulated poll
A common practise to temporarily disable a socket in a poll call is to negate the socket fd.  poll should then ignore the socket.
emulated_poll does this with the following code:
        if (poll_fd->fd < 0 || !poll_fd->events)
            goto skip1;

However on Windows the fd field in WSAPOLLFD is unsigned int!!!  So the check for a negative fd value always fails.
This results in select returning an error with an error code of 10038 -- Socket operation on nonsocket.
The fix is to type cast fd like so:
        if ((int)poll_fd->fd < 0 || !poll_fd->events)

This may be the cause of some high CPU load reports.  I noticed the load being 50% with my application running on Windows XP.

Signed-off-by: Graham Newton <gnewton@peavey-eu.com>
2013-11-09 08:11:41 +08:00
Andy Green
d1eac60f81 interface improve visibility fail if not found
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-09 08:07:38 +08:00
Andreas Pakulat
dae94d8adc Windows Fix usage in Windows XP targetting projects
This is important since this stuff is in publicly included headers
and even though the usage of the WSAPoll API is a runtime decision
the public headers may be used in code that needs to build with
_WIN32_WINNT=0x0501 to support WinXP.

When building a project using libwebsockets with that define set
to 0x0501 winsock.h will not define the WSAPOLLFD struct causing that
project to fail to compile.
2013-11-04 10:18:14 +08:00
Andy Green
29338d9ef3 unixify websock w32.h line endings
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-11-04 10:17:50 +08:00
Andreas Pakulat
fe8589c07c Windows Fix include for win32helpers
The installed headers are all in the same directory, so no relative
path possible there. The cmake files already add the win32helpers
directory to the include paths, so this builds just fine.
2013-11-04 10:12:08 +08:00
Andreas Pakulat
7e8674007d Windows Fix installing the dll
Without a runtime install directory, cmake won't install the dll at
all. Only the import library was installed. So fix that.
2013-11-04 10:08:42 +08:00
Andreas Pakulat
68bd4bd7bf Support _WIN32 in addition to WIN32 define
MSVC8 and MSVC9 set only _WIN32, so support that define as well to be able
to compile libwebsockets with those compilers.
2013-11-04 10:04:31 +08:00
Andreas Pakulat
39ceebcfbf Drop wsockcompat.h header its not part of msvc
I don't see a wsockcompat.h anywhere in MSVC9 or MSVC8 and their
corresponding sdk's. It does not seem like this is a standard windows
header, so better drop that and add the compat-defines to the same
place that already has other WSA compat defines.
2013-11-04 09:53:59 +08:00
Graham Newton
b1aa1d3389 handle HUP on any mode socket
I am using libwebsockets on Windows 7 in external poll mode.
I am finding that if I present a socket fd on a normal HTTP connection
(LWS_CONNMODE_HTTP_SERVING:) to libwebsocket_service_fd with just a HUP
event, the event doesn't get handled but revents gets cleared indicating
that the event has been handled.  Should it be handled in the same way
as LWS_CONNMODE_WS_SERVING?

(Modified by AG to apply to all sockets)

Signed-off-by: Andy Green <andy.green@linaro.org>
Signed-off-by: Graham Newton <gnewton@peavey-eu.com>
2013-11-04 09:47:06 +08:00
Andy Green
9b8a29f8ca trac41 WIN32 add wsockcompat.h
Using Windows 7 64 bit, cloned repo on 20130926. Using Qt creator and Microsoft Visual C++ Compiler 9.0 (x86).
Result (errors from compile output): D:\Projects\CDPStudioAPI\libwebsockets_orig\lib\client-handshake.c:87: error: C2065: 'EALREADY' : undeclared identifier
D:\Projects\CDPStudioAPI\libwebsockets_orig\lib\client-handshake.c:87: error: C2065: 'EINPROGRESS' : undeclared identifier
Possible solution is to use wsockcompat.h (compatibility header for using EALREADY, EINPROGRESS etc in older versions of Windows SDK). Compiled fine when I #included wsockcompat.h into client-handshake.c

Reported-by: mart22n via Trac 41
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-26 21:18:44 +08:00
Andy Green
81877e6a4c v1.2.3 changelog update
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-26 20:36:08 +08:00
Markus Elfring
7521233176 make header protection unique remove __prefix
Signed-off-by: Markus Elfring <markus.elfring@web.de>
2013-10-26 20:23:00 +08:00
Markus Elfring
299244f7fc fix cmake quoting
A few parameters (like "${PROJECT_BINARY_DIR}/lws_config.h" and "${PROJECT_SOURCE_DIR}/lib") are passed to CMake commands in your build script without enclosing them by quotation marks. I see that these places will result in build difficulties if the contents of the used variables will contain special characters like spaces.

Signed-off-by: Markus Elfring <markus.elfring@web.de>
2013-10-26 20:03:43 +08:00
shys
cfa8ac34c7 cover-proxy-read-EAGAIN.patch
Subject: [PATCH] Because of nonblocking sockets reading from  proxy might not
 work in one turn. We should check for EAGAIN.
2013-10-25 22:30:25 +08:00
shys
5efcb3f7de Subject: [PATCH] Additional check for EISONN. On iOS "if (connect()) == -1 ||
errno == EISCONN)" doesn't work.
2013-10-25 22:28:28 +08:00
shys
6b5c1af439 Subject: [PATCH] On iOS with nonblocking sockets I experience SSL error which
is not really an error (
 http://lists.freeradius.org/pipermail/freeradius-users/2009-August/040155.html
 ). Added check for that. Additional fixes for comments and logging.
2013-10-25 22:26:36 +08:00
u0u0
44e260e004 fix origin
And fix client header of Origin, add prefix "http://" to make a valid URI, to make golang websocket server happy.
2013-10-25 22:17:21 +08:00
Andy Green
36efd82da6 defer changing to proxy uri until connected
Reported-by: shyswork
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-25 22:07:57 +08:00
Andy Green
6811457323 add EISCONN handling to client connect attempt
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-24 22:32:06 +08:00
shys
24f4eb648b wait ssl connect completion on client proxy path
Subject: [PATCH] We can ran into situation (at least on iOS) when with openssl
 nonblocking BIO and http proxy we don't perform ssl_connect straight away so
 we need to retry until we finish ssl_connect. If we don't do that we will
 fail in LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY when testing for "HTTP/1.0
 200" successful connection.

Signed-off-by: shys <shyswork@zoho.com>
2013-10-24 22:27:08 +08:00
shys
b4e800e333 manual proxy forcing api
add function to manually setup proxy. Useful on iOS where
 getenv doesn't return proxy settings

Simplified by AG

Signed-off-by: shys <shyswork@zoho.com>
Signed-off-by: Andy Green <andy@warmcat.com>
2013-10-24 22:12:03 +08:00
Arokux X
e0b3d13fbf CMAKE help if cwd not git dir
Hi all,

please consider applying the patch below. The git is called in some
different directory and that is why fails. I'm not sure why it was
called in different directory, maybe because I build libwebsockets
with CMake's ExternalProject.

Best,
Arokux

Signed-off-by: Arokux X <arokux@gmail.com>
2013-10-24 21:53:39 +08:00
Andy Green
8d15cf4a14 fix typo in NO_SERVER case
Reported-by: shyswork via github
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-24 21:47:06 +08:00
Andy Green
8b2d6f0ee7 use compatible_close for sockets
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-22 06:49:30 +08:00
Andy Green
0c0bf4a985 fix clean return path user code handle
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-18 19:23:06 +08:00
Andy Green
1f4267bda8 add explicit error for partial send
This patch adds code to handle the situation that a prepared user buffer could not all be sent on the
socket at once.  There are two kinds of situation to handle

1) User code handles it: The connection only has extensions active that do not rewrite the buffer.
In this case, the patch caused libwebsocket_write() to simply return the amount of user buffer that
was consumed (this is specifically the amount of user buffer used in sending what was accepted,
nothing else).  So user code can just advance its buffer that much and resume sending when the socket
is writable again.  This continues the frame rather than starting a new one or new fragment.

2) The connections has extensions active which actually send something quite different than what the
user buffer contains, for example a compression extension.  In this case, libwebsockets will dynamically
malloc a buffer to contain a copy of the remaining unsent data, request notifiction when writeable again,
and automatically spill and free this buffer with the highest priority before passing on the writable
notification to anything else.  For this situation, the call to write will return that it used the
whole user buffer, even though part is still rebuffered.

This patch should enable libwebsockets to detect the two cases and take the appropriate action.

There are also two choices for user code to deal with partial sends.

1) Leave the no_buffer_all_partial_tx member in the protocol struct at zero.  The library will dyamically
buffer anything you send that did not get completely written to the socket, and automatically spill it next
time the socket is writable.  You can use this method if your sent frames are relatvely small and unlikely to get
truncated anyway.

2) Set the no_buffer_all_partial_tx member in the protocol struct.  User code now needs to take care of the
return value from libwebsocket_write() and deal with resending the remainder if not all of the requested amount
got sent.  You should use this method if you are sending large messages and want to maximize throughput and efficiency.

Since the new member no_buffer_all_partial_tx will be zero by default, this patch will auto-rebuffer any
partial sends by default.  That's good for most cases but if you attempt to send large blocks, make sure you
follow option 2) above.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-17 08:09:19 +08:00
Andy Green
5dc62ead9d trac 40 client connection properly nonblocking
As spotted by JM on Trac#40

http://libwebsockets.org/trac/libwebsockets/ticket/40

client connect didn't do anything about being truly nonblocking.  This patch
should hopefully solve that.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-20 20:26:12 +08:00
Fujii Bunichiroh
e92947680a force failed header parse to act
''...Websocket servers return failure responses other than HTTP Status 101 in the case of
mismatches of WebSocket version or additional header data etc...
It seems that libwebsockets shows "WARN: problems parsing header" error in such cases without
calling any callbacks or returning error code. Is this right?
I modified lib/client.c to handle this.''

Signed-off-by: Fujii Bunichiroh <Bunichiroh.Fujii@jp.sony.com>
2013-09-18 21:01:02 +08:00
Andy Green
8eda4117dd remove bae64 decode and selftest
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 20:57:59 +08:00
Andy Green
512c246338 trac #39: allow fd 0 for connection
Reported (with fix) by Martijn The http://libwebsockets.org/trac/ticket/39

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 12:59:33 +08:00
Erland Isaksson
578a24df3d cmake fix for osx 64 bit
AG tested on 64-bit Fedora no problems

Signed-off-by: Erland Isaksson <erland@isaksson.info>
2013-09-18 09:00:52 +08:00
Andy Green
9beedc163c trac 36 make libwebsocket_set_timeout public
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 08:47:15 +08:00
Andy Green
96d48fdc28 change LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION user param usage
Also audit the bail_nuke_ah usage as Daniel Griscom suggested.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 08:32:55 +08:00
David Gauchard
6c58228577 fix http incomplete send handling
Signed-off-by: David Gauchard <gauchard@laas.fr>
2013-06-29 10:24:16 +08:00
Joachim Bauch
8294c1fa4f Request "send" not to trigger SIGPIPE on errors. 2013-06-29 10:22:09 +08:00
Jiri Hnidek
eb51a7a6ef add CMake find function for libwebsockets
Signed-off-by: Jiri Hnidek <jiri.hnidek@tul.cz>
2013-06-29 10:18:52 +08:00
Niall T. Davidson
db761be972 Added additional LWS_CALLBACK_CLOSED_HTTP callback to just_kill_connection branch of close_and_free_session 2013-06-29 10:16:18 +08:00
Joachim Bauch
d727e9f698 Support empty ping and pong packets. 2013-06-23 14:47:26 +08:00
Joachim Bauch
d8b8542d59 Declare "sha1_init" statically to avoid naming conflicts if linked statically with other libraries providing a method with the same name (e.g. OpenSSL). 2013-06-23 14:45:15 +08:00
Andy Green
0c9563bbd2 add LWS_CALLBACK_CLOSED_HTTP
Adds a callback to allow handling HTTP protocol connections
closing.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-06-10 22:54:40 +08:00
Andy Green
7cf6cb00c2 trac 28 - differentiate between http serving and accepted http connection
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-19 14:04:10 +08:00
Simon Wulf
502b9948f2 trac 28 brackets around POLLIN flag test
Signed-off-by: Simon Wulf <simonwulf.lund@bredband.net>
2013-05-06 06:14:03 +08:00
Andy Green
66986b2e85 log err if unable to open http file
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-03 21:13:35 +08:00
Andy Green
6c72070fd4 trac 29 convert more snprintf stowaways
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-02 08:15:53 +08:00
Andy Green
86aa80509f trac 29 echo remoe mention of syslog constants for win32
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-02 07:04:54 +08:00