Software /
code /
prosody-modules
Comparison
mod_vjud/mod_vjud.lua @ 789:7e40d6680093
mod_vjud: Allow working as a component, in which case the parent domain is searched.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 09 Aug 2012 20:31:13 +0200 |
parent | 787:cec49ee88c23 |
child | 879:3a17fc0127b1 |
comparison
equal
deleted
inserted
replaced
788:aeb0999f12fa | 789:7e40d6680093 |
---|---|
26 <nick>{nick}</nick> | 26 <nick>{nick}</nick> |
27 <email>{email}</email> | 27 <email>{email}</email> |
28 </item> | 28 </item> |
29 ]]; | 29 ]]; |
30 | 30 |
31 local base_host = module:get_option_string("vjud_search_domain", | |
32 module:get_host_type() == "component" | |
33 and module.host:gsub("^[^.]+%.","") | |
34 or module.host); | |
35 | |
36 module:depends"disco"; | |
31 module:add_feature("jabber:iq:search"); | 37 module:add_feature("jabber:iq:search"); |
32 | 38 |
33 local opted_in; | 39 local opted_in; |
34 function module.load() | 40 function module.load() |
35 opted_in = dm_load(nil, module.host, "user_index") or {}; | 41 opted_in = dm_load(nil, module.host, "user_index") or {}; |
58 end | 64 end |
59 end | 65 end |
60 end | 66 end |
61 }; | 67 }; |
62 | 68 |
63 local function get_user_vcard(user) | 69 local function get_user_vcard(user, host) |
64 local vCard = dm_load(user, module.host, "vcard"); | 70 local vCard = dm_load(user, host or base_host, "vcard"); |
65 if vCard then | 71 if vCard then |
66 vCard = st.deserialize(vCard); | 72 vCard = st.deserialize(vCard); |
67 vCard = vcard.from_xep54(vCard); | 73 vCard = vcard.from_xep54(vCard); |
68 return setmetatable(vCard, vCard_mt); | 74 return setmetatable(vCard, vCard_mt); |
69 end | 75 end |
70 end | 76 end |
71 | 77 |
72 local at_host = "@"..module.host; | 78 local at_host = "@"..base_host; |
73 | 79 |
74 module:hook("iq/host/jabber:iq:search:query", function(event) | 80 module:hook("iq/host/jabber:iq:search:query", function(event) |
75 local origin, stanza = event.origin, event.stanza; | 81 local origin, stanza = event.origin, event.stanza; |
76 | 82 |
77 if stanza.attr.type == "get" then | 83 if stanza.attr.type == "get" then |
90 end | 96 end |
91 | 97 |
92 local reply = st.reply(stanza):query("jabber:iq:search"); | 98 local reply = st.reply(stanza):query("jabber:iq:search"); |
93 | 99 |
94 local username, hostname = jid_split(email); | 100 local username, hostname = jid_split(email); |
95 if hostname == module.host and username and usermanager.user_exists(username, hostname) then | 101 if hostname == base_host and username and usermanager.user_exists(username, hostname) then |
96 local vCard = get_user_vcard(username); | 102 local vCard = get_user_vcard(username); |
97 if vCard then | 103 if vCard then |
98 reply:add_child(item_template.apply{ | 104 reply:add_child(item_template.apply{ |
99 jid = username..at_host; | 105 jid = username..at_host; |
100 first = vCard.N and vCard.N[2] or nil; | 106 first = vCard.N and vCard.N[2] or nil; |
131 if state then -- the second return value | 137 if state then -- the second return value |
132 if data.action == "cancel" then | 138 if data.action == "cancel" then |
133 return { status = "canceled" }; | 139 return { status = "canceled" }; |
134 end | 140 end |
135 | 141 |
136 if not username or not hostname or hostname ~= module.host then | 142 if not username or not hostname or hostname ~= base_host then |
137 return { status = "error", error = { type = "cancel", | 143 return { status = "error", error = { type = "cancel", |
138 condition = "forbidden", message = "Invalid user or hostname." } }; | 144 condition = "forbidden", message = "Invalid user or hostname." } }; |
139 end | 145 end |
140 | 146 |
141 local fields = opt_in_layout:data(data.form); | 147 local fields = opt_in_layout:data(data.form); |