Commit graph

420 commits

Author SHA1 Message Date
Denis Osvald
14f994f52a test-server-extpoll: add 1-per-second timeout servicing
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-10-07 17:33:31 +08:00
Denis Osvald
3f8082fecf test-server-extpoll: check for forced service before looping again
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-10-07 17:04:33 +08:00
Andy Green
8b0dd360aa update attack.sh
Lws cares about trailing \n on a lot of these tests now.  Make it check it still cares on one and remove
the trailing \n on the others.

There's 2 changes in the results about /..//?, it seems to apply / to uri arg 1.  But it doesn't seem
to make a problem so just adapt the results for now.
2016-10-06 20:41:29 +08:00
Peter Pentchev
fb71b790cd Subject: Fix some typographical and grammatical errors. 2016-10-03 21:31:27 +08:00
Andy Green
a496700b3a lws_snprintf
Thanks to Fabrice Gilot for reporting the problem that led to uncovering this.

Due to a misunderstanding of the return value of snprintf (it is not truncated according
to the max size passed in) in several places relying on snprintf to truncate the length
overflows are possible.

This patch wraps snprintf with a new lws_snprintf() which does truncate its length to allow
the buffer limiting scheme to work properly.

All users should update with these fixes.
2016-09-15 02:22:57 +08:00
Fredrik Skogman
9c04a107c9 Updated test programs to build on Solaris. Some whitespaces cleanup. 2016-09-10 04:53:28 +08:00
Andy Green
e35d91a860 per-vhost headers and lwsws conf support
This l;ets you add per-vhost arbitrary headers on served files, eg

     "headers": [{
        "X-Content-Type-Options": "nosniff",
        "X-XSS-Protection": "1; mode=block",
        "x-frame-options": "SAMEORIGIN"
        }],
2016-08-27 17:07:06 +08:00
Patrick Gansterer
396b58ce70 Remove unneeded #include <stdint.h>
This fixes the build for Visual Studio 2008.
2016-08-26 18:31:09 +08:00
Andy Green
a5ec7212ff test html: js date uses ms 2016-08-23 18:29:17 +08:00
Andy Green
95fff47a91 client-add-PUSH-http-body-capability
Support HTTP body sending on client connections.

Add demo to test-client.

Run the normal test server, then

$ libwebsockets-test-client http://localhost:7681/formtest -o

It will post the string "hello" to the POST test using application/x-www-form-urlencoded

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

Also ensures any of the Client HTTP transient modes will call back LWS_CALLBACK_CLOSED_CLIENT_HTTP
if they close

https://github.com/warmcat/libwebsockets/issues/600
2016-08-10 21:23:01 +08:00
Andy Green
bbf93693d8 client fixups after esp8266 2016-08-10 21:23:01 +08:00
Andy Green
7acf76cd3d esp8266 initial support 2016-08-10 21:20:23 +08:00
Andy Green
f32d25051c ws ping pong on idle connections
This adds a new member to the context creation info struct "ws_ping_pong_interval".

If nonzero, it sets the number of seconds that established ws connections are
allowed to be idle before a PING is forced to be sent.  If zero (the default) then
tracking of idle connection is disabled for backwards compatibility.

Timeouts cover both the period between decision to send the ping and it being
sent (because it needs the socket to become writeable), and the period between
the ping being sent and the PONG coming back.

INFO debug logs are issues when the timeout stuff is operating.

You can test the server side by running the test server hacked to set ws_ping_pong_interval
and debug log mask of 15.  Both the mirror protocol and the server-status protocol are
idle if nothing is happening and will trigger the PING / PONG testing.  (You can also
test using lwsws and /etc/lwsws/conf with "ws-pingpong-secs": "20" in the global section)

For client, run the test client with -n -P 20 for 20s interval.  -n stops the test client
writing using the mirror protocol, so it will be idle and trigger the PING / PONGs.

