Changeset

7278:1891854b25ac

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 14 Mar 2016 14:20:37 +0100
parents 7270:df22e314946c (current diff) 7277:7be7108cb6ed (diff)
children 7280:8b5a9208c212
files plugins/mod_s2s/mod_s2s.lua
diffstat 4 files changed, 37 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/core/rostermanager.lua	Fri Mar 11 20:35:26 2016 +0100
+++ b/core/rostermanager.lua	Mon Mar 14 14:20:37 2016 +0100
@@ -75,7 +75,6 @@
 		-- stanza ready
 		for _, session in pairs(hosts[host].sessions[username].sessions) do
 			if session.interested then
-				-- FIXME do we need to set stanza.attr.to?
 				session.send(stanza);
 			end
 		end
--- a/plugins/mod_s2s/mod_s2s.lua	Fri Mar 11 20:35:26 2016 +0100
+++ b/plugins/mod_s2s/mod_s2s.lua	Mon Mar 14 14:20:37 2016 +0100
@@ -366,7 +366,7 @@
 	elseif session.direction == "outgoing" then
 		session.notopen = nil;
 		if not attr.id then
-			log("error", "Stream response did not give us a stream id!");
+			log("error", "Stream response from %s did not give us a stream id!", session.to_host);
 			session:close({ condition = "undefined-condition", text = "Missing stream ID" });
 			return;
 		end
--- a/plugins/mod_storage_sql.lua	Fri Mar 11 20:35:26 2016 +0100
+++ b/plugins/mod_storage_sql.lua	Mon Mar 14 14:20:37 2016 +0100
@@ -133,15 +133,17 @@
 map_store.remove = {};
 function map_store:get(username, key)
 	local ok, result = engine:transaction(function()
+		local data;
 		if type(key) == "string" and key ~= "" then
-			for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do
-				return deserialize(row[1], row[2]);
+			for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, key) do
+				data = deserialize(row[1], row[2]);
 			end
+			return data;
 		else
-			for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do
-				local data = deserialize(row[1], row[2]);
-				return data and data[key] or nil;
+			for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do
+				data = deserialize(row[1], row[2]);
 			end
+			return data and data[key] or nil;
 		end
 	end);
 	if not ok then return nil, result; end
@@ -163,9 +165,8 @@
 				end
 			else
 				local extradata = {};
-				for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do
+				for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do
 					extradata = deserialize(row[1], row[2]);
-					break;
 				end
 				engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
 					host, username or "", self.store, "");
@@ -260,8 +261,9 @@
 		if query.total then
 			local stats = engine:select("SELECT COUNT(*) FROM `prosodyarchive` WHERE " .. t_concat(where, " AND "), unpack(args));
 			if stats then
-				local _total = stats()
-				total = _total and _total[1];
+				for row in stats do
+					total = row[1];
+				end
 			end
 			if query.limit == 0 then -- Skip the real query
 				return noop, total;
--- a/util/sql.lua	Fri Mar 11 20:35:26 2016 +0100
+++ b/util/sql.lua	Mon Mar 14 14:20:37 2016 +0100
@@ -25,8 +25,8 @@
 local function is_index(x) return getmetatable(x)==index_mt; end
 local function is_table(x) return getmetatable(x)==table_mt; end
 local function is_query(x) return getmetatable(x)==query_mt; end
-local function Integer(n) return "Integer()" end
-local function String(n) return "String()" end
+local function Integer() return "Integer()" end
+local function String() return "String()" end
 
 local function Column(definition)
 	return setmetatable(definition, column_mt);
@@ -124,6 +124,14 @@
 function engine:onconnect()
 	-- Override from create_engine()
 end
+
+function engine:prepquery(sql)
+	if self.params.driver == "PostgreSQL" then
+		sql = sql:gsub("`", "\"");
+	end
+	return sql;
+end
+
 function engine:execute(sql, ...)
 	local success, err = self:connect();
 	if not success then return success, err; end
@@ -153,17 +161,13 @@
 end
 
 function engine:execute_query(sql, ...)
-	if self.params.driver == "PostgreSQL" then
-		sql = sql:gsub("`", "\"");
-	end
+	sql = self:prepquery(sql);
 	local stmt = assert(self.conn:prepare(sql));
 	assert(stmt:execute(...));
 	return stmt:rows();
 end
 function engine:execute_update(sql, ...)
-	if self.params.driver == "PostgreSQL" then
-		sql = sql:gsub("`", "\"");
-	end
+	sql = self:prepquery(sql);
 	local prepared = self.prepared;
 	local stmt = prepared[sql];
 	if not stmt then
@@ -295,19 +299,21 @@
 	local driver = self.params.driver;
 	if driver == "SQLite3" then
 		return self:transaction(function()
-			if self:select"PRAGMA encoding;"()[1] == "UTF-8" then
-				self.charset = "utf8";
+			for encoding in self:select"PRAGMA encoding;" do
+				if encoding[1] == "UTF-8" then
+					self.charset = "utf8";
+				end
 			end
 		end);
 	end
 	local set_names_query = "SET NAMES '%s';"
 	local charset = "utf8";
 	if driver == "MySQL" then
-		local ok, charsets = self:transaction(function()
-			return self:select"SELECT `CHARACTER_SET_NAME` FROM `information_schema`.`CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;";
+		self:transaction(function()
+			for row in self:select"SELECT `CHARACTER_SET_NAME` FROM `information_schema`.`CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;" do
+				charset = row and row[1] or charset;
+			end
 		end);
-		local row = ok and charsets();
-		charset = row and row[1] or charset;
 		set_names_query = set_names_query:gsub(";$", (" COLLATE '%s';"):format(charset.."_bin"));
 	end
 	self.charset = charset;
@@ -321,12 +327,16 @@
 		local ok, actual_charset = self:transaction(function ()
 			return self:select"SHOW SESSION VARIABLES LIKE 'character_set_client'";
 		end);
+		local charset_ok;
 		for row in actual_charset do
 			if row[2] ~= charset then
 				log("error", "MySQL %s is actually %q (expected %q)", row[1], row[2], charset);
-				return false, "Failed to set connection encoding";
+				charset_ok = false;
 			end
 		end
+		if not charset_ok then
+			return false, "Failed to set connection encoding";
+		end
 	end
 
 	return true;