Commit graph

1880 commits

Author SHA1 Message Date
Sterling Jensen
ecaed5ec94 Fix leak caused by undestroyed pthread mutex 2016-05-13 09:42:37 +08:00
Andy Green
bf31c1bc87 win32 libuv related build fixes
https://github.com/warmcat/libwebsockets/issues/526

On master, cleanups and refactor mean the last two problems already
don't exist (array is gone from main.c and http.c is deleted)

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-13 08:20:12 +08:00
Andy Green
2700d1c0c3 protocol_client_loopback_test
This is used to confirm that SSL client connections can coexist with
a vhost doing serving.

To set it up,

/*
 * This is a bit fiddly...
 *
 * 0) If you want the wss:// test to work, make sure the vhost is marked with
 *    enable-client-ssl if using lwsws, or call lws_init_vhost_client_ssl() on
 *    the vhost if you're doing it by hand.
 *
 * 1) enable the protocol on a vhost
 *
 *      "ws-protocols": [{
 *     "client-loopback-test": {
 *      "status": "ok"
 *     },  ...
 *
 *     the vhost should listen on 80 (ws://) or 443 (wss://)
 *
 * 2) mount the http part of the test one level down on the same vhost, eg
 *   {
 *      "mountpoint": "/c",
 *      "origin": "callback://client-loopback-test"
 *   }
 *
 * 3) Use a browser to visit the mountpoint with a URI attached for looping
 *    back, eg, if testing on localhost
 *
 *    http://localhost/c/ws://localhost
 *    https://localhost/c/wss://localhost
 *
 * 4) The HTTP part of this test protocol will try to do the requested
 *    ws client connection, to the same test protocol on the same
 *    server.
 */

Results should look like this

lwsws[29938]: client connection to localhost:443 with ssl: 1 started
lwsws[29938]: server part: LWS_CALLBACK_ESTABLISHED
lwsws[29938]: checking client ext permessage-deflate
lwsws[29938]: instantiating client ext permessage-deflate
lwsws[29938]: Client connection established
lwsws[29938]: Client connection received 7 from server 'Made it'

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-12 21:14:13 +08:00
Andy Green
fb8be0507e add lws_init_vhost_client_ssl api to allow client ssl use on a vhost
Also add lwsws "enable-client-ssl": "1" vhost option to match.

Client cert iclient ssl is not supported in lwsws, if someone wants it, it can be added.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-12 21:14:13 +08:00
Andy Green
b6d229d726 check oom on lws_malloc
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-12 21:04:33 +08:00
Andy Green
03e628b9a6 windows no chown on log file generation
https://github.com/warmcat/libwebsockets/issues/524

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-11 18:59:27 +08:00
Andy Green
5e203f78e2 output allow LWS_PRE+4 on top of rx_buffer_size for max send chunk
https://github.com/warmcat/libwebsockets/issues/522

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-10 21:35:38 +08:00
Andy Green
0a4da2c71f lwsws remove all protocols use lws default http
Actually lwsws doesn't need his own protocol handler even for http
any more.  The default http handler in lws should do everything.

Move the cgi routing into lws default http protocol handler, and
delete lwsws one.  Remove all protocols from lwsws so the lws
default one gets used.

With this, and the earlier move of lejp into lws, lwsws itself
becomes 15.5KB of x86_64 (mainly conf parsing).

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-10 11:28:30 +08:00
Andy Green
677d6c1516 lwsws cleanup and allocate config strings dynamically
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-10 10:42:19 +08:00
Andy Green
f530de84ac lwsws remove non libuv SIGINT handler
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-10 10:31:16 +08:00
Andy Green
5afc56770d lejp bring into lws
lejp is already in lws as part of lwsws.  However it's too generally useful
to just put directly in lwsws, it will lead to multiple copies of the source
in differet subprojects.

This moves it directly into lws, lwsws now gets it from there.

