diff --git a/doc/lcurl.ldoc b/doc/lcurl.ldoc index fb821e1..110a51e 100644 --- a/doc/lcurl.ldoc +++ b/doc/lcurl.ldoc @@ -12,6 +12,11 @@ function form() end -- @treturn[1] easy new curl easy object function easy() end +--- Create Multi object +-- +-- @treturn[1] multi new curl multi object +function multi() end + --- Returns libcurl version as human readable string -- function version() end @@ -41,7 +46,7 @@ do -- @tparam[opt] string type provides the content-type for this part -- @tparam[opt] table headers specifies extra headers for the form POST section -- @return[1] self -function httpform:add_content() end +function add_content() end --- 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] table headers specifies extra headers for the form POST section -- @return[1] self -function httpform:add_buffer() end +function add_buffer() end --- Add new part to form. -- @@ -62,7 +67,7 @@ function httpform:add_buffer() end -- By default it is basename of path. -- @tparam[opt] table headers specifies extra headers for the form POST section -- @return[1] self -function httpform:add_file() end +function add_file() end --- Serialize multipart/formdata HTTP POST chain. -- @@ -70,7 +75,7 @@ function httpform:add_file() end -- -- @usage print(post:get()) -- -function httpform:get() end +function get() end --- Serialize multipart/formdata HTTP POST chain. -- @@ -86,7 +91,7 @@ function httpform:get() end -- post:get(table.insert, t) -- print(table.concat(t)) -- -function httpform:get() end +function get() end --- Serialize multipart/formdata HTTP POST chain. -- @@ -99,11 +104,11 @@ function httpform:get() end -- f = io.open(...) -- post:get(f) -- -function httpform:get() end +function get() end --- Free multipart/formdata. -- -function httpform:free() end +function free() end end @@ -115,28 +120,28 @@ do --- Perform a file transfer -- -- @return[1] self -function easy:perfom() end +function perfom() end --- URL encodes the given string -- -- @tparam string url -- @return[1] encoded url -function easy:escape() end +function escape() end --- URL decodes the given string -- -- @tparam string url -- @return[1] decoded url -function easy:unescape() end +function unescape() end --- Re-initializes all options previously set. -- -- @treturn easy self -function easy:reset() end +function reset() end --- End easy session -- -function easy:close() end +function close() end --- Set options. -- @@ -150,7 +155,7 @@ function easy:close() end -- function(t, n) return table.remove(t) end, -- {"1111", "2222"} -- ) -function easy:setopt() end +function setopt() end --- Get information. -- @@ -161,7 +166,7 @@ function easy:setopt() end -- print(c:getinfo(curl.INFO_EFFECTIVE_URL)) -- print(c:getinfo(curl.INFO_TOTAL_TIME)) -- print(c:getinfo(curl.INFO_RESPONSE_CODE)) -function easy:getinfo() end +function getinfo() end --- Set writer function. -- @@ -174,7 +179,7 @@ function easy:getinfo() end -- @param[opt] context writer context -- @return[1] self -- -function easy:setopt_writefunction() end +function setopt_writefunction() end --- Set writer function. -- @@ -183,7 +188,7 @@ function easy:setopt_writefunction() end -- @tparam object writer -- @return[1] self -- -function easy:setopt_writefunction() end +function setopt_writefunction() end --- Set header function. -- @@ -196,7 +201,7 @@ function easy:setopt_writefunction() end -- @param[opt] context writer context -- @return[1] self -- -function easy:setopt_headerfunction() end +function setopt_headerfunction() end --- Set header function. -- @@ -205,7 +210,7 @@ function easy:setopt_headerfunction() end -- @tparam object writer -- @return[1] self -- -function easy:setopt_headerfunction() end +function setopt_headerfunction() end --- Set reader function. -- @@ -219,7 +224,7 @@ function easy:setopt_headerfunction() end -- @param[opt] context reader context -- @return[1] self -- -function easy:setopt_readfunction() end +function setopt_readfunction() end --- Set reader function. -- @@ -228,7 +233,7 @@ function easy:setopt_readfunction() end -- @tparam object reader -- @return[1] self -- -function easy:setopt_readfunction() end +function setopt_readfunction() end --- Set progress function. -- @@ -245,7 +250,7 @@ function easy:setopt_readfunction() end -- @param[opt] context progress context -- @return[1] self -- -function easy:setopt_progressfunction() end +function setopt_progressfunction() end --- Set reader function. -- @@ -254,19 +259,30 @@ function easy:setopt_progressfunction() end -- @tparam object reader -- @return[1] self -- -function easy:setopt_readfunction() end +function setopt_readfunction() end --- Set HTTP multipart/formdata -- -- @tparam httpform data -- @return[1] self -function easy:setopt_httpform() end +function setopt_httpform() end --- Set HTTP multipart/formdata -- -- @tparam string data -- @tparam[opt=#data] number length -- @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 diff --git a/msvc/lcurl.vcproj b/msvc/lcurl.vcproj index c82ac65..ffb66c7 100644 --- a/msvc/lcurl.vcproj +++ b/msvc/lcurl.vcproj @@ -189,6 +189,10 @@ RelativePath="..\src\lchttppost.c" > + + @@ -239,6 +243,10 @@ RelativePath="..\src\lcinfoeasy.h" > + + diff --git a/src/lceasy.c b/src/lceasy.c index b99ff48..545e8c4 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -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 *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; } diff --git a/src/lcmulti.c b/src/lcmulti.c new file mode 100644 index 0000000..15940fe --- /dev/null +++ b/src/lcmulti.c @@ -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); +} \ No newline at end of file diff --git a/src/lcmulti.h b/src/lcmulti.h new file mode 100644 index 0000000..455a6cc --- /dev/null +++ b/src/lcmulti.h @@ -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 diff --git a/src/lcurl.c b/src/lcurl.c index b78924e..d586d1d 100644 --- a/src/lcurl.c +++ b/src/lcurl.c @@ -1,5 +1,6 @@ #include "lcurl.h" #include "lceasy.h" +#include "lcmulti.h" #include "lcerror.h" #include "lchttppost.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); } +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){ 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); } +static int lcurl_multi_new(lua_State *L){ + return lcurl_multi_create(L, LCURL_ERROR_RAISE); +} + static int lcurl_hpost_new(lua_State *L){ return lcurl_hpost_create(L, LCURL_ERROR_RAISE); } @@ -76,6 +85,7 @@ static const struct luaL_Reg lcurl_functions[] = { {"error", lcurl_error_new }, {"form", lcurl_hpost_new }, {"easy", lcurl_easy_new }, + {"multi", lcurl_multi_new }, {"version", lcurl_version }, {"version_info", lcurl_version_info }, @@ -84,8 +94,11 @@ static const struct luaL_Reg lcurl_functions[] = { static const struct luaL_Reg lcurl_functions_safe[] = { {"error", lcurl_error_new }, - {"httppost", lcurl_hpost_new_safe }, + {"form", lcurl_hpost_new_safe }, {"easy", lcurl_easy_new_safe }, + {"multi", lcurl_multi_new_safe }, + {"version", lcurl_version }, + {"version_info", lcurl_version_info }, {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_hpost_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);