summaryrefslogtreecommitdiff
path: root/project2/p2webMain.cpp
blob: 716495f0cd686cc9a70ca66c049d76133985b599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <libxml/tree.h>
#include <fcgi_stdio.h>
#include "envproc.h"
#include <boost/bind.hpp>

int
xmlWrite(void * _out, const char * buf, int len)
{
	return FCGX_PutStr(buf, len, (FCGX_Stream*)_out);
}

int main(void)
{
	FCGX_Stream *in, *_out, *err;
	FCGX_ParamArray envp;

	while (FCGX_Accept(&in, &_out, &err, &envp) >= 0) 
	{
		try {
			EnvironmentProcessor ep(boost::bind(FCGX_GetParam, _1, envp));

			xmlDoc * doc = ep.process();

			FCGX_FPrintF(_out, "Content-type: text/xml-xslt\r\n\r\n");      
			xmlOutputBufferPtr out = xmlOutputBufferCreateIO(
					xmlWrite, NULL, _out, xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8));
			xmlSaveFileTo(out, doc, NULL);
			xmlFreeDoc(doc);
		}
		catch (const std::exception & e) {
			FCGX_FPrintF(_out, "Content-type: text/plain\r\n\r\n");      
			FCGX_FPrintF(_out, "Kaboom!\r\n\r\n");      
			FCGX_FPrintF(_out, "%s\r\n\r\n", e.what());      
		}
		catch (...) {
			FCGX_FPrintF(_out, "Content-type: text/plain\r\n\r\n");      
			FCGX_FPrintF(_out, "Kaboom!\r\n\r\n");      
			FCGX_FPrintF(_out, "Unknown exception.\r\n\r\n");      
		}
	}
	return 0;
}