local keyval_store = {};
keyval_store.__index = keyval_store;
function keyval_store:get(username)
- user,store = username,self.store;
+ user, store = username, self.store;
local ok, result = engine:transaction(keyval_store_get);
- if not ok then return ok, result; end
+ if not ok then
+ module:log("error", "Unable to read from database %s store for %s: %s", store, username or "<host>", result);
+ return nil, result;
+ end
- return result;
+ return result;
end
function keyval_store:set(username, data)
user,store = username,self.store;
return iterator(result);
end
+ --- Archive store API
+
+local map_store = {};
+map_store.__index = map_store;
+function map_store:get(username, key)
+ local ok, result = engine:transaction(function()
+ if type(key) == "string" and key ~= "" then
+ for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do
+ return deserialize(row[1], row[2]);
+ end
+ else
+ error("TODO: non-string keys");
+ end
+ end);
+ if not ok then return nil, result; end
+ return result;
+end
+function map_store:set(username, key, data)
+ local ok, result = engine:transaction(function()
+ if type(key) == "string" and key ~= "" then
+ engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
+ host, username or "", self.store, key);
+ if data ~= nil then
+ local t, value = assert(serialize(data));
+ engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value);
+ end
+ else
+ error("TODO: non-string keys");
+ end
+ return true;
+ end);
+ if not ok then return nil, result; end
+ return result;
+end
+
local archive_store = {}
archive_store.caps = {
total = true;
return um_is_admin(jid, module.host);
end
-room_mt = muclib.room_mt; -- Yes, global.
-local _set_affiliation = room_mt.set_affiliation;
-local _get_affiliation = room_mt.get_affiliation;
-function muclib.room_mt:get_affiliation(jid)
- if is_admin(jid) then return "owner"; end
- return _get_affiliation(self, jid);
-end
-function muclib.room_mt:set_affiliation(actor, jid, affiliation, callback, reason)
- if affiliation ~= "owner" and is_admin(jid) then return nil, "modify", "not-acceptable"; end
- return _set_affiliation(self, actor, jid, affiliation, callback, reason);
+do -- Monkey patch to make server admins room owners
+ local _get_affiliation = room_mt.get_affiliation;
+ function room_mt:get_affiliation(jid)
+ if is_admin(jid) then return "owner"; end
+ return _get_affiliation(self, jid);
+ end
+
+ local _set_affiliation = room_mt.set_affiliation;
+ function room_mt:set_affiliation(actor, jid, ...)
- if is_admin(jid) then return nil, "modify", "not-acceptable"; end
++ if affiliation ~= "owner" and is_admin(jid) then return nil, "modify", "not-acceptable"; end
+ return _set_affiliation(self, actor, jid, ...);
+ end
end
-local function room_route_stanza(room, stanza) module:send(stanza); end
+local persistent = module:require "muc/persistent";
+local persistent_rooms_storage = module:open_store("persistent");
+local persistent_rooms = module:open_store("persistent", "map");
+local room_configs = module:open_store("config");
+
local function room_save(room, forced)
local node = jid_split(room.jid);
- persistent_rooms[room.jid] = room._data.persistent;
- if room._data.persistent then
+ local is_persistent = persistent.get(room);
+ persistent_rooms:set(nil, room.jid, is_persistent);
+ if is_persistent then
local history = room._data.history;
room._data.history = nil;
local data = {