view mod_register_oob_url/mod_register_oob_url.lua @ 3656:3e0f4d727825

mod_vcard_muc: Add an alternative method of signaling avatar change When the avatar has been changed, a signal is sent that the room configuration has changed. Clients then do a disco#info query to find the SHA-1 of the new avatar. They can then fetch it as before, or not if they have it cached already. This is meant to be less disruptive than signaling via presence, which caused problems for some clients. If clients transition to the new method, the old one can eventually be removed. The namespace is made up while waiting for standardization. Otherwise it is very close to what's described in https://xmpp.org/extensions/inbox/muc-avatars.html
author Kim Alvefur <zash@zash.se>
date Sun, 25 Aug 2019 20:46:43 +0200
parents a7c2df6b2662
children
line wrap: on
line source

-- Register via OOB URL
-- Copyright (c) 2018 Daniel Gultsch
--
-- This module is MIT/X11 licensed
--

local st = require "util.stanza";
local namespace = "http://jabber.org/features/iq-register"
local register_stream_feature = st.stanza("register", {xmlns=namespace}):up();
local allow_registration = module:get_option_boolean("allow_registration", false);
local registration_url = module:get_option_string("register_oob_url", nil)

if allow_registration then
	module:log("info","obb registration is disabled as long as IBR is allowed. Set `allow_registration` to false")
end

if not registration_url then
	module:log("info","registration url not configured. Add `register_oob_url` to prosody.cfg")
end

local function on_stream_features(event)
	if not registration_url then
		return
	end
	local session, features = event.origin, event.features;
	if session.type == "c2s_unauthed" and not allow_registration then
		features:add_child(register_stream_feature);
	end
end

local function on_registration_requested(event)
	local session, stanza = event.origin, event.stanza
	if session.type ~= "c2s_unauthed" or stanza.attr.type ~= "get" then
		return
	end
	if not allow_registration and registration_url then
		local reply = st.reply(stanza)
		reply:query("jabber:iq:register")
			:tag("x", {xmlns = "jabber:x:oob"})
				:tag("url"):text(registration_url);
		return session.send(reply)
	end
end

module:hook("stream-features", on_stream_features)
module:hook("stanza/iq/jabber:iq:register:query", on_registration_requested, 1)

-- vim: noexpandtab tabstop=4 shiftwidth=4