Browse Source

[lua] handle filter->vr == NULL in lua filters, handle filter->in == NULL in xsendfile

Change-Id: I5326ce72f1b45bf0b64194e6ec8935b6261d18d2
personal/stbuehler/wip
Stefan Bühler 6 years ago
parent
commit
b37d95facf
  1. 14
      contrib/core__xsendfile.lua
  2. 8
      src/main/filter.c
  3. 5
      src/main/filters_lua.c

14
contrib/core__xsendfile.lua

@ -17,8 +17,11 @@ end
-- normal method to handle content
function XFilterDrop:handle(vr, outq, inq)
-- drop further input (we closed it already)
inq:skip_all()
-- drop input, close it
if nil ~= inq then
inq.is_closed = true
inq:skip_all()
end
return lighty.HANDLER_GO_ON
end
@ -26,8 +29,11 @@ end
-- returns the filter object so you can insert your own content in f.out (it is already closed)
local function add_drop_filter(vr)
local f = vr:add_filter_out(XFilterDrop:new())
f['in'].is_closed = true
f['in']:skip_all()
local inq = f['in']
if nil ~= inq then
inq.is_closed = true
inq:skip_all()
end
f.out.is_closed = true
return f
end

8
src/main/filter.c

@ -139,12 +139,9 @@ liFilter* li_filter_new(liVRequest* vr, liFilterHandlerCB handle_data, liFilterF
static void li_filter_stop(liFilter *filter) {
liVRequest *vr = filter->vr;
if (NULL == vr) return;
filter->vr = NULL;
/* remove from vr filters list */
LI_FORCE_ASSERT(vr->filters->len > 0);
LI_FORCE_ASSERT(g_ptr_array_index(vr->filters, filter->filter_ndx) == filter);
if (vr->filters->len - 1 != filter->filter_ndx) {
/* not the last filter, swap: */
liFilter *last = g_ptr_array_index(vr->filters, vr->filters->len - 1);
@ -153,8 +150,7 @@ static void li_filter_stop(liFilter *filter) {
}
g_ptr_array_set_size(vr->filters, vr->filters->len - 1);
li_stream_again(&filter->stream);
filter->vr = NULL;
li_stream_release(&filter->stream);
}

5
src/main/filters_lua.c

@ -202,7 +202,7 @@ static filter_lua_state* filter_lua_state_new(liVRequest *vr, filter_lua_config
}
static void filter_lua_state_free(liVRequest *vr, filter_lua_state *state) {
liServer *srv = vr->wrk->srv;
liServer *srv = NULL != vr ? vr->wrk->srv : NULL;
lua_State *L = state->LL->L;
li_lua_lock(state->LL);
@ -225,6 +225,7 @@ static void filter_lua_free(liVRequest *vr, liFilter *f) {
}
static liHandlerResult filter_lua_handle(liVRequest *vr, liFilter *f) {
liServer *srv = NULL != vr ? vr->wrk->srv : NULL;
filter_lua_state *state = (filter_lua_state*) f->param;
lua_State *L = state->LL->L;
liHandlerResult res;
@ -235,7 +236,7 @@ static liHandlerResult filter_lua_handle(liVRequest *vr, liFilter *f) {
li_lua_push_vrequest(L, vr); /* +1 */
li_lua_push_chunkqueue(L, f->out); /* +1 */
li_lua_push_chunkqueue(L, f->in); /* +1 */
if (li_lua_call_object(NULL, vr, L, "handle", 4, 1, FALSE)) { /* -4, +1 on success */
if (li_lua_call_object(srv, vr, L, "handle", 4, 1, FALSE)) { /* -4, +1 on success */
res = LI_HANDLER_GO_ON;
if (!lua_isnil(L, -1)) {
int rc = lua_tointeger(L, -1);

Loading…
Cancel
Save