From 7e302e2b0e578b6916b7d29d1a250d97b59ac8ae Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 27 Nov 2016 20:46:55 +0100 Subject: configure: Use $() and quotes instead of `` [shellcheck] --- configure | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 2513eed3..d530debe 100755 --- a/configure +++ b/configure @@ -81,7 +81,7 @@ EOF while [ "$1" ] do - value="`echo $1 | sed 's/[^=]*=\(.*\)/\1/'`" + value="$(echo "$1" | sed 's/[^=]*=\(.*\)/\1/')" if echo "$value" | grep -q "~" then echo @@ -268,8 +268,8 @@ fi find_program() { path="$PATH" - item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`" - path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`" + item="$(echo "$path" | sed 's/\([^:]*\):.*/\1/')" + path="$(echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p')" found="no" while [ "$item" ] do @@ -278,8 +278,8 @@ find_program() { found="yes" break fi - item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`" - path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`" + item="$(echo "$path" | sed 's/\([^:]*\):.*/\1/')" + path="$(echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p')" done if [ "$found" = "yes" ] then @@ -301,7 +301,7 @@ then find_lua="$LUA_DIR" fi else - find_lua=`find_program lua$suffix` + find_lua="$(find_program lua$suffix)" fi if [ "$find_lua" ] then @@ -316,12 +316,12 @@ then echo -n "Looking for Lua... " if [ ! "$find_lua" ] then - find_lua=`find_program lua$LUA_SUFFIX` + find_lua"=$(find_program lua$LUA_SUFFIX)" echo "lua$LUA_SUFFIX found in \$PATH: $find_lua" fi if [ "$find_lua" ] then - LUA_DIR=`dirname $find_lua` + LUA_DIR="$(dirname $find_lua)" LUA_BINDIR="$find_lua" else echo "lua$LUA_SUFFIX not found in \$PATH." -- cgit v1.2.3 From 8f3f909b30079072560fb3cb1b21c95c2845cce9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Nov 2016 06:55:48 +0100 Subject: configure: Fix quote on the correct side of the equals sign --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index d530debe..974823c3 100755 --- a/configure +++ b/configure @@ -316,7 +316,7 @@ then echo -n "Looking for Lua... " if [ ! "$find_lua" ] then - find_lua"=$(find_program lua$LUA_SUFFIX)" + find_lua="$(find_program lua$LUA_SUFFIX)" echo "lua$LUA_SUFFIX found in \$PATH: $find_lua" fi if [ "$find_lua" ] -- cgit v1.2.3 From 06124bad4d8c84f2d18e64a55eef0a8bfa55e7eb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Nov 2016 07:30:21 +0100 Subject: util.stanza: Add an is_stanza() function to check if an object is a stanza --- util/stanza.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/stanza.lua b/util/stanza.lua index 8bb9ba05..2191fa8e 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -14,6 +14,7 @@ local s_format = string.format; local s_match = string.match; local tostring = tostring; local setmetatable = setmetatable; +local getmetatable = getmetatable; local pairs = pairs; local ipairs = ipairs; local type = type; @@ -45,6 +46,10 @@ local function new_stanza(name, attr) return setmetatable(stanza, stanza_mt); end +local function is_stanza(s) + return getmetatable(s) == stanza_mt; +end + function stanza_mt:query(xmlns) return self:tag("query", { xmlns = xmlns }); end @@ -417,6 +422,7 @@ end return { stanza_mt = stanza_mt; stanza = new_stanza; + is_stanza = is_stanza; new_id = new_id; preserialize = preserialize; deserialize = deserialize; -- cgit v1.2.3 From 5c7a04bc7b0b4fac73fa2259715ba030aa792ff4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Nov 2016 07:30:39 +0100 Subject: mod_storage_sql: Use is_stanza() from util.stanza --- plugins/mod_storage_sql.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 4f46b3f6..b7ade340 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -7,10 +7,8 @@ local xml_parse = require "util.xml".parse; local uuid = require "util.uuid"; local resolve_relative_path = require "util.paths".resolve_relative_path; -local stanza_mt = require"util.stanza".stanza_mt; -local getmetatable = getmetatable; +local is_stanza = require"util.stanza".is_stanza; local t_concat = table.concat; -local function is_stanza(x) return getmetatable(x) == stanza_mt; end local noop = function() end local unpack = unpack -- cgit v1.2.3 From 42f67b2a729db0b48129109ef9cd41f0fd476ec1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 29 Nov 2016 08:20:42 +0100 Subject: mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636) --- plugins/mod_storage_sql.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index b7ade340..fa241ed9 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -433,14 +433,22 @@ local function upgrade_table(params, apply_changes) return changes; end -local function normalize_params(params) - if params.driver == "SQLite3" then - if params.database ~= ":memory:" then - params.database = resolve_relative_path(prosody.paths.data or ".", params.database or "prosody.sqlite"); - end +local function normalize_database(driver, database) + if driver == "SQLite3" and database ~= ":memory:" then + return resolve_relative_path(prosody.paths.data or ".", database or "prosody.sqlite"); end - assert(params.driver and params.database, "Configuration error: Both the SQL driver and the database need to be specified"); - return params; + return database; +end + +local function normalize_params(params) + return { + driver = assert(params.driver, "Configuration error: Both the SQL driver and the database need to be specified"); + database = assert(normalize_database(params.driver, params.database), "Configuration error: Both the SQL driver and the database need to be specified"); + username = params.username; + password = params.password; + host = params.host; + params.port; + }; end function module.load() -- cgit v1.2.3 From 3d31b0f2ebd4b806ea1d084bf44b9ee2ac594655 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 03:22:42 +0100 Subject: mod_storage_sql: Include missing parameter table key 'port' --- plugins/mod_storage_sql.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index fa241ed9..aef7ff8b 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -447,7 +447,7 @@ local function normalize_params(params) username = params.username; password = params.password; host = params.host; - params.port; + port = params.port; }; end -- cgit v1.2.3 From 854e22b394fd523c783e79a2a03a4dab28e7e5d6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 06:47:03 +0100 Subject: mod_register: Record the time of registration in the account details store --- plugins/mod_register.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index eaa0614d..c376117f 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -257,6 +257,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) -- TODO unable to write file, file may be locked, etc, what's the correct error? local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); if usermanager_create_user(username, password, host) then + data.registered = os.time(); if next(data) and not account_details:set(username, data) then log("debug", "Could not store extra details"); usermanager_delete_user(username, host); -- cgit v1.2.3 From b4b0a1a7f20ac379d6c4fcd64e5c6331fb47620d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 10:02:01 +0100 Subject: mod_storage_sql: Don't say 'Unknown command' if no command was given (fixes attempt to concatenate nil) --- plugins/mod_storage_sql.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index aef7ff8b..1872ea34 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -504,6 +504,8 @@ function module.command(arg) upgrade_table(params, true); end print("All done!"); + elseif command then + print("Unknown command: "..command); else print("Unknown command: "..command); end -- cgit v1.2.3 From 547a7061bc8fd3c4f5f490bb7f54fc26558f6e26 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 10:02:26 +0100 Subject: mod_storage_sql: List available commands if no commands given (currenly only one available) --- plugins/mod_storage_sql.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 1872ea34..67a441b7 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -507,6 +507,7 @@ function module.command(arg) elseif command then print("Unknown command: "..command); else - print("Unknown command: "..command); + print("Available commands:"); + print("","upgrade - Perform database upgrade"); end end -- cgit v1.2.3 From b505c4dd28533f117a2085a020426111411e6d88 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 10:02:57 +0100 Subject: mod_storage_sql: Normalize parameters for upgrade command --- plugins/mod_storage_sql.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 67a441b7..819846bb 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -484,7 +484,7 @@ function module.command(arg) -- We need to find every unique dburi in the config local uris = {}; for host in pairs(prosody.hosts) do - local params = config.get(host, "sql") or default_params; + local params = normalize_params(config.get(host, "sql") or default_params); uris[sql.db2uri(params)] = params; end print("We will check and upgrade the following databases:\n"); -- cgit v1.2.3