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

219 commits

Author SHA1 Message Date
James Darpinian
8674bf1585 ACME: fixes
Increase polling time and poll the "order" endpoint instead of the "finalize" endpoint. These changes are required for ACME to work with Let's Encrypt as of 2024.
2024-06-24 12:36:09 +01:00
Nick
2dc148e3a3 clean: remove needless LWS_PRE
Several examples trim their buffer with an extra LWS_PRE from the end...
actually end should point to end the end of buf without a second LWS_PRE
reservation.

https://github.com/warmcat/libwebsockets/issues/2629
2022-05-04 08:43:26 +01:00
orefkov
edf670a3e6 acme: update for v2
https://github.com/warmcat/libwebsockets/issues/2609

AG: api logging updates
2022-04-11 06:39:55 +01:00
Andy Green
946b1fbff1 coverity: 2021-12-1 uplevel fixes 2022-03-15 10:28:09 +00:00
Andy Green
155b1c83b5 plugins: openmetrics_export: graceful fail if unconfigured 2022-03-15 10:28:09 +00:00
Andy Green
7e841130e0 coverity fixes 2022-01-16 10:48:11 +00:00
Andy Green
53d195022f cmake: Enable WITH_MINIMAL_EXAMPLES by default
Although many of the examples must be run from the example directory as
cwd, everyone getting started probably wants to try the examples, cmake
knows how to do it, so let's enable it by default.
2021-11-11 11:52:46 +00:00
Andy Green
270a14813f sshd: fix leak on disconnect
Disconnect wants to keep a copy of the description string, but it is never
freed.  Make it ephemeral just for the ->disconnect_reason() op so it is
cleaned out correctly.
2021-11-07 07:04:09 +00:00
Andy Green
095798d5d9 sshd: plugin: work with _BUILTIN
The sshd example has gotten crufted a few different ways.

Adapt the test-sshd protocol and callbacks to not collide with the plugin
ssh-demo exports, for BUILTIN case.

Do not build a static copy of ssh-base for test-sshd if PLUGINS_BUILTIN is
going to provide it via lws import.

Add pvo for ssh-base to enable it on to the test-sshd vhost.

Banner staging in buf[] shared some of source and dest when it was copied
in, move it up a bit to avoid this.

Add note about rsa key disable workaround on Fedora.

test-sshd uses CGI (and requires it enabled to build) because it predates
lws_spawn... lws cgi was migrated to lws_spawn, really the test=sshd needs
rewriting to use lws_spawn directly instead of cgi.
2021-11-07 07:04:09 +00:00
Jakov Smolić
252890d19c plugins: sshd: eg musl needs sys/types if available
https://github.com/warmcat/libwebsockets/issues/2477
2021-11-04 07:12:37 +00:00
Orefkov Aleksander
d1248188e0 pugins: sshd: handle window-change request
Added processing of window-change request, according to RFC 4254 6.7
https://datatracker.ietf.org/doc/html/rfc4254#section-6.7
For processing called callback pty_req with empty terminal and modes.
2021-10-19 15:39:53 +01:00
Orefkov Aleksander
2504eba456 plugins: sshd: channel fixes
In responses  with channel numbers, the sender's channel number is sent instead of the recipient's channel number.
See for example https://datatracker.ietf.org/doc/html/rfc4254#section-5.1
Putty uses channel 256 for session, and existing code break it with "Received SSH2_MSG_CHANNEL_OPEN_CONFIRMATION for nonexistent channel 0" error.
2021-10-19 10:50:09 +01:00
Orefkov Aleksander
4c5e7a37df plugins: sshd: mbedtls 3 extra adaptation
In fresh mbedtls rsa public decrypt is deprecated and not work on public keys.
Replaced by lws_genrsa_hash_sig_verify.
2021-10-19 10:50:01 +01:00
Orefkov Aleksander
e34e6fe263 plugins: sshd: sc25519 must handle last bit
This was originally commented because Coverity objected to it.
2021-10-19 06:38:45 +01:00
Andy Green
fabe78d222 Wextra
Add -Wextra (with -Wno-unused-parameter) to unix builds in addition to
-Wall -Werror.

