Annotate

plugins/mod_vcard.lua @ 353:e7d776b5ebb9

Remove an old FIXME comment
author Matthew Wild <mwild1@gmail.com>
date Wed, 19 Nov 2008 23:25:04 +0000
parent 307:8ff052a77cac
child 357:17bcecb06420
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 require "util.datamanager"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local datamanager = datamanager;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local st = require "util.stanza"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 local t_concat, t_insert = table.concat, table.insert;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 require "util.jid"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 local jid_split = jid.split;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10
195
08753eafbf46 vcards for s2s
Matthew Wild <mwild1@gmail.com>
parents: 184
diff changeset
11 add_iq_handler({"c2s", "s2sin"}, "vcard-temp",
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 function (session, stanza)
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 if stanza.tags[1].name == "vCard" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local to = stanza.attr.to;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 if stanza.attr.type == "get" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 local vCard;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 if to then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local node, host = jid_split(to);
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 if hosts[host] and hosts[host].type == "local" then
90
da468ed49a7b Stanza preserialize/deserialize helpers, to strip and restore stanzas respectively. Fixed mod_vcard to use these.
Matthew Wild <mwild1@gmail.com>
parents: 89
diff changeset
20 vCard = st.deserialize(datamanager.load(node, host, "vCard")); -- load vCard for user or server
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 else
90
da468ed49a7b Stanza preserialize/deserialize helpers, to strip and restore stanzas respectively. Fixed mod_vcard to use these.
Matthew Wild <mwild1@gmail.com>
parents: 89
diff changeset
23 vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 if vCard then
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
26 session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 else
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
28 session.send(st.error_reply(stanza, "cancel", "item-not-found"));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 elseif stanza.attr.type == "set" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 if not to or to == session.username.."@"..session.host then
90
da468ed49a7b Stanza preserialize/deserialize helpers, to strip and restore stanzas respectively. Fixed mod_vcard to use these.
Matthew Wild <mwild1@gmail.com>
parents: 89
diff changeset
32 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
33 session.send(st.reply(stanza));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 else
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 -- TODO unable to write file, file may be locked, etc, what's the correct error?
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
36 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 else
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
39 session.send(st.error_reply(stanza, "auth", "forbidden"));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 return true;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 end);
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 add_event_hook("stream-features",
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 function (session, features)
89
081e920dc74e Fixed: incorrect auth check
Waqas Hussain <waqas20@gmail.com>
parents: 86
diff changeset
48 if session.type == "c2s" then
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 t_insert(features, "<feature var='vcard-temp'/>");
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 end);