annotate mod_muc_cache_media/mod_muc_cache_media.lua @ 6412:c25b98d42ed0

mod_muc_cache_media: Initial commit
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Sun, 22 Feb 2026 01:08:33 -0500
parents
children 48fca0914fcf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6412
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
1 local http = require "net.http"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
2 local resolver = require "net.resolvers.basic"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
3 local socket_url = require "socket.url"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
4 local st = require "util.stanza"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
5 local async = require "util.async"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
6 local promise = require "util.promise"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
7 local mime = require "mime"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
8 local lfs = require "lfs"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
9 local hashes = require "util.hashes"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
10 local jid = require "util.jid"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
11
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
12 local storage_path = module:get_option_string("muc_media_store_path", "/var/lib/prosody/muc-media")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
13 local public_base_url = module:get_option_string("muc_media_public_base", "https://cache.example.com")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
14 local max_size = module:get_option_number("muc_media_max_size", 10 * 1024 * 1024)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
15 local MAX_REDIRECTS = 5
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
16
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
17 lfs.mkdir(storage_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
18
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
19 local mime_extensions = {
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
20 ["image/jpeg"] = ".jpg",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
21 ["image/jpg"] = ".jpg",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
22 ["image/png"] = ".png",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
23 ["image/gif"] = ".gif",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
24 ["image/webp"] = ".webp",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
25 ["image/avif"] = ".avif",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
26 ["video/mp4"] = ".mp4",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
27 ["video/webm"] = ".webm",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
28 ["audio/mpeg"] = ".mp3",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
29 ["audio/ogg"] = ".ogg",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
30 }
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
31
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
32 local function extension_from_content_type(content_type)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
33 if not content_type then return ".bin" end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
34 local clean = content_type:match("^[^;]+")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
35 clean = clean and clean:lower()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
36 return mime_extensions[clean] or ".bin"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
37 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
38
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
39 local function ipv4_to_number(ip)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
40 local a,b,c,d = ip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
41 if not a then return nil end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
42 return (tonumber(a) << 24) | (tonumber(b) << 16) | (tonumber(c) << 8) | tonumber(d)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
43 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
44
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
45 local function ipv4_in_range(ip, base, mask) return (ip & mask) == base end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
46
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
47 local function is_private_ipv4(ip)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
48 local n = ipv4_to_number(ip)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
49 if not n then return false end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
50 if ipv4_in_range(n, 0x0A000000, 0xFF000000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
51 if ipv4_in_range(n, 0xAC100000, 0xFFF00000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
52 if ipv4_in_range(n, 0xC0A80000, 0xFFFF0000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
53 if ipv4_in_range(n, 0x7F000000, 0xFF000000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
54 if ipv4_in_range(n, 0xA9FE0000, 0xFFFF0000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
55 if ipv4_in_range(n, 0x00000000, 0xFF000000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
56 if ipv4_in_range(n, 0xE0000000, 0xF0000000) then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
57 return false
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
58 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
59
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
60 local function is_private_ipv6(ip)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
61 ip = ip:lower()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
62 if ip == "::1" then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
63 if ip:match("^fc") or ip:match("^fd") then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
64 if ip:match("^fe8") or ip:match("^fe9") or ip:match("^fea") or ip:match("^feb") then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
65 if ip == "::" then return true end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
66 return false
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
67 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
68
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
69 local function is_safe_host(host)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
70 if not host then return false end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
71 host = host:lower()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
72 if host == "localhost" then return false end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
73 local records = socket_dns.getaddrinfo(host)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
74 if not records then return false end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
75 for _, r in ipairs(records) do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
76 local ip = r.addr
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
77 if ip:match("^%d+%.%d+%.%d+%.%d+$") then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
78 if is_private_ipv4(ip) then return false end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
79 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
80 if is_private_ipv6(ip) then return false end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
81 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
82 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
83 return true
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
84 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
85
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
86 local function sha256_file(path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
87 local f = io.open(path,"rb")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
88 if not f then return nil end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
89 -- TODO: incremental hash
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
90 local digest = hashes.sha256(f:read("*all"))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
91 f:close()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
92 return mime.b64(digest)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
93 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
94
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
95 local function sha3_256_file(path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
96 local f = io.open(path,"rb")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
97 if not f then return nil end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
98 -- TODO: incremental hash
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
99 local digest = hashes.sha3_256(f:read("*all"))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
100 f:close()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
101 return mime.b64(digest)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
102 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
103
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
104 local function file_size(path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
105 return lfs.attributes(path,"size") or 0
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
106 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
107
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
108 local function filename_from_url(url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
109 return url:match(".*/([^/?]+)$") or "file"
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
110 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
111
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
112 local function resolve_redirects(url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
113 return promise.new(function(resolve, reject)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
114 local current_url = url
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
115 local redirects = 0
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
116
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
117 local function step()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
118 if redirects > MAX_REDIRECTS then reject("too many redirects"); return end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
119 http.request(current_url,{
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
120 method="HEAD";
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
121 redirect=false;
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
122 }, function(_, code, response)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
123 if not code or code == 0 then reject("request failed"); return end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
124 if code>=300 and code<400 and response.headers.location then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
125 redirects = redirects + 1
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
126 local location = response.headers.location
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
127 local parsed = socket_url.parse(current_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
128 if not location:match("^https?://") then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
129 location = parsed.scheme.."://"..parsed.host..(parsed.port and ":"..parsed.port or "")..location
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
130 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
131 current_url = location
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
132 step()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
133 return
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
134 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
135 resolve(current_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
136 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
137 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
138
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
139 step()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
140 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
141 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
142
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
143 local function all_safe(resolv, didnext, net, ip)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
144 if didnext and not ip then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
145 return promise.resolve(true)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
146 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
147
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
148 if not didnext or (net == "tcp4" and not is_private_ipv4(ip))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
149 or (net == "tcp6" and not is_private_ipv6(ip)) then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
150 return promise.new(function(resolve)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
151 resolv:next(function(net,ip,port,extra)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
152 all_safe(resolv, true, net, ip):next(resolve)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
153 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
154 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
155 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
156 return promise.resolve(false)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
157 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
158 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
159
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
160 local function secure_download_to_disk(original_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
161 return resolve_redirects(original_url):next(function(final_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
162 local parsed = socket_url.parse(final_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
163 if not parsed or (parsed.scheme~="http" and parsed.scheme~="https") then return promise.reject("invalid scheme") end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
164
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
165 return all_safe(resolver.new(parsed.host, 443, "tcp", { servername = parsed.host })):next(function(is_all_safe)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
166 if not is_all_safe then return promise.reject("no safe IP") end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
167
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
168 local tmpname = storage_path.."/tmp_"..tostring(math.random(1e9))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
169 local file = io.open(tmpname,"wb")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
170 if not file then return promise.reject("cannot open temp file") end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
171
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
172 return promise.new(function(resolve, reject)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
173 http.request(final_url,{
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
174 method = "GET";
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
175 redirect = false;
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
176 body_size_limit = max_size;
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
177 streaming_handler = function(r) return file, function() file:close(); file = nil end end;
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
178 }, function(_, code, response)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
179 if code ~= 200 then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
180 if file then file:close() end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
181 os.remove(tmpname)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
182 reject("bad status")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
183 return
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
184 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
185 if file then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
186 file:write(response.body)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
187 file:close()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
188 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
189 resolve({ tmpname, response.headers["content-type"] })
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
190 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
191 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
192 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
193 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
194 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
195
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
196 module:hook("muc-broadcast-message", function(event)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
197 local stanza = event.stanza
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
198 if stanza.attr.type ~= "groupchat" then return end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
199
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
200 local url_map = {}
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
201
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
202 -- Collect OOB URLs
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
203 for oob in stanza:childtags("x","jabber:x:oob") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
204 local url_tag = oob:get_child("url")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
205 if url_tag then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
206 url_map[url_tag:get_text()] = {}
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
207 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
208 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
209
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
210 -- Collect SIMS URLs
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
211 for ref in stanza:childtags("reference","urn:xmpp:reference:0") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
212 for ms in ref:childtags("media-sharing","urn:xmpp:sims:1") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
213 local sources = ms:get_child("sources")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
214 if sources then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
215 for sref in sources:childtags("reference","urn:xmpp:reference:0") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
216 local uri = sref.attr.uri
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
217 if uri then url_map[uri] = {} end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
218 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
219 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
220 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
221 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
222
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
223 -- Cache each URL
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
224 for original_url,_ in pairs(url_map) do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
225 local result, err = async.wait_for(secure_download_to_disk(original_url))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
226 local tmp_path, content_type = result and result[1], result and result[2]
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
227 if not err and tmp_path then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
228 local sha2 = sha256_file(tmp_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
229 local sha3 = sha3_256_file(tmp_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
230 local size = file_size(tmp_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
231 local name = filename_from_url(original_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
232 if sha2 then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
233 local ext = extension_from_content_type(content_type)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
234 local final_name = sha2:gsub("+","-"):gsub("/","_"):gsub("=","")..ext
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
235 local final_path = storage_path.."/"..final_name
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
236 if not lfs.attributes(final_path) then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
237 os.rename(tmp_path, final_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
238 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
239 os.remove(tmp_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
240 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
241 url_map[original_url] = { local_url = public_base_url.."/"..final_name, path=final_path, sha2=sha2, sha3=sha3, size=size, name=name, content_type=content_type }
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
242 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
243 os.remove(tmp_path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
244 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
245 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
246 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
247
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
248 -- Rewrite URLs and enrich/create SIMS
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
249 local original_body = stanza:get_child_text("body")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
250 for original_url,data in pairs(url_map) do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
251 if data.local_url then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
252
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
253 for oob in stanza:childtags("x","jabber:x:oob") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
254 local url_tag = oob:get_child("url")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
255 if url_tag and url_tag:get_text() == original_url then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
256 oob:maptags(function(el)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
257 if el.name == "url" then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
258 return st.stanza("url"):text(data.local_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
259 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
260 return el
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
261 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
262 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
263 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
264 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
265
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
266 stanza:maptags(function(el)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
267 if el.name == "body" then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
268 return st.stanza("body"):text(el:get_text():gsub(original_url, data.local_url))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
269 elseif el.name == "fallback" and el.attr.xmlns == "urn:xmpp:fallback:0" and (el.attr["for"] == "jabber:x:oob" or el.attr["for"] == "urn:xmpp:sims:1") then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
270 return el:maptags(function(subel)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
271 local s, e = string.find(original_body, original_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
272 if subel.name == "body" and math.abs(s - tonumber(subel.attr.start)) < 5 then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
273 subel.attr["end"] = tostring((tonumber(subel.attr["end"]) - #original_url) + #data.local_url)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
274 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
275 return subel
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
276 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
277 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
278 return el
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
279 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
280 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
281
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
282 local found = false
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
283 -- Enrich existing SIMS references
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
284 for ref in stanza:childtags("reference","urn:xmpp:reference:0") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
285 for ms in ref:childtags("media-sharing","urn:xmpp:sims:1") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
286 local sources = ms:get_child("sources")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
287 if sources then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
288 for sref in sources:childtags("reference","urn:xmpp:reference:0") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
289 if sref.attr.uri == original_url then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
290 found = true
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
291 sref.attr.uri = data.local_url
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
292 local file_tag = ms:get_child("file","urn:xmpp:jingle:apps:file-transfer:5")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
293 if not file_tag then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
294 file_tag = st.stanza("file",{ xmlns="urn:xmpp:jingle:apps:file-transfer:5" })
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
295 ms:add_child(file_tag)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
296 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
297 file_tag:maptags(function(el)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
298 if el.name == "size" or el.name == "hash" then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
299 return nil
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
300 else
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
301 return el
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
302 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
303 end)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
304 -- Fill name
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
305 if not file_tag:get_child("name") then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
306 file_tag:add_child(st.stanza("name"):text(data.name))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
307 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
308 -- Fill size
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
309 if not file_tag:get_child("size") then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
310 file_tag:add_child(st.stanza("size"):text(tostring(data.size)))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
311 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
312 -- Fill SHA256 hash
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
313 local sha2_tag = nil
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
314 for htag in file_tag:childtags("hash","urn:xmpp:hashes:2") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
315 if htag.attr.algo=="sha2-256" then sha2_tag = htag end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
316 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
317 if not sha2_tag then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
318 file_tag:add_child(st.stanza("hash",{ xmlns="urn:xmpp:hashes:2", algo="sha2-256" }):text(data.sha2))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
319 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
320 if data.sha3 then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
321 -- Fill SHA3-256 hash
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
322 local sha3_tag = nil
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
323 for htag in file_tag:childtags("hash","urn:xmpp:hashes:2") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
324 if htag.attr.algo=="sha3-256" then sha3_tag = htag end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
325 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
326 if not sha3_tag then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
327 file_tag:add_child(st.stanza("hash",{ xmlns="urn:xmpp:hashes:2", algo="sha3-256" }):text(data.sha3))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
328 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
329 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
330 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
331 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
332 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
333 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
334 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
335 -- Create new SIMS if none existed
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
336 if not found then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
337 local ref = st.stanza("reference",{ xmlns="urn:xmpp:reference:0", type="data" })
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
338 local ms = st.stanza("media-sharing",{ xmlns="urn:xmpp:sims:1" })
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
339 local file_tag = st.stanza("file",{ xmlns="urn:xmpp:jingle:apps:file-transfer:5" })
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
340 file_tag:add_child(st.stanza("media-type"):text(data.content_type or "application/octet-stream"))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
341 file_tag:add_child(st.stanza("name"):text(data.name))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
342 file_tag:add_child(st.stanza("size"):text(tostring(data.size)))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
343 file_tag:add_child(st.stanza("hash",{ xmlns="urn:xmpp:hashes:2", algo="sha2-256" }):text(data.sha2))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
344 if data.sha3 then file_tag:add_child(st.stanza("hash",{ xmlns="urn:xmpp:hashes:2", algo="sha3-256" }):text(data.sha3)) end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
345 ms:add_child(file_tag)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
346 local sources = st.stanza("sources")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
347 sources:add_child(st.stanza("reference",{ xmlns="urn:xmpp:reference:0", type="data", uri=data.local_url }))
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
348 ms:add_child(sources)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
349 ref:add_child(ms)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
350 stanza:add_child(ref)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
351 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
352 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
353 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
354 end, 100)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
355
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
356 local archive = module:open_store("muc_log", "archive");
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
357
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
358 module:hook("muc-moderate-message", function(event)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
359 local room = event.room
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
360 local stanza_id = event.stanza_id
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
361 if not room or not stanza_id then return end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
362
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
363 local room_node = jid.split(room.jid);
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
364
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
365 -- Find message by stanza_id
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
366 local query = {
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
367 with = "message<groupchat";
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
368 ids = { stanza_id };
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
369 }
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
370
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
371 local items, err = archive:find(room_node, query)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
372 if not items or err then return end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
373
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
374 for id, stanza, when in items do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
375 -- Extract SIMS hashes
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
376 for ref in stanza:childtags("reference", "urn:xmpp:reference:0") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
377 for ms in ref:childtags("media-sharing", "urn:xmpp:sims:1") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
378 local file_tag = ms:get_child("file", "urn:xmpp:jingle:apps:file-transfer:5")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
379 if file_tag then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
380 for hash_tag in file_tag:childtags("hash", "urn:xmpp:hashes:2") do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
381 if hash_tag.attr.algo == "sha2-256" then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
382 local sha2 = hash_tag:get_text()
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
383 if sha2 then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
384 local prefix = sha2:gsub("+","-"):gsub("/","_"):gsub("=","")
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
385 -- Files are named: hash + extension
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
386 for file in lfs.dir(storage_path) do
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
387 if file:match("^" .. prefix) then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
388 local path = storage_path .. "/" .. file
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
389 if lfs.attributes(path) then
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
390 os.remove(path)
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
391 module:log("debug",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
392 "Deleted cached media %s for moderated message %s",
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
393 file, stanza_id
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
394 )
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
395 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
396 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
397 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
398 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
399 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
400 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
401 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
402 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
403 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
404 end
c25b98d42ed0 mod_muc_cache_media: Initial commit
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
405 end)