scansion/objects/client.lua

changeset 164
14500a149b31
parent 130
ce99abde467b
child 171
433a1f36d0d3
equal deleted inserted replaced
163:0e2150680a25 164:14500a149b31
93 end; 93 end;
94 94
95 receives = function (client, data) 95 receives = function (client, data)
96 local wait, done = async.waiter(); 96 local wait, done = async.waiter();
97 local expected_stanza = false; 97 local expected_stanza = false;
98 local have_received_stanza = false;
98 data = table.concat(data):gsub("\t", " "):gsub("^%s+", ""):gsub("%s+$", ""); 99 data = table.concat(data):gsub("\t", " "):gsub("^%s+", ""):gsub("%s+$", "");
99 if data ~= "nothing" then 100 if data ~= "nothing" then
100 expected_stanza = fill_vars(client.script, assert(parse_xml(data))); 101 expected_stanza = fill_vars(client.script, assert(parse_xml(data)));
101 end 102 end
102 local function stanza_handler(received_stanza) 103 local function stanza_handler(received_stanza)
104 have_received_stanza = true;
103 if not expected_stanza then 105 if not expected_stanza then
104 error(new_error("unexpected-stanza", { 106 error(new_error("unexpected-stanza", {
105 text = "Received unexpected stanza"; 107 text = "Received unexpected stanza";
106 stanza = tostring(received_stanza); 108 stanza = tostring(received_stanza);
107 })); 109 }));
127 client.log("Calling done") 129 client.log("Calling done")
128 done(); 130 done();
129 end 131 end
130 client.stream:hook("stanza", stanza_handler, 100); 132 client.stream:hook("stanza", stanza_handler, 100);
131 verse.add_task(client.stanza_timeout or default_stanza_timeout, function () 133 verse.add_task(client.stanza_timeout or default_stanza_timeout, function ()
134 if have_received_stanza then return; end
132 if expected_stanza then 135 if expected_stanza then
133 client.log("TIMEOUT waiting for %s", expected_stanza) 136 client.log("TIMEOUT waiting for %s", expected_stanza)
134 local e = new_error("stanza-timeout", { text = "Timed out waiting for stanza" }); 137 local e = new_error("stanza-timeout", { text = "Timed out waiting for stanza" });
135 error(e); 138 error(e);
136 end 139 end

mercurial