Software /
code /
prosody
Annotate
plugins/mod_pep_simple.lua @ 9830:d935a0f0de24
MUC: Factor out role change permission check into its own method
I would like to invert this logic so that it checks if the role change
is allowed instead of checking if it is not allowed as it does now, in
order to make it easier to understand.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 24 Feb 2019 16:18:30 +0100 |
parent | 9691:e11e076f0eb8 |
child | 10111:0f335815244f |
rev | line source |
---|---|
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:
2327
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2327
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5683
diff
changeset
|
4 -- |
1522
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 is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
5170 | 14 local pairs = pairs; |
1401
a3ce55c1e43a
mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents:
1400
diff
changeset
|
15 local next = next; |
1437
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
16 local type = type; |
9691
e11e076f0eb8
various: Don't rely on _G.unpack existing
Kim Alvefur <zash@zash.se>
parents:
9074
diff
changeset
|
17 local unpack = table.unpack or unpack; -- luacheck: ignore 113 |
3344 | 18 local calculate_hash = require "util.caps".calculate_hash; |
5013
ab693eea0869
mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table.
Kim Alvefur <zash@zash.se>
parents:
5004
diff
changeset
|
19 local core_post_stanza = prosody.core_post_stanza; |
6865
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
20 local bare_sessions = prosody.bare_sessions; |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 |
8330
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
22 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
23 |
6864
0129ffcaa7ab
mod_pep: Document data structures, so I don't have to spend time remembering every time I work on this module
Matthew Wild <mwild1@gmail.com>
parents:
5804
diff
changeset
|
24 -- Used as canonical 'empty table' |
1430
39169cf8d36f
mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents:
1429
diff
changeset
|
25 local NULL = {}; |
6864
0129ffcaa7ab
mod_pep: Document data structures, so I don't have to spend time remembering every time I work on this module
Matthew Wild <mwild1@gmail.com>
parents:
5804
diff
changeset
|
26 -- data[user_bare_jid][node] = item_stanza |
1323
e1bfe7816761
mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents:
1136
diff
changeset
|
27 local data = {}; |
6864
0129ffcaa7ab
mod_pep: Document data structures, so I don't have to spend time remembering every time I work on this module
Matthew Wild <mwild1@gmail.com>
parents:
5804
diff
changeset
|
28 --- recipients[user_bare_jid][contact_full_jid][subscribed_node] = true |
1325
b58645973d7d
mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents:
1324
diff
changeset
|
29 local recipients = {}; |
6864
0129ffcaa7ab
mod_pep: Document data structures, so I don't have to spend time remembering every time I work on this module
Matthew Wild <mwild1@gmail.com>
parents:
5804
diff
changeset
|
30 -- hash_map[hash][subscribed_nodes] = true |
1437
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
31 local hash_map = {}; |
1323
e1bfe7816761
mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents:
1136
diff
changeset
|
32 |
2045
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
33 module.save = function() |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
34 return { data = data, recipients = recipients, hash_map = hash_map }; |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
35 end |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
36 module.restore = function(state) |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
37 data = state.data or {}; |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
38 recipients = state.recipients or {}; |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
39 hash_map = state.hash_map or {}; |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
40 end |
3b7473a3fa44
PEP: Better reload support.
Waqas Hussain <waqas20@gmail.com>
parents:
2044
diff
changeset
|
41 |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
42 local function subscription_presence(user_bare, recipient) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
43 local recipient_bare = jid_bare(recipient); |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
44 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
|
45 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
|
46 return is_contact_subscribed(username, host, recipient_bare); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
47 end |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
48 |
6544
2f709bc35575
mod_pep: Fire an event when an item is published
Kim Alvefur <zash@zash.se>
parents:
5805
diff
changeset
|
49 module:hook("pep-publish-item", function (event) |
7453
b1efeee55972
mod_pep: Include the bare user jid in event
Kim Alvefur <zash@zash.se>
parents:
6866
diff
changeset
|
50 local session, bare, node, id, item = event.session, event.user, event.node, event.id, event.item; |
2041
8cf9b978ab36
PEP: Fixed namespace for the <item> element in PEP broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
1696
diff
changeset
|
51 item.attr.xmlns = nil; |
2326
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
|
52 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
|
53 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
|
54 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
|
55 :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
|
56 :tag('items', {node=node}) |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 :add_child(item) |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 :up() |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 :up(); |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 |
1323
e1bfe7816761
mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents:
1136
diff
changeset
|
61 -- store for the future |
e1bfe7816761
mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents:
1136
diff
changeset
|
62 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
|
63 if disable then |
1440
d3117a6ad1bf
mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents:
1439
diff
changeset
|
64 if user_data then |
d3117a6ad1bf
mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents:
1439
diff
changeset
|
65 user_data[node] = nil; |
d3117a6ad1bf
mod_pep: Fixed a nil access error
Waqas Hussain <waqas20@gmail.com>
parents:
1439
diff
changeset
|
66 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
|
67 end |
1401
a3ce55c1e43a
mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents:
1400
diff
changeset
|
68 else |
a3ce55c1e43a
mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents:
1400
diff
changeset
|
69 if not user_data then user_data = {}; data[bare] = user_data; end |
5682
e7b9ba2d0638
mod_pep: When a client supplies no id on a published item, reflect our generated id back to it
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
70 user_data[node] = {id, item}; |
1401
a3ce55c1e43a
mod_pep: Remove data when a user disables a node
Waqas Hussain <waqas20@gmail.com>
parents:
1400
diff
changeset
|
71 end |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
72 |
1430
39169cf8d36f
mod_pep: Broadcast only to available recipients with caps
Waqas Hussain <waqas20@gmail.com>
parents:
1429
diff
changeset
|
73 -- broadcast |
1437
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
74 for recipient, notify in pairs(recipients[bare] or NULL) do |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
75 if notify[node] then |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
76 stanza.attr.to = recipient; |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
77 core_post_stanza(session, stanza); |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
78 end |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 end |
6544
2f709bc35575
mod_pep: Fire an event when an item is published
Kim Alvefur <zash@zash.se>
parents:
5805
diff
changeset
|
80 end); |
2f709bc35575
mod_pep: Fire an event when an item is published
Kim Alvefur <zash@zash.se>
parents:
5805
diff
changeset
|
81 |
1439
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
82 local function publish_all(user, recipient, session) |
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
83 local d = data[user]; |
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
84 local notify = recipients[user] and recipients[user][recipient]; |
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
85 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
|
86 for node in pairs(notify) do |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
87 if d[node] then |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
88 local id, item = unpack(d[node]); |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
89 session.send(st.message({from=user, to=recipient, type='headline'}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
90 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
91 :tag('items', {node=node}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
92 :add_child(item) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
93 :up() |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
94 :up()); |
1439
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
95 end |
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
96 end |
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
97 end |
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
98 end |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 |
1428
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
100 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
|
101 local t = stanza.attr.type; |
51cfb152cb38
mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents:
1428
diff
changeset
|
102 if not t then |
1428
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
103 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
|
104 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
|
105 local attr = child.attr; |
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
106 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
|
107 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
|
108 else -- legacy caps |
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
109 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
|
110 end |
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
111 return; -- bad caps format |
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
112 end |
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
113 end |
1429
51cfb152cb38
mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents:
1428
diff
changeset
|
114 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
|
115 return; |
1428
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
116 end |
1429
51cfb152cb38
mod_pep: Ignore presence subscriptions when extractng hash information
Waqas Hussain <waqas20@gmail.com>
parents:
1428
diff
changeset
|
117 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
|
118 end |
02e97e716675
mod_pep: Added function get_caps_hash_from_presence
Waqas Hussain <waqas20@gmail.com>
parents:
1425
diff
changeset
|
119 |
1399
8879f8278762
mod_pep: Fixed detection of contact presence changes
Waqas Hussain <waqas20@gmail.com>
parents:
1338
diff
changeset
|
120 module:hook("presence/bare", function(event) |
8728
41c959c5c84b
Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents:
8330
diff
changeset
|
121 -- inbound presence to bare JID received |
1399
8879f8278762
mod_pep: Fixed detection of contact presence changes
Waqas Hussain <waqas20@gmail.com>
parents:
1338
diff
changeset
|
122 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
|
123 local user = stanza.attr.to or (origin.username..'@'..origin.host); |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
124 local t = stanza.attr.type; |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
125 local self = not stanza.attr.to; |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
126 |
6865
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
127 -- Only cache subscriptions if user is online |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
128 if not bare_sessions[user] then return; end |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
129 |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
130 if not t then -- available presence |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
131 if self or subscription_presence(user, stanza.attr.from) then |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
132 local recipient = stanza.attr.from; |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
133 local current = recipients[user] and recipients[user][recipient]; |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
134 local hash = get_caps_hash_from_presence(stanza, current); |
4207
06eb75d071ec
mod_pep: Fix comparison between incoming hash and the cached hash for a JID, fixes repeated PEP events on presence (fixes #225)
Matthew Wild <mwild1@gmail.com>
parents:
3738
diff
changeset
|
135 if current == hash or (current and current == hash_map[hash]) then return; end |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
136 if not hash then |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
137 if recipients[user] then recipients[user][recipient] = nil; end |
1439
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
138 else |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
139 recipients[user] = recipients[user] or {}; |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
140 if hash_map[hash] then |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
141 recipients[user][recipient] = hash_map[hash]; |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
142 publish_all(user, recipient, origin); |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
143 else |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
144 recipients[user][recipient] = hash; |
3738
ae2ac97b23b1
mod_pep: Fixed a traceback when non-local users send presence.
Waqas Hussain <waqas20@gmail.com>
parents:
3737
diff
changeset
|
145 local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host; |
3737
659563b1db89
mod_pep: Handle the case where local contacts send directed presence with caps hash.
Waqas Hussain <waqas20@gmail.com>
parents:
3668
diff
changeset
|
146 if self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then |
5804
bb27ba619932
mod_pep: Update COMPAT comment, it seems Asterisk 1.8 also suffers from this issue (thanks Lonnie Abelbeck)
Matthew Wild <mwild1@gmail.com>
parents:
5682
diff
changeset
|
147 -- COMPAT from ~= stanza.attr.to because OneTeam and Asterisk 1.8 can't deal with missing from attribute |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
148 origin.send( |
4394
676b0845eae4
mod_pep: Always include a 'from' attribute on service discovery requests to local clients (compatibility fix for OneTeam).
Waqas Hussain <waqas20@gmail.com>
parents:
4207
diff
changeset
|
149 st.stanza("iq", {from=user, to=stanza.attr.from, id="disco", type="get"}) |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
150 :query("http://jabber.org/protocol/disco#info") |
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
151 ); |
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
152 end |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
153 end |
1439
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
154 end |
1325
b58645973d7d
mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents:
1324
diff
changeset
|
155 end |
3132
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
156 elseif t == "unavailable" then |
4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
Waqas Hussain <waqas20@gmail.com>
parents:
3130
diff
changeset
|
157 if recipients[user] then recipients[user][stanza.attr.from] = nil; end |
3668
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
158 elseif not self and t == "unsubscribe" then |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
159 local from = jid_bare(stanza.attr.from); |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
160 local subscriptions = recipients[user]; |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
161 if subscriptions then |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
162 for subscriber in pairs(subscriptions) do |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
163 if jid_bare(subscriber) == from then |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
164 recipients[user][subscriber] = nil; |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
165 end |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
166 end |
29a340777d7b
mod_pep: Remove PEP subscriptions on getting a presence unsubscribe.
Waqas Hussain <waqas20@gmail.com>
parents:
3667
diff
changeset
|
167 end |
1325
b58645973d7d
mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents:
1324
diff
changeset
|
168 end |
1327
20285e9d71ee
mod_pep: Give the presence handler a higher than default priority
Waqas Hussain <waqas20@gmail.com>
parents:
1325
diff
changeset
|
169 end, 10); |
1325
b58645973d7d
mod_pep: Send items to contacts coming online
Waqas Hussain <waqas20@gmail.com>
parents:
1324
diff
changeset
|
170 |
1404
12abd2da8885
mod_pep: Use new style events
Waqas Hussain <waqas20@gmail.com>
parents:
1402
diff
changeset
|
171 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
|
172 local session, stanza = event.origin, event.stanza; |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
173 local payload = stanza.tags[1]; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
174 |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
175 if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then |
8965
1cc5ea1df5ba
mod_pep: Move comment to a shorter line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8728
diff
changeset
|
176 payload = payload.tags[1]; -- <publish node='http://jabber.org/protocol/tune'> |
1cc5ea1df5ba
mod_pep: Move comment to a shorter line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8728
diff
changeset
|
177 if payload and (payload.name == 'publish' or payload.name == 'retract') and payload.attr.node then |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
178 local node = payload.attr.node; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
179 payload = payload.tags[1]; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
180 if payload and payload.name == "item" then -- <item> |
5682
e7b9ba2d0638
mod_pep: When a client supplies no id on a published item, reflect our generated id back to it
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
181 local id = payload.attr.id or "1"; |
e7b9ba2d0638
mod_pep: When a client supplies no id on a published item, reflect our generated id back to it
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
182 payload.attr.id = id; |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
183 session.send(st.reply(stanza)); |
6544
2f709bc35575
mod_pep: Fire an event when an item is published
Kim Alvefur <zash@zash.se>
parents:
5805
diff
changeset
|
184 module:fire_event("pep-publish-item", { |
8124
20e92f6688b2
mod_pep: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7871
diff
changeset
|
185 node = node, user = jid_bare(session.full_jid), actor = session.jid, |
20e92f6688b2
mod_pep: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7871
diff
changeset
|
186 id = id, session = session, item = st.clone(payload); |
6544
2f709bc35575
mod_pep: Fire an event when an item is published
Kim Alvefur <zash@zash.se>
parents:
5805
diff
changeset
|
187 }); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
188 return true; |
7871
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
189 else |
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
190 module:log("debug", "Payload is missing the <item>", node); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
191 end |
7871
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
192 else |
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
193 module:log("debug", "Unhandled payload: %s", payload and payload:top_tag() or "(no payload)"); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
194 end |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
195 elseif stanza.attr.type == 'get' then |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
196 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:
2326
diff
changeset
|
197 if subscription_presence(user, stanza.attr.from) then |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
198 local user_data = data[user]; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
199 local node, requested_id; |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
200 payload = payload.tags[1]; |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
201 if payload and payload.name == 'items' then |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
202 node = payload.attr.node; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
203 local item = payload.tags[1]; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
204 if item and item.name == "item" then |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
205 requested_id = item.attr.id; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
206 end |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
207 end |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
208 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:
2326
diff
changeset
|
209 local id, item = unpack(user_data[node]); |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
210 if not requested_id or id == requested_id then |
8966
9106e9286203
mod_pep: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8965
diff
changeset
|
211 local reply_stanza = st.reply(stanza) |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
212 :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
213 :tag('items', {node=node}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
214 :add_child(item) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
215 :up() |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
216 :up(); |
8966
9106e9286203
mod_pep: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8965
diff
changeset
|
217 session.send(reply_stanza); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
218 return true; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
219 else -- requested item doesn't exist |
8966
9106e9286203
mod_pep: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8965
diff
changeset
|
220 local reply_stanza = st.reply(stanza) |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
221 :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
222 :tag('items', {node=node}) |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
223 :up(); |
8966
9106e9286203
mod_pep: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8965
diff
changeset
|
224 session.send(reply_stanza); |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
225 return true; |
1425
8187f72b7425
mod_pep: Removed some YODO comments
Waqas Hussain <waqas20@gmail.com>
parents:
1424
diff
changeset
|
226 end |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
227 elseif node then -- node doesn't exist |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
228 session.send(st.error_reply(stanza, 'cancel', 'item-not-found')); |
7871
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
229 module:log("debug", "Item '%s' not found", node) |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
230 return true; |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
231 else --invalid request |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
232 session.send(st.error_reply(stanza, 'modify', 'bad-request')); |
7871
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
233 module:log("debug", "Invalid request: %s", tostring(payload)); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
234 return true; |
1425
8187f72b7425
mod_pep: Removed some YODO comments
Waqas Hussain <waqas20@gmail.com>
parents:
1424
diff
changeset
|
235 end |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
236 else --no presence subscription |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
237 session.send(st.error_reply(stanza, 'auth', 'not-authorized') |
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
238 :tag('presence-subscription-required', {xmlns='http://jabber.org/protocol/pubsub#errors'})); |
7871
09aa0453bdcc
mod_pep: Add some additional debug logging
Kim Alvefur <zash@zash.se>
parents:
7454
diff
changeset
|
239 module:log("debug", "Unauthorized request: %s", tostring(payload)); |
2327
5839f303addf
mod_pep: Support item retrieval use cases
Paul Aurich <paul@darkrain42.org>
parents:
2326
diff
changeset
|
240 return true; |
1136
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
241 end |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
242 end |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
243 end); |
506012db54e8
mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
244 |
3648
c0148fddd81f
mod_pep: Updated disco#info result handler to use new event name format.
Waqas Hussain <waqas20@gmail.com>
parents:
3344
diff
changeset
|
245 module:hook("iq-result/bare/disco", function(event) |
1424
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
246 local session, stanza = event.origin, event.stanza; |
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
247 if stanza.attr.type == "result" then |
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
248 local disco = stanza.tags[1]; |
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
249 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
|
250 -- Process disco response |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
251 local self = not stanza.attr.to; |
1437
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
252 local user = stanza.attr.to or (session.username..'@'..session.host); |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
253 local contact = stanza.attr.from; |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
254 local current = recipients[user] and recipients[user][contact]; |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
255 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
|
256 local ver = current; |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
257 if not string.find(current, "#") then |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
258 ver = calculate_hash(disco.tags); -- calculate hash |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
259 end |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
260 local notify = {}; |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
261 for _, feature in pairs(disco.tags) do |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
262 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
|
263 local nfeature = feature.attr.var:match("^(.*)%+notify$"); |
1437
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
264 if nfeature then notify[nfeature] = true; end |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
265 end |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
266 end |
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
267 hash_map[ver] = notify; -- update hash map |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
268 if self then |
3666
44c4789d6e17
mod_pep: Fixed a nil access (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3664
diff
changeset
|
269 for jid, item in pairs(session.roster) do -- for all interested contacts |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
270 if item.subscription == "both" or item.subscription == "from" then |
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
271 if not recipients[jid] then recipients[jid] = {}; end |
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
272 recipients[jid][contact] = notify; |
3667
5c39dce29eaf
mod_pep: Fixed regression where PEP messages were not correctly being broadcasted on caps hash change.
Waqas Hussain <waqas20@gmail.com>
parents:
3666
diff
changeset
|
273 publish_all(jid, contact, session); |
3664
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
274 end |
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
275 end |
345cd1e04e80
mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
Waqas Hussain <waqas20@gmail.com>
parents:
3648
diff
changeset
|
276 end |
3667
5c39dce29eaf
mod_pep: Fixed regression where PEP messages were not correctly being broadcasted on caps hash change.
Waqas Hussain <waqas20@gmail.com>
parents:
3666
diff
changeset
|
277 recipients[user][contact] = notify; -- set recipient's data to calculated data |
1437
cf2eba9b1716
mod_pep: Entity capabilities
Waqas Hussain <waqas20@gmail.com>
parents:
1430
diff
changeset
|
278 -- send messages to recipient |
1439
f989608964ec
mod_pep: Use cached caps
Waqas Hussain <waqas20@gmail.com>
parents:
1437
diff
changeset
|
279 publish_all(user, contact, session); |
1424
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
280 end |
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
281 end |
6969ad97ca58
mod_pep: Added handler for disco responses
Waqas Hussain <waqas20@gmail.com>
parents:
1404
diff
changeset
|
282 end); |
2384
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
283 |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
284 module:hook("account-disco-info", function(event) |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
285 local reply = event.reply; |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
286 reply:tag('identity', {category='pubsub', type='pep'}):up(); |
8330
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
287 reply:tag('feature', {var=xmlns_pubsub}):up(); |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
288 local features = { |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
289 "access-presence", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
290 "auto-create", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
291 "auto-subscribe", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
292 "filtered-notifications", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
293 "item-ids", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
294 "last-published", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
295 "presence-notifications", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
296 "presence-subscribe", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
297 "publish", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
298 "retract-items", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
299 "retrieve-items", |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
300 }; |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
301 for _, feature in ipairs(features) do |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
302 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); |
8d5c2eef1654
mod_pep: Advertise pubsub features that I believe to be implented
Kim Alvefur <zash@zash.se>
parents:
8329
diff
changeset
|
303 end |
2384
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
304 end); |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
305 |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
306 module:hook("account-disco-items", function(event) |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
307 local reply = event.reply; |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5170
diff
changeset
|
308 local bare = reply.attr.to; |
2384
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
309 local user_data = data[bare]; |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
310 |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
311 if user_data then |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
312 for node, _ in pairs(user_data) do |
8125
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
313 reply:tag('item', {jid=bare, node=node}):up(); |
2384
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
314 end |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
315 end |
7bec10f26082
mod_pep: Handle service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
2327
diff
changeset
|
316 end); |
6865
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
317 |
8125
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
318 module:hook("account-disco-info-node", function (event) |
8967
c809f334363c
mod_pep: Remove unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8966
diff
changeset
|
319 local stanza, node = event.stanza, event.node; |
8125
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
320 local user = stanza.attr.to; |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
321 local user_data = data[user]; |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
322 if user_data and user_data[node] then |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
323 event.exists = true; |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
324 event.reply:tag('identity', {category='pubsub', type='leaf'}):up(); |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
325 end |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
326 end); |
5f0c642a41a1
mod_pep: Handle disco#info queries to nodes (fixes #805)
Kim Alvefur <zash@zash.se>
parents:
8124
diff
changeset
|
327 |
6865
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
328 module:hook("resource-unbind", function (event) |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
329 local user_bare_jid = event.session.username.."@"..event.session.host; |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
330 if not bare_sessions[user_bare_jid] then -- User went offline |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
331 -- We don't need this info cached anymore, clear it. |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
332 recipients[user_bare_jid] = nil; |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
333 end |
20b0f0b48655
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
Matthew Wild <mwild1@gmail.com>
parents:
6864
diff
changeset
|
334 end); |