Annotate

plugins/mod_vcard.lua @ 683:7428244a82a6

Change default maximum inactivity period to 60s from 30s
author Matthew Wild <mwild1@gmail.com>
date Fri, 09 Jan 2009 19:16:47 +0000
parent 615:4ae3e81513f3
child 758:b1885732e979
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
615
4ae3e81513f3 0.1 -> 0.2
Matthew Wild <mwild1@gmail.com>
parents: 549
diff changeset
1 -- Prosody IM v0.2
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
2 -- Copyright (C) 2008 Matthew Wild
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
3 -- Copyright (C) 2008 Waqas Hussain
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
4 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
5 -- This program is free software; you can redistribute it and/or
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
6 -- modify it under the terms of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
7 -- as published by the Free Software Foundation; either version 2
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
8 -- of the License, or (at your option) any later version.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
9 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
10 -- This program is distributed in the hope that it will be useful,
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
13 -- GNU General Public License for more details.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
14 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
15 -- You should have received a copy of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
16 -- along with this program; if not, write to the Free Software
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
18 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
19
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
20
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 require "util.datamanager"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 local datamanager = datamanager;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local st = require "util.stanza"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local t_concat, t_insert = table.concat, table.insert;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 require "util.jid"
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 local jid_split = jid.split;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30
541
3521e0851c9e Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
31 module:add_feature("vcard-temp");
421
63be85693710 Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents: 357
diff changeset
32
438
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 421
diff changeset
33 module:add_iq_handler({"c2s", "s2sin"}, "vcard-temp",
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 function (session, stanza)
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 if stanza.tags[1].name == "vCard" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 local to = stanza.attr.to;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 if stanza.attr.type == "get" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 local vCard;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 if to then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 local node, host = jid_split(to);
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 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
42 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
43 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 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
45 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
46 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 if vCard then
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
48 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
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, "cancel", "item-not-found"));
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 elseif stanza.attr.type == "set" then
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 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
54 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
55 session.send(st.reply(stanza));
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 else
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 -- 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
58 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
59 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 else
307
8ff052a77cac Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents: 195
diff changeset
61 session.send(st.error_reply(stanza, "auth", "forbidden"));
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
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 return true;
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 end);
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67
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
68 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
69 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
70 function (session, features)
89
081e920dc74e Fixed: incorrect auth check
Waqas Hussain <waqas20@gmail.com>
parents: 86
diff changeset
71 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
72 features:tag("feature", feature_vcard_attr):up();
86
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 end
a2085854c72c Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 end);