Software /
code /
prosody-modules
Comparison
mod_service_directories/mod_service_directories.lua @ 759:6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 01 Aug 2012 02:29:01 +0200 |
parent | 552:d1e83cb12885 |
child | 904:7648ee2d59d1 |
comparison
equal
deleted
inserted
replaced
758:295ae44b8a01 | 759:6531a029fce5 |
---|---|
12 local st = require "util.stanza"; | 12 local st = require "util.stanza"; |
13 local jid_split = require "util.jid".split; | 13 local jid_split = require "util.jid".split; |
14 local adhoc_new = module:require "adhoc".new; | 14 local adhoc_new = module:require "adhoc".new; |
15 local to_ascii = require "util.encodings".idna.to_ascii; | 15 local to_ascii = require "util.encodings".idna.to_ascii; |
16 local nameprep = require "util.encodings".stringprep.nameprep; | 16 local nameprep = require "util.encodings".stringprep.nameprep; |
17 local core_post_stanza = core_post_stanza; | |
18 local pairs, ipairs = pairs, ipairs; | 17 local pairs, ipairs = pairs, ipairs; |
19 local module = module; | 18 local module = module; |
20 local hosts = hosts; | 19 local hosts = hosts; |
21 | 20 |
22 local subscription_from = {}; | 21 local subscription_from = {}; |
37 local node, host, resource = jid_split(stanza.attr.from); | 36 local node, host, resource = jid_split(stanza.attr.from); |
38 if stanza.attr.from ~= host then return; end -- not from a host | 37 if stanza.attr.from ~= host then return; end -- not from a host |
39 | 38 |
40 local t = stanza.attr.type; | 39 local t = stanza.attr.type; |
41 if t == "probe" then | 40 if t == "probe" then |
42 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id })); | 41 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id })); |
43 elseif t == "subscribe" then | 42 elseif t == "subscribe" then |
44 subscription_from[host] = true; | 43 subscription_from[host] = true; |
45 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "subscribed" })); | 44 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "subscribed" })); |
46 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id })); | 45 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id })); |
47 add_contact(host); | 46 add_contact(host); |
48 elseif t == "subscribed" then | 47 elseif t == "subscribed" then |
49 subscription_to[host] = true; | 48 subscription_to[host] = true; |
50 query_host(host); | 49 query_host(host); |
51 elseif t == "unsubscribe" then | 50 elseif t == "unsubscribe" then |
52 subscription_from[host] = nil; | 51 subscription_from[host] = nil; |
53 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "unsubscribed" })); | 52 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "unsubscribed" })); |
54 remove_contact(host); | 53 remove_contact(host); |
55 elseif t == "unsubscribed" then | 54 elseif t == "unsubscribed" then |
56 subscription_to[host] = nil; | 55 subscription_to[host] = nil; |
57 remove_contact(host); | 56 remove_contact(host); |
58 end | 57 end |
62 function remove_contact(host, id) | 61 function remove_contact(host, id) |
63 contact_features[host] = nil; | 62 contact_features[host] = nil; |
64 contact_vcards[host] = nil; | 63 contact_vcards[host] = nil; |
65 if subscription_to[host] then | 64 if subscription_to[host] then |
66 subscription_to[host] = nil; | 65 subscription_to[host] = nil; |
67 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = id, type = "unsubscribe" })); | 66 module:send(st.presence({ from = module.host, to = host, id = id, type = "unsubscribe" })); |
68 end | 67 end |
69 if subscription_from[host] then | 68 if subscription_from[host] then |
70 subscription_from[host] = nil; | 69 subscription_from[host] = nil; |
71 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = id, type = "unsubscribed" })); | 70 module:send(st.presence({ from = module.host, to = host, id = id, type = "unsubscribed" })); |
72 end | 71 end |
73 end | 72 end |
74 function add_contact(host, id) | 73 function add_contact(host, id) |
75 if not subscription_to[host] then | 74 if not subscription_to[host] then |
76 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = id, type = "subscribe" })); | 75 module:send(st.presence({ from = module.host, to = host, id = id, type = "subscribe" })); |
77 end | 76 end |
78 end | 77 end |
79 | 78 |
80 -- Admin ad-hoc command to subscribe | 79 -- Admin ad-hoc command to subscribe |
81 | 80 |
108 | 107 |
109 -- Disco query remote host | 108 -- Disco query remote host |
110 function query_host(host) | 109 function query_host(host) |
111 local stanza = st.iq({ from = module.host, to = host, type = "get", id = "mod_service_directories:disco" }) | 110 local stanza = st.iq({ from = module.host, to = host, type = "get", id = "mod_service_directories:disco" }) |
112 :query("http://jabber.org/protocol/disco#info"); | 111 :query("http://jabber.org/protocol/disco#info"); |
113 core_post_stanza(hosts[module.host], stanza); | 112 module:send(stanza); |
114 end | 113 end |
115 | 114 |
116 -- Handle disco query result | 115 -- Handle disco query result |
117 module:hook("iq-result/bare/mod_service_directories:disco", function(event) | 116 module:hook("iq-result/bare/mod_service_directories:disco", function(event) |
118 local origin, stanza = event.origin, event.stanza; | 117 local origin, stanza = event.origin, event.stanza; |
133 contact_features[host] = features; | 132 contact_features[host] = features; |
134 | 133 |
135 if features["urn:ietf:params:xml:ns:vcard-4.0"] then | 134 if features["urn:ietf:params:xml:ns:vcard-4.0"] then |
136 local stanza = st.iq({ from = module.host, to = host, type = "get", id = "mod_service_directories:vcard" }) | 135 local stanza = st.iq({ from = module.host, to = host, type = "get", id = "mod_service_directories:vcard" }) |
137 :tag("vcard", { xmlns = "urn:ietf:params:xml:ns:vcard-4.0" }); | 136 :tag("vcard", { xmlns = "urn:ietf:params:xml:ns:vcard-4.0" }); |
138 core_post_stanza(hosts[module.host], stanza); | 137 module:send(stanza); |
139 end | 138 end |
140 return true; | 139 return true; |
141 end); | 140 end); |
142 | 141 |
143 -- Handle vcard result | 142 -- Handle vcard result |