Software /
code /
prosody
Annotate
plugins/mod_vcard.lua @ 360:e918c979ad1a
Remove or comment useless prints, or change them to log()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 20 Nov 2008 03:00:43 +0000 |
parent | 357:17bcecb06420 |
child | 421:63be85693710 |
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 |
195 | 11 add_iq_handler({"c2s", "s2sin"}, "vcard-temp", |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 function (session, stanza) |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 if stanza.tags[1].name == "vCard" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local to = stanza.attr.to; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 if stanza.attr.type == "get" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local vCard; |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 if to then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local node, host = jid_split(to); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 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
|
20 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
|
21 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 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
|
23 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
|
24 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 if vCard then |
307
8ff052a77cac
Fix mod_vcard to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
195
diff
changeset
|
26 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
|
27 else |
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.error_reply(stanza, "cancel", "item-not-found")); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 elseif stanza.attr.type == "set" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 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
|
32 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
|
33 session.send(st.reply(stanza)); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 -- 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
|
36 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
|
37 end |
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, "auth", "forbidden")); |
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 end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 return true; |
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 end); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 |
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
|
46 local feature_vcard_attr = { var='vcard-temp' }; |
86
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 |
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
|
50 features:tag("feature", feature_vcard_attr):up(); |
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); |