Software /
code /
prosody
Comparison
plugins/mod_vcard.lua @ 5500:eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 19 Apr 2013 16:14:06 +0200 |
parent | 5017:a6bae9d72c8f |
child | 5776:bd0ff8ae98a8 |
comparison
equal
deleted
inserted
replaced
5498:2a67235e1d4d | 5500:eeea0eb2602a |
---|---|
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local st = require "util.stanza" | 9 local st = require "util.stanza" |
10 local jid_split = require "util.jid".split; | 10 local jid_split = require "util.jid".split; |
11 local datamanager = require "util.datamanager" | 11 |
12 local vcards = module:open_store(); | |
12 | 13 |
13 module:add_feature("vcard-temp"); | 14 module:add_feature("vcard-temp"); |
14 | 15 |
15 local function handle_vcard(event) | 16 local function handle_vcard(event) |
16 local session, stanza = event.origin, event.stanza; | 17 local session, stanza = event.origin, event.stanza; |
17 local to = stanza.attr.to; | 18 local to = stanza.attr.to; |
18 if stanza.attr.type == "get" then | 19 if stanza.attr.type == "get" then |
19 local vCard; | 20 local vCard; |
20 if to then | 21 if to then |
21 local node, host = jid_split(to); | 22 local node, host = jid_split(to); |
22 vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server | 23 vCard = st.deserialize(vcards:get(node)); -- load vCard for user or server |
23 else | 24 else |
24 vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard | 25 vCard = st.deserialize(vcards:get(session.username));-- load user's own vCard |
25 end | 26 end |
26 if vCard then | 27 if vCard then |
27 session.send(st.reply(stanza):add_child(vCard)); -- send vCard! | 28 session.send(st.reply(stanza):add_child(vCard)); -- send vCard! |
28 else | 29 else |
29 session.send(st.error_reply(stanza, "cancel", "item-not-found")); | 30 session.send(st.error_reply(stanza, "cancel", "item-not-found")); |
30 end | 31 end |
31 else | 32 else |
32 if not to then | 33 if not to then |
33 if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then | 34 if vcards:set(session.username, st.preserialize(stanza.tags[1])) then |
34 session.send(st.reply(stanza)); | 35 session.send(st.reply(stanza)); |
35 else | 36 else |
36 -- TODO unable to write file, file may be locked, etc, what's the correct error? | 37 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
37 session.send(st.error_reply(stanza, "wait", "internal-server-error")); | 38 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
38 end | 39 end |