This can successfully build everything in Sai without warnings / errors.
2021-07-04 10:29:54 +01:00
Andy Green
5d8cf03221 logs: log contexts 2021-07-01 05:20:53 +01:00
Andy Green
a481a6eb69 plugin: post: check unexpected write after protocol unbind 2021-06-14 11:20:42 +01:00
Andy Green
24abd699f6 http: parser: straighten out %00 legality
https://github.com/warmcat/libwebsockets/issues/2262

This adds a README explaining what can be expected if your URLs contain
%00, and adds a safe helper for urlargs-by-name that is length-based.

Contains fix for extra NUL on some headers

https://github.com/warmcat/libwebsockets/issues/2267
2021-04-10 09:21:33 +01:00
Andy Green
3f4623bb36 lws_metrics
There are a few build options that are trying to keep and report
various statistics

 - DETAILED_LATENCY
 - SERVER_STATUS
 - WITH_STATS

remove all those and establish a generic rplacement, lws_metrics.

lws_metrics makes its stats available via an lws_system ops function
pointer that the user code can set.

Openmetrics export is supported, for, eg, prometheus scraping.
2021-03-08 21:47:28 +00:00
Andy Green
671ffe7063 plugins: ssh: xenial warning fixes 2021-02-28 17:07:51 +00:00
Andy Green
8d5341d74e vh init: make sure protocol set 2021-02-20 13:54:32 +00:00
Andy Green
0e6df74409 plugins: add option LWS_WITH_PLUGINS_BUILTIN
Add the ability to just build plugins into the main library.
They are already designed to have a pinhole export for when
they are used as dynamic lib plugins so their namespace
does not conflict.
2021-01-31 20:24:29 +00:00
Andy Green
6497220e87 plugins: add LWS_BUILD_HASH to header and require match
Also prioritize LD_LIBRARY_PATH check for plugins first

Iterate through paths in LD_LIBRARY_PATH in order

Warn on failed plugins init but continue protocol init
2021-01-28 05:52:41 +00:00
Andy Green
d5618f6059 Wconversion: workarounds for CentOS7 2021-01-22 12:25:03 +00:00
Andy Green
60b5ca649e server_status: adapt for tags 2021-01-11 08:12:46 +00:00
Andy Green
c9731c5f17 type comparisons: fixes
This is a huge patch that should be a global NOP.

For unix type platforms it enables -Wconversion to issue warnings (-> error)
for all automatic casts that seem less than ideal but are normally concealed
by the toolchain.

This is things like passing an int to a size_t argument.  Once enabled, I
went through all args on my default build (which build most things) and
tried to make the removed default cast explicit.

With that approach it neither change nor bloat the code, since it compiles
to whatever it was doing before, just with the casts made explicit... in a
few cases I changed some length args from int to size_t but largely left
the causes alone.

From now on, new code that is relying on less than ideal casting
will complain and nudge me to improve it by warnings.
2021-01-05 10:56:38 +00:00
Andy Green
0ceba15d9c lws_lifecycle
This adds some new objects and helpers for keeping and logging
info on grouped allocations, a group is, eg, SS handles or client
wsis.

Allocated objects get a context-unique "tag" string intended to replace
%p / wsi pointers etc.  Pointers quickly become confusing when
allocations are freed and reused, the tag string won't repeat
until you produce 2^64 objects in a context.

