Mercurial > prosody-modules
comparison mod_vjud/mod_vjud.lua @ 2008:cf3bdcb633f0
mod_vjud: Handle vCard decoding errors by logging them (Thanks Roi)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 14 Jan 2016 18:24:35 +0100 |
| parents | 400a7fdd2049 |
| children | a90c7d7e7413 |
comparison
equal
deleted
inserted
replaced
| 2007:dc1299ca0185 | 2008:cf3bdcb633f0 |
|---|---|
| 57 end | 57 end |
| 58 end | 58 end |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 local function get_user_vcard(user, host) | 61 local function get_user_vcard(user, host) |
| 62 local vCard = dm_load(user, host or base_host, "vcard"); | 62 local vCard err = dm_load(user, host or base_host, "vcard"); |
| 63 if vCard then | 63 if not vCard then return nil, err; end |
| 64 vCard = st.deserialize(vCard); | 64 vCard = st.deserialize(vCard); |
| 65 vCard = vcard.from_xep54(vCard); | 65 vCard, err = vcard.from_xep54(vCard); |
| 66 return setmetatable(vCard, vCard_mt); | 66 if not vCard then return nil, err; end |
| 67 end | 67 return setmetatable(vCard, vCard_mt); |
| 68 end | 68 end |
| 69 | 69 |
| 70 local at_host = "@"..base_host; | 70 local at_host = "@"..base_host; |
| 71 | 71 |
| 72 local users; -- The user iterator | 72 local users; -- The user iterator |
| 100 | 100 |
| 101 local reply = st.reply(stanza):query("jabber:iq:search"); | 101 local reply = st.reply(stanza):query("jabber:iq:search"); |
| 102 | 102 |
| 103 local username, hostname = jid_split(email); | 103 local username, hostname = jid_split(email); |
| 104 if hostname == base_host and username and usermanager.user_exists(username, hostname) then | 104 if hostname == base_host and username and usermanager.user_exists(username, hostname) then |
| 105 local vCard = get_user_vcard(username); | 105 local vCard, err = get_user_vcard(username); |
| 106 if vCard then | 106 if not vCard then |
| 107 module:log("debug", "Couldn't get vCard for user %s: %s", username, err or "unknown error"); | |
| 108 else | |
| 107 reply:add_child(item_template.apply{ | 109 reply:add_child(item_template.apply{ |
| 108 jid = username..at_host; | 110 jid = username..at_host; |
| 109 first = vCard.N and vCard.N[2] or nil; | 111 first = vCard.N and vCard.N[2] or nil; |
| 110 last = vCard.N and vCard.N[1] or nil; | 112 last = vCard.N and vCard.N[1] or nil; |
| 111 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username; | 113 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username; |
