1if 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
10
11local libname = " curl "
12local libfile = " libcurl "
13
14local curllib = resolvers . libraries . validoptional ( libname )
15
16if not curllib then return end
17
18
19
20local next , type = next , type
21local lower , gsub = string . lower , string . gsub
22
23local 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
34 [ " chunkdata " ] = 201 ,
35
36 [ " closepolicy " ] = 72 ,
37 [ " closesocketdata " ] = 209 ,
38
39 [ " connectonly " ] = 141 ,
40 [ " connecttimeout " ] = 78 ,
41 [ " connecttimeoutms " ] = 156 ,
42
43
44
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
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
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
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
106 [ " ioctldata " ] = 131 ,
107
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
136 [ " password " ] = 174 ,
137 [ " port " ] = 3 ,
138 [ " post " ] = 47 ,
139
140
141
142 [ " postquote " ] = 39 ,
143 [ " postredir " ] = 161 ,
144 [ " prequote " ] = 93 ,
145 [ " private " ] = 103 ,
146 [ " progressdata " ] = 57 ,
147
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
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
178 [ " serverresponsetimeout " ] = 112 ,
179 [ " share " ] = 100 ,
180 [ " sockoptdata " ] = 149 ,
181
182 [ " socks5gssapinec " ] = 180 ,
183 [ " socks5gssapiservice " ] = 179 ,
184 [ " sshauthtypes " ] = 151 ,
185 [ " sshhostpublickeymd5 " ] = 162 ,
186 [ " sshkeydata " ] = 185 ,
187
188 [ " sshknownhosts " ] = 183 ,
189 [ " sshprivatekeyfile " ] = 153 ,
190 [ " sshpublickeyfile " ] = 152 ,
191 [ " sslcipherlist " ] = 83 ,
192 [ " sslctxdata " ] = 109 ,
193
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
234 [ " writeheader " ] = 29 ,
235 [ " writeinfo " ] = 40 ,
236 [ " xferinfodata " ] = 57 ,
237
238 [ " xoauth2bearer " ] = 220 ,
239}
240
241table . 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
246end )
247
248local curl_fetch = curllib . fetch
249local curl_escape = curllib . escape
250local curl_unescape = curllib . unescape
251local curl_getversion = curllib . getversion
252
253local report = logs . reporter ( libname )
254
255local 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 ( )
262end
263
264local 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
282end
283
284local 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
292
293
294package . loaded [ libname ] = curl
295
296return curl
297 |