Mercurial > prosody-modules
comparison mod_profile/mod_profile.lua @ 1744:fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 18 May 2015 02:56:41 +0200 |
parents | 8fbe16c83807 |
children | 851cb0b3d584 |
comparison
equal
deleted
inserted
replaced
1743:8fbe16c83807 | 1744:fbef84033fae |
---|---|
90 local data = storage:get(username); | 90 local data = storage:get(username); |
91 if not data then | 91 if not data then |
92 data = legacy_storage:get(username); | 92 data = legacy_storage:get(username); |
93 data = data and st.deserialize(data); | 93 data = data and st.deserialize(data); |
94 if data then | 94 if data then |
95 return origin.send(st.reply(stanza):add_child(data)); | 95 origin.send(st.reply(stanza):add_child(data)); |
96 return true; | |
96 end | 97 end |
97 end | 98 end |
98 if not data then | 99 if not data then |
99 return origin.send(st.error_reply(stanza, "cancel", "item-not-found")); | 100 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
100 end | 101 return true; |
101 return origin.send(st.reply(stanza):add_child(vcard.to_xep54(data))); | 102 end |
103 origin.send(st.reply(stanza):add_child(vcard.to_xep54(data))); | |
104 return true; | |
102 end | 105 end |
103 | 106 |
104 local function handle_set(event) | 107 local function handle_set(event) |
105 local origin, stanza = event.origin, event.stanza; | 108 local origin, stanza = event.origin, event.stanza; |
106 local data = vcard.from_xep54(stanza.tags[1]); | 109 local data = vcard.from_xep54(stanza.tags[1]); |
107 local username = origin.username; | 110 local username = origin.username; |
108 local to = stanza.attr.to; | 111 local to = stanza.attr.to; |
109 if to then | 112 if to then |
110 if not is_admin(jid_bare(stanza.attr.from), module.host) then | 113 if not is_admin(jid_bare(stanza.attr.from), module.host) then |
111 return origin.send(st.error_reply(stanza, "auth", "forbidden")); | 114 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
115 return true; | |
112 end | 116 end |
113 username = jid_split(to); | 117 username = jid_split(to); |
114 end | 118 end |
115 local ok, err = storage:set(username, data); | 119 local ok, err = storage:set(username, data); |
116 if not ok then | 120 if not ok then |
117 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); | 121 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
122 return true; | |
118 end | 123 end |
119 | 124 |
120 if pep_plus and username then | 125 if pep_plus and username then |
121 update_pep(username, data); | 126 update_pep(username, data); |
122 end | 127 end |
123 | 128 |
124 return origin.send(st.reply(stanza)); | 129 origin.send(st.reply(stanza)); |
130 return true; | |
125 end | 131 end |
126 | 132 |
127 module:hook("iq-get/bare/vcard-temp:vCard", handle_get); | 133 module:hook("iq-get/bare/vcard-temp:vCard", handle_get); |
128 module:hook("iq-get/host/vcard-temp:vCard", handle_get); | 134 module:hook("iq-get/host/vcard-temp:vCard", handle_get); |
129 | 135 |
184 module:hook("iq-get/bare/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event) | 190 module:hook("iq-get/bare/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event) |
185 local origin, stanza = event.origin, event.stanza; | 191 local origin, stanza = event.origin, event.stanza; |
186 local username = jid_split(stanza.attr.to) or origin.username; | 192 local username = jid_split(stanza.attr.to) or origin.username; |
187 local data = storage:get(username); | 193 local data = storage:get(username); |
188 if not data then | 194 if not data then |
189 return origin.send(st.error_reply(stanza, "cancel", "item-not-found")); | 195 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
190 end | 196 return true; |
191 return origin.send(st.reply(stanza):add_child(vcard.to_vcard4(data))); | 197 end |
198 origin.send(st.reply(stanza):add_child(vcard.to_vcard4(data))); | |
199 return true; | |
192 end); | 200 end); |
193 | 201 |
194 if vcard.from_vcard4 then | 202 if vcard.from_vcard4 then |
195 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event) | 203 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event) |
196 local origin, stanza = event.origin, event.stanza; | 204 local origin, stanza = event.origin, event.stanza; |
197 local ok, err = storage:set(origin.username, vcard.from_vcard4(stanza.tags[1])); | 205 local ok, err = storage:set(origin.username, vcard.from_vcard4(stanza.tags[1])); |
198 if not ok then | 206 if not ok then |
199 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); | 207 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
208 return true; | |
200 end | 209 end |
201 return origin.send(st.reply(stanza)); | 210 origin.send(st.reply(stanza)); |
211 return true; | |
202 end); | 212 end); |
203 else | 213 else |
204 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event) | 214 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event) |
205 local origin, stanza = event.origin, event.stanza; | 215 local origin, stanza = event.origin, event.stanza; |
206 return origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented")); | 216 origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented")); |
217 return true; | |
207 end); | 218 end); |
208 end | 219 end |
209 end | 220 end |
210 | 221 |