Comparison

plugins/mod_smacks.lua @ 11978:628374809421

mod_smacks: Remove redundant fields Given that the registry is scoped per user and the module is scoped per host, there seems no point to checking or storing both username and host here.
author Kim Alvefur <zash@zash.se>
date Wed, 01 Dec 2021 16:26:53 +0100
parent 11977:9f7a6f7d13de
child 11979:705c4c07a860
comparison
equal deleted inserted replaced
11977:9f7a6f7d13de 11978:628374809421
80 session.log("warn", "User has too much hibernated sessions, removing oldest session (token: %s)", resumption_token); 80 session.log("warn", "User has too much hibernated sessions, removing oldest session (token: %s)", resumption_token);
81 -- store old session's h values on force delete 81 -- store old session's h values on force delete
82 -- save only actual h value and username/host (for security) 82 -- save only actual h value and username/host (for security)
83 old_session_registry.set(session.username, resumption_token, { 83 old_session_registry.set(session.username, resumption_token, {
84 h = session.handled_stanza_count, 84 h = session.handled_stanza_count,
85 username = session.username,
86 host = session.host
87 }); 85 });
88 return true; -- allow session to be removed from full cache to make room for new one 86 return true; -- allow session to be removed from full cache to make room for new one
89 end); 87 end);
90 88
91 local function ack_delayed(session, stanza) 89 local function ack_delayed(session, stanza)
505 session.log("debug", "Destroying session for hibernating too long"); 503 session.log("debug", "Destroying session for hibernating too long");
506 session_registry.set(session.username, session.resumption_token, nil); 504 session_registry.set(session.username, session.resumption_token, nil);
507 -- save only actual h value and username/host (for security) 505 -- save only actual h value and username/host (for security)
508 old_session_registry.set(session.username, session.resumption_token, { 506 old_session_registry.set(session.username, session.resumption_token, {
509 h = session.handled_stanza_count, 507 h = session.handled_stanza_count,
510 username = session.username,
511 host = session.host
512 }); 508 });
513 session.resumption_token = nil; 509 session.resumption_token = nil;
514 sessionmanager.destroy_session(session); 510 sessionmanager.destroy_session(session);
515 else 511 else
516 session.log("debug", "Session resumed before hibernation timeout, all is well") 512 session.log("debug", "Session resumed before hibernation timeout, all is well")
556 local id = stanza.attr.previd; 552 local id = stanza.attr.previd;
557 local original_session = session_registry.get(session.username, id); 553 local original_session = session_registry.get(session.username, id);
558 if not original_session then 554 if not original_session then
559 session.log("debug", "Tried to resume non-existent session with id %s", id); 555 session.log("debug", "Tried to resume non-existent session with id %s", id);
560 local old_session = old_session_registry.get(session.username, id); 556 local old_session = old_session_registry.get(session.username, id);
561 if old_session and session.username == old_session.username 557 if old_session then
562 and session.host == old_session.host
563 and old_session.h then
564 session.send(st.stanza("failed", { xmlns = xmlns_sm, h = format_h(old_session.h) }) 558 session.send(st.stanza("failed", { xmlns = xmlns_sm, h = format_h(old_session.h) })
565 :tag("item-not-found", { xmlns = xmlns_errors }) 559 :tag("item-not-found", { xmlns = xmlns_errors })
566 ); 560 );
567 else 561 else
568 session.send(st.stanza("failed", { xmlns = xmlns_sm }) 562 session.send(st.stanza("failed", { xmlns = xmlns_sm })