Sun, 18 Oct 2009 03:08:41 +0500
componentmanager: Added a FIXME comment.
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
1 | -- Prosody IM |
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:
894
diff
changeset
|
11 | local hosts = _G.hosts; |
a3d77353c18a
mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents:
894
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:
894
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 | |
1956
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
20 | local xmlns_vcard = "vcard-temp"; |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
21 | |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
22 | module:add_feature(xmlns_vcard); |
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
357
diff
changeset
|
23 | |
1956
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
24 | function handle_vcard(session, stanza) |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
25 | if stanza.tags[1].name == "vCard" then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
26 | local to = stanza.attr.to; |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
27 | if stanza.attr.type == "get" then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
28 | local vCard; |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
29 | if to then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
30 | local node, host = jid_split(to); |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
31 | if hosts[host] and hosts[host].type == "local" then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
32 | 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
|
33 | end |
1956
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
34 | else |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
35 | vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
36 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
37 | if vCard then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
38 | session.send(st.reply(stanza):add_child(vCard)); -- send vCard! |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
39 | else |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
40 | session.send(st.error_reply(stanza, "cancel", "item-not-found")); |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
41 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
42 | elseif stanza.attr.type == "set" then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
43 | if not to or to == session.username.."@"..session.host then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
44 | if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
45 | session.send(st.reply(stanza)); |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
46 | else |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
47 | -- TODO unable to write file, file may be locked, etc, what's the correct error? |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
48 | session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
49 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
50 | else |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
51 | session.send(st.error_reply(stanza, "auth", "forbidden")); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 | end |
1956
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
53 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
54 | return true; |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
55 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
56 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
57 | |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
58 | module:add_iq_handler({"c2s", "s2sin", "component"}, xmlns_vcard, handle_vcard); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 | |
1956
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
60 | -- COMPAT: https://support.process-one.net/browse/EJAB-1045 |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
61 | if module:get_option("vcard_compatibility") then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
62 | module:hook("iq/full", function (data) |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
63 | local stanza = data.stanza; |
1957
5856b2dcf81e
mod_vcard: Hide me from the trailing-whitespace police
Matthew Wild <mwild1@gmail.com>
parents:
1956
diff
changeset
|
64 | if stanza.attr.type == "get" and stanza.tags[1] |
1956
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
65 | and stanza.tags[1].attr.xmlns == xmlns_vcard then |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
66 | return handle_vcard(data.origin, stanza); |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
67 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
68 | end, 1); |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
69 | end |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
70 | |
ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
1779
diff
changeset
|
71 | local feature_vcard_attr = { var=xmlns_vcard }; |
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
|
72 | 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
|
73 | function (session, features) |
89
081e920dc74e
Fixed: incorrect auth check
Waqas Hussain <waqas20@gmail.com>
parents:
86
diff
changeset
|
74 | 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
|
75 | features:tag("feature", feature_vcard_attr):up(); |
86
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 | end |
a2085854c72c
Added: vCard plugin: mod_vcard
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 | end); |