C based xinclude processor
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 1 Aug 2005 15:00:03 +0000 (15:00 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 1 Aug 2005 15:00:03 +0000 (15:00 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1582 dcc99617-32d9-48b4-a31d-7c20da2025e4

OpenSRF/src/xinclude/Makefile [new file with mode: 0644]
OpenSRF/src/xinclude/mod_xinclude.c [new file with mode: 0644]

diff --git a/OpenSRF/src/xinclude/Makefile b/OpenSRF/src/xinclude/Makefile
new file mode 100644 (file)
index 0000000..b9be5f0
--- /dev/null
@@ -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 (file)
index 0000000..022a149
--- /dev/null
@@ -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 <libxml/parser.h>
+#include <libxml/xinclude.h>
+
+#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,
+};
+