Software /
code /
prosody
Comparison
util/datamanager.lua @ 117:8e5c5e6a3240
Fixed: datamanager.store and datamanager.load could crash when username or host arguments were nil. (useful for server specific and global data).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 02:49:43 +0500 |
parent | 88:023320150c65 |
child | 129:0f119bece309 |
comparison
equal
deleted
inserted
replaced
116:72e698cdabd7 | 117:8e5c5e6a3240 |
---|---|
66 end | 66 end |
67 end | 67 end |
68 | 68 |
69 function load(username, host, datastore) | 69 function load(username, host, datastore) |
70 local data, ret = loadfile(getpath(username, host, datastore)); | 70 local data, ret = loadfile(getpath(username, host, datastore)); |
71 if not data then log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end | 71 if not data then |
72 log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil)); | |
73 return nil; | |
74 end | |
72 setfenv(data, {}); | 75 setfenv(data, {}); |
73 local success, ret = pcall(data); | 76 local success, ret = pcall(data); |
74 if not success then log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end | 77 if not success then |
78 log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil)); | |
79 return nil; | |
80 end | |
75 return ret; | 81 return ret; |
76 end | 82 end |
77 | 83 |
78 function store(username, host, datastore, data) | 84 function store(username, host, datastore, data) |
79 local f, msg = io_open(getpath(username, host, datastore), "w+"); | 85 local f, msg = io_open(getpath(username, host, datastore), "w+"); |
80 if not f then log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..username.."@"..host); return nil; end | 86 if not f then |
87 log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or nil).."@"..(host or nil)); | |
88 return nil; | |
89 end | |
81 f:write("return "); | 90 f:write("return "); |
82 simplesave(f, data); | 91 simplesave(f, data); |
83 f:close(); | 92 f:close(); |
84 return true; | 93 return true; |
85 end | 94 end |