comparison mod_smacks/mod_smacks.lua @ 1407:b631c8a8b9e7

mod_smacks: Assert that the 'h' attribute is present and a number
author Kim Alvefur <zash@zash.se>
date Wed, 07 May 2014 14:21:33 +0200
parents 7d76dd2310ef
children ed2a9c00b5c4
comparison
equal deleted inserted replaced
1406:7d76dd2310ef 1407:b631c8a8b9e7
191 function handle_a(origin, stanza) 191 function handle_a(origin, stanza)
192 if not origin.smacks then return; end 192 if not origin.smacks then return; end
193 origin.awaiting_ack = nil; 193 origin.awaiting_ack = nil;
194 -- Remove handled stanzas from outgoing_stanza_queue 194 -- Remove handled stanzas from outgoing_stanza_queue
195 --log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or ""); 195 --log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or "");
196 local handled_stanza_count = tonumber(stanza.attr.h)-origin.last_acknowledged_stanza; 196 local h = tonumber(stanza.attr.h);
197 if not h then
198 origin:close{ condition = "invalid-xml"; text = "Missing or invalid 'h' attribute"; };
199 end
200 local handled_stanza_count = h-origin.last_acknowledged_stanza;
197 local queue = origin.outgoing_stanza_queue; 201 local queue = origin.outgoing_stanza_queue;
198 if handled_stanza_count > #queue then 202 if handled_stanza_count > #queue then
199 session.log("warn", "The client says it handled %d new stanzas, but we only sent %d :)", 203 session.log("warn", "The client says it handled %d new stanzas, but we only sent %d :)",
200 handled_stanza_count, #queue); 204 handled_stanza_count, #queue);
201 session.log("debug", "Client h: %d, our h: %d", tonumber(stanza.attr.h), origin.last_acknowledged_stanza); 205 session.log("debug", "Client h: %d, our h: %d", tonumber(stanza.attr.h), origin.last_acknowledged_stanza);