prosody: Enable storage manager.
[prosody.git] / plugins / mod_private.lua
index 91ea83e1e1b9d92fb9656d2572bcea05658048bd..abf1ec039a5d076c361d39784a2ce16dc453f757 100644 (file)
@@ -1,11 +1,21 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+-- 
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+
 
 local st = require "util.stanza"
-local send = require "core.sessionmanager".send_to_session
 
 local jid_split = require "util.jid".split;
 local datamanager = require "util.datamanager"
 
-add_iq_handler("c2s", "jabber:iq:private",
+module:add_feature("jabber:iq:private");
+
+module:add_iq_handler("c2s", "jabber:iq:private",
        function (session, stanza)
                local type = stanza.attr.type;
                local query = stanza.tags[1];
@@ -16,12 +26,16 @@ add_iq_handler("c2s", "jabber:iq:private",
                                if #query.tags == 1 then
                                        local tag = query.tags[1];
                                        local key = tag.name..":"..tag.attr.xmlns;
-                                       local data = datamanager.load(node, host, "private");
+                                       local data, err = datamanager.load(node, host, "private");
+                                       if err then
+                                               session.send(st.error_reply(stanza, "wait", "internal-server-error"));
+                                               return true;
+                                       end
                                        if stanza.attr.type == "get" then
                                                if data and data[key] then
-                                                       send(session, st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key])));
+                                                       session.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key])));
                                                else
-                                                       send(session, st.reply(stanza):add_child(stanza.tags[1]));
+                                                       session.send(st.reply(stanza):add_child(stanza.tags[1]));
                                                end
                                        else -- set
                                                if not data then data = {}; end;
@@ -32,16 +46,16 @@ add_iq_handler("c2s", "jabber:iq:private",
                                                end
                                                -- TODO delete datastore if empty
                                                if datamanager.store(node, host, "private", data) then
-                                                       send(session, st.reply(stanza));
+                                                       session.send(st.reply(stanza));
                                                else
-                                                       send(session, st.error_reply(stanza, "wait", "internal-server-error"));
+                                                       session.send(st.error_reply(stanza, "wait", "internal-server-error"));
                                                end
                                        end
                                else
-                                       send(session, st.error_reply(stanza, "modify", "bad-format"));
+                                       session.send(st.error_reply(stanza, "modify", "bad-format"));
                                end
                        else
-                               send(session, st.error_reply(stanza, "cancel", "forbidden"));
+                               session.send(st.error_reply(stanza, "cancel", "forbidden"));
                        end
                end
-       end);
\ No newline at end of file
+       end);