Changeset

7758:2b305ec8c146

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Fri, 02 Dec 2016 11:13:05 +0100
parents 7747:0e442402cebc (current diff) 7757:437fb77e5ded (diff)
children 7765:4757c3644168
files plugins/mod_storage_sql.lua util/stanza.lua
diffstat 4 files changed, 36 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Sun Nov 27 01:06:23 2016 +0100
+++ b/configure	Fri Dec 02 11:13:05 2016 +0100
@@ -81,7 +81,7 @@
 
 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 @@
 
 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 @@
          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 @@
             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 @@
    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."
--- a/plugins/mod_register.lua	Sun Nov 27 01:06:23 2016 +0100
+++ b/plugins/mod_register.lua	Fri Dec 02 11:13:05 2016 +0100
@@ -257,6 +257,7 @@
 						-- 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);
--- a/plugins/mod_storage_sql.lua	Sun Nov 27 01:06:23 2016 +0100
+++ b/plugins/mod_storage_sql.lua	Fri Dec 02 11:13:05 2016 +0100
@@ -7,10 +7,8 @@
 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
@@ -435,14 +433,22 @@
 	return changes;
 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
+	return database;
+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
-	end
-	assert(params.driver and params.database, "Configuration error: Both the SQL driver and the database need to be specified");
-	return 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;
+		port = params.port;
+	};
 end
 
 function module.load()
@@ -478,7 +484,7 @@
 		-- 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");
@@ -498,7 +504,10 @@
 			upgrade_table(params, true);
 		end
 		print("All done!");
+	elseif command then
+		print("Unknown command: "..command);
 	else
-		print("Unknown command: "..command);
+		print("Available commands:");
+		print("","upgrade - Perform database upgrade");
 	end
 end
--- a/util/stanza.lua	Sun Nov 27 01:06:23 2016 +0100
+++ b/util/stanza.lua	Fri Dec 02 11:13:05 2016 +0100
@@ -14,6 +14,7 @@
 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 @@
 	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
@@ -422,6 +427,7 @@
 return {
 	stanza_mt = stanza_mt;
 	stanza = new_stanza;
+	is_stanza = is_stanza;
 	new_id = new_id;
 	preserialize = preserialize;
 	deserialize = deserialize;