Changeset

4954:e8a487c42b36

merge upstream
author Goffi <goffi@goffi.org>
date Sat, 28 May 2022 16:43:04 +0200
parents 4953:7d6ae8bb95dc (current diff) 4952:ccce785f53e1 (diff)
children 4955:537054999093
files
diffstat 13 files changed, 167 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_auth_dovecot/README.markdown	Sat May 28 16:42:13 2022 +0200
+++ b/mod_auth_dovecot/README.markdown	Sat May 28 16:43:04 2022 +0200
@@ -3,6 +3,11 @@
 - 'Stage-Alpha'
 - 'Type-Auth'
 summary: Dovecot authentication module
+rockspec:
+  build:
+    modules:
+      mod_auth_dovecot: mod_auth_dovecot/mod_auth_dovecot.lua
+      mod_auth_dovecot.sasl_dovecot: mod_auth_dovecot/sasl_dovecot.lib.lua
 ...
 
 Introduction
--- a/mod_auth_dovecot/auth_dovecot/sasl_dovecot.lib.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_auth_dovecot/auth_dovecot/sasl_dovecot.lib.lua	Sat May 28 16:43:04 2022 +0200
@@ -24,6 +24,7 @@
 local t_concat = table.concat;
 local m_random = math.random;
 local tostring, tonumber = tostring, tonumber;
+local unpack = table.unpack or unpack;
 
 local socket = require "socket"
 
--- a/mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua	Sat May 28 16:43:04 2022 +0200
@@ -15,5 +15,6 @@
 		local reserved_nick = jid.resource(occupant.nick);
 		module:log("debug", "Automatically reserving nickname '%s' for <%s>", reserved_nick, user_jid);
 		room:set_affiliation_data(user_jid, "reserved_nickname", reserved_nick);
+		room._reserved_nicks = nil; -- force refresh of nickname map
 	end
 end);
--- a/mod_muc_occupant_id/README.markdown	Sat May 28 16:42:13 2022 +0200
+++ b/mod_muc_occupant_id/README.markdown	Sat May 28 16:43:04 2022 +0200
@@ -17,6 +17,6 @@
 =============
 
   ------- ------------------
-  trunk   Works
+  0.12    Built-in, not needed
   0.11    Works; except in MUC-PMs
   ------- ------------------
--- a/mod_net_proxy/README.markdown	Sat May 28 16:42:13 2022 +0200
+++ b/mod_net_proxy/README.markdown	Sat May 28 16:43:04 2022 +0200
@@ -173,5 +173,7 @@
 
   ----- -----
   trunk Works
+  0.12  Works
+  0.11  Works
   0.10  Works
   ----- -----
--- a/mod_net_proxy/mod_net_proxy.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_net_proxy/mod_net_proxy.lua	Sat May 28 16:43:04 2022 +0200
@@ -8,7 +8,7 @@
 
 -- Imports
 local softreq = require "util.dependencies".softreq;
-local bit = assert(softreq "bit" or softreq "bit32", "No bit module found. See https://prosody.im/doc/depends#bitop");
+local bit = assert(softreq "bit" or softreq "bit32" or softreq "util.bitcompat", "No bit module found. See https://prosody.im/doc/depends#bitop");
 local hex = require "util.hex";
 local ip = require "util.ip";
 local net = require "util.net";
--- a/mod_onions/mod_onions.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_onions/mod_onions.lua	Sat May 28 16:43:04 2022 +0200
@@ -10,10 +10,7 @@
 
 local softreq = require "util.dependencies".softreq;
 
-local bit;
-pcall(function() bit = require"bit"; end);
-bit = bit or softreq"bit32"
-if not bit then module:log("error", "No bit module found. Either LuaJIT 2, lua-bitop or Lua 5.2 is required"); end
+local bit = assert(softreq "bit" or softreq "bit32" or softreq "util.bitcompat", "No bit module found. See https://prosody.im/doc/depends#bitop");
 
 local band = bit.band;
 local rshift = bit.rshift;
--- a/mod_reload_modules/mod_reload_modules.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_reload_modules/mod_reload_modules.lua	Sat May 28 16:43:04 2022 +0200
@@ -8,6 +8,12 @@
 		return;
 	end
 	local configured_modules = module:get_option_inherited_set("modules_enabled", {});
+	local component_module = module:get_option_string("component_module");
+	if component_module then
+		-- Ensure awareness of the component module so that it is not unloaded
+		configured_modules:add(component_module);
+	end
+
 	-- ignore removed hosts
 	if not prosody.hosts[module.host] then
 		module:log("warn", "Ignoring host %s: host was removed...", module.host);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_rest/example/prosody_oauth.py	Sat May 28 16:43:04 2022 +0200
