Mercurial > prosody-modules
comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 2702:caabb980d1d8
Merge commit
| author | tmolitor <thilo@eightysoft.de> |
|---|---|
| date | Mon, 24 Apr 2017 20:57:23 +0200 |
| parents | 1b081c8fc1d9 |
| children | e5ce64aee4ac |
comparison
equal
deleted
inserted
replaced
| 2701:d96831e46b64 | 2702:caabb980d1d8 |
|---|---|
| 89 end | 89 end |
| 90 | 90 |
| 91 local stream_session = { notopen = true }; | 91 local stream_session = { notopen = true }; |
| 92 local stream_callbacks = { handlestanza = cb, stream_ns = "jabber:client", default_ns = "jabber:client" }; | 92 local stream_callbacks = { handlestanza = cb, stream_ns = "jabber:client", default_ns = "jabber:client" }; |
| 93 local stream = new_stream(stream_session, stream_callbacks); | 93 local stream = new_stream(stream_session, stream_callbacks); |
| 94 local dates = self:dates() or empty; | 94 local dates = self:dates(username) or empty; |
| 95 local function reset_stream() | 95 local function reset_stream() |
| 96 stream:reset(); | 96 stream:reset(); |
| 97 stream_session.notopen = true; | 97 stream_session.notopen = true; |
| 98 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag()); | 98 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag()); |
| 99 stream_session.notopen = nil; | 99 stream_session.notopen = nil; |
| 277 if typ ~= "archive" then return nil, "unsupported-store"; end | 277 if typ ~= "archive" then return nil, "unsupported-store"; end |
| 278 return setmetatable({ store = store }, archive_mt); | 278 return setmetatable({ store = store }, archive_mt); |
| 279 end | 279 end |
| 280 | 280 |
| 281 function provider:purge(username) | 281 function provider:purge(username) |
| 282 for store in dm.stores(username, module.host) do | 282 local encoded_username = dm.path_encode((username or "@") .. "@"); |
| 283 local dates = dm.list_load(username, module.host, store) or empty; | 283 local basepath = prosody.paths.data .. "/" .. dm.path_encode(module.host); |
| 284 if dates[1] and type(dates[1]) == "string" and dates[1]:match("^%d%d%d%d%-%d%d%-%d%d$") then | 284 for store in lfs.dir(basepath) do |
| 285 module:log("info", "Store %s looks like an archive store, emptying it...", store); | 285 store = basepath .. "/" .. dm.path_encode(store); |
| 286 provider:open(store, "archive"):delete(username); | 286 if lfs.attributes(store, "mode") == "directory" then |
| 287 end | 287 for file in lfs.dir(store) do |
| 288 end | 288 if file:sub(1, #encoded_username) == encoded_username then |
| 289 return true; | 289 if file:sub(-4) == ".xml" or file:sub(-5) == ".list" then |
| 290 os.remove(store .. "/" .. file); | |
| 291 end | |
| 292 end | |
| 293 end | |
| 294 return true; | |
| 295 end | |
| 296 end | |
| 290 end | 297 end |
| 291 | 298 |
| 292 module:provides("storage", provider); | 299 module:provides("storage", provider); |
