1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <sys/types.h>
14 #include <anna/core/tracing/Logger.hpp>
15 #include <anna/core/tracing/TraceMethod.hpp>
16 #include <anna/config/defines.hpp>
17 #include <anna/core/functions.hpp>
19 #include <libxml/parser.h>
21 #include <anna/xml/DTDMemory.hpp>
25 using namespace anna::xml;
27 DTDMemory::DTDMemory() {
28 a_filename = "/tmp/anna.xml.";
29 a_filename += functions::asString((int) getpid());
33 //---------------------------------------------------------------------------------------------
34 // Aunque la libXML ofrece funciones para analizar una DTD a partir de un buffer de memoria
35 // hemos sido incapaces de hacerla funcionar correctamente. Así que nos vemos obligados
36 // a volcar el buffer en un archivo .. y una vez allí analizarlo con la función que analiza
37 // la DTD a partir de un archivo.
38 //---------------------------------------------------------------------------------------------
39 _xmlDtd* DTDMemory::parse(const char* content) const
40 throw(RuntimeException) {
41 LOGMETHOD(TraceMethod tf("anna::xml::DTDMemory", "parse", ANNA_FILE_LOCATION));
45 Logger::write(Logger::Debug, "DTD", content, ANNA_FILE_LOCATION);
46 Logger::write(Logger::Debug, "Temporary file", a_filename.c_str(), ANNA_FILE_LOCATION)
49 if((stream = open(a_filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1)
50 throw RuntimeException(a_filename, errno, ANNA_FILE_LOCATION);
52 if(write(stream, content, anna_strlen(content)) == -1) {
53 const int xerrno = errno;
55 unlink(a_filename.c_str());
56 throw RuntimeException(a_filename, xerrno, ANNA_FILE_LOCATION);
61 if((result = xmlParseDTD(NULL, BAD_CAST(a_filename.c_str()))) == NULL) {
62 unlink(a_filename.c_str());
63 throw RuntimeException("DTD is wrong", ANNA_FILE_LOCATION);
66 unlink(a_filename.c_str());