# HG changeset patch # User Matthew Wild # Date 1646411621 0 # Node ID 0fd58f54d6537eca4f6041ed3564d5d7efbb9e9b # Parent f0be98bab9dd5756275763a83b01e54dd48342a2# Parent 713f8ee9e1b40c799ca3286cfa013ea302f334a0 Merge config-updates+check-turn from timber diff -r 713f8ee9e1b4 -r 0fd58f54d653 CHANGES --- a/CHANGES Fri Mar 04 16:13:05 2022 +0000 +++ b/CHANGES Fri Mar 04 16:33:41 2022 +0000 @@ -58,6 +58,7 @@ - MUC: support for XEP-0421 occupant identifiers - `prosodyctl check connectivity` via observe.jabber.network - libunbound for DNS queries +- The POSIX poll() API used by server_epoll on \*nix other than Linux ## Changes diff -r 713f8ee9e1b4 -r 0fd58f54d653 GNUmakefile --- a/GNUmakefile Fri Mar 04 16:13:05 2022 +0000 +++ b/GNUmakefile Fri Mar 04 16:33:41 2022 +0000 @@ -31,23 +31,36 @@ -$(MAKE) -C certs localhost.crt example.com.crt endif -CMODULES=util/encodings.so util/encodings.so util/pposix.so util/signal.so util/struct.so +install-etc: prosody.cfg.lua.install + $(MKDIR) $(CONFIG) + $(MKDIR) $(CONFIG)/certs + $(INSTALL_DATA) certs/* $(CONFIG)/certs + test -f $(CONFIG)/prosody.cfg.lua || $(INSTALL_DATA) prosody.cfg.lua.install $(CONFIG)/prosody.cfg.lua -install: prosody.install prosodyctl.install prosody.cfg.lua.install $(CMODULES) - $(MKDIR) $(BIN) $(CONFIG) $(MODULES) $(SOURCE) - $(MKDIR_PRIVATE) $(DATA) - $(MKDIR) $(MAN)/man1 - $(MKDIR) $(CONFIG)/certs - $(MKDIR) $(SOURCE)/core $(SOURCE)/net $(SOURCE)/util +install-bin: prosody.install prosodyctl.install + $(MKDIR) $(BIN) $(INSTALL_EXEC) ./prosody.install $(BIN)/prosody $(INSTALL_EXEC) ./prosodyctl.install $(BIN)/prosodyctl + +install-core: + $(MKDIR) $(SOURCE) + $(MKDIR) $(SOURCE)/core $(INSTALL_DATA) core/*.lua $(SOURCE)/core + +install-net: + $(MKDIR) $(SOURCE) + $(MKDIR) $(SOURCE)/net $(INSTALL_DATA) net/*.lua $(SOURCE)/net $(MKDIR) $(SOURCE)/net/http $(SOURCE)/net/resolvers $(SOURCE)/net/websocket $(INSTALL_DATA) net/http/*.lua $(SOURCE)/net/http $(INSTALL_DATA) net/resolvers/*.lua $(SOURCE)/net/resolvers $(INSTALL_DATA) net/websocket/*.lua $(SOURCE)/net/websocket + +install-util: util/encodings.so util/encodings.so util/pposix.so util/signal.so util/struct.so + $(MKDIR) $(SOURCE) + $(MKDIR) $(SOURCE)/util $(INSTALL_DATA) util/*.lua $(SOURCE)/util + $(MAKE) install -C util-src $(INSTALL_DATA) util/*.so $(SOURCE)/util $(MKDIR) $(SOURCE)/util/sasl $(INSTALL_DATA) util/sasl/*.lua $(SOURCE)/util/sasl @@ -55,17 +68,27 @@ $(INSTALL_DATA) util/human/*.lua $(SOURCE)/util/human $(MKDIR) $(SOURCE)/util/prosodyctl $(INSTALL_DATA) util/prosodyctl/*.lua $(SOURCE)/util/prosodyctl + +install-plugins: + $(MKDIR) $(MODULES) $(MKDIR) $(MODULES)/mod_pubsub $(MODULES)/adhoc $(MODULES)/muc $(MODULES)/mod_mam $(INSTALL_DATA) plugins/*.lua $(MODULES) $(INSTALL_DATA) plugins/mod_pubsub/*.lua $(MODULES)/mod_pubsub $(INSTALL_DATA) plugins/adhoc/*.lua $(MODULES)/adhoc $(INSTALL_DATA) plugins/muc/*.lua $(MODULES)/muc $(INSTALL_DATA) plugins/mod_mam/*.lua $(MODULES)/mod_mam - $(INSTALL_DATA) certs/* $(CONFIG)/certs + +install-man: + $(MKDIR) $(MAN)/man1 $(INSTALL_DATA) man/prosodyctl.man $(MAN)/man1/prosodyctl.1 - test -f $(CONFIG)/prosody.cfg.lua || $(INSTALL_DATA) prosody.cfg.lua.install $(CONFIG)/prosody.cfg.lua + +install-meta: -test -f prosody.version && $(INSTALL_DATA) prosody.version $(SOURCE)/prosody.version - $(MAKE) install -C util-src + +install-data: + $(MKDIR_PRIVATE) $(DATA) + +install: install-util install-net install-core install-plugins install-bin install-etc install-man install-meta install-data clean: rm -f prosody.install diff -r 713f8ee9e1b4 -r 0fd58f54d653 core/certmanager.lua --- a/core/certmanager.lua Fri Mar 04 16:13:05 2022 +0000 +++ b/core/certmanager.lua Fri Mar 04 16:33:41 2022 +0000 @@ -120,7 +120,7 @@ if f then -- TODO look for chained certificates local firstline = f:read(); - if firstline == "-----BEGIN CERTIFICATE-----" then + if firstline == "-----BEGIN CERTIFICATE-----" and lfs.attributes(find_matching_key(full), "mode") == "file" then f:seek("set") local cert = ssl.loadcertificate(f:read("*a")) -- TODO if more than one cert is found for a name, the most recently diff -r 713f8ee9e1b4 -r 0fd58f54d653 core/portmanager.lua --- a/core/portmanager.lua Fri Mar 04 16:13:05 2022 +0000 +++ b/core/portmanager.lua Fri Mar 04 16:33:41 2022 +0000 @@ -216,7 +216,9 @@ end function get_service_at(interface, port) - local data = active_services:search(nil, interface, port)[1][1]; + local data = active_services:search(nil, interface, port); + if not data or not data[1] or not data[1][1] then return nil, "not-found"; end + data = data[1][1]; return data.service, data.server; end diff -r 713f8ee9e1b4 -r 0fd58f54d653 makefile --- a/makefile Fri Mar 04 16:13:05 2022 +0000 +++ b/makefile Fri Mar 04 16:33:41 2022 +0000 @@ -30,21 +30,39 @@ $(MAKE) -C certs localhost.crt example.com.crt .endif -install: prosody.install prosodyctl.install prosody.cfg.lua.install util/encodings.so util/encodings.so util/pposix.so util/signal.so - $(MKDIR) $(BIN) $(CONFIG) $(MODULES) $(SOURCE) - $(MKDIR_PRIVATE) $(DATA) - $(MKDIR) $(MAN)/man1 +install-etc: prosody.cfg.lua.install + $(MKDIR) $(CONFIG) $(MKDIR) $(CONFIG)/certs - $(MKDIR) $(SOURCE)/core $(SOURCE)/net $(SOURCE)/util + test -f $(CONFIG)/prosody.cfg.lua || $(INSTALL_DATA) prosody.cfg.lua.install $(CONFIG)/prosody.cfg.lua +.if $(EXCERTS) == "yes" + $(INSTALL_DATA) certs/localhost.crt certs/localhost.key $(CONFIG)/certs + $(INSTALL_DATA) certs/example.com.crt certs/example.com.key $(CONFIG)/certs +.endif + +install-bin: prosody.install prosodyctl.install + $(MKDIR) $(BIN) $(INSTALL_EXEC) ./prosody.install $(BIN)/prosody $(INSTALL_EXEC) ./prosodyctl.install $(BIN)/prosodyctl + +install-core: + $(MKDIR) $(SOURCE) + $(MKDIR) $(SOURCE)/core $(INSTALL_DATA) core/*.lua $(SOURCE)/core + +install-net: + $(MKDIR) $(SOURCE) + $(MKDIR) $(SOURCE)/net $(INSTALL_DATA) net/*.lua $(SOURCE)/net $(MKDIR) $(SOURCE)/net/http $(SOURCE)/net/resolvers $(SOURCE)/net/websocket $(INSTALL_DATA) net/http/*.lua $(SOURCE)/net/http $(INSTALL_DATA) net/resolvers/*.lua $(SOURCE)/net/resolvers $(INSTALL_DATA) net/websocket/*.lua $(SOURCE)/net/websocket + +install-util: util/encodings.so util/encodings.so util/pposix.so util/signal.so + $(MKDIR) $(SOURCE) + $(MKDIR) $(SOURCE)/util $(INSTALL_DATA) util/*.lua $(SOURCE)/util + $(MAKE) install -C util-src $(INSTALL_DATA) util/*.so $(SOURCE)/util $(MKDIR) $(SOURCE)/util/sasl $(INSTALL_DATA) util/sasl/*.lua $(SOURCE)/util/sasl @@ -52,20 +70,27 @@ $(INSTALL_DATA) util/human/*.lua $(SOURCE)/util/human $(MKDIR) $(SOURCE)/util/prosodyctl $(INSTALL_DATA) util/prosodyctl/*.lua $(SOURCE)/util/prosodyctl + +install-plugins: + $(MKDIR) $(MODULES) $(MKDIR) $(MODULES)/mod_pubsub $(MODULES)/adhoc $(MODULES)/muc $(MODULES)/mod_mam $(INSTALL_DATA) plugins/*.lua $(MODULES) $(INSTALL_DATA) plugins/mod_pubsub/*.lua $(MODULES)/mod_pubsub $(INSTALL_DATA) plugins/adhoc/*.lua $(MODULES)/adhoc $(INSTALL_DATA) plugins/muc/*.lua $(MODULES)/muc $(INSTALL_DATA) plugins/mod_mam/*.lua $(MODULES)/mod_mam -.if $(EXCERTS) == "yes" - $(INSTALL_DATA) certs/localhost.crt certs/localhost.key $(CONFIG)/certs - $(INSTALL_DATA) certs/example.com.crt certs/example.com.key $(CONFIG)/certs -.endif + +install-man: + $(MKDIR) $(MAN)/man1 $(INSTALL_DATA) man/prosodyctl.man $(MAN)/man1/prosodyctl.1 - test -f $(CONFIG)/prosody.cfg.lua || $(INSTALL_DATA) prosody.cfg.lua.install $(CONFIG)/prosody.cfg.lua + +install-meta: -test -f prosody.version && $(INSTALL_DATA) prosody.version $(SOURCE)/prosody.version - $(MAKE) install -C util-src + +install-data: + $(MKDIR_PRIVATE) $(DATA) + +install: install-util install-net install-core install-plugins install-bin install-etc install-man install-meta install-data clean: rm -f prosody.install diff -r 713f8ee9e1b4 -r 0fd58f54d653 plugins/mod_c2s.lua --- a/plugins/mod_c2s.lua Fri Mar 04 16:13:05 2022 +0000 +++ b/plugins/mod_c2s.lua Fri Mar 04 16:33:41 2022 +0000 @@ -433,7 +433,7 @@ end, -80); module:hook("server-stopping", function(event) - local wait, done = async.waiter(); + local wait, done = async.waiter(1, true); module:hook("c2s-closed", function () if next(sessions) == nil then done(); end end) @@ -446,7 +446,7 @@ -- Wait for them to close properly if they haven't already if next(sessions) ~= nil then - add_task(stream_close_timeout+1, done); + add_task(stream_close_timeout+1, function () done() end); module:log("info", "Waiting for sessions to close"); wait(); end diff -r 713f8ee9e1b4 -r 0fd58f54d653 plugins/mod_carbons.lua --- a/plugins/mod_carbons.lua Fri Mar 04 16:13:05 2022 +0000 +++ b/plugins/mod_carbons.lua Fri Mar 04 16:33:41 2022 +0000 @@ -69,6 +69,12 @@ return false, "default"; end +module:hook("carbons-should-copy", function (event) + local should, why = should_copy(event.stanza); + event.reason = why; + return should; +end, -1) + local function message_handler(event, c2s) local origin, stanza = event.origin, event.stanza; local orig_type = stanza.attr.type or "normal"; @@ -101,7 +107,9 @@ return -- No use in sending carbons to an offline user end - local should, why = should_copy(stanza, c2s, bare_jid); + local event_payload = { stanza = stanza; session = origin }; + local should = module:fire_event("carbons-should-copy", event_payload); + local why = event_payload.reason; if not should then module:log("debug", "Not copying stanza: %s (%s)", stanza:top_tag(), why); diff -r 713f8ee9e1b4 -r 0fd58f54d653 plugins/mod_mam/mod_mam.lua --- a/plugins/mod_mam/mod_mam.lua Fri Mar 04 16:13:05 2022 +0000 +++ b/plugins/mod_mam/mod_mam.lua Fri Mar 04 16:33:41 2022 +0000 @@ -54,7 +54,7 @@ local use_total = module:get_option_boolean("mam_include_total", true); function schedule_cleanup() - -- replaced by non-noop later if cleanup is enabled + -- replaced later if cleanup is enabled end -- Handle prefs. @@ -311,7 +311,7 @@ return stanza; end -local function should_store(stanza, c2s) --> boolean, reason: string +local function should_store(stanza) --> boolean, reason: string local st_type = stanza.attr.type or "normal"; -- FIXME pass direction of stanza and use that along with bare/full JID addressing -- for more accurate MUC / type=groupchat check @@ -320,7 +320,7 @@ -- Headline messages are ephemeral by definition return false, "headline"; end - if st_type == "error" and not c2s then + if st_type == "error" then -- Errors not sent sent from a local client -- Why would a client send an error anyway? if jid_resource(stanza.attr.to) then @@ -380,6 +380,12 @@ return false, "default"; end +module:hook("archive-should-store", function (event) + local should, why = should_store(event.stanza); + event.reason = why; + return should; +end, -1) + -- Handle messages local function message_handler(event, c2s) local origin, stanza = event.origin, event.stanza; @@ -396,9 +402,12 @@ -- Filter out that claim to be from us event.stanza = strip_stanza_id(stanza, store_user); - local should, why = should_store(stanza, c2s); + local event_payload = { stanza = stanza; session = origin }; + local should = module:fire_event("archive-should-store", event_payload); + local why = event_payload.reason; + if not should then - log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), why); + log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), event_payload.reason); return; end diff -r 713f8ee9e1b4 -r 0fd58f54d653 plugins/mod_s2s.lua --- a/plugins/mod_s2s.lua Fri Mar 04 16:13:05 2022 +0000 +++ b/plugins/mod_s2s.lua Fri Mar 04 16:33:41 2022 +0000 @@ -973,7 +973,7 @@ end end - local wait, done = async.waiter(); + local wait, done = async.waiter(1, true); module:hook("s2s-closed", function () if next(sessions) == nil then done(); end end, 1) @@ -987,7 +987,7 @@ -- Wait for them to close properly if they haven't already if next(sessions) ~= nil then module:log("info", "Waiting for sessions to close"); - add_task(stream_close_timeout + 1, done); + add_task(stream_close_timeout + 1, function () done() end); wait(); end diff -r 713f8ee9e1b4 -r 0fd58f54d653 teal-src/util/poll.d.tl --- a/teal-src/util/poll.d.tl Fri Mar 04 16:13:05 2022 +0000 +++ b/teal-src/util/poll.d.tl Fri Mar 04 16:33:41 2022 +0000 @@ -17,8 +17,15 @@ local record lib new : function () : state + EEXIST : integer + EMFILE : integer ENOENT : integer - EEXIST : integer + enum api_backend + "epoll" + "poll" + "select" + end + api : api_backend end return lib diff -r 713f8ee9e1b4 -r 0fd58f54d653 util-src/poll.c --- a/util-src/poll.c Fri Mar 04 16:13:05 2022 +0000 +++ b/util-src/poll.c Fri Mar 04 16:33:41 2022 +0000 @@ -1,7 +1,7 @@ /* * Lua polling library - * Copyright (C) 2017-2018 Kim Alvefur + * Copyright (C) 2017-2022 Kim Alvefur * * This project is MIT licensed. Please see the * COPYING file in the source package for more information. @@ -12,8 +12,15 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) #define USE_EPOLL +#define POLL_BACKEND "epoll" +#elif defined(__unix__) +#define USE_POLL +#define POLL_BACKEND "poll" +#else +#define USE_SELECT +#define POLL_BACKEND "select" #endif #ifdef USE_EPOLL @@ -21,18 +28,21 @@ #ifndef MAX_EVENTS #define MAX_EVENTS 64 #endif -#else +#endif +#ifdef USE_POLL +#include +#ifndef MAX_EVENTS +#define MAX_EVENTS 10000 +#endif +#endif +#ifdef USE_SELECT #include #endif #include #include -#ifdef USE_EPOLL -#define STATE_MT "util.poll" -#else -#define STATE_MT "util.poll