Annotate

plugins/mod_pep_plus.lua @ 8300:7759eb130938

mod_pep_plus, mod_pubsub: Store node content in separate archive stores
author Kim Alvefur <zash@zash.se>
date Sun, 08 Oct 2017 01:56:44 +0200
parent 8218:2c75a5ba58fc
child 8303:053cf683c2c7
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;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 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
5 local st = require "util.stanza";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 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
7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
9 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
10 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
11 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
12
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 local lib_pubsub = module:require "pubsub";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local handlers = lib_pubsub.handlers;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
16 local empty_set = set_new();
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
17
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 local services = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 local recipients = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 local hash_map = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 function module.save()
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 return { services = services };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 function module.restore(data)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 services = data.services;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30 local function subscription_presence(user_bare, recipient)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 local recipient_bare = jid_bare(recipient);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
32 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
33 local username, host = jid_split(user_bare);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
34 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
35 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
36
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
37 local function simple_itemstore(user)
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
38 return function (config, node)
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8218
diff changeset
39 module:log("debug", "new simple_itemstore(%q, %q)", user, node);
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8218
diff changeset
40 local archive = module:open_store("pep_"..node, "archive");
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
41 return lib_pubsub.simple_itemstore(archive, config, user, node, false);
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
42 end
8215
835bb32c36b4 mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8214
diff changeset
43 end
835bb32c36b4 mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8214
diff changeset
44
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 local function get_broadcaster(name)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 local function simple_broadcast(kind, node, jids, item)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 if item then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 item = st.clone(item);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 item.attr.xmlns = nil; -- Clear the pubsub namespace
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51 local message = st.message({ from = name, type = "headline" })
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52 :tag("event", { xmlns = xmlns_pubsub_event })
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 :tag(kind, { node = node })
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
54 :add_child(item);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
55 for jid in pairs(jids) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
56 module:log("debug", "Sending notification to %s from %s: %s", jid, name, tostring(item));
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 message.attr.to = jid;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58 module:send(message);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
59 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
60 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
61 return simple_broadcast;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
62 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63
6264
12a083299bb7 mod_pep_plus: Expose get_pep_service()
Kim Alvefur <zash@zash.se>
parents: 5852
diff changeset
64 function get_pep_service(name)
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8218
diff changeset
65 module:log("debug", "get_pep_service(%q)");
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
66 local service = services[name];
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
67 if service then
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
68 return service;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 end
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
70 service = pubsub.new({
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71 capabilities = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
72 none = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74 publish = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75 retract = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
76 get_nodes = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
77
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 subscribe = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
79 unsubscribe = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 get_subscription = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81 get_subscriptions = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
82 get_items = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
83
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
89 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
93 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 subscriber = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96 publish = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97 retract = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 get_nodes = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
100 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
105
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 publisher = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118 publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 retract = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 get_nodes = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138 owner = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
139 create = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
140 publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141 retract = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 delete = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
143 get_nodes = true;
6443
f4403c270ea2 mod_pep_plus: Add node config form
Kim Alvefur <zash@zash.se>
parents: 6432
diff changeset
144 configure = true;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
145
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
147 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
148 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
149 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
151
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_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
154 unsubscribe_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
155 get_subscription_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
156 get_subscriptions_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
157
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
158 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
159 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
160
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
161 set_affiliation = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
162 };
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
6444
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
165 node_defaults = {
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
166 ["pubsub#max_items"] = "1";
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
167 };
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
168
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
169 autocreate_on_publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
170 autocreate_on_subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
171
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
172 itemstore = simple_itemstore(name);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
173 broadcaster = get_broadcaster(name);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
174 get_affiliation = function (jid)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
175 if jid_bare(jid) == name then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
176 return "owner";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
177 elseif subscription_presence(name, jid) then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
178 return "subscriber";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
180 end;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
181
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
182 normalize_jid = jid_bare;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
183 });
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
184 services[name] = service;
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
185 module:add_item("pep-service", { service = service, jid = name });
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
186 return service;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
187 end
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 function handle_pubsub_iq(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
190 local origin, stanza = event.origin, event.stanza;
8214
da8bc600902a mod_pep_plus: Fix all of the warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6449
diff changeset
191 local pubsub_tag = stanza.tags[1];
da8bc600902a mod_pep_plus: Fix all of the warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6449
diff changeset
192 local action = pubsub_tag.tags[1];
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
193 if not action then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
194 return origin.send(st.error_reply(stanza, "cancel", "bad-request"));
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
195 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
196 local service_name = stanza.attr.to or origin.username.."@"..origin.host
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
197 local service = get_pep_service(service_name);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
198 local handler = handlers[stanza.attr.type.."_"..action.name];
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
199 if handler then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
200 handler(origin, stanza, action, service);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
201 return true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
202 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
203 end
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 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
206 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
207
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
208 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
209 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
210
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
211 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
212 local t = stanza.attr.type;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
213 if not t then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
214 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
215 if child then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
216 local attr = child.attr;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
217 if attr.hash then -- new caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
218 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
219 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
220 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
221 else -- legacy caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
222 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
223 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
224 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
225 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
226 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
227 return; -- no or bad caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
228 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
229 return;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
230 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
231 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
232 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
233
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
234 local function resend_last_item(jid, node, service)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
235 local ok, items = service:get_items(node, jid);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
236 if not ok then return; end
8214
da8bc600902a mod_pep_plus: Fix all of the warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6449
diff changeset
237 for _, id in ipairs(items) do
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
238 service.config.broadcaster("items", node, { [jid] = true }, items[id]);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
239 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
240 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
241
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
242 local function update_subscriptions(recipient, service_name, nodes)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
243 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
244 nodes = nodes or empty_set;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
245
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
246 local service_recipients = recipients[service_name];
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
247 if not service_recipients then
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
248 service_recipients = {};
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
249 recipients[service_name] = service_recipients;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
250 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
251
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
252 local current = service_recipients[recipient];
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
253 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
254 current = empty_set;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
255 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
256
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
257 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
258 return;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
259 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
260
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
261 for node in current - nodes do
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
262 service:remove_subscription(node, recipient, recipient);
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
263 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
264
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
265 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
266 service:add_subscription(node, recipient, recipient);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
267 resend_last_item(recipient, node, service);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
268 end
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
269
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
270 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
271 nodes = nil;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
272 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
273
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
274 service_recipients[recipient] = nodes;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
275 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
276
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
277 module:hook("presence/bare", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
278 -- inbound presence to bare JID recieved
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
279 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
280 local user = stanza.attr.to or (origin.username..'@'..origin.host);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
281 local t = stanza.attr.type;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
282 local self = not stanza.attr.to;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
283
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
284 if not t then -- available presence
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
285 if self or subscription_presence(user, stanza.attr.from) then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
286 local recipient = stanza.attr.from;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
287 local current = recipients[user] and recipients[user][recipient];
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
288 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
289 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
290 if not hash then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
291 update_subscriptions(recipient, user);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
292 else
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
293 recipients[user] = recipients[user] or {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
294 if hash_map[hash] then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
295 update_subscriptions(recipient, user, hash_map[hash]);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
296 else
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
297 recipients[user][recipient] = hash;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
298 local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
299 if self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
300 -- 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
301 origin.send(
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
302 st.stanza("iq", {from=user, to=stanza.attr.from, id="disco", type="get"})
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
303 :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
304 );
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
305 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
306 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
307 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
308 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
309 elseif t == "unavailable" then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
310 update_subscriptions(stanza.attr.from, user);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
311 elseif not self and t == "unsubscribe" then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
312 local from = jid_bare(stanza.attr.from);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
313 local subscriptions = recipients[user];
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
314 if subscriptions then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
315 for subscriber in pairs(subscriptions) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
316 if jid_bare(subscriber) == from then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
317 update_subscriptions(subscriber, user);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
318 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
319 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
320 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
321 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
322 end, 10);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
323
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
324 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
325 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
326 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
327 if not disco then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
328 return;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
329 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
330
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
331 -- Process disco response
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
332 local self = not stanza.attr.to;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
333 local user = stanza.attr.to or (origin.username..'@'..origin.host);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
334 local contact = stanza.attr.from;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
335 local current = recipients[user] and recipients[user][contact];
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
336 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
337 local ver = current;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
338 if not string.find(current, "#") then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
339 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
340 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
341 local notify = set_new();
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
342 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
343 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
344 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
345 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
346 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
347 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
348 hash_map[ver] = notify; -- update hash map
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
349 if self then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
350 for jid, item in pairs(origin.roster) do -- for all interested contacts
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
351 if item.subscription == "both" or item.subscription == "from" then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
352 if not recipients[jid] then recipients[jid] = {}; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
353 update_subscriptions(contact, jid, notify);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
354 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
355 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
356 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
357 update_subscriptions(contact, user, notify);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
358 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
359
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
360 module:hook("account-disco-info-node", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
361 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
362 local service_name = stanza.attr.to or origin.username.."@"..origin.host
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
363 local service = get_pep_service(service_name);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
364 local node = event.node;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
365 local ok = service:get_items(node, jid_bare(stanza.attr.from) or true);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
366 if not ok then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
367 event.exists = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
368 reply:tag('identity', {category='pubsub', type='leaf'}):up();
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
369 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
370
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
371 module:hook("account-disco-info", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
372 local reply = event.reply;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
373 reply:tag('identity', {category='pubsub', type='pep'}):up();
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
374 reply:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up();
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
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
377 module:hook("account-disco-items-node", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
378 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
379 local node = event.node;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
380 local service_name = stanza.attr.to or origin.username.."@"..origin.host
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
381 local service = get_pep_service(service_name);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
382 local ok, ret = service:get_items(node, jid_bare(stanza.attr.from) or true);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
383 if not ok then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
384 event.exists = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
385 for _, id in ipairs(ret) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
386 reply:tag("item", { jid = service_name, name = id }):up();
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
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
390 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
391 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
392
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
393 local service_name = reply.attr.from or origin.username.."@"..origin.host
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
394 local service = get_pep_service(service_name);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
395 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
396 if not ok then return; 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 for node, node_obj in pairs(ret) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
399 reply:tag("item", { jid = service_name, node = node, name = node_obj.config.name }):up();
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
400 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
401 end);