libs-imp-curl.lua /size: 10 Kb    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
libs-imp-curl
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to luat-lib.mkxl
"
,
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
-- c:/data/develop/tex-context/tex/texmf-win64/bin/lib/luametatex/lua/copies/curl/libcurl.dll
10 11
local
libname
=
"
curl
"
12
local
libfile
=
"
libcurl
"
13 14
local
curllib
=
resolvers
.
libraries
.
validoptional
(
libname
)
15 16
if
not
curllib
then
return
end
17 18
-- We're good, so we continue.
19 20
local
next
,
type
=
next
,
type
21
local
lower
,
gsub
=
string
.
lower
,
string
.
gsub
22 23
local
mapping
=
{
24
[
"
acceptencoding
"
]
=
102
,
25
[
"
accepttimeoutms
"
]
=
212
,
26
[
"
addressscope
"
]
=
171
,
27
[
"
append
"
]
=
50
,
28
[
"
autoreferer
"
]
=
58
,
29
[
"
buffersize
"
]
=
98
,
30
[
"
cainfo
"
]
=
65
,
31
[
"
capath
"
]
=
97
,
32
[
"
certinfo
"
]
=
172
,
33
-- ["chunkbgnfunction"] = 198,
34
[
"
chunkdata
"
]
=
201
,
35
-- ["chunkendfunction"] = 199,
36
[
"
closepolicy
"
]
=
72
,
37
[
"
closesocketdata
"
]
=
209
,
38
-- ["closesocketfunction"] = 208,
39
[
"
connectonly
"
]
=
141
,
40
[
"
connecttimeout
"
]
=
78
,
41
[
"
connecttimeoutms
"
]
=
156
,
42
-- ["convfromnetworkfunction"] = 142,
43
-- ["convfromutf8function"] = 144,
44
-- ["convtonetworkfunction"] = 143,
45
[
"
cookie
"
]
=
22
,
46
[
"
cookiefile
"
]
=
31
,
47
[
"
cookiejar
"
]
=
82
,
48
[
"
cookielist
"
]
=
135
,
49
[
"
cookiesessionv
"
]
=
96
,
50
[
"
copypostfields
"
]
=
165
,
51
[
"
crlf
"
]
=
27
,
52
[
"
crlfile
"
]
=
169
,
53
[
"
customrequest
"
]
=
36
,
54
[
"
debugdata
"
]
=
95
,
55
-- ["debugfunction"] = 94,
56
[
"
dirlistonly
"
]
=
48
,
57
[
"
dnscachetimeout
"
]
=
92
,
58
[
"
dnsinterface
"
]
=
221
,
59
[
"
dnslocalip4
"
]
=
222
,
60
[
"
dnslocalip6
"
]
=
223
,
61
[
"
dnsservers
"
]
=
211
,
62
[
"
dnsuseglobalcache
"
]
=
91
,
63
[
"
egdsocket
"
]
=
77
,
64
[
"
errorbuffer
"
]
=
10
,
65
[
"
expect100timeoutms
"
]
=
227
,
66
[
"
failonerror
"
]
=
45
,
67
[
"
file
"
]
=
1
,
68
[
"
filetime
"
]
=
69
,
69
[
"
fnmatchdata
"
]
=
202
,
70
-- ["fnmatchfunction"] = 200,
71
[
"
followlocation
"
]
=
52
,
72
[
"
forbidreuse
"
]
=
75
,
73
[
"
freshconnect
"
]
=
74
,
74
[
"
ftpaccount
"
]
=
134
,
75
[
"
ftpalternativetouser
"
]
=
147
,
76
[
"
ftpcreatemissingdirs
"
]
=
110
,
77
[
"
ftpfilemethod
"
]
=
138
,
78
[
"
ftpresponsetimeout
"
]
=
112
,
79
[
"
ftpskippasvip
"
]
=
137
,
80
[
"
ftpsslccc
"
]
=
154
,
81
[
"
ftpuseeprt
"
]
=
106
,
82
[
"
ftpuseepsv
"
]
=
85
,
83
[
"
ftpusepret
"
]
=
188
,
84
[
"
ftpport
"
]
=
17
,
85
[
"
ftpsslauth
"
]
=
129
,
86
[
"
gssapidelegation
"
]
=
210
,
87
[
"
header
"
]
=
42
,
88
[
"
headerdata
"
]
=
29
,
89
-- ["headerfunction"] = 79,
90
[
"
http200aliases
"
]
=
104
,
91
[
"
httpcontentdecoding
"
]
=
158
,
92
[
"
httptransferdecoding
"
]
=
157
,
93
[
"
httpversion
"
]
=
84
,
94
[
"
httpauth
"
]
=
107
,
95
[
"
httpget
"
]
=
80
,
96
[
"
httpheader
"
]
=
23
,
97
[
"
httppost
"
]
=
24
,
98
[
"
httpproxytunnel
"
]
=
61
,
99
[
"
ignorecontentlength
"
]
=
136
,
100
[
"
infile
"
]
=
9
,
101
[
"
infilesize
"
]
=
14
,
102
[
"
infilesizelarge
"
]
=
115
,
103
[
"
interface
"
]
=
62
,
104
[
"
interleavedata
"
]
=
195
,
105
-- ["interleavefunction"] = 196,
106
[
"
ioctldata
"
]
=
131
,
107
-- ["ioctlfunction"] = 130,
108
[
"
ipresolve
"
]
=
113
,
109
[
"
issuercert
"
]
=
170
,
110
[
"
keypasswd
"
]
=
26
,
111
[
"
krblevel
"
]
=
63
,
112
[
"
localport
"
]
=
139
,
113
[
"
localportrange
"
]
=
140
,
114
[
"
loginoptions
"
]
=
224
,
115
[
"
lowspeedlimit
"
]
=
19
,
116
[
"
lowspeedtime
"
]
=
20
,
117
[
"
mailauth
"
]
=
217
,
118
[
"
mailfrom
"
]
=
186
,
119
[
"
mailrcpt
"
]
=
187
,
120
[
"
maxrecvspeedlarge
"
]
=
146
,
121
[
"
maxsendspeedlarge
"
]
=
145
,
122
[
"
maxconnects
"
]
=
71
,
123
[
"
maxfilesize
"
]
=
114
,
124
[
"
maxfilesizelarge
"
]
=
117
,
125
[
"
maxredirs
"
]
=
68
,
126
[
"
netrc
"
]
=
51
,
127
[
"
netrcfile
"
]
=
118
,
128
[
"
newdirectoryperms
"
]
=
160
,
129
[
"
newfileperms
"
]
=
159
,
130
[
"
nobody
"
]
=
44
,
131
[
"
noprogress
"
]
=
43
,
132
[
"
noproxy
"
]
=
177
,
133
[
"
nosignal
"
]
=
99
,
134
[
"
opensocketdata
"
]
=
164
,
135
-- ["opensocketfunction"] = 163,
136
[
"
password
"
]
=
174
,
137
[
"
port
"
]
=
3
,
138
[
"
post
"
]
=
47
,
139
-- ["postfields"] = 15,
140
-- ["postfieldsize"] = 60,
141
-- ["postfieldsizelarge"] = 120,
142
[
"
postquote
"
]
=
39
,
143
[
"
postredir
"
]
=
161
,
144
[
"
prequote
"
]
=
93
,
145
[
"
private
"
]
=
103
,
146
[
"
progressdata
"
]
=
57
,
147
-- ["progressfunction"] = 56,
148
[
"
protocols
"
]
=
181
,
149
[
"
proxy
"
]
=
4
,
150
[
"
proxytransfermode
"
]
=
166
,
151
[
"
proxyauth
"
]
=
111
,
152
[
"
proxypassword
"
]
=
176
,
153
[
"
proxyport
"
]
=
59
,
154
[
"
proxytype
"
]
=
101
,
155
[
"
proxyusername
"
]
=
175
,
156
[
"
proxyuserpwd
"
]
=
6
,
157
[
"
put
"
]
=
54
,
158
[
"
quote
"
]
=
28
,
159
[
"
randomfile
"
]
=
76
,
160
[
"
range
"
]
=
7
,
161
[
"
readdata
"
]
=
9
,
162
-- ["readfunction"] = 12,
163
[
"
redirprotocols
"
]
=
182
,
164
[
"
referer
"
]
=
16
,
165
[
"
resolve
"
]
=
203
,
166
[
"
resumefrom
"
]
=
21
,
167
[
"
resumefromlarge
"
]
=
116
,
168
[
"
rtspclientcseq
"
]
=
193
,
169
[
"
rtsprequest
"
]
=
189
,
170
[
"
rtspservercseq
"
]
=
194
,
171
[
"
rtspsessionid
"
]
=
190
,
172
[
"
rtspstreamuri
"
]
=
191
,
173
[
"
rtsptransport
"
]
=
192
,
174
[
"
rtspheader
"
]
=
23
,
175
[
"
saslir
"
]
=
218
,
176
[
"
seekdata
"
]
=
168
,
177
-- ["seekfunction"] = 167,
178
[
"
serverresponsetimeout
"
]
=
112
,
179
[
"
share
"
]
=
100
,
180
[
"
sockoptdata
"
]
=
149
,
181
-- ["sockoptfunction"] = 148,
182
[
"
socks5gssapinec
"
]
=
180
,
183
[
"
socks5gssapiservice
"
]
=
179
,
184
[
"
sshauthtypes
"
]
=
151
,
185
[
"
sshhostpublickeymd5
"
]
=
162
,
186
[
"
sshkeydata
"
]
=
185
,
187
-- ["sshkeyfunction"] = 184,
188
[
"
sshknownhosts
"
]
=
183
,
189
[
"
sshprivatekeyfile
"
]
=
153
,
190
[
"
sshpublickeyfile
"
]
=
152
,
191
[
"
sslcipherlist
"
]
=
83
,
192
[
"
sslctxdata
"
]
=
109
,
193
-- ["sslctxfunction"] = 108,
194
[
"
sslenablealpn
"
]
=
226
,
195
[
"
sslenablenpn
"
]
=
225
,
196
[
"
ssloptions
"
]
=
216
,
197
[
"
sslsessionidcache
"
]
=
150
,
198
[
"
sslverifyhost
"
]
=
81
,
199
[
"
sslverifypeer
"
]
=
64
,
200
[
"
sslcert
"
]
=
25
,
201
[
"
sslcerttype
"
]
=
86
,
202
[
"
sslengine
"
]
=
89
,
203
[
"
sslenginedefault
"
]
=
90
,
204
[
"
sslkey
"
]
=
87
,
205
[
"
sslkeytype
"
]
=
88
,
206
[
"
sslversion
"
]
=
32
,
207
[
"
stderr
"
]
=
37
,
208
[
"
tcpkeepalive
"
]
=
213
,
209
[
"
tcpkeepidle
"
]
=
214
,
210
[
"
tcpkeepintvl
"
]
=
215
,
211
[
"
tcpnodelay
"
]
=
121
,
212
[
"
telnetoptions
"
]
=
70
,
213
[
"
tftpblksize
"
]
=
178
,
214
[
"
timecondition
"
]
=
33
,
215
[
"
timeout
"
]
=
13
,
216
[
"
timeoutms
"
]
=
155
,
217
[
"
timevalue
"
]
=
34
,
218
[
"
tlsauthpassword
"
]
=
205
,
219
[
"
tlsauthtype
"
]
=
206
,
220
[
"
tlsauthusername
"
]
=
204
,
221
[
"
transferencoding
"
]
=
207
,
222
[
"
transfertext
"
]
=
53
,
223
[
"
unrestrictedauth
"
]
=
105
,
224
[
"
upload
"
]
=
46
,
225
[
"
url
"
]
=
2
,
226
[
"
usessl
"
]
=
119
,
227
[
"
useragent
"
]
=
18
,
228
[
"
username
"
]
=
173
,
229
[
"
userpwd
"
]
=
5
,
230
[
"
verbose
"
]
=
41
,
231
[
"
wildcardmatch
"
]
=
197
,
232
[
"
writedata
"
]
=
1
,
233
-- ["writefunction"] = 11,
234
[
"
writeheader
"
]
=
29
,
235
[
"
writeinfo
"
]
=
40
,
236
[
"
xferinfodata
"
]
=
57
,
237
-- ["xferinfofunction"] = 219,
238
[
"
xoauth2bearer
"
]
=
220
,
239
}
240 241
table
.
setmetatableindex
(
mapping
,
function
(
t
,
k
)
242
local
s
=
gsub
(
lower
(
k
)
,
"
[^a-z0-9]
"
,
"
"
)
243
local
v
=
rawget
(
t
,
s
)
or
false
244
t
[
k
]
=
v
245
return
v
246
end
)
247 248
local
curl_fetch
=
curllib
.
fetch
249
local
curl_escape
=
curllib
.
escape
250
local
curl_unescape
=
curllib
.
unescape
251
local
curl_getversion
=
curllib
.
getversion
252 253
local
report
=
logs
.
reporter
(
libname
)
254 255
local
function
okay
(
)
256
if
resolvers
.
libraries
.
optionalloaded
(
libname
,
libfile
)
then
257
okay
=
function
(
)
return
true
end
258
else
259
okay
=
function
(
)
return
false
end
260
end
261
return
okay
(
)
262
end
263 264
local
function
fetch
(
options
)
265
if
okay
(
)
then
266
local
t
=
type
(
options
)
267
if
t
=
=
"
table
"
then
268
local
o
=
{
}
269
for
name
,
value
in
next
,
options
do
270
local
index
=
mapping
[
name
]
271
if
index
then
272
o
[
index
]
=
value
273
end
274
end
275
return
curl_fetch
(
o
)
276
elseif
t
=
=
"
string
"
then
277
return
curl_fetch
{
[
mapping
.
url
]
=
options
}
278
else
279
report
(
"
invalid argument
"
)
280
end
281
end
282
end
283 284
local
curl
=
{
285
getversion
=
function
(
)
return
okay
(
)
and
curl_getversion
(
)
end
,
286
escape
=
function
(
s
)
return
okay
(
)
and
curl_escape
(
s
)
end
,
287
unescape
=
function
(
s
)
return
okay
(
)
and
curl_unescape
(
s
)
end
,
288
fetch
=
fetch
,
289
}
290 291
-- inspect(curl.fetch("http://www.pragma-ade.com/index.html"))
292
-- inspect(curl.fetch { url = "http://www.pragma-ade.com/index.html" })
293 294
package
.
loaded
[
libname
]
=
curl
295 296
return
curl
297