From e2a7306687a3bd83fd23999a0b8274ec5b4bf7b2 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 1 Aug 2005 15:00:03 +0000 Subject: [PATCH] C based xinclude processor git-svn-id: svn://svn.open-ils.org/ILS/trunk@1582 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- OpenSRF/src/xinclude/Makefile | 22 +++++++++ OpenSRF/src/xinclude/mod_xinclude.c | 73 +++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 OpenSRF/src/xinclude/Makefile create mode 100644 OpenSRF/src/xinclude/mod_xinclude.c diff --git a/OpenSRF/src/xinclude/Makefile b/OpenSRF/src/xinclude/Makefile new file mode 100644 index 0000000000..b9be5f0d24 --- /dev/null +++ b/OpenSRF/src/xinclude/Makefile @@ -0,0 +1,22 @@ +SO=mod_xinclude.so + +# -------------------------------------------------------- +#TMPDIR = /tmp/ilstmp/opensrf +#LIBDIR = /openils/lib +#CC_OPTS = -Wall -O2 -fPIC -I /usr/include/libxml2 -I /opt/include +#LD_OPTS = -lxml2 +#APXS2 = /opt/bin/apxs +# -------------------------------------------------------- + +all: $(SO) + +install: + cp $(TMPDIR)/$(SO) $(LIBDIR)/$(SO) + $(APXS2) -i -a -n xinclude $(LIBDIR)/$(SO) + +$(SO): mod_xinclude.c + $(CC) -c $(CC_OPTS) mod_xinclude.c + $(CC) $(LD_OPTS) -shared -W1 mod_xinclude.o -o $(TMPDIR)/$(SO) + +clean: + /bin/rm -f *.o *.so diff --git a/OpenSRF/src/xinclude/mod_xinclude.c b/OpenSRF/src/xinclude/mod_xinclude.c new file mode 100644 index 0000000000..022a149439 --- /dev/null +++ b/OpenSRF/src/xinclude/mod_xinclude.c @@ -0,0 +1,73 @@ +#include "httpd.h" +#include "http_config.h" +#include "http_core.h" +#include "http_protocol.h" +#include "apr_compat.h" +#include "apr_strings.h" + +#include +#include + +#define MODULE_NAME "xinclude_module" + +static int mod_xinclude_handler (request_rec *r) { + + /* make sure we're needed first thing*/ + if (strcmp(r->handler, MODULE_NAME )) + return DECLINED; + + /* set content type */ + ap_set_content_type(r, "text/html"); + + + /* which file are we parsing */ + char* file = r->filename; + + if(!file) { + fprintf(stderr, "No XML file to parse"); + return HTTP_INTERNAL_SERVER_ERROR; + } + + /* parse the doc */ + xmlDocPtr doc = xmlParseFile(file); + + if(!doc) { + fprintf(stderr, "Error parsing XML file %s\n", file); + return HTTP_INTERNAL_SERVER_ERROR; + } + + /* process the xincludes */ + int status = xmlXIncludeProcess(doc); + + if(status < 0) { + fprintf(stderr, "Error processing XIncludes in XML file %s\n", file); + return HTTP_INTERNAL_SERVER_ERROR; + } + + xmlBufferPtr xmlbuf = xmlBufferCreate(); + xmlNodeDump( xmlbuf, doc, xmlDocGetRootElement(doc), 0, 0); + char* xml = (char*) (xmlBufferContent(xmlbuf)); + + ap_rputs(xml,r); + + xmlBufferFree(xmlbuf); + xmlFreeDoc(doc); + + return OK; +} + + +static void mod_xinclude_register_hooks (apr_pool_t *p) { + ap_hook_handler(mod_xinclude_handler, NULL, NULL, APR_HOOK_MIDDLE); +} + +module AP_MODULE_DECLARE_DATA xinclude_module = { + STANDARD20_MODULE_STUFF, + NULL, + NULL, + NULL, + NULL, + NULL, + mod_xinclude_register_hooks, +}; + -- 2.43.2