client.lua

changeset 411
db462d4feb44
parent 400
0db9cb909cf1
child 430
b1f7214c6ec2
--- a/client.lua	Fri Apr 07 19:39:59 2017 +0200
+++ b/client.lua	Tue Apr 18 16:46:26 2017 +0200
@@ -22,7 +22,7 @@
 	stream_ns = xmlns_stream,
 	stream_tag = "stream",
 	 default_ns = "jabber:client" };
-	
+
 function stream_callbacks.streamopened(stream, attr)
 	stream.stream_id = attr.id;
 	if not stream:event("opened", attr) then
@@ -76,25 +76,25 @@
 function stream:connect_client(jid, pass)
 	self.jid, self.password = jid, pass;
 	self.username, self.host, self.resource = jid_split(jid);
-	
+
 	-- Required XMPP features
 	self:add_plugin("tls");
 	self:add_plugin("sasl");
 	self:add_plugin("bind");
 	self:add_plugin("session");
-	
+
 	function self.data(conn, data)
 		local ok, err = self.stream:feed(data);
 		if ok then return; end
 		self:debug("Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
 		self:close("xml-not-well-formed");
 	end
-	
+
 	self:hook("connected", function () self:reopen(); end);
 	self:hook("incoming-raw", function (data) return self.data(self.conn, data); end);
-	
+
 	self.curr_id = 0;
-	
+
 	self.tracked_iqs = {};
 	self:hook("stanza", function (stanza)
 		local id, type = stanza.attr.id, stanza.attr.type;
@@ -104,7 +104,7 @@
 			return true;
 		end
 	end);
-	
+
 	self:hook("stanza", function (stanza)
 		local ret;
 		if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then
@@ -132,13 +132,13 @@
 			self:event("stanza-out", data);
 		end
 	end);
-	
+
 	self:hook("stanza-out", function (stanza)
 		if not stanza.attr.xmlns then
 			self:event(stanza.name.."-out", stanza);
 		end
 	end);
-	
+
 	local function stream_ready()
 		self:event("ready");
 	end
@@ -155,12 +155,12 @@
 			return self:close(reason);
 		end
 	end
-	
+
 	local function start_connect()
 		-- Initialise connection
 		self:connect(self.connect_host or self.host, self.connect_port or 5222);
 	end
-	
+
 	if not (self.connect_host or self.connect_port) then
 		-- Look up SRV records
 		adns.lookup(function (answer)
@@ -171,14 +171,14 @@
 					table.insert(srv_hosts, record.srv);
 				end
 				table.sort(srv_hosts, compare_srv_priorities);
-				
+
 				local srv_choice = srv_hosts[1];
 				self.srv_choice = 1;
 				if srv_choice then
 					self.connect_host, self.connect_port = srv_choice.target, srv_choice.port;
 					self:debug("Best record found, will connect to %s:%d", self.connect_host or self.host, self.connect_port or 5222);
 				end
-				
+
 				self:hook("disconnected", function ()
 					if self.srv_hosts and self.srv_choice < #self.srv_hosts then
 						self.srv_choice = self.srv_choice + 1;
@@ -188,7 +188,7 @@
 						return true;
 					end
 				end, 1000);
-				
+
 				self:hook("connected", function ()
 					self.srv_hosts = nil;
 				end, 1000);

mercurial