@@ -70,19 +70,21 @@ 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 -> debug .cb_ref = p -> debug .ud_ref = LUA_NOREF ;
84
- p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
85
- 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 -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
85
+ p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
86
+ p -> chunk_end .cb_ref = p -> chunk_end .ud_ref = LUA_NOREF ;
87
+ p -> rbuffer .ref = LUA_NOREF ;
86
88
for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
87
89
p -> lists [i ] = LUA_NOREF ;
88
90
}
@@ -149,17 +151,23 @@ static int lcurl_easy_cleanup(lua_State *L){
149
151
luaL_unref (L , LCURL_LUA_REGISTRY , p -> debug .ud_ref );
150
152
luaL_unref (L , LCURL_LUA_REGISTRY , p -> match .cb_ref );
151
153
luaL_unref (L , LCURL_LUA_REGISTRY , p -> match .ud_ref );
154
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .cb_ref );
155
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .ud_ref );
156
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .cb_ref );
157
+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .ud_ref );
152
158
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .cb_ref );
153
159
luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .ud_ref );
154
160
luaL_unref (L , LCURL_LUA_REGISTRY , p -> rbuffer .ref );
155
161
156
- p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
157
- p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
158
- p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
159
- p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
160
- p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
161
- p -> debug .cb_ref = p -> debug .ud_ref = LUA_NOREF ;
162
- p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
162
+ p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
163
+ p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
164
+ p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
165
+ p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
166
+ p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
167
+ p -> debug .cb_ref = p -> debug .ud_ref = LUA_NOREF ;
168
+ p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
169
+ p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
170
+ p -> chunk_end .cb_ref = p -> chunk_end .ud_ref = LUA_NOREF ;
163
171
p -> rbuffer .ref = LUA_NOREF ;
164
172
165
173
for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
@@ -666,6 +674,31 @@ static int lcurl_easy_unset_FNMATCH_FUNCTION(lua_State *L){
666
674
return 1 ;
667
675
}
668
676
677
+ static int lcurl_easy_unset_CHUNK_BGN_FUNCTION (lua_State * L ){
678
+ lcurl_easy_t * p = lcurl_geteasy (L );
679
+
680
+ CURLcode code = curl_easy_setopt (p -> curl , CURLOPT_CHUNK_BGN_FUNCTION , NULL );
681
+ if (code != CURLE_OK ){
682
+ return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , code );
683
+ }
684
+ // curl_easy_setopt(p->curl, CURLOPT_CHUNK_DATA, NULL);
685
+
686
+ lua_settop (L , 1 );
687
+ return 1 ;
688
+ }
689
+ static int lcurl_easy_unset_CHUNK_END_FUNCTION (lua_State * L ){
690
+ lcurl_easy_t * p = lcurl_geteasy (L );
691
+
692
+ CURLcode code = curl_easy_setopt (p -> curl , CURLOPT_CHUNK_END_FUNCTION , NULL );
693
+ if (code != CURLE_OK ){
694
+ return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , code );
695
+ }
696
+ // curl_easy_setopt(p->curl, CURLOPT_CHUNK_DATA, NULL);
697
+
698
+ lua_settop (L , 1 );
699
+ return 1 ;
700
+ }
701
+
669
702
#endif
670
703
671
704
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
@@ -1194,6 +1227,113 @@ static int lcurl_easy_set_FNMATCH_FUNCTION(lua_State *L){
1194
1227
1195
1228
//}
1196
1229
1230
+ //{ Chunk begin/end
1231
+
1232
+ #if LCURL_CURL_VER_GE (7 ,21 ,0 )
1233
+
1234
+ static int lcurl_chunk_bgn_callback (struct curl_fileinfo * info , void * arg , int remains ) {
1235
+ lcurl_easy_t * p = arg ;
1236
+ lua_State * L = p -> L ;
1237
+ int ret = CURL_CHUNK_BGN_FUNC_OK ;
1238
+ int top = lua_gettop (L );
1239
+ int n = lcurl_util_push_cb (L , & p -> chunk_bgn );
1240
+
1241
+ assert (NULL != p -> L );
1242
+
1243
+ lua_newtable (L );
1244
+ lua_pushstring (L , info -> filename ); lua_setfield (L , -2 , "filename" );
1245
+ lua_pushinteger (L , info -> filetype ); lua_setfield (L , -2 , "filetype" );
1246
+ lutil_pushint64 (L , info -> time ); lua_setfield (L , -2 , "time" );
1247
+ lutil_pushint64 (L , info -> perm ); lua_setfield (L , -2 , "perm" );
1248
+ lua_pushinteger (L , info -> uid ); lua_setfield (L , -2 , "uid" );
1249
+ lua_pushinteger (L , info -> gid ); lua_setfield (L , -2 , "gid" );
1250
+ lutil_pushint64 (L , info -> size ); lua_setfield (L , -2 , "size" );
1251
+ lutil_pushint64 (L , info -> hardlinks ); lua_setfield (L , -2 , "hardlinks" );
1252
+ lutil_pushint64 (L , info -> flags ); lua_setfield (L , -2 , "flags" );
1253
+
1254
+ lua_newtable (L );
1255
+ if (info -> strings .time ) { lua_pushstring (L , info -> strings .time ); lua_setfield (L , -2 , "time" ); }
1256
+ if (info -> strings .perm ) { lua_pushstring (L , info -> strings .perm ); lua_setfield (L , -2 , "perm" ); }
1257
+ if (info -> strings .user ) { lua_pushstring (L , info -> strings .user ); lua_setfield (L , -2 , "user" ); }
1258
+ if (info -> strings .group ) { lua_pushstring (L , info -> strings .group ); lua_setfield (L , -2 , "group" ); }
1259
+ if (info -> strings .target ){ lua_pushstring (L , info -> strings .target ); lua_setfield (L , -2 , "target" ); }
1260
+ lua_setfield (L , -2 , "strings" );
1261
+
1262
+ lua_pushinteger (L , remains );
1263
+
1264
+ if (lua_pcall (L , n + 1 , LUA_MULTRET , 0 )) {
1265
+ assert (lua_gettop (L ) >= top );
1266
+ lua_pushlightuserdata (L , (void * )LCURL_ERROR_TAG );
1267
+ lua_insert (L , top + 1 );
1268
+ return CURL_CHUNK_BGN_FUNC_FAIL ;
1269
+ }
1270
+
1271
+ if (lua_gettop (L ) > top ){
1272
+ if (lua_isnil (L , top + 1 ) && (!lua_isnoneornil (L , top + 2 ))){
1273
+ lua_settop (L , top + 2 );
1274
+ lua_remove (L , top + 1 );
1275
+ lua_pushlightuserdata (L , (void * )LCURL_ERROR_TAG );
1276
+ lua_insert (L , top + 1 );
1277
+ return CURL_CHUNK_BGN_FUNC_FAIL ;
1278
+ }
1279
+ ret = lua_toboolean (L , top + 1 ) ? CURL_CHUNK_BGN_FUNC_OK : CURL_CHUNK_BGN_FUNC_SKIP ;
1280
+ }
1281
+
1282
+ lua_settop (L , top );
1283
+ return ret ;
1284
+ }
1285
+
1286
+ static int lcurl_chunk_end_callback (void * arg ) {
1287
+ lcurl_easy_t * p = arg ;
1288
+ lua_State * L = p -> L ;
1289
+ int ret = CURL_CHUNK_END_FUNC_OK ;
1290
+ int top = lua_gettop (L );
1291
+ int n = lcurl_util_push_cb (L , & p -> chunk_end );
1292
+
1293
+ assert (NULL != p -> L );
1294
+
1295
+ if (lua_pcall (L , n - 1 , LUA_MULTRET , 0 )) {
1296
+ assert (lua_gettop (L ) >= top );
1297
+ lua_pushlightuserdata (L , (void * )LCURL_ERROR_TAG );
1298
+ lua_insert (L , top + 1 );
1299
+ return CURL_CHUNK_END_FUNC_FAIL ;
1300
+ }
1301
+
1302
+ if (lua_gettop (L ) > top ){
1303
+ if (lua_isnil (L , top + 1 ) && (!lua_isnoneornil (L , top + 2 ))){
1304
+ lua_settop (L , top + 2 );
1305
+ lua_remove (L , top + 1 );
1306
+ lua_pushlightuserdata (L , (void * )LCURL_ERROR_TAG );
1307
+ lua_insert (L , top + 1 );
1308
+ return CURL_CHUNK_END_FUNC_FAIL ;
1309
+ }
1310
+ ret = lua_toboolean (L , top + 1 ) ? CURL_CHUNK_END_FUNC_OK : CURL_CHUNK_END_FUNC_FAIL ;
1311
+ }
1312
+
1313
+ lua_settop (L , top );
1314
+ return ret ;
1315
+ }
1316
+
1317
+ static int lcurl_easy_set_CHUNK_BGN_FUNCTION (lua_State * L ){
1318
+ lcurl_easy_t * p = lcurl_geteasy (L );
1319
+ return lcurl_easy_set_callback (L , p , & p -> chunk_bgn ,
1320
+ CURLOPT_CHUNK_BGN_FUNCTION , CURLOPT_CHUNK_DATA ,
1321
+ "chunk_bgn" , lcurl_chunk_bgn_callback
1322
+ );
1323
+ }
1324
+
1325
+ static int lcurl_easy_set_CHUNK_END_FUNCTION (lua_State * L ){
1326
+ lcurl_easy_t * p = lcurl_geteasy (L );
1327
+ return lcurl_easy_set_callback (L , p , & p -> chunk_bgn ,
1328
+ CURLOPT_CHUNK_END_FUNCTION , CURLOPT_CHUNK_DATA ,
1329
+ "chunk_bgn" , lcurl_chunk_bgn_callback
1330
+ );
1331
+ }
1332
+
1333
+ #endif
1334
+
1335
+ //}
1336
+
1197
1337
//}
1198
1338
1199
1339
static int lcurl_easy_setopt (lua_State * L ){
@@ -1225,6 +1365,8 @@ static int lcurl_easy_setopt(lua_State *L){
1225
1365
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1226
1366
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
1227
1367
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
1368
+ OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
1369
+ OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
1228
1370
#endif
1229
1371
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1230
1372
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
@@ -1257,6 +1399,8 @@ static int lcurl_easy_unsetopt(lua_State *L){
1257
1399
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1258
1400
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
1259
1401
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
1402
+ OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
1403
+ OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
1260
1404
#endif
1261
1405
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1262
1406
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
@@ -1333,6 +1477,8 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
1333
1477
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1334
1478
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
1335
1479
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
1480
+ OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
1481
+ OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
1336
1482
#endif
1337
1483
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1338
1484
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
@@ -1353,6 +1499,8 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
1353
1499
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1354
1500
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
1355
1501
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
1502
+ OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
1503
+ OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
1356
1504
#endif
1357
1505
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1358
1506
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
@@ -1398,6 +1546,8 @@ static const lcurl_const_t lcurl_easy_opt[] = {
1398
1546
OPT_ENTRY (debugfunction , DEBUGFUNCTION , TTT , 0 , 0 )
1399
1547
#if LCURL_CURL_VER_GE (7 ,21 ,0 )
1400
1548
OPT_ENTRY (fnmatch_function , FNMATCH_FUNCTION , TTT , 0 , 0 )
1549
+ OPT_ENTRY (chunk_bgn_function , CHUNK_BGN_FUNCTION , TTT , 0 , 0 )
1550
+ OPT_ENTRY (chunk_end_function , CHUNK_END_FUNCTION , TTT , 0 , 0 )
1401
1551
#endif
1402
1552
#if LCURL_CURL_VER_GE (7 ,46 ,0 )
1403
1553
OPT_ENTRY (stream_depends , STREAM_DEPENDS , TTT , 0 , 0 )
@@ -1430,7 +1580,8 @@ void lcurl_easy_initlib(lua_State *L, int nup){
1430
1580
compatiable for readfunction
1431
1581
*/
1432
1582
LCURL_STATIC_ASSERT (offsetof(lcurl_easy_t , magic ) == offsetof(lcurl_hpost_stream_t , magic ));
1433
- LCURL_STATIC_ASSERT (sizeof (((lcurl_easy_t * )0 )-> magic ) == sizeof (((lcurl_hpost_stream_t * )0 )-> magic ));
1583
+ LCURL_STATIC_ASSERT (offsetof(lcurl_easy_t , L ) == offsetof(lcurl_hpost_stream_t , L ));
1584
+ LCURL_STATIC_ASSERT (offsetof(lcurl_easy_t , rd ) == offsetof(lcurl_hpost_stream_t , rd ));
1434
1585
1435
1586
if (!lutil_createmetap (L , LCURL_EASY , lcurl_easy_methods , nup ))
1436
1587
lua_pop (L , nup );
0 commit comments