@@ -70,17 +70,18 @@ int lcurl_easy_create(lua_State *L, int error_mode){
70
70
p -> err_mode = error_mode ;
71
71
if (!p -> curl ) return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , CURLE_FAILED_INIT );
72
72
73
- p -> magic = LCURL_EASY_MAGIC ;
74
- p -> L = NULL ;
75
- p -> post = NULL ;
76
- p -> multi = NULL ;
77
- p -> storage = lcurl_storage_init (L );
78
- p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
79
- p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
80
- p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
81
- p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
82
- p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
83
- p -> rbuffer .ref = LUA_NOREF ;
73
+ p -> magic = LCURL_EASY_MAGIC ;
74
+ p -> L = NULL ;
75
+ p -> post = NULL ;
76
+ p -> multi = NULL ;
77
+ p -> storage = lcurl_storage_init (L );
78
+ p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
79
+ p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
80
+ p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
81
+ p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
82
+ p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
83
+ p -> debug .cb_ref = p -> debug .ud_ref = LUA_NOREF ;
84
+ p -> rbuffer .ref = LUA_NOREF ;
84
85
for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
85
86
p -> lists [i ] = LUA_NOREF ;
86
87
}
@@ -143,16 +144,19 @@ static int lcurl_easy_cleanup(lua_State *L){
143
144
luaL_unref (L , LCURL_LUA_REGISTRY , p -> pr .ud_ref );
144
145
luaL_unref (L , LCURL_LUA_REGISTRY , p -> seek .cb_ref );
145
146
luaL_unref (L , LCURL_LUA_REGISTRY , p -> seek .ud_ref );
147
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> debug .cb_ref );
148
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> debug .ud_ref );
146
149
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .cb_ref );
147
150
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .ud_ref );
148
151
luaL_unref (L , LCURL_LUA_REGISTRY , p -> rbuffer .ref );
149
152
150
- p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
151
- p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
152
- p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
153
- p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
154
- p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
155
- p -> rbuffer .ref = LUA_NOREF ;
153
+ p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
154
+ p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
155
+ p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
156
+ p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
157
+ p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
158
+ p -> debug .cb_ref = p -> debug .ud_ref = LUA_NOREF ;
159
+ p -> rbuffer .ref = LUA_NOREF ;
156
160
157
161
for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
158
162
p -> lists [i ] = LUA_NOREF ;
@@ -630,6 +634,19 @@ static int lcurl_easy_unset_SEEKFUNCTION(lua_State *L){
630
634
return 1 ;
631
635
}
632
636
637
+ static int lcurl_easy_unset_DEBUGFUNCTION (lua_State * L ){
638
+ lcurl_easy_t * p = lcurl_geteasy (L );
639
+
640
+ CURLcode code = curl_easy_setopt (p -> curl , CURLOPT_DEBUGFUNCTION , NULL );
641
+ if (code != CURLE_OK ){
642
+ return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , code );
643
+ }
644
+ curl_easy_setopt (p -> curl , CURLOPT_DEBUGDATA , NULL );
645
+
646
+ lua_settop (L , 1 );
647
+ return 1 ;
648
+ }
649
+
633
650
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
634
651
635
652
static int lcurl_easy_unset_STREAM_DEPENDS (lua_State * L ){
@@ -1067,14 +1084,45 @@ static int lcurl_seek_callback(void *arg, curl_off_t offset, int origin){
1067
1084
1068
1085
static int lcurl_easy_set_SEEKFUNCTION (lua_State * L ){
1069
1086
lcurl_easy_t * p = lcurl_geteasy (L );
1070
- return lcurl_easy_set_callback (L , p , & p -> hd ,
1087
+ return lcurl_easy_set_callback (L , p , & p -> seek ,
1071
1088
CURLOPT_SEEKFUNCTION , CURLOPT_SEEKDATA ,
1072
1089
"seek" , lcurl_seek_callback
1073
1090
);
1074
1091
}
1075
1092
1076
1093
//}
1077
1094
1095
+ //{ Debug
1096
+
1097
+ static int lcurl_debug_callback (CURL * handle , curl_infotype type , char * data , size_t size , void * arg ){
1098
+ lcurl_easy_t * p = arg ;
1099
+ lua_State * L = p -> L ;
1100
+ int top = lua_gettop (L );
1101
+ int n = lcurl_util_push_cb (L , & p -> debug );
1102
+
1103
+ assert (NULL != p -> L );
1104
+ assert (handle == p -> curl );
1105
+
1106
+ lua_pushinteger (L , type );
1107
+ lua_pushlstring (L , data , size );
1108
+
1109
+ // just ignore all errors from Lua callback
1110
+ lua_pcall (L , n + 1 , LUA_MULTRET , 0 );
1111
+ lua_settop (L , top );
1112
+
1113
+ return 0 ;
1114
+ }
1115
+
1116
+ static int lcurl_easy_set_DEBUGFUNCTION (lua_State * L ){
1117
+ lcurl_easy_t * p = lcurl_geteasy (L );
1118
+ return lcurl_easy_set_callback (L , p , & p -> debug ,
1119
+ CURLOPT_DEBUGFUNCTION , CURLOPT_DEBUGDATA ,
1120
+ "debug" , lcurl_debug_callback
1121
+ );
1122
+ }
1123
+
1124
+ //}
1125
+
1078
1126
//}
1079
1127
1080
1128
static int lcurl_easy_setopt (lua_State * L ){
@@ -1103,6 +1151,7 @@ static int lcurl_easy_setopt(lua_State *L){
1103
1151
OPT_ENTRY (headerfunction , HEADERFUNCTION , TTT , 0 , 0 )
1104
1152
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
1105
1153
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
1154
+ OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1106
1155
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1107
1156
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
1108
1157
OPT_ENTRY (stream_depends_e , STREAM_DEPENDS_E , TTT , 0 , 0 )
@@ -1131,6 +1180,7 @@ static int lcurl_easy_unsetopt(lua_State *L){
1131
1180
OPT_ENTRY (headerfunction , HEADERFUNCTION , TTT , 0 , 0 )
1132
1181
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
1133
1182
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
1183
+ OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1134
1184
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1135
1185
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
1136
1186
OPT_ENTRY (stream_depends_e , STREAM_DEPENDS_E , TTT , 0 , 0 )
@@ -1203,6 +1253,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
1203
1253
OPT_ENTRY (headerfunction , HEADERFUNCTION , TTT , 0 , 0 )
1204
1254
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
1205
1255
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
1256
+ OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1206
1257
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1207
1258
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
1208
1259
OPT_ENTRY (stream_depends_e , STREAM_DEPENDS_E , TTT , 0 , 0 )
@@ -1219,6 +1270,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
1219
1270
OPT_ENTRY (headerfunction , HEADERFUNCTION , TTT , 0 , 0 )
1220
1271
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
1221
1272
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
1273
+ OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1222
1274
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1223
1275
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
1224
1276
OPT_ENTRY (stream_depends_e , STREAM_DEPENDS_E , TTT , 0 , 0 )
@@ -1260,6 +1312,7 @@ static const lcurl_const_t lcurl_easy_opt[] = {
1260
1312
OPT_ENTRY (headerfunction , HEADERFUNCTION , TTT , 0 , 0 )
1261
1313
OPT_ENTRY (progressfunction , PROGRESSFUNCTION , TTT , 0 , 0 )
1262
1314
OPT_ENTRY (seekfunction , SEEKFUNCTION , TTT , 0 , 0 )
1315
+ OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1263
1316
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1264
1317
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
1265
1318
OPT_ENTRY (stream_depends_e , STREAM_DEPENDS_E , TTT , 0 , 0 )
@@ -1271,6 +1324,17 @@ static const lcurl_const_t lcurl_easy_opt[] = {
1271
1324
#include "lcinfoeasy.h"
1272
1325
#undef OPT_ENTRY
1273
1326
1327
+ #define OPT_ENTRY (N ) { #N, CURL##N },
1328
+ // Debug message types not easy info
1329
+ OPT_ENTRY (INFO_TEXT )
1330
+ OPT_ENTRY (INFO_HEADER_IN )
1331
+ OPT_ENTRY (INFO_HEADER_OUT )
1332
+ OPT_ENTRY (INFO_DATA_IN )
1333
+ OPT_ENTRY (INFO_DATA_OUT )
1334
+ OPT_ENTRY (INFO_SSL_DATA_OUT )
1335
+ OPT_ENTRY (INFO_SSL_DATA_IN )
1336
+ #undef OPT_ENTRY
1337
+
1274
1338
{NULL , 0 }
1275
1339
};
1276
1340
0 commit comments