aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-09-13 16:35:48 +0100
committerMatthew Wild <mwild1@gmail.com>2018-09-13 16:35:48 +0100
commit27d8902b8e38dd459f0b69dc9f17ebf6ad3e2059 (patch)
treeb0c749993e031bfa71f9cb2b0b672b83c20bd985 /util
parentc3ba0cd3c5865294540fb559400941fa9c729eaa (diff)
downloadprosody-27d8902b8e38dd459f0b69dc9f17ebf6ad3e2059.tar.gz
prosody-27d8902b8e38dd459f0b69dc9f17ebf6ad3e2059.zip
util.stanza: Don't automatically generate ids for iq stanzas
Users of this API should provide their own id attribute that meets their uniqueness requirements. The current implementation leaks information (i.e. how many iq stanzas have been sent by the server to other JIDs). Providing any strong guarantees of randomness here would need to pull in additional dependencies that we don't want in this simple library.
Diffstat (limited to 'util')
-rw-r--r--util/stanza.lua13
1 files changed, 4 insertions, 9 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index f08baef7..79522ed5 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -347,12 +347,6 @@ function stanza_mt.get_error(stanza)
return error_type, condition or "undefined-condition", text;
end
-local id = 0;
-local function new_id()
- id = id + 1;
- return "lx"..id;
-end
-
local function preserialize(stanza)
local s = { name = stanza.name, attr = stanza.attr };
for _, child in ipairs(stanza) do
@@ -430,8 +424,10 @@ local function message(attr, body)
end
end
local function iq(attr)
- if attr and not attr.id then attr.id = new_id(); end
- return new_stanza("iq", attr or { id = new_id() });
+ if not (attr and attr.id) then
+ error("iq stanzas require an id attribute");
+ end
+ return new_stanza("iq", attr);
end
local function reply(orig)
@@ -502,7 +498,6 @@ return {
stanza_mt = stanza_mt;
stanza = new_stanza;
is_stanza = is_stanza;
- new_id = new_id;
preserialize = preserialize;
deserialize = deserialize;
clone = clone;