changeset 590:40b707d7a809

mod_smacks: Handle a client trying to <enable> twice, or trying to <enable> before resource binding (thanks Thijs Alkemade)
author Matthew Wild <mwild1@gmail.com>
date Wed, 01 Feb 2012 23:29:05 +0000
parents 57ac609444c4
children 36003cae2370
files mod_smacks/mod_smacks.lua
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua	Wed Feb 01 23:27:23 2012 +0000
+++ b/mod_smacks/mod_smacks.lua	Wed Feb 01 23:29:05 2012 +0000
@@ -89,6 +89,18 @@
 end
 
 module:hook_stanza(xmlns_sm, "enable", function (session, stanza)
+	local err, err_text;
+	if session.smacks then
+		err, err_text = "unexpected-request", "Stream management already enabled for this stream";
+	elseif not session.resource then
+		err, err_text = "unexpected-request", "Attempted to enable stream management before resource binding";
+	end
+	if err then
+		session.log("warn", "Failed to enable smacks: %s", err_text); -- TODO: XEP doesn't say we can send error text, should it?
+		session.send(st.stanza("failed", { xmlns = xmlns_sm }):tag(err, { xmlns = xmlns_errors}));
+		return true;
+	end
+
 	module:log("debug", "Enabling stream management");
 	session.smacks = true;