Comparison

plugins/mod_bookmarks.lua @ 12178:0aa99a6dfb3e

mod_bookmarks: Fix traceback on attempt to convert invalid bookmark Found by accidentally publishing {urn:xmpp:bookmarks:0}conference instead of :1 due to testing this earlier for the blocking. By the principle of garbage in, garbage out, just generate a bookmark from the item id / JID and carry on with a warning.
author Kim Alvefur <zash@zash.se>
date Tue, 11 Jan 2022 00:06:48 +0100
parent 12177:024cc878f472
child 12259:57792ed670e7
comparison
equal deleted inserted replaced
12177:024cc878f472 12178:0aa99a6dfb3e
39 local function generate_legacy_storage(items) 39 local function generate_legacy_storage(items)
40 local storage = st.stanza("storage", { xmlns = namespace_legacy }); 40 local storage = st.stanza("storage", { xmlns = namespace_legacy });
41 for _, item_id in ipairs(items) do 41 for _, item_id in ipairs(items) do
42 local item = items[item_id]; 42 local item = items[item_id];
43 local bookmark = item:get_child("conference", namespace); 43 local bookmark = item:get_child("conference", namespace);
44 if not bookmark then
45 module:log("warn", "Invalid bookmark published: expected {%s}conference, got {%s}%s", namespace,
46
47 item.tags[1] and item.tags[1].attr.xmlns, item.tags[1] and item.tags[1].name);
48 end
44 local conference = st.stanza("conference", { 49 local conference = st.stanza("conference", {
45 jid = item.attr.id, 50 jid = item.attr.id,
46 name = bookmark.attr.name, 51 name = bookmark and bookmark.attr.name,
47 autojoin = bookmark.attr.autojoin, 52 autojoin = bookmark and bookmark.attr.autojoin,
48 }); 53 });
49 local nick = bookmark:get_child_text("nick"); 54 local nick = bookmark and bookmark:get_child_text("nick");
50 if nick ~= nil then 55 if nick ~= nil then
51 conference:text_tag("nick", nick):up(); 56 conference:text_tag("nick", nick):up();
52 end 57 end
53 local password = bookmark:get_child_text("password"); 58 local password = bookmark and bookmark:get_child_text("password");
54 if password ~= nil then 59 if password ~= nil then
55 conference:text_tag("password", password):up(); 60 conference:text_tag("password", password):up();
56 end 61 end
57 storage:add_child(conference); 62 storage:add_child(conference);
58 end 63 end