aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/datamanager.lua15
-rw-r--r--util/jid.lua5
2 files changed, 16 insertions, 4 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 1deb6b3d..f4ae958c 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -68,16 +68,25 @@ end
function load(username, host, datastore)
local data, ret = loadfile(getpath(username, host, datastore));
- if not data then log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end
+ if not data then
+ log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil));
+ return nil;
+ end
setfenv(data, {});
local success, ret = pcall(data);
- if not success then log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end
+ if not success then
+ log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil));
+ return nil;
+ end
return ret;
end
function store(username, host, datastore, data)
local f, msg = io_open(getpath(username, host, datastore), "w+");
- if not f then log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..username.."@"..host); return nil; end
+ if not f then
+ log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or nil).."@"..(host or nil));
+ return nil;
+ end
f:write("return ");
simplesave(f, data);
f:close();
diff --git a/util/jid.lua b/util/jid.lua
index 28dd1a92..b1e4131d 100644
--- a/util/jid.lua
+++ b/util/jid.lua
@@ -4,9 +4,12 @@ local match = string.match;
module "jid"
function split(jid)
- if not jid then return nil; end
+ if not jid then return; end
+ -- TODO verify JID, and return; if invalid
local node = match(jid, "^([^@]+)@");
local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)");
local resource = match(jid, "/(.+)$");
return node, server, resource;
end
+
+return _M; \ No newline at end of file