yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | ///////////////////////////////////////////////////////////////////////////
|
| 2 | //
|
| 3 | // Copyright (c) 2000-2003 Intel Corporation
|
| 4 | // All rights reserved.
|
| 5 | //
|
| 6 | // Redistribution and use in source and binary forms, with or without
|
| 7 | // modification, are permitted provided that the following conditions are met:
|
| 8 | //
|
| 9 | // * Redistributions of source code must retain the above copyright notice,
|
| 10 | // this list of conditions and the following disclaimer.
|
| 11 | // * Redistributions in binary form must reproduce the above copyright notice,
|
| 12 | // this list of conditions and the following disclaimer in the documentation
|
| 13 | // and/or other materials provided with the distribution.
|
| 14 | // * Neither name of Intel Corporation nor the names of its contributors
|
| 15 | // may be used to endorse or promote products derived from this software
|
| 16 | // without specific prior written permission.
|
| 17 | //
|
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. NO EVENT SHALL INTEL OR
|
| 22 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 23 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
| 26 | // OF LIABILITY, WHETHER CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 | // NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OF THE USE OF THIS
|
| 28 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 | //
|
| 30 | ///////////////////////////////////////////////////////////////////////////
|
| 31 |
|
| 32 | #ifndef CWMP_XML_PARSER_H
|
| 33 | #define CWMP_XML_PARSER_H
|
| 34 |
|
| 35 | #include "cwmp/xmlet.h"
|
| 36 | #include "xmlbuffer.h"
|
| 37 |
|
| 38 | // XMLParser definitions
|
| 39 | #define QUOT """
|
| 40 | #define LT "<"
|
| 41 | #define GT ">"
|
| 42 | #define APOS "'"
|
| 43 | #define AMP "&"
|
| 44 | #define ESC_HEX "&#x"
|
| 45 | #define ESC_DEC "&#"
|
| 46 |
|
| 47 | typedef struct XmlNameSpaceURI
|
| 48 | {
|
| 49 | char *nsURI;
|
| 50 | char *prefix;
|
| 51 | struct XmlNameSpaceURI *nextNsURI;
|
| 52 | } XmlNameSpaceURI;
|
| 53 |
|
| 54 |
|
| 55 | typedef struct XmlElementStack
|
| 56 | {
|
| 57 | char *element;
|
| 58 | char *prefix;
|
| 59 | char *namespaceUri;
|
| 60 | XmlNameSpaceURI *pNsURI;
|
| 61 | struct XmlElementStack *nextElement;
|
| 62 | } XmlElementStack;
|
| 63 |
|
| 64 |
|
| 65 | typedef enum
|
| 66 | {
|
| 67 | E_ELEMENT,
|
| 68 | E_ATTRIBUTE,
|
| 69 | E_CONTENT,
|
| 70 | } XmlParserState;
|
| 71 |
|
| 72 | typedef struct XmlParser
|
| 73 | {
|
| 74 | char *dataBuffer; //data buffer
|
| 75 | char *curPtr; //ptr to the token parsed
|
| 76 | char *savePtr; //Saves for backup
|
| 77 | XmlBuffer lastElem;
|
| 78 | XmlBuffer tokenBuf;
|
| 79 |
|
| 80 | XmlNode *pNeedPrefixNode;
|
| 81 | XmlElementStack *pCurElement;
|
| 82 | XmlNode *currentNodePtr;
|
| 83 | XmlParserState state;
|
| 84 |
|
| 85 | BOOL bHasTopLevel;
|
| 86 |
|
| 87 | } XMLParser;
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 | int XmlParserLoadDocument(
|
| 92 | #ifdef USE_CWMP_MEMORY_POOL
|
| 93 | Pool * pool,
|
| 94 | #endif
|
| 95 | XmlDocument **retDoc, char * xmlFile, BOOL file);
|
| 96 | BOOL XmlParserIsValidXmlName(const char * name);
|
| 97 | int XmlParserSetNodePrefixAndLocalName(
|
| 98 | #ifdef USE_CWMP_MEMORY_POOL
|
| 99 | Pool * pool,
|
| 100 | #endif
|
| 101 |
|
| 102 | XmlNode * node);
|
| 103 | void XmlParserFreeNodeContent(
|
| 104 | #ifdef USE_CWMP_MEMORY_POOL
|
| 105 | Pool * pool,
|
| 106 | #endif
|
| 107 | XmlNode * node);
|
| 108 |
|
| 109 | void XmlAttrFree(
|
| 110 | #ifdef USE_CWMP_MEMORY_POOL
|
| 111 | Pool * pool,
|
| 112 | #endif
|
| 113 |
|
| 114 | XmlAttribute *attrNode);
|
| 115 | void XmlAttrInit(XmlAttribute *attrNode);
|
| 116 |
|
| 117 | void XmlNamedNodeMapInit(XmlNamedNodeMap *nnMap);
|
| 118 | int XmlNamedNodeMapAddToNamedNodeMap(
|
| 119 | #ifdef USE_CWMP_MEMORY_POOL
|
| 120 | Pool * pool,
|
| 121 | #endif
|
| 122 |
|
| 123 | XmlNamedNodeMap **nnMap, XmlNode * add);
|
| 124 |
|
| 125 | void XmlNodeInit(XmlNode * node);
|
| 126 | BOOL XmlNodeCompare(XmlNode * left, XmlNode * right);
|
| 127 |
|
| 128 | void XmlNodeGetElementsByTagName(
|
| 129 | #ifdef USE_CWMP_MEMORY_POOL
|
| 130 | Pool * pool,
|
| 131 | #endif
|
| 132 | XmlNode * n, char *tagname, XmlNodeList **list);
|
| 133 | void XmlNodeGetElementsByTagNameNS(
|
| 134 | #ifdef USE_CWMP_MEMORY_POOL
|
| 135 | Pool * pool,
|
| 136 | #endif
|
| 137 | XmlNode * node,const char *namespaceURI,
|
| 138 | const char *localName, XmlNodeList **list);
|
| 139 |
|
| 140 | int XmlNodeSetNodeProperties(
|
| 141 | #ifdef USE_CWMP_MEMORY_POOL
|
| 142 | Pool * pool,
|
| 143 | #endif
|
| 144 | XmlNode* node, XmlNode * src);
|
| 145 |
|
| 146 | void XmlNodeListInit(XmlNodeList *nList);
|
| 147 | int XmlNodeListAddToNodeList(
|
| 148 | #ifdef USE_CWMP_MEMORY_POOL
|
| 149 | Pool * pool,
|
| 150 | #endif
|
| 151 | XmlNodeList **nList, XmlNode * add);
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 | static char * XmlStrduptrim(Pool * pool, const char * data)
|
| 156 | {
|
| 157 | char buffer[1024+1] = {0};
|
| 158 | char * p;
|
| 159 | char * q;
|
| 160 |
|
| 161 | int len = 0;
|
| 162 |
|
| 163 | if (!data)
|
| 164 | {
|
| 165 | return NULL;
|
| 166 | }
|
| 167 |
|
| 168 | memset(buffer, 0, sizeof(buffer));
|
| 169 | strncpy(buffer, data, sizeof(buffer)-1);
|
| 170 | buffer[sizeof(buffer)-1] = '\0';
|
| 171 |
|
| 172 | len = (strlen(data) < sizeof(buffer)) ? strlen(buffer) : (sizeof(buffer) -1 );
|
| 173 |
|
| 174 | p = buffer;
|
| 175 |
|
| 176 | while ((*p <= ' ') && (*p != '\n'))
|
| 177 | {
|
| 178 | p ++;
|
| 179 | }
|
| 180 |
|
| 181 | // KW 1: use len instead of strlen(data);
|
| 182 | q = buffer + len;
|
| 183 | if ((*q == 0) && (q != p))
|
| 184 | {
|
| 185 | q --;
|
| 186 | }
|
| 187 |
|
| 188 |
|
| 189 | while ((*p <= ' ') && (q != p))
|
| 190 | {
|
| 191 | q --;
|
| 192 | }
|
| 193 |
|
| 194 | if (q < (buffer + sizeof(buffer) - 1)) //cov
|
| 195 | *(q+1) = 0;
|
| 196 |
|
| 197 | return PSTRDUP(p);
|
| 198 |
|
| 199 | }
|
| 200 |
|
| 201 | #endif // _IXMLPARSER_H
|
| 202 |
|