Mercurial > prosody-modules
comparison mod_bookmarks/mod_bookmarks.lua @ 3282:9346ed926842
mod_bookmarks: Display the bare JID instead of the username in logs.
| author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
|---|---|
| date | Sat, 25 Aug 2018 17:39:01 +0200 |
| parents | cf8ad9fd7f15 |
| children | 87769f53fdc8 |
comparison
equal
deleted
inserted
replaced
| 3281:27cc66bf918b | 3282:9346ed926842 |
|---|---|
| 21 end | 21 end |
| 22 | 22 |
| 23 module:log("debug", "Getting private bookmarks: %s", bookmarks); | 23 module:log("debug", "Getting private bookmarks: %s", bookmarks); |
| 24 | 24 |
| 25 local username = session.username; | 25 local username = session.username; |
| 26 local jid = username.."@"..session.host; | |
| 26 local service = mod_pep.get_pep_service(username); | 27 local service = mod_pep.get_pep_service(username); |
| 27 local ok, id, item = service:get_last_item("storage:bookmarks", session.full_jid); | 28 local ok, id, item = service:get_last_item("storage:bookmarks", session.full_jid); |
| 28 if not ok then | 29 if not ok then |
| 29 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", username, id); | 30 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, id); |
| 30 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to retrive bookmarks from PEP")); | 31 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to retrive bookmarks from PEP")); |
| 31 return; | 32 return; |
| 32 end | 33 end |
| 33 if not id or not item then | 34 if not id or not item then |
| 34 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", username); | 35 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid); |
| 35 session.send(st.reply(stanza):add_child(query)); | 36 session.send(st.reply(stanza):add_child(query)); |
| 36 return | 37 return |
| 37 end | 38 end |
| 38 module:log("debug", "Got item %s: %s", id, item); | 39 module:log("debug", "Got item %s: %s", id, item); |
| 39 | 40 |
| 40 local content = item.tags[1]; | 41 local content = item.tags[1]; |
| 41 module:log("debug", "Sending back private for %s: %s", username, content); | 42 module:log("debug", "Sending back private for %s: %s", jid, content); |
| 42 session.send(st.reply(stanza):query("jabber:iq:private"):add_child(content)); | 43 session.send(st.reply(stanza):query("jabber:iq:private"):add_child(content)); |
| 43 return true; | 44 return true; |
| 44 end | 45 end |
| 45 | 46 |
| 46 function publish_to_pep(jid, bookmarks) | 47 function publish_to_pep(jid, bookmarks) |
| 68 end | 69 end |
| 69 | 70 |
| 70 module:log("debug", "Private bookmarks set by client, publishing to pep"); | 71 module:log("debug", "Private bookmarks set by client, publishing to pep"); |
| 71 local ok, err = publish_to_pep(session.full_jid, bookmarks); | 72 local ok, err = publish_to_pep(session.full_jid, bookmarks); |
| 72 if not ok then | 73 if not ok then |
| 73 module:log("error", "Failed to publish to PEP bookmarks for %s: %s", session.username, err); | 74 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); |
| 74 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); | 75 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); |
| 75 return; | 76 return; |
| 76 end | 77 end |
| 77 | 78 |
| 78 session.send(st.reply(stanza)); | 79 session.send(st.reply(stanza)); |
| 80 end | 81 end |
| 81 | 82 |
| 82 local function on_resource_bind(event) | 83 local function on_resource_bind(event) |
| 83 local session = event.session; | 84 local session = event.session; |
| 84 local username = session.username; | 85 local username = session.username; |
| 86 local jid = username.."@"..session.host; | |
| 85 | 87 |
| 86 local data, err = private_storage:get(username, "storage:storage:bookmarks"); | 88 local data, err = private_storage:get(username, "storage:storage:bookmarks"); |
| 87 if not data then | 89 if not data then |
| 88 module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", username, err); | 90 module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", jid, err); |
| 89 local service = mod_pep.get_pep_service(username); | 91 local service = mod_pep.get_pep_service(username); |
| 90 local ok, id = service:get_last_item("storage:bookmarks", session.full_jid); | 92 local ok, id = service:get_last_item("storage:bookmarks", session.full_jid); |
| 91 if not ok or not id then | 93 if not ok or not id then |
| 92 module:log("debug", "Additionally, no PEP bookmarks were existing for %s", username); | 94 module:log("debug", "Additionally, no PEP bookmarks were existing for %s", jid); |
| 93 module:fire_event("bookmarks/empty", { session = session }); | 95 module:fire_event("bookmarks/empty", { session = session }); |
| 94 end | 96 end |
| 95 return; | 97 return; |
| 96 end | 98 end |
| 97 local bookmarks = st.deserialize(data); | 99 local bookmarks = st.deserialize(data); |
| 98 module:log("debug", "Got private bookmarks of %s: %s", username, bookmarks); | 100 module:log("debug", "Got private bookmarks of %s: %s", jid, bookmarks); |
| 99 | 101 |
| 100 module:log("debug", "Going to store PEP item for %s", username); | 102 module:log("debug", "Going to store PEP item for %s", jid); |
| 101 local ok, err = publish_to_pep(session.full_jid, bookmarks); | 103 local ok, err = publish_to_pep(session.full_jid, bookmarks); |
| 102 if not ok then | 104 if not ok then |
| 103 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", username, err); | 105 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", jid, err); |
| 104 return; | 106 return; |
| 105 end | 107 end |
| 106 module:log("debug", "Stored bookmarks to PEP for %s", username); | 108 module:log("debug", "Stored bookmarks to PEP for %s", jid); |
| 107 | 109 |
| 108 local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil); | 110 local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil); |
| 109 if not ok then | 111 if not ok then |
| 110 module:log("error", "Failed to remove private bookmarks of %s: %s", username, err); | 112 module:log("error", "Failed to remove private bookmarks of %s: %s", jid, err); |
| 111 return; | 113 return; |
| 112 end | 114 end |
| 113 module:log("debug", "Removed private bookmarks of %s, migration done!", username); | 115 module:log("debug", "Removed private bookmarks of %s, migration done!", jid); |
| 114 end | 116 end |
| 115 | 117 |
| 116 local function on_item_published(event) | 118 local function on_item_published(event) |
| 117 module:fire_event("bookmarks/updated", event); | 119 module:fire_event("bookmarks/updated", event); |
| 118 end | 120 end |
