annotate mod_archive/mod_archive.lua @ 196:a1c2677257da

mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
author shinysky<shinysky1986(AT)gmail.com>
date Wed, 07 Jul 2010 17:31:31 +0800
parents 4d9ed6374a1f
children a3b5810de3e4
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";
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
10 local jid = require "util.jid";
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
11 local datetime = require "util.datetime";
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
12
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
13 local PREFS_DIR = "archive_prefs";
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
14 local ARCHIVE_DIR = "archive";
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
15
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
16 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
17 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
18 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
19 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
20 module:add_feature("urn:xmpp:archive:pref");
195
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
21 module:add_feature("http://jabber.org/protocol/rsm");
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
22
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
23 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
24 -- Utils
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
25 ------------------------------------------------------------
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
26 local function load_prefs(node, host)
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
27 return st.deserialize(dm.load(node, host, PREFS_DIR));
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
28 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
29
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
30 local function store_prefs(data, node, host)
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
31 dm.store(node, host, PREFS_DIR, st.preserialize(data));
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
32 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
33
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
34 local function os_time()
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
35 -- return tostring(os.time(os.date('!*t')));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
36 return datetime.datetime();
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
37 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
38
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
39 local function date_parse(s)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
40 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z");
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
41 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec});
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
42 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
43
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
44 local function store_msg(msg, node, host, isfrom)
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
45 local body = msg:child_with_name("body");
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
46 local thread = msg:child_with_name("thread");
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
47 local data = dm.list_load(node, host, ARCHIVE_DIR);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
48 local tag = (isfrom and "from") or "to";
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
49 if data then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
50 for k, v in ipairs(data) do
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
51 local collection = st.deserialize(v);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
52 if collection.attr["thread"] == thread:get_text() then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
53 -- TODO figure out secs
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
54 collection:tag(tag, {secs='1', utc=os_time()}):add_child(body);
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
55 local ver = tonumber(collection.attr["version"]) + 1;
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
56 collection.attr["version"] = tostring(ver);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
57 data[k] = collection;
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
58 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data));
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
59 return;
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
60 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
61 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
62 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
63 -- not found, create new collection
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
64 local utc = os_time();
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
65 local collection = st.stanza('chat', {with = isfrom and msg.attr.to or msg.attr.from, start=utc, thread=thread:get_text(), version='0'});
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
66 collection:tag(tag, {secs='0', utc=utc}):add_child(body);
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
67 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(collection));
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
68 end
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
69
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
70 local function save_result(collection)
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
71 local save = st.stanza('save', {xmlns='urn:xmpp:archive'});
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
72 local chat = st.stanza('chat', collection.attr);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
73 save:add_child(chat);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
74 return save;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
75 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
76
195
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
77 local function gen_uid(c)
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
78 return c.attr["start"] .. c.attr["with"];
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
79 end
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
80
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
81 ------------------------------------------------------------
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
82 -- Preferences
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
83 ------------------------------------------------------------
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
84 local function preferences_handler(event)
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
85 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
86 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
87 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
88 if stanza.attr.type == "get" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
89 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
90 if data then
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
91 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
92 else
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
93 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
94 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
95 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
96 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
97 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
98 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
99 origin.send(reply);
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
100 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
101 elseif stanza.attr.type == "set" then
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
102 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
103 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
104 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
105 data = st.stanza('pref', {xmlns='urn:xmpp:archive'});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
106 data:tag('default', {otr='concede', save='false'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
107 data:tag('method', {type='auto', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
108 data:tag('method', {type='local', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
109 data:tag('method', {type='manual', use='concede'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
110 data:tag('auto', {save='false'}):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
111 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
112 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
113 if not elem then return false end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
114 -- "default" | "item" | "session" | "method"
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
115 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
116 if elem.name == "default" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
117 local setting = data:child_with_name(elem.name)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
118 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
119 setting.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
120 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
121 -- setting.attr["unset"] = nil
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
122 elseif elem.name == "item" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
123 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
124 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
125 -- TODO bare JID or full JID?
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
126 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
127 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
128 child.attr[k] = v;
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 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
131 break;
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 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
134 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
135 data:tag(elem.name, elem.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
136 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
137 elseif elem.name == "session" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
138 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
139 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
140 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
141 for k, v in pairs(elem.attr) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
142 child.attr[k] = v;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
143 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
144 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
145 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
146 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
147 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
148 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
149 data:tag(elem.name, elem.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
150 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
151 elseif elem.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
152 local newpref = stanza.tags[1]; -- iq:pref
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
153 for _, e in ipairs(newpref.tags) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
154 -- if e.name ~= "method" then continue end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
155 local found = false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
156 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
157 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
158 child.attr["use"] = e.attr["use"];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
159 found = true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
160 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
161 end
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 if not found then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
164 data:tag(e.name, e.attr):up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
165 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
166 end
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 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
169 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
170 local user = bare_sessions[node.."@"..host];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
171 local push = st.iq({type="set"});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
172 push = push:tag('pref', {xmlns='urn:xmpp:archive'});
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
173 if elem.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
174 for child in data:children() do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
175 if child.name == "method" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
176 push:add_child(child);
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 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
179 else
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
180 push:add_child(elem);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
181 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
182 push = push:up();
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
183 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
184 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
185 push.attr.to = res.full_jid;
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
186 res.send(push);
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
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
189 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
190 return true;
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
191 end
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
192
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
193 local function itemremove_handler(event)
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
194 -- TODO use 'assert' to check incoming stanza?
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
195 -- or use pcall() to catch exceptions?
165
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].tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
201 if not elem or elem.name ~= "item" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
202 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
203 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
204 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
205 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
206 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
207 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
208 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
209 for i, child in ipairs(data) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
210 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
211 table.remove(data, i)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
212 break;
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 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
215 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
216 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
217 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
218 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
219
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
220 local function sessionremove_handler(event)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
221 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
222 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
223 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
224 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
225 local elem = stanza.tags[1].tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
226 if not elem or elem.name ~= "session" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
227 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
228 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
229 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
230 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
231 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
232 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
233 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
234 for i, child in ipairs(data) do
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
235 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
236 table.remove(data, i)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
237 break;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
238 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
239 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
240 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
241 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
242 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
243 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
244
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
245 local function auto_handler(event)
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
246 -- 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
247 local origin, stanza = event.origin, event.stanza;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
248 if stanza.attr.type ~= "set" then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
249 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
250 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
251 local elem = stanza.tags[1];
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
252 local node, host = origin.username, origin.host;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
253 local data = load_prefs(node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
254 if not data then
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
255 return false;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
256 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
257 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
258 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
259 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
260 end
165
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
261 store_prefs(data, node, host);
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
262 origin.send(st.reply(stanza));
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
263 return true;
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
264 end
fd8d76daad97 mod_archive: preference handling is done.
shinysky<shinysky1986(AT)gmail.com>
parents: 159
diff changeset
265
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
266 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
267 -- Manual Archiving
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
268 ------------------------------------------------------------
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
269 local function save_handler(event)
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
270 local origin, stanza = event.origin, event.stanza;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
271 if stanza.attr.type ~= "set" then
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
272 return false;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
273 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
274 local elem = stanza.tags[1].tags[1];
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
275 if not elem or elem.name ~= "chat" then
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
276 return false;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
277 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
278 local node, host = origin.username, origin.host;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
279 local data = dm.list_load(node, host, ARCHIVE_DIR);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
280 if data then
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
281 for k, v in ipairs(data) do
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
282 local collection = st.deserialize(v);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
283 if collection.attr["with"] == elem.attr["with"]
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
284 and collection.attr["start"] == elem.attr["start"] then
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
285 -- TODO check if there're duplicates
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
286 for newchild in elem:children() do
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
287 if type(newchild) == "table" then
188
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
288 if newchild.name == "from" or newchild.name == "to" then
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
289 collection:add_child(newchild);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
290 elseif newchild.name == "note" or newchild.name == "previous"
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
291 or newchild.name == "next" or newchild.name == "x" then
188
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
292 local found = false;
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
293 for i, c in ipairs(collection) do
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
294 if c.name == newchild.name then
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
295 found = true;
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
296 collection[i] = newchild;
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
297 break;
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
298 end
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
299 end
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
300 if not found then
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
301 collection:add_child(newchild);
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
302 end
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
303 end
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
304 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
305 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
306 local ver = tonumber(collection.attr["version"]) + 1;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
307 collection.attr["version"] = tostring(ver);
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
308 collection.attr["subject"] = elem.attr["subject"];
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
309 origin.send(st.reply(stanza):add_child(save_result(collection)));
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
310 data[k] = collection;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
311 dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data));
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
312 return true;
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
313 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
314 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
315 end
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
316 -- not found, create new collection
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
317 elem.attr["version"] = "0";
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
318 origin.send(st.reply(stanza):add_child(save_result(elem)));
188
5e8ea3733dc6 mod_archive: there can be only one note/previous/next/x element in a collection.
shinysky<shinysky1986(AT)gmail.com>
parents: 187
diff changeset
319 -- TODO check if elem is valid(?)
187
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
320 dm.list_append(node, host, ARCHIVE_DIR, st.preserialize(elem));
670c99e96c52 mod_archive: first commit for manual archiving, need polishing
shinysky<shinysky1986(AT)gmail.com>
parents: 182
diff changeset
321 -- TODO unsuccessful reply
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
322 return true;
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
323 end
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
324
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
325 ------------------------------------------------------------
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
326 -- Archive Management
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
327 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
328 local function filter_with(with, coll_with)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
329 return not with or coll_with:find(with);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
330 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
331
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
332 local function filter_start(start, coll_start)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
333 return not start or start <= coll_start;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
334 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
335
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
336 local function filter_end(endtime, coll_start)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
337 return not endtime or endtime >= coll_start;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
338 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
339
196
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
340 local function find_coll(resset, uid)
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
341 for i, c in ipairs(resset) do
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
342 if gen_uid(c) == uid then
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
343 return i;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
344 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
345 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
346 return nil;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
347 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
348
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
349 local function list_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
350 local origin, stanza = event.origin, event.stanza;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
351 local node, host = origin.username, origin.host;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
352 local data = dm.list_load(node, host, ARCHIVE_DIR);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
353 local elem = stanza.tags[1];
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
354 local resset = {}
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
355 if data then
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
356 for k, v in ipairs(data) do
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
357 local collection = st.deserialize(v);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
358 local res = filter_with(elem.attr["with"], collection.attr["with"]);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
359 res = res and filter_start(elem.attr["start"], collection.attr["start"]);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
360 res = res and filter_end(elem.attr["end"], collection.attr["start"]);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
361 if res then
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
362 table.insert(resset, collection);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
363 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
364 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
365 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
366 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'});
196
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
367 local count = table.getn(resset);
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
368 if count > 0 then
195
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
369 local max = elem.tags[1]:child_with_name("max");
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
370 if max then
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
371 max = tonumber(max:get_text());
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
372 else max = 100; end
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
373 local after = elem.tags[1]:child_with_name("after");
196
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
374 local before = elem.tags[1]:child_with_name("before");
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
375 local index = elem.tags[1]:child_with_name("index");
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
376 local s, e = 1, 1+max;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
377 if after then
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
378 after = after:get_text();
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
379 s = find_coll(resset, after);
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
380 if not s then -- not found
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
381 origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
382 return true;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
383 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
384 s = s + 1;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
385 e = s + max;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
386 elseif before then
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
387 before = before:get_text();
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
388 if not before or before == '' then -- the last page
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
389 e = count + 1;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
390 s = e - max;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
391 else
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
392 e = find_coll(resset, before);
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
393 if not e then -- not found
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
394 origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
395 return true;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
396 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
397 s = e - max;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
398 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
399 elseif index then
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
400 s = tonumber(index:get_text()) + 1; -- 0-based
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
401 e = s + max;
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
402 end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
403 if s < 1 then s = 1; end
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
404 if e > count + 1 then e = count + 1; end
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
405 -- Assuming result set is sorted.
196
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
406 for i = s, e-1 do
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
407 reply:add_child(st.stanza('chat', resset[i].attr));
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
408 end
195
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
409 local set = st.stanza('set', {xmlns='http://jabber.org/protocol/rsm'});
196
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
410 if s <= e-1 then
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
411 set:tag('first', {index=s-1}):text(gen_uid(resset[s])):up()
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
412 :tag('last'):text(gen_uid(resset[e-1])):up();
195
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
413 end
196
a1c2677257da mod_archive: XEP-0059 Result Set Management for Retrieving a List of Collections is DONE
shinysky<shinysky1986(AT)gmail.com>
parents: 195
diff changeset
414 set:tag('count'):text(tostring(count)):up();
195
4d9ed6374a1f mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
shinysky<shinysky1986(AT)gmail.com>
parents: 193
diff changeset
415 reply:add_child(set);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
416 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
417 origin.send(reply);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
418 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
419 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
420
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
421 local function retrieve_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
422 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
423 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
424 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
425
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
426 local function remove_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
427 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
428 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
429 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
430
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
431 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
432 -- Replication
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
433 ------------------------------------------------------------
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
434 local function modified_handler(event)
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
435 module:log("debug", "-- stanza:\n%s", tostring(event.stanza));
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
436 return true;
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
437 end
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
438
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
439 ------------------------------------------------------------
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
440 -- Message Handler
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
441 ------------------------------------------------------------
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
442 local function msg_handler(data)
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
443 -- TODO if not auto_archive_enabled then return nil;
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
444 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
445 local origin, stanza = data.origin, data.stanza;
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
446 local body = stanza:child_with_name("body");
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
447 local thread = stanza:child_with_name("thread");
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
448 module:log("debug", "-- msg:\n%s", tostring(stanza));
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
449 if body then
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
450 module:log("debug", "-- msg body:\n%s", tostring(body));
182
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
451 -- TODO mapping messages and conversations to collections if no thread
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
452 if thread then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
453 module:log("debug", "-- msg thread:\n%s", tostring(thread));
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
454 -- module:log("debug", "-- msg body text:\n%s", body:get_text());
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
455 local from_node, from_host = jid.split(stanza.attr.from);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
456 local to_node, to_host = jid.split(stanza.attr.to);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
457 -- FIXME only archive messages of users on this host
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
458 if from_host == "localhost" then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
459 store_msg(stanza, from_node, from_host, true);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
460 end
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
461 if to_host == "localhost" then
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
462 store_msg(stanza, to_node, to_host, false);
43d9e0944276 mod_archive: now auto archiving is almost done.
shinysky<shinysky1986(AT)gmail.com>
parents: 178
diff changeset
463 end
178
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
464 end
62f47a93b5b7 mod_archive: Now we can archive messages, even though not in organized way.
shinysky<shinysky1986(AT)gmail.com>
parents: 172
diff changeset
465 end
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
466 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
467 end
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
468
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
469 -- Preferences
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
470 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
471 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
472 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
473 module:hook("iq/self/urn:xmpp:archive:auto", auto_handler);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
474 -- Manual archiving
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
475 module:hook("iq/self/urn:xmpp:archive:save", save_handler);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
476 -- Archive management
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
477 module:hook("iq/self/urn:xmpp:archive:list", list_handler);
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
478 module:hook("iq/self/urn:xmpp:archive:retrieve", retrieve_handler);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
479 module:hook("iq/self/urn:xmpp:archive:remove", remove_handler);
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
480 -- Replication
159
9a37898f4f7c mod_archive: Added features: Determining Server Support & Determining Preferences
shinysky<shinysky1986(AT)gmail.com>
parents: 157
diff changeset
481 module:hook("iq/self/urn:xmpp:archive:modified", modified_handler);
157
86c28405c5da initial commitment of mod_archive
shinysky<shinysky1986(AT)gmail.com>
parents:
diff changeset
482
172
ac826882a8cf mod_archive: The element auto MAY include a 'scope' attribute; Added message hook.
shinysky<shinysky1986(AT)gmail.com>
parents: 165
diff changeset
483 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
484 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
485
193
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
486 -- FIXME sort collections
18a0e5c0bb62 mod_archive: Archive Management - Retrieving a List of Collections
shinysky<shinysky1986(AT)gmail.com>
parents: 188
diff changeset
487