scansion/objects/client.lua

changeset 84
c9061cd9951b
parent 83
52f8fa7f999e
child 90
8458f8bdb3b0
--- a/scansion/objects/client.lua	Fri Feb 19 11:48:04 2016 +0000
+++ b/scansion/objects/client.lua	Fri Feb 19 11:48:31 2016 +0000
@@ -85,12 +85,21 @@
 
 	receives = function (client, data)
 		local wait, done = async.waiter();
-		local expected_stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", "  ")))));
+		local expected_stanza = false;
+		data = table.concat(data):gsub("\t", "    "):gsub("^%s+", ""):gsub("%s+$", "");
+		if data ~= "nothing" then
+			expected_stanza = fill_vars(client.script, assert(parse_xml(data)));
+		end
 		local function stanza_handler(received_stanza)
-			if not stanzacmp.stanzas_match(expected_stanza, received_stanza) then
-				client.log("NOT IT!")
-				client.log("Expected: %s", expected_stanza);
-				client.log("Received: %s", received_stanza);
+			if not expected_stanza then
+				error(new_error("Received unexpected stanza", { stanza = tostring(received_stanza) }));
+			elseif not expected_stanza or not stanzacmp.stanzas_match(expected_stanza, received_stanza) then
+				if not expected_stanza then
+					client.log("Received a stanza when none were expected: %s", received_stanza);
+				else
+					client.log("Expected: %s", expected_stanza);
+					client.log("Received: %s", received_stanza);
+				end
 				error(new_error("Received unexpected stanza", { stanza = tostring(received_stanza) }));
 			else
 				client.last_received_id = received_stanza.attr.id;

mercurial