Mercurial > prosody-modules
annotate mod_storage_muc_log/mod_storage_muc_log.lua @ 6257:fa45ae704b79
mod_cloud_notify: Update Readme
diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md
--- a/mod_cloud_notify/README.md
+++ b/mod_cloud_notify/README.md
@@ -1,109 +1,106 @@
----
-labels:
-- 'Stage-Beta'
-summary: 'XEP-0357: Cloud push notifications'
----
+# Introduction
-Introduction
-============
+This module enables support for sending "push notifications" to clients
+that need it, typically those running on certain mobile devices.
-This module enables support for sending "push notifications" to clients that
-need it, typically those running on certain mobile devices.
+As well as this module, your client must support push notifications (the
+apps that need it generally do, of course) and the app developer's push
+gateway must be reachable from your Prosody server (this happens over a
+normal XMPP server-to-server 's2s' connection).
-As well as this module, your client must support push notifications (the apps
-that need it generally do, of course) and the app developer's push gateway
-must be reachable from your Prosody server (this happens over a normal XMPP
-server-to-server 's2s' connection).
-
-Details
-=======
+# Details
Some platforms, notably Apple's iOS and many versions of Android, impose
-limits that prevent applications from running or accessing the network in the
-background. This makes it difficult or impossible for an XMPP application to
-remain reliably connected to a server to receive messages.
-
-In order for messaging and other apps to receive notifications, the OS vendors
-run proprietary servers that their OS maintains a permanent connection to in
-the background. Then they provide APIs to application developers that allow
-sending notifications to specific devices via those servers.
+limits that prevent applications from running or accessing the network
+in the background. This makes it difficult or impossible for an XMPP
+application to remain reliably connected to a server to receive
+messages.
-When you connect to your server with an app that requires push notifications,
-it will use this module to set up a "push registration". When you receive
-a message but your device is not connected to the server, this module will
-generate a notification and send it to the push gateway operated by your
-application's developers). Their gateway will then connect to your device's
-OS vendor and ask them to forward the notification to your device. When your
-device receives the notification, it will display it or wake up the app so it
-can connect to XMPP and receive any pending messages.
+In order for messaging and other apps to receive notifications, the OS
+vendors run proprietary servers that their OS maintains a permanent
+connection to in the background. Then they provide APIs to application
+developers that allow sending notifications to specific devices via
+those servers.
-This protocol is described for developers in [XEP-0357: Push Notifications].
+When you connect to your server with an app that requires push
+notifications, it will use this module to set up a "push registration".
+When you receive a message but your device is not connected to the
+server, this module will generate a notification and send it to the push
+gateway operated by your application's developers). Their gateway will
+then connect to your device's OS vendor and ask them to forward the
+notification to your device. When your device receives the notification,
+it will display it or wake up the app so it can connect to XMPP and
+receive any pending messages.
-For this module to work reliably, you must have [mod_smacks], [mod_mam] and
-[mod_carbons] also enabled on your server.
+This protocol is described for developers in \[XEP-0357: Push
+Notifications\].
+
+For this module to work reliably, you must have \[mod_smacks\],
+\[mod_mam\] and \[mod_carbons\] also enabled on your server.
-Some clients, notably Siskin and Snikket iOS need some additional extensions
-that are not currently defined in a standard XEP. To support these clients,
-see [mod_cloud_notify_extensions].
+Some clients, notably Siskin and Snikket iOS need some additional
+extensions that are not currently defined in a standard XEP. To support
+these clients, see \[mod_cloud_notify_extensions\].
-Configuration
-=============
+# Configuration
- Option Default Description
- ------------------------------------ ----------------- -------------------------------------------------------------------------------------------------------------------
- `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty
- `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled
- `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached)
- `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours)
- `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended.
- `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended.
+ Option Default Description
+ -------------------------------------- ---------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty
+ `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled
+ `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached)
+ `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours)
+ `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended.
+ `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended.
-(\*) There are privacy implications for enabling these options.
+(\*) There are privacy implications for enabling these options.[^1]
-Internal design notes
-=====================
+# Internal design notes
-App servers are notified about offline messages, messages stored by [mod_mam]
-or messages waiting in the smacks queue.
-The business rules outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2].
+App servers are notified about offline messages, messages stored by
+\[mod_mam\] or messages waiting in the smacks queue. The business rules
+outlined
+[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html)
+are all honored[^2].
-To cooperate with [mod_smacks] this module consumes some events:
-`smacks-ack-delayed`, `smacks-hibernation-start` and `smacks-hibernation-end`.
-These events allow this module to send out notifications for messages received
-while the session is hibernated by [mod_smacks] or even when smacks
-acknowledgements for messages are delayed by a certain amount of seconds
-configurable with the [mod_smacks] setting `smacks_max_ack_delay`.
+To cooperate with \[mod_smacks\] this module consumes some events:
+`smacks-ack-delayed`, `smacks-hibernation-start` and
+`smacks-hibernation-end`. These events allow this module to send out
+notifications for messages received while the session is hibernated by
+\[mod_smacks\] or even when smacks acknowledgements for messages are
+delayed by a certain amount of seconds configurable with the
+\[mod_smacks\] setting `smacks_max_ack_delay`.
-The `smacks_max_ack_delay` setting allows to send out notifications to clients
-which aren't already in smacks hibernation state (because the read timeout or
-connection close didn't already happen) but also aren't responding to acknowledgement
-request in a timely manner. This setting thus allows conversations to be smoother
-under such circumstances.
+The `smacks_max_ack_delay` setting allows to send out notifications to
+clients which aren't already in smacks hibernation state (because the
+read timeout or connection close didn't already happen) but also aren't
+responding to acknowledgement request in a timely manner. This setting
+thus allows conversations to be smoother under such circumstances.
-The new event `cloud-notify-ping` can be used by any module to send out a cloud
-notification to either all registered endpoints for the given user or only the endpoints
-given in the event data.
+The new event `cloud-notify-ping` can be used by any module to send out
+a cloud notification to either all registered endpoints for the given
+user or only the endpoints given in the event data.
-The config setting `push_notification_important_body` can be used to specify an alternative
-body text to send to the remote pubsub node if the stanza is encrypted or has a body.
-This way the real contents of the message aren't revealed to the push appserver but it
-can still see that the push is important.
-This is used by Chatsecure on iOS to send out high priority pushes in those cases for example.
+The config setting `push_notification_important_body` can be used to
+specify an alternative body text to send to the remote pubsub node if
+the stanza is encrypted or has a body. This way the real contents of the
+message aren't revealed to the push appserver but it can still see that
+the push is important. This is used by Chatsecure on iOS to send out
+high priority pushes in those cases for example.
-Compatibility
-=============
-
-**Note:** This module should be used with Lua 5.2 and higher. Using it with
-Lua 5.1 may cause push notifications to not be sent to some clients.
+# Compatibility
------- -----------------------------------------------------------------------------
- trunk Works
- 0.12 Works
- 0.11 Works
- 0.10 Works
- 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua)
------- -----------------------------------------------------------------------------
+**Note:** This module should be used with Lua 5.2 and higher. Using it
+with Lua 5.1 may cause push notifications to not be sent to some
+clients.
+ ------- -----------------------------------------------------------------
+ trunk Works as of 25-06-13
+ 13 Works
+ 0.12 Works
+ ------- -----------------------------------------------------------------
-[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service
-[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown)
+[^1]: The service which is expected to forward notifications to
+ something like Google Cloud Messaging or Apple Notification Service
+
+[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
| author | Menel <menel@snikket.de> |
|---|---|
| date | Fri, 13 Jun 2025 10:36:52 +0200 |
| parents | 85b849d5ec88 |
| children |
| rev | line source |
|---|---|
|
2821
e8f0acfdccca
mod_storage_muc_log: Ignore setting the global 'open', it's part of the storage API
Kim Alvefur <zash@zash.se>
parents:
2820
diff
changeset
|
1 -- luacheck: ignore 212/self 431/err 131/open |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local datamanager = require"core.storagemanager".olddm; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local xml_parse = require"util.xml".parse; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local data_load, data_store = datamanager.load, datamanager.store; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local datastore = "muc_log"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local datetime = require"util.datetime" |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local lfs = require"lfs"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local os_date = os.date; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
|
1568
c357039c1ab1
mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents:
1566
diff
changeset
|
11 local timef, datef = "!%H:%M:%S", "!%y%m%d"; |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local host = module.host; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local driver = {}; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local driver_mt = { __index = driver }; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 do |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 -- Sanity check |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 -- Fun fact: 09:00 and 21:00 en_HK are both "09:00:00 UTC" |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local t = os_date("!*t"); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 t.hour = 9; |
|
1568
c357039c1ab1
mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents:
1566
diff
changeset
|
22 local am = os_date("!%X", os.time(t)); |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 t.hour = 21; |
|
1568
c357039c1ab1
mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents:
1566
diff
changeset
|
24 local pm = os_date("!%X", os.time(t)); |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 if am == pm then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 module:log("warn", "Timestamps in AM and PM are identical in your locale, expect timestamps to be wrong"); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end |
| 1569 | 28 if os_date("!%X", os.time(t)) ~= os_date(timef, os.time(t)) then |
|
1568
c357039c1ab1
mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents:
1566
diff
changeset
|
29 module:log("warn", "Timestamp format differ from what mod_muc_log used, this module may not work correctly"); |
|
c357039c1ab1
mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents:
1566
diff
changeset
|
30 end |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 local function parse_silly(date, time) |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 local year, month, day = date:match("^(%d%d)(%d%d)(%d%d)"); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 year = "20"..year; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 -- year = (year < "70" and "20" or "19") .. year; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 local hour, min, sec = time:match("(%d%d)%D+(%d%d)%D+(%d%d)"); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 if hour == "12" and time:find("[Aa][Mm]") then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 hour = "00"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 elseif hour < "12" and time:find("[Pp][Mm]") then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 hour = tostring(tonumber(hour) % 12 + 12); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 return datetime.parse(("%s-%s-%sT%s:%s:%sZ"):format(year, month, day, hour or "00", min or "00", sec or "00")); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 local function st_with(tag) |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 local with = tag.attr.type; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 return with and tag.name .. "<" .. with or tag.name; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 |
|
2356
49a01b78b45f
mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
1760
diff
changeset
|
51 function driver:append(node, key, stanza, when, with) -- luacheck: ignore 212/key |
|
49a01b78b45f
mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
1760
diff
changeset
|
52 -- luacheck: ignore 311/with |
|
49a01b78b45f
mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
1760
diff
changeset
|
53 -- 'with' doesn't exist in the original mod_muc_log, so gets derived here |
|
1753
54c8a0cb2996
mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents:
1569
diff
changeset
|
54 if type(when) ~= "number" then |
|
1760
e72f9eac51c8
mod_storage_(various): Order swapping in 54c8a0cb2996 was backwards
Kim Alvefur <zash@zash.se>
parents:
1759
diff
changeset
|
55 when, with, stanza = stanza, when, with; |
|
1753
54c8a0cb2996
mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents:
1569
diff
changeset
|
56 end |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 local today = os_date(datef, when); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 local now = os_date(timef, when); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 local data = data_load(node, host, datastore .. "/" .. today) or {}; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 data[#data + 1] = "<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 datamanager.getpath(node, host, datastore, nil, true); -- create the datastore dir |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 local ok, err = data_store(node, host, datastore .. "/" .. today, data); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 if not ok then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 return ok, err; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 return today .. "_" .. #data; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 |
|
2357
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
69 function driver:dates(node) |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 local path = datamanager.getpath(node, host, datastore):match("(.*)/"); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 local ok, iter, state, var = pcall(lfs.dir, path); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 if not ok then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 module:log("warn", iter); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 return nil, iter; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 local dates, i = {}, 1; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 for dir in iter, state, var do |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 if lfs.attributes(datamanager.getpath(node, host, datastore .. "/" .. dir), "mode") == "file" then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 dates[i], i = dir, i+1; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 end |
|
2825
d0c4ecabf3f5
mod_storage_muc_log: Signal store being empty correctly
Kim Alvefur <zash@zash.se>
parents:
2821
diff
changeset
|
84 if dates[1] == nil then return nil end |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 table.sort(dates); |
|
2357
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
86 return dates; |
|
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
87 end |
|
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
88 |
|
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
89 function driver:find(node, query) |
|
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
90 local dates, err = self:dates(node); |
|
093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents:
2356
diff
changeset
|
91 if not dates then return dates, err; end |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 return coroutine.wrap(function () |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 local start_date = query and query.start and os_date(datef, query.start) or dates[1]; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates]; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 local start_time = query and query.start and os_date(timef, query.start) or dates[1]; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 local end_time = query and query["end"] and os_date(timef, query["end"]) or dates[#dates]; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 local query_with = query and query.with; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 local query_limit = query and query.limit; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 local seek_once = query and query.after; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 local today, time, data, err, item; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 local inner_start, inner_stop, inner_step; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 local outer_start, outer_stop, outer_step = 1, #dates, 1; |
|
2820
f3a09a559201
mod_storage_muc_log: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2357
diff
changeset
|
105 if query and query.reverse then |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 outer_start, outer_stop, outer_step = outer_stop, outer_start, -outer_step; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 seek_once = query.before; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 if seek_once then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 end_date = seek_once:match"^(%d+)_%d"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 elseif seek_once then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 start_date = seek_once:match"^(%d+)_%d"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 local matches = 0; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 for i = outer_start, outer_stop, outer_step do |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 today = dates[i]; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 if today >= start_date and today <= end_date then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 data, err = data_load(node, host, datastore .. "/" .. today); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 if data then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 inner_start, inner_stop, inner_step = 1, #data, 1; |
|
2820
f3a09a559201
mod_storage_muc_log: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2357
diff
changeset
|
121 if query and query.reverse then |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 inner_start, inner_stop, inner_step = inner_stop, inner_start, -inner_step; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 if seek_once then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 inner_start = tonumber(seek_once:match("_(%d+)$")); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 inner_start = inner_start + (query and query.reverse and -1 or 1); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 seek_once = nil; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 end |
|
2356
49a01b78b45f
mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
1760
diff
changeset
|
129 for i = inner_start, inner_stop, inner_step do -- luacheck: ignore 423/i |
|
49a01b78b45f
mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
1760
diff
changeset
|
130 item, err = data[i], nil; |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 if item then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 item, err = xml_parse(item); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 if item then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 time = item.attr.time; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 item = item.tags[1]; |
|
3468
228e59bee8ad
mod_storage_muc_log: Return 'with' property for items (API conformance)
Kim Alvefur <zash@zash.se>
parents:
2825
diff
changeset
|
137 local with = st_with(item); |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 if (today >= start_date or time >= start_time) and |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 (today <= end_date or time <= end_time) and |
|
3468
228e59bee8ad
mod_storage_muc_log: Return 'with' property for items (API conformance)
Kim Alvefur <zash@zash.se>
parents:
2825
diff
changeset
|
140 (not query_with or query_with == with) and |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 item:get_child_text("alreadyJoined") ~= "true" then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 matches = matches + 1; |
|
3468
228e59bee8ad
mod_storage_muc_log: Return 'with' property for items (API conformance)
Kim Alvefur <zash@zash.se>
parents:
2825
diff
changeset
|
143 coroutine.yield(today.."_"..i, item, parse_silly(today, time), with); |
|
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 if query_limit and matches >= query_limit then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 return; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 elseif err then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 module:log("warn", err); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 elseif err then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 module:log("warn", err); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 end); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 function open(_, store, typ) |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 if typ ~= "archive" then |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 return nil, "unsupported-store"; |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 return setmetatable({ store = store, type = typ }, driver_mt); |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
165 end |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
166 |
|
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
167 module:provides "storage"; |
