Skip to content

Commit 554c642

Browse files
authored
Merge branch 'master' into master
2 parents 6facbae + cb29348 commit 554c642

File tree

5 files changed

+313
-91
lines changed

5 files changed

+313
-91
lines changed

appveyor.yml

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
version: 0.3.2.{build}
2-
3-
os:
4-
- Windows Server 2012 R2
5-
6-
shallow_clone: true
7-
8-
environment:
9-
LR_EXTERNAL: c:\external
10-
CURL_VER: 7.65.1
11-
12-
matrix:
13-
- LUA: "lua 5.1"
14-
- LUA: "lua 5.2"
15-
- LUA: "lua 5.3"
16-
17-
platform:
18-
- x64
19-
- x86
20-
# - mingw
21-
22-
cache:
23-
- c:\hererocks -> appveyor.yml
24-
- c:\external -> appveyor.yml
25-
26-
install:
27-
- set PATH=C:\Python27\Scripts;%LR_EXTERNAL%;%PATH%
28-
- if /I "%platform%"=="x86" set HR_TARGET=vs_32
29-
- if /I "%platform%"=="x64" set HR_TARGET=vs_64
30-
- if /I "%platform%"=="mingw" set HR_TARGET=mingw
31-
- if /I "%platform%"=="mingw" set PATH=C:\MinGW\bin;%PATH%
32-
- if not exist "%LR_EXTERNAL%" (
33-
mkdir "%LR_EXTERNAL%" &&
34-
mkdir "%LR_EXTERNAL%\lib" &&
35-
mkdir "%LR_EXTERNAL%\include"
36-
)
37-
- if not exist c:\hererocks (
38-
pip install hererocks &&
39-
hererocks c:\hererocks --%LUA% --target %HR_TARGET% -rlatest
40-
)
41-
- call c:\hererocks\bin\activate
42-
- luarocks show luarocks-fetch-gitrec >nul 2>&1 || luarocks install luarocks-fetch-gitrec
43-
44-
before_build:
45-
# external deps
46-
- call .appveyor\install_curl.bat
47-
48-
build_script:
49-
- set LUA_CURL_VER=scm-0
50-
- if "%APPVEYOR_REPO_TAG%" == "true" set LUA_CURL_VER=%APPVEYOR_REPO_TAG_NAME:~1%-1
51-
- echo "Making lua-curl-%LUA_CURL_VER% ..."
52-
- luarocks make rockspecs/lua-curl-%LUA_CURL_VER%.rockspec
53-
54-
before_test:
55-
# test deps
56-
- if "%LUA%"=="lua 5.1" luarocks show bit32 >nul 2>&1 || luarocks install bit32
57-
- luarocks show lunitx >nul 2>&1 || luarocks install lunitx
58-
- luarocks show dkjson >nul 2>&1 || luarocks install dkjson
59-
- luarocks show luafilesystem >nul 2>&1 || luarocks install luafilesystem
60-
- luarocks show lua-path >nul 2>&1 || luarocks install lua-path
61-
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser
62-
--server=http://luarocks.org/manifests/moteus
63-
- luarocks show pegasus-router >nul 2>&1 || luarocks install pegasus-router
64-
--server=http://luarocks.org/dev
65-
- ps: $TestServer = Start-Process lua -ArgumentList test/server.lua -RedirectStandardOutput "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt" -RedirectStandardError "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt" -PassThru
66-
- curl -s http://127.0.0.1:7090/get
67-
68-
test_script:
69-
- echo "Testing..."
70-
- cd %APPVEYOR_BUILD_FOLDER%\test
71-
- lua run.lua
72-
- lua test_pause02.c.lua
73-
- lua test_multi_callback.lua
74-
- lua test_multi_nested_callback.lua
75-
76-
after_test:
77-
- cd %APPVEYOR_BUILD_FOLDER%
78-
- .appveyor\pack_artifact.bat lua-curl bin-rock
79-
80-
on_failure:
81-
- ps: Stop-Process -Id $TestServer.Id
82-
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
83-
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
84-
85-
on_finish:
86-
- curl -s http://127.0.0.1:7090/get
87-
- ps: Stop-Process -Id $TestServer.Id
1+
version: 0.3.2.{build}
2+
3+
os:
4+
- Windows Server 2012 R2
5+
6+
shallow_clone: true
7+
8+
environment:
9+
LR_EXTERNAL: c:\external
10+
CURL_VER: 7.65.1
11+
12+
matrix:
13+
- LUA: "lua 5.1"
14+
- LUA: "lua 5.2"
15+
- LUA: "lua 5.3"
16+
17+
platform:
18+
- x64
19+
- x86
20+
# - mingw
21+
22+
cache:
23+
- c:\hererocks -> appveyor.yml
24+
- c:\external -> appveyor.yml
25+
26+
install:
27+
- set PATH=C:\Python27\Scripts;%LR_EXTERNAL%;%PATH%
28+
- if /I "%platform%"=="x86" set HR_TARGET=vs_32
29+
- if /I "%platform%"=="x64" set HR_TARGET=vs_64
30+
- if /I "%platform%"=="mingw" set HR_TARGET=mingw
31+
- if /I "%platform%"=="mingw" set PATH=C:\MinGW\bin;%PATH%
32+
- if not exist "%LR_EXTERNAL%" (
33+
mkdir "%LR_EXTERNAL%" &&
34+
mkdir "%LR_EXTERNAL%\lib" &&
35+
mkdir "%LR_EXTERNAL%\include"
36+
)
37+
- if not exist c:\hererocks (
38+
pip install hererocks &&
39+
hererocks c:\hererocks --%LUA% --target %HR_TARGET% -rlatest
40+
)
41+
- call c:\hererocks\bin\activate
42+
- luarocks show luarocks-fetch-gitrec >nul 2>&1 || luarocks install luarocks-fetch-gitrec
43+
44+
before_build:
45+
# external deps
46+
- call .appveyor\install_curl.bat
47+
48+
build_script:
49+
- set LUA_CURL_VER=scm-0
50+
- if "%APPVEYOR_REPO_TAG%" == "true" set LUA_CURL_VER=%APPVEYOR_REPO_TAG_NAME:~1%-1
51+
- echo "Making lua-curl-%LUA_CURL_VER% ..."
52+
- luarocks make rockspecs/lua-curl-%LUA_CURL_VER%.rockspec
53+
54+
before_test:
55+
# test deps
56+
- if "%LUA%"=="lua 5.1" luarocks show bit32 >nul 2>&1 || luarocks install bit32
57+
- luarocks show lunitx >nul 2>&1 || luarocks install lunitx
58+
- luarocks show dkjson >nul 2>&1 || luarocks install dkjson
59+
- luarocks show luafilesystem >nul 2>&1 || luarocks install luafilesystem
60+
- luarocks show lua-path >nul 2>&1 || luarocks install lua-path
61+
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser
62+
--server=http://luarocks.org/manifests/moteus
63+
- luarocks show pegasus-router >nul 2>&1 || luarocks install pegasus-router
64+
--server=http://luarocks.org/dev
65+
- ps: $TestServer = Start-Process lua -ArgumentList test/server.lua -RedirectStandardOutput "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt" -RedirectStandardError "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt" -PassThru
66+
- curl -s http://127.0.0.1:7090/get
67+
68+
test_script:
69+
- echo "Testing..."
70+
- cd %APPVEYOR_BUILD_FOLDER%\test
71+
- lua run.lua
72+
- lua test_pause02.c.lua
73+
- lua test_multi_callback.lua
74+
- lua test_multi_nested_callback.lua
75+
76+
after_test:
77+
- cd %APPVEYOR_BUILD_FOLDER%
78+
- .appveyor\pack_artifact.bat lua-curl bin-rock
79+
80+
on_failure:
81+
- ps: Stop-Process -Id $TestServer.Id
82+
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
83+
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
84+
85+
on_finish:
86+
- curl -s http://127.0.0.1:7090/get
87+
- ps: Stop-Process -Id $TestServer.Id