Like lwsws, by default at cmake it is disabled.  Selecting LWS_WITH_LWSWS now
selects LWS_WITH_LEJP and you can set that at cmake individually as well.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-10 09:47:10 +08:00
Andy Green
b293f52672 logging migrate user stimulated logging to info
https://github.com/warmcat/libwebsockets/issues/520

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-09 13:31:43 +08:00
Andy Green
b24aaeb822 add protocol plugin for post demo
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-09 10:05:43 +08:00
Andy Green
4010694d04 POST handling dont autocomplete transaction
Until now lws has finished the HTTP transaction when the POST body was
completely received.

However that needlessly makes it impossible to send a HTTP 200 and a
response without a redirect.

This changes lws behaviour after sending the LWS_CALLBACK_HTTP_BODY_COMPLETION
callback to no longer terminate the HTTP transaction.

If you want the old behaviour, you can terminate the transaction with
lws_http_transaction_completed() in the LWS_CALLBACK_HTTP_BODY_COMPLETION
callback.

Otherwise it's now possible to call lws_callback_on_writable() from
LWS_CALLBACK_HTTP_BODY_COMPLETION.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-09 09:37:44 +08:00
Andy Green
4e3b0ce973 libuv tidy up destroy and disable timer races during shutdown
Also don't make us wait 1s for init to finish.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-08 17:07:46 +08:00
Andy Green
584f7109a0 client fix for operation with libuv
- libuv socket init binding was missing for client

 - failures like no ws protocol match are deferred until the
   ah is bound.  Check for these failures and make sure we
   tell the guy trying to set up the client connection the
   wsi is NULL if it has already failed and closed.

 - pfd.events was not initialized for the client init path

With this general client function is more robust but also
client connections work properly with libuv.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-08 17:03:01 +08:00
Andy Green
11d8efef88 context only destroy protocols if init got sent
If for some reason we exit before the protocol init action
(which is delayed for libuv) we should not send the protocol
destroy messages

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-08 17:00:38 +08:00
Andy Green
ad45efa434 client handle connection fail at second phase properly
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-08 16:58:18 +08:00
Andy Green
43bfd951fa test server post also take care about POST len termination
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-08 16:56:34 +08:00
Andy Green
26019a2586 update api docs v2.0
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-07 14:24:36 +08:00
Andy Green
3db2c65157 fix %3d handling in path part and add attack.sh
https://github.com/warmcat/libwebsockets/issues/518

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-07 08:31:33 +08:00
Andy Green
6cca3fbb12 protocol plugins default also add example in test server v2.0
This shows how to deliver per-vhost, per-protocol option
name:value pairs using code.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-06 15:56:13 +08:00
Andy Green
f6585285cb protocol plugins set default
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-06 14:24:59 +08:00
Andy Green
f4767497d3 mimetypes add additional canned
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-06 08:02:57 +08:00
OndraCo
a709cbb2f5 MSVC from 2015 up has vsnprintf 2016-05-06 07:48:56 +08:00
OndraCo
6a81b08dc2 Disabled static link handling for WIN_CE to temporarily avoid the fact that it has no stat struct 2016-05-06 07:48:56 +08:00
OndraCo
624b23df5e Changes to enable WIN CE support 2016-05-06 07:48:23 +08:00
Enno Boland
b6e2ad6b50 lib/server.c: fix ipv6 support 2016-05-06 07:47:54 +08:00
Enno Boland
7731a3e575 lib/ssl.c: fix libre- and boringssl 2016-05-06 07:46:26 +08:00
Andy Green
aef3dc4ad7 snip changelog back to 1.7
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-06 07:45:19 +08:00
Andy Green
5500643f3c v2.0.0
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-05 09:40:18 +08:00
Andy Green
ad40037c80 recv revert treating zero as hangup
While checking with ab, I found
commit 30cdb3ac8f
Author: Justin Chen <justinchen00@github.invalid.com>
Date:   Thu Apr 14 21:40:53 2016 +0800

    recv treat zero return as error

    https://github.com/warmcat/libwebsockets/issues/475

turned ab performance to crap, reverting it made everything fast again.

recv manpage says there is three ways to get zero returned

1)       When a stream socket peer has performed an orderly shutdown, the return value will be 0  (the  traditional  "end-of-file"
       return).

2)       Datagram  sockets  in  various  domains  (e.g., the UNIX and Internet domains) permit zero-length datagrams.  When such a
       datagram is received, the return value is 0.