The timeout interval may be up to +10s late, as lws checks for affected connections every
10s.
2016-08-10 21:20:23 +08:00
Andy Green
2671b7469a plugins-dim-webpage-when-connection-lost 2016-07-14 08:57:28 +08:00
Andy Green
722cc4a366 plugin table dirlisting 2016-07-14 08:57:28 +08:00
Andy Green
675c349cc5 client ssl add flag to control server cert hostname check 2016-07-14 08:57:28 +08:00
Andy Green
81c221ed35 CLIENT_CONNECTION_ERROR add strings
This clears up a couple of issues with client connect.

 - if CLIENT_CONNECTION_ERROR is coming, which of the many
   ways the rejection may have happened is documented in the
   in argument.  It's still possible if it just got hung up on
   in will be NULL, but now it has MANY more canned strings
   describing the issue available at the callback

	"getaddrinfo (ipv6) failed"
	"unknown address family"
	"getaddrinfo (ipv4) failed"
	"set socket opts failed"
	"insert wsi failed"
	"lws_ssl_client_connect1 failed"
	"lws_ssl_client_connect2 failed"
	"Peer hung up"
	"read failed"
	"HS: URI missing"
	"HS: Redirect code but no Location"
	"HS: URI did not parse"
	"HS: Redirect failed"
	"HS: Server did not return 200"
	"HS: OOM"
	"HS: disallowed by client filter"
	"HS: disallowed at ESTABLISHED"
	"HS: ACCEPT missing"
	"HS: ws upgrade response not 101"
	"HS: UPGRADE missing"
	"HS: Upgrade to something other than websocket"
	"HS: CONNECTION missing"
	"HS: UPGRADE malformed"
	"HS: PROTOCOL malformed"
	"HS: Cannot match protocol"
	"HS: EXT: list too big"
	"HS: EXT: failed setting defaults"
	"HS: EXT: failed parsing defaults"
	"HS: EXT: failed parsing options"
	"HS: EXT: Rejects server options"
	"HS: EXT: unknown ext"
	"HS: Accept hash wrong"
	"HS: Rejected by filter cb"
	"HS: OOM"
	"HS: SO_SNDBUF failed"
	"HS: Rejected at CLIENT_ESTABLISHED"

 - until now the user code did not get the new wsi that was created
    in the client connection action until it returned.  However the
    client connection action may provoke callbacks like
    CLIENT_CONNECTION_ERROR before then, if multiple client connections
    are initiated it makes it unknown to user code which one the callback
    applies to.  The wsi is provided in the callback but it has not yet
    returned from the client connect api to give that wsi to the user code.

    To solve that there is a new member added to client connect info struct,
    pwsi, which lets you pass a pointer to a struct wsi * in the user code
    that will get filled in with the new wsi.  That happens before any
    callbacks could be provoked, and it is updated to NULL if the connect
    action fails before returning from the client connect api.
2016-07-14 08:57:27 +08:00
Andy Green
f25eefdd41 reduce log spew and document test-server variants 2016-07-14 08:57:27 +08:00
Andy Green
9ec76d4b72 test-libev add server-status protocol 2016-07-14 08:57:27 +08:00
Andy Green
7f92ee802c lws_bind_protocol
When using http/1.1+ keepalive and mounts, the relationship between
a connection and a protocol becomes dynamic.  The same connection might
visit different bits of the url space served by different mounts using
different protocols.

This patch ensures protocols can cleanly manage their per-connection
allocations by using the following callbacks when the protocol changes

 LWS_CALLBACK_HTTP_BIND_PROTOCOL
 LWS_CALLBACK_HTTP_DROP_PROTOCOL

For example if the pss wants to malloc stuff at runtime, it should do it
in LWS_CALLBACK_HTTP_BIND_PROTOCOL or later, and clean it up in
...DROP_PROTOCOL.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-06-18 09:36:27 +08:00
Andy Green
7a2fc442b6 protocol generic sessions
Signed-off-by: Andy Green <andy@warmcat.com>
2016-06-18 06:44:31 +08:00
Andy Green
c55fd27d75 introduce urlencode decode and sql escape public apis
This adds

 - simple lws_urlencode()
 - simple lws_urldecode()
 - simple lws_sql_purify

