Simplify code of cURL module.
This commit is contained in:
parent
c2f8fc99f9
commit
e0dfc3a490
142
src/lua/cURL.lua
142
src/lua/cURL.lua
@ -32,33 +32,38 @@ local function wrap_setopt_flags(k, flags)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------
|
local function class(ctor)
|
||||||
local Easy = {} do
|
local C = {}
|
||||||
|
C.__index = function(self, k)
|
||||||
|
local fn = C[k]
|
||||||
|
|
||||||
Easy.__index = function(self, k)
|
if not fn and self._handle[k] then
|
||||||
local fn = Easy[k]
|
fn = wrap_function(k)
|
||||||
|
self[k] = fn
|
||||||
if not fn and self._handle[k] then
|
end
|
||||||
fn = wrap_function(k)
|
return fn
|
||||||
self[k] = fn
|
|
||||||
end
|
end
|
||||||
return fn
|
|
||||||
|
function C:new()
|
||||||
|
local h, err = ctor()
|
||||||
|
if not h then return nil, err end
|
||||||
|
|
||||||
|
local o = setmetatable({
|
||||||
|
_handle = h
|
||||||
|
}, self)
|
||||||
|
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:handle()
|
||||||
|
return self._handle
|
||||||
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
end
|
end
|
||||||
|
|
||||||
function Easy:new()
|
-------------------------------------------
|
||||||
local h, err = curl.easy()
|
local Easy = class(curl.easy) do
|
||||||
if not h then return nil, err end
|
|
||||||
|
|
||||||
local o = setmetatable({
|
|
||||||
_handle = h
|
|
||||||
}, self)
|
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Easy:handle()
|
|
||||||
return self._handle
|
|
||||||
end
|
|
||||||
|
|
||||||
local perform = wrap_function("perform")
|
local perform = wrap_function("perform")
|
||||||
local setopt_share = wrap_function("setopt_share")
|
local setopt_share = wrap_function("setopt_share")
|
||||||
@ -172,57 +177,31 @@ Easy.setopt_proxytype = wrap_setopt_flags("proxytype", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Easy.setopt_httpauth = wrap_setopt_flags("httpauth", {
|
Easy.setopt_httpauth = wrap_setopt_flags("httpauth", {
|
||||||
["NONE" ] = curl.AUTH_NONE;
|
["NONE" ] = curl.AUTH_NONE;
|
||||||
["BASIC" ] = curl.AUTH_BASIC;
|
["BASIC" ] = curl.AUTH_BASIC;
|
||||||
["DIGEST" ] = curl.AUTH_DIGEST;
|
["DIGEST" ] = curl.AUTH_DIGEST;
|
||||||
["GSSNEGOTIATE" ] = curl.AUTH_GSSNEGOTIATE;
|
["GSSNEGOTIATE" ] = curl.AUTH_GSSNEGOTIATE;
|
||||||
["NTLM" ] = curl.AUTH_NTLM;
|
["NTLM" ] = curl.AUTH_NTLM;
|
||||||
["DIGEST_IE" ] = curl.AUTH_DIGEST_IE;
|
["DIGEST_IE" ] = curl.AUTH_DIGEST_IE;
|
||||||
["NTLM_WB" ] = curl.AUTH_NTLM_WB;
|
["NTLM_WB" ] = curl.AUTH_NTLM_WB;
|
||||||
["ONLY" ] = curl.AUTH_ONLY;
|
["ONLY" ] = curl.AUTH_ONLY;
|
||||||
["ANY" ] = curl.AUTH_ANY;
|
["ANY" ] = curl.AUTH_ANY;
|
||||||
["ANYSAFE" ] = curl.AUTH_ANYSAFE;
|
["ANYSAFE" ] = curl.AUTH_ANYSAFE;
|
||||||
["SSH_ANY" ] = curl.SSH_AUTH_ANY;
|
["SSH_ANY" ] = curl.SSH_AUTH_ANY;
|
||||||
["SSH_NONE" ] = curl.SSH_AUTH_NONE;
|
["SSH_NONE" ] = curl.SSH_AUTH_NONE;
|
||||||
["SSH_PUBLICKEY" ] = curl.SSH_AUTH_PUBLICKEY;
|
["SSH_PUBLICKEY" ] = curl.SSH_AUTH_PUBLICKEY;
|
||||||
["SSH_PASSWORD" ] = curl.SSH_AUTH_PASSWORD;
|
["SSH_PASSWORD" ] = curl.SSH_AUTH_PASSWORD;
|
||||||
["SSH_HOST" ] = curl.SSH_AUTH_HOST;
|
["SSH_HOST" ] = curl.SSH_AUTH_HOST;
|
||||||
["SSH_KEYBOARD" ] = curl.SSH_AUTH_KEYBOARD;
|
["SSH_KEYBOARD" ] = curl.SSH_AUTH_KEYBOARD;
|
||||||
["SSH_AGENT" ] = curl.SSH_AUTH_AGENT;
|
["SSH_AGENT" ] = curl.SSH_AUTH_AGENT;
|
||||||
["SSH_DEFAULT" ] = curl.SSH_AUTH_DEFAULT;
|
["SSH_DEFAULT" ] = curl.SSH_AUTH_DEFAULT;
|
||||||
})
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
local Multi = {} do
|
local Multi = class(curl.multi) do
|
||||||
|
|
||||||
Multi.__index = function(self, k)
|
|
||||||
local fn = Multi[k]
|
|
||||||
|
|
||||||
if not fn and self._handle[k] then
|
|
||||||
fn = wrap_function(k)
|
|
||||||
self[k] = fn
|
|
||||||
end
|
|
||||||
return fn
|
|
||||||
end
|
|
||||||
|
|
||||||
function Multi:new()
|
|
||||||
local h, err = curl.multi()
|
|
||||||
if not h then return nil, err end
|
|
||||||
|
|
||||||
local o = setmetatable({
|
|
||||||
_handle = h;
|
|
||||||
_easy = {};
|
|
||||||
}, self)
|
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Multi:handle()
|
|
||||||
return self._handle
|
|
||||||
end
|
|
||||||
|
|
||||||
local perform = wrap_function("perform")
|
local perform = wrap_function("perform")
|
||||||
local add_handle = wrap_function("add_handle")
|
local add_handle = wrap_function("add_handle")
|
||||||
@ -309,32 +288,7 @@ end
|
|||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
local Share = {} do
|
local Share = class(curl.share) do
|
||||||
|
|
||||||
Share.__index = function(self, k)
|
|
||||||
local fn = Share[k]
|
|
||||||
|
|
||||||
if not fn and self._handle[k] then
|
|
||||||
fn = wrap_function(k)
|
|
||||||
self[k] = fn
|
|
||||||
end
|
|
||||||
return fn
|
|
||||||
end
|
|
||||||
|
|
||||||
function Share:new()
|
|
||||||
local h, err = curl.share()
|
|
||||||
if not h then return nil, err end
|
|
||||||
|
|
||||||
local o = setmetatable({
|
|
||||||
_handle = h
|
|
||||||
}, self)
|
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Share:handle()
|
|
||||||
return self._handle
|
|
||||||
end
|
|
||||||
|
|
||||||
Share.setopt_share = wrap_setopt_flags("share", {
|
Share.setopt_share = wrap_setopt_flags("share", {
|
||||||
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
|
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user