Software /
code /
prosody
Annotate
plugins/mod_vcard.lua @ 1042:a3d77353c18a
mod_*: Fix a load of global accesses
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 22 Apr 2009 21:32:23 +0100 |
parent | 896:2c0b9e3c11c3 |
child | 1523:841d61be198f |
rev | line source |
---|---|
896 | 1 -- Prosody IM v0.4 |
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 | 5 -- This project is MIT/X11 licensed. Please see the |
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 |
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
|
22 module:add_iq_handler({"c2s", "s2sin"}, "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); |