TS-2333 Change the SAX callbacks to not clash with libxml2
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/03cb4153 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/03cb4153 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/03cb4153 Branch: refs/heads/5.0.x Commit: 03cb4153fbcae13921711fefc0cfe8eb649f71d3 Parents: 752e01e Author: Leif Hedstrom <[email protected]> Authored: Tue Nov 12 11:18:42 2013 -0700 Committer: Leif Hedstrom <[email protected]> Committed: Tue Nov 12 15:36:32 2013 -0700 ---------------------------------------------------------------------- CHANGES | 3 ++ mgmt/stats/StatProcessor.cc | 66 ++++++++++++++++++++++++++-------------- mgmt/stats/StatProcessor.h | 3 ++ mgmt/utils/XmlUtils.cc | 6 ++-- 4 files changed, 52 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/03cb4153/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index ff4ea6e..17ec11f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 4.2.0 + *) [TS-2333] Change the SAX callbacks to not clash with libxml2, which broke + synthetic metric completely. + *) [TS-2339] Cleanup Makefile.am, fixing missing / wrong _SOURCES entries. *) [TS-2341] Cast TSHttpStatus to int to suppress compiler warning in clang http://git-wip-us.apache.org/repos/asf/trafficserver/blob/03cb4153/mgmt/stats/StatProcessor.cc ---------------------------------------------------------------------- diff --git a/mgmt/stats/StatProcessor.cc b/mgmt/stats/StatProcessor.cc index 93a3f05..aeee702 100644 --- a/mgmt/stats/StatProcessor.cc +++ b/mgmt/stats/StatProcessor.cc @@ -43,19 +43,39 @@ static unsigned statCount = 0; // global statistics object counter bool nodeVar; bool sumClusterVar; +// These helpers are used to work around the unsigned char'iness of xmlchar when +// using libxml2. We don't have any tags (now) which uses UTF8. +static int +xml_atoi(const xmlchar *nptr) +{ + return atoi((const char*)nptr); +} -void -startElement(void * /* userData ATS_UNUSED */, const char *name, const char **atts) +static double +xml_atof(const xmlchar *nptr) +{ + return atof((const char*)nptr); +} + +static int +xml_strcmp(const xmlchar *s1, const char *s2) +{ + return strcmp((const char *)s1, s2); +} + + +static void +elementStart(void * /* userData ATS_UNUSED */, const xmlchar *name, const xmlchar **atts) { int i = 0; - if (!strcmp(name, "ink:statistics")) + if (!xml_strcmp(name, "ink:statistics")) currentTag = ROOT_TAG; - else if (!strcmp(name, "statistics")) + else if (!xml_strcmp(name, "statistics")) currentTag = STAT_TAG; - else if (!strcmp(name, "destination")) + else if (!xml_strcmp(name, "destination")) currentTag = DST_TAG; - else if (!strcmp(name, "expression")) + else if (!xml_strcmp(name, "expression")) currentTag = EXPR_TAG; else currentTag = INVALID_TAG; @@ -69,15 +89,15 @@ startElement(void * /* userData ATS_UNUSED */, const char *name, const char **at for (i = 0; atts[i]; i += 2) { ink_assert(atts[i + 1]); // Attribute comes in pairs, hopefully. - if (!strcmp(atts[i], "minimum")) { - statObject->m_stats_min = (MgmtFloat) atof(atts[i + 1]); + if (!xml_strcmp(atts[i], "minimum")) { + statObject->m_stats_min = (MgmtFloat) xml_atof(atts[i + 1]); statObject->m_has_min = true; - } else if (!strcmp(atts[i], "maximum")) { - statObject->m_stats_max = (MgmtFloat) atof(atts[i + 1]); + } else if (!xml_strcmp(atts[i], "maximum")) { + statObject->m_stats_max = (MgmtFloat) xml_atof(atts[i + 1]); statObject->m_has_max = true; - } else if (!strcmp(atts[i], "interval")) { - statObject->m_update_interval = (ink_hrtime) atoi(atts[i + 1]); - } else if (!strcmp(atts[i], "debug")) { + } else if (!xml_strcmp(atts[i], "interval")) { + statObject->m_update_interval = (ink_hrtime) xml_atoi(atts[i + 1]); + } else if (!xml_strcmp(atts[i], "debug")) { statObject->m_debug = (atts[i + 1] && atts[i + 1][0] == '1'); } @@ -97,10 +117,10 @@ startElement(void * /* userData ATS_UNUSED */, const char *name, const char **at if (atts) for (i = 0; atts[i]; i += 2) { ink_assert(atts[i + 1]); // Attribute comes in pairs, hopefully. - if (!strcmp(atts[i], "scope")) { - nodeVar = (!strcmp(atts[i + 1], "node") ? true : false); - } else if (!strcmp(atts[i], "operation")) { - sumClusterVar = (!strcmp(atts[i + 1], "sum") ? true : false); + if (!xml_strcmp(atts[i], "scope")) { + nodeVar = (!xml_strcmp(atts[i + 1], "node") ? true : false); + } else if (!xml_strcmp(atts[i], "operation")) { + sumClusterVar = (!xml_strcmp(atts[i + 1], "sum") ? true : false); } Debug(MODULE_INIT, "\tDESTINTATION w/ attribute: %s -> %s\n", atts[i], atts[i + 1]); @@ -118,8 +138,8 @@ startElement(void * /* userData ATS_UNUSED */, const char *name, const char **at } -void -endElement(void * /* userData ATS_UNUSED */, const char */* name ATS_UNUSED */) +static void +elementEnd(void * /* userData ATS_UNUSED */, const xmlchar */* name ATS_UNUSED */) { switch (currentTag) { case STAT_TAG: @@ -138,7 +158,7 @@ endElement(void * /* userData ATS_UNUSED */, const char */* name ATS_UNUSED */) } -void +static void charDataHandler(void * /* userData ATS_UNUSED */, const xmlchar * name, int /* len ATS_UNUSED */) { if (currentTag != EXPR_TAG && currentTag != DST_TAG) { @@ -192,7 +212,7 @@ StatProcessor::rereadConfig() */ XML_Parser parser = XML_ParserCreate(NULL); XML_SetUserData(parser, NULL); - XML_SetElementHandler(parser, startElement, endElement); + XML_SetElementHandler(parser, elementStart, elementEnd); XML_SetCharacterDataHandler(parser, charDataHandler); /* @@ -221,8 +241,8 @@ StatProcessor::rereadConfig() /* Parse XML with libxml2 */ xmlSAXHandler sax; memset(&sax, 0, sizeof(xmlSAXHandler)); - sax.startElement = startElement; - sax.endElement = endElement; + sax.startElement = elementStart; + sax.endElement = elementEnd; sax.characters = charDataHandler; sax.initialized = 1; xmlParserCtxtPtr parser = xmlCreatePushParserCtxt(&sax, NULL, NULL, 0, NULL); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/03cb4153/mgmt/stats/StatProcessor.h ---------------------------------------------------------------------- diff --git a/mgmt/stats/StatProcessor.h b/mgmt/stats/StatProcessor.h index e543e6c..dccd213 100644 --- a/mgmt/stats/StatProcessor.h +++ b/mgmt/stats/StatProcessor.h @@ -46,15 +46,18 @@ #define _FOOTER #include "DynamicStats.h" #include "StatType.h" + #if HAVE_LIBEXPAT #include "expat.h" typedef XML_Char xmlchar; #elif HAVE_LIBXML2 #include <libxml/parser.h> +#include <libxml/SAX2.h> typedef xmlChar xmlchar; #else # error "No XML parser - please configure expat or libxml2" #endif + #include <string.h> #include <stdlib.h> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/03cb4153/mgmt/utils/XmlUtils.cc ---------------------------------------------------------------------- diff --git a/mgmt/utils/XmlUtils.cc b/mgmt/utils/XmlUtils.cc index 317703f..21b56f4 100644 --- a/mgmt/utils/XmlUtils.cc +++ b/mgmt/utils/XmlUtils.cc @@ -386,7 +386,7 @@ XMLNode::getAttributeValueByName(const char *pAName) return p; } -void /*XMLDom:: */ +static void /*XMLDom:: */ elementStart(void *pObj, const xmlchar *el, const xmlchar **attr) { XMLDom *pDom = (XMLDom *) pObj; @@ -427,7 +427,7 @@ elementStart(void *pObj, const xmlchar *el, const xmlchar **attr) } } -void /*XMLDom:: */ +static void /*XMLDom:: */ elementEnd(void *pObj, const xmlchar * /* el ATS_UNUSED */) { /*ASSERT(strcmp(el, pCur->pNodeName) == 0); */ @@ -435,7 +435,7 @@ elementEnd(void *pObj, const xmlchar * /* el ATS_UNUSED */) pDom->m_pCur = pDom->m_pCur->m_pParentNode; } -void /*XMLDom:: */ +static void /*XMLDom:: */ charHandler(void *pObj, const xmlchar *s, int len) { XMLNode *pNode = ((XMLDom *) pObj)->m_pCur;
