Add. reset method.

This commit is contained in:
Alexey Melnichuk 2014-08-27 11:08:13 +05:00
parent 430ebb927e
commit bb7a6c3571
4 changed files with 26 additions and 4 deletions

View File

@ -129,6 +129,11 @@ function easy:escape() end
-- @return[1] decoded url
function easy:unescape() end
--- Re-initializes all options previously set.
--
-- @treturn easy self
function easy:reset() end
--- End easy session
--
function easy:close() end

View File

@ -83,8 +83,7 @@ static int lcurl_easy_cleanup(lua_State *L){
}
if(p->storage != LUA_NOREF){
lcurl_storage_free(L, p->storage);
p->storage = LUA_NOREF;
p->storage = lcurl_storage_free(L, p->storage);
}
return 0;
@ -153,6 +152,22 @@ static int lcurl_easy_unescape(lua_State *L){
return 1;
}
static int lcurl_easy_reset(lua_State *L){
lcurl_easy_t *p = lcurl_geteasy(L);
CURLcode code = curl_easy_init(p->curl);
if(code != CURLE_OK){
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, code);
}
lua_settop(L, 1);
if(p->storage != LUA_NOREF){
lcurl_storage_free(L, p->storage);
p->storage = lcurl_storage_init(L);
}
return 1;
}
//{ OPTIONS
static int lcurl_opt_set_long_(lua_State *L, int opt){
@ -682,6 +697,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
#include "lcinfoeasy.h"
#undef OPT_ENTRY
{ "reset", lcurl_easy_reset },
{ "setopt", lcurl_easy_setopt },
{ "getinfo", lcurl_easy_getinfo },
{ "escape", lcurl_easy_escape },

View File

@ -44,7 +44,7 @@ struct curl_slist* lcurl_storage_remove_slist(lua_State *L, int storage, int idx
return list;
}
void lcurl_storage_free(lua_State *L, int storage){
int lcurl_storage_free(lua_State *L, int storage){
lua_rawgeti(L, LCURL_LUA_REGISTRY, storage);
lua_rawgeti(L, -1, 1); // list storage
if(lua_istable(L, -1)){
@ -59,6 +59,7 @@ void lcurl_storage_free(lua_State *L, int storage){
}
lua_pop(L, 1);
luaL_unref(L, LCURL_LUA_REGISTRY, storage);
return LUA_NOREF;
}
struct curl_slist* lcurl_util_array_to_slist(lua_State *L, int t){

View File

@ -24,7 +24,7 @@ int lcurl_storage_preserve_slist(lua_State *L, int storage, struct curl_slist *
struct curl_slist* lcurl_storage_remove_slist(lua_State *L, int storage, int idx);
void lcurl_storage_free(lua_State *L, int storage);
int lcurl_storage_free(lua_State *L, int storage);
struct curl_slist* lcurl_util_array_to_slist(lua_State *L, int t);