In addition the tag string documents the object group, with prefixes
like "wsi-" or "vh-" and contain object-specific additional
information like the vhost name, address / port  or the role of the wsi.
At creation time the lws code can use a format string and args
to add whatever group-specific info makes sense, eg, a wsi bound
to a secure stream can also append the guid of the secure stream,
it's copied into the new object tag and so is still available
cleanly after the stream is destroyed if the wsi outlives it.
2021-01-04 05:26:50 +00:00
Andy Green
5c988d7714 plugins: more explicit header inclusion
32-bit Debian doesn't have these included by other includes
already and needs them explicitly.
2020-10-26 11:24:21 +00:00
Andy Green
8d88d2f4f1 plugins: use new export symbol convention 2020-10-09 21:30:49 +01:00
Andy Green
5c7b5af92a cmake: disable export visibility when building lws static
This is complicated by the fact extern on a function declaration implies
visibility... we have to make LWS_EXTERN empty when building static.

And, setting target_compile_definitions() doesn't work inside macros,
so it has to be set explicitly for the plugins.

Checking the symbol status needs nm -C -D as per

https://stackoverflow.com/questions/37934388/symbol-visibility-not-working-as-expected

after this patch, libwebsockets.a shows no symbols when checked like that and
the static-linked minimal examples only show -U for their other dynamic
imports.

In a handful of cases we use LWS_EXTERN on extern data declarations,
those then need to change to explicit extern.
2020-09-06 11:46:25 +01:00
Andy Green
c6c7ab2b44 event libs: default to building as dynamically loaded plugins
Event lib support as it has been isn't scaling well, at the low level
libevent and libev headers have a namespace conflict so they can't
both be built into the same image, and at the distro level, binding
all the event libs to libwebsockets.so makes a bloaty situation for
packaging, lws will drag in all the event libs every time.

This patch implements the plan discussed here

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

and refactors the event lib support so they are built into isolated
plugins and bound at runtime according to what the application says
it wants to use.  The event lib plugins can be packaged individually
so that only the needed sets of support are installed (perhaps none
of them if the user code is OK with the default poll() loop).  And
dependent user code can mark the specific event loop plugin package
as required so pieces are added as needed.

The eventlib-foreign example is also refactored to build the selected
lib support isolated.

A readme is added detailing the changes and how to use them.

https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.event-libs.md
2020-08-31 16:51:37 +01:00
Andy Green
d98101d1e3 plugins: generalize and provide public api
Move the common plugin scanning dir stuff to be based on lws_dir, which
already builds for windows.  Previously this was done via dirent for unix
and libuv for windows.

Reduce the dl plat stuff to just wrap instantiation and destruction of
dynlibs, establish common code in lib/misc/dir.c for plugin scanning
itself.

Migrate the libuv windows dl stuff to windows-plugins.c, so that he's
available even if later libuv loop support becomes and event lib plugin.

Remove the existing api exports scheme for plugins, just export a const struct
now which has a fixed header type but then whatever you want afterwards depending
on the class / purpose of the plugin.  Place a "class" string in the header so
there can be different kinds of plugins implying different types exported.

Make the plugin apis public and add support for filter by class string, and
per instantation / destruction callbacks so the subclassed header type can
do its thing for the plugin class.  The user provides a linked-list base
for his class of plugins, so he can manage them completely separately and
in user code / user export types.

Rip out some last hangers-on from generic sessions / tables.

This is all aimed at making the plugins support general enough so it can
provide event lib plugins later.
2020-08-31 16:51:37 +01:00
Andy Green
629c8138b1 sai: freebsd 2020-08-10 15:04:10 +01:00
Andy Green
4f84fcb124 cmake: windows: WIN32_HELPERS_PATH already ready for one-level-down CMakeLists.txt
https://github.com/warmcat/libwebsockets/issues/1992
2020-07-30 06:02:48 +01:00
Andy Green
dfa9423983 coverity: missing malloc return check
This is only coming at vhost startup, for a server that's before we
go busy with heap.  But still, it should be checked.
2020-07-15 16:18:00 +01:00
Andy Green
599625be34 remove: generic sessions
As far as I know there are no users of this, although it worked
it's basically unmaintainable due to handling the sql and JSON
manually.