src/lceasy.c

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ int lcurl_easy_create(lua_State *L, int error_mode){
9797
p->match.cb_ref = p->match.ud_ref = LUA_NOREF;
9898
p->chunk_bgn.cb_ref = p->chunk_bgn.ud_ref = LUA_NOREF;
9999
p->chunk_end.cb_ref = p->chunk_end.ud_ref = LUA_NOREF;
100+
#if LCURL_CURL_VER_GE(7,64,0)
101+
p->trailer.cb_ref = p->trailer.ud_ref = LUA_NOREF;
102+
#endif
100103
p->rbuffer.ref = LUA_NOREF;
101104
for(i = 0; i < LCURL_LIST_COUNT; ++i){
102105
p->lists[i] = LUA_NOREF;
@@ -179,10 +182,14 @@ static int lcurl_easy_cleanup(lua_State *L){
179182
luaL_unref(L, LCURL_LUA_REGISTRY, p->chunk_bgn.ud_ref);
180183
luaL_unref(L, LCURL_LUA_REGISTRY, p->chunk_end.cb_ref);
181184
luaL_unref(L, LCURL_LUA_REGISTRY, p->chunk_end.ud_ref);
185+
#if LCURL_CURL_VER_GE(7,64,0)
186+
luaL_unref(L, LCURL_LUA_REGISTRY, p->trailer.cb_ref);
187+
luaL_unref(L, LCURL_LUA_REGISTRY, p->trailer.ud_ref);
188+
#endif
182189
luaL_unref(L, LCURL_LUA_REGISTRY, p->hd.cb_ref);
183190
luaL_unref(L, LCURL_LUA_REGISTRY, p->hd.ud_ref);
184191
luaL_unref(L, LCURL_LUA_REGISTRY, p->rbuffer.ref);
185-
192+
186193
p->wr.cb_ref = p->wr.ud_ref = LUA_NOREF;
187194
p->rd.cb_ref = p->rd.ud_ref = LUA_NOREF;
188195
p->hd.cb_ref = p->hd.ud_ref = LUA_NOREF;
@@ -192,6 +199,9 @@ static int lcurl_easy_cleanup(lua_State *L){
192199
p->match.cb_ref = p->match.ud_ref = LUA_NOREF;
193200
p->chunk_bgn.cb_ref = p->chunk_bgn.ud_ref = LUA_NOREF;
194201
p->chunk_end.cb_ref = p->chunk_end.ud_ref = LUA_NOREF;
202+
#if LCURL_CURL_VER_GE(7,64,0)
203+
p->trailer.cb_ref = p->trailer.ud_ref = LUA_NOREF;
204+
#endif
195205
p->rbuffer.ref = LUA_NOREF;
196206

197207
for(i = 0; i < LCURL_LIST_COUNT; ++i){
@@ -324,10 +334,12 @@ static int lcurl_opt_set_long_(lua_State *L, int opt){
324334
if(lua_isboolean(L, 2)){
325335
val = lua_toboolean(L, 2);
326336
if( val
327-
&& (opt == CURLOPT_SSL_VERIFYHOST)
337+
&& (
338+
(opt == CURLOPT_SSL_VERIFYHOST)
328339
#if LCURL_CURL_VER_GE(7,52,0)
329-
&& (opt == CURLOPT_PROXY_SSL_VERIFYHOST)
340+
|| (opt == CURLOPT_PROXY_SSL_VERIFYHOST)
330341
#endif
342+
)
331343
){
332344
val = 2;
333345
}
@@ -566,6 +578,7 @@ static int lcurl_easy_set_CURLU(lua_State *L) {
566578
}
567579

568580
#endif
581+
569582
//}
570583

571584
//{ unset
@@ -953,6 +966,27 @@ static int lcurl_easy_unset_CURLU(lua_State *L) {
953966

954967
#endif
955968

969+
#if LCURL_CURL_VER_GE(7,64,0)
970+
971+
static int lcurl_easy_unset_TRAILERFUNCTION(lua_State *L){
972+
lcurl_easy_t *p = lcurl_geteasy(L);
973+
974+
CURLcode code = curl_easy_setopt(p->curl, CURLOPT_TRAILERFUNCTION, NULL);
975+
if(code != CURLE_OK){
976+
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, code);
977+
}
978+
curl_easy_setopt(p->curl, CURLOPT_TRAILERDATA, NULL);
979+
980+
luaL_unref(L, LCURL_LUA_REGISTRY, p->trailer.cb_ref);
981+
luaL_unref(L, LCURL_LUA_REGISTRY, p->trailer.ud_ref);
982+
p->trailer.cb_ref = p->trailer.ud_ref = LUA_NOREF;
983+
984+
lua_settop(L, 1);
985+
return 1;
986+
}
987+
988+
#endif
989+
956990
//}
957991

958992
//}
@@ -1618,6 +1652,70 @@ static int lcurl_easy_set_CHUNK_END_FUNCTION(lua_State *L){
16181652

16191653
//}
16201654

1655+
//{ Trailer
1656+
1657+
#if LCURL_CURL_VER_GE(7,64,0)
1658+
1659+
static int lcurl_trailer_callback(struct curl_slist **list, void *arg) {
1660+
lcurl_easy_t *p = arg;
1661+
lua_State *L = p->L;
1662+
int top = lua_gettop(L);
1663+
int n = lcurl_util_push_cb(L, &p->trailer);
1664+
1665+
if (lua_pcall(L, n - 1, LUA_MULTRET, 0)) {
1666+
assert(lua_gettop(L) >= top);
1667+
lua_pushlightuserdata(L, (void*)LCURL_ERROR_TAG);
1668+
lua_insert(L, top + 1);
1669+
return CURL_TRAILERFUNC_ABORT;
1670+
}
1671+
1672+
n = lua_gettop(L);
1673+
1674+
if (n == top) {
1675+
return CURL_TRAILERFUNC_OK;
1676+
}
1677+
1678+
/* libcurl will free the list */
1679+
*list = lcurl_util_to_slist(L, top + 1);
1680+
if (*list) {
1681+
lua_settop(L, top);
1682+
return CURL_TRAILERFUNC_OK;
1683+
}
1684+
1685+
// empty array or NULL
1686+
if (lua_istable(L, top + 1) || lutil_is_null(L, top + 1)) {
1687+
lua_settop(L, top);
1688+
return CURL_TRAILERFUNC_OK;
1689+
}
1690+
1691+
// true
1692+
if((lua_type(L, top + 1) == LUA_TBOOLEAN) && (lua_toboolean(L, top + 1))){
1693+
lua_settop(L, top);
1694+
return CURL_TRAILERFUNC_OK;
1695+
}
1696+
1697+
// single nil
1698+
if((n == (top + 1)) && lua_isnil(L, top + 1)){
1699+
lua_settop(L, top);
1700+
return CURL_TRAILERFUNC_OK;
1701+
}
1702+
1703+
lua_settop(L, top);
1704+
return CURL_TRAILERFUNC_ABORT;
1705+
}
1706+
1707+
static int lcurl_easy_set_TRAILERFUNCTION (lua_State *L){
1708+
lcurl_easy_t *p = lcurl_geteasy(L);
1709+
return lcurl_easy_set_callback(L, p, &p->trailer,
1710+
CURLOPT_TRAILERFUNCTION, CURLOPT_TRAILERDATA,
1711+
"trailer", lcurl_trailer_callback
1712+
);
1713+
}
1714+
1715+
#endif
1716+
1717+
//}
1718+
16211719
//}
16221720

16231721
static int lcurl_easy_setopt(lua_State *L){
@@ -1780,6 +1878,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
17801878
#if LCURL_CURL_VER_GE(7,63,0)
17811879
OPT_ENTRY(curlu, CURLU, TTT, 0, 0)
17821880
#endif
1881+
#if LCURL_CURL_VER_GE(7,64,0)
1882+
OPT_ENTRY(trailerfunction, TRAILERFUNCTION, TTT, 0, 0)
1883+
#endif
17831884
#undef OPT_ENTRY
17841885

17851886
#define OPT_ENTRY(L, N, T, S, D) { "unsetopt_"#L, lcurl_easy_unset_##N },
@@ -1808,6 +1909,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
18081909
#if LCURL_CURL_VER_GE(7,63,0)
18091910
OPT_ENTRY(curlu, CURLU, TTT, 0, 0)
18101911
#endif
1912+
#if LCURL_CURL_VER_GE(7,64,0)
1913+
OPT_ENTRY(trailerfunction, TRAILERFUNCTION, TTT, 0, 0)
1914+
#endif
18111915
#undef OPT_ENTRY
18121916

18131917
#define OPT_ENTRY(L, N, T, S) { "getinfo_"#L, lcurl_easy_get_##N },
@@ -1868,6 +1972,9 @@ static const lcurl_const_t lcurl_easy_opt[] = {
18681972
#if LCURL_CURL_VER_GE(7,63,0)
18691973
OPT_ENTRY(curlu, CURLU, TTT, 0, 0)
18701974
#endif
1975+
#if LCURL_CURL_VER_GE(7,64,0)
1976+
OPT_ENTRY(trailerfunction, TRAILERFUNCTION, TTT, 0, 0)
1977+
#endif
18711978
#undef OPT_ENTRY
18721979
#undef FLG_ENTRY
18731980

src/lceasy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ typedef struct lcurl_easy_tag{
8989
lcurl_callback_t match;
9090
lcurl_callback_t chunk_bgn;
9191
lcurl_callback_t chunk_end;
92+
#if LCURL_CURL_VER_GE(7,64,0)
93+
lcurl_callback_t trailer;
94+
#endif
9295
}lcurl_easy_t;
9396

9497
int lcurl_easy_create(lua_State *L, int error_mode);
@@ -111,6 +114,9 @@ size_t lcurl_read_callback(lua_State *L,
111114
#ifdef lcurl_mime_t
112115
#undef lcurl_mime_t
113116
#endif
117+
#ifdef lcurl_url_t
118+
#undef lcurl_url_t
119+
#endif
114120
#endif
115121

116122
#endif

src/lcopteasy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ OPT_ENTRY(doh_url, DOH_URL, STR, 0, LCURL_DEFA
461461
OPT_ENTRY(upload_buffersize, UPLOAD_BUFFERSIZE, LNG, 0, 64 * 1024)
462462
#endif
463463

464+
#if LCURL_CURL_VER_GE(7,64,0)
465+
OPT_ENTRY(http09_allowed, HTTP09_ALLOWED, LNG, 0, 0)
466+
#endif
467+
464468
#if LCURL_CURL_VER_GE(7,65,0)
465469
OPT_ENTRY(maxage_conn, MAXAGE_CONN, LNG, 0, LCURL_DEFAULT_VALUE)
466470
#endif

0 commit comments

Comments
 (0)