Software /
code /
prosody
Annotate
plugins/mod_vcard.lua @ 154:1fee9396ca2f
Fix mod_legacyauth to not use old stanza_dispatch
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 24 Oct 2008 14:45:50 +0100 |
parent | 90:da468ed49a7b |
child | 184:6528845e8673 |
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 |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 add_iq_handler("c2s", "vcard-temp", |
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 |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local iq = st.reply(stanza); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 iq:add_child(vCard); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 send(session, iq); -- send vCard! |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 send(session, st.error_reply(stanza, "cancel", "item-not-found")); |
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 elseif stanza.attr.type == "set" then |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 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
|
35 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
|
36 send(session, st.reply(stanza)); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 -- 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
|
39 send(session, st.error_reply(stanza, "wait", "internal-server-error")); |
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 else |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 send(session, st.error_reply(stanza, "auth", "forbidden")); |
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 return true; |
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 end); |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 add_event_hook("stream-features", |
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 |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 t_insert(features, "<feature var='vcard-temp'/>"); |
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); |