@@ -0,0 +1,37 @@
+from oauthlib.oauth2 import LegacyApplicationClient
+from requests_oauthlib import OAuth2Session
+
+
+class ProsodyRestClient(LegacyApplicationClient):
+    pass
+
+
+class ProsodyRestSession(OAuth2Session):
+    def __init__(self, base_url=None, token_url=None, rest_url=None, *args, **kwargs):
+        if base_url and not token_url:
+            token_url = base_url + "/oauth2/token"
+        if base_url and not rest_url:
+            rest_url = base_url + "/rest"
+        self._prosody_rest_url = rest_url
+        self._prosody_token_url = token_url
+
+        super().__init__(client=ProsodyRestClient(*args, **kwargs))
+
+    def fetch_token(self, *args, **kwargs):
+        return super().fetch_token(token_url=self._prosody_token_url, *args, **kwargs)
+
+    def xmpp(self, json=None, *args, **kwargs):
+        return self.post(self._prosody_rest_url, json=json, *args, **kwargs)
+
+
+if __name__ == "__main__":
+    # Example usage
+
+    # from prosody_oauth import ProsodyRestSession
+    from getpass import getpass
+
+    p = ProsodyRestSession(base_url=input("Base URL: "), client_id="app")
+    
+    p.fetch_token(username=input("XMPP Address: "), password=getpass("Password: "))
+
+    print(p.xmpp(json={"disco": True, "to": "jabber.org"}).json())
--- a/mod_rest/jsonmap.lib.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_rest/jsonmap.lib.lua	Sat May 28 16:43:04 2022 +0200
@@ -506,6 +506,13 @@
 		local archive = t.archive;
 		if archive["with"] or archive["start"] or archive["end"] or archive["before-id"] or archive["after-id"]
 			or archive["ids"] then
+			if type(archive["ids"]) == "string" then
+				local ids = {};
+				for id in archive["ids"]:gmatch("[^,]+") do
+					table.insert(ids, id);
+				end
+				archive["ids"] = ids;
+			end
 			archive.form = {
 				type = "submit";
 				fields = {
--- a/mod_rest/mod_rest.lua	Sat May 28 16:42:13 2022 +0200
+++ b/mod_rest/mod_rest.lua	Sat May 28 16:43:04 2022 +0200
@@ -68,6 +68,20 @@
 	end
 end
 
+local function event_suffix(jid_to)
+	local node, _, resource = jid.split(jid_to);
+	if node then
+		if resource then
+			return '/full';
+		else
+			return '/bare';
+		end
+	else
+		return '/host';
+	end
+end
+
+
 -- TODO This ought to be handled some way other than duplicating this
 -- core.stanza_router code here.
 local function compat_preevents(origin, stanza) --> boolean : handled
@@ -356,10 +370,31 @@
 			return post_errors.new("iq_tags");
 		end
 
-		return module:send_iq(payload, origin):next(
+		-- special handling of multiple responses to MAM queries primarily from
+		-- remote hosts, local go directly to origin.send()
+		local archive_event_name = "message"..event_suffix(from);
+		local archive_handler;
+		local archive_query = payload:get_child("query", "urn:xmpp:mam:2");
+		if archive_query then
+			archive_handler = function(result_event)
+				if result_event.stanza:find("{urn:xmpp:mam:2}result/@queryid") == archive_query.attr.queryid then
+					origin.send(result_event.stanza);
+					return true;
+				end
+			end
+			module:hook(archive_event_name, archive_handler, 1);
+		end
+
+		local p = module:send_iq(payload, origin):next(
 			function (result)
 				module:log("debug", "Sending[rest]: %s", result.stanza:top_tag());
 				response.headers.content_type = send_type;
+				if responses[1] then
+					local tail = responses[#responses];
+					if tail.name ~= "iq" or tail.attr.from ~= result.stanza.attr.from or tail.attr.id ~= result.stanza.attr.id then
+						origin.send(result.stanza);
+					end
+				end
 				if responses[2] then
 					return encode(send_type, responses);
 				end
@@ -377,6 +412,14 @@
 					return error;
 				end
 			end);
+
+		if archive_handler then
+			p:finally(function ()
+				module:unhook(archive_event_name, archive_handler);
+			end)
+		end
+
+		return p;
 	else
 		function origin.send(stanza)
 			module:log("debug", "Sending[rest]: %s", stanza:top_tag());
--- a/mod_rest/res/openapi.yaml	Sat May 28 16:42:13 2022 +0200
+++ b/mod_rest/res/openapi.yaml	Sat May 28 16:43:04 2022 +0200
@@ -151,6 +151,58 @@
         '200':
           $ref: '#/components/responses/success'
 
+
+  /rest/archive/{to}:
+    get:
+      tags:
+      - query
+      summary: Query a message archive
+      security:
+      - basic: []
+      - token: []
+      parameters:
+      - $ref: '#/components/parameters/to'
+      - name: with
+        in: query
+        schema:
+          type: string
+      - name: start
+        in: query
+        schema:
+          type: string
+      - name: end
+        in: query
+        schema:
+          type: string
+      - name: before-id
+        in: query
+        schema:
+          type: string
+      - name: after-id
+        in: query
+        schema:
+          type: string
+      - name: ids
+        in: query
+        schema:
+          type: string
+        description: comma-separated list of archive ids
+      - name: after
+        in: query
+        schema:
+          type: string
+      - name: before
+        in: query
+        schema:
+          type: string
+      - name: max
+        in: query
+        schema:
+          type: integer
+      responses:
+        '200':
+          $ref: '#/components/responses/success'
+
 components:
   schemas:
     stanza:
--- a/mod_rest/res/schema-xmpp.json	Sat May 28 16:42:13 2022 +0200
+++ b/mod_rest/res/schema-xmpp.json	Sat May 28 16:43:04 2022 +0200
@@ -735,6 +735,15 @@
                   "namespace" : "urn:xmpp:chat-markers:0"
                }
             },
+            "encryption" : {
+               "title" : "XEP-0380: Explicit Message Encryption",
+               "type" : "string",
+               "xml" : {
+                  "name" : "encryption",
+                  "namespace" : "urn:xmpp:eme:0",
+                  "x_single_attribute" : "namespace"
+               }
+            },
             "fallback" : {
                "title" : "XEP-0428: Fallback Indication",
                "type" : "boolean",