From 89df062a5e59c9bad2e15b0b11a89361cc439cb1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 12 Mar 2016 18:13:24 +0100 Subject: rostermanager: Remove FIXME, per XMPP Core 8.1.1.1, we do not need to set the 'to' attribute --- core/rostermanager.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 7f6fb82a..58d1f16e 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -75,7 +75,6 @@ local function roster_push(username, host, jid) -- 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 -- cgit v1.2.3 From b65ec4aebe68d0810faa076c7ae68acc2abe34e3 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 13 Mar 2016 17:38:49 +0100 Subject: util.sql: Move per-driver (currenly only PostgreSQL) query transform into its own method --- util/sql.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/util/sql.lua b/util/sql.lua index 9981ac3c..85664567 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -124,6 +124,14 @@ end 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 @@ local function debugquery(where, sql, ...) 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 -- cgit v1.2.3 From 9df91659b930ab36d9761b049d18ed30f4b93352 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 13 Mar 2016 17:42:22 +0100 Subject: mod_storage_sql: Add LIMIT clause to queries where only a single row is expected --- plugins/mod_storage_sql.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index bf3c1c7b..a289310b 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -134,11 +134,11 @@ map_store.remove = {}; function map_store:get(username, key) local ok, result = engine:transaction(function() 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 + 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 return deserialize(row[1], row[2]); end 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 + 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 local data = deserialize(row[1], row[2]); return data and data[key] or nil; end @@ -163,7 +163,7 @@ function map_store:set_keys(username, keydatas) 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 -- cgit v1.2.3 From 144597d16ba3c2dde9196d39cce0c68c67801806 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 13 Mar 2016 17:43:33 +0100 Subject: mod_storage_sql: Allow loops over results to end on their own --- plugins/mod_storage_sql.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index a289310b..70f1ab83 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -133,15 +133,17 @@ map_store.__index = map_store; 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`=? LIMIT 1", host, username or "", self.store, key) do - return deserialize(row[1], row[2]); + 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`=? LIMIT 1", host, username or "", self.store, "") do - local data = deserialize(row[1], row[2]); - return data and data[key] or nil; + data = deserialize(row[1], row[2]); end + return data and data[key] or nil; end end); if not ok then return nil, result; end @@ -165,7 +167,6 @@ function map_store:set_keys(username, keydatas) local extradata = {}; 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 @@ function archive_store:find(username, query) 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; -- cgit v1.2.3 From 2b1ff306c3970d25100201ffe313cb307826bb3b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 13 Mar 2016 18:31:53 +0100 Subject: util.sql: Don't break out of result retreival loops --- util/sql.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/sql.lua b/util/sql.lua index 85664567..43c65a19 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -299,19 +299,21 @@ function engine:set_encoding() -- to UTF-8 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; @@ -325,12 +327,16 @@ function engine:set_encoding() -- to UTF-8 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; -- cgit v1.2.3 From f46a677512bbc57129de689c6ce2ae3b32278a09 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 13 Mar 2016 18:35:00 +0100 Subject: util.sql: Remove unused arguments [luacheck] --- util/sql.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/sql.lua b/util/sql.lua index 43c65a19..dcf665fb 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -25,8 +25,8 @@ local function is_column(x) return getmetatable(x)==column_mt; end 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); -- cgit v1.2.3 From d1578059cb3152347cddb265cf4b224741dc3997 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 14 Mar 2016 13:27:02 +0100 Subject: mod_s2s: Include name of remote server when it's missing the stream ID (thanks Ge0rG) --- plugins/mod_s2s/mod_s2s.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index 3e80c77b..16320ad1 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -363,7 +363,7 @@ function stream_callbacks.streamopened(session, attr) 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 -- cgit v1.2.3