1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
Commit graph

168 commits

Author SHA1 Message Date
Andy Green
b6641af88d api-test: lws_struct-json: add worked example
Add support for implicit schema polymorphism
2020-05-27 08:40:12 +01:00
Andy Green
e4a9307b11 lejp: support outer element is array 2020-05-11 21:20:29 +01:00
Andy Green
9f1d019352 CTest: migrate and deprecate existing selftest scripts
Replace the bash selftest plumbing with CTest.

To use the selftests, build with -DLWS_WITH_MINIMAL_EXAMPLES=1
and `CTEST_OUTPUT_ON_FAILURE=1 make test` or just
`make test`.

To disable tests that require internet access, also give
-DLWS_CTEST_INTERNET_AVAILABLE=0

Remove travis and appveyor scripts on master.

Remove travis and appveyor decals on README.md.
2020-05-11 15:40:13 +01:00
Andy Green
af26f0c765 lejp: correct return temp type to int
lejp_parse() return type is an int... but in the function, the temp
for it is a char.  This leads to badness that is currently worked
around by casting the return through a signed char type.

But that leads to more badness since if there's >127 bytes of buffer
left after the end of the JSON object, we misreport it.

Bite the bullet and fix the temp type, and fix up all the guys
who were working around it at the caller return casting to use the
resulting straight int.

If you are using this api, remove any casting you may have cut-
and-pasted like this

n = (int)(signed char)lejp_parse(...);

... to just be like this...

n = lejp_parse(...);
2020-05-11 15:17:14 +01:00
Andy Green
3d995cf7c5 fds: add sanity checks 2020-05-05 06:34:58 +01:00
Andy Green
cced12822b lws_dir: add rm -rf and glob filter callbacks
Bring over two general-purpose callbacks for lws_dir from Sai
2020-05-03 14:16:48 +01:00
Andy Green
fa7c86951c lws_struct: blob
Add support for blob type in sqlite3... it's unusual in that it
is created into the table schema as a column of blob type, but is
not serialized or deserialized into or from JSON or sqlite.

Because the size of blobs is open-ended, accessing them in one
hit may not be possible, eg, exceed the size of available heap.
As binary, they would have to be base64-encoded in JSON
representation and that bloating may be excessive, with, eg,
a 500MB blob.  So while they can be defined using lws_struct
schema, and coexist inside a column of a table managed by
lws_struct, they must be read and written separately.
2020-05-03 13:04:15 +01:00
Andy Green
d9f793ae12 logs: allow giving log bitfields from cmake to force build or exclusion
By default this doesn't change any existing logging behaviour at all.

But it allows you to define cmake options to force or force-disable the
build of individual log levels using new cmake option bitfields
LWS_LOGGING_BITFIELD_SET and LWS_LOGGING_BITFIELD_CLEAR.

Eg, -DLWS_LOGGING_BITFIELD_SET="(LLL_INFO)" can force INFO log level
built even in release mode.  -DLWS_LOGGING_BITFIELD_CLEAR="(LLL_NOTICE)"
will likewise remove NOTICE logging from the build regardless of
DEBUG or RELEASE mode.
2020-04-22 06:59:01 +01:00
Andy Green
40803b3e0d lws_struct: sqlite open option for create or not 2020-04-20 12:56:58 +01:00
Andy Green
a57e62d502 ctest: fixes-and-changes 2020-04-19 08:43:01 +01:00
Andy Green
886a588963 lws_dir: XFS does not report directories via dirent
If it says it's unknown, we always need to fall back on to the stat method.
2020-04-16 11:18:40 +01:00
Andy Green
63c8a23776 lws_spawn: windows
Move the unix spawn.c from lib/misc through to lib/plat/unix, and
add an implementation for windows in lib/plat/windows
2020-04-13 19:29:09 +01:00
Andy Green
acc3e9ba13 lws_struct: sqlite3: avoid chown for windows 2020-04-11 16:55:54 +01:00
Andy Green
d7294a714e windows: import tronkko's dirent.h
Win32 compatible version of dirent.h microsoft just don't seem to be
able to include themselves.

MIT license, same as lws, link to original github project in the header
2020-04-08 11:26:53 +01:00
Andy Green
d3308df40f windows: pthreads
Add support for external pthreads lib on windows and some docs about how to do.

It can build with LWS_WITH_THREADPOOL and LWS_WITH_MINIMAL_EXAMPLES including the
pthreads-dependent ones without warnings or errors on windows platform as well with this.

pthreads_t can be anything, including a struct - not a pointer-to-a-struct
but the struct itself.  These can't be cast to a void * for printing as they can
on linux, where the base type is a pointer.

