/* * * 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" #include "CmdValCmd.hpp" int CmdValConstant(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int retStatus = 0; char *dictName; /* 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 DataDictionary */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Constant/DataDictionaryName", ctxRes); if(xmlXPathNodeSetIsEmpty(resRes->nodesetval)) { xmlFreeDoc(docRes); return 30011; } dictName = (char *)xmlXPathCastToString(resRes); /* Check if dictionary exists */ if (VCrepPresent(applicationName, "DataDictionary", dictName) == false) { *docError = ValCreateErrorDoc(); ValInsertPredefinedError(0, 1, 40009, dictName, *docError); retStatus = 30010; } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; } int CmdValIndex(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int i, retStatus = 0, hits = 0; char *dictName, evalString[1024]; /* Init */ *docError = NULL; *docError = ValCreateErrorDoc(); /* Get document from repository */ retStatus = VCrepGet(&docRes, applicationName, objectType, objectName); if (retStatus != 0) { xmlFreeDoc(docRes); return 30006; } /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get number of IndexEntries */ resRes = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Index/OccurrencesIndexEntry/IndexEntry)", ctxRes); hits = (int)xmlXPathCastToNumber(resRes); if (hits == 0) { xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); return 0; } /* Process all data dictionary names */ for (i=1; i<=hits; i++) { sprintf(evalString,"/ProLinga/Repository/Command/Object/Index/OccurrencesIndexEntry/IndexEntry[%d]/DataDictionaryName", i); resRes = xmlXPathEval((const xmlChar *)evalString, ctxRes); dictName = (char *)xmlXPathCastToString(resRes); /* Check if dictionary exists */ if (VCrepPresent(applicationName, "DataDictionary", dictName) == false) { ValInsertPredefinedError(0, i, 40009, dictName, *docError); retStatus = 30010; } } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; } int CmdValRecord(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int i, retStatus = 0, hits = 0; char *dictName, evalString[1024]; /* Init */ *docError = NULL; *docError = ValCreateErrorDoc(); /* Get document from repository */ retStatus = VCrepGet(&docRes, applicationName, objectType, objectName); if (retStatus != 0) { xmlFreeDoc(docRes); return 30006; } /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get number of Record Entries */ resRes = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry)", ctxRes); hits = (int)xmlXPathCastToNumber(resRes); if (hits == 0) { xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); return 0; } /* Process all data dictionary names */ for (i=1; i<=hits; i++) { sprintf(evalString,"/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry[%d]/DataDictionaryName", i); resRes = xmlXPathEval((const xmlChar *)evalString, ctxRes); dictName = (char *)xmlXPathCastToString(resRes); /* Check if dictionary exists */ if (VCrepPresent(applicationName, "DataDictionary", dictName) == false) { ValInsertPredefinedError(0, i, 40009, dictName, *docError); retStatus = 30010; } } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; } int CmdValTable(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int i, retStatus = 0, hits = 0; char *dsrcName, *recName, *idxName, evalString[1024]; /* Init */ *docError = NULL; *docError = ValCreateErrorDoc(); /* Get document from repository */ retStatus = VCrepGet(&docRes, applicationName, objectType, objectName); if (retStatus != 0) { xmlFreeDoc(docRes); return 30006; } /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get DataSource */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataSourceName", ctxRes); if(xmlXPathNodeSetIsEmpty(resRes->nodesetval)) { xmlFreeDoc(docRes); return 30011; } dsrcName = (char *)xmlXPathCastToString(resRes); /* Optional, but if there is a value, check it is ok */ if (strlen(dsrcName) > 0) { /* Check if datasource exists */ if (VCrepPresent(applicationName, "DataSource", dsrcName) == false) { ValInsertPredefinedError(0, 1, 40012, dsrcName, *docError); retStatus = 30010; } } /* Get number of TableRecord Entries */ resRes = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry)", ctxRes); hits = (int)xmlXPathCastToNumber(resRes); if (hits == 0) { xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); return 0; } /* Process all table record names */ for (i=1; i<=hits; i++) { sprintf(evalString,"/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry[%d]/RecordName", i); resRes = xmlXPathEval((const xmlChar *)evalString, ctxRes); recName = (char *)xmlXPathCastToString(resRes); /* Check if dictionary exists */ if (VCrepPresent(applicationName, "Record", recName) == false) { ValInsertPredefinedError(0, i, 40010, recName, *docError); retStatus = 30010; } } /* Get number of TableIndex Entries */ resRes = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Table/OccurrencesTableIndexEntry/TableIndexEntry)", ctxRes); hits = (int)xmlXPathCastToNumber(resRes); if (hits == 0) { xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); return 0; } /* Process all table record names */ for (i=1; i<=hits; i++) { sprintf(evalString,"/ProLinga/Repository/Command/Object/Table/OccurrencesTableIndexEntry/TableIndexEntry[%d]/IndexName", i); resRes = xmlXPathEval((const xmlChar *)evalString, ctxRes); idxName = (char *)xmlXPathCastToString(resRes); /* Check if index exists */ if (VCrepPresent(applicationName, "Index", idxName) == false) { ValInsertPredefinedError(0, i, 40011, idxName, *docError); retStatus = 30010; } } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; } int CmdValThread(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int retStatus = 0; char *logicName; /* 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 */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Thread/LogicName", ctxRes); if(xmlXPathNodeSetIsEmpty(resRes->nodesetval)) { xmlFreeDoc(docRes); return 30011; } logicName = (char *)xmlXPathCastToString(resRes); /* Check if logic exists */ if (VCrepPresent(applicationName, "Logic", logicName) == false) { *docError = ValCreateErrorDoc(); ValInsertPredefinedError(0, 1, 40013, logicName, *docError); retStatus = 30010; } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; } int CmdValVariable(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int retStatus = 0; char *dictName; /* 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 DataDictionary */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Variable/DataDictionaryName", ctxRes); if(xmlXPathNodeSetIsEmpty(resRes->nodesetval)) { xmlFreeDoc(docRes); return 30011; } dictName = (char *)xmlXPathCastToString(resRes); /* Check if dictionary exists */ if (VCrepPresent(applicationName, "DataDictionary", dictName) == false) { *docError = ValCreateErrorDoc(); ValInsertPredefinedError(0, 1, 40009, dictName, *docError); retStatus = 30010; } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; } int CmdValVariableGroup(const char *applicationName, const char *objectType, const char *objectName, char **externalError, xmlDocPtr *docError) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; int i, retStatus = 0, hits = 0; char *dictName, evalString[1024]; /* Init */ *docError = NULL; *docError = ValCreateErrorDoc(); /* Get document from repository */ retStatus = VCrepGet(&docRes, applicationName, objectType, objectName); if (retStatus != 0) { xmlFreeDoc(docRes); return 30006; } /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get number of Variable Group Entries */ resRes = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/VariableGroup/OccurrencesVariableEntry/VariableEntry)", ctxRes); hits = (int)xmlXPathCastToNumber(resRes); if (hits == 0) { xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); return 0; } /* Process all data dictionary names */ for (i=1; i<=hits; i++) { sprintf(evalString,"/ProLinga/Repository/Command/Object/VariableGroup/OccurrencesVariableEntry/VariableEntry[%d]/DataDictionaryName", i); resRes = xmlXPathEval((const xmlChar *)evalString, ctxRes); dictName = (char *)xmlXPathCastToString(resRes); /* Check if dictionary exists */ if (VCrepPresent(applicationName, "DataDictionary", dictName) == false) { ValInsertPredefinedError(0, i, 40009, dictName, *docError); retStatus = 30010; } } /* Cleanup */ xmlXPathFreeContext(ctxRes); xmlFreeDoc(docRes); /* Return */ return retStatus; }