Software /
code /
prosody
Annotate
plugins/mod_vcard.lua @ 212:9d6da9ed9063
Internal component support
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 04 Nov 2008 17:25:12 +0500 |
parent | 195:08753eafbf46 |
child | 307:8ff052a77cac |
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 send = require "core.sessionmanager".send_to_session |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local t_concat, t_insert = table.concat, table.insert; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 require "util.jid" |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local jid_split = jid.split; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 |
195 | 12 add_iq_handler({"c2s", "s2sin"}, "vcard-temp", |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 function (session, stanza) |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 if stanza.tags[1].name == "vCard" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 local to = stanza.attr.to; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 if stanza.attr.type == "get" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local vCard; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 if to then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 local node, host = jid_split(to); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 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
|
21 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
|
22 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 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
|
24 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
|
25 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 if vCard then |
184
6528845e8673
mod_vcard: Fixed to use new util.stanza.add_child
Waqas Hussain <waqas20@gmail.com>
parents:
90
diff
changeset
|
27 send(session, st.reply(stanza):add_child(vCard)); -- send vCard! |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 send(session, st.error_reply(stanza, "cancel", "item-not-found")); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 elseif stanza.attr.type == "set" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 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
|
33 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 send(session, st.reply(stanza)); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 send(session, st.error_reply(stanza, "wait", "internal-server-error")); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 send(session, st.error_reply(stanza, "auth", "forbidden")); |
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 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 return true; |
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 end); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 add_event_hook("stream-features", |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 function (session, features) |
89
081e920dc74e
Fixed: incorrect auth check
Waqas Hussain <waqas20@gmail.com>
parents:
86
diff
changeset
|
49 if session.type == "c2s" then |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 t_insert(features, "<feature var='vcard-temp'/>"); |
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); |