Annotate

mod_archive/mod_archive.lua @ 172:ac826882a8cf

mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
author shinysky<shinysky1986(AT)gmail.com>
date Sun, 13 Jun 2010 23:47:50 +0800
parent 165:fd8d76daad97
child 178:62f47a93b5b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
1 -- Prosody IM
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
2 -- Copyright (C) 2010 Dai Zhiwei
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
3 --
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
6 --
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
7
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
8 local st = require "util.stanza";
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
9 local dm = require "util.datamanager";
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
10
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
11 local PREFS_DIR = "archive_prefs";
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
12 local ARCHIVE_DIR = "archive";
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
13
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
14 module:add_feature("urn:xmpp:archive");
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
15 module:add_feature("urn:xmpp:archive:auto");
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
16 module:add_feature("urn:xmpp:archive:manage");
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
17 module:add_feature("urn:xmpp:archive:manual");
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
18 module:add_feature("urn:xmpp:archive:pref");
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
19
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
20 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
21 -- Utils
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
22 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
23 local function load_prefs(node, host, dir)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
24 return st.deserialize(dm.load(node, host, dir or PREFS_DIR));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
25 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
26
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
27 local function store_prefs(data, node, host, dir)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
28 dm.store(node, host, dir or PREFS_DIR, st.preserialize(data));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
29 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
30
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
31 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
32 -- Preferences
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
33 ------------------------------------------------------------
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
34 local function preferences_handler(event)
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
35 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
36 module:log("debug", "-- Enter preferences_handler()");
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
37 module:log("debug", "-- pref:\n%s", tostring(stanza));
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
38 if stanza.attr.type == "get" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
39 local data = load_prefs(origin.username, origin.host);
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
40 if data then
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
41 origin.send(st.reply(stanza):add_child(data));
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
42 else
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
43 local reply = st.reply(stanza):tag('pref', {xmlns='urn:xmpp:archive'});
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
44 reply:tag('default', {otr='concede', save='false', unset='true'}):up();
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
45 reply:tag('method', {type='auto', use='concede'}):up();
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
46 reply:tag('method', {type='local', use='concede'}):up();
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
47 reply:tag('method', {type='manual', use='concede'}):up();
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
48 reply:tag('auto', {save='false'}):up();
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
49 origin.send(reply);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
50 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
51 elseif stanza.attr.type == "set" then
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
52 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
53 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
54 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
55 data = st.stanza('pref', {xmlns='urn:xmpp:archive'});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
56 data:tag('default', {otr='concede', save='false'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
57 data:tag('method', {type='auto', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
58 data:tag('method', {type='local', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
59 data:tag('method', {type='manual', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
60 data:tag('auto', {save='false'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
61 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
62 local elem = stanza.tags[1].tags[1]; -- iq:pref:xxx
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
63 if not elem then return false end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
64 -- "default" | "item" | "session" | "method"
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
65 -- FIXME there may be many item/session/method sections!!
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
66 elem.attr["xmlns"] = nil; -- TODO why there is an extra xmlns attr?
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
67 if elem.name == "default" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
68 local setting = data:child_with_name(elem.name)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
69 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
70 setting.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
71 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
72 -- setting.attr["unset"] = nil
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
73 elseif elem.name == "item" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
74 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
75 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
76 -- TODO bare JID or full JID?
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
77 if child.name == elem.name and child.attr["jid"] == elem.attr["jid"] then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
78 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
79 child.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
80 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
81 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
82 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
83 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
84 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
85 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
86 data:tag(elem.name, elem.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
87 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
88 elseif elem.name == "session" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
89 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
90 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
91 if child.name == elem.name and child.attr["thread"] == elem.attr["thread"] then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
92 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
93 child.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
94 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
95 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
96 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
97 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
98 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
99 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
100 data:tag(elem.name, elem.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
101 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
102 elseif elem.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
103 local newpref = stanza.tags[1]; -- iq:pref
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
104 for _, e in ipairs(newpref.tags) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
105 -- if e.name ~= "method" then continue end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
106 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
107 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
108 if child.name == "method" and child.attr["type"] == e.attr["type"] then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
109 child.attr["use"] = e.attr["use"];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
110 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
111 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
112 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
113 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
114 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
115 data:tag(e.name, e.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
116 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
117 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
118 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
119 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
120 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
121 local user = bare_sessions[node.."@"..host];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
122 local push = st.iq({type="set"});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
123 push = push:tag('pref', {xmlns='urn:xmpp:archive'});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
124 if elem.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
125 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
126 if child.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
127 push:add_child(child);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
128 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
129 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
130 else
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
131 push:add_child(elem);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
132 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
133 push = push:up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
134 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
135 if res.presence then -- to resource
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
136 push.attr.to = res.full_jid;
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
137 res.send(push);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
138 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
139 end
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
140 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
141 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
142 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
143
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
144 local function itemremove_handler(event)
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
145 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
146 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
147 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
148 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
149 local elem = stanza.tags[1].tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
150 if not elem or elem.name ~= "item" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
151 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
152 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
153 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
154 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
155 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
156 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
157 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
158 for i, child in ipairs(data) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
159 if child.name == "item" and child.attr["jid"] == elem.attr["jid"] then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
160 table.remove(data, i)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
161 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
162 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
163 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
164 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
165 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
166 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
167 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
168
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
169 local function sessionremove_handler(event)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
170 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
171 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
172 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
173 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
174 local elem = stanza.tags[1].tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
175 if not elem or elem.name ~= "session" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
176 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
177 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
178 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
179 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
180 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
181 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
182 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
183 for i, child in ipairs(data) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
184 if child.name == "session" and child.attr["thread"] == elem.attr["thread"] then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
185 table.remove(data, i)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
186 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
187 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
188 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
189 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
190 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
191 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
192 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
193
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
194 local function auto_handler(event)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
195 -- event.origin.send(st.error_reply(event.stanza, "cancel", "feature-not-implemented"));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
196 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
197 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
198 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
199 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
200 local elem = stanza.tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
201 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
202 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
203 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
204 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
205 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
206 local setting = data:child_with_name(elem.name)
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
207 for k, v in pairs(elem.attr) do
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
208 setting.attr[k] = v;
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
209 end
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
210 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
211 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
212 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
213 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
214
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
215 local function chat_handler(event)
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
216 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
217 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
218 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
219
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
220 local function list_handler(event)
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
221 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
222 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
223 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
224
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
225 local function modified_handler(event)
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
226 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
227 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
228 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
229
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
230 local function remove_handler(event)
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
231 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
232 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
233 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
234
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
235 local function retrieve_handler(event)
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
236 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
237 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
238 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
239
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
240 local function save_handler(event)
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
241 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
242 return true;
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
243 end
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
244
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
245 local function msg_handler(data)
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
246 module:log("debug", "-- Enter msg_handler()");
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
247 local origin, stanza = data.origin, data.stanza;
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
248 module:log("debug", "-- msg:\n%s", tostring(stanza));
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
249 return nil;
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
250 end
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
251
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
252 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler);
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
253 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
254 module:hook("iq/self/urn:xmpp:archive:sessionremove", sessionremove_handler);
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
255 module:hook("iq/self/urn:xmpp:archive:auto", auto_handler);
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
256 -- module:hook("iq/self/urn:xmpp:archive:chat", chat_handler);
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
257 module:hook("iq/self/urn:xmpp:archive:list", list_handler);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
258 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
259 module:hook("iq/self/urn:xmpp:archive:remove", remove_handler);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
260 module:hook("iq/self/urn:xmpp:archive:retrieve", retrieve_handler);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
261 module:hook("iq/self/urn:xmpp:archive:save", save_handler);
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
262
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
263 module:hook("message/full", msg_handler, 10);
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
264 module:hook("message/bare", msg_handler, 10);
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
265