data-crl.lua /size: 2074 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
data-crl
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to luat-lib.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
-- this one is replaced by data-sch.lua --
10 11
local
gsub
=
string
.
gsub
12
local
exists
=
io
.
exists
13 14
local
resolvers
=
resolvers
15
local
finders
=
resolvers
.
finders
16
local
openers
=
resolvers
.
openers
17
local
loaders
=
resolvers
.
loaders
18 19
local
setfirstwritablefile
=
caches
.
setfirstwritablefile
20 21
local
curl
=
resolvers
.
curl
or
{
}
22
resolvers
.
curl
=
curl
23
local
cached
=
{
}
24 25
local
runner
=
sandbox
.
registerrunner
{
26
name
=
"
curl resolver
"
,
27
method
=
"
execute
"
,
28
program
=
"
curl
"
,
29
template
=
'
--silent --insecure --create-dirs --output "%cachename%" "%original%"
'
,
30
checkers
=
{
31
cachename
=
"
cache
"
,
32
original
=
"
url
"
,
33
}
34
}
35 36
local
function
runcurl
(
specification
)
37
local
original
=
specification
.
original
38
-- local scheme = specification.scheme
39
local
cleanname
=
gsub
(
original
,
"
[^%a%d%.]+
"
,
"
-
"
)
40
local
cachename
=
setfirstwritablefile
(
cleanname
,
"
curl
"
)
41
if
not
cached
[
original
]
then
42
if
not
exists
(
cachename
)
then
43
cached
[
original
]
=
cachename
44
runner
{
45
cachename
=
cachename
,
46
original
=
original
,
47
}
48
end
49
if
exists
(
cachename
)
then
50
cached
[
original
]
=
cachename
51
else
52
cached
[
original
]
=
"
"
53
end
54
end
55
return
cached
[
original
]
56
end
57 58
-- old code: we could be cleaner using specification (see schemes)
59 60
local
function
finder
(
specification
,
filetype
)
61
return
resolvers
.
methodhandler
(
"
finders
"
,
runcurl
(
specification
)
,
filetype
)
62
end
63 64
local
opener
=
openers
.
file
65
local
loader
=
loaders
.
file
66 67
local
function
install
(
scheme
)
68
finders
[
scheme
]
=
finder
69
openers
[
scheme
]
=
opener
70
loaders
[
scheme
]
=
loader
71
end
72 73
resolvers
.
curl
.
install
=
install
74 75
install
(
'
http
'
)
76
install
(
'
https
'
)
77
install
(
'
ftp
'
)
78