annotate mod_bookmarks/mod_bookmarks.lua @ 3733:9a3d25311fd9

mod_log_json: Use filename from logging config
author Kim Alvefur <zash@zash.se>
date Sun, 03 Nov 2019 14:33:01 +0100
parents 7575399ae544
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3678
7575399ae544 mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3544
diff changeset
1 local mm = require "core.modulemanager";
7575399ae544 mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3544
diff changeset
2 if mm.get_modules_for_host(module.host):contains("bookmarks2") then
7575399ae544 mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3544
diff changeset
3 error("mod_bookmarks and mod_bookmarks2 are conflicting, please disable one of them.", 0);
7575399ae544 mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3544
diff changeset
4 end
7575399ae544 mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3544
diff changeset
5
3238
786ba175f2e5 mod_bookmarks: Require forgotten util.jid module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3235
diff changeset
6 local st = require "util.stanza";
786ba175f2e5 mod_bookmarks: Require forgotten util.jid module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3235
diff changeset
7 local jid_split = require "util.jid".split;
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 local mod_pep = module:depends "pep";
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 local private_storage = module:open_store("private", "map");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11
3294
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
12 local default_options = {
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
13 ["persist_items"] = true;
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
14 ["access_model"] = "whitelist";
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
15 };
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
16
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 module:hook("account-disco-info", function (event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 event.reply:tag("feature", { var = "urn:xmpp:bookmarks-conversion:0" }):up();
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 end);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 local function on_retrieve_private_xml(event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 local stanza, session = event.stanza, event.origin;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 local query = stanza:get_child("query", "jabber:iq:private");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 if query == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 local bookmarks = query:get_child("storage", "storage:bookmarks");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 if bookmarks == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
3230
ba0d444b64aa mod_bookmarks: Simplify last item retrieval thanks to Prosody b6ffd4f951b9.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3229
diff changeset
33 module:log("debug", "Getting private bookmarks: %s", bookmarks);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 local username = session.username;
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
36 local jid = username.."@"..session.host;
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 local service = mod_pep.get_pep_service(username);
3230
ba0d444b64aa mod_bookmarks: Simplify last item retrieval thanks to Prosody b6ffd4f951b9.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3229
diff changeset
38 local ok, id, item = service:get_last_item("storage:bookmarks", session.full_jid);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 if not ok then
3543
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
40 if id == "item-not-found" then
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
41 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid);
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
42 session.send(st.reply(stanza):add_child(query));
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
43 else
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
44 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, id);
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
45 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to retrive bookmarks from PEP"));
11629f04ddd0 mod_bookmarks: Check for item-not-found and return empty Private XML. Fixes #1265 (thanks gerald and thebigfrog!)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3487
diff changeset
46 end
3544
7893115bf382 mod_bookmarks: Return true when a stanza has been sent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3543
diff changeset
47 return true;
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 end
3233
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3232
diff changeset
49 if not id or not item then
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
50 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid);
3233
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3232
diff changeset
51 session.send(st.reply(stanza):add_child(query));
3544
7893115bf382 mod_bookmarks: Return true when a stanza has been sent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3543
diff changeset
52 return true;
3233
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3232
diff changeset
53 end
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3232
diff changeset
54 module:log("debug", "Got item %s: %s", id, item);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 local content = item.tags[1];
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
57 module:log("debug", "Sending back private for %s: %s", jid, content);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 session.send(st.reply(stanza):query("jabber:iq:private"):add_child(content));
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 return true;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61
3235
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
62 function publish_to_pep(jid, bookmarks)
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
63 local service = mod_pep.get_pep_service(jid_split(jid));
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" })
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 :add_child(bookmarks);
3294
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
66 return service:publish("storage:bookmarks", jid, "current", item, default_options);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 -- Synchronise Private XML to PEP.
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 local function on_publish_private_xml(event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 local stanza, session = event.stanza, event.origin;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 local query = stanza:get_child("query", "jabber:iq:private");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 if query == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 local bookmarks = query:get_child("storage", "storage:bookmarks");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 if bookmarks == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 module:log("debug", "Private bookmarks set by client, publishing to pep");
3235
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
83 local ok, err = publish_to_pep(session.full_jid, bookmarks);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 if not ok then
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
85 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP"));
3544
7893115bf382 mod_bookmarks: Return true when a stanza has been sent.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3543
diff changeset
87 return true;
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 session.send(st.reply(stanza));
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 return true;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 local function on_resource_bind(event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 local session = event.session;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 local username = session.username;
3290
87769f53fdc8 mod_bookmarks: Delete the node before attempting migration, to make sure its config is correct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3282
diff changeset
97 local service = mod_pep.get_pep_service(username);
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
98 local jid = username.."@"..session.host;
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 local data, err = private_storage:get(username, "storage:storage:bookmarks");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 if not data then
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
102 module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", jid, err);
3234
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
103 local ok, id = service:get_last_item("storage:bookmarks", session.full_jid);
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
104 if not ok or not id then
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
105 module:log("debug", "Additionally, no PEP bookmarks were existing for %s", jid);
3234
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
106 module:fire_event("bookmarks/empty", { session = session });
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
107 end
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 local bookmarks = st.deserialize(data);
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
111 module:log("debug", "Got private bookmarks of %s: %s", jid, bookmarks);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112
3290
87769f53fdc8 mod_bookmarks: Delete the node before attempting migration, to make sure its config is correct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3282
diff changeset
113 -- We don’t care if deleting succeeds or not, we only want to start with a non-existent node.
87769f53fdc8 mod_bookmarks: Delete the node before attempting migration, to make sure its config is correct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3282
diff changeset
114 module:log("debug", "Deleting possibly existing PEP item for %s", jid);
87769f53fdc8 mod_bookmarks: Delete the node before attempting migration, to make sure its config is correct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3282
diff changeset
115 service:delete("storage:bookmarks", jid);
87769f53fdc8 mod_bookmarks: Delete the node before attempting migration, to make sure its config is correct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3282
diff changeset
116
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
117 module:log("debug", "Going to store PEP item for %s", jid);
3235
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
118 local ok, err = publish_to_pep(session.full_jid, bookmarks);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 if not ok then
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
120 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", jid, err);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 end
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
123 module:log("debug", "Stored bookmarks to PEP for %s", jid);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 if not ok then
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
127 module:log("error", "Failed to remove private bookmarks of %s: %s", jid, err);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 end
3282
9346ed926842 mod_bookmarks: Display the bare JID instead of the username in logs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3253
diff changeset
130 module:log("debug", "Removed private bookmarks of %s, migration done!", jid);
3229
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132
3294
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
133 local function on_node_created(event)
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
134 local service, node, actor = event.service, event.node, event.actor;
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
135 if node ~= "storage:bookmarks" then
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
136 return;
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
137 end
3487
e60933722248 mod_bookmarks: Use correct variable, fixes a traceback (thanks dan)
Kim Alvefur <zash@zash.se>
parents: 3476
diff changeset
138 local ok, node_config = service:get_node_config(node, actor);
3476
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
139 if not ok then
3487
e60933722248 mod_bookmarks: Use correct variable, fixes a traceback (thanks dan)
Kim Alvefur <zash@zash.se>
parents: 3476
diff changeset
140 module:log("error", "Failed to get node config of %s: %s", node, node_config);
3476
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
141 return;
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
142 end
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
143 local changed = false;
3294
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
144 for config_field, value in pairs(default_options) do
3476
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
145 if node_config[config_field] ~= value then
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
146 node_config[config_field] = value;
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
147 changed = true;
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
148 end
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
149 end
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
150 if not changed then
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
151 return;
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
152 end
3487
e60933722248 mod_bookmarks: Use correct variable, fixes a traceback (thanks dan)
Kim Alvefur <zash@zash.se>
parents: 3476
diff changeset
153 local ok, err = service:set_node_config(node, actor, node_config);
3476
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
154 if not ok then
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
155 module:log("error", "Failed to set node config of %s: %s", node, err);
4ce945490a24 mod_bookmarks: Actually save node config
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3473
diff changeset
156 return;
3294
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
157 end
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
158 end
947790ec4406 mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3290
diff changeset
159
3308
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
160 module:hook("iq/bare/jabber:iq:private:query", function (event)
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
161 if event.stanza.attr.type == "get" then
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
162 return on_retrieve_private_xml(event);
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
163 else
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
164 return on_publish_private_xml(event);
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
165 end
7155cc1adf8f mod_bookmarks: Handle iq:private queries before mod_private
Kim Alvefur <zash@zash.se>
parents: 3307
diff changeset
166 end, 1);
3234
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
167 module:hook("resource-bind", on_resource_bind);
3307
303b17ec8264 mod_bookmarks: Correctly hook events on PEP services
Kim Alvefur <zash@zash.se>
parents: 3294
diff changeset
168 module:handle_items("pep-service", function (event)
303b17ec8264 mod_bookmarks: Correctly hook events on PEP services
Kim Alvefur <zash@zash.se>
parents: 3294
diff changeset
169 local service = event.item.service;
303b17ec8264 mod_bookmarks: Correctly hook events on PEP services
Kim Alvefur <zash@zash.se>
parents: 3294
diff changeset
170 module:hook_object_event(service.events, "node-created", on_node_created);
303b17ec8264 mod_bookmarks: Correctly hook events on PEP services
Kim Alvefur <zash@zash.se>
parents: 3294
diff changeset
171 end, function () end, true);