@@ -97,6 +97,9 @@ int lcurl_easy_create(lua_State *L, int error_mode){
97
97
p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
98
98
p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
99
99
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
100
103
p -> rbuffer .ref = LUA_NOREF ;
101
104
for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
102
105
p -> lists [i ] = LUA_NOREF ;
@@ -179,10 +182,14 @@ static int lcurl_easy_cleanup(lua_State *L){
179
182
luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .ud_ref );
180
183
luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .cb_ref );
181
184
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
182
189
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .cb_ref );
183
190
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .ud_ref );
184
191
luaL_unref (L , LCURL_LUA_REGISTRY , p -> rbuffer .ref );
185
-
192
+
186
193
p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
187
194
p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
188
195
p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
@@ -192,6 +199,9 @@ static int lcurl_easy_cleanup(lua_State *L){
192
199
p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
193
200
p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
194
201
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
195
205
p -> rbuffer .ref = LUA_NOREF ;
196
206
197
207
for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
@@ -324,10 +334,12 @@ static int lcurl_opt_set_long_(lua_State *L, int opt){
324
334
if (lua_isboolean (L , 2 )){
325
335
val = lua_toboolean (L , 2 );
326
336
if ( val
327
- && (opt == CURLOPT_SSL_VERIFYHOST )
337
+ && (
338
+ (opt == CURLOPT_SSL_VERIFYHOST )
328
339
#if LCURL_CURL_VER_GE (7 ,52 ,0 )
329
- && (opt == CURLOPT_PROXY_SSL_VERIFYHOST )
340
+ || (opt == CURLOPT_PROXY_SSL_VERIFYHOST )
330
341
#endif
342
+ )
331
343
){
332
344
val = 2 ;
333
345
}
@@ -566,6 +578,7 @@ static int lcurl_easy_set_CURLU(lua_State *L) {
566
578
}
567
579
568
580
#endif
581
+
569
582
//}
570
583
571
584
//{ unset
@@ -953,6 +966,27 @@ static int lcurl_easy_unset_CURLU(lua_State *L) {
953
966
954
967
#endif
955
968
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
+
956
990
//}
957
991
958
992
//}
@@ -1618,6 +1652,70 @@ static int lcurl_easy_set_CHUNK_END_FUNCTION(lua_State *L){
1618
1652
1619
1653
//}
1620
1654
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
+
1621
1719
//}
1622
1720
1623
1721
static int lcurl_easy_setopt (lua_State * L ){
@@ -1780,6 +1878,9 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
1780
1878
#if LCURL_CURL_VER_GE (7 ,63 ,0 )
1781
1879
OPT_ENTRY (curlu , CURLU , TTT , 0 , 0 )
1782
1880
#endif
1881
+ #if LCURL_CURL_VER_GE (7 ,64 ,0 )
1882
+ OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
1883
+ #endif
1783
1884
#undef OPT_ENTRY
1784
1885
1785
1886
#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[] = {
1808
1909
#if LCURL_CURL_VER_GE (7 ,63 ,0 )
1809
1910
OPT_ENTRY (curlu , CURLU , TTT , 0 , 0 )
1810
1911
#endif
1912
+ #if LCURL_CURL_VER_GE (7 ,64 ,0 )
1913
+ OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
1914
+ #endif
1811
1915
#undef OPT_ENTRY
1812
1916
1813
1917
#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[] = {
1868
1972
#if LCURL_CURL_VER_GE (7 ,63 ,0 )
1869
1973
OPT_ENTRY (curlu , CURLU , TTT , 0 , 0 )
1870
1974
#endif
1975
+ #if LCURL_CURL_VER_GE (7 ,64 ,0 )
1976
+ OPT_ENTRY (trailerfunction , TRAILERFUNCTION , TTT , 0 , 0 )
1977
+ #endif
1871
1978
#undef OPT_ENTRY
1872
1979
#undef FLG_ENTRY
1873
1980
0 commit comments