/* * * ProLinga-Validate * * Copyright (C) 2002-2008 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Validate. * * ProLinga-Validate 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-Validate 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-Validate. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "ValCommon.h" #include #include #include #include "VCRepositoryCommand.hpp" #include "ValidateDocument.hpp" #include "ValMain.hpp" int CmdValLogic(const bool transformOnly, const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes, docVal; xmlNodePtr curRes, curVal; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int retStatus = 0; char *logicText, tmpFileName[255], shellCmd[255]; FILE *fp; /* Init */ *docError = NULL; /* Get document from repository */ retStatus = VCrepGet(&docRes, applicationName, objectType, objectName); if (retStatus != 0) { xmlFreeDoc(docRes); return 30006; } /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get Logic Text */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Logic/SourceCode", ctxRes); logicText = (char *)xmlXPathCastToString(resRes); /* Write logic to temp file */ sprintf(tmpFileName, "/usr/tmp/XV-%s", objectName); fp = fopen(tmpFileName, "w"); fprintf(fp, "%s\n", logicText); fclose(fp); /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Validate File */ docRes = ValidateDoc(transformOnly, applicationName, tmpFileName); /* Check for generate errors */ ctxRes = xmlXPathNewContext(docRes); resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Runner/Statements", ctxRes); if(xmlXPathNodeSetIsEmpty(resRes->nodesetval)) { /* xmlBufferPtr bufRes = xmlBufferCreate(); curRes = xmlDocGetRootElement(docRes); xmlNodeDump(bufRes, docRes, curRes, 0, 1); printf("%s\n", (char *)xmlBufferContent(bufRes)); xmlBufferFree(bufRes); */ *docError = xmlCopyDoc(docRes,1); retStatus = 30010; } else { *docError = NULL; /* Create new document */ docVal = xmlNewDoc((const xmlChar *)"1.0"); docVal->children = xmlNewDocNode(docVal, NULL, (const xmlChar *)"ProLinga", NULL); curVal = xmlDocGetRootElement(docVal); curVal = xmlNewTextChild (curVal, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (curVal, (const xmlChar *)"Version", (const xmlChar *)"1.0"); curVal = xmlNewTextChild (curVal, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (curVal, (const xmlChar *)"Name", (const xmlChar *)"Put"); xmlNewProp (curVal, (const xmlChar *)"Mode", (const xmlChar *)"Request"); curVal = xmlNewTextChild (curVal, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp (curVal, (const xmlChar *)"Application", (const xmlChar *)applicationName); xmlNewProp (curVal, (const xmlChar *)"Type", (const xmlChar *)"RunControl"); xmlNewProp (curVal, (const xmlChar *)"Name", (const xmlChar *)objectName); //curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)fileName, (const xmlChar *)""); curVal = xmlNewTextChild (curVal, NULL, (const xmlChar *)"RunControl", (const xmlChar *)""); curRes = xmlDocGetRootElement(docRes); curRes = curRes->children; xmlAddChild(curVal, xmlCopyNodeList(curRes)); /* Write validated document to repository */ retStatus = VCrepPut(docVal); if (retStatus != 0) { xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); xmlFreeDoc(docVal); return 30009; } /* Cleanup */ xmlFreeDoc(docVal); } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); sprintf(shellCmd, "rm %s", tmpFileName); system(shellCmd); /* Return */ return retStatus; }