Annotate

plugins/mod_vcard.lua @ 1940:85d51cea2c4c

componentmanager: Fix oops in pattern for matching subdomain
author Matthew Wild <mwild1@gmail.com>
date Fri, 09 Oct 2009 00:15:39 +0100
parent 1779:3da808c7bfa2
child 1956:ec04b571fa86
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
1 -- Prosody IM
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
8
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
9
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10
1042
a3d77353c18a mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
11 local hosts = _G.hosts;
a3d77353c18a mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
12 local datamanager = require "util.datamanager"
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local st = require "util.stanza"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local t_concat, t_insert = table.concat, table.insert;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16
1042
a3d77353c18a mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
17 local jid = require "util.jid"
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local jid_split = jid.split;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
541
3521e0851c9e Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
20 module:add_feature("vcard-temp");
421
63be85693710 Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents: 357
diff changeset
21
1779
3da808c7bfa2 mod_vcard: Handle vcard requests from local components.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
22 module:add_iq_handler({"c2s", "s2sin", "component"}, "vcard-temp",
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 function (session, stanza)
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 if stanza.tags[1].name == "vCard" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local to = stanza.attr.to;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 if stanza.attr.type == "get" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local vCard;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 if to then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 local node, host = jid_split(to);
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 if hosts[host] and hosts[host].type == "local" then
549
c0947c0af398 Changed the datastore for vCards from vCard to vcard in mod_vcard and mod_register
Waqas Hussain <waqas20@gmail.com>
parents: 541
diff changeset
31 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
32 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 else
549
c0947c0af398 Changed the datastore for vCards from vCard to vcard in mod_vcard and mod_register
Waqas Hussain <waqas20@gmail.com>
parents: 541
diff changeset
34 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
35 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 if vCard then
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
37 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
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, "cancel", "item-not-found"));
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 elseif stanza.attr.type == "set" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 if not to or to == session.username.."@"..session.host then
549
c0947c0af398 Changed the datastore for vCards from vCard to vcard in mod_vcard and mod_register
Waqas Hussain <waqas20@gmail.com>
parents: 541
diff changeset
43 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
44 session.send(st.reply(stanza));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 else
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 -- 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
47 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
48 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 else
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
50 session.send(st.error_reply(stanza, "auth", "forbidden"));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 return true;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 end);
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56
357
17bcecb06420 Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
Matthew Wild <mwild1@gmail.com>
parents: 307
diff changeset
57 local feature_vcard_attr = { var='vcard-temp' };
549
c0947c0af398 Changed the datastore for vCards from vCard to vcard in mod_vcard and mod_register
Waqas Hussain <waqas20@gmail.com>
parents: 541
diff changeset
58 module:add_event_hook("stream-features",
c0947c0af398 Changed the datastore for vCards from vCard to vcard in mod_vcard and mod_register
Waqas Hussain <waqas20@gmail.com>
parents: 541
diff changeset
59 function (session, features)
89
081e920dc74e Fixed: incorrect auth check
Waqas Hussain <waqas20@gmail.com>
parents: 86
diff changeset
60 if session.type == "c2s" then
357
17bcecb06420 Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
Matthew Wild <mwild1@gmail.com>
parents: 307
diff changeset
61 features:tag("feature", feature_vcard_attr):up();
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 end);