@@ -396,60 +396,58 @@ ngx_http_lua_body_filter_init(void)
396
396
397
397
398
398
int
399
- ngx_http_lua_body_filter_param_get ( lua_State * L , ngx_http_request_t * r )
399
+ ngx_http_lua_ffi_get_body_filter_param_eof ( ngx_http_request_t * r )
400
400
{
401
- u_char * data , * p ;
402
- size_t size ;
403
401
ngx_chain_t * cl ;
404
- ngx_buf_t * b ;
405
- int idx ;
406
402
ngx_chain_t * in ;
407
403
408
404
ngx_http_lua_main_conf_t * lmcf ;
409
405
410
- idx = luaL_checkint (L , 2 );
406
+ lmcf = ngx_http_get_module_main_conf (r , ngx_http_lua_module );
407
+ in = lmcf -> body_filter_chain ;
411
408
412
- dd ( "index: %d" , idx );
409
+ /* asking for the eof argument */
413
410
414
- if (idx != 1 && idx != 2 ) {
415
- lua_pushnil (L );
416
- return 1 ;
411
+ for (cl = in ; cl ; cl = cl -> next ) {
412
+ if (cl -> buf -> last_buf || cl -> buf -> last_in_chain ) {
413
+ return 1 ;
414
+ }
417
415
}
418
416
419
- lmcf = ngx_http_get_module_main_conf ( r , ngx_http_lua_module ) ;
420
- in = lmcf -> body_filter_chain ;
417
+ return 0 ;
418
+ }
421
419
422
- if (idx == 2 ) {
423
- /* asking for the eof argument */
424
420
425
- for (cl = in ; cl ; cl = cl -> next ) {
426
- if (cl -> buf -> last_buf || cl -> buf -> last_in_chain ) {
427
- lua_pushboolean (L , 1 );
428
- return 1 ;
429
- }
430
- }
421
+ int
422
+ ngx_http_lua_ffi_get_body_filter_param_body (ngx_http_request_t * r ,
423
+ u_char * * data_p , size_t * len_p )
424
+ {
425
+ size_t size ;
426
+ ngx_chain_t * cl ;
427
+ ngx_buf_t * b ;
428
+ ngx_chain_t * in ;
431
429
432
- lua_pushboolean (L , 0 );
433
- return 1 ;
434
- }
430
+ ngx_http_lua_main_conf_t * lmcf ;
435
431
436
- /* idx == 1 */
432
+ lmcf = ngx_http_get_module_main_conf (r , ngx_http_lua_module );
433
+ in = lmcf -> body_filter_chain ;
437
434
438
435
size = 0 ;
439
436
440
437
if (in == NULL ) {
441
438
/* being a cleared chain on the Lua land */
442
- lua_pushliteral ( L , "" ) ;
443
- return 1 ;
439
+ * len_p = 0 ;
440
+ return NGX_OK ;
444
441
}
445
442
446
443
if (in -> next == NULL ) {
447
444
448
445
dd ("seen only single buffer" );
449
446
450
447
b = in -> buf ;
451
- lua_pushlstring (L , (char * ) b -> pos , b -> last - b -> pos );
452
- return 1 ;
448
+ * data_p = b -> pos ;
449
+ * len_p = b -> last - b -> pos ;
450
+ return NGX_OK ;
453
451
}
454
452
455
453
dd ("seen multiple buffers" );
@@ -464,7 +462,26 @@ ngx_http_lua_body_filter_param_get(lua_State *L, ngx_http_request_t *r)
464
462
}
465
463
}
466
464
467
- data = (u_char * ) lua_newuserdata (L , size );
465
+ /* the buf is need and is not allocated from Lua land yet, return with
466
+ * the actual size */
467
+ * len_p = size ;
468
+ return NGX_AGAIN ;
469
+ }
470
+
471
+
472
+ int
473
+ ngx_http_lua_ffi_copy_body_filter_param_body (ngx_http_request_t * r ,
474
+ u_char * data )
475
+ {
476
+ u_char * p ;
477
+ ngx_chain_t * cl ;
478
+ ngx_buf_t * b ;
479
+ ngx_chain_t * in ;
480
+
481
+ ngx_http_lua_main_conf_t * lmcf ;
482
+
483
+ lmcf = ngx_http_get_module_main_conf (r , ngx_http_lua_module );
484
+ in = lmcf -> body_filter_chain ;
468
485
469
486
for (p = data , cl = in ; cl ; cl = cl -> next ) {
470
487
b = cl -> buf ;
@@ -475,8 +492,7 @@ ngx_http_lua_body_filter_param_get(lua_State *L, ngx_http_request_t *r)
475
492
}
476
493
}
477
494
478
- lua_pushlstring (L , (char * ) data , size );
479
- return 1 ;
495
+ return NGX_OK ;
480
496
}
481
497
482
498
0 commit comments