3)       The value 0 may also be returned if the requested number of bytes to receive from a stream socket was 0.

we can't just assume it means the peer shut down.

If the peer shut down, then the event loop should get an event on the socket like POLLHUP and deal with it that way.

So the patch mentioned above is simply reverted here.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-05 09:06:09 +08:00
Andy Green
c25b290b20 stats upgrade rx tx to long long
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-04 15:59:55 +08:00
Andy Green
8b02454634 cgi add generic wait as antizombie defence
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-04 12:23:27 +08:00
Andy Green
4eab21976c clean build warning on windows
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-04 11:11:15 +08:00
Andy Green
8554bd43bd appveyor openssl 1.0.2h
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-04 11:02:33 +08:00
Andy Green
5474221a0c libuv fixes for foreign loop test
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-04 08:40:46 +08:00
Denis Osvald
d098ba47cb test server foreign loop
AG: adapt to use switch on existing test-server-libuv app
AG: correct the foreign lifecycle to be valgrind clean

This adds a switch -f --foreign that makes the test-server-libuv test
create his own libuv loop outside of lws, and use lws on it before
destroying lws and then his own loop.

If selected, the foreign loop runs for 5s before lws and 10s after
lws is stopped, for testing purposes.

Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-05-04 06:00:37 +08:00
Andy Green
8ea8d08623 client provide user_space on LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER
https://github.com/warmcat/libwebsockets/issues/509

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-03 21:39:16 +08:00
Andy Green
f1fd882d57 client fix reaction to tls failure
https://github.com/warmcat/libwebsockets/issues/508

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-03 07:26:10 +08:00
Andy Green
cae57ad98d plugins_dir convert to array
If OOT lws plugins will be packaged as separate projects,
they're going to want to install their plugins somewhere
that makes sense for the package instead of one big lws
plugin dir.

This patch changes info to have a const char ** to a NULL
terminated array of directories it should search for
plugins.  lwsws knows about this and you can add to the
dir array using config fragments like

{
  "global": {
   "plugin-dir": "/usr/local/share/coherent-timeline/plugins"
  }
}

if the config fragment in /etc/lwsws/conf.d/ is also managed by the
package with the plugin, it can very cleanly add and remove itself
from lwsws based on package install status.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 10:03:25 +08:00
Andy Green
4d5ac9c910 plugin standalone example for oot build
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 07:49:29 +08:00
Andy Green
d5dc5dff13 provide default empty protocol zero handler if NULL protocols in info
Move the dummy stub protocol into the library as the default
if NULL protocols given, since that is likely to become popular.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 07:49:29 +08:00
Andy Green
2f72f67a65 libwebsockets-test-server-v2.0 showing how to use mounts and plugins
No dependency on test-server.h (just libwebsockets.h and getopt.h / syslog.h)

No need for any user callback code and all in one short file.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 06:03:10 +08:00
Andy Green
952fcdede1 per vhost options struct explicitly const
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 06:01:59 +08:00
Andy Green
4664f71ed3 create_vhost move mounts list to info
There's no reason to not have the mounts linked list init also in the info
struct, rather than provide as a paramater to lws_create_vhost().  Now
is a good time to normalize that since this api only exists in master.

This also allows oldstyle "do everything at context creation time in one
vhost" guys to leverage mounts.

Also there's no reason the mounts linked-list pointer and all uses in lws
are non-const, so make them all explicitly const *.

Update the info struct docs to clarify which members are used when creating
a vhost and which for context creation.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 04:59:54 +08:00
Patrick Farrell
72e0e2a516 Add warn_unused_result check, attribute only supported by GCC 3.4 or later
warn_unused_result was introduced in GCC version 3.4.

Change-Id: I6c2cc938d2b868ddfe0889cc41d7fa9d70e1b907
2016-04-30 02:07:13 +08:00
Stephan Eberle
67729c954f Eliminated compile warning in test-client.c 2016-04-27 07:38:52 +08:00
Stephan Eberle
ff32d01742 Fixed misspelled size_t 2016-04-27 07:36:41 +08:00
Stephan Eberle
8087959acf Fixed build failure under Visual Studio 14 2015 2016-04-27 07:34:43 +08:00