Mercurial > prosody-modules
annotate mod_service_directories/mod_service_directories.lua @ 874:a8e777e2d44f
Test login for user 'seven'
author | Rob Hoelz <rob@hoelz.ro> |
---|---|
date | Mon, 10 Dec 2012 22:34:23 +0100 |
parents | 6531a029fce5 |
children | 7648ee2d59d1 |
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 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
|
18 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
|
19 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
|
20 |
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 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
|
22 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
|
23 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
|
24 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
|
25 |
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 -- 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
|
27 |
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 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
|
29 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
|
30 |
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 -- 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
|
32 |
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 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
|
34 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
|
35 |
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 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
|
37 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
|
38 |
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 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
|
40 if t == "probe" then |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
41 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id })); |
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
|
42 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
|
43 subscription_from[host] = true; |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
44 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "subscribed" })); |
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
45 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id })); |
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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 subscription_from[host] = nil; |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
52 module:send(st.presence({ from = module.host, to = host, id = stanza.attr.id, type = "unsubscribed" })); |
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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 |
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 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
|
62 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
|
63 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
|
64 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
|
65 subscription_to[host] = nil; |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
66 module:send(st.presence({ from = module.host, to = host, id = id, type = "unsubscribe" })); |
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
|
67 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
|
68 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
|
69 subscription_from[host] = nil; |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
70 module:send(st.presence({ from = module.host, to = host, id = id, type = "unsubscribed" })); |
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
|
71 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
|
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 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
|
74 if not subscription_to[host] then |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
75 module:send(st.presence({ from = module.host, to = host, id = id, type = "subscribe" })); |
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
|
76 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
|
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 |
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 -- 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
|
80 |
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 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
|
82 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
|
83 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
|
84 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
|
85 |
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 { 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
|
87 { 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
|
88 }; |
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 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
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 |
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 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
|
106 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
|
107 |
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 -- 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
|
109 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
|
110 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
|
111 :query("http://jabber.org/protocol/disco#info"); |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
112 module:send(stanza); |
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
|
113 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
|
114 |
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 -- 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
|
116 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
|
117 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
|
118 |
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 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
|
120 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
|
121 |
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 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
|
123 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
|
124 |
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 -- 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
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 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
|
133 |
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 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
|
135 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
|
136 :tag("vcard", { xmlns = "urn:ietf:params:xml:ns:vcard-4.0" }); |
759
6531a029fce5
mod_service_directories: Replace use of core_post_stanza() with module:send()
Kim Alvefur <zash@zash.se>
parents:
552
diff
changeset
|
137 module:send(stanza); |
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
|
138 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
|
139 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
|
140 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
|
141 |
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 -- 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
|
143 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
|
144 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
|
145 |
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 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
|
147 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
|
148 |
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 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
|
150 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
|
151 |
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 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
|
153 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
|
154 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
|
155 |
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 -- 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
|
157 |
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 -- 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
|
159 |
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 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
|
161 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
|
162 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
|
163 |
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 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
|
165 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
|
166 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
|
167 :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
|
168 :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
|
169 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
|
170 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
|
171 :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
|
172 :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
|
173 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
|
174 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
|
175 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
|
176 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
|
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 |