/* * * 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 "VCValidateCommand.hpp" #include #include #include "ValConfig.hpp" #include "VCDocumentParse.hpp" #include "ValMain.hpp" #include /* Make sure global handles keep their value */ static char *repositoryEndPointStaticPtr; static int repositoryCompressionLevelStaticPtr; static xmlDocPtr docSyntaxStaticPtr; /* Global handles */ char *repositoryEndPoint = repositoryEndPointStaticPtr; int repositoryCompressionLevel = repositoryCompressionLevelStaticPtr; xmlDocPtr docSyntax = docSyntaxStaticPtr; xmlDocPtr VCProcessError(char *errorString) { xmlDocPtr docValidateResponse; char *validateResponse; /* Generate generic error */ validateResponse = new char[1024]; strcpy(validateResponse, "\n\t\n\t\t\n\t\t\t\n\t\t\t\tError\n\t\t\t\tCan not process Validate Command\n\t\t\t\t"); strcat(validateResponse, errorString); strcat(validateResponse, "\n\t\t\t\n\t\t\n\t\n"); /* Load response into xml doc */ docValidateResponse = xmlParseMemory(validateResponse, strlen(validateResponse)); /* Clean up */ delete validateResponse; /* Return */ return docValidateResponse; } PlValidate::PlValidate() { /* Init */ isValidateOpen = false; } PlValidate::~PlValidate() { /* free */ } void PlValidate::validateOpen(const char *configFileName) { char *confName, *repositoryHost, tmpRepositoryEndPoint[255], *syntaxFile; int repositoryPort; ConfigValPtr confValPtr; /* Return if already open */ if (isValidateOpen == true) return; /* Get Config */ if (configFileName == NULL) confName = DEF_CONFIG_FILE; else confName = (char *)configFileName; /* Get Config */ confValPtr = new ConfigVal(confName); /* Set RepositoryEndPoint */ repositoryHost = confValPtr->getStringValue("RepositoryHost", DEF_REPOSITORY_HOST); repositoryPort = confValPtr->getNumberValue("RepositoryPort", DEF_REPOSITORY_PORT); sprintf(tmpRepositoryEndPoint, "%s:%d", repositoryHost, repositoryPort); /* Set Global value */ repositoryEndPoint = new char[strlen(tmpRepositoryEndPoint)+1]; strcpy(repositoryEndPoint, tmpRepositoryEndPoint); repositoryEndPointStaticPtr = repositoryEndPoint; /* Load Syntax Document */ syntaxFile = confValPtr->getStringValue("LanguageValidationFile", DEF_SYNTAX_FILE); docSyntax = VCParseSyntaxDoc(syntaxFile); docSyntaxStaticPtr = docSyntax; /* Get Repository Compression Level */ repositoryCompressionLevel = confValPtr->getNumberValue("RepositoryCompressionLevel", DEF_REPOSITORY_COMP_LEVEL); /* Set status */ isValidateOpen = true; /* Free */ delete confValPtr; } void PlValidate::validateClose(void) { /* Return if already closed */ if (isValidateOpen == false) return; /* Set status */ isValidateOpen = false; /* Free */ delete repositoryEndPoint; xmlFreeDoc(docSyntax); } xmlDocPtr PlValidate::executeCommand(const xmlDocPtr validateRequest) { xmlDocPtr validateResponse; /* Return if validate not open or process command */ if (isValidateOpen == false) validateResponse = VCProcessError("Validate not opened."); else validateResponse = VCValidateCommand(validateRequest); /* Return */ return validateResponse; }