Annotate

plugins/mod_pep.lua @ 9074:0462405b1cfb

mod_pep -> mod_pep_simple, mod_pep_plus -> mod_pep
author Matthew Wild <mwild1@gmail.com>
date Wed, 01 Aug 2018 19:08:09 +0100
parent 9061:plugins/mod_pep_plus.lua@82dd435c942c
child 9077:aefb96a52f5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 local pubsub = require "util.pubsub";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 local jid_bare = require "util.jid".bare;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 local jid_split = require "util.jid".split;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
4 local jid_join = require "util.jid".join;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 local set_new = require "util.set".new;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 local st = require "util.stanza";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7 local calculate_hash = require "util.caps".calculate_hash;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
8320
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
9 local cache = require "util.cache";
8341
910d3c3f60a6 mod_pep_plus: Use feature detection from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8339
diff changeset
10 local set = require "util.set";
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 local lib_pubsub = module:require "pubsub";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
18 local empty_set = set_new();
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
19
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 local services = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 local recipients = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 local hash_map = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
24 local host = module.host;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
25
8949
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
26 local node_config = module:open_store("pep", "map");
8306
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
27 local known_nodes = module:open_store("pep");
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
28
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29 function module.save()
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30 return { services = services };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
32
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
33 function module.restore(data)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
34 services = data.services;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
35 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
36
8696
164da3186511 mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8377
diff changeset
37 function is_item_stanza(item)
164da3186511 mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8377
diff changeset
38 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item";
164da3186511 mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8377
diff changeset
39 end
164da3186511 mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8377
diff changeset
40
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
41 local function subscription_presence(username, recipient)
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
42 local user_bare = jid_join(username, host);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 local recipient_bare = jid_bare(recipient);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 if (recipient_bare == user_bare) then return true; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 return is_contact_subscribed(username, host, recipient_bare);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47
8949
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
48 local function nodestore(username)
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
49 -- luacheck: ignore 212/self
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
50 local store = {};
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
51 function store:get(node)
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
52 local data, err = node_config:get(username, node)
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
53 if data == true then
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
54 -- COMPAT Previously stored only a boolean representing 'persist_items'
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
55 data = {
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
56 name = node;
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
57 config = {};
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
58 subscribers = {};
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
59 affiliations = {};
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
60 };
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
61 end
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
62 return data, err;
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
63 end
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
64 function store:set(node, data)
9029
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
65 if data then
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
66 -- Save the data without subscriptions
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
67 -- TODO Save explicit subscriptions maybe?
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
68 data = {
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
69 name = data.name;
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
70 config = data.config;
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
71 affiliations = data.affiliations;
9030
7d0b7e086c6a mod_pep_plus: Include an empty set of subscribers (fixes traceback)
Kim Alvefur <zash@zash.se>
parents: 9029
diff changeset
72 subscribers = {};
9029
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
73 };
c5e738b54d77 mod_pep_plus: Don't save subscriptions since they are normally session based and transient
Kim Alvefur <zash@zash.se>
parents: 8982
diff changeset
74 end
8949
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
75 return node_config:set(username, node, data);
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
76 end
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
77 function store:users()
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
78 return pairs(known_nodes:get(username) or {});
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
79 end
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
80 return store;
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
81 end
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
82
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
83 local function simple_itemstore(username)
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
84 return function (config, node)
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8332
diff changeset
85 if config["persist_items"] then
8320
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
86 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
87 local archive = module:open_store("pep_"..node, "archive");
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
88 return lib_pubsub.archive_itemstore(archive, config, username, node, false);
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
89 else
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
90 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8332
diff changeset
91 return cache.new(tonumber(config["max_items"]));
8320
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8319
diff changeset
92 end
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
93 end
8215
835bb32c36b4 mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8214
diff changeset
94 end
835bb32c36b4 mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8214
diff changeset
95
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
96 local function get_broadcaster(username)
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
97 local user_bare = jid_join(username, host);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 local function simple_broadcast(kind, node, jids, item)
8895
d00ea07de9a0 mod_pep_plus: Prevent nil from being added as a child on item deletion.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8753
diff changeset
99 local message = st.message({ from = user_bare, type = "headline" })
d00ea07de9a0 mod_pep_plus: Prevent nil from being added as a child on item deletion.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8753
diff changeset
100 :tag("event", { xmlns = xmlns_pubsub_event })
d00ea07de9a0 mod_pep_plus: Prevent nil from being added as a child on item deletion.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8753
diff changeset
101 :tag(kind, { node = node });
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 if item then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 item = st.clone(item);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 item.attr.xmlns = nil; -- Clear the pubsub namespace
8895
d00ea07de9a0 mod_pep_plus: Prevent nil from being added as a child on item deletion.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8753
diff changeset
105 message:add_child(item);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 for jid in pairs(jids) do
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
108 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item));
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 message.attr.to = jid;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 module:send(message);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 return simple_broadcast;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
116 function get_pep_service(username)
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
117 module:log("debug", "get_pep_service(%q)", username);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
118 local user_bare = jid_join(username, host);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
119 local service = services[username];
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
120 if service then
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
121 return service;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122 end
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
123 service = pubsub.new({
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 capabilities = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 none = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127 publish = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 retract = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 get_nodes = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131 subscribe = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 unsubscribe = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 get_subscription = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 get_subscriptions = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135 get_items = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
139 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
140 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
143 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
144
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
145 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
147 subscriber = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
148 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
149 publish = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150 retract = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
151 get_nodes = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
152
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
153 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
154 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
155 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
156 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
157 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
158
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
159 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
160 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
161 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
162 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
163
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
164 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
165 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
166
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
167 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
168 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
169 publisher = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
170 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
171 publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
172 retract = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
173 get_nodes = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
174
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
175 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
176 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
177 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
178 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
180
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
181 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
182 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
183 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
184 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
185
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
186 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
187 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
188
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
189 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
190 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
191 owner = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
192 create = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
193 publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
194 retract = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
195 delete = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
196 get_nodes = true;
6443
f4403c270ea2 mod_pep_plus: Add node config form
Kim Alvefur <zash@zash.se>
parents: 6432
diff changeset
197 configure = true;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
198
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
199 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
200 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
201 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
202 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
203 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
204
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
205
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
206 subscribe_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
207 unsubscribe_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
208 get_subscription_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
209 get_subscriptions_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
210
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
211 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
212 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
213
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
214 set_affiliation = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
215 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
216 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
217
6444
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
218 node_defaults = {
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8332
diff changeset
219 ["max_items"] = 1;
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8332
diff changeset
220 ["persist_items"] = true;
6444
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
221 };
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
222
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
223 autocreate_on_publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
224 autocreate_on_subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
225
8949
9194431b6447 mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents: 8895
diff changeset
226 nodestore = nodestore(username);
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
227 itemstore = simple_itemstore(username);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
228 broadcaster = get_broadcaster(username);
8696
164da3186511 mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8377
diff changeset
229 itemcheck = is_item_stanza;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
230 get_affiliation = function (jid)
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
231 if jid_bare(jid) == user_bare then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
232 return "owner";
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
233 elseif subscription_presence(username, jid) then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
234 return "subscriber";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
235 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
236 end;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
237
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
238 normalize_jid = jid_bare;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
239 });
8306
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
240 local nodes, err = known_nodes:get(username);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
241 if nodes then
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
242 module:log("debug", "Restoring nodes for user %s", username);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
243 for node in pairs(nodes) do
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
244 module:log("debug", "Restoring node %q", node);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
245 service:create(node, true);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
246 end
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
247 elseif err then
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
248 module:log("error", "Could not restore nodes for %s: %s", username, err);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
249 else
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
250 module:log("debug", "No known nodes");
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
251 end
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
252 services[username] = service;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
253 module:add_item("pep-service", { service = service, jid = user_bare });
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
254 return service;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
255 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
256
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
257 function handle_pubsub_iq(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
258 local origin, stanza = event.origin, event.stanza;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
259 local service_name = origin.username;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
260 if stanza.attr.to ~= nil then
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
261 service_name = jid_split(stanza.attr.to);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
262 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
263 local service = get_pep_service(service_name);
8335
9db72349095f mod_pep_plus: Use dispatch function from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
264
9db72349095f mod_pep_plus: Use dispatch function from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
265 return lib_pubsub.handle_pubsub_iq(event, service)
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
266 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
267
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
268 module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
269 module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
270
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
271 module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody"));
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
272 module:add_feature("http://jabber.org/protocol/pubsub#publish");
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
273
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
274 local function get_caps_hash_from_presence(stanza, current)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
275 local t = stanza.attr.type;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
276 if not t then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
277 local child = stanza:get_child("c", "http://jabber.org/protocol/caps");
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
278 if child then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
279 local attr = child.attr;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
280 if attr.hash then -- new caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
281 if attr.hash == 'sha-1' and attr.node and attr.ver then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
282 return attr.ver, attr.node.."#"..attr.ver;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
283 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
284 else -- legacy caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
285 if attr.node and attr.ver then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
286 return attr.node.."#"..attr.ver.."#"..(attr.ext or ""), attr.node.."#"..attr.ver;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
287 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
288 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
289 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
290 return; -- no or bad caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
291 elseif t == "unavailable" or t == "error" then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
292 return;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
293 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
294 return current; -- no caps, could mean caps optimization, so return current
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
295 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
296
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
297 local function resend_last_item(jid, node, service)
8377
58cdbbe3b86a mod_pep_plus: Broadcast only the last item (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8342
diff changeset
298 local ok, id, item = service:get_last_item(node, jid);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
299 if not ok then return; end
8377
58cdbbe3b86a mod_pep_plus: Broadcast only the last item (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8342
diff changeset
300 if not id then return; end
58cdbbe3b86a mod_pep_plus: Broadcast only the last item (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8342
diff changeset
301 service.config.broadcaster("items", node, { [jid] = true }, item);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
302 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
303
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
304 local function update_subscriptions(recipient, service_name, nodes)
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
305 nodes = nodes or empty_set;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
306
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
307 local service_recipients = recipients[service_name];
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
308 if not service_recipients then
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
309 service_recipients = {};
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
310 recipients[service_name] = service_recipients;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
311 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
312
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
313 local current = service_recipients[recipient];
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
314 if not current or type(current) ~= "table" then
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
315 current = empty_set;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
316 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
317
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
318 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
319 return;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
320 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
321
8753
d6373a378b73 mod_pep_plus: Skip getting PEP service instance for sessions that have not touched PEP
Kim Alvefur <zash@zash.se>
parents: 8728
diff changeset
322 local service = get_pep_service(service_name);
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
323 for node in current - nodes do
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
324 service:remove_subscription(node, recipient, recipient);
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
325 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
326
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
327 for node in nodes - current do
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
328 service:add_subscription(node, recipient, recipient);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
329 resend_last_item(recipient, node, service);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
330 end
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
331
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
332 if nodes == empty_set or nodes:empty() then
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
333 nodes = nil;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
334 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
335
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
336 service_recipients[recipient] = nodes;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
337 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
338
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
339 module:hook("presence/bare", function(event)
8728
41c959c5c84b Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents: 8696
diff changeset
340 -- inbound presence to bare JID received
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
341 local origin, stanza = event.origin, event.stanza;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
342 local t = stanza.attr.type;
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
343 local is_self = not stanza.attr.to;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
344 local username = jid_split(stanza.attr.to);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
345 local user_bare = jid_bare(stanza.attr.to);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
346 if is_self then
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
347 username = origin.username;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
348 user_bare = jid_join(username, host);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
349 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
350
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
351 if not t then -- available presence
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
352 if is_self or subscription_presence(username, stanza.attr.from) then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
353 local recipient = stanza.attr.from;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
354 local current = recipients[username] and recipients[username][recipient];
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
355 local hash, query_node = get_caps_hash_from_presence(stanza, current);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
356 if current == hash or (current and current == hash_map[hash]) then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
357 if not hash then
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
358 update_subscriptions(recipient, username);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
359 else
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
360 recipients[username] = recipients[username] or {};
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
361 if hash_map[hash] then
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
362 update_subscriptions(recipient, username, hash_map[hash]);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
363 else
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
364 recipients[username][recipient] = hash;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
365 local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
366 if is_self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
367 -- COMPAT from ~= stanza.attr.to because OneTeam can't deal with missing from attribute
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
368 origin.send(
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
369 st.stanza("iq", {from=user_bare, to=stanza.attr.from, id="disco", type="get"})
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
370 :tag("query", {xmlns = "http://jabber.org/protocol/disco#info", node = query_node})
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
371 );
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
372 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
373 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
374 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
375 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
376 elseif t == "unavailable" then
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
377 update_subscriptions(stanza.attr.from, username);
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
378 elseif not is_self and t == "unsubscribe" then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
379 local from = jid_bare(stanza.attr.from);
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
380 local subscriptions = recipients[username];
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
381 if subscriptions then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
382 for subscriber in pairs(subscriptions) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
383 if jid_bare(subscriber) == from then
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
384 update_subscriptions(subscriber, username);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
385 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
386 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
387 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
388 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
389 end, 10);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
390
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
391 module:hook("iq-result/bare/disco", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
392 local origin, stanza = event.origin, event.stanza;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
393 local disco = stanza:get_child("query", "http://jabber.org/protocol/disco#info");
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
394 if not disco then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
395 return;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
396 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
397
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
398 -- Process disco response
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
399 local is_self = stanza.attr.to == nil;
8315
967f04fe7fd4 mod_pep_plus: Add missing variable
Kim Alvefur <zash@zash.se>
parents: 8307
diff changeset
400 local user_bare = jid_bare(stanza.attr.to);
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
401 local username = jid_split(stanza.attr.to);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
402 if is_self then
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
403 username = origin.username;
8315
967f04fe7fd4 mod_pep_plus: Add missing variable
Kim Alvefur <zash@zash.se>
parents: 8307
diff changeset
404 user_bare = jid_join(username, host);
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
405 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
406 local contact = stanza.attr.from;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
407 local current = recipients[username] and recipients[username][contact];
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
408 if type(current) ~= "string" then return; end -- check if waiting for recipient's response
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
409 local ver = current;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
410 if not string.find(current, "#") then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
411 ver = calculate_hash(disco.tags); -- calculate hash
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
412 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
413 local notify = set_new();
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
414 for _, feature in pairs(disco.tags) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
415 if feature.name == "feature" and feature.attr.var then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
416 local nfeature = feature.attr.var:match("^(.*)%+notify$");
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
417 if nfeature then notify:add(nfeature); end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
418 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
419 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
420 hash_map[ver] = notify; -- update hash map
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
421 if is_self then
8307
94860b5733d3 mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents: 8306
diff changeset
422 -- Optimization: Fiddle with other local users
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
423 for jid, item in pairs(origin.roster) do -- for all interested contacts
8304
9f8476c77fa8 mod_pep_plus: Skip over roster metadata (version, pending) entry
Kim Alvefur <zash@zash.se>
parents: 8303
diff changeset
424 if jid then
8307
94860b5733d3 mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents: 8306
diff changeset
425 local contact_node, contact_host = jid_split(jid);
9061
82dd435c942c mod_pep_plus: Fix boolean logic precedence (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 9030
diff changeset
426 if contact_host == host and (item.subscription == "both" or item.subscription == "from") then
8307
94860b5733d3 mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents: 8306
diff changeset
427 update_subscriptions(user_bare, contact_node, notify);
8304
9f8476c77fa8 mod_pep_plus: Skip over roster metadata (version, pending) entry
Kim Alvefur <zash@zash.se>
parents: 8303
diff changeset
428 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
429 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
430 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
431 end
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
432 update_subscriptions(contact, username, notify);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
433 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
434
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
435 module:hook("account-disco-info-node", function(event)
8982
4a576c39bb2f mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8949
diff changeset
436 local stanza, origin = event.stanza, event.origin;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
437 local service_name = origin.username;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
438 if stanza.attr.to ~= nil then
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
439 service_name = jid_split(stanza.attr.to);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
440 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
441 local service = get_pep_service(service_name);
8982
4a576c39bb2f mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8949
diff changeset
442 return lib_pubsub.handle_disco_info_node(event, service);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
443 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
444
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
445 module:hook("account-disco-info", function(event)
8319
57e3ad11f3f6 mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
446 local origin, reply = event.origin, event.reply;
57e3ad11f3f6 mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
447
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
448 reply:tag('identity', {category='pubsub', type='pep'}):up();
8319
57e3ad11f3f6 mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
449
57e3ad11f3f6 mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
450 local username = jid_split(reply.attr.from) or origin.username;
57e3ad11f3f6 mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
451 local service = get_pep_service(username);
57e3ad11f3f6 mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
452
8342
0c0990a575de mod_pep_plus: Fix a typo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8341
diff changeset
453 local supported_features = lib_pubsub.get_feature_set(service) + set.new{
8341
910d3c3f60a6 mod_pep_plus: Use feature detection from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8339
diff changeset
454 -- Features not covered by the above
8332
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
455 "access-presence",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
456 "auto-subscribe",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
457 "filtered-notifications",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
458 "last-published",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
459 "persistent-items",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
460 "presence-notifications",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
461 "presence-subscribe",
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
462 };
8341
910d3c3f60a6 mod_pep_plus: Use feature detection from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8339
diff changeset
463
8342
0c0990a575de mod_pep_plus: Fix a typo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8341
diff changeset
464 for feature in supported_features do
8332
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
465 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up();
e89b57d0d80a mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents: 8331
diff changeset
466 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
467 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
468
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
469 module:hook("account-disco-items-node", function(event)
8982
4a576c39bb2f mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8949
diff changeset
470 local stanza, origin = event.stanza, event.origin;
8321
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
471 local is_self = stanza.attr.to == nil;
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
472 local username = jid_split(stanza.attr.to);
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
473 if is_self then
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
474 username = origin.username;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
475 end
8321
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
476 local service = get_pep_service(username);
8982
4a576c39bb2f mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8949
diff changeset
477 return lib_pubsub.handle_disco_items_node(event, service);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
478 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
479
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
480 module:hook("account-disco-items", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
481 local reply, stanza, origin = event.reply, event.stanza, event.origin;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
482
8321
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
483 local is_self = stanza.attr.to == nil;
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
484 local user_bare = jid_bare(stanza.attr.to);
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
485 local username = jid_split(stanza.attr.to);
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
486 if is_self then
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
487 username = origin.username;
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
488 user_bare = jid_join(username, host);
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
489 end
8321
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
490 local service = get_pep_service(username);
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
491
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
492 local ok, ret = service:get_nodes(jid_bare(stanza.attr.from));
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
493 if not ok then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
494
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
495 for node, node_obj in pairs(ret) do
8321
73ff49a42ea8 mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents: 8320
diff changeset
496 reply:tag("item", { jid = user_bare, node = node, name = node_obj.config.name }):up();
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
497 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
498 end);