Gradually better capabilities have appeared in lws, like
lws_struct abstracting out the sql and JSON, and now generic
JWT... these have been used in Sai to great effect and displaced
the only organic would-be user of this.

There is a better path to do this stuff now and no point keeping
this around.
2020-07-15 16:18:00 +01:00
Andy Green
2a772776a9 windows: for data exports use explicit extern
LWS_EXTERN needs to be empty for windows when declaring functions in the
headers.  But for data, it needs the explicit extern otherwise on windows
or mingw based builds, it thinks we are redeclaring the data each time.
2020-06-07 07:53:36 +01:00
Andy Green
c0294c3e10 clean: use lws_intptr_t where needed 2020-06-03 06:48:06 +01:00
Andy Green
286cf4357a sul: multiple timer domains
Adapt the pt sul owner list to be an array, and define two different lists,
one that acts like before and is the default for existing users, and another
that has the ability to cooperate with systemwide suspend to restrict the
interval spent suspended so that it will wake in time for the earliest
thing on this wake-suspend sul list.

Clean the api a bit and add lws_sul_cancel() that only needs the sul as the
argument.

Add a flag for client creation info to indicate that this client connection
is important enough that, eg, validity checking it to detect silently dead
connections should go on the wake-suspend sul list.  That flag is exposed in
secure streams policy so it can be added to a streamtype with
"swake_validity": true

Deprecate out the old vhost timer stuff that predates sul.  Add a flag
LWS_WITH_DEPRECATED_THINGS in cmake so users can get it back temporarily
before it will be removed in a v4.2.

Adapt all remaining in-tree users of it to use explicit suls.
2020-06-02 08:37:10 +01:00
Andy Green
b3131fdfdd cmakelist: Augean Stables refactor
Establish a new distributed CMake architecture with CMake code related to
a source directory moving to be in the subdir in its own CMakeLists.txt.
In particular, there's now one in ./lib which calls through to ones
further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc.

This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction,
and it's much easier to maintain sub-CMakeLists.txt that are in the same
directory as the sources they manage, and conceal all the details that that
level.

Child CMakelists.txt become responsible for:

 - include_directories() definition (this is not supported by CMake
   directly, it passes it back up via PARENT_SCOPE vars in helper
   macros)

 - Addition child CMakeLists.txt inclusion, for example toplevel ->
   role -> role subdir

 - Source file addition to the build

 - Dependent library path resolution... this is now a private thing
   in the child CMakeLists.txt, it just passes back any adaptations
   to include_directories() and the LIB_LIST without filling the
   parent namespace with the details
2020-05-27 08:40:12 +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
40803b3e0d lws_struct: sqlite open option for create or not 2020-04-20 12:56:58 +01: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
9a1f184915 rtos diet: http: remove headers at buildtime according to config
Headers related to ws or h2 are now elided if the ws or h2 role
is not enabled for build.  In addition, a new build-time option
LWS_WITH_HTTP_UNCOMMON_HEADERS on by default allows removal of
less-common http headers to shrink the parser footprint.

Minilex is adapted to produce 8 different versions of the lex
table, chosen at build-time according to which headers are
included in the build.

If you don't need the unusual headers, or aren't using h2 or ws,
this chops down the size of the ah and the rodata needed to hold
the parsing table from 87 strings / pointers to 49, and the
parsing table from 1177 to 696 bytes.
2020-03-04 11:00:04 +00:00
Andy Green
def2cd7017 generic-sessions: debugging 2020-02-21 17:32:41 +00:00
Andy Green
5055096e47 clean: codacy 2020-01-14 10:06:26 +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
86fe71fdf3 lws_get_random: change length to size_t for coverity 2020-01-11 07:58:37 +00:00
Andy Green
0bfd39135e cleaning 2020-01-05 22:17:58 +00:00