Let's fix all the usage of those to determine their own thread index in terms
of the meaning to the program rather than as a tid.
2020-04-07 14:05:21 +01:00
Andy Green
2d55e18947 ss: windows build adaptations
Windows compiler finds various non-bug things to complain about when
building with SS and other options, fix them up
2020-04-06 20:25:06 +01:00
Andy Green
370ba6f5ed lws_struct: handle empty char array serialization 2020-04-05 12:06:31 +01:00
Andy Green
fb3fd499e3 threadpool: allow multiple threadpool tasks to bind to same wsi 2020-04-04 10:47:11 +01:00
Andy Green
4caeb56bec vfork
There's a subtle difference between fork and vfork... when doing the
dup() before the exec, with cfork we are still dealing with the
parent process "possessed" by the forked process briefly inbetween
the vfork() and the exec().

That matters because when we close the duplicated fds for the stdxxx
pipes, with vfork we're closing the fd we still want to hold in the
parent process.
2020-04-01 05:56:45 +01:00
Andy Green
c261f5a90e spawn: on OSX only waitpid can get return code 2020-03-24 11:21:10 +00:00
Andy Green
6d5ebd237c threadpool: lack of task when getting status should be taken as FINISHED 2020-03-21 14:43:50 +00:00
Andy Green
54029c4896 lws_struct: sqlite: order defaults to _lws_idx but may be overridden
The internal order that a dll2 of structs was written might or might not be
what the guy deserializing it cares about
2020-03-20 19:44:10 +00:00
Andy Green
44fa7e39e3 lws_dir: uv: clean up temp loop on fail 2020-03-19 14:34:29 +00:00
Andy Green
c6165f8680 lws_spawn: get result to temp si
We pass the temp si to the reap callback, we delete the lsp one beforehand.
But we were collecting the spawn retcode into the lsp one...
2020-03-18 12:20:41 +00:00
Andy Green
af20721500 threadpool: enable to use secure streams as well as direct wsi
This extends threadpool slightly so it can bind enqueued tasks to a
secure streams handle as well as a straight wsi.

Either the .wsi must be set as before, or the .ss handle if you are
using secure streams, when enqueuing a task on the taskpool.

A couple of other helpers get ss-aware wrappers if LWS_WITH_SECURE_STREAMS

Although threadpool was originally designed for server (gitohashi)
actually it's also fine working with client wsi / Secure Streams,
if you have a situation a client connection is associated with heavy
processing.
2020-03-16 13:58:07 +00:00
Andy Green
993c7c3192 fsmount: delete session dir on mount 2020-03-05 14:12:24 +00:00
Andy Green
28ce32af64 client: secure streams
Secure Streams is an optional layer on top of lws that separates policy
like endpoint selection and tls cert validation into a device JSON
policy document.

Code that wants to open a client connection just specifies a streamtype name,
and no longer deals with details like the endpoint, the protocol (!) or anything
else other than payloads and optionally generic metadata; the JSON policy
contains all the details for each streamtype.  h1, h2, ws and mqtt client
connections are supported.

Logical secure streams outlive any particular connection and supports "nailed-up"
connectivity regardless of underlying connection stability.
2020-03-04 12:17:49 +00:00
Andy Green
55ea791a77 lws_struct: store which toplevel schema matched
We can give the lws_struct parser a table of toplevel schemas, record
which one we chose so the caller can know how to interpret the result
2020-03-04 12:17:48 +00:00
Andy Green
30fc8e9caf lws_struct sqlite3
Continue with lws_struct, add sqlite support for one
level of lws_dll2_t lists of structs serialization and
deserialization, plus the matching api-test.
2020-03-04 11:00:04 +00:00
Andy Green
1da0096d4d lws_fsmount: overlayfs apis 2020-02-21 17:32:41 +00:00
Andy Green
8a7e0edb7d lws_spawn_piped: break out from cgi
The vfork optimized spawn, stdxxx and terminal handling in the cgi
implementation is quite mature and sophisticated, and useful for
other things unrelated to cgi.  Break it out into its own public
api under LWS_WITH_SPAWN, off by default.

Expand it so the parent wsi is optional, and the role and protocol
bindings for stdxxx pipes can be set.  Allow optional sul timeout
and external lws_dll2 owner for extant children.

Remove inline style from minimal http-server-cgi
2020-02-21 17:32:41 +00:00
Andy Green
6a737b7ca6 lwsac: add lwsac_extend api 2020-02-21 17:32:41 +00:00
Andy Green
4683ae2596 cmake: fix situation like mingw where toolchain file sets platform defines
https://github.com/warmcat/libwebsockets/issues/1831
2020-02-04 14:16:18 +00:00
Andy Green
774240f73b linkit: support build using public sdk
This provides support to build lws using the linkit 7697 public SDK
from here https://docs.labs.mediatek.com/resource/mt7687-mt7697/en/downloads

