+function set_data_path(path)
+ log("debug", "Setting data path to: %s", path);
+ data_path = path;
+end
+
+local function callback(username, host, datastore, data)
+ for _, f in ipairs(callbacks) do
+ username, host, datastore, data = f(username, host, datastore, data);
+ if username == false then break; end
+ end
+
+ return username, host, datastore, data;
+end
+function add_callback(func)
+ if not callbacks[func] then -- Would you really want to set the same callback more than once?
+ callbacks[func] = true;
+ callbacks[#callbacks+1] = func;
+ return true;
+ end
+end
+function remove_callback(func)
+ if callbacks[func] then
+ for i, f in ipairs(callbacks) do
+ if f == func then
+ callbacks[i] = nil;
+ callbacks[f] = nil;
+ return true;
+ end
+ end
+ end
+end
+
+function getpath(username, host, datastore, ext, create)
+ ext = ext or "dat";
+ host = (host and encode(host)) or "_global";
+ username = username and encode(username);
+ if username then
+ if create then mkdir(mkdir(mkdir(data_path).."/"..host).."/"..datastore); end
+ return format("%s/%s/%s/%s.%s", data_path, host, datastore, username, ext);
+ elseif host then
+ if create then mkdir(mkdir(data_path).."/"..host); end
+ return format("%s/%s/%s.%s", data_path, host, datastore, ext);
+ else
+ if create then mkdir(data_path); end
+ return format("%s/%s.%s", data_path, datastore, ext);
+ end