Coder Social home page Coder Social logo

lua-curlv3's Introduction

Lua binding to libcurl

Build Status Build status Coverage Status Licence

Status

This module include three layer

  1. lcurl module provide low level pure C binding to libcurl.
    Almost ready and needs tests. I have no plans to change this API.

  2. cURL module provide compatibility for Lua-cURLv2 API.
    Almost ready and needs tests.

  3. cURL module provide new high level API.
    In fact for now it provide lcurl API directly and needed to redesign.

Documentation

lcurl API
Lua-cURLv2 API
Lua-cURLv3 API

Original Lua-cURLv2 binding has several problems:

  • it can not return error codes but just raise Lua errors (Fixed. use cURL.safe module)
  • it raise Lua error from callback that may result resource leak in libcurl (Fixed.)
  • it does not provide building multipart/formdata explicitly (Fixed.)
  • it has memory leak when send multipart/formdata (Fixed.)
  • it does not save string for curl options that may result crush in libcurl (Fixed.)
  • there no way to get result for operations in multi interface (e.g. if one of easy operation fail you can not get result code/error message) (Fixed. But it does not very handy interface.)
  • you can not use your own callback function to perform operation with multi interface (Could not be fixed without changing API.)
  • you can not pass your context to callback functions (Could not be fixed without changing API.)

Installation

Using LuaRocks:

luarocks install Lua-cURL

Install current master:

luarocks install Lua-cURL --server=https://luarocks.org/dev

List of incompatibility with original Lua-cURLv2

  • objects are tables
  • multi:perform() also returns ("done",code), ("error",error) and ("response",code) records
  • writer callback does not recv string len (just string itself)
  • on Lua > 5.2 errors are objects but not strings

Usage

-- HTTP Get
curl.easy{
    url = 'http://httpbin.org/get',
    httpheader = {
      "X-Test-Header1: Header-Data1",
      "X-Test-Header2: Header-Data2",
    },
    writefunction = io.stderr -- use io.stderr:write()
  }
  :perform()
:close()
-- HTTP Post
curl.easy()
  :setopt_url('http://posttestserver.com/post.php')
  :setopt_writefunction(io.write)
  :setopt_httppost(curl.form() -- Lua-cURL guarantee that form will be alive
    :add_content("test_content", "some data", {
      "MyHeader: SomeValue"
    })
    :add_buffer("test_file", "filename", "text data", "text/plain", {
      "Description: my file description"
    })
    :add_file("test_file2", "BuildLog.htm", "application/octet-stream", {
      "Description: my file description"
    })
  )
  :perform()
:close()
-- FTP Upload
local function get_bin_by(str,n)
  local pos = 1 - n
  return function()
    pos = pos + n
    return (str:sub(pos,pos+n-1))
  end
end

curl.easy()
  :setopt_url("ftp://moteus:[email protected]/test.dat")
  :setopt_upload(true)
  :setopt_readfunction(
    get_bin_by(("0123456789"):rep(4), 9)
  )
  :perform()
:close()
-- Multi FTP Upload

-- We get error E_LOGIN_DENIED for this operation
e1 = curl.easy{url = "ftp://moteus:[email protected]/test1.dat", upload = true}
  :setopt_readfunction(
    function(t) return table.remove(t) end, {"1111", "2222"}
  )

e2 = curl.easy{url = "ftp://moteus:[email protected]/test2.dat", upload = true}
  :setopt_readfunction(get_bin_by(("e"):rep(1000), 5))

m = curl.multi()
m:add_handle(e1)
m:add_handle(e2)

while m:perform() > 0 do m:wait() end

while true do
  h, ok, err = m:info_read()
  if h == 0 then break end

  if h == e1 then 
    assert(ok == nil)
    assert(err:name() == "LOGIN_DENIED")
    assert(err:no() == curl.E_LOGIN_DENIED)
  end

  if h == e2 then 
    assert(ok == true)
  end
end

lua-curlv3's People

Contributors

anderson-cujo avatar cryi avatar moteus avatar msva avatar srdgame avatar szakharchenko avatar technomancy avatar uudiin avatar zhaozg 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua-curlv3's Issues

Implement Lua-cURL interface.

Need to implement

  • perform functions for easy/multi
  • post function for easy interface
  • string names for options values
  • streams for easy:post()
  • ???
cURL = require "lcurl.cURL"
...

@msva Have you interest to help implement/test this.

Using curl.easy / c:perform

I'm using curl.easy and c:perform and trying to error trap the c:perform statement. For example, I'm trying to post to a web page, but the link (cellular) is currently down giving me error 7. I need to trap this error and then have my app retry. Please can you advise?

Compatibility with strict.lua

Please make the functions wrap_callback() and wrap_socketfunction() in cURL.lua local. Right not the cURL module cannot be used with strict.lua.

