Mercurial > prosody-modules
annotate mod_register_oob_url/mod_register_oob_url.lua @ 5119:048e339706ba
mod_rest: Remove manual reference expansion in schema
This hack was originally added to reduce the number of definitions of
common attributes (type, to, from etc) and payloads (e.g. delay). This
predated pointers and references, and until now was needed because
parsing picked out the correct stanza kind from the schema, which broke
internal references.
Removing this hack paves the way for allowing the schema to be
configured or customized more easily.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 20 Dec 2022 21:48:28 +0100 |
parents | a7c2df6b2662 |
children |
rev | line source |
---|---|
2860
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
1 -- Register via OOB URL |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
2 -- Copyright (c) 2018 Daniel Gultsch |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
3 -- |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
4 -- This module is MIT/X11 licensed |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
5 -- |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
6 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
7 local st = require "util.stanza"; |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
8 local namespace = "http://jabber.org/features/iq-register" |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
9 local register_stream_feature = st.stanza("register", {xmlns=namespace}):up(); |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
10 local allow_registration = module:get_option_boolean("allow_registration", false); |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
11 local registration_url = module:get_option_string("register_oob_url", nil) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
12 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
13 if allow_registration then |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
14 module:log("info","obb registration is disabled as long as IBR is allowed. Set `allow_registration` to false") |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
15 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
16 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
17 if not registration_url then |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
18 module:log("info","registration url not configured. Add `register_oob_url` to prosody.cfg") |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
19 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
20 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
21 local function on_stream_features(event) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
22 if not registration_url then |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
23 return |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
24 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
25 local session, features = event.origin, event.features; |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
26 if session.type == "c2s_unauthed" and not allow_registration then |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
27 features:add_child(register_stream_feature); |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
28 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
29 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
30 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
31 local function on_registration_requested(event) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
32 local session, stanza = event.origin, event.stanza |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
33 if session.type ~= "c2s_unauthed" or stanza.attr.type ~= "get" then |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
34 return |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
35 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
36 if not allow_registration and registration_url then |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
37 local reply = st.reply(stanza) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
38 reply:query("jabber:iq:register") |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
39 :tag("x", {xmlns = "jabber:x:oob"}) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
40 :tag("url"):text(registration_url); |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
41 return session.send(reply) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
42 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
43 end |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
44 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
45 module:hook("stream-features", on_stream_features) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
46 module:hook("stanza/iq/jabber:iq:register:query", on_registration_requested, 1) |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
47 |
a7c2df6b2662
mod_registration_oob_url: inital commit. simple/straight forward module to advertise oob registration url
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
48 -- vim: noexpandtab tabstop=4 shiftwidth=4 |