Comparison

core/storagemanager.lua @ 4076:00ce99071368

storagemanager: Add new "null" provider to get used when loading a driver or opening a store fails, instead of falling back to the default driver
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Jan 2011 13:56:39 +0000
parent 4075:c082ded3b5f1
child 4011:0df6b99cb74a
comparison
equal deleted inserted replaced
4075:c082ded3b5f1 4076:00ce99071368
13 for k,v in pairs(datamanager) do olddm[k] = v; end 13 for k,v in pairs(datamanager) do olddm[k] = v; end
14 local prosody = prosody; 14 local prosody = prosody;
15 15
16 module("storagemanager") 16 module("storagemanager")
17 17
18 local null_storage_method = function () return false, "no data storage active"; end
19 local null_storage_driver = setmetatable(
20 {
21 name = "null",
22 open = function (self) return self; end
23 }, {
24 __index = function (self, method)
25 return null_storage_method;
26 end
27 }
28 );
29
30 --TODO: Move default driver to mod_auth_internal
18 local default_driver_mt = { name = "internal" }; 31 local default_driver_mt = { name = "internal" };
19 default_driver_mt.__index = default_driver_mt; 32 default_driver_mt.__index = default_driver_mt;
20 function default_driver_mt:open(store) 33 function default_driver_mt:open(store)
21 return setmetatable({ host = self.host, store = store }, default_driver_mt); 34 return setmetatable({ host = self.host, store = store }, default_driver_mt);
22 end 35 end
71 driver_name = config.get(host, "core", "default_storage"); 84 driver_name = config.get(host, "core", "default_storage");
72 driver = load_driver(host, driver_name); 85 driver = load_driver(host, driver_name);
73 if not driver then 86 if not driver then
74 if driver_name or (type(storage) == "string" 87 if driver_name or (type(storage) == "string"
75 or type(storage) == "table" and storage[store]) then 88 or type(storage) == "table" and storage[store]) then
76 log("warn", "Falling back to default driver for %s storage on %s", store, host); 89 log("warn", "Falling back to null driver for %s storage on %s", store, host);
90 driver_name = "null";
91 driver = null_storage_driver;
92 else
93 driver_name = "internal";
94 driver = load_driver(host, driver_name);
77 end 95 end
78 driver_name = "internal";
79 driver = load_driver(host, driver_name);
80 end 96 end
81 end 97 end
82 98
83 local ret, err = driver:open(store, typ); 99 local ret, err = driver:open(store, typ);
84 if not ret then 100 if not ret then
85 if err == "unsupported-store" then 101 if err == "unsupported-store" then
86 log("debug", "Storage driver %s does not support store %s (%s), falling back to internal driver", 102 log("debug", "Storage driver %s does not support store %s (%s), falling back to internal driver",
87 driver_name, store, typ); 103 driver_name, store, typ);
88 ret = setmetatable({ host = host, store = store }, default_driver_mt); -- default to default driver 104 ret = null_storage_driver;
89 err = nil; 105 err = nil;
90 end 106 end
91 end 107 end
92 return ret, err; 108 return ret, err;
93 end 109 end