C based xinclude processor
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 1 Aug 2005 15:00:03 +0000 (15:00 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 1 Aug 2005 15:00:03 +0000 (15:00 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@444 9efc2488-bf62-4759-914b-345cdb29e865

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

diff --git a/src/xinclude/Makefile b/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/src/xinclude/mod_xinclude.c b/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,
+};
+