Mercurial > prosody-modules
comparison mod_privilege/mod_privilege.lua @ 1662:d440a22fa0af
mod_privilege: advertise_perm method now use session.send instead of module:send to avoid to go back in hook
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 06 Apr 2015 02:08:09 +0200 |
parents | 69aa2b54ba8a |
children | ca07a6ada631 |
comparison
equal
deleted
inserted
replaced
1661:69aa2b54ba8a | 1662:d440a22fa0af |
---|---|
28 | 28 |
29 --> Permissions management <-- | 29 --> Permissions management <-- |
30 | 30 |
31 privileges = module:get_option("privileged_entities", {}) | 31 privileges = module:get_option("privileged_entities", {}) |
32 | 32 |
33 function advertise_perm(to_jid, perms) | 33 function advertise_perm(session, to_jid, perms) |
34 -- send <message/> stanza to advertise permissions | 34 -- send <message/> stanza to advertise permissions |
35 -- as expained in section 4.2 | 35 -- as expained in section 4.2 |
36 local message = st.message({to=to_jid}) | 36 local message = st.message({to=to_jid}) |
37 :tag("privilege", {xmlns=_PRIV_ENT_NS}) | 37 :tag("privilege", {xmlns=_PRIV_ENT_NS}) |
38 | 38 |
39 for _, perm in pairs({'roster', 'message', 'presence'}) do | 39 for _, perm in pairs({'roster', 'message', 'presence'}) do |
40 if perms[perm] then | 40 if perms[perm] then |
41 message:tag("perm", {access=perm, type=perms[perm]}):up() | 41 message:tag("perm", {access=perm, type=perms[perm]}):up() |
42 end | 42 end |
43 end | 43 end |
44 | 44 session.send(message) |
45 module:send(message) | 45 end |
46 | |
46 end | 47 end |
47 | 48 |
48 function on_auth(event) | 49 function on_auth(event) |
49 -- Check if entity is privileged according to configuration, | 50 -- Check if entity is privileged according to configuration, |
50 -- and set session.privileges accordingly | 51 -- and set session.privileges accordingly |
69 end | 70 end |
70 end | 71 end |
71 if session.type == "component" then | 72 if session.type == "component" then |
72 -- we send the message stanza only for component | 73 -- we send the message stanza only for component |
73 -- it will be sent at first <presence/> for other entities | 74 -- it will be sent at first <presence/> for other entities |
74 advertise_perm(bare_jid, ent_priv) | 75 advertise_perm(session, bare_jid, ent_priv) |
75 end | 76 end |
76 end | 77 end |
77 | 78 |
78 session.privileges = ent_priv | 79 session.privileges = ent_priv |
79 end | 80 end |
81 function on_presence(event) | 82 function on_presence(event) |
82 -- Permission are already checked at this point, | 83 -- Permission are already checked at this point, |
83 -- we only advertise them to the entity | 84 -- we only advertise them to the entity |
84 local session, stanza = event.origin, event.stanza; | 85 local session, stanza = event.origin, event.stanza; |
85 if session.privileges then | 86 if session.privileges then |
86 advertise_perm(session.full_jid, session.privileges) | 87 advertise_perm(session, session.full_jid, session.privileges) |
87 end | 88 end |
88 end | 89 end |
89 | 90 |
90 module:hook('authentication-success', on_auth) | 91 module:hook('authentication-success', on_auth) |
91 module:hook('component-authenticated', on_auth) | 92 module:hook('component-authenticated', on_auth) |