Merge 0.10->trunk
authorKim Alvefur <zash@zash.se>
Thu, 25 Jun 2015 16:57:43 +0000 (18:57 +0200)
committerKim Alvefur <zash@zash.se>
Thu, 25 Jun 2015 16:57:43 +0000 (18:57 +0200)
1  2 
plugins/mod_storage_sql2.lua
plugins/muc/mod_muc.lua

index c1030ab037ef626f7925dee058bf4dea2316ed9a,7c797447028ba888afbeeed8c8eddd6c2f8a3120..9a9e60614fec36756749fca74e80a9f7b073f098
@@@ -195,10 -101,13 +101,13 @@@ en
  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;
@@@ -214,39 -123,8 +123,41 @@@ function keyval_store:users(
        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;
index db85a73fdf03511b90cd3b0574c2afa570fa37bd,693515042456856a5c7b1b994ecf5a19c48f02ec..03a23e09fc2ce1ad97f1e5712264003dfe9334e9
@@@ -30,30 -52,23 +30,30 @@@ local function is_admin(jid
        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 = {