51 local stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", " "))))); |
51 local stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", " "))))); |
52 client.stream:send(stanza); |
52 client.stream:send(stanza); |
53 end; |
53 end; |
54 |
54 |
55 receives = function (client, data) |
55 receives = function (client, data) |
|
56 local wait, done = async.waiter(); |
56 local expected_stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", " "))))); |
57 local expected_stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", " "))))); |
57 local function stanza_handler(received_stanza) |
58 local function stanza_handler(received_stanza) |
58 if not stanzacmp.stanzas_match(expected_stanza, received_stanza) then |
59 if not stanzacmp.stanzas_match(expected_stanza, received_stanza) then |
59 client.log("NOT IT!") |
60 client.log("NOT IT!") |
60 client.log("Expected: %s", expected_stanza); |
61 client.log("Expected: %s", expected_stanza); |
62 error("Received unexpected stanza"); |
63 error("Received unexpected stanza"); |
63 else |
64 else |
64 client.log("YES! %s", expected_stanza) |
65 client.log("YES! %s", expected_stanza) |
65 end |
66 end |
66 expected_stanza = nil; |
67 expected_stanza = nil; |
|
68 done(); |
67 end |
69 end |
68 client.stream:hook("stanza", stanza_handler, 100); |
70 client.stream:hook("stanza", stanza_handler, 100); |
69 verse.add_task(stanza_timeout, function () |
71 verse.add_task(stanza_timeout, function () |
70 if not expected_stanza then return; end |
72 if not expected_stanza then return; end |
71 client.log("TIMEOUT waiting for %s", expected_stanza) |
73 client.log("TIMEOUT waiting for %s", expected_stanza) |
72 error("Timed out waiting for stanza"); |
74 error("Timed out waiting for stanza"); |
|
75 done(); |
73 end); |
76 end); |
|
77 wait(); |
74 end; |
78 end; |
75 |
79 |
76 disconnects = function (client) |
80 disconnects = function (client) |
77 end; |
81 end; |
78 } |
82 } |