This toolchain has some challenges, its int32_t / uint32_t are long,
so assumptions about format strings for those being %u / %d / %x all
break.  This fixes all the cases for the features enabled by the
default cmake settings.
2020-01-17 07:45:34 +00:00
Andy Green
72a5993deb clean: explicitly include libwebsockets.h in internal c now we use stddint types earlier
Some toolchains don't bring it in soon enough by reference from
other headers
2020-01-15 12:07:20 +00:00
Andy Green
157acfc906 windows: clean type warnings
There are some minor public api type improvements rather than cast everywhere
inside lws and user code to work around them... these changed from int to
size_t

 - lws_buflist_use_segment() return
 - lws_tokenize_t .len and .token_len
 - lws_tokenize_cstr() length
 - lws_get_peer_simple() namelen
 - lws_get_peer_simple_fd() namelen, int fd -> lws_sockfd_type fd
 - lws_write_numeric_address() len
 - lws_sa46_write_numeric_address() len

These changes are typically a NOP for user code
2020-01-11 14:04:50 +00:00
Andy Green
0bfd39135e cleaning 2020-01-05 22:17:58 +00:00
Andy Green
c4ab815aaf _GNU_SOURCE: only define if not already defined
https://github.com/warmcat/libwebsockets/issues/1803
2019-12-22 18:17:45 +00:00
Andy Green
277d0e5e4c license: fix up last mentions of lgpl outside of the source file license grant part 2019-12-02 11:19:30 +00:00
Andy Green
b2a112568c cov263975: help coverity see false positive 2019-11-12 10:28:53 +00:00
Zhiwen Zheng
3299c54130 illumos: fix build errors 2019-11-04 13:49:13 +00:00
Andy Green
ef14f00f64 osx: needs sys/dirent.h 2019-11-04 13:49:13 +00:00
Andy Green
ce55c5dfe4 lwsac: fix header split optimization 2019-11-02 18:34:05 +00:00
Kristján Valur Jónsson
1b51301c8d lejp: fix warnings on windows 2019-10-23 06:36:11 +01:00
Andy Green
ebdc0ad084 lwsac-backfill
Optimizations for memory-tight systems.

Check all previous gaps first for any usage, so gaps we created when
faced with perhaps a relatively large allocation that left a lot of
the last chunk on the table can be backfilled with smaller things as
it goes on.

Separate the members that only live in the head object out of the
buffer management object, reducing the cost of new chunks.  Allocate
the head object members as the first thing in the first chunk, and
adjust all the code to look there for them.
2019-10-17 09:19:57 +01:00
Andy Green
c776ac50d6 lwsac: add blob deduplication helper
Add lwsac helper api to allow user code to perform constant string folding
easily within an lwsac.  After isolating a string or blob that it wants to store in
the lwsac and point to, it can check if the string or blob already exists earlier
in the lwsac first, and if so just point to that without copying it in again.

For some formats with repeated strings like JSON, the saving can add up to
something useful.
2019-10-17 09:19:57 +01:00
Andy Green
127e53cf98 client: multipart mime generation helpers
lws has been able to generate client multipart mime as shown
in minimal-http-client-post, but it requires a lot of user
boilerplate to handle the boundary, related transaction header,
and multipart headers.

This patch adds a client creation flag to indicate it will
carry multipart mime, which autocreates the boundary string
and applies the transaction header with it, and an api to
form the boundary headers between the different mime parts
and the terminating boundary.
2019-10-12 12:41:14 +01:00
Zhiwen Zheng
14746d9014 illumos: fixes for build warnings 2019-10-12 12:41:14 +01:00
Andy Green
6a6f365ce7 semmle: fix warnings
They're all cosmetic or minor js stuff.

Add related shield.io icons to README.
2019-09-22 09:35:07 -07:00
Andy Green
c591e1adfc asynchronous dns for ipv4 and ipv6
This adds the option to have lws do its own dns resolution on
the event loop, without blocking.  Existing implementations get
the name resolution done by the libc, which is blocking.  In
the case you are opening client connections but need to carefully
manage latency, another connection opening and doing the name
resolution becomes a big problem.

Currently it supports

 - ipv4 / A records
 - ipv6 / AAAA records
 - ipv4-over-ipv6 ::ffff:1.2.3.4 A record promotion for ipv6
 - only one server supported over UDP :53
 - nameserver discovery on linux, windows, freertos

It also has some nice advantages

 - lws-style paranoid response parsing
 - random unique tid generation to increase difficulty of poisoning
 - it's really integrated with the lws event loop, it does not spawn
   threads or use the libc resolver, and of course no blocking at all
 - platform-specific server address capturing (from /etc/resolv.conf
   on linux, windows apis on windows)
 - it has LRU caching
 - piggybacking (multiple requests before the first completes go on
   a list on the first request, not spawn multiple requests)
 - observes TTL in cache
 - TTL and timeout use lws_sul timers on the event loop
 - ipv6 pieces only built if cmake LWS_IPV6 enabled
2019-09-19 06:54:53 +01:00