]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/xinclude/mod_xinclude.c
fixed thinko in delete
[Evergreen.git] / OpenSRF / src / xinclude / mod_xinclude.c
1 #include "httpd.h"
2 #include "http_config.h"
3 #include "http_core.h"
4 #include "http_protocol.h"
5 #include "apr_compat.h"
6 #include "apr_strings.h"
7
8 #include <libxml/parser.h>
9 #include <libxml/xinclude.h>
10
11 #define MODULE_NAME "xinclude_module"
12
13 static int mod_xinclude_handler (request_rec *r) {
14
15         /* make sure we're needed first thing*/
16         if (strcmp(r->handler, MODULE_NAME )) 
17                 return DECLINED;
18
19         /* set content type */
20         ap_set_content_type(r, "text/html");
21
22
23         /* which file are we parsing */
24         char* file = r->filename;
25
26         if(!file) { 
27                 fprintf(stderr, "No XML file to parse");
28                 fflush(stderr);
29                 return HTTP_INTERNAL_SERVER_ERROR;
30         }
31
32         /* parse the doc */
33         xmlDocPtr doc = xmlParseFile(file);
34
35         if(!doc) {
36                 fprintf(stderr, "Error parsing XML file %s\n", file);
37                 fflush(stderr);
38                 return HTTP_INTERNAL_SERVER_ERROR;
39         }
40
41         /* process the xincludes */
42         int status = xmlXIncludeProcess(doc);
43         
44         if(status < 0) {
45                 fprintf(stderr, "Error processing XIncludes in  XML file %s\n", file);
46                 fflush(stderr);
47                 return HTTP_INTERNAL_SERVER_ERROR;
48         }
49
50         xmlBufferPtr xmlbuf = xmlBufferCreate();
51         xmlNodeDump( xmlbuf, doc, xmlDocGetRootElement(doc), 0, 0);
52         char* xml = (char*) (xmlBufferContent(xmlbuf));
53
54         ap_rputs(xml,r);
55
56         xmlBufferFree(xmlbuf);
57         xmlFreeDoc(doc);
58
59         return OK;
60 }
61
62
63 static void mod_xinclude_register_hooks (apr_pool_t *p) {
64         ap_hook_handler(mod_xinclude_handler, NULL, NULL, APR_HOOK_MIDDLE);
65 }
66
67 module AP_MODULE_DECLARE_DATA xinclude_module = {
68         STANDARD20_MODULE_STUFF,
69         NULL,
70         NULL,
71         NULL,
72         NULL,
73         NULL,
74         mod_xinclude_register_hooks,
75 };
76