1if 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
10
11local gsub = string.gsub
12local exists = io.exists
13
14local resolvers = resolvers
15local finders = resolvers.finders
16local openers = resolvers.openers
17local loaders = resolvers.loaders
18
19local setfirstwritablefile = caches.setfirstwritablefile
20
21local curl = resolvers.curl or { }
22resolvers.curl = curl
23local cached = { }
24
25local 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
36local function runcurl(specification)
37 local original = specification.original
38
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]
56end
57
58
59
60local function finder(specification,filetype)
61 return resolvers.methodhandler("finders",runcurl(specification),filetype)
62end
63
64local opener = openers.file
65local loader = loaders.file
66
67local function install(scheme)
68 finders[scheme] = finder
69 openers[scheme] = opener
70 loaders[scheme] = loader
71end
72
73resolvers.curl.install = install
74
75install('http')
76install('https')
77install('ftp')
78 |