Those expect the data to all be there and process it up until
the first '\0'.

There is also a larger opaque apis for handling POST_BODY urldecode.  To
enable these, you need to give cmake -DLWS_WITH_STATEFUL_URLDECODE=1 (or
arrange any larger feature that relies on it sets that in CMakeLists.txt)

 - stateful urldecode with parameter array

These have create / process / destroy semantics on a struct that maintains
decode state.

Stateful urldecode is capable of dealing with large POST data in multiple
POST_BODY callbacks cleanly, eg, file transfer by POST.

Stateful urldecode with parameter array wraps the above with a canned
callback that stores the urldecoded data and indexes them in a pointer
array matching an array of parameter names.

You may also pass it an optional callback when creating it, that will recieve
uploaded file content.

The test html is updated to support both urlencoded and multipart forms,
with some javascript to do clientside validation of an arbitrary 100KB
file size limit (there is no file size limit in the apis).

Signed-off-by: Andy Green <andy@warmcat.com>
2016-06-14 12:04:38 +08:00
Alexander Bruines
ed7c63e07d Android: update to use SDK Python script
The latest Android SDK updates deprecate the shell script
 used to create a standalone toolchain. This patch updates the Makefile for
 the Android test-client to use the new Python script to create the standalone
 toolchains.
2016-06-07 02:42:32 +08:00
Alexander Bruines
d6fba75433 Adroid test-server client 2016-05-28 19:51:33 +08:00
Andy Green
7a9970f90d win fix warnings from appveyor
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-15 08:31:01 +08:00
Andy Green
8ef14c0e0a lwsws conf mount extra mimetypes
This patch adds the ability to provide extra mimtypes on a mount.

lwsws conf learns how to do them.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-14 10:22:56 +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
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
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
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
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
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
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
Stephan Eberle
67729c954f Eliminated compile warning in test-client.c 2016-04-27 07:38:52 +08:00
Andy Green
f79534e0a4 post example in test server
https://github.com/warmcat/libwebsockets/issues/501

This demonstrates how to do a 303 redirect on POST and provide
the results there, in both libwebsockets-test-server and the
plugin version.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-25 10:04:49 +08:00
Andy Green
1536c5beb6 coverity 160160/160161 test server commanline args strncpy NUL management
Just test app argument string handling, it is "HIGH" impact as Coverity
says but it's not network-accessible or in the library.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-23 07:21:48 +08:00
Andy Green
c673125ce0 client http
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-18 20:05:43 +08:00
Andy Green
451cee5d47 polarssl implementation
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-18 20:05:43 +08:00
Alexander Bruines
ddd9bfaaac Add testapps support for client certs and CRLs
AG: plumb into cmake to avoid travis mac blowing up
2016-04-14 20:59:16 +08:00
Andy Green
f5efa74cb7 cgi post
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-13 11:53:40 +08:00
Andy Green
a5e73a1a4b lwsws cgi integration
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-13 11:53:40 +08:00
Andy Green
d459a6fadc lwsws redirect and correct vhost selection before accept
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-08 18:38:06 +08:00
Andy Green
150233d61f urldecode forbid malformed
And update attack.sh to confirm the new test cases

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-07 10:08:35 +08:00
Andy Green
020770566e plugins
This adds support for dynamically loaded plugins at runtime, which
can expose their own protocols or extensions transparently.

With these changes lwsws defaults to OFF in cmake, and if enabled it
automatically enables plugins and libuv support.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-07 09:38:08 +08:00
Meir Yanovich
d5ff4bf1bc win32 needs strange strftime args 2016-04-05 19:15:34 +08:00
Andy Green
a19ff9b24d uri processing reject paths not starting with slash
https://github.com/warmcat/libwebsockets/issues/481

Return 403 Forbidden if we don't end up with a uri path starting with /

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-05 06:58:04 +08:00