Merge 0.9->trunk
[prosody.git] / core / storagemanager.lua
index a9759b6a2e98b9b376257cb9f31786dbbfffa41f..36a671beb68a70ae5abaa069e8bec7df4e42909b 100644 (file)
@@ -33,12 +33,12 @@ local stores_available = multitable.new();
 
 function initialize_host(host)
        local host_session = hosts[host];
-       host_session.events.add_handler("item-added/data-driver", function (event)
+       host_session.events.add_handler("item-added/storage-provider", function (event)
                local item = event.item;
                stores_available:set(host, item.name, item);
        end);
        
-       host_session.events.add_handler("item-removed/data-driver", function (event)
+       host_session.events.add_handler("item-removed/storage-provider", function (event)
                local item = event.item;
                stores_available:set(host, item.name, nil);
        end);
@@ -59,7 +59,7 @@ function load_driver(host, driver_name)
 end
 
 function get_driver(host, store)
-       local storage = config.get(host, "core", "storage");
+       local storage = config.get(host, "storage");
        local driver_name;
        local option_type = type(storage);
        if option_type == "string" then
@@ -68,7 +68,7 @@ function get_driver(host, store)
                driver_name = storage[store];
        end
        if not driver_name then
-               driver_name = config.get(host, "core", "default_storage") or "internal";
+               driver_name = config.get(host, "default_storage") or "internal";
        end
        
        local driver = load_driver(host, driver_name);
@@ -95,8 +95,7 @@ function open(host, store, typ)
 end
 
 function purge(user, host)
-       local storage = config.get(host, "core", "storage");
-       local driver_name;
+       local storage = config.get(host, "storage");
        if type(storage) == "table" then
                -- multiple storage backends in use that we need to purge
                local purged = {};
@@ -119,11 +118,18 @@ end
 function datamanager.store(username, host, datastore, data)
        return open(host, datastore):set(username, data);
 end
-function datamanager.list_stores(username, host)
-       return get_driver(host):list_stores(username);
+function datamanager.users(host, datastore, typ)
+       local driver = open(host, datastore, typ);
+       if not driver.users then
+               return function() log("warn", "storage driver %s does not support listing users", driver.name) end
+       end
+       return driver:users();
+end
+function datamanager.stores(username, host, typ)
+       return get_driver(host):stores(username, typ);
 end
 function datamanager.purge(username, host)
-       return purge(username);
+       return purge(username, host);
 end
 
 return _M;