Add. Init multi interface.

This commit is contained in:
Alexey Melnichuk 2014-08-27 12:05:44 +05:00
parent d2118f2c93
commit bf72021579
6 changed files with 143 additions and 26 deletions

View File

@ -12,6 +12,11 @@ function form() end
-- @treturn[1] easy new curl easy object -- @treturn[1] easy new curl easy object
function easy() end function easy() end
--- Create Multi object
--
-- @treturn[1] multi new curl multi object
function multi() end
--- Returns libcurl version as human readable string --- Returns libcurl version as human readable string
-- --
function version() end function version() end
@ -41,7 +46,7 @@ do
-- @tparam[opt] string type provides the content-type for this part -- @tparam[opt] string type provides the content-type for this part
-- @tparam[opt] table headers specifies extra headers for the form POST section -- @tparam[opt] table headers specifies extra headers for the form POST section
-- @return[1] self -- @return[1] self
function httpform:add_content() end function add_content() end
--- Add new part to form. --- Add new part to form.
-- --
@ -51,7 +56,7 @@ function httpform:add_content() end
-- @tparam[opt] string type provides the content-type for this part -- @tparam[opt] string type provides the content-type for this part
-- @tparam[opt] table headers specifies extra headers for the form POST section -- @tparam[opt] table headers specifies extra headers for the form POST section
-- @return[1] self -- @return[1] self
function httpform:add_buffer() end function add_buffer() end
--- Add new part to form. --- Add new part to form.
-- --
@ -62,7 +67,7 @@ function httpform:add_buffer() end
-- By default it is basename of path. -- By default it is basename of path.
-- @tparam[opt] table headers specifies extra headers for the form POST section -- @tparam[opt] table headers specifies extra headers for the form POST section
-- @return[1] self -- @return[1] self
function httpform:add_file() end function add_file() end
--- Serialize multipart/formdata HTTP POST chain. --- Serialize multipart/formdata HTTP POST chain.
-- --
@ -70,7 +75,7 @@ function httpform:add_file() end
-- --
-- @usage print(post:get()) -- @usage print(post:get())
-- --
function httpform:get() end function get() end
--- Serialize multipart/formdata HTTP POST chain. --- Serialize multipart/formdata HTTP POST chain.
-- --
@ -86,7 +91,7 @@ function httpform:get() end
-- post:get(table.insert, t) -- post:get(table.insert, t)
-- print(table.concat(t)) -- print(table.concat(t))
-- --
function httpform:get() end function get() end
--- Serialize multipart/formdata HTTP POST chain. --- Serialize multipart/formdata HTTP POST chain.
-- --
@ -99,11 +104,11 @@ function httpform:get() end
-- f = io.open(...) -- f = io.open(...)
-- post:get(f) -- post:get(f)
-- --
function httpform:get() end function get() end
--- Free multipart/formdata. --- Free multipart/formdata.
-- --
function httpform:free() end function free() end
end end
@ -115,28 +120,28 @@ do
--- Perform a file transfer --- Perform a file transfer
-- --
-- @return[1] self -- @return[1] self
function easy:perfom() end function perfom() end
--- URL encodes the given string --- URL encodes the given string
-- --
-- @tparam string url -- @tparam string url
-- @return[1] encoded url -- @return[1] encoded url
function easy:escape() end function escape() end
--- URL decodes the given string --- URL decodes the given string
-- --
-- @tparam string url -- @tparam string url
-- @return[1] decoded url -- @return[1] decoded url
function easy:unescape() end function unescape() end
--- Re-initializes all options previously set. --- Re-initializes all options previously set.
-- --
-- @treturn easy self -- @treturn easy self
function easy:reset() end function reset() end
--- End easy session --- End easy session
-- --
function easy:close() end function close() end
--- Set options. --- Set options.
-- --
@ -150,7 +155,7 @@ function easy:close() end
-- function(t, n) return table.remove(t) end, -- function(t, n) return table.remove(t) end,
-- {"1111", "2222"} -- {"1111", "2222"}
-- ) -- )
function easy:setopt() end function setopt() end
--- Get information. --- Get information.
-- --
@ -161,7 +166,7 @@ function easy:setopt() end
-- print(c:getinfo(curl.INFO_EFFECTIVE_URL)) -- print(c:getinfo(curl.INFO_EFFECTIVE_URL))
-- print(c:getinfo(curl.INFO_TOTAL_TIME)) -- print(c:getinfo(curl.INFO_TOTAL_TIME))
-- print(c:getinfo(curl.INFO_RESPONSE_CODE)) -- print(c:getinfo(curl.INFO_RESPONSE_CODE))
function easy:getinfo() end function getinfo() end
--- Set writer function. --- Set writer function.
-- --
@ -174,7 +179,7 @@ function easy:getinfo() end
-- @param[opt] context writer context -- @param[opt] context writer context
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_writefunction() end function setopt_writefunction() end
--- Set writer function. --- Set writer function.
-- --
@ -183,7 +188,7 @@ function easy:setopt_writefunction() end
-- @tparam object writer -- @tparam object writer
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_writefunction() end function setopt_writefunction() end
--- Set header function. --- Set header function.
-- --
@ -196,7 +201,7 @@ function easy:setopt_writefunction() end
-- @param[opt] context writer context -- @param[opt] context writer context
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_headerfunction() end function setopt_headerfunction() end
--- Set header function. --- Set header function.
-- --
@ -205,7 +210,7 @@ function easy:setopt_headerfunction() end
-- @tparam object writer -- @tparam object writer
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_headerfunction() end function setopt_headerfunction() end
--- Set reader function. --- Set reader function.
-- --
@ -219,7 +224,7 @@ function easy:setopt_headerfunction() end
-- @param[opt] context reader context -- @param[opt] context reader context
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_readfunction() end function setopt_readfunction() end
--- Set reader function. --- Set reader function.
-- --
@ -228,7 +233,7 @@ function easy:setopt_readfunction() end
-- @tparam object reader -- @tparam object reader
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_readfunction() end function setopt_readfunction() end
--- Set progress function. --- Set progress function.
-- --
@ -245,7 +250,7 @@ function easy:setopt_readfunction() end
-- @param[opt] context progress context -- @param[opt] context progress context
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_progressfunction() end function setopt_progressfunction() end
--- Set reader function. --- Set reader function.
-- --
@ -254,19 +259,30 @@ function easy:setopt_progressfunction() end
-- @tparam object reader -- @tparam object reader
-- @return[1] self -- @return[1] self
-- --
function easy:setopt_readfunction() end function setopt_readfunction() end
--- Set HTTP multipart/formdata --- Set HTTP multipart/formdata
-- --
-- @tparam httpform data -- @tparam httpform data
-- @return[1] self -- @return[1] self
function easy:setopt_httpform() end function setopt_httpform() end
--- Set HTTP multipart/formdata --- Set HTTP multipart/formdata
-- --
-- @tparam string data -- @tparam string data
-- @tparam[opt=#data] number length -- @tparam[opt=#data] number length
-- @return[1] self -- @return[1] self
function easy:setopt_postfields() end function setopt_postfields() end
end
--- Muli curl object
-- @type multi
--
do
--- End multi session
--
function close() end
end end

View File

@ -189,6 +189,10 @@
RelativePath="..\src\lchttppost.c" RelativePath="..\src\lchttppost.c"
> >
</File> </File>
<File
RelativePath="..\src\lcmulti.c"
>
</File>
<File <File
RelativePath="..\src\lcurl.c" RelativePath="..\src\lcurl.c"
> >
@ -239,6 +243,10 @@
RelativePath="..\src\lcinfoeasy.h" RelativePath="..\src\lcinfoeasy.h"
> >
</File> </File>
<File
RelativePath="..\src\lcmulti.h"
>
</File>
<File <File
RelativePath="..\src\lcopteasy.h" RelativePath="..\src\lcopteasy.h"
> >

View File

@ -32,7 +32,7 @@ int lcurl_easy_create(lua_State *L, int error_mode){
lcurl_easy_t *lcurl_geteasy_at(lua_State *L, int i){ lcurl_easy_t *lcurl_geteasy_at(lua_State *L, int i){
lcurl_easy_t *p = (lcurl_easy_t *)lutil_checkudatap (L, i, LCURL_EASY); lcurl_easy_t *p = (lcurl_easy_t *)lutil_checkudatap (L, i, LCURL_EASY);
luaL_argcheck (L, p != NULL, 1, LCURL_PREFIX"HTTPPost object expected"); luaL_argcheck (L, p != NULL, 1, LCURL_EASY_NAME" expected");
return p; return p;
} }

59
src/lcmulti.c Normal file
View File

@ -0,0 +1,59 @@
#include "lcurl.h"
#include "lceasy.h"
#include "lcmulti.h"
#include "lcerror.h"
#include "lcutils.h"
#include "lchttppost.h"
static const char *LCURL_ERROR_TAG = "LCURL_ERROR_TAG";
#define LCURL_MULTI_NAME LCURL_PREFIX" Multi"
static const char *LCURL_MULTI = LCURL_MULTI_NAME;
//{
int lcurl_multi_create(lua_State *L, int error_mode){
lcurl_multi_t *p = lutil_newudatap(L, lcurl_multi_t, LCURL_MULTI);
p->curl = curl_multi_init();
if(!p->curl) return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_MULTI, CURLM_INTERNAL_ERROR);
return 1;
}
lcurl_multi_t *lcurl_getmulti_at(lua_State *L, int i){
lcurl_multi_t *p = (lcurl_multi_t *)lutil_checkudatap (L, i, LCURL_MULTI);
luaL_argcheck (L, p != NULL, 1, LCURL_MULTI_NAME" expected");
return p;
}
static int lcurl_multi_cleanup(lua_State *L){
lcurl_multi_t *p = lcurl_getmulti(L);
if(p->curl){
curl_multi_cleanup(p->curl);
p->curl = NULL;
}
return 0;
}
//}
static const struct luaL_Reg lcurl_multi_methods[] = {
{"close", lcurl_multi_cleanup },
{"__gc", lcurl_multi_cleanup },
{NULL,NULL}
};
static const lcurl_const_t lcurl_multi_opt[] = {
{NULL, 0}
};
void lcurl_multi_initlib(lua_State *L, int nup){
if(!lutil_createmetap(L, LCURL_MULTI, lcurl_multi_methods, nup))
lua_pop(L, nup);
lua_pop(L, 1);
lcurl_util_set_const(L, lcurl_multi_opt);
}

20
src/lcmulti.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef _LCMULTI_H_
#define _LCMULTI_H_
#include "lcurl.h"
#include "lcutils.h"
typedef struct lcurl_multi_tag{
CURLM *curl;
int err_mode;
}lcurl_multi_t;
int lcurl_multi_create(lua_State *L, int error_mode);
lcurl_multi_t *lcurl_getmulti_at(lua_State *L, int i);
#define lcurl_getmulti(L) lcurl_getmulti_at((L),1)
void lcurl_multi_initlib(lua_State *L, int nup);
#endif

View File

@ -1,5 +1,6 @@
#include "lcurl.h" #include "lcurl.h"
#include "lceasy.h" #include "lceasy.h"
#include "lcmulti.h"
#include "lcerror.h" #include "lcerror.h"
#include "lchttppost.h" #include "lchttppost.h"
#include "lcutils.h" #include "lcutils.h"
@ -15,6 +16,10 @@ static int lcurl_easy_new_safe(lua_State *L){
return lcurl_easy_create(L, LCURL_ERROR_RETURN); return lcurl_easy_create(L, LCURL_ERROR_RETURN);
} }
static int lcurl_multi_new_safe(lua_State *L){
return lcurl_multi_create(L, LCURL_ERROR_RETURN);
}
static int lcurl_hpost_new_safe(lua_State *L){ static int lcurl_hpost_new_safe(lua_State *L){
return lcurl_hpost_create(L, LCURL_ERROR_RETURN); return lcurl_hpost_create(L, LCURL_ERROR_RETURN);
} }
@ -23,6 +28,10 @@ static int lcurl_easy_new(lua_State *L){
return lcurl_easy_create(L, LCURL_ERROR_RAISE); return lcurl_easy_create(L, LCURL_ERROR_RAISE);
} }
static int lcurl_multi_new(lua_State *L){
return lcurl_multi_create(L, LCURL_ERROR_RAISE);
}
static int lcurl_hpost_new(lua_State *L){ static int lcurl_hpost_new(lua_State *L){
return lcurl_hpost_create(L, LCURL_ERROR_RAISE); return lcurl_hpost_create(L, LCURL_ERROR_RAISE);
} }
@ -76,6 +85,7 @@ static const struct luaL_Reg lcurl_functions[] = {
{"error", lcurl_error_new }, {"error", lcurl_error_new },
{"form", lcurl_hpost_new }, {"form", lcurl_hpost_new },
{"easy", lcurl_easy_new }, {"easy", lcurl_easy_new },
{"multi", lcurl_multi_new },
{"version", lcurl_version }, {"version", lcurl_version },
{"version_info", lcurl_version_info }, {"version_info", lcurl_version_info },
@ -84,8 +94,11 @@ static const struct luaL_Reg lcurl_functions[] = {
static const struct luaL_Reg lcurl_functions_safe[] = { static const struct luaL_Reg lcurl_functions_safe[] = {
{"error", lcurl_error_new }, {"error", lcurl_error_new },
{"httppost", lcurl_hpost_new_safe }, {"form", lcurl_hpost_new_safe },
{"easy", lcurl_easy_new_safe }, {"easy", lcurl_easy_new_safe },
{"multi", lcurl_multi_new_safe },
{"version", lcurl_version },
{"version_info", lcurl_version_info },
{NULL,NULL} {NULL,NULL}
}; };
@ -120,6 +133,7 @@ static int luaopen_lcurl_(lua_State *L, const struct luaL_Reg *func){
lua_pushvalue(L, -2); lcurl_error_initlib(L, 1); lua_pushvalue(L, -2); lcurl_error_initlib(L, 1);
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); lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY); lua_pushvalue(L, -2); lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);