Add. setopt method to share interface

This commit is contained in:
Alexey Melnichuk 2014-08-28 12:40:13 +05:00
parent 7babe0c872
commit 18c97805c1
4 changed files with 102 additions and 1 deletions

View File

@ -112,6 +112,32 @@ function free() end
end end
--- Curl error object
-- @type error
--
do
--- Get the number value of error.
--
-- @treturn number number of error (curl.E_XXX constants)
function no ()end
--- Get the error name.
--
-- @treturn string error name (e.g. "UNSUPPORTED_PROTOCOL", "BAD_OPTION")
function name ()end
--- Get the error description.
--
-- @treturn string error description (e.g. "Login denied")
function msg ()end
--- Get the full error description.
--
-- @treturn string string that contain name, message and number of error
function __tostring ()end
end
--- Easy curl object --- Easy curl object
-- @type easy -- @type easy
-- --

View File

@ -1 +1,17 @@
#ifndef OPT_ENTRY
# define OPT_ENTRY(a,b,c,d)
#endif
#ifndef FLG_ENTRY
# define FLG_ENTRY(a)
#endif
OPT_ENTRY(share, SHARE, LNG, 0 )
OPT_ENTRY(unshare, UNSHARE, LNG, 0 )
FLG_ENTRY(LOCK_DATA_COOKIE)
FLG_ENTRY(LOCK_DATA_DNS)
FLG_ENTRY(LOCK_DATA_SSL_SESSION)
#undef OPT_ENTRY
#undef FLG_ENTRY

View File

@ -1,5 +1,4 @@
#include "lcurl.h" #include "lcurl.h"
#include "lceasy.h"
#include "lcshare.h" #include "lcshare.h"
#include "lcerror.h" #include "lcerror.h"
#include "lcutils.h" #include "lcutils.h"
@ -36,9 +35,62 @@ static int lcurl_share_cleanup(lua_State *L){
return 0; return 0;
} }
//{ OPTIONS
static int lcurl_opt_set_long_(lua_State *L, int opt){
lcurl_share_t *p = lcurl_getshare(L);
long val; CURLSHcode code;
if(lua_isboolean(L, 2)) val = lua_toboolean(L, 2);
else{
luaL_argcheck(L, lua_type(L, 2) == LUA_TNUMBER, 2, "number or boolean expected");
val = luaL_checklong(L, 2);
}
code = curl_share_setopt(p->curl, opt, val);
if(code != CURLSHE_OK){
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_SHARE, code);
}
lua_settop(L, 1);
return 1;
}
#define LCURL_LNG_OPT(N, S) static int lcurl_share_set_##N(lua_State *L){\
return lcurl_opt_set_long_(L, CURLSHOPT_##N);\
}
#define OPT_ENTRY(L, N, T, S) LCURL_##T##_OPT(N, S)
#include "lcoptshare.h"
#undef OPT_ENTRY
#undef LCURL_LNG_OPT
//}
static int lcurl_share_setopt(lua_State *L){
lcurl_share_t *p = lcurl_getshare(L);
int opt = luaL_checklong(L, 2);
lua_remove(L, 2);
#define OPT_ENTRY(l, N, T, S) case CURLSHOPT_##N: return lcurl_share_set_##N(L);
switch(opt){
#include "lcoptshare.h"
}
#undef OPT_ENTRY
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_BAD_OPTION);
}
//} //}
static const struct luaL_Reg lcurl_share_methods[] = { static const struct luaL_Reg lcurl_share_methods[] = {
{"setopt", lcurl_share_setopt },
#define OPT_ENTRY(L, N, T, S) { "setopt_"#L, lcurl_share_set_##N },
#include "lcoptshare.h"
#undef OPT_ENTRY
{"close", lcurl_share_cleanup }, {"close", lcurl_share_cleanup },
{"__gc", lcurl_share_cleanup }, {"__gc", lcurl_share_cleanup },
@ -47,6 +99,12 @@ static const struct luaL_Reg lcurl_share_methods[] = {
static const lcurl_const_t lcurl_share_opt[] = { static const lcurl_const_t lcurl_share_opt[] = {
#define OPT_ENTRY(L, N, T, S) { "OPT_SHARE_"#N, CURLSHOPT_##N },
#define FLG_ENTRY(N) { #N, CURL_##N },
# include "lcoptshare.h"
#undef OPT_ENTRY
#undef FLG_ENTRY
{NULL, 0} {NULL, 0}
}; };

View File

@ -145,6 +145,7 @@ static int luaopen_lcurl_(lua_State *L, const struct luaL_Reg *func){
lua_pushvalue(L, -2); lcurl_hpost_initlib(L, 1); lua_pushvalue(L, -2); lcurl_hpost_initlib(L, 1);
lua_pushvalue(L, -2); lcurl_easy_initlib (L, 1); lua_pushvalue(L, -2); lcurl_easy_initlib (L, 1);
lua_pushvalue(L, -2); lcurl_multi_initlib(L, 1); lua_pushvalue(L, -2); lcurl_multi_initlib(L, 1);
lua_pushvalue(L, -2); lcurl_share_initlib(L, 1);
lua_pushvalue(L, -2); lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY); lua_pushvalue(L, -2); lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);