Software /
code /
prosody
Annotate
plugins/mod_vcard.lua @ 506:96f9f8dd9a45
Automated merge with h-h.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 30 Nov 2008 15:18:45 +0100 |
parent | 438:193f9dd64f17 |
child | 519:cccd610a0ef9 |
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 |
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
357
diff
changeset
|
11 require "core.discomanager".set("vcard", "vcard-temp"); |
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
357
diff
changeset
|
12 |
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
|
13 module:add_iq_handler({"c2s", "s2sin"}, "vcard-temp", |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 function (session, stanza) |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 if stanza.tags[1].name == "vCard" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local to = stanza.attr.to; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 if stanza.attr.type == "get" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local vCard; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 if to then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local node, host = jid_split(to); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 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
|
22 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
|
23 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 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
|
25 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
|
26 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 if vCard then |
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.reply(stanza):add_child(vCard)); -- send vCard! |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 else |
307
8ff052a77cac
Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
195
diff
changeset
|
30 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
|
31 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 elseif stanza.attr.type == "set" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 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
|
34 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
|
35 session.send(st.reply(stanza)); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 -- 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
|
38 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
|
39 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 else |
307
8ff052a77cac
Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
195
diff
changeset
|
41 session.send(st.error_reply(stanza, "auth", "forbidden")); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 end |
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 return true; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 end |
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 |
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
|
48 local feature_vcard_attr = { var='vcard-temp' }; |
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
|
49 module:add_event_hook("stream-features", |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 function (session, features) |
89
081e920dc74e
Fixed: incorrect auth check
Waqas Hussain <waqas20@gmail.com>
parents:
86
diff
changeset
|
51 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
|
52 features:tag("feature", feature_vcard_attr):up(); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 end); |