annotate mod_service_directories/mod_service_directories.lua @ 735:c1b0f0c33c6a

mod_archive: Fix hour offset in stored message date os.date expect a timestamp in local time, that is subject to daylight saving. But since we pass an UTC timestamp to os.date one hour is (wrongly) added in the summer. The only sensible thing is to call the os.date only once with the ! parametter. And then parsing this sting to get the utc_timestamp. Calling os.date with an UTC timestamp is not possible, and calling os.date twice without timestamp could give different results.
author Olivier Goffart <ogoffart@woboq.com>
date Wed, 04 Jul 2012 13:49:57 +0200
parents d1e83cb12885
children 6531a029fce5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
552
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 -- Prosody IM
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2011 Waqas Hussain
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 --
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 --
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 -- An implementation of [XEP-0309: Service Directories]
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 -- Imports and defines
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local st = require "util.stanza";
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local jid_split = require "util.jid".split;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local adhoc_new = module:require "adhoc".new;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local to_ascii = require "util.encodings".idna.to_ascii;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 local nameprep = require "util.encodings".stringprep.nameprep;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 local core_post_stanza = core_post_stanza;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local pairs, ipairs = pairs, ipairs;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 local module = module;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 local hosts = hosts;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 local subscription_from = {};
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 local subscription_to = {};
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 local contact_features = {};
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local contact_vcards = {};
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 -- Advertise in disco
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 module:add_identity("server", "directory", "Prosody");
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 module:add_feature("urn:xmpp:server-presence");
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 -- Handle subscriptions
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 module:hook("presence/host", function(event) -- inbound presence to the host
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 local origin, stanza = event.origin, event.stanza;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 local node, host, resource = jid_split(stanza.attr.from);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 if stanza.attr.from ~= host then return; end -- not from a host
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 local t = stanza.attr.type;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 if t == "probe" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 elseif t == "subscribe" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 subscription_from[host] = true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "subscribed" }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 add_contact(host);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 elseif t == "subscribed" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 subscription_to[host] = true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 query_host(host);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 elseif t == "unsubscribe" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 subscription_from[host] = nil;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "unsubscribed" }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 remove_contact(host);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 elseif t == "unsubscribed" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 subscription_to[host] = nil;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 remove_contact(host);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 return true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 end, 10); -- priority over mod_presence
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 function remove_contact(host, id)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 contact_features[host] = nil;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 contact_vcards[host] = nil;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 if subscription_to[host] then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 subscription_to[host] = nil;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = id, type = "unsubscribe" }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 if subscription_from[host] then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 subscription_from[host] = nil;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = id, type = "unsubscribed" }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 function add_contact(host, id)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 if not subscription_to[host] then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = host, id = id, type = "subscribe" }));
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 -- Admin ad-hoc command to subscribe
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 local function add_contact_handler(self, data, state)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 local layout = {
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 title = "Adding a Server Buddy";
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85 instructions = "Fill out this form to add a \"server buddy\".";
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 { name = "peerjid", type = "jid-single", required = true, label = "The server to add" };
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 };
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 if not state then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 return { status = "executing", form = layout }, "executing";
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 elseif data.action == "canceled" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 return { status = "canceled" };
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95 else
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96 local fields = layout:data(data);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97 local peerjid = nameprep(fields.peerjid);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 if not peerjid or peerjid == "" or #peerjid > 1023 or not to_ascii(peerjid) then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 return { status = "completed", error = { message = "Invalid JID" } };
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 add_contact(peerjid);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 return { status = "completed" };
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 local add_contact_command = adhoc_new("Adding a Server Buddy", "http://jabber.org/protocol/admin#server-buddy", add_contact_handler, "admin");
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 module:add_item("adhoc", add_contact_command);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 -- Disco query remote host
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 function query_host(host)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 local stanza = st.iq({ from = module.host, to = host, type = "get", id = "mod_service_directories:disco" })
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 :query("http://jabber.org/protocol/disco#info");
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 core_post_stanza(hosts[module.host], stanza);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
116 -- Handle disco query result
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 module:hook("iq-result/bare/mod_service_directories:disco", function(event)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 local origin, stanza = event.origin, event.stanza;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
119
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 if not subscription_to[stanza.attr.from] then return; end -- not from a contact
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
121 local host = stanza.attr.from;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 local query = stanza:get_child("query", "http://jabber.org/protocol/disco#info")
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 if not query then return; end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126 -- extract disco features
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127 local features = {};
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128 for _,tag in ipairs(query.tags) do
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
129 if tag.name == "feature" and tag.attr.var then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
130 features[tag.attr.var] = true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
133 contact_features[host] = features;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
134
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 if features["urn:ietf:params:xml:ns:vcard-4.0"] then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 local stanza = st.iq({ from = module.host, to = host, type = "get", id = "mod_service_directories:vcard" })
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
137 :tag("vcard", { xmlns = "urn:ietf:params:xml:ns:vcard-4.0" });
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 core_post_stanza(hosts[module.host], stanza);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 return true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 end);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143 -- Handle vcard result
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 module:hook("iq-result/bare/mod_service_directories:vcard", function(event)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 local origin, stanza = event.origin, event.stanza;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 if not subscription_to[stanza.attr.from] then return; end -- not from a contact
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148 local host = stanza.attr.from;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
149
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
150 local vcard = stanza:get_child("vcard", "urn:ietf:params:xml:ns:vcard-4.0");
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151 if not vcard then return; end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
152
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
153 contact_vcards[host] = st.clone(vcard);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
154 return true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
155 end);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
156
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157 -- PubSub
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159 -- TODO the following should be replaced by mod_pubsub
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
160
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
161 module:hook("iq-get/host/http://jabber.org/protocol/pubsub:pubsub", function(event)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
162 local origin, stanza = event.origin, event.stanza;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
163 local payload = stanza.tags[1];
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
164
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
165 local items = payload:get_child("items", "http://jabber.org/protocol/pubsub");
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
166 if items and items.attr.node == "urn:xmpp:contacts" then
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
167 local reply = st.reply(stanza)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
168 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
169 :tag("items", { node = "urn:xmpp:contacts" });
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
170 for host, vcard in pairs(contact_vcards) do
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
171 reply:tag("item", { id = host })
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
172 :add_child(vcard)
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
173 :up();
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
174 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
175 origin.send(reply);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
176 return true;
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
177 end
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
178 end);
d1e83cb12885 mod_service_directories: Initial commit. Untested. Support for both directory and buddy use cases. Incomplete pubsub support (only getting all items supported).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
179