Comparison

component.lua @ 411:db462d4feb44

verse: trim trailing whitespace
author Kim Alvefur <zash@zash.se>
date Tue, 18 Apr 2017 16:46:26 +0200
parent 410:6171ef2a4025
child 485:c9a144591649
comparison
equal deleted inserted replaced
410:6171ef2a4025 411:db462d4feb44
17 17
18 local stream_callbacks = { 18 local stream_callbacks = {
19 stream_ns = xmlns_stream, 19 stream_ns = xmlns_stream,
20 stream_tag = "stream", 20 stream_tag = "stream",
21 default_ns = xmlns_component }; 21 default_ns = xmlns_component };
22 22
23 function stream_callbacks.streamopened(stream, attr) 23 function stream_callbacks.streamopened(stream, attr)
24 stream.stream_id = attr.id; 24 stream.stream_id = attr.id;
25 if not stream:event("opened", attr) then 25 if not stream:event("opened", attr) then
26 stream.notopen = nil; 26 stream.notopen = nil;
27 end 27 end
53 end 53 end
54 54
55 function stream:connect_component(jid, pass) 55 function stream:connect_component(jid, pass)
56 self.jid, self.password = jid, pass; 56 self.jid, self.password = jid, pass;
57 self.username, self.host, self.resource = jid_split(jid); 57 self.username, self.host, self.resource = jid_split(jid);
58 58
59 function self.data(conn, data) 59 function self.data(conn, data)
60 local ok, err = self.stream:feed(data); 60 local ok, err = self.stream:feed(data);
61 if ok then return; end 61 if ok then return; end
62 stream:debug("Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); 62 stream:debug("Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
63 stream:close("xml-not-well-formed"); 63 stream:close("xml-not-well-formed");
64 end 64 end
65 65
66 self:hook("incoming-raw", function (data) return self.data(self.conn, data); end); 66 self:hook("incoming-raw", function (data) return self.data(self.conn, data); end);
67 67
68 self.curr_id = 0; 68 self.curr_id = 0;
69 69
70 self.tracked_iqs = {}; 70 self.tracked_iqs = {};
71 self:hook("stanza", function (stanza) 71 self:hook("stanza", function (stanza)
72 local id, type = stanza.attr.id, stanza.attr.type; 72 local id, type = stanza.attr.id, stanza.attr.type;
73 if id and stanza.name == "iq" and (type == "result" or type == "error") and self.tracked_iqs[id] then 73 if id and stanza.name == "iq" and (type == "result" or type == "error") and self.tracked_iqs[id] then
74 self.tracked_iqs[id](stanza); 74 self.tracked_iqs[id](stanza);
75 self.tracked_iqs[id] = nil; 75 self.tracked_iqs[id] = nil;
76 return true; 76 return true;
77 end 77 end
78 end); 78 end);
79 79
80 self:hook("stanza", function (stanza) 80 self:hook("stanza", function (stanza)
81 local ret; 81 local ret;
82 if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then 82 if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then
83 if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then 83 if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then
84 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; 84 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;