Mercurial > prosody-hg
view plugins/mod_offline.lua @ 14179:25beb66fab38 13.0
util.crypto: Use post-Lua 5.1 buffer API
Tha Lua 5.1 buffer API was frustrating to work with. luaL_prepbuffer() only
allocates LUAL_BUFFERSIZE - there is no way to request a specific size.
LUAL_BUFFERSIZE is set to BUFSIZ by default, which is generally 8192 bytes on
Linux, however it may vary between platforms.
The variation means this buffer could potentially overflow (small BUFSIZ with
large signature).
The Lua 5.2+ buffer API enables requesting a specific buffer size, so that's
what we do now.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 25 May 2026 15:11:47 +0100 |
| parents | 74b9e05af71e |
| children | 30d457b2b0c4 |
line wrap: on
line source
-- Prosody IM -- Copyright (C) 2008-2009 Matthew Wild -- Copyright (C) 2008-2009 Waqas Hussain -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- local datetime = require "prosody.util.datetime"; local jid_split = require "prosody.util.jid".split; local offline_messages = module:open_store("offline", "archive"); module:add_feature("msgoffline"); module:hook("message/offline/handle", function(event) local origin, stanza = event.origin, event.stanza; local to = stanza.attr.to; local node; if to then node = jid_split(to) else node = origin.username; end local ok = offline_messages:append(node, nil, stanza, os.time(), ""); if ok then module:log("debug", "Saved to offline storage: %s", stanza:top_tag()); end return ok; end, -1); module:hook("message/offline/broadcast", function(event) local origin = event.origin; origin.log("debug", "Broadcasting offline messages"); local node, host = origin.username, origin.host; local data = offline_messages:find(node); if not data then return true; end for _, stanza, when in data do stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = datetime.datetime(when)}):up(); -- XEP-0203 origin.send(stanza); end local ok = offline_messages:delete(node); if type(ok) == "number" and ok > 0 then origin.log("debug", "%d offline messages consumed"); end return true; end, -1);
