You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2012/08/27 13:58:34 UTC
svn commit: r1377647 - /httpd/httpd/trunk/modules/lua/mod_lua.c
Author: humbedooh
Date: Mon Aug 27 11:58:34 2012
New Revision: 1377647
URL: http://svn.apache.org/viewvc?rev=1377647&view=rev
Log:
Fix some style issues, use a more persistent bucket for passing along data (and clean it up the right places), and remove in/out-put filters from the chain if need be.
Modified:
httpd/httpd/trunk/modules/lua/mod_lua.c
Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=1377647&r1=1377646&r2=1377647&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
+++ httpd/httpd/trunk/modules/lua/mod_lua.c Mon Aug 27 11:58:34 2012
@@ -390,7 +390,6 @@ static apr_status_t lua_output_filter_ha
lua_filter_ctx* ctx;
conn_rec *c = r->connection;
apr_bucket *pbktIn;
- apr_bucket_brigade *pbbOut = NULL;
/* Set up the initial filter context and acquire the function.
* The corresponding Lua function should yield here.
@@ -402,15 +401,16 @@ static apr_status_t lua_output_filter_ha
}
if (rc == APR_ENOENT) {
/* No filter entry found (or the script declined to filter), just pass on the buckets */
+ ap_remove_output_filter(f);
return ap_pass_brigade(f->next,pbbIn);
}
f->ctx = ctx;
+ ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
}
ctx = (lua_filter_ctx*) f->ctx;
L = ctx->L;
/* While the Lua function is still yielding, pass in buckets to the coroutine */
if (!ctx->broken) {
- pbbOut=apr_brigade_create(r->pool, c->bucket_alloc);
for (pbktIn = APR_BRIGADE_FIRST(pbbIn);
pbktIn != APR_BRIGADE_SENTINEL(pbbIn);
pbktIn = APR_BUCKET_NEXT(pbktIn))
@@ -432,11 +432,16 @@ static apr_status_t lua_output_filter_ha
const char* output = lua_tolstring(L, 1, &olen);
pbktOut = apr_bucket_heap_create(output, olen, NULL,
c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut);
+ APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
+ ap_pass_brigade(f->next, ctx->tmpBucket);
+ apr_brigade_cleanup(ctx->tmpBucket);
}
else {
ctx->broken = 1;
ap_lua_release_state(L, ctx->spec, r);
+ ap_remove_output_filter(f);
+ apr_brigade_cleanup(pbbIn);
+ apr_brigade_cleanup(ctx->tmpBucket);
return HTTP_INTERNAL_SERVER_ERROR;
}
}
@@ -452,21 +457,17 @@ static apr_status_t lua_output_filter_ha
const char* output = lua_tolstring(L, 1, &olen);
pbktOut = apr_bucket_heap_create(output, olen, NULL,
c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut);
+ APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktOut);
}
- pbktEOS=apr_bucket_eos_create(c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS);
+ pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(ctx->tmpBucket, pbktEOS);
ap_lua_release_state(L, ctx->spec, r);
+ ap_pass_brigade(f->next, ctx->tmpBucket);
}
}
- /* Clean up and pass on the brigade to the next filter in the chain */
+ /* Clean up */
apr_brigade_cleanup(pbbIn);
- if (pbbOut) {
- return ap_pass_brigade(f->next,pbbOut);
- }
- else {
- return ap_pass_brigade(f->next,pbbIn);
- }
+ return APR_SUCCESS;
}
@@ -490,14 +491,18 @@ static apr_status_t lua_input_filter_han
if (!f->ctx) {
rc = lua_setup_filter_ctx(f,r,&ctx);
f->ctx = ctx;
- ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
if (rc == APR_EGENERAL) {
ctx->broken = 1;
+ ap_remove_input_filter(f);
return HTTP_INTERNAL_SERVER_ERROR;
}
if (rc == APR_ENOENT ) {
+ ap_remove_input_filter(f);
ctx->broken = 1;
}
+ if (rc == APR_SUCCESS) {
+ ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
+ }
}
ctx = (lua_filter_ctx*) f->ctx;
L = ctx->L;
@@ -508,7 +513,6 @@ static apr_status_t lua_input_filter_han
if (APR_BRIGADE_EMPTY(ctx->tmpBucket)) {
ret = ap_get_brigade(f->next, ctx->tmpBucket, eMode, eBlock, nBytes);
-
if (eMode == AP_MODE_EATCRLF || ret != APR_SUCCESS)
return ret;
}
@@ -528,7 +532,7 @@ static apr_status_t lua_input_filter_han
}
/* read the bucket */
- ret=apr_bucket_read(pbktIn, &data, &len, eBlock);
+ ret = apr_bucket_read(pbktIn, &data, &len, eBlock);
if(ret != APR_SUCCESS) {
return ret;
}
@@ -549,6 +553,8 @@ static apr_status_t lua_input_filter_han
else {
ctx->broken = 1;
ap_lua_release_state(L, ctx->spec, r);
+ ap_remove_input_filter(f);
+ apr_bucket_delete(pbktIn);
return HTTP_INTERNAL_SERVER_ERROR;
}
}