Comparison

mod_archive/mod_archive.lua @ 159:9a37898f4f7c

mod_archive: Added features: Determining Server Support & Determining Preferences
author shinysky<shinysky1986(AT)gmail.com>
date Sat, 29 May 2010 22:02:36 +0800
parent 157:86c28405c5da
child 165:fd8d76daad97
comparison
equal deleted inserted replaced
158:1a5d5d4f08fe 159:9a37898f4f7c
1 -- Prosody IM 1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Dai Zhiwei 2 -- Copyright (C) 2010 Dai Zhiwei
3 -- 3 --
4 -- This project is MIT/X11 licensed. Please see the 4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information. 5 -- COPYING file in the source package for more information.
6 -- 6 --
7 7
8 local st = require "util.stanza"; 8 local st = require "util.stanza";
9 local dm = require "util.datamanager"
9 10
10 module:add_feature("urn:xmpp:archive"); 11 module:add_feature("urn:xmpp:archive");
12 module:add_feature("urn:xmpp:archive:auto");
13 module:add_feature("urn:xmpp:archive:manage");
14 module:add_feature("urn:xmpp:archive:manual");
15 module:add_feature("urn:xmpp:archive:pref");
11 16
12 local function preferences_handler(event) 17 local function preferences_handler(event)
18 local origin, stanza = event.origin, event.stanza;
19 module:log("debug", "-- Enter preferences_handler()");
20 module:log("debug", "-- pref:\n%s", tostring(stanza));
21 if stanza.attr.type == "get" then
22 -- dm.store(origin.username, origin.host, "archive_prefs", st.preserialize(reply.tags[1]));
23 local data = st.deserialize(dm.load(origin.username, origin.host, "archive_prefs"));
24 if data then
25 origin.send(st.reply(stanza):add_child(data));
26 else
27 local reply = st.reply(stanza):tag('pref', {xmlns='urn:xmpp:archive'});
28 reply:tag('default', {otr='concede', save='false', unset='true'}):up();
29 reply:tag('method', {type='auto', use='concede'}):up();
30 reply:tag('method', {type='local', use='concede'}):up();
31 reply:tag('method', {type='manual', use='concede'}):up();
32 reply:tag('auto', {save='false'}):up();
33 origin.send(reply);
34 -- origin.send(st.reply(stanza));
35 end
36 return true;
37 elseif stanza.attr.type == "set" then
38 return false;
39 end
40 end
41
42 local function auto_handler(event)
43 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
44 if event.stanza.attr.type == "set" then
45 event.origin.send(st.error_reply(event.stanza, "cancel", "feature-not-implemented"));
46 return true;
47 end
48 end
49
50 local function chat_handler(event)
51 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
52 return true;
53 end
54
55 local function itemremove_handler(event)
56 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
57 return true;
58 end
59
60 local function list_handler(event)
61 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
62 return true;
63 end
64
65 local function modified_handler(event)
66 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
67 return true;
68 end
69
70 local function remove_handler(event)
71 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
72 return true;
73 end
74
75 local function retrieve_handler(event)
76 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
77 return true;
78 end
79
80 local function save_handler(event)
81 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
13 return true; 82 return true;
14 end 83 end
15 84
16 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler); 85 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler);
86 module:hook("iq/self/urn:xmpp:archive:auto", auto_handler);
87 module:hook("iq/self/urn:xmpp:archive:chat", chat_handler);
88 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler);
89 module:hook("iq/self/urn:xmpp:archive:list", list_handler);
90 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler);
91 module:hook("iq/self/urn:xmpp:archive:remove", remove_handler);
92 module:hook("iq/self/urn:xmpp:archive:retrieve", retrieve_handler);
93 module:hook("iq/self/urn:xmpp:archive:save", save_handler);
17 94