+** NAME : enterXML
+** SYNOPSIS : int enterXML()
+** PARAMETERS :
+** RETURN VALUE : None
+**
+** DESCRIPTION : Analyze the DOM tree from the XML input.
+** The DOM tree was previously parsed by readXMLinput().
+**
+** VARS USED :
+** VARS CHANGED :
+** FUNCTIONS USED :
+** SEE ALSO :
+** LAST MODIFIED : Apr 29, 2003
+**=========================================================================
+*/
+
+void client_message::enterXML()
+{
+ xmlXPathObjectPtr res;
+ xmlXPathContextPtr pathcontext;
+
+ /* Try to find the host in the database */
+
+ String objectid;
+
+ objectid = database.find_host(hostname);
+ if (objectid == "")
+ {
+ std::cerr << "Please define the host " << hostname << " in the database.\n";
+ return;
+ }
+ if (verbose)
+ {
+ std::cout << "Object id for " << hostname << " is " << objectid << "\n";
+ }
+
+ pathcontext = xmlXPathNewContext(xmlDom);
+ pathcontext->node = xmlDocGetRootElement(xmlDom);
+ res = xmlXPathEval((const xmlChar *)"data/node()", pathcontext);
+
+ if (res->nodesetval != NULL)
+ {
+ // Find the first child element of the <data> element.
+
+ xmlNodePtr node = *res->nodesetval->nodeTab;
+ while (node->type != XML_ELEMENT_NODE)
+ {
+ node = node->next;
+ }
+ if (strcmp((char *)node->name, "log") == 0)
+ {
+ // Each child contains a log entry, raw or cooked.
+
+ node = node->children;
+ while (node != NULL)
+ {
+ if (node->type == XML_ELEMENT_NODE)
+ {
+ if (strcmp((char *)node->name, "raw") == 0)
+ {
+ std::cerr << "Can not cook <raw> log elements yet.\n";
+ }
+ else if (strcmp((char *)node->name, "cooked") == 0)
+ {
+ // Find the parts of the log entry
+
+ xmlNodePtr item;
+ String log_hostname;
+ UTC log_date;
+ String raw("");;
+ String log_service;
+
+ if (verbose)
+ {
+ std::cout << "Analyzing cooked element.\n";
+ }
+ pathcontext->node = node;
+
+ res = xmlXPathEval((const xmlChar *)"hostname/text()", pathcontext);
+ if (res->nodesetval != NULL)
+ {
+ item = *res->nodesetval->nodeTab;
+ log_hostname = (const char *)item->content;
+ if (log_hostname != hostname(0, ~log_hostname))
+ {
+ std::cerr << "Hostname " << log_hostname << " does not match.\n";
+ log_hostname = "";
+ }
+ }
+ else
+ {
+ log_hostname = hostname;
+ }
+
+ res = xmlXPathEval((const xmlChar *)"service/text()", pathcontext);
+ if (res->nodesetval != NULL)
+ {
+ item = *res->nodesetval->nodeTab;
+ log_service = (const char *)item->content;
+ }
+ else
+ {
+ log_service = service;
+ }
+
+ res = xmlXPathEval((const xmlChar *)"timestamp/text()", pathcontext);
+ if (res->nodesetval != NULL)
+ {
+ item = *res->nodesetval->nodeTab;
+ log_date = String((const char *)item->content);
+ }
+ else
+ {
+ std::cerr << "<timestamp> missing from cooked log element.\n";
+ }
+
+ res = xmlXPathEval((const xmlChar *)"raw/text()", pathcontext);
+ if (res->nodesetval != NULL)
+ {
+ item = *res->nodesetval->nodeTab;
+ raw = String((const char *)item->content);
+ }
+ else
+ {
+ std::cerr << "<raw> missing from cooked log element.\n";
+ }
+
+ if (raw != "" && log_hostname != "" && log_date.proper())
+ {
+ String insertion("insert into log (objectid, servicecode,"
+ " object_timestamp, timestamp, rawdata, processed) values (");
+
+ /* Insert a new record into the log table */
+
+ insertion += "'" + objectid + "',";
+ insertion += "'" + log_service + "',";
+ insertion += "'" + log_date.format("%Y-%m-%d %T") + "',";
+ insertion += "'" + arrival.format("%Y-%m-%d %T") + "',";
+ insertion += "'" + SQL_Escape(raw) + "',FALSE";
+ insertion += ")";
+
+ if (testmode)
+ {
+ std::cout << insertion << "\n";
+ }
+ else
+ {
+ database.Query(insertion);
+ }
+
+ if (verbose)
+ {
+ std::cout << "\n\n";
+ }
+ }
+ }
+ }
+ node = node->next;
+ }
+ }
+ else
+ {
+ std::cerr << "Data element " << node->name << " is not supported.\n";
+ }
+ }
+ else
+ {
+ std::cerr << "Data node not found.\n";
+ }
+}
+
+/*=========================================================================