/*
*
* ProLinga-Web
*
* Copyright (C) 2002-2008 Xobas Software.
* All rights reserved.
*
* This file is part of ProLinga-Web.
*
* ProLinga-Web is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProLinga-Web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProLinga-Web. If not, see .
*
* More information is available at the following addresses:
*
* Website : http://www.prolinga.org
*
* Email : prolinga-list@prolinga.org
*
*
*/
#include "WebCommon.h"
#include
#include
#include
#include
#include
#include
#include
#include "WebProcess.hpp"
int WebProcess(xmlDocPtr docRes)
{
xmlDocPtr docReturn, docTrans;
xmlNodePtr curRes;
xmlXPathContextPtr ctxRes;
xmlXPathObjectPtr resRes;
xsltStylesheetPtr xslWeb = NULL;
char *format, *content, *transform, *transFormat;
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Find out Format */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/@Format", ctxRes);
format = (char *)xmlXPathCastToString(resRes);
if (strcmp(format, "XML") == 0)
{
/* Position to response */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/Object/Response", ctxRes);
curRes = resRes->nodesetval->nodeTab[0]->xmlChildrenNode;
while (curRes != NULL)
{
if (xmlNodeIsText(curRes) == 0)
break;
curRes = curRes->next;
}
docReturn = xmlNewDoc((const xmlChar *)"1.0");
if (curRes == NULL)
docReturn->children = xmlNewDocNode(docRes, NULL, (const xmlChar *)"Null", NULL);
else
docReturn->children = xmlCopyNodeList(curRes);
/* Find out if requires a transform */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/Object/Transform", ctxRes);
if (resRes->nodesetval != NULL && resRes->nodesetval->nodeNr > 0)
{
/* Get xslt document name */
transform = (char *)xmlXPathCastToString(resRes);
/* Get output format */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/Object/Transform/@Format", ctxRes);
transFormat = (char *)xmlXPathCastToString(resRes);
/* Load style sheet */
xmlLoadExtDtdDefaultValue = 1;
xslWeb = xsltParseStylesheetFile((const xmlChar *)transform);
/* Apply Style Sheet */
docTrans = xsltApplyStylesheet(xslWeb, docReturn, NULL);
/* Print result */
if (strcmp(transFormat, "XML") == 0)
printf("Content-type: text/xml\n\n");
else if (strcmp(transFormat, "WML") == 0)
printf("Content-type: text/vnd.wap.wml\n\n");
else if (strcmp(transFormat, "HTML") == 0)
printf("Content-type: text/html\n\n");
else
printf("Content-type: text/plain\n\n");
xsltSaveResultToFile(stdout, docTrans, xslWeb);
/* Clean up style sheet */
xsltFreeStylesheet(xslWeb);
xmlFreeDoc(docTrans);
}
else
{
/* Print response */
printf("Content-type: text/xml\n\n");
xmlSaveFile("-", docReturn);
}
}
else if (strcmp(format, "HTML") == 0)
{
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/Object/Response", ctxRes);
content = (char *)xmlXPathCastToString(resRes);
printf("Content-type: text/html\n\n");
printf("%s\n", content);
}
else if (strcmp(format, "WML") == 0)
{
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/Object/Response", ctxRes);
content = (char *)xmlXPathCastToString(resRes);
printf("Content-type: text/vnd.wap.wml\n\n");
printf("%s\n", content);
}
else if (strcmp(format, "TEXT") == 0)
{
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Web/Command/Object/Response", ctxRes);
content = (char *)xmlXPathCastToString(resRes);
printf("Content-type: text/plain\n\n");
printf("%s\n", content);
}
else
{
printf("Content-type: text/plain\n\n");
printf("ProLinga-Web: Invalid service or unsupported format selected.\n");
printf("\nVersion: %s\n", VERSION);
printf("Copyright © 2002-2008 The ProLinga Team.\n");
printf("All rights reserved.\n");
}
/* Return */
return 0;
}