From 047404cab0e0419092215e93d2b1d865d4549679 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:24:59 +0200 Subject: mod_storage_internal: Add method for listing stores --- plugins/mod_storage_internal.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua index 821d1e1a..cd778373 100644 --- a/plugins/mod_storage_internal.lua +++ b/plugins/mod_storage_internal.lua @@ -16,4 +16,8 @@ function driver:set(user, data) return datamanager.store(user, host, self.store, data); end +function driver:list_stores(username) + return datamanager.list_stores(username, host); +end + module:add_item("data-driver", driver); -- cgit v1.2.3 From d58703f58288f9f98c2d02a40fdbc807f4da6af2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:26:33 +0200 Subject: mod_storage_sql: Split out query handling logic from getsql() into a separate function --- plugins/mod_storage_sql.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 6a2d36f1..8b05c822 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -175,7 +175,7 @@ local function deserialize(t, value) end end -local function getsql(sql, ...) +local function dosql(sql, ...) if params.driver == "PostgreSQL" then sql = sql:gsub("`", "\""); end @@ -184,12 +184,15 @@ local function getsql(sql, ...) if not stmt and not test_connection() then error("connection failed"); end if not stmt then module:log("error", "QUERY FAILED: %s %s", err, debug.traceback()); return nil, err; end -- run query - local ok, err = stmt:execute(host or "", user or "", store or "", ...); + local ok, err = stmt:execute(...); if not ok and not test_connection() then error("connection failed"); end if not ok then return nil, err; end return stmt; end +local function getsql(sql, ...) + return dosql(sql, host or "", user or "", store or "", ...); +end local function setsql(sql, ...) local stmt, err = getsql(sql, ...); if not stmt then return stmt, err; end -- cgit v1.2.3 From a1b0be048a60d63da9057e1791e5db4c41b3a6c0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:27:45 +0200 Subject: mod_storage_sql: Add method for listing stores --- plugins/mod_storage_sql.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 8b05c822..211f4d5f 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -352,4 +352,22 @@ function driver:open(store, typ) return nil, "unsupported-store"; end +function driver:list_stores(username) -- Not to be confused with the list store type + local sql = (username == true + and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?" + or "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?"); + if username == true or not username then + username = ""; + end + local stmt, err = dosql(sql, host, username); + if not stmt then + return nil, err; + end + local stores = {}; + for row in stmt:rows() do + stores[#stores+1] = row[1]; + end + return stores; +end + module:add_item("data-driver", driver); -- cgit v1.2.3 From acf5902aaf7dc3bbdc0cde8f4737fe0e4534720b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:36:36 +0200 Subject: mod_storage_internal: Add method for removing all data belonging to a user --- plugins/mod_storage_internal.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua index cd778373..92ac3ef5 100644 --- a/plugins/mod_storage_internal.lua +++ b/plugins/mod_storage_internal.lua @@ -20,4 +20,8 @@ function driver:list_stores(username) return datamanager.list_stores(username, host); end +function driver:purge(user) + return datamanager.purge(user, host); +end + module:add_item("data-driver", driver); -- cgit v1.2.3 From 066faa6e4eadbb95f982d50aaabde03a6254a669 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:36:42 +0200 Subject: mod_storage_sql: Add method for removing all data belonging to a user --- plugins/mod_storage_sql.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 211f4d5f..6d19eee6 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -370,4 +370,12 @@ function driver:list_stores(username) -- Not to be confused with the list store return stores; end +function driver:purge(username) + local stmt, err = dosql("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); + if not stmt then return stmt, err; end + local changed, err = stmt:affected(); + if not changed then return changed, err; end + return true, changed; +end + module:add_item("data-driver", driver); -- cgit v1.2.3