*****************************/
-static const char *RCSID = "$Id: message.cpp,v 1.19 2011-03-24 10:20:37 arjen Exp $";
+#include <unistd.h>
+#include <fstream>
#include <algorithm>
#include <libxml/xpath.h>
#include <libxml/debugXML.h>
+
#include "message.h"
//#define DEBUG
}
if (strcmp((char *)node->name, "log") == 0)
{
+ int log_entry_counter = 0;
+
// Each child contains a log entry, raw or cooked.
node = node->children;
{
if (node->type == XML_ELEMENT_NODE)
{
+ log_entry_counter++;
+
xmlNodePtr item;
String log_hostname;
UTC log_date;
String raw("");;
String log_service;
+ if (verbose)
+ {
+ *Log << "Log entry " << log_entry_counter << " is " << node->name << "\n";
+ }
if (strcmp((char *)node->name, "raw") == 0 && node->children != NULL)
{
item = node->children;
}
else
{
- *Log << "<timestamp> missing from cooked log element.\n";
+ *Log << "<timestamp> missing from cooked log element nr " << log_entry_counter << ".\n";
}
res = xmlXPathEval((const xmlChar *)"raw/text()", pathcontext);
}
else
{
- *Log << "<raw> missing from cooked log element.\n";
+ *Log << "<raw> missing from cooked log element nr " << log_entry_counter << ".\n";
}
}
}
}
+void client_message::saveXML(String filename)
+{
+ std::ofstream xmlfile;
+
+ xmlfile.open(filename);
+ xmlfile << xmlBuffer.str();
+}
+
/*=========================================================================
** NAME : enter
** SYNOPSIS : int enter()
** PARAMETERS :
** RETURN VALUE : The number of lines successfully parsed from the input
+** or a negative number if an error is encountered.
+** The error return values are:
+** -1 No database connection.
+** -2 XML parser error.
**
** DESCRIPTION :
**
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Nov 26, 2003
+** LAST MODIFIED : Sep 22, 2020
**=========================================================================
*/
int client_message::enter()
{
+ int nr_lines = 0;
+
pan.mf->set_message_type(pan.lc->message_type());
pan.mf->construct_XML(input, xmlBuffer);
xmlDom = xmlParseMemory(xmlBuffer.str(), xmlBuffer.pcount());
- if (xmlDom)
+ if (database.is_connected())
{
- if (extractHeader())
+ if (xmlDom)
+ {
+ if (extractHeader())
+ {
+ enterXML();
+ }
+ }
+ else
{
- enterXML();
+ *Log << "XML parser FAILED.\n";
+ nr_lines = -2; // XML parse error
}
}
else
{
- *Log << "XML parser FAILED.\n";
+ *Log << "Database connection FAILED.\n";
+ nr_lines = -1; // No database connection
}
- return 0;
+ return nr_lines;
}