Giter VIP home page Giter VIP logo

lua-curlv2's Introduction

lua-curlv2's People

Contributors

flyingtime avatar funkyass avatar janniz avatar kimperator avatar markand avatar moteus avatar msva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua-curlv2's Issues

Error "The specified procedure could not be found"

Greetings. After compiling with MVS10 and connection of the library, I get the error "The specified procedure could not be found". How to fix or you can choose to publish the compiled version? Thank you.

Memory leak on easy post

Doc says that client should call curl_formfree for curl_httppost element.

Also strings for some options should be preserved (e.g. CURLOPT_POSTFIELDS)
I think we need just create some storage in registry for each easy object and save such Lua strings there to prevent collecting them.

current master doesn't compile on fedora 17

karlp@pojak:/src$ git clone git://github.com/msva/lua-curl.git
remote: Counting objects: 501, done.
remote: Compressing objects: 100% (174/174), done.
remote: Total 501 (delta 330), reused 473 (delta 308)
Receiving objects: 100% (501/501), 85.36 KiB, done.
Resolving deltas: 100% (330/330), done.
karlp@pojak:
/src$ cd lua-curl/
karlp@pojak:/src/lua-curl (master)$ ./autogen.sh
libtoolize: putting auxiliary files in .'. libtoolize: linking file./ltmain.sh'
libtoolize: Consider adding AC_CONFIG_MACRO_DIR([m4])' to configure.ac and libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree. libtoolize: Consider adding-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
configure.ac:6: required file ./config.guess' not found configure.ac:6:automake --add-missing' can install config.guess' configure.ac:6: required file./config.sub' not found
configure.ac:6: automake --add-missing' can installconfig.sub'
configure.ac:2: required file ./install-sh' not found configure.ac:2:automake --add-missing' can install install-sh' configure.ac:2: required file./missing' not found
configure.ac:2: automake --add-missing' can installmissing'
src/Makefile.am: required file ./depcomp' not found src/Makefile.am:automake --add-missing' can install `depcomp'
karlp@pojak:
/src/lua-curl (master)$ ./configure
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
karlp@pojak:~/src/lua-curl (master)$

Any hints?

Patch add progress handle

Hi,

Sometimes, we need show progress info, please review this patch, I think it's useful.

thanks.

 src/Lua-cURL-callback.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/Lua-cURL.c          | 13 ++++++++++++-
 src/Lua-cURL.h          |  4 +++-
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/src/Lua-cURL-callback.c b/src/Lua-cURL-callback.c
index 6ced8e4..57d26bf 100644
--- a/src/Lua-cURL-callback.c
+++ b/src/Lua-cURL-callback.c
@@ -60,6 +60,21 @@ static size_t l_easy_headerfunction(void *ptr, size_t size, size_t nmemb, void *
   return nmemb*size;
 }

+static int l_easy_progressfunction(void *clientp,   curl_off_t dltotal,   curl_off_t dlnow,   curl_off_t ultotal,   curl_off_t ulnow)
+{
+   lua_State* L = (lua_State*)clientp;
+   int aborted = 0;
+   lua_getfield(L, -1, "progressfunction");
+   lua_pushinteger(L, (lua_Integer)dltotal);
+   lua_pushinteger(L, (lua_Integer)dlnow);
+   lua_pushinteger(L, (lua_Integer)ultotal);
+   lua_pushinteger(L, (lua_Integer)ulnow);
+
+   lua_call(L, 4, 1);
+   aborted = luaL_checkint(L, -1);
+   lua_pop(L,1);
+   return aborted;
+}

 int l_easy_setup_writefunction(lua_State *L, CURL* curl) {
     /* Lua State as userdata argument */
@@ -92,6 +107,20 @@ int l_easy_setup_headerfunction(lua_State *L, CURL* curl) {
   return 0;
 }

+
+int l_easy_setup_progressfunction(lua_State *L, CURL* curl) {
+   /* Lua State as userdata argument */
+   l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
+   if (curl_easy_setopt(curl, CURLOPT_XFERINFODATA ,L) != CURLE_OK)
+       luaL_error(L, "%s", privatep->error);
+
+   if (curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, l_easy_progressfunction) != CURLE_OK)
+       luaL_error(L, "%s", privatep->error);
+
+   curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); 
+   return 0;
+}
+
 int l_easy_clear_headerfunction(lua_State *L, CURL* curl) {
   l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
   if (curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, NULL) != CURLE_OK)
@@ -118,3 +147,13 @@ int l_easy_clear_readfunction(lua_State *L, CURL* curl) {
     luaL_error(L, "%s", privatep->error);
   return 0;
 }
+
+int l_easy_clear_progressfunction(lua_State *L, CURL* curl) {
+   l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
+   if (curl_easy_setopt(curl, CURLOPT_XFERINFODATA, NULL) != CURLE_OK)
+       luaL_error(L, "%s", privatep->error);
+   if (curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, NULL) != CURLE_OK)
+       luaL_error(L, "%s", privatep->error);
+   curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); 
+   return 0;
+}
diff --git a/src/Lua-cURL.c b/src/Lua-cURL.c
index 851d4b0..4ad9f11 100644
--- a/src/Lua-cURL.c
+++ b/src/Lua-cURL.c
@@ -128,6 +128,9 @@ int l_easy_perform(lua_State *L) {
   int headerfunction;
   /* do readcallback */
   int readfunction;
+  /* do progresscallback */
+  int progressfunction;
+
   /* curl_easy_perform return code*/
   CURLcode perform_status;

@@ -155,6 +158,12 @@ int l_easy_perform(lua_State *L) {
     l_easy_setup_readfunction(L, privatep->curl);
   lua_pop(L, 1);

+  /* set progress callback function only if entry exist in callback-table */
+  lua_getfield(L, 2, "progressfunction");
+  progressfunction = lua_isfunction(L, -1)?1:0;
+  if(progressfunction)
+     l_easy_setup_progressfunction(L, privatep->curl);
+  lua_pop(L, 1);

   /* callback table is on top on stack */
   perform_status = curl_easy_perform(curl);
@@ -166,6 +175,8 @@ int l_easy_perform(lua_State *L) {
     l_easy_clear_writefunction(L, privatep->curl);
   if (readfunction)
     l_easy_clear_readfunction(L, privatep->curl);
+  if (progressfunction)
+     l_easy_clear_progressfunction(L, privatep->curl);

   if (perform_status != CURLE_OK)
     return luaL_error(L, "%s", privatep->error);
@@ -201,7 +212,7 @@ int l_getdate(lua_State *L) {
   time_t t = curl_getdate(date, NULL);
   if (t == -1)
     return luaL_error(L, "fails to parse the date string");
-  lua_pushinteger(L, t);
+  lua_pushinteger(L, (lua_Integer)t);
   return 1;
 }

diff --git a/src/Lua-cURL.h b/src/Lua-cURL.h
index 76955b4..5b5e4a0 100644
--- a/src/Lua-cURL.h
+++ b/src/Lua-cURL.h
@@ -98,9 +98,11 @@ void l_easy_setopt_free_slists(l_easy_private *privp);
 int l_easy_setup_writefunction(lua_State *L, CURL* curl);
 int l_easy_setup_headerfunction(lua_State *L, CURL* curl);
 int l_easy_setup_readfunction(lua_State *L, CURL* curl);
+int l_easy_setup_progressfunction(lua_State *L, CURL* curl);
 int l_easy_clear_headerfunction(lua_State *L, CURL* curl);
-int l_easy_clear_writefunction(lua_State *L, CURL* curl);
 int l_easy_clear_readfunction(lua_State *L, CURL* curl);
+int l_easy_clear_writefunction(lua_State *L, CURL* curl);
+int l_easy_clear_progressfunction(lua_State *L, CURL* curl);

 /* Lua module functions */
 int l_easy_init (lua_State *L);

Doesn't work with Lua 5.2 (patch provided)

All this newfangled github stuff confuses this gray-bearded programmer, so I have no idea of the proper channels for this.

This patch seems to make Lua-cURL work with Lua 5.2. The only user-side change is that, in keeping with 5.2's conventions, one has to do something like local cURL = require "cURL" instead of just require "cURL" to use it.

--- lua-curl/src/Lua-cURL.c        2012-10-26 11:42:03.000000000 -0600
+++ lua-curl-52comp/src/Lua-cURL.c 2012-11-09 20:30:15.000000000 -0700
@@ -298,7 +298,11 @@
   luaL_newmetatable(L, LUACURL_EASYMETATABLE);

   /* register in easymetatable */
+#if LUA_VERSION_NUM < 502
   luaL_register(L, NULL, luacurl_easy_m);
+#else
+  luaL_setfuncs(L, luacurl_easy_m, 0);
+#endif

   /* easymetatable.__index = easymetatable */
   lua_pushvalue(L, -1);
@@ -313,7 +317,11 @@
   luaL_newmetatable(L, LUACURL_SHAREMETATABLE);

   /* register in sharemetatable */
+#if LUA_VERSION_NUM < 502
   luaL_register(L, NULL, luacurl_share_m);
+#else
+  luaL_setfuncs(L, luacurl_share_m, 0);
+#endif

   /* sharemetatable.__index = sharemetatable */
   lua_pushvalue(L, -1);
@@ -321,7 +329,11 @@

   /* MULTI START */
   luaL_newmetatable(L, LUACURL_MULTIMETATABLE);
+#if LUA_VERSION_NUM < 502
   luaL_register(L, NULL, luacurl_multi_m);
+#else
+  luaL_setfuncs(L, luacurl_multi_m, 0);
+#endif
     /* multemetatable.__index = multimetatable */
   lua_pushvalue(L, -1);
   lua_setfield(L, -2, "__index");
@@ -334,7 +346,11 @@


   /* return module functions */
+#if LUA_VERSION_NUM < 502
   luaL_register(L, "cURL", luacurl_f);
+#else
+  luaL_newlib(L, luacurl_f);
+#endif

   /* initialize curl once */
   if ((rc = curl_global_init(CURL_GLOBAL_ALL)) != CURLE_OK)

multi mode question

for data, type, easy in m:perform() do
-- if (type == "header") then print(data) end
if (type == "data" and c == easy) then f1:write(data) end
if (type == "data" and c2 == easy) then f2:write(data) end
end
WARNING: 'multi' mode is incompatible with curl built with threads support.

Does it means the http request in multi mode is execute synchronous?

Add support for CURLOPT_PROTOCOLS

I would like to add support for CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS (in curl_easy_setopt), but that requires some design choices to be made.

Both the options get a long that holds a bitmask of CURLPROTO_* defines from "curl.h", so:
1) In order to add those options to lua-curl, CURLPROTOs should be exposed somewhere in the lua module (note that the order in which protocols are listed in curl_version_info_data.protocols doesn't reflect the CURLPROTOs defines values, so they are not useful in this case);
2) keeping the api style, the new lua functions will accept one and only one long; in that case, since lua5.1 doesn't have official support for bitwise operations, users of that version must rely on external libraries for computing the protocols bitmask. Despite that seems cumbersome to me, I think that lua-curl won't benefit from a change in the api style.

Discussing the matter before implementing anything would be nice

current master still doesn't compile on fedora 17 (libtool)

After fixing issue #1, the autotools mess seems mostly fixed.

Now...

/bin/sh ../libtool --tag=CC --mode=link gcc -g -O2 -llua -lm -ldl -lcurl -avoid-version -module -o cURL.la -rpath cURL_la-Lua-cURL.lo cURL_la-Lua-utility.lo cURL_la-Lua-cURL-getinfo.lo cURL_la-Lua-cURL-setopt.lo cURL_la-Lua-cURL-callback.lo cURL_la-Lua-cURL-post.lo cURL_la-Lua-cURL-multi.lo cURL_la-Lua-cURL-share.lo
libtool: link: only absolute run-paths are allowed
make[1]: *** [cURL.la] Error 1

tag new release

Hi,

I wonder if it would be possible to tag a new release with lua 5.2 support?

thanks!

make error

when I install on centos 6.5,after cmake ,I meet the error
/root/lua-curl/src/Lua-cURL-callback.c: 在函数‘l_easy_setup_progressfunction’中:
/root/lua-curl/src/Lua-cURL-callback.c:114: 错误:‘CURLOPT_XFERINFODATA’未声明(在此函数内第一次使用)
/root/lua-curl/src/Lua-cURL-callback.c:114: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
/root/lua-curl/src/Lua-cURL-callback.c:114: 错误:所在的函数内也只报告一次。)
/root/lua-curl/src/Lua-cURL-callback.c:117: 错误:‘CURLOPT_XFERINFOFUNCTION’未声明(在此函数内第一次使用)
/root/lua-curl/src/Lua-cURL-callback.c: 在函数‘l_easy_clear_progressfunction’中:
/root/lua-curl/src/Lua-cURL-callback.c:153: 错误:‘CURLOPT_XFERINFODATA’未声明(在此函数内第一次使用)
/root/lua-curl/src/Lua-cURL-callback.c:155: 错误:‘CURLOPT_XFERINFOFUNCTION’未声明(在此函数内第一次使用)
make[2]: *** [CMakeFiles/cURL.dir/src/Lua-cURL-callback.c.o] 错误 1
make[1]: *** [CMakeFiles/cURL.dir/all] 错误 2
make: *** [all] 错误 2

Discuss new API for Lua-cURL

This is my suggestion
For now it just easy class

  1. Easy ctor allows table to set optoins
  2. set method allows table or key-value pair
  3. rename setopt_XXX to set_XXX.
  4. rename readfunction ... to read
  5. may be allow use table/array as value for read/header
  6. Allow true/false as values for options
  7. rename getinfo_XXX to get_XXX
  8. implement posthttp object
  9. export cleanup method to Lua
e = curl.easy{url = 'http://example.com', upload = false}
print(e:get_effective_url())
e:perform{write = print}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.