Can I install as Portable edition?

My current environment does not allow me to install luarocks etc. I'd like to download required modules and then put them into a inlcude dir. Is it possible?

How can I catch timeout?

When I try to download a big file I get this: lua: [OPERATION_TIMEDOUT] Timeout was reached (28)
But the execution of the function stops right away. I want to be able to handle this error? How can I do it?

failed installing in FreeBSD with luarocks

luarocks-5.1 install Lua-cURL

..
..
cc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c src/l52util.c -o src/l52util.o -I/usr/local/include
Data segment size exceeds process limit

Error: Build error: Failed compiling object src/l52util.o

Allows do not init libcurl when load lua-curl.

We use some host application which already loads libcurl and calls curl_global_init.
After that host application creates Lua state and runs Lua script which load lua-curl.
In this case we have not call curl_global_init because host application
may configure curl not in default mode.

Real life use case - FreeSWITCH.

I can imagine 2 way.

  1. some environment variable (e.g. LCURL_NO_INIT)
  2. separate load function luaopen_lcurl_no_init

I prefer first variant.

failed compile on mac

make CFLAGS=-I/usr/local/lua

6 warnings generated.
src/lchttppost.c:119:12: warning: unused function 'lcurl_hpost_to_s' [-Wunused-function]
static int lcurl_hpost_to_s(lua_State *L){
           ^
1 warning generated.
ld: library not found for -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [lcurl.so] Error 1
bash-3.2$ uname -a
Darwin MacBook-Air 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
bash-3.2$ 

Propagate error from easy callback to multi info_read

Now we can not raise error because we have no context. So we should store stack after error in callback (readfunction/writefunction etc.). Same if we want return value from callback.

But may be we can implement error callback on easy and/or multi object and calls this function from callbacks itself?

Initializing httppost when creating object

In the post_form.lua example we can see the following code:

  httppost = cURL.form{

    -- file form filesystem
    name01 = {
      file = "post_form.lua",
      type = "text/plain",
      name = "post.lua",
    },

    -- file form string
    name02 = {
      data = "<html><bold>bold</bold></html>",
      name = "dummy.html",
      type = "text/html",
    },

    -- file form stream object
    name03 = {
      stream  = Stream:new('8', 25),
      name    = "stream1.txt",
      type    = "text/plain",
      headers = {
        "X-Test-Char : 8",
        "X-Test-length : 25",
      }
    },

    -- file form stream function
    name04 = {
      stream  = stream,
      length  = length,
      name    = "stream2.txt",
      type    = "text/plain",
    },

  }, 

But is this really still supported? I don't see anything in the source code that could handle such code. Instead, it looks like form objects have to be filled using add_content, add_file, etc.

So if this example is a leftover from Lua-cURLv2, please delete it... (and also adapt the doc)

Add new easy handle during multi iteration

Example

for d,t,e in m:iperform() do
  if (t == 'done') or (t == 'error') then
    -- iperform should remove easy handle by himself
  end
  if ... then
    m:add_handle(curl.easy{...}) -- this should be valid
  end
end

Got issues while making for iOS

I got this error while building for iOS, but can't fix it.

xcrun -sdk iphoneos gcc -arch armv7 -arch armv7s -arch arm64 -miphoneos-version-min=6.0 -O2 -g -pipe -fPIC -ggdb -DPTHREADS -std=c99 -I../../../include -I../../../include/lua -c -o l52util.o l52util.c
xcrun -sdk iphoneos gcc -arch armv7 -arch armv7s -arch arm64 -miphoneos-version-min=6.0 -O2 -g -pipe -fPIC -ggdb -DPTHREADS -std=c99 -I../../../include -I../../../include/lua -c -o lceasy.o lceasy.c
In file included from lceasy.c:19:
./lcurlapi.h:26:2: error: expected ';' after struct
}lcurl_url_t;
 ^
 ;
./lcurlapi.h:22:1: warning: typedef requires a name [-Wmissing-declarations]
typedef struct lcurl_url_tag {
^~~~~~~
1 warning and 1 error generated.
make: *** [lceasy.o] Error 1

Release new version

Lua-cURL 0.3.1

Add:

  • Support Lua 5.3
  • Support socket_action interface (see uvwget example)
  • lcurl handles supptort custom userdata (setdata/getdata methods)

Fix:

  • cURLv3 multi:info_read returns lcurl handle instead cURLv3
  • iterator for Multi handle returns handles of correct types

R=@msva

undefined symbol: lcurl_mime_set_lua

my hello.lua file:

local cURL = require("cURL")

When I try to run lua hello.lua, it has error:

lua: error loading module 'lcurl' from file '/home/tk/.luarocks/lib/lua/5.3/lcurl.so':
        /home/tk/.luarocks/lib/lua/5.3/lcurl.so: undefined symbol: lcurl_mime_set_lua
stack traceback:
        [C]: in ?
        [C]: in function 'require'
        /home/tk/.luarocks/share/lua/5.3/cURL.lua:11: in main chunk
        [C]: in function 'require'
        hello.lua:12: in main chunk
        [C]: in ?

My lua-curl package is installed from luarocks install --local lua-curl

My environment:
LuaRocks 2.4.4
Lua version: 5.3

Upper case module name issue

Would it be possible to rename cURL to curl in the require() calls and filenames?
As some OS are case sensitive wrt filenames and some are not this results in system-dependent behaviour. It's also less confusing to have everything lowercase, it's the common practice for Lua modules, and it makes life easier for writers of package managers.

Error loading module lcurl on Lubuntu 18.04 with version 0.3.8-1

/usr/bin/lua: error loading module 'lcurl' from file '/usr/local/lib/lua/5.2/lcurl.so':
/usr/local/lib/lua/5.2/lcurl.so: undefined symbol: lcurl_mime_set_lua
stack traceback:
[C]: in ?
[C]: in function 'require'
/usr/local/share/lua/5.2/cURL.lua:11: in main chunk
[C]: in function 'require'

64 bit system

Implement `add_stream` for curl.form class.

I think we need strict use form with stream only with one easy handle.
And we need specify this handle when call add_stream.
In other cases we can write this code:

--- suppose 200 - stream length
form = curl.form():add_stream("text.html", 200)

-- We can not detect in callback easy hadle
c1 = curl.easy():setopt_httppost(form):setopt_readfunction(...)
c2 = curl.easy():setopt_httppost(form):setopt_readfunction(...)

m = curl.multi()
  :add_handle(c1)
  :add_handle(c2)

m:perform()

So interface should be `add_stream(name, length, easy [, headers])

Support CURLOPT_ALTSVC

This options marked as experemental in 7.64.1.
So I will wait until it will be released because I have no much time to track status of this feature.

Does not build on Ubuntu Linux 10.04LTS

I cannot manage to build it on Ubuntu 10.04LTS via Luarock (but I suspect it is not a Luarock issue).

It this version of libcurl unsupported?

sp@ubuntu1040lts:~/luarocks/bin$ ./luarocks install lua-curl
Installing https://rocks.moonscript.org/lua-curl-0.3.1-1.src.rock...
Using https://rocks.moonscript.org/lua-curl-0.3.1-1.src.rock... switching to 'build' mode
Archive:  v0.3.1.zip
40695b42648253f2e0b7466256ac292ec37c4602
...
gcc -O2 -fPIC -I/home/sp/luajit/include/lua5.1 -c src/l52util.c -o src/l52util.o -I/usr/include
gcc -O2 -fPIC -I/home/sp/luajit/include/lua5.1 -c src/lceasy.c -o src/lceasy.o -I/usr/include
gcc -O2 -fPIC -I/home/sp/luajit/include/lua5.1 -c src/lcerror.c -o src/lcerror.o -I/usr/include
gcc -O2 -fPIC -I/home/sp/luajit/include/lua5.1 -c src/lchttppost.c -o src/lchttppost.o -I/usr/include
gcc -O2 -fPIC -I/home/sp/luajit/include/lua5.1 -c src/lcurl.c -o src/lcurl.o -I/usr/include
src/lcurl.c:173:28: error: ‘CURLGSSAPI_DELEGATION_NONE’ undeclared here (not in a function)
 #define FLG_ENTRY(N) { #N, CURL##N },
                            ^
src/lcflags.h:48:1: note: in expansion of macro ‘FLG_ENTRY’
 FLG_ENTRY(GSSAPI_DELEGATION_NONE          )
 ^
src/lcurl.c:173:28: error: ‘CURLGSSAPI_DELEGATION_POLICY_FLAG’ undeclared here (not in a function)
 #define FLG_ENTRY(N) { #N, CURL##N },
                            ^
src/lcflags.h:49:1: note: in expansion of macro ‘FLG_ENTRY’
 FLG_ENTRY(GSSAPI_DELEGATION_POLICY_FLAG   )
 ^
src/lcurl.c:173:28: error: ‘CURLGSSAPI_DELEGATION_FLAG’ undeclared here (not in a function)
 #define FLG_ENTRY(N) { #N, CURL##N },
                            ^
src/lcflags.h:50:1: note: in expansion of macro ‘FLG_ENTRY’
 FLG_ENTRY(GSSAPI_DELEGATION_FLAG          )
 ^

Error: Build error: Failed compiling object src/lcurl.o

sp@ubuntu1040lts:~/luarocks/bin$ dpkg -l | grep curl
ii  curl                                7.19.7-1ubuntu1.11                  Get a file from an HTTP, HTTPS or FTP server
ii  gnupg-curl                          1.4.10-2ubuntu1.8                   GNU privacy guard - a free PGP replacement (
ii  libcurl3                            7.19.7-1ubuntu1.11                  Multi-protocol file transfer library (OpenSS
ii  libcurl3-gnutls                     7.19.7-1ubuntu1.11                  Multi-protocol file transfer library (GnuTLS
ii  libcurl4-openssl-dev                7.19.7-1ubuntu1.11                  Development files and documentation for libc
ii  python-pycurl                       7.19.0-3                            Python bindings to libcurl

memory leak, easy gc not work.

If make h:close(), it work better, but less memory leak.

local cURL = require("lcurl")

c  = cURL.easy()
  :setopt_url("http://www.lua.org/")
  :setopt_writefunction(function() end)

c1  = cURL.easy()
  :setopt_url("http://www.lua.org/")
  :setopt_writefunction(function() end)

m = cURL.multi()
  :add_handle(c)
  :add_handle(c1)

while m:perform() > 0 do
  m:wait()  
  local h,b,e = m:info_read()
  if (h~=0) then
    if(b==true) then
      print('OK')
      m:remove_handle (h)
      --h:close()
      h = nil

      local c2  = cURL.easy()
      :setopt_url("http://www.lua.org/")
      :setopt_writefunction(function() end)
      m:add_handle(c2)

    else
      print('ERR',e)
    end
  end
end

print(m:info_read())

Fail build on centos 6.5(64bits)

curl --version

curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

gcc -O2 -fPIC -I/usr/local/include/luajit-2.0 -c src/l52util.c -o src/l52util.o -I/usr/include
gcc -O2 -fPIC -I/usr/local/include/luajit-2.0 -c src/lceasy.c -o src/lceasy.o -I/usr/include
In file included from src/lceasy.c:230:
src/lcopteasy.h: In function 'lcurl_easy_set_WILDCARDMATCH':
src/lcopteasy.h:33: error: 'CURLOPT_WILDCARDMATCH' undeclared (first use in this function)
src/lcopteasy.h:33: error: (Each undeclared identifier is reported only once
src/lcopteasy.h:33: error: for each function it appears in.)
src/lcopteasy.h: In function 'lcurl_easy_set_TLSAUTH_USERNAME':
src/lcopteasy.h:77: error: 'CURLOPT_TLSAUTH_USERNAME' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_TLSAUTH_PASSWORD':
src/lcopteasy.h:78: error: 'CURLOPT_TLSAUTH_PASSWORD' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_TLSAUTH_TYPE':
src/lcopteasy.h:79: error: 'CURLOPT_TLSAUTH_TYPE' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_ACCEPT_ENCODING':
src/lcopteasy.h:89: error: 'CURLOPT_ACCEPT_ENCODING' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_TRANSFER_ENCODING':
src/lcopteasy.h:90: error: 'CURLOPT_TRANSFER_ENCODING' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_MAIL_FROM':
src/lcopteasy.h:121: error: 'CURLOPT_MAIL_FROM' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_MAIL_RCPT':
src/lcopteasy.h:122: error: 'CURLOPT_MAIL_RCPT' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_FTP_USE_PRET':
src/lcopteasy.h:137: error: 'CURLOPT_FTP_USE_PRET' undeclared (first use in this function)
src/lcopteasy.h: In function 'lcurl_easy_set_RESOLVE':
src/lcopteasy.h:178: error: 'CURLOPT_RESOLVE' undeclared (first use in this function)
In file included from src/lceasy.c:364:
src/lcinfoeasy.h: In function 'lcurl_easy_get_PRIMARY_PORT':
src/lcinfoeasy.h:30: error: 'CURLINFO_PRIMARY_PORT' undeclared (first use in this function)
src/lcinfoeasy.h: In function 'lcurl_easy_get_LOCAL_IP':
src/lcinfoeasy.h:31: error: 'CURLINFO_LOCAL_IP' undeclared (first use in this function)
src/lcinfoeasy.h: In function 'lcurl_easy_get_LOCAL_PORT':
src/lcinfoeasy.h:32: error: 'CURLINFO_LOCAL_PORT' undeclared (first use in this function)
src/lcinfoeasy.h: In function 'lcurl_easy_get_RTSP_SESSION_ID':
src/lcinfoeasy.h:37: error: 'CURLINFO_RTSP_SESSION_ID' undeclared (first use in this function)
src/lcinfoeasy.h: In function 'lcurl_easy_get_RTSP_CLIENT_CSEQ':
src/lcinfoeasy.h:38: error: 'CURLINFO_RTSP_CLIENT_CSEQ' undeclared (first use in this function)
src/lcinfoeasy.h: In function 'lcurl_easy_get_RTSP_SERVER_CSEQ':
src/lcinfoeasy.h:39: error: 'CURLINFO_RTSP_SERVER_CSEQ' undeclared (first use in this function)
src/lcinfoeasy.h: In function 'lcurl_easy_get_RTSP_CSEQ_RECV':
src/lcinfoeasy.h:40: error: 'CURLINFO_RTSP_CSEQ_RECV' undeclared (first use in this function)
src/lceasy.c: In function 'lcurl_read_callback':
src/lceasy.c:509: warning: incompatible implicit declaration of built-in function 'memcpy'
src/lceasy.c:513: warning: incompatible implicit declaration of built-in function 'memcpy'
src/lceasy.c:541: warning: incompatible implicit declaration of built-in function 'memcpy'
In file included from src/lceasy.c:649:
src/lcopteasy.h: In function 'lcurl_easy_setopt':
src/lcopteasy.h:33: error: 'CURLOPT_WILDCARDMATCH' undeclared (first use in this function)
src/lcopteasy.h:77: error: 'CURLOPT_TLSAUTH_USERNAME' undeclared (first use in this function)
src/lcopteasy.h:78: error: 'CURLOPT_TLSAUTH_PASSWORD' undeclared (first use in this function)
src/lcopteasy.h:79: error: 'CURLOPT_TLSAUTH_TYPE' undeclared (first use in this function)
src/lcopteasy.h:89: error: 'CURLOPT_ACCEPT_ENCODING' undeclared (first use in this function)
src/lcopteasy.h:90: error: 'CURLOPT_TRANSFER_ENCODING' undeclared (first use in this function)
src/lcopteasy.h:121: error: 'CURLOPT_MAIL_FROM' undeclared (first use in this function)
src/lcopteasy.h:122: error: 'CURLOPT_MAIL_RCPT' undeclared (first use in this function)
src/lcopteasy.h:137: error: 'CURLOPT_FTP_USE_PRET' undeclared (first use in this function)
src/lcopteasy.h:178: error: 'CURLOPT_RESOLVE' undeclared (first use in this function)
src/lceasy.c:660: error: 'CURLE_UNKNOWN_OPTION' undeclared (first use in this function)
In file included from src/lceasy.c:670:
src/lcinfoeasy.h: In function 'lcurl_easy_getinfo':
src/lcinfoeasy.h:30: error: 'CURLINFO_PRIMARY_PORT' undeclared (first use in this function)
src/lcinfoeasy.h:31: error: 'CURLINFO_LOCAL_IP' undeclared (first use in this function)
src/lcinfoeasy.h:32: error: 'CURLINFO_LOCAL_PORT' undeclared (first use in this function)
src/lcinfoeasy.h:37: error: 'CURLINFO_RTSP_SESSION_ID' undeclared (first use in this function)
src/lcinfoeasy.h:38: error: 'CURLINFO_RTSP_CLIENT_CSEQ' undeclared (first use in this function)
src/lcinfoeasy.h:39: error: 'CURLINFO_RTSP_SERVER_CSEQ' undeclared (first use in this function)
src/lcinfoeasy.h:40: error: 'CURLINFO_RTSP_CSEQ_RECV' undeclared (first use in this function)
src/lceasy.c:674: error: 'CURLE_UNKNOWN_OPTION' undeclared (first use in this function)
In file included from src/lceasy.c:712:
src/lcopteasy.h: At top level:
src/lcopteasy.h:33: error: 'CURLOPT_WILDCARDMATCH' undeclared here (not in a function)
src/lcopteasy.h:77: error: 'CURLOPT_TLSAUTH_USERNAME' undeclared here (not in a function)
src/lcopteasy.h:78: error: 'CURLOPT_TLSAUTH_PASSWORD' undeclared here (not in a function)
src/lcopteasy.h:79: error: 'CURLOPT_TLSAUTH_TYPE' undeclared here (not in a function)
src/lcopteasy.h:89: error: 'CURLOPT_ACCEPT_ENCODING' undeclared here (not in a function)
src/lcopteasy.h:90: error: 'CURLOPT_TRANSFER_ENCODING' undeclared here (not in a function)
src/lcopteasy.h:121: error: 'CURLOPT_MAIL_FROM' undeclared here (not in a function)
src/lcopteasy.h:122: error: 'CURLOPT_MAIL_RCPT' undeclared here (not in a function)
src/lcopteasy.h:137: error: 'CURLOPT_FTP_USE_PRET' undeclared here (not in a function)
src/lcopteasy.h:178: error: 'CURLOPT_RESOLVE' undeclared here (not in a function)
In file included from src/lceasy.c:724:
src/lcinfoeasy.h:30: error: 'CURLINFO_PRIMARY_PORT' undeclared here (not in a function)
src/lcinfoeasy.h:31: error: 'CURLINFO_LOCAL_IP' undeclared here (not in a function)
src/lcinfoeasy.h:32: error: 'CURLINFO_LOCAL_PORT' undeclared here (not in a function)
src/lcinfoeasy.h:37: error: 'CURLINFO_RTSP_SESSION_ID' undeclared here (not in a function)
src/lcinfoeasy.h:38: error: 'CURLINFO_RTSP_CLIENT_CSEQ' undeclared here (not in a function)
src/lcinfoeasy.h:39: error: 'CURLINFO_RTSP_SERVER_CSEQ' undeclared here (not in a function)
src/lcinfoeasy.h:40: error: 'CURLINFO_RTSP_CSEQ_RECV' undeclared here (not in a function)

Support CURLOPT_ERRORBUFFER

Problems to solve

  1. Where and when allocate error buffer.
    Options
  • part of lcurl_easy_t structure
  • full userdata and store ref/ptr to it internally
  • new separate object lcurl_error_buffer_t and provide Lua API for it.
  1. How to assign this option from Lua code (set to 0/1/true/false/nil/null)
  2. Does it make sence allows to increase buffer size over than CURL_ERROR_SIZE? From the doc The buffer must be at least CURL_ERROR_SIZE bytes big.
  3. Provide API for error object to access to information from associated buffer.

luarocks does not work on windows when trying to install luacurl

C:\Windows\System32>luarocks install Lua-cURL --server=https://luarocks.org/dev
C:\Program Files (x86)\Lua\5.1\lua: C:\Program Files (x86)\Lua\5.1\lua/luarocks\fs.lua:37: attempt to concatenate local
'loaded_platform' (a nil value)
stack traceback:
C:\Program Files (x86)\Lua\5.1\lua/luarocks\fs.lua:37: in main chunk
[C]: in function 'require'
...rogram Files (x86)\Lua\5.1\lua\luarocks\command_line.lua:7: in main chunk
[C]: in function 'require'
C:\Program Files (x86)\Lua\5.1\luarocks.lua:3: in main chunk
[C]: at 0x004020f0

What do you think the problem might be?

build warning on macOS

cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/l52util.o src/l52util.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lchttppost.o src/lchttppost.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
src/lchttppost.c:119:12: warning: unused function 'lcurl_hpost_to_s' [-Wunused-function]
static int lcurl_hpost_to_s(lua_State *L){
           ^
1 warning generated.
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lcurl.o src/lcurl.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lceasy.o src/lceasy.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
src/lceasy.c:118:15: warning: unused variable 'code' [-Wunused-variable]
    CURLMcode code = lcurl__multi_remove_handle(L, p->multi, p);
              ^
src/lceasy.c:1703:3: warning: unused typedef 'static_assert_failed_at_line_1703' [-Wunused-local-typedef]
  LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, L,       lcurl_hpost_stream_t, L);
  ^
src/lcutils.h:36:48: note: expanded from macro 'LCURL_ASSERT_SAME_OFFSET'
#define LCURL_ASSERT_SAME_OFFSET(a, am, b, bm) LCURL_STATIC_ASSERT( (offsetof(a,am)) == (offsetof(b,bm)) )
                                               ^
src/lcutils.h:33:48: note: expanded from macro 'LCURL_STATIC_ASSERT'
#define LCURL_STATIC_ASSERT(expr) typedef char LCURL_CONCAT_STATIC_ASSERT_IMPL_(static_assert_failed_at...
                                               ^
src/lcutils.h:31:48: note: expanded from macro 'LCURL_CONCAT_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT_STATIC_ASSERT_IMPL_(x, y) LCURL_CONCAT1_STATIC_ASSERT_IMPL_ (x, y)
                                               ^
src/lcutils.h:32:49: note: expanded from macro 'LCURL_CONCAT1_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT1_STATIC_ASSERT_IMPL_(x, y) x##y
                                                ^
<scratch space>:158:1: note: expanded from here
static_assert_failed_at_line_1703
^
src/lceasy.c:1702:3: warning: unused typedef 'static_assert_failed_at_line_1702' [-Wunused-local-typedef]
  LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, magic,   lcurl_hpost_stream_t, magic);
  ^
src/lcutils.h:36:48: note: expanded from macro 'LCURL_ASSERT_SAME_OFFSET'
#define LCURL_ASSERT_SAME_OFFSET(a, am, b, bm) LCURL_STATIC_ASSERT( (offsetof(a,am)) == (offsetof(b,bm)) )
                                               ^
src/lcutils.h:33:48: note: expanded from macro 'LCURL_STATIC_ASSERT'
#define LCURL_STATIC_ASSERT(expr) typedef char LCURL_CONCAT_STATIC_ASSERT_IMPL_(static_assert_failed_at...
                                               ^
src/lcutils.h:31:48: note: expanded from macro 'LCURL_CONCAT_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT_STATIC_ASSERT_IMPL_(x, y) LCURL_CONCAT1_STATIC_ASSERT_IMPL_ (x, y)
                                               ^
src/lcutils.h:32:49: note: expanded from macro 'LCURL_CONCAT1_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT1_STATIC_ASSERT_IMPL_(x, y) x##y
                                                ^
<scratch space>:156:1: note: expanded from here
static_assert_failed_at_line_1702
^
src/lceasy.c:1706:3: warning: unused typedef 'static_assert_failed_at_line_1706' [-Wunused-local-typedef]
  LCURL_ASSERT_SAME_FIELD_SIZE(lcurl_easy_t, rbuffer, lcurl_hpost_stream_t, rbuffer);
  ^
src/lcutils.h:37:52: note: expanded from macro 'LCURL_ASSERT_SAME_FIELD_SIZE'
#define LCURL_ASSERT_SAME_FIELD_SIZE(a, am, b, bm) LCURL_ASSERT_SAME_SIZE(((a*)0)->am, ((b*)0)->bm)
                                                   ^
src/lcutils.h:35:38: note: expanded from macro 'LCURL_ASSERT_SAME_SIZE'
#define LCURL_ASSERT_SAME_SIZE(a, b) LCURL_STATIC_ASSERT( sizeof(a) == sizeof(b) )
                                     ^
src/lcutils.h:33:48: note: expanded from macro 'LCURL_STATIC_ASSERT'
#define LCURL_STATIC_ASSERT(expr) typedef char LCURL_CONCAT_STATIC_ASSERT_IMPL_(static_assert_failed_at...
                                               ^
src/lcutils.h:31:48: note: expanded from macro 'LCURL_CONCAT_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT_STATIC_ASSERT_IMPL_(x, y) LCURL_CONCAT1_STATIC_ASSERT_IMPL_ (x, y)
                                               ^
src/lcutils.h:32:49: note: expanded from macro 'LCURL_CONCAT1_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT1_STATIC_ASSERT_IMPL_(x, y) x##y
                                                ^
<scratch space>:164:1: note: expanded from here
static_assert_failed_at_line_1706
^
src/lceasy.c:1704:3: warning: unused typedef 'static_assert_failed_at_line_1704' [-Wunused-local-typedef]
  LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, rd,      lcurl_hpost_stream_t, rd);
  ^
src/lcutils.h:36:48: note: expanded from macro 'LCURL_ASSERT_SAME_OFFSET'
#define LCURL_ASSERT_SAME_OFFSET(a, am, b, bm) LCURL_STATIC_ASSERT( (offsetof(a,am)) == (offsetof(b,bm)) )
                                               ^
src/lcutils.h:33:48: note: expanded from macro 'LCURL_STATIC_ASSERT'
#define LCURL_STATIC_ASSERT(expr) typedef char LCURL_CONCAT_STATIC_ASSERT_IMPL_(static_assert_failed_at...
                                               ^
src/lcutils.h:31:48: note: expanded from macro 'LCURL_CONCAT_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT_STATIC_ASSERT_IMPL_(x, y) LCURL_CONCAT1_STATIC_ASSERT_IMPL_ (x, y)
                                               ^
src/lcutils.h:32:49: note: expanded from macro 'LCURL_CONCAT1_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT1_STATIC_ASSERT_IMPL_(x, y) x##y
                                                ^
<scratch space>:160:1: note: expanded from here
static_assert_failed_at_line_1704
^
src/lceasy.c:1705:3: warning: unused typedef 'static_assert_failed_at_line_1705' [-Wunused-local-typedef]
  LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, rbuffer, lcurl_hpost_stream_t, rbuffer);
  ^
src/lcutils.h:36:48: note: expanded from macro 'LCURL_ASSERT_SAME_OFFSET'
#define LCURL_ASSERT_SAME_OFFSET(a, am, b, bm) LCURL_STATIC_ASSERT( (offsetof(a,am)) == (offsetof(b,bm)) )
                                               ^
src/lcutils.h:33:48: note: expanded from macro 'LCURL_STATIC_ASSERT'
#define LCURL_STATIC_ASSERT(expr) typedef char LCURL_CONCAT_STATIC_ASSERT_IMPL_(static_assert_failed_at...
                                               ^
src/lcutils.h:31:48: note: expanded from macro 'LCURL_CONCAT_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT_STATIC_ASSERT_IMPL_(x, y) LCURL_CONCAT1_STATIC_ASSERT_IMPL_ (x, y)
                                               ^
src/lcutils.h:32:49: note: expanded from macro 'LCURL_CONCAT1_STATIC_ASSERT_IMPL_'
#define LCURL_CONCAT1_STATIC_ASSERT_IMPL_(x, y) x##y
                                                ^
<scratch space>:162:1: note: expanded from here
static_assert_failed_at_line_1705
^
6 warnings generated.
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lcmulti.o src/lcmulti.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lcutils.o src/lcutils.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lcerror.o src/lcerror.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
cc -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -c -o src/lcshare.o src/lcshare.c
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
cc -shared -I/Users/zhaozg/iOS/include/luajit-2.1 -DCURL_STATICLIB -I/Users/zhaozg/iOS/include  -O2 -g -pipe -fPIC -undefined dynamic_lookup  -Wall -Wno-unused-value -DPTHREADS  -o lcurl.so src/l52util.o src/lchttppost.o src/lcurl.o src/lceasy.o src/lcmulti.o src/lcutils.o src/lcerror.o src/lcshare.o -ldl -L/Users/zhaozg/iOS/lib -l

machine info

MacBook-Air:Lua-cURLv3 zhaozg$ uname -a
Darwin MacBook-Air 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

Release v0.3.3

  • Change. Use string value to represent error category.
  • Fix. call all callback from coroutine where perform was called.
  • Add. Support cURL 7.48.0

Running the script post_mime.lua Error

When i running post_mime.lua ,there is a erroe: post_mime.lua:8: attempt to call method 'mime' (a nil value) . What should I do to solve this problem,thank.

ubuntu@4D:~/Lua-cURLv3-master/examples/cURLv3$ qlua post_mime.lua
qlua: post_mime.lua:8: attempt to call method 'mime' (a nil value)
stack traceback:
[C]: in function 'mime'
post_mime.lua:8: in main chunk

Unable to compile lcerror.c

gcc -O2 -fPIC -I/home/kyson/workspace/devlop/release/sdk/ar71xx/staging_dir/hostpkg/include -c src/lcerror.c -o src/lcerror.o -I/mnt/sda1/install/lua-5.1.5/src
src/lcerr_easy.h: In function 'lcurl_err_easy_mnemo':
src/lcerror.c:32:22: error: duplicate case value
#define ERR_ENTRY(E) case CURLE_##E: return #E;
^
src/lcerr_easy.h:74:1: note: in expansion of macro 'ERR_ENTRY'
ERR_ENTRY ( SSL_CACERT )
^
src/lcerror.c:32:22: error: previously used here
#define ERR_ENTRY(E) case CURLE_##E: return #E;
^
src/lcerr_easy.h:65:1: note: in expansion of macro 'ERR_ENTRY'
ERR_ENTRY ( PEER_FAILED_VERIFICATION )
^

Please can someone help?

install error typedef‘lcurl_multi_t’

why my install is error?
[root@lua bin]# ./luarocks install Lua-cURL --server=https://rocks.moonscript.org/dev
Installing https://rocks.moonscript.org/dev/lua-curl-scm-0.rockspec
gcc -O2 -fPIC -I/www/wdlinux/openresty/luajit/include/luajit-2.1 -c src/l52util.c -o src/l52util.o -I/usr/include
gcc -O2 -fPIC -I/www/wdlinux/openresty/luajit/include/luajit-2.1 -c src/lceasy.c -o src/lceasy.o -I/usr/include
In file included from src/lceasy.c:17:
src/lcmulti.h:24: 错误:typedef‘lcurl_multi_t’重定义
src/lceasy.h:38: 附注:‘lcurl_multi_t’的上一个声明在此

Error: Build error: Failed compiling object src/lceasy.o
[root@lua bin]#

Release variant of library

For now I see three variants of release:

  1. Release lcurl library as it is now (with optional intall lcurl.cURL module as cURL)
  2. Release lcurl and move lcurl.cURL module to separate project (maby as replacement) for Lua-cURL project)
  3. Replace Lua-cURL module with this one.

What I think:

  1. We got one more cURL binding.
  2. We have low level binding lcurl and high level cURL (pure Lua module).
  3. Incompatibility with old version.

How can I set ssl key passwd?

I merged my key and cert pem files into one file for apple push notification. I want to set the password for the key, but i cannot find setopt_sslkeypasswd.
Is is missing or is there any other way to do this?

Can't make Lua cURL v3 initiate a GET query

I can't make Lua cURL v3 initiate a GET query using the following code:

  local c = curl.easy{                          
         url = su,
         httpget = true,
         [curl.OPT_USERPWD] = l..":"..p,
         httpheader = { "Content-Type: application/x-www-form-urlencoded"; };
         postfields = 'params={ "token": "'..st..'" }';
     } 

or

  local c = curl.easy{                          
         url = su,
         [curl.OPT_HTTPGET] = true,
         [curl.OPT_USERPWD] = l..":"..p,
         httpheader = { "Content-Type: application/x-www-form-urlencoded"; };
         postfields = 'params={ "token": "'..st..'" }';
     } 

POST works fine though.

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.