From a760a9a3f1abe2aa9443a5dce0fcad2eebb77215 Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 2 May 2013 10:04:04 +0200 Subject: [PATCH] ported the xslt plugin to the new api --- buildconf/all.ini | 2 +- plugins/xslt/uwsgiplugin.py | 4 ++-- plugins/xslt/xslt.c | 21 ++++++++------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/buildconf/all.ini b/buildconf/all.ini index 8fd474a5..c86e5fb2 100644 --- a/buildconf/all.ini +++ b/buildconf/all.ini @@ -1,3 +1,3 @@ [uwsgi] -main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi +main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav inherit = base diff --git a/plugins/xslt/uwsgiplugin.py b/plugins/xslt/uwsgiplugin.py index 593ab80f..8a8c20c1 100644 --- a/plugins/xslt/uwsgiplugin.py +++ b/plugins/xslt/uwsgiplugin.py @@ -2,7 +2,7 @@ import os NAME='xslt' CFLAGS = os.popen('xslt-config --cflags').read().rstrip().split() -LDFLAGS = os.popen('xslt-config --libs').read().rstrip().split() -LIBS = [] +LDFLAGS = [] +LIBS = os.popen('xslt-config --libs').read().rstrip().split() GCC_LIST = ['xslt'] diff --git a/plugins/xslt/xslt.c b/plugins/xslt/xslt.c index f1c7c855..b39880b5 100644 --- a/plugins/xslt/xslt.c +++ b/plugins/xslt/xslt.c @@ -316,9 +316,10 @@ static void uwsgi_xslt_log(struct wsgi_request *wsgi_req) { log_request(wsgi_req); } -static int transform_toxslt(struct wsgi_request *wsgi_req, struct uwsgi_buffer *ub, struct uwsgi_buffer **new, void *data) { +static int transform_toxslt(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) { int ret = -1; - struct uwsgi_transformation_xslt_conf *utxc = (struct uwsgi_transformation_xslt_conf *) data; + struct uwsgi_transformation_xslt_conf *utxc = (struct uwsgi_transformation_xslt_conf *) ut->data; + struct uwsgi_buffer *ub = ut->chunk; xmlDoc *doc = xmlReadMemory(ub->buf, ub->pos, NULL, NULL, 0); if (!doc) goto end; @@ -327,18 +328,12 @@ static int transform_toxslt(struct wsgi_request *wsgi_req, struct uwsgi_buffer * char *output = uwsgi_xslt_apply( doc, utxc->stylesheet->buf, utxc->params ? utxc->params->buf : NULL, &rlen); if (!output) goto end; - if (uwsgi_response_prepare_headers_int(wsgi_req, wsgi_req->status)) goto end; - if (uwsgi_response_add_content_length(wsgi_req, rlen)) goto end; - if (uwsgi_response_add_content_type(wsgi_req, utxc->content_type->buf, utxc->content_type->pos)) goto end; - - *new = uwsgi_buffer_new(rlen); - if (uwsgi_buffer_append(*new, output, rlen)) { - xmlFree(output); - uwsgi_buffer_destroy(*new); - *new = NULL; - goto end; + // do not check for errors !!! + if (ut->round == 1) { + uwsgi_response_add_content_type(wsgi_req, utxc->content_type->buf, utxc->content_type->pos); } - xmlFree(output); + + uwsgi_buffer_map(ub, output, rlen); ret = 0; end: