aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-07-28 20:59:03 +0100
committerMatthew Wild <mwild1@gmail.com>2012-07-28 20:59:03 +0100
commit8aafe03289bdc2e8697bf72d226c4325ffc8d51f (patch)
tree57f657bdb5f9107ab5d46cd8ea6e0f18e7a20b11 /plugins
parent655defbb532f079c1476511db9c47b141a1d9792 (diff)
parent5e57a36957ea2d717865eefa2155c5dc854f8b4d (diff)
downloadprosody-8aafe03289bdc2e8697bf72d226c4325ffc8d51f.tar.gz
prosody-8aafe03289bdc2e8697bf72d226c4325ffc8d51f.zip
Merge with Zash
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_internal.lua8
-rw-r--r--plugins/mod_storage_sql.lua33
2 files changed, 39 insertions, 2 deletions
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 821d1e1a..92ac3ef5 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -16,4 +16,12 @@ 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
+
+function driver:purge(user)
+ return datamanager.purge(user, host);
+end
+
module:add_item("data-driver", driver);
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 6a2d36f1..6d19eee6 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
@@ -349,4 +352,30 @@ 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
+
+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);