@@ -32,34 +32,39 @@ local function wrap_setopt_flags(k, flags)
3232 end
3333end
3434
35- ---- ---------------------------------------
36- local Easy = {} do
37-
38- Easy .__index = function (self , k )
39- local fn = Easy [k ]
40-
41- if not fn and self ._handle [k ] then
42- fn = wrap_function (k )
43- self [k ] = fn
35+ local function class (ctor )
36+ local C = {}
37+ C .__index = function (self , k )
38+ local fn = C [k ]
39+
40+ if not fn and self ._handle [k ] then
41+ fn = wrap_function (k )
42+ self [k ] = fn
43+ end
44+ return fn
4445 end
45- return fn
46- end
4746
48- function Easy :new ()
49- local h , err = curl . easy ()
50- if not h then return nil , err end
47+ function C :new ()
48+ local h , err = ctor ()
49+ if not h then return nil , err end
5150
52- local o = setmetatable ({
53- _handle = h
54- }, self )
51+ local o = setmetatable ({
52+ _handle = h
53+ }, self )
5554
56- return o
57- end
55+ return o
56+ end
57+
58+ function C :handle ()
59+ return self ._handle
60+ end
5861
59- function Easy :handle ()
60- return self ._handle
62+ return C
6163end
6264
65+ ---- ---------------------------------------
66+ local Easy = class (curl .easy ) do
67+
6368local perform = wrap_function (" perform" )
6469local setopt_share = wrap_function (" setopt_share" )
6570local setopt_readfunction = wrap_function (" setopt_readfunction" )
@@ -172,57 +177,31 @@ Easy.setopt_proxytype = wrap_setopt_flags("proxytype", {
172177})
173178
174179Easy .setopt_httpauth = wrap_setopt_flags (" httpauth" , {
175- [" NONE" ] = curl .AUTH_NONE ;
176- [" BASIC" ] = curl .AUTH_BASIC ;
177- [" DIGEST" ] = curl .AUTH_DIGEST ;
178- [" GSSNEGOTIATE" ] = curl .AUTH_GSSNEGOTIATE ;
179- [" NTLM" ] = curl .AUTH_NTLM ;
180- [" DIGEST_IE" ] = curl .AUTH_DIGEST_IE ;
181- [" NTLM_WB" ] = curl .AUTH_NTLM_WB ;
182- [" ONLY" ] = curl .AUTH_ONLY ;
183- [" ANY" ] = curl .AUTH_ANY ;
184- [" ANYSAFE" ] = curl .AUTH_ANYSAFE ;
185- [" SSH_ANY" ] = curl .SSH_AUTH_ANY ;
186- [" SSH_NONE" ] = curl .SSH_AUTH_NONE ;
187- [" SSH_PUBLICKEY" ] = curl .SSH_AUTH_PUBLICKEY ;
188- [" SSH_PASSWORD" ] = curl .SSH_AUTH_PASSWORD ;
189- [" SSH_HOST" ] = curl .SSH_AUTH_HOST ;
190- [" SSH_KEYBOARD" ] = curl .SSH_AUTH_KEYBOARD ;
191- [" SSH_AGENT" ] = curl .SSH_AUTH_AGENT ;
192- [" SSH_DEFAULT" ] = curl .SSH_AUTH_DEFAULT ;
180+ [" NONE" ] = curl .AUTH_NONE ;
181+ [" BASIC" ] = curl .AUTH_BASIC ;
182+ [" DIGEST" ] = curl .AUTH_DIGEST ;
183+ [" GSSNEGOTIATE" ] = curl .AUTH_GSSNEGOTIATE ;
184+ [" NTLM" ] = curl .AUTH_NTLM ;
185+ [" DIGEST_IE" ] = curl .AUTH_DIGEST_IE ;
186+ [" NTLM_WB" ] = curl .AUTH_NTLM_WB ;
187+ [" ONLY" ] = curl .AUTH_ONLY ;
188+ [" ANY" ] = curl .AUTH_ANY ;
189+ [" ANYSAFE" ] = curl .AUTH_ANYSAFE ;
190+ [" SSH_ANY" ] = curl .SSH_AUTH_ANY ;
191+ [" SSH_NONE" ] = curl .SSH_AUTH_NONE ;
192+ [" SSH_PUBLICKEY" ] = curl .SSH_AUTH_PUBLICKEY ;
193+ [" SSH_PASSWORD" ] = curl .SSH_AUTH_PASSWORD ;
194+ [" SSH_HOST" ] = curl .SSH_AUTH_HOST ;
195+ [" SSH_KEYBOARD" ] = curl .SSH_AUTH_KEYBOARD ;
196+ [" SSH_AGENT" ] = curl .SSH_AUTH_AGENT ;
197+ [" SSH_DEFAULT" ] = curl .SSH_AUTH_DEFAULT ;
193198})
194199
195200end
196201---- ---------------------------------------
197202
198203---- ---------------------------------------
199- local Multi = {} do
200-
201- Multi .__index = function (self , k )
202- local fn = Multi [k ]
203-
204- if not fn and self ._handle [k ] then
205- fn = wrap_function (k )
206- self [k ] = fn
207- end
208- return fn
209- end
210-
211- function Multi :new ()
212- local h , err = curl .multi ()
213- if not h then return nil , err end
214-
215- local o = setmetatable ({
216- _handle = h ;
217- _easy = {};
218- }, self )
219-
220- return o
221- end
222-
223- function Multi :handle ()
224- return self ._handle
225- end
204+ local Multi = class (curl .multi ) do
226205
227206local perform = wrap_function (" perform" )
228207local add_handle = wrap_function (" add_handle" )
309288---- ---------------------------------------
310289
311290---- ---------------------------------------
312- local Share = {} do
313-
314- Share .__index = function (self , k )
315- local fn = Share [k ]
316-
317- if not fn and self ._handle [k ] then
318- fn = wrap_function (k )
319- self [k ] = fn
320- end
321- return fn
322- end
323-
324- function Share :new ()
325- local h , err = curl .share ()
326- if not h then return nil , err end
327-
328- local o = setmetatable ({
329- _handle = h
330- }, self )
331-
332- return o
333- end
334-
335- function Share :handle ()
336- return self ._handle
337- end
291+ local Share = class (curl .share ) do
338292
339293Share .setopt_share = wrap_setopt_flags (" share" , {
340294 [ " COOKIE" ] = curl .LOCK_DATA_COOKIE ;
0 commit comments