Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,45 @@ language: c

sudo: false

env:
global:
- LUAROCKS=2.2.2
matrix:
- LUA=lua5.1
- LUA=lua5.2
- LUA=lua5.3
- LUA=luajit
matrix:
include:
- compiler: ": Lua51"
env: LUA="lua 5.1"
- compiler: ": Lua52"
env: LUA="lua 5.2"
- compiler: ": Lua53"
env: LUA="lua 5.3"
- compiler: ": LuaJIT20"
env: LUA="luajit 2.0"
- compiler: ": LuaJIT21"
env: LUA="luajit 2.1"

cache:
directories:
- here
- $HOME/.cache/pip

branches:
only:
- master

before_install:
- source .travis/setenv_lua.sh
- export CC=gcc
- pip install --user cpp-coveralls
- luarocks install luafilesystem --from=https://rocks.moonscript.org/dev
- luarocks install luacov-coveralls
- luarocks install lunitx
- luarocks install dkjson --deps-mode=none
- pip install --user hererocks
- hererocks here -r^ --$LUA
- export PATH=$PATH:$PWD/here/bin

install:
- luarocks make rockspecs/lua-curl-scm-0.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"

script:
before_script:
- luarocks show luacov-coveralls || luarocks install luacov-coveralls
- luarocks show lunitx || luarocks install lunitx
- luarocks show luafilesystem || luarocks install luafilesystem
- luarocks show dkjson || luarocks install dkjson --deps-mode=none

script:
- cd test
- lua -e "print(require 'cURL.utils'.find_ca_bundle())"
- lunit.sh test_easy.lua
Expand All @@ -37,7 +51,7 @@ script:

after_success:
- coveralls -b .. -r .. --dump c.report.json
- luacov-coveralls -j c.report.json
- luacov-coveralls -j c.report.json -v

notifications:
email:
Expand Down
15 changes: 0 additions & 15 deletions .travis/platform.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .travis/setenv_lua.sh

This file was deleted.

122 changes: 0 additions & 122 deletions .travis/setup_lua.sh

This file was deleted.

25 changes: 20 additions & 5 deletions src/lceasy.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ int lcurl_easy_create(lua_State *L, int error_mode){

p->err_mode = error_mode;
if(!p->curl) return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, CURLE_FAILED_INIT);
p->L = L;

p->magic = LCURL_EASY_MAGIC;
p->L = NULL;
p->post = NULL;
p->storage = lcurl_storage_init(L);
p->wr.cb_ref = p->wr.ud_ref = LUA_NOREF;
p->rd.cb_ref = p->rd.ud_ref = LUA_NOREF;
Expand Down Expand Up @@ -115,6 +118,12 @@ static int lcurl_easy_perform(lua_State *L){

assert(p->rbuffer.ref == LUA_NOREF);

// store reference to current coroutine to callbacks
p->L = L;
if(p->post){
p->post->L = L;
}

code = curl_easy_perform(p->curl);

if(p->rbuffer.ref != LUA_NOREF){
Expand Down Expand Up @@ -308,6 +317,8 @@ static int lcurl_easy_set_HTTPPOST(lua_State *L){
curl_easy_setopt(p->curl, CURLOPT_READFUNCTION, lcurl_hpost_read_callback);
}

p->post = post;

lua_settop(L, 1);
return 1;
}
Expand Down Expand Up @@ -420,6 +431,8 @@ static int lcurl_easy_unset_HTTPPOST(lua_State *L){
lcurl_storage_remove_i(L, p->storage, CURLOPT_HTTPPOST);
}

p->post = NULL;

lua_settop(L, 1);
return 1;
}
Expand Down Expand Up @@ -758,12 +771,15 @@ static size_t lcurl_read_callback(lua_State *L,

static size_t lcurl_easy_read_callback(char *buffer, size_t size, size_t nitems, void *arg){
lcurl_easy_t *p = arg;
if(p->magic == LCURL_HPOST_STREAM_MAGIC){
return lcurl_hpost_read_callback(buffer, size, nitems, arg);
}
return lcurl_read_callback(p->L, &p->rd, &p->rbuffer, buffer, size, nitems);
}

static size_t lcurl_hpost_read_callback(char *buffer, size_t size, size_t nitems, void *arg){
lcurl_hpost_stream_t *p = arg;
return lcurl_read_callback(p->L, &p->rd, &p->rbuffer, buffer, size, nitems);
return lcurl_read_callback(*p->L, &p->rd, &p->rbuffer, buffer, size, nitems);
}

static int lcurl_easy_set_READFUNCTION(lua_State *L){
Expand Down Expand Up @@ -1035,9 +1051,8 @@ void lcurl_easy_initlib(lua_State *L, int nup){
/* Hack. We ensure that lcurl_easy_t and lcurl_hpost_stream_t
compatiable for readfunction
*/
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, L) == offsetof(lcurl_hpost_stream_t, L));
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, rd) == offsetof(lcurl_hpost_stream_t, rd));
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, rbuffer) == offsetof(lcurl_hpost_stream_t, rbuffer));
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, magic) == offsetof(lcurl_hpost_stream_t, magic));
LCURL_STATIC_ASSERT(sizeof(((lcurl_easy_t*)0)->magic) == sizeof(((lcurl_hpost_stream_t*)0)->magic));

if(!lutil_createmetap(L, LCURL_EASY, lcurl_easy_methods, nup))
lua_pop(L, nup);
Expand Down
7 changes: 7 additions & 0 deletions src/lceasy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "lcurl.h"
#include "lcutils.h"
#include "lchttppost.h"

#define LCURL_LST_INDEX(N) LCURL_##N##_LIST,
#define LCURL_STR_INDEX(N)
Expand All @@ -32,11 +33,17 @@ enum {
#undef LCURL_LNG_INDEX
#undef OPT_ENTRY

#define LCURL_EASY_MAGIC 0xEA

typedef struct lcurl_easy_tag{
unsigned char magic;

lua_State *L;
lcurl_callback_t rd;
lcurl_read_buffer_t rbuffer;

lcurl_hpost_t *post;

CURL *curl;
int storage;
int lists[LCURL_LIST_COUNT];
Expand Down
3 changes: 2 additions & 1 deletion src/lchttppost.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static lcurl_hpost_stream_t *lcurl_hpost_stream_add(lua_State *L, lcurl_hpost_t
lcurl_hpost_stream_t *stream = malloc(sizeof(lcurl_hpost_stream_t));
if(!stream) return NULL;

stream->L = L;
stream->magic = LCURL_HPOST_STREAM_MAGIC;
stream->L = &p->L;
stream->rbuffer.ref = LUA_NOREF;
stream->rd.cb_ref = stream->rd.ud_ref = LUA_NOREF;
stream->next = NULL;
Expand Down
7 changes: 6 additions & 1 deletion src/lchttppost.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
#include "lcutils.h"
#include <stdlib.h>

#define LCURL_HPOST_STREAM_MAGIC 0xAA

typedef struct lcurl_hpost_stream_tag{
lua_State *L;
unsigned char magic;

lua_State **L;
lcurl_callback_t rd;
lcurl_read_buffer_t rbuffer;
struct lcurl_hpost_stream_tag *next;
}lcurl_hpost_stream_t;

typedef struct lcurl_hpost_tag{
lua_State *L;
struct curl_httppost *post;
struct curl_httppost *last;
int storage;
Expand Down
15 changes: 15 additions & 0 deletions src/lcmulti.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ static int lcurl_multi_perform(lua_State *L){
lcurl_multi_t *p = lcurl_getmulti(L);
int running_handles = 0;
CURLMcode code;

lua_settop(L, 1);
lua_rawgeti(L, LCURL_LUA_REGISTRY, p->h_ref);
lua_pushnil(L);
while(lua_next(L, 2)){
lcurl_easy_t *e = lcurl_geteasy_at(L, -1);
e->L = L;
if(e->post){
e->post->L = L;
}
lua_pop(L, 1);
}

lua_settop(L, 1);

while((code = curl_multi_perform(p->curl, &running_handles)) == CURLM_CALL_MULTI_PERFORM);
if(code != CURLM_OK){
lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_MULTI, code);
Expand Down
2 changes: 1 addition & 1 deletion test/.luacov
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ return {
-- configuration for luacov-coveralls reporter
coveralls = {
pathcorrect = {
{"/usr/local/share/lua/5.[123]", "src/lua"};
{"^.-[/\\]share[/\\]lua[/\\]5.%d", "src/lua"};
},
},
}
2 changes: 1 addition & 1 deletion test/test_curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function test_add_handle()
end
end

m = assert_equal(m, m:add_handle(next_easy()))
assert_equal(m, m:add_handle(next_easy()))

for data, type, easy in m:iperform() do

Expand Down
Loading