aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2025-02-16 13:44:23 +0000
committerMatthew Wild <mwild1@gmail.com>2025-02-16 13:44:23 +0000
commit14c171ab612fa55966524c01661de41673683e61 (patch)
treea6a649ab400937d91cd3fd95bf118aec759f13e0 /plugins
parent5c2dbef89da68a8a8312a399649429cad721f6cb (diff)
parent573e9f27169c5791c81d0548149afca880395bda (diff)
downloadprosody-14c171ab612fa55966524c01661de41673683e61.tar.gz
prosody-14c171ab612fa55966524c01661de41673683e61.zip
Merge 13.0->trunk
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_bosh.lua2
-rw-r--r--plugins/mod_http_altconnect.lua52
-rw-r--r--plugins/mod_websocket.lua2
3 files changed, 56 insertions, 0 deletions
diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua
index 091a7d81..fc2c92ae 100644
--- a/plugins/mod_bosh.lua
+++ b/plugins/mod_bosh.lua
@@ -557,6 +557,8 @@ function module.add_host(module)
["POST /"] = handle_POST;
};
});
+
+ module:depends("http_altconnect", true);
end
if require"prosody.core.modulemanager".get_modules_for_host("*"):contains(module.name) then
diff --git a/plugins/mod_http_altconnect.lua b/plugins/mod_http_altconnect.lua
new file mode 100644
index 00000000..9252433e
--- /dev/null
+++ b/plugins/mod_http_altconnect.lua
@@ -0,0 +1,52 @@
+-- mod_http_altconnect
+-- XEP-0156: Discovering Alternative XMPP Connection Methods
+
+module:depends"http";
+
+local mm = require "prosody.core.modulemanager";
+local json = require"prosody.util.json";
+local st = require"prosody.util.stanza";
+local array = require"prosody.util.array";
+
+local advertise_bosh = module:get_option_boolean("advertise_bosh", true);
+local advertise_websocket = module:get_option_boolean("advertise_websocket", true);
+
+local function get_supported()
+ local uris = array();
+ if advertise_bosh and (mm.is_loaded(module.host, "bosh") or mm.is_loaded("*", "bosh")) then
+ uris:push({ rel = "urn:xmpp:alt-connections:xbosh", href = module:http_url("bosh", "/http-bind") });
+ end
+ if advertise_websocket and (mm.is_loaded(module.host, "websocket") or mm.is_loaded("*", "websocket")) then
+ uris:push({ rel = "urn:xmpp:alt-connections:websocket", href = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws") });
+ end
+ return uris;
+end
+
+
+local function GET_xml(event)
+ local response = event.response;
+ local xrd = st.stanza("XRD", { xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' });
+ local uris = get_supported();
+ for _, method in ipairs(uris) do
+ xrd:tag("Link", method):up();
+ end
+ response.headers.content_type = "application/xrd+xml"
+ response.headers.access_control_allow_origin = "*";
+ return '<?xml version="1.0" encoding="UTF-8"?>' .. tostring(xrd);
+end
+
+local function GET_json(event)
+ local response = event.response;
+ local jrd = { links = get_supported() };
+ response.headers.content_type = "application/json"
+ response.headers.access_control_allow_origin = "*";
+ return json.encode(jrd);
+end;
+
+module:provides("http", {
+ default_path = "/.well-known";
+ route = {
+ ["GET /host-meta"] = GET_xml;
+ ["GET /host-meta.json"] = GET_json;
+ };
+});
diff --git a/plugins/mod_websocket.lua b/plugins/mod_websocket.lua
index 7120f3cc..dfc1a215 100644
--- a/plugins/mod_websocket.lua
+++ b/plugins/mod_websocket.lua
@@ -367,6 +367,8 @@ function module.add_host(module)
};
});
+ module:depends("http_altconnect", true);
+
module:hook("c2s-read-timeout", keepalive, -0.9);
end