/* * * 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 "VCDocumentParse.hpp" #include "ValMain.hpp" void VCParseErrorResponse(const int errorId, xmlDocPtr *docResponse) { xmlNodePtr curResponse; char dummyId[10]=""; /* Create Error Response file */ *docResponse = xmlNewDoc((const xmlChar *)XML_VERSION); (*docResponse)->children = xmlNewDocNode(*docResponse, NULL, (const xmlChar *)ROOT_ELEM, NULL); curResponse = xmlDocGetRootElement(*docResponse); xmlNewTextChild (curResponse, NULL, (const xmlChar *)"Validate", (const xmlChar *)""); curResponse = (curResponse)->xmlChildrenNode; xmlNewProp (curResponse, (const xmlChar *)"Version", (const xmlChar *)VAL_DOC_VERSION); curResponse = xmlNewTextChild (curResponse, NULL, (const xmlChar *)"Error", (const xmlChar *)""); sprintf(dummyId, "%d", errorId); xmlNewProp (curResponse, (const xmlChar *)"Id", (const xmlChar *)dummyId); xmlNewTextChild (curResponse, NULL, (const xmlChar *)"Severity", (const xmlChar *)"Error"); // xmlNewTextChild (curResponse, NULL, (const xmlChar *)"Severity", (const xmlChar *)errorValSeverity[errorTable10000[errorId-10000].severity]); // xmlNewTextChild (curResponse, NULL, (const xmlChar *)"Description", (const xmlChar *)errorTable10000[errorId-10000].description); xmlNewTextChild (curResponse, NULL, (const xmlChar *)"Description", (const xmlChar *)"Error parsing document"); } int VCDocumentParse(const char *rcIn, const int docType, xmlDocPtr *doc) { xmlNodePtr cur; if (docType == 0) *doc = xmlParseFile(rcIn); else *doc = xmlParseMemory(rcIn, strlen(rcIn)); /* simple validation, implement XML schema at later stage */ if (*doc == NULL) return 10001; cur = xmlDocGetRootElement(*doc); if (cur == NULL) return 10002; if (xmlStrcmp(cur->name, (const xmlChar *) ROOT_ELEM)) return 10003; /* ... etc ... */ return 0; } xmlDocPtr VCParseSyntaxDoc(const char *syntaxFile) { xmlDocPtr docSyntax; int status = 0; /* Parse Document */ status = VCDocumentParse(syntaxFile, PARSE_FILE, &docSyntax); /* Return */ if (status != 0) return NULL; else return docSyntax; }