TS-2343 Remove the --schema option from Traffic Manager
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/5bfafacc Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/5bfafacc Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/5bfafacc Branch: refs/heads/5.0.x Commit: 5bfafacc6b6affcf1b0dbcdc0ad70ddb84818804 Parents: 81cf29c Author: Leif Hedstrom <[email protected]> Authored: Tue Nov 12 16:57:25 2013 -0700 Committer: Leif Hedstrom <[email protected]> Committed: Tue Nov 12 16:57:25 2013 -0700 ---------------------------------------------------------------------- mgmt/Main.cc | 17 -- mgmt/utils/Makefile.am | 10 +- mgmt/utils/MgmtSchema.cc | 335 --------------------- mgmt/utils/MgmtSchema.h | 57 ---- mgmt/utils/XmlUtils.cc | 663 ------------------------------------------ mgmt/utils/XmlUtils.h | 153 ---------- proxy/Main.cc | 1 - 7 files changed, 2 insertions(+), 1234 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/mgmt/Main.cc ---------------------------------------------------------------------- diff --git a/mgmt/Main.cc b/mgmt/Main.cc index 8dde9b6..59d697a 100644 --- a/mgmt/Main.cc +++ b/mgmt/Main.cc @@ -27,7 +27,6 @@ #include "Main.h" #include "MgmtUtils.h" -#include "MgmtSchema.h" #include "WebMgmtUtils.h" #include "WebIntrMain.h" #include "WebOverview.h" @@ -78,9 +77,6 @@ static char debug_tags[1024] = ""; static char action_tags[1024] = ""; static bool proxy_on = true; -static bool schema_on = false; -static char *schema_path = NULL; - // TODO: Check if really need those char system_root_dir[PATH_NAME_MAX + 1]; char system_runtime_dir[PATH_NAME_MAX + 1]; @@ -519,11 +515,6 @@ main(int argc, char **argv) } else if (strcmp(argv[i], "-proxyBackDoor") == 0) { ++i; proxy_backdoor = atoi(argv[i]); - } else if (strcmp(argv[i], "-schema") == 0) { - // hidden option - ++i; - schema_path = argv[i]; - schema_on = true; } else { printUsage(); } @@ -696,14 +687,6 @@ main(int argc, char **argv) ink_assert(found); } - if (schema_on) { - XMLDom schema; - schema.LoadFile(schema_path); - bool validate = validateRecordsConfig(&schema); - ink_release_assert(validate); - } - - in_addr_t min_ip = inet_network("224.0.0.255"); in_addr_t max_ip = inet_network("239.255.255.255"); in_addr_t group_addr_ip = inet_network(group_addr); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/mgmt/utils/Makefile.am ---------------------------------------------------------------------- diff --git a/mgmt/utils/Makefile.am b/mgmt/utils/Makefile.am index 052db51..68d59d4 100644 --- a/mgmt/utils/Makefile.am +++ b/mgmt/utils/Makefile.am @@ -42,17 +42,11 @@ libutils_lm_a_CPPFLAGS = $(ink_with_modules_local) $(AM_CPPFLAGS) libutils_lm_a_SOURCES = \ ExpandingArray.cc \ ExpandingArray.h \ - MgmtSchema.cc \ - MgmtSchema.h \ MgmtUtils.cc \ MgmtUtils.h \ WebMgmtUtils.cc \ - WebMgmtUtils.h \ - XmlUtils.cc \ - XmlUtils.h + WebMgmtUtils.h libutils_p_a_SOURCES = \ MgmtUtils.cc \ - MgmtUtils.h \ - XmlUtils.cc \ - XmlUtils.h + MgmtUtils.h http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/mgmt/utils/MgmtSchema.cc ---------------------------------------------------------------------- diff --git a/mgmt/utils/MgmtSchema.cc b/mgmt/utils/MgmtSchema.cc deleted file mode 100644 index 8b3eb4b..0000000 --- a/mgmt/utils/MgmtSchema.cc +++ /dev/null @@ -1,335 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#include "libts.h" -#include "MgmtSchema.h" -#include "Main.h" - -//******************************************************** -// XML Schema Validation -//******************************************************** -static InkHashTable *g_record_ht = NULL; - -//******************************************************** -// validateDefault -//******************************************************** -bool -validateDefault(XMLNode * exposure, char *recName, char *default_value) -{ - char *rec_default = 0; - - char *exposure_level = exposure->getAttributeValueByName("level"); - if (!exposure_level) { - fprintf(stderr, "invalid <exposure> - no attribute 'level' %s\n", recName); - return false; - } - - if (strcmp(exposure_level, "system") != 0 && strcmp(exposure_level, "unused") != 0) { - RecGetRecordDefaultDataString_Xmalloc(recName, &rec_default); - - if (rec_default == NULL) { - if (default_value != NULL) - goto Lerror; - - } else { - if (default_value == NULL) - goto Lerror; - if (!(strcmp(rec_default, default_value) == 0)) - if (atof(rec_default) != atof(default_value)) - goto Lerror; - } - } - ats_free(rec_default); - - return true; - -Lerror: - fprintf(stderr, "invalid - default mismatch: %s (%s != %s)\n", recName, - rec_default ? rec_default : "NULL", default_value ? default_value : "NULL"); - return false; -} - - -//******************************************************** -// validateType -//******************************************************** -bool -validateType(XMLNode * record) -{ - RecDataT rec_type = RECD_NULL; - char *attrName; - - if (!(attrName = record->getAttributeValueByName("name"))) { - fprintf(stderr, "invalid <record> - 'name' undefined\n"); - goto Lerror; - } - if (RecGetRecordDataType((char *) attrName, &rec_type) != REC_ERR_OKAY) { - fprintf(stderr, "invalid <record> - undefined %s\n", attrName); - goto Lerror; - } - if (!(attrName = record->getAttributeValueByName("type"))) { - fprintf(stderr, "invalid <record> - 'type' undefined\n"); - goto Lerror; - } - if (!((strcmp(attrName, "INT") == 0 && rec_type == RECD_INT)) && - !((strcmp(attrName, "STRING") == 0 && rec_type == RECD_STRING)) && - !((strcmp(attrName, "FLOAT") == 0 && rec_type == RECD_FLOAT))) { - fprintf(stderr, "invalid <record> - unknown type: %s\n", attrName); - goto Lerror; - } - return true; - -Lerror: - return false; -} - -//******************************************************** -// validateRestart -//******************************************************** -bool -validateRestart(XMLNode * reconfigure, char *recName) -{ - - SCHM_UpdateT restart_t; - char *nodeValue; - - RecGetRecordUpdateType(recName, &restart_t); - - if (!(nodeValue = reconfigure->getNodeValue())) { - fprintf(stderr, "invalid <reconfigure> - empty\n"); - goto Lerror; - } - if (restart_t != SCHM_RU_NULL) { - // check only the ones with RU type defined - if (!(restart_t == SCHM_RU_RESTART_TS && (strcmp(nodeValue, "traffic_server") == 0)) && - !(restart_t == SCHM_RU_RESTART_TM && (strcmp(nodeValue, "traffic_manager") == 0)) && - !(restart_t == SCHM_RU_RESTART_TC && (strcmp(nodeValue, "traffic_cop") == 0)) && - !(restart_t == SCHM_RU_REREAD && (strcmp(nodeValue, "traffic_manager") == 0))) { - fprintf(stderr, "invalid <reconfigure> - unknown value: %s, %s\n", nodeValue, recName); - goto Lerror; - } - } else { // at least check the value defined - if (!(strcmp(nodeValue, "traffic_server") == 0) && - !(strcmp(nodeValue, "traffic_manager") == 0) && !(strcmp(nodeValue, "traffic_cop") == 0)) { - fprintf(stderr, "invalid <reconfigure> - unknown value: %s, %s\n", nodeValue, recName); - } - } - return true; - -Lerror: - return false; -} - - -//******************************************************** -// validateSyntax -//******************************************************** -bool -validateSyntax(XMLNode * validate, char *recName) -{ - SCHM_CheckT check_t; - char *pattern; - char *nodeValue; - char *attrValue; - - RecGetRecordCheckType(recName, &check_t); - RecGetRecordCheckExpr(recName, &pattern); - - if (!(attrValue = validate->getAttributeValueByName("type"))) { - fprintf(stderr, "invalid <validate> - 'type' undefined\n"); - goto Lerror; - } - if (!(nodeValue = validate->getNodeValue())) { - // 'integer' type can have no nodeValue - if (strcmp(attrValue, "integer") != 0) { - fprintf(stderr, "invalid <validate> - empty: %s\n", recName); - goto Lerror; - } - } - - if (check_t == SCHM_RC_STR && (strcmp(attrValue, "match_regexp") == 0)) { - if (!nodeValue || !strcmp(nodeValue, pattern)) - goto Lerror; - } - if (check_t == SCHM_RC_INT && (strcmp(attrValue, "int_range") == 0)) { - // RecordsConfig.cc side - Tokenizer dashTok("-"); - char *p = pattern; - while (*p != '[') { - p++; - } // skip to '[' - if (dashTok.Initialize(++p, COPY_TOKS) == 2) { - int l_limit = atoi(dashTok[0]); - int u_limit = atoi(dashTok[1]); - - // schema side - Tokenizer commaTok(","); - char *s = nodeValue; - if (commaTok.Initialize(s, COPY_TOKS) == 2) { - int l_limit_s = atoi(commaTok[0]); - int u_limit_s = atoi(commaTok[1]); - if (l_limit != l_limit_s || u_limit != u_limit_s) { - fprintf(stderr, "invalid <validate> - range mismatch: %s\n", recName); - goto Lerror; - } - } else { - fprintf(stderr, "invalid <validate> - unknown format: %s\n", recName); - goto Lerror; - } - } - } - - - return true; - -Lerror: - return false; -} - - -//******************************************************** -// validateNode -//******************************************************** -bool -validateNode(XMLNode * node, char *default_value) -{ - XMLNode *child; - // RecordUpdateType update_t; - char *varName = NULL; - // char *nodeName; - int err = true; - - if (node) { - if (strcmp(node->getNodeName(), "appinfo") == 0) { - - // get record node - child = node->getNodeByPath("record"); - if (!child) - goto Ldone; - - varName = child->getAttributeValueByName("name"); - if (varName) { - ink_hash_table_insert(g_record_ht, varName, NULL); - } - // validate record type - err = validateType(child); - if (!err) - goto Lerror; - - // validate record restart type - child = node->getNodeByPath("reconfigure"); - if (child) { - err = validateRestart(child, varName); - if (!err) - goto Lerror; - } - // validate record value syntax - child = node->getNodeByPath("validate"); - if (child) { - err = validateSyntax(child, varName); - if (!err) - goto Lerror; - } - // validate record exposure - child = node->getNodeByPath("exposure"); - if (child) { - err = validateDefault(child, varName, default_value); - if (!err) - goto Lerror; - } - } - } -Ldone: - return err; - -Lerror: - err = false; - return err; -} - -//******************************************************** -// validateSchemaNode -//******************************************************** -bool -validateSchemaNode(XMLNode * node) -{ - bool err = true; - XMLNode *child; - char *default_value = NULL; - - while (node) { - validateNode(node, default_value); - - for (int i = 0; i < node->getChildCount(); i++) { - child = node->getChildNode(i); - if (strcmp(child->getNodeName(), "attribute") == 0) { - default_value = child->getAttributeValueByName("default"); - child = child->getNodeByPath("annotation/appinfo"); - if (child) { - if (!validateNode(child, default_value)) { - err = false; - } - } - } else { - if (!validateSchemaNode(child)) { - err = false; - } - } - } - break; - } - return err; -} - -//******************************************************** -// validateRecordCoverage -//******************************************************** -bool -validateRecordCoverage() -{ - bool err = true; - //fix me - return err; -} - - -//******************************************************** -// validateRecordsConfig -//******************************************************** -bool -validateRecordsConfig(XMLNode * schema) -{ - bool err = true; - - g_record_ht = ink_hash_table_create(InkHashTableKeyType_String); - - validateSchemaNode(schema); - validateRecordCoverage(); - return err; - - /* - Lerror: - err = false; - return err; - */ -} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/mgmt/utils/MgmtSchema.h ---------------------------------------------------------------------- diff --git a/mgmt/utils/MgmtSchema.h b/mgmt/utils/MgmtSchema.h deleted file mode 100644 index 77f591f..0000000 --- a/mgmt/utils/MgmtSchema.h +++ /dev/null @@ -1,57 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#ifndef __MGMT_SCHEMA_ -#define __MGMT_SCHEMA_ - -/**************************************************************************** - * - * MgmtSchema.h - Functions for interfacing to manage Traffic Server Schema - * - * - * - ****************************************************************************/ - -#include "ink_hash_table.h" -#include "XmlUtils.h" - -#include "P_RecCore.h" - -#define SCHM_UpdateT RecUpdateT -#define SCHM_RU_NULL RECU_NULL -#define SCHM_RU_REREAD RECU_DYNAMIC -#define SCHM_RU_RESTART_TS RECU_RESTART_TS -#define SCHM_RU_RESTART_TM RECU_RESTART_TM -#define SCHM_RU_RESTART_TC RECU_RESTART_TC - -#define SCHM_CheckT RecCheckT -#define SCHM_RC_NULL RECC_NULL -#define SCHM_RC_STR RECC_STR -#define SCHM_RC_INT RECC_INT -#define SCHM_RC_IP RECC_IP - - -bool validateRecordsConfig(XMLNode * node); -bool validateNode(XMLNode * node); - -#endif // __MGMT_SCHEMA http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/mgmt/utils/XmlUtils.cc ---------------------------------------------------------------------- diff --git a/mgmt/utils/XmlUtils.cc b/mgmt/utils/XmlUtils.cc deleted file mode 100644 index 21b56f4..0000000 --- a/mgmt/utils/XmlUtils.cc +++ /dev/null @@ -1,663 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#include "ink_autoconf.h" -#if HAVE_LIBEXPAT -#include "expat.h" -typedef XML_Char xmlchar; -#elif HAVE_LIBXML2 -#include <libxml/parser.h> -typedef xmlChar xmlchar; -#else -# error "No XML parser. Please configure expat or libxml2" -#endif -#include <stdio.h> -#include <stdlib.h> -#include "ink_platform.h" -#include "ink_defs.h" -#include <sys/types.h> -#include <sys/stat.h> - -#include "XmlUtils.h" -#include "ink_error.h" - -/**************************************************************************** - * - * XmlUtils.cc - Functions for interfacing to XML parser (expat) - * - * - * - * - * This code was taken from the xmlparse library developed - * by Xing Xiong for SynText. - ****************************************************************************/ - -const char *gcstr_lb = "<"; -const char *gcstr_rb = ">"; -const char *gcstr_lbend = "</"; -const char *gcstr_rbend = "/>"; - -void -XMLNode::PrintAll() -{ - XMLNode *p; - p = m_pFirstChild; - while (p) { - p->PrintAll(); - p = p->m_pNext; - } -} - -int -alloc_and_copy(char **pDest, const char *pSource) -{ - int len; - if (NULL == pSource) - return 1; - - len = strlen(pSource); - *pDest = new char[len + 1]; - if (NULL == *pDest) - return 2; - - memcpy(*pDest, pSource, len); - (*pDest)[len] = 0; - return 0; -} - -int -XMLNode::setNodeName(const char *psName) -{ - return alloc_and_copy(&m_pNodeName, psName); -} - -int -XMLNode::setNodeValue(const char *psValue) -{ - return alloc_and_copy(&m_pNodeValue, psValue); -} - - -/* the ppsAttr should contains 2N+1 char*. - The last one of pssAttr should be a NULL. - */ -int -XMLNode::setAttributes(char **ppsAttr) -{ - int i; - if (m_pAList) { - for (i = 0; i < m_nACount; i++) { - delete m_pAList[i].pAName; - delete m_pAList[i].pAValue; - } - - delete[]m_pAList; - m_pAList = NULL; - m_nACount = 0; - } - - int nCount = 0; - for (i = 0; ppsAttr[i]; i += 2) - nCount++; /*Calculate how many elements. */ - if (nCount == 0) - return 0; - - m_nACount = nCount; - m_pAList = new Attribute[nCount]; - for (i = 0; i < nCount; i++) { - /* Attribute Name: attr[2*i], Value: attr[2*i+1]; */ - alloc_and_copy(&m_pAList[i].pAName, ppsAttr[2 * i]); - alloc_and_copy(&m_pAList[i].pAValue, ppsAttr[2 * i + 1]); - } - return 0; -} - - -XMLNode::XMLNode() -{ - m_pNodeName = NULL; - m_pNodeValue = NULL; - m_pNext = NULL; - m_pParentNode = NULL; - m_pFirstChild = NULL; - m_nChildCount = 0; - - m_nACount = 0; - m_pAList = NULL; - m_pLastChild = 0; -} - -XMLNode::~XMLNode() -{ - XMLNode *p; - - /* delete NodeName and NodeValue. */ - if (m_pNodeName) { - delete m_pNodeName; - m_pNodeName = NULL; - } - if (m_pNodeValue) { - delete m_pNodeValue; - m_pNodeValue = NULL; - } - - /* delete all attributes. */ - if (m_nACount) { - for (int i = 0; i < m_nACount; i++) { - delete m_pAList[i].pAName; - delete m_pAList[i].pAValue; - } - delete m_pAList; - m_pAList = NULL; - } - - /* delete all the children. */ - p = m_pFirstChild; - while (p) { - XMLNode *pTemp = p->m_pNext; - delete p; - p = pTemp; - } - m_pFirstChild = NULL; -} - -int -XMLNode::getChildCount(const char *pTagName) -{ - XMLNode *p; - int nCount = 0; - if (m_nChildCount == 0) - return 0; - - p = m_pFirstChild; - while (p) { - if (!strcmp(p->m_pNodeName, pTagName)) - nCount++; - p = p->m_pNext; - } - - return nCount; -} - -XMLNode * -XMLNode::getChildNode(int nIndex) -{ - XMLNode *p = m_pFirstChild; - while (nIndex--) { - if (p == NULL) - return NULL; - p = p->m_pNext; - } - return p; -} - -XMLNode * -XMLNode::getChildNode(const char *pTagName, int nIndex) -{ - XMLNode *p = m_pFirstChild; - while (nIndex >= 0) { - /* try to find the next child node with given name. */ - while (p && strcmp(p->m_pNodeName, pTagName)) - p = p->m_pNext; - if (p == NULL) - return NULL; - nIndex--; - if (nIndex >= 0) - p = p->m_pNext; - } - return p; -} - -void -XMLNode::AppendChild(XMLNode * p) -{ - if (m_nChildCount == 0) { - m_pFirstChild = p; - m_pLastChild = p; - } else { - m_pLastChild->m_pNext = p; - m_pLastChild = p; - } - - //p->m_pNext = NULL; - p->m_pParentNode = this; - m_nChildCount++; -} - -/* <pName pAttr>pValue</pName> - pValue may be NULL. - pAttr may be NULL, otherwise, there is already a " " at its beginning. - */ -char * -ConstructXMLBlock(const char *pName, const char *pValue, const char *pAttr) -{ - int NameLen = strlen(pName); - int ValueLen = 0; - if (pValue) - ValueLen = strlen(pValue); - int AttrLen = 0; - if (pAttr) - AttrLen = strlen(pAttr); - - char *p = new char[NameLen * 2 + AttrLen + ValueLen + 6]; - p[0] = '<'; - - int nOffset = 1; - memcpy(p + nOffset, pName, NameLen); - nOffset += NameLen; - - if (pAttr) { - memcpy(p + nOffset, pAttr, AttrLen); - nOffset += AttrLen; - } - - p[nOffset++] = '>'; - if (pValue) { - memcpy(p + nOffset, pValue, ValueLen); - nOffset += ValueLen; - } - - p[nOffset++] = '<'; - p[nOffset++] = '/'; - memcpy(p + nOffset, pName, NameLen); - nOffset += NameLen; - - p[nOffset++] = '>'; - p[nOffset] = 0; - /*p[NameLen*2+5+ValueLen] = 0; */ - return p; -} - -/* Allocate a new piece of memory to contain the new string. - p1 may be NULL. - if p1 is not NULL, then delete it. - */ -char * -AppendStr(char *p1, const char *p2) -{ - int nLen1 = 0; - if (p1) - nLen1 = strlen(p1); - - int nLen2 = strlen(p2); - char *p = new char[nLen1 + nLen2 + 1]; - if (!p) - return NULL; - - if (p1) { - memcpy(p, p1, nLen1); - delete[] p1; - } - memcpy(p + nLen1, p2, nLen2); - p[nLen1 + nLen2] = 0; - return p; -} - -char * -XMLNode::getAttributeString() -{ - char *pAttr = NULL; - for (int i = 0; i < m_nACount; i++) { - // coverity[new_array][var_assign][delete_var] - pAttr = AppendStr(pAttr, " "); - // coverity[new_array][var_assign][delete_var] - pAttr = AppendStr(pAttr, m_pAList[i].pAName); - - // coverity [delete_var] - pAttr = AppendStr(pAttr, "=\""); - - // coverity[new_array][var_assign] - pAttr = AppendStr(pAttr, m_pAList[i].pAValue); - // coverity[new_array][var_assign][delete_var] - pAttr = AppendStr(pAttr, "\""); - } - - return pAttr; -} - -/* - There are better ways to implement this function. - */ -char * -XMLNode::getXML() -{ - char *pBody = NULL; - if (m_pNodeValue) - // coverity[var_assign][new_array] - pBody = AppendStr(NULL, m_pNodeValue); - - XMLNode *pChild = m_pFirstChild; - while (pChild) { - char *pChildXML = pChild->getXML(); - if (!pChildXML) { - delete[] pBody; - return NULL; - } - - pBody = AppendStr(pBody, pChildXML); - delete[] pChildXML; - - pChild = pChild->m_pNext; - } - - char *pAttr = getAttributeString(); - char *pRet = ConstructXMLBlock(m_pNodeName, pBody, pAttr); - - delete[] pBody; - delete[] pAttr; - - return pRet; -} - -char * -XMLNode::getAttributeValueByName(const char *pAName) -{ - if (!pAName) - return NULL; - - char *p = NULL; - for (int i = 0; i < m_nACount; i++) { - if (!strcmp(pAName, m_pAList[i].pAName)) { - p = m_pAList[i].pAValue; - break; - } - } - - return p; -} - -static void /*XMLDom:: */ -elementStart(void *pObj, const xmlchar *el, const xmlchar **attr) -{ - XMLDom *pDom = (XMLDom *) pObj; - int nTagLen; - char *pTag; - - if (!pDom->m_pCur) { - pDom->m_pCur = (XMLNode *) pDom; - } else { - XMLNode *p = new XMLNode; - pDom->m_pCur->AppendChild(p); - pDom->m_pCur = p; - } - - nTagLen = strlen((const char*)el); - pTag = new char[nTagLen + 1]; - pDom->m_pCur->m_pNodeName = pTag; - memcpy(pTag, el, nTagLen); - pTag[nTagLen] = 0; - - if (!attr) - return; - - int i; - int nCount = 0; - for (i = 0; attr[i]; i += 2) - nCount++; /*Calculate how many elements. */ - if (nCount == 0) - return; - else - pDom->m_pCur->m_nACount = nCount; - - pDom->m_pCur->m_pAList = new Attribute[nCount]; - for (i = 0; i < nCount; i++) { - /* Attribute Name: attr[2*i], Value: attr[2*i+1]; */ - alloc_and_copy(&pDom->m_pCur->m_pAList[i].pAName, (const char*)attr[2 * i]); - alloc_and_copy(&pDom->m_pCur->m_pAList[i].pAValue, (const char*)attr[2 * i + 1]); - } -} - -static void /*XMLDom:: */ -elementEnd(void *pObj, const xmlchar * /* el ATS_UNUSED */) -{ - /*ASSERT(strcmp(el, pCur->pNodeName) == 0); */ - XMLDom *pDom = (XMLDom *) pObj; - pDom->m_pCur = pDom->m_pCur->m_pParentNode; -} - -static void /*XMLDom:: */ -charHandler(void *pObj, const xmlchar *s, int len) -{ - XMLNode *pNode = ((XMLDom *) pObj)->m_pCur; - int oldlen; - char *p = pNode->m_pNodeValue; - if (!p) - oldlen = 0; - else - oldlen = strlen(p); - - char *pValue = new char[len + oldlen + 1]; - if (oldlen) - memcpy(pValue, pNode->m_pNodeValue, oldlen); - memcpy(pValue + oldlen, s, len); - pValue[len + oldlen] = 0; - - if (pNode->m_pNodeValue) - delete pNode->m_pNodeValue; - pNode->m_pNodeValue = pValue; - - /*printf("Len: %d, Value: %s\n", len, pValue); */ -} - -int -XMLDom::LoadXML(const char *pXml) -{ - int rv = 0; -#if HAVE_LIBEXPAT - /* Old (expat) xml parsing */ - XML_Parser p = XML_ParserCreate(NULL); - if (!p) /* no Memory. */ - return 1; - - - XML_SetUserData(p, (void *) this); - /* We can cast this. */ - XML_SetElementHandler(p, - /*(void (*)(void *, const char *, const char**)) */ elementStart, - /*(void (*)(void *, const char *)) */ elementEnd - ); - - XML_SetCharacterDataHandler(p, - /*(void (*)(void *, const char *, int)) */ charHandler - ); - - if (!XML_Parse(p, pXml, strlen(pXml), 1)) { - rv = 2; /*return 2; Parse Error: bad xml format. */ - } - XML_ParserFree(p); - -#else - /* Alternative (libxml2) xml parsing */ - xmlParserCtxtPtr p; - xmlSAXHandler sax; - memset(&sax, 0, sizeof(xmlSAXHandler)); - sax.startElement = elementStart; - sax.endElement = elementEnd; - sax.characters = charHandler; - sax.initialized = 1; - p = xmlCreatePushParserCtxt(&sax, this, NULL, 0, NULL); - if (!p) /* no Memory. */ - return 1; - - /* Looks as if this is actually the whole xml and expat version's - * use of 0 for is_final is a bug. We'll use 1. - */ - if (xmlParseChunk(p, pXml, strlen(pXml), 1) != 0) { - rv = 2; /* expat version ignores error, so we'll do likewise */ - } - xmlFreeParserCtxt(p); -#endif - - /* I don't know why the "return 2" in the old (expat) version was - * commented out. Possibly because the call to XML_Parse incorrectly - * used 0 for is_final last arg, in which case we should restore it. - * If it's a bug in the caller then we'll just have to return 0 always. - */ - return rv; -} - -int -XMLDom::LoadFile(const char *psFileName) -{ - int nSize; - struct stat file_stat; - char *pBuffer; - FILE *pf; - int n; - - // coverity[fs_check_call] - if (stat(psFileName, &file_stat) != 0) - return 3; /*File not existing or bad format. */ - nSize = file_stat.st_size; - - // coverity [alloc_fn][var_assign] - pBuffer = new char[nSize + 1]; - if (pBuffer == NULL) /*No memory */ - return 1; - - // coverity[toctou] - pf = fopen(psFileName, "rb"); - if (pf == NULL) - return 3; - - // coverity[noescape] - n = fread(pBuffer, 1, nSize, pf); - fclose(pf); - if (n != nSize) { - if (pBuffer) - delete[]pBuffer; - return 3; - } - - pBuffer[nSize] = 0; - n = LoadXML(pBuffer); - delete[]pBuffer; - return n; -} - -XMLNode * -XMLNode::getNodeByPath(const char *pPath) -{ - if (!pPath) - return NULL; - - char *p; - // coverity[alloc_arg] - alloc_and_copy(&p, pPath); - // coverity[noescape] - int len = strlen(p); - int pos; - for (pos = 0; pos < len; pos++) { - if (p[pos] == '/') - p[pos] = 0; - } - - pos = 0; - XMLNode *pCur = this; - while (pos < len) { - // coverity[noescape] - pCur = pCur->getChildNode(p + pos); - if (pCur == NULL) { - if (p) { - delete[]p; - } - return NULL; - } - // coverity[noescape] - pos += strlen(p + pos) + 1; - } - - delete[]p; - return pCur; -} - -char * -XMLNode::getNodeValue(const char *pPath) -{ - XMLNode *p = getNodeByPath(pPath); - if (!p) - return NULL; - return p->getNodeValue(); -} - -void -XMLNode::WriteFile(FILE * pf) -{ - XMLNode *pChild = m_pFirstChild; - if ((fwrite(gcstr_lb, 1, 1, pf) != 1) || - (fwrite(m_pNodeName, 1, strlen(m_pNodeName), pf) != strlen(m_pNodeName))) - return; - - char *pAttr = getAttributeString(); - if (pAttr) { - if (fwrite(pAttr, 1, strlen(pAttr), pf) != strlen(pAttr)) { - delete[]pAttr; - return; - } - delete[]pAttr; - } - - if (fwrite(gcstr_rb, 1, 1, pf) != 1) - return; - if (m_pNodeValue) - if (fwrite(m_pNodeValue, 1, strlen(m_pNodeValue), pf) != strlen(m_pNodeValue)) - return; - - while (pChild) { - pChild->WriteFile(pf); - pChild = pChild->m_pNext; - } - - if ((fwrite(gcstr_lbend, 1, 2, pf) != 2) || - (fwrite(m_pNodeName, 1, strlen(m_pNodeName), pf) != strlen(m_pNodeName)) || - (fwrite(gcstr_rb, 1, 1, pf) != 1)) - return; - - return; -} - -int -XMLDom::SaveToFile(const char *psFileName) -{ - FILE *pf; - if (psFileName == NULL) - return 3; /*Bad file Name */ - - pf = fopen(psFileName, "wb"); - if (NULL == pf) - return 3; /*Can't open file */ - WriteFile(pf); - fclose(pf); - - return 0; -} - -XMLDom::XMLDom() -{ - m_pCur = NULL; -} - -XMLDom::~XMLDom() -{ - return; -} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/mgmt/utils/XmlUtils.h ---------------------------------------------------------------------- diff --git a/mgmt/utils/XmlUtils.h b/mgmt/utils/XmlUtils.h deleted file mode 100644 index 7c1f6b8..0000000 --- a/mgmt/utils/XmlUtils.h +++ /dev/null @@ -1,153 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#ifndef _INKXML_H_ -#define _INKXML_H_ -#include <stdio.h> - -/**************************************************************************** - * - * XmlUtils.h - Functions for interfacing to XML parser (expat) - * - * - * - * - * This code was taken from the xmlparse library developed - * by Xing Xiong for SynText. - ****************************************************************************/ - -/************************************************** - XMLNode definition. - **************************************************/ - -typedef struct -{ - char *pAName; /*Element Name. */ - char *pAValue; /*Element Value. */ -} Attribute; - -class XMLNode -{ -public: - XMLNode(); - ~XMLNode(); - - int getChildCount() - { - return m_nChildCount; - } - - /* Calculate how many children has the input TagName. */ - int getChildCount(const char *pTagName); - - /* Index a childNode in the child List. */ - XMLNode *getChildNode(int nIndex = 0); - - /* Index the "nIndex"th child with given tag Name. */ - XMLNode *getChildNode(const char *pTagName, int nIndex = 0); - XMLNode *getParentNode() - { - return m_pParentNode; - } - - /* Input is: "TagName1/TagName2/TagName3" */ - XMLNode *getNodeByPath(const char *pPath); - - XMLNode *getNext() - { - return m_pNext; - } - void AppendChild(XMLNode * p); - - char *getNodeName() - { - return m_pNodeName; - } - char *getNodeValue() - { - return m_pNodeValue; - } - char *getNodeValue(const char *pPath); - char *getAttributeValueByName(const char *pAName); - - /* will return full XML text of this node(including the children) - return NULL if error. - Attention: user need to free the returned string, using "delete". - */ - char *getXML(); - - int setNodeName(const char *psName); - int setNodeValue(const char *psValue); - - /* the ppsAttr should contains 2N+1 char*. - The last one of pssAttr should be a NULL. - */ - int setAttributes(char **ppsAttr); - - void WriteFile(FILE * pf); - - /* Testing method */ - void PrintAll(); - -/*need a better way to solve this. */ -/*protected: */ - char *m_pNodeName; - char *m_pNodeValue; - - int m_nChildCount; - XMLNode *m_pFirstChild; /* the first Child. */ - XMLNode *m_pLastChild; /* the last Child. */ - XMLNode *m_pParentNode; - XMLNode *m_pNext; - - int m_nACount; /* Attribute number. */ - Attribute *m_pAList; /* Attribute List. */ -private: - char *getAttributeString(); -}; - -/************************************************** - XMLDom definition. - **************************************************/ - -class XMLDom:public XMLNode -{ -public: - XMLDom(); - ~XMLDom(); - - int LoadXML(const char *pXml); - int LoadFile(const char *psFileName); - int SaveToFile(const char *psFileName); - -/* -protected: - void elementStart(const char* el, const char** attr); - void elementEnd(const char* el); - void charHandler(const char *s,int len); -*/ - - XMLNode *m_pCur; /* the current XMLNode. used during parsing. */ -}; - -#endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5bfafacc/proxy/Main.cc ---------------------------------------------------------------------- diff --git a/proxy/Main.cc b/proxy/Main.cc index ed9141b..431d94c 100644 --- a/proxy/Main.cc +++ b/proxy/Main.cc @@ -86,7 +86,6 @@ extern "C" int plock(int); #include "Update.h" #include "congest/Congestion.h" #include "RemapProcessor.h" -#include "XmlUtils.h" #include "I_Tasks.h" #include "InkAPIInternal.h"
