plugins/mod_pep.lua

Tue, 01 Jun 2010 20:10:17 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 01 Jun 2010 20:10:17 +0100
changeset 3130
80e630e60f06
parent 2925
692b3c6c5bd2
child 3132
4d2251242ac1
permissions
-rw-r--r--

mod_pep: Use is_contact_subscribed (which uses the new rostermanager fix to avoid unnecessary roster loads)

1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1461
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2329
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2329
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1461
diff changeset
4 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1461
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1461
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1461
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1461
diff changeset
8
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local jid_bare = require "util.jid".bare;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local jid_split = require "util.jid".split;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local st = require "util.stanza";
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local hosts = hosts;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local user_exists = require "core.usermanager".user_exists;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 local pairs, ipairs = pairs, ipairs;
1401
a3ce55c1e43a mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents: 1400
diff changeset
17 local next = next;
1437
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
18 local type = type;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
19 local sha1 = require "util.hashes".sha1;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
20 local base64 = require "util.encodings".base64.encode;
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
1430
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
22 local NULL = {};
1323
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
23 local data = {};
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
24 local recipients = {};
1437
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
25 local hash_map = {};
1323
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
26
2045
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
27 module.save = function()
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
28 return { data = data, recipients = recipients, hash_map = hash_map };
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
29 end
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
30 module.restore = function(state)
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
31 data = state.data or {};
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
32 recipients = state.recipients or {};
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
33 hash_map = state.hash_map or {};
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
34 end
3b7473a3fa44 PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents: 2044
diff changeset
35
1696
2afc87ccc379 mod_pep: Added name 'Prosody' to the pubsub/pep identity
Waqas Hussain <waqas20@gmail.com>
parents: 1625
diff changeset
36 module:add_identity("pubsub", "pep", "Prosody");
1338
0bfc8d866479 mod_pep: Add pubsub#publsih disco feature to host
Waqas Hussain <waqas20@gmail.com>
parents: 1335
diff changeset
37 module:add_feature("http://jabber.org/protocol/pubsub#publish");
1335
7c71783b40cf mod_pep: Add host identity pubsub/pep
Waqas Hussain <waqas20@gmail.com>
parents: 1332
diff changeset
38
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
39 local function subscription_presence(user_bare, recipient)
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
40 local recipient_bare = jid_bare(recipient);
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
41 if (recipient_bare == user_bare) then return true end
3130
80e630e60f06 mod_pep: Use is_contact_subscribed (which uses the new rostermanager fix to avoid unnecessary roster loads)
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
42 local username, host = jid_split(user_bare);
80e630e60f06 mod_pep: Use is_contact_subscribed (which uses the new rostermanager fix to avoid unnecessary roster loads)
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
43 return is_contact_subscribed(username, host, recipient_bare);
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
44 end
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
45
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
46 local function publish(session, node, id, item)
2041
8cf9b978ab36 PEP: Fixed namespace for the <item> element in PEP broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents: 1696
diff changeset
47 item.attr.xmlns = nil;
2328
814eaba0c777 mod_pep: Allow storage of urn:xmpp:avatar:data node (payload only with base64 data)
Paul Aurich <paul@darkrain42.org>
parents: 2045
diff changeset
48 local disable = #item.tags ~= 1 or #item.tags[1] == 0;
1619
ae3250783db2 mod_pep: Added support for pubsub item retraction
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
49 if #item.tags == 0 then item.name = "retract"; end
1402
34723bbd5acb mod_pep: Broadcast from the user's bare JID, not full JID
Waqas Hussain <waqas20@gmail.com>
parents: 1401
diff changeset
50 local bare = session.username..'@'..session.host;
34723bbd5acb mod_pep: Broadcast from the user's bare JID, not full JID
Waqas Hussain <waqas20@gmail.com>
parents: 1401
diff changeset
51 local stanza = st.message({from=bare, type='headline'})
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'})
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 :tag('items', {node=node})
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 :add_child(item)
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 :up()
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 :up();
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57
1323
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
58 -- store for the future
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
59 local user_data = data[bare];
1401
a3ce55c1e43a mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents: 1400
diff changeset
60 if disable then
1440
d3117a6ad1bf mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents: 1439
diff changeset
61 if user_data then
d3117a6ad1bf mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents: 1439
diff changeset
62 user_data[node] = nil;
d3117a6ad1bf mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents: 1439
diff changeset
63 if not next(user_data) then data[bare] = nil; end
d3117a6ad1bf mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents: 1439
diff changeset
64 end
1401
a3ce55c1e43a mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents: 1400
diff changeset
65 else
a3ce55c1e43a mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents: 1400
diff changeset
66 if not user_data then user_data = {}; data[bare] = user_data; end
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
67 user_data[node] = {id or "1", item};
1401
a3ce55c1e43a mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents: 1400
diff changeset
68 end
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
69
1430
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
70 -- broadcast
1437
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
71 for recipient, notify in pairs(recipients[bare] or NULL) do
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
72 if notify[node] then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
73 stanza.attr.to = recipient;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
74 core_post_stanza(session, stanza);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
75 end
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 end
1439
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
78 local function publish_all(user, recipient, session)
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
79 local d = data[user];
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
80 local notify = recipients[user] and recipients[user][recipient];
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
81 if d and notify then
1451
cc0aa9470775 mod_pep: Fixed boolean indexing error while casting all messages for a user
Waqas Hussain <waqas20@gmail.com>
parents: 1440
diff changeset
82 for node in pairs(notify) do
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
83 if d[node] then
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
84 local id, item = unpack(d[node]);
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
85 session.send(st.message({from=user, to=recipient, type='headline'})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
86 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
87 :tag('items', {node=node})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
88 :add_child(item)
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
89 :up()
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
90 :up());
1439
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
91 end
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
92 end
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
93 end
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
94 end
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95
1428
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
96 local function get_caps_hash_from_presence(stanza, current)
1429
51cfb152cb38 mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents: 1428
diff changeset
97 local t = stanza.attr.type;
51cfb152cb38 mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents: 1428
diff changeset
98 if not t then
1428
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
99 for _, child in pairs(stanza.tags) do
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
100 if child.name == "c" and child.attr.xmlns == "http://jabber.org/protocol/caps" then
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
101 local attr = child.attr;
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
102 if attr.hash then -- new caps
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
103 if attr.hash == 'sha-1' and attr.node and attr.ver then return attr.ver, attr.node.."#"..attr.ver; end
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
104 else -- legacy caps
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
105 if attr.node and attr.ver then return attr.node.."#"..attr.ver.."#"..(attr.ext or ""), attr.node.."#"..attr.ver; end
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
106 end
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
107 return; -- bad caps format
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
108 end
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
109 end
1429
51cfb152cb38 mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents: 1428
diff changeset
110 elseif t == "unavailable" or t == "error" then
51cfb152cb38 mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents: 1428
diff changeset
111 return;
1428
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
112 end
1429
51cfb152cb38 mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents: 1428
diff changeset
113 return current; -- no caps, could mean caps optimization, so return current
1428
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
114 end
02e97e716675 mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents: 1425
diff changeset
115
1399
8879f8278762 mod_pep: Fixed detection of contact presence changes
Waqas Hussain <waqas20@gmail.com>
parents: 1338
diff changeset
116 module:hook("presence/bare", function(event)
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
117 -- inbound presence to bare JID recieved
1399
8879f8278762 mod_pep: Fixed detection of contact presence changes
Waqas Hussain <waqas20@gmail.com>
parents: 1338
diff changeset
118 local origin, stanza = event.origin, event.stanza;
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
119 local user = stanza.attr.to or (origin.username..'@'..origin.host);
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
120
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
121 if not stanza.attr.to or subscription_presence(user, stanza.attr.from) then
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
122 local recipient = stanza.attr.from;
1430
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
123 local current = recipients[user] and recipients[user][recipient];
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
124 local hash = get_caps_hash_from_presence(stanza, current);
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
125 if current == hash then return; end
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
126 if not hash then
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
127 if recipients[user] then recipients[user][recipient] = nil; end
1430
39169cf8d36f mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents: 1429
diff changeset
128 else
1332
f7fed9f77455 mod_pep: Fix a nil index bug
Waqas Hussain <waqas20@gmail.com>
parents: 1327
diff changeset
129 recipients[user] = recipients[user] or {};
1439
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
130 if hash_map[hash] then
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
131 recipients[user][recipient] = hash_map[hash];
1457
4723bd466a54 mod_pep: Pass origin/session to publish_all()
Matthew Wild <mwild1@gmail.com>
parents: 1451
diff changeset
132 publish_all(user, recipient, origin);
1439
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
133 else
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
134 recipients[user][recipient] = hash;
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
135 origin.send(
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
136 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"})
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
137 :query("http://jabber.org/protocol/disco#info")
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
138 );
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
139 end
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
140 end
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
141 end
1327
20285e9d71ee mod_pep: Give the presence handler a higher than default priority
Waqas Hussain <waqas20@gmail.com>
parents: 1325
diff changeset
142 end, 10);
1325
b58645973d7d mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents: 1324
diff changeset
143
1404
12abd2da8885 mod_pep: Use new style events
Waqas Hussain <waqas20@gmail.com>
parents: 1402
diff changeset
144 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event)
12abd2da8885 mod_pep: Use new style events
Waqas Hussain <waqas20@gmail.com>
parents: 1402
diff changeset
145 local session, stanza = event.origin, event.stanza;
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
146 local payload = stanza.tags[1];
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
147
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148 if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
149 payload = payload.tags[1];
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
150 if payload and (payload.name == 'publish' or payload.name == 'retract') and payload.attr.node then -- <publish node='http://jabber.org/protocol/tune'>
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
151 local node = payload.attr.node;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
152 payload = payload.tags[1];
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
153 if payload and payload.name == "item" then -- <item>
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
154 local id = payload.attr.id;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
155 session.send(st.reply(stanza));
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
156 publish(session, node, id, st.clone(payload));
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
157 return true;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
158 end
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
159 end
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
160 elseif stanza.attr.type == 'get' then
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
161 local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
162 if subscription_presence(user, stanza.attr.from) then
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
163 local user_data = data[user];
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
164 local node, requested_id;
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
165 payload = payload.tags[1];
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
166 if payload and payload.name == 'items' then
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
167 node = payload.attr.node;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
168 local item = payload.tags[1];
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
169 if item and item.name == "item" then
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
170 requested_id = item.attr.id;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
171 end
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
172 end
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
173 if node and user_data and user_data[node] then -- Send the last item
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
174 local id, item = unpack(user_data[node]);
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
175 if not requested_id or id == requested_id then
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
176 local stanza = st.reply(stanza)
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
177 :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
178 :tag('items', {node=node})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
179 :add_child(item)
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
180 :up()
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
181 :up();
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
182 session.send(stanza);
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
183 return true;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
184 else -- requested item doesn't exist
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
185 local stanza = st.reply(stanza)
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
186 :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
187 :tag('items', {node=node})
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
188 :up();
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
189 session.send(stanza);
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
190 return true;
1425
8187f72b7425 mod_pep: Removed some YODO comments
Waqas Hussain <waqas20@gmail.com>
parents: 1424
diff changeset
191 end
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
192 elseif node then -- node doesn't exist
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
193 session.send(st.error_reply(stanza, 'cancel', 'item-not-found'));
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
194 return true;
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
195 else --invalid request
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
196 session.send(st.error_reply(stanza, 'modify', 'bad-request'));
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
197 return true;
1425
8187f72b7425 mod_pep: Removed some YODO comments
Waqas Hussain <waqas20@gmail.com>
parents: 1424
diff changeset
198 end
2329
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
199 else --no presence subscription
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
200 session.send(st.error_reply(stanza, 'auth', 'not-authorized')
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
201 :tag('presence-subscription-required', {xmlns='http://jabber.org/protocol/pubsub#errors'}));
5839f303addf mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents: 2328
diff changeset
202 return true;
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
203 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
204 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
205 end);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
206
1437
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
207 local function calculate_hash(disco_info)
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
208 local identities, features, extensions = {}, {}, {};
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
209 for _, tag in pairs(disco_info) do
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
210 if tag.name == "identity" then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
211 table.insert(identities, (tag.attr.category or "").."\0"..(tag.attr.type or "").."\0"..(tag.attr["xml:lang"] or "").."\0"..(tag.attr.name or ""));
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
212 elseif tag.name == "feature" then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
213 table.insert(features, tag.attr.var or "");
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
214 elseif tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
215 local form = {};
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
216 local FORM_TYPE;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
217 for _, field in pairs(tag.tags) do
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
218 if field.name == "field" and field.attr.var then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
219 local values = {};
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
220 for _, val in pairs(field.tags) do
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
221 val = #val.tags == 0 and table.concat(val); -- FIXME use get_text?
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
222 if val then table.insert(values, val); end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
223 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
224 table.sort(values);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
225 if field.attr.var == "FORM_TYPE" then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
226 FORM_TYPE = values[1];
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
227 elseif #values > 0 then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
228 table.insert(form, field.attr.var.."\0"..table.concat(values, "<"));
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
229 else
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
230 table.insert(form, field.attr.var);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
231 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
232 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
233 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
234 table.sort(form);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
235 form = table.concat(form, "<");
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
236 if FORM_TYPE then form = FORM_TYPE.."\0"..form; end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
237 table.insert(extensions, form);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
238 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
239 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
240 table.sort(identities);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
241 table.sort(features);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
242 table.sort(extensions);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
243 if #identities > 0 then identities = table.concat(identities, "<"):gsub("%z", "/").."<"; else identities = ""; end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
244 if #features > 0 then features = table.concat(features, "<").."<"; else features = ""; end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
245 if #extensions > 0 then extensions = table.concat(extensions, "<"):gsub("%z", "<").."<"; else extensions = ""; end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
246 local S = identities..features..extensions;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
247 local ver = base64(sha1(S));
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
248 return ver, S;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
249 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
250
1424
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
251 module:hook("iq/bare/disco", function(event)
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
252 local session, stanza = event.origin, event.stanza;
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
253 if stanza.attr.type == "result" then
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
254 local disco = stanza.tags[1];
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
255 if disco and disco.name == "query" and disco.attr.xmlns == "http://jabber.org/protocol/disco#info" then
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
256 -- Process disco response
1437
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
257 local user = stanza.attr.to or (session.username..'@'..session.host);
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
258 local contact = stanza.attr.from;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
259 local current = recipients[user] and recipients[user][contact];
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
260 if type(current) ~= "string" then return; end -- check if waiting for recipient's response
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
261 local ver = current;
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
262 if not string.find(current, "#") then
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
263 ver = calculate_hash(disco.tags); -- calculate hash
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
264 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
265 local notify = {};
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
266 for _, feature in pairs(disco.tags) do
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
267 if feature.name == "feature" and feature.attr.var then
1461
51f0202b0868 mod_pep: Escape + in pattern
Matthew Wild <mwild1@gmail.com>
parents: 1457
diff changeset
268 local nfeature = feature.attr.var:match("^(.*)%+notify$");
1437
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
269 if nfeature then notify[nfeature] = true; end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
270 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
271 end
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
272 hash_map[ver] = notify; -- update hash map
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
273 recipients[user][contact] = notify; -- set recipient's data to calculated data
cf2eba9b1716 mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents: 1430
diff changeset
274 -- send messages to recipient
1439
f989608964ec mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents: 1437
diff changeset
275 publish_all(user, contact, session);
1424
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
276 end
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
277 end
6969ad97ca58 mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents: 1404
diff changeset
278 end);
2384
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
279
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
280 module:hook("account-disco-info", function(event)
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
281 local stanza = event.stanza;
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
282 stanza:tag('identity', {category='pubsub', type='pep'}):up();
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
283 stanza:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up();
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
284 end);
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
285
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
286 module:hook("account-disco-items", function(event)
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
287 local session, stanza = event.session, event.stanza;
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
288 local bare = session.username..'@'..session.host;
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
289 local user_data = data[bare];
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
290
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
291 if user_data then
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
292 for node, _ in pairs(user_data) do
2385
470004f8f4ed mod_pep: Added a TODO.
Waqas Hussain <waqas20@gmail.com>
parents: 2384
diff changeset
293 stanza:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes
2384
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
294 end
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
295 end
7bec10f26082 mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 2329
diff changeset
296 end);

mercurial