1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef __XML_TINYPARSER_H__ 18#define __XML_TINYPARSER_H__ 19 20#ifdef __cplusplus 21extern "C" { 22#endif 23 24#include <drm_common_types.h> 25 26#define XML_DOM_PARSER 27#define WBXML_DOM_PARSER 28#define XML_DOM_CHECK_ENDTAG 29#define XML_ENABLE_ERRNO 30#define WBXML_OLD_VERSION /* for drm only */ 31 32#ifdef DEBUG_MODE 33void XML_PrintMallocInfo(); 34#endif /* DEBUG_MODE */ 35 36#define XML_TRUE 1 37#define XML_FALSE 0 38#define XML_EOF 0 39#define XML_TAG_START 0 40#define XML_TAG_END 1 41#define XML_TAG_SELF 2 42 43#define XML_MAX_PROPERTY_LEN 256 44#define XML_MAX_ATTR_NAME_LEN 256 45#define XML_MAX_ATTR_VALUE_LEN 256 46#define XML_MAX_VALUE_LEN 256 47 48#define XML_ERROR_OK 0 49#define XML_ERROR_BUFFER_NULL -1 50#define XML_ERROR_ATTR_NAME -2 51#define XML_ERROR_ATTR_MISSED_EQUAL -3 52#define XML_ERROR_PROPERTY_NAME -4 53#define XML_ERROR_ATTR_VALUE -5 54#define XML_ERROR_ENDTAG -6 55#define XML_ERROR_NO_SUCH_NODE -7 56#define XML_ERROR_PROPERTY_END -8 57#define XML_ERROR_VALUE -9 58#define XML_ERROR_NO_START_TAG -14 59#define XML_ERROR_NOVALUE -15 60 61#define WBXML_ERROR_MISSED_CONTENT -10 62#define WBXML_ERROR_MBUINT32 -11 63#define WBXML_ERROR_MISSED_STARTTAG -12 64#define WBXML_ERROR_MISSED_ENDTAG -13 65 66#ifdef XML_ENABLE_ERRNO 67extern int32_t xml_errno; 68#define XML_ERROR(x) do { xml_errno = x; } while (0) 69#else /* XML_ENABLE_ERRNO */ 70#define XML_ERROR 71#endif /* XML_ENABLE_ERRNO */ 72 73#ifdef XML_DOM_PARSER 74uint8_t *XML_DOM_getNode(uint8_t *buffer, const uint8_t *const node); 75uint8_t *XML_DOM_getNodeValue(uint8_t *buffer, uint8_t *node, 76 uint8_t **value, int32_t *valueLen); 77 78uint8_t *XML_DOM_getValue(uint8_t *buffer, uint8_t **pValue, int32_t *valueLen); 79uint8_t *XML_DOM_getAttr(uint8_t *buffer, uint8_t **pName, int32_t *nameLen, 80 uint8_t **pValue, int32_t *valueLen); 81 82uint8_t *XML_DOM_getNextNode(uint8_t *buffer, uint8_t **pNodeName, 83 int32_t *nodenameLen); 84 85uint8_t *XML_DOM_getTag(uint8_t *buffer, int32_t *tagLen, int32_t *tagType); 86#endif /* XML_DOM_PARSER */ 87 88#ifdef WBXML_DOM_PARSER 89 90#define WBXML_WITH_ATTR 0x80 91#define WBXML_WITH_CONTENT 0x40 92#define WBXML_ATTR_END 0x01 93#define WBXML_CONTENT_END 0x01 94 95#define WBXML_SWITCH_PAGE 0x00 96#define WBXML_STR_I 0x03 97#define WBXML_END 0x00 98#define WBXML_OPAUE 0xC3 99#define WBXML_STR_T 0x83 100#define WBXML_OPAQUE 0xC3 101 102#define WBXML_GET_TAG(x) ((x) & 0x3F) /* get 6-digits */ 103#define WBXML_HAS_ATTR(x) ((x) & WBXML_WITH_ATTR) 104#define WBXML_HAS_CONTENT(x) ((x) & WBXML_WITH_CONTENT) 105 106typedef struct _WBXML { 107 uint8_t version; 108 uint8_t unUsed[3]; 109 uint32_t publicid; 110 uint32_t charset; 111 int32_t strTableLen; 112 uint8_t *strTable; 113 uint8_t *Content; 114 uint8_t *End; 115 uint8_t *curPtr; 116 int32_t depth; 117} WBXML; 118 119typedef int32_t XML_BOOL; 120 121#ifdef WBXML_OLD_VERSION 122uint8_t *WBXML_DOM_getNode(uint8_t *buffer, int32_t bufferLen, 123 uint8_t *node); 124uint8_t *WBXML_DOM_getNodeValue(uint8_t *buffer, int32_t bufferLen, 125 uint8_t *node, 126 uint8_t **value, 127 int32_t *valueLen); 128#endif /* WBXML_OLD_VERSION */ 129 130XML_BOOL WBXML_DOM_Init(WBXML * pWbxml, uint8_t *buffer, 131 int32_t bufferLen); 132XML_BOOL WBXML_DOM_Eof(WBXML * pWbxml); 133uint8_t WBXML_DOM_GetTag(WBXML * pWbxml); 134uint8_t WBXML_DOM_GetChar(WBXML * pWbxml); 135uint8_t WBXML_DOM_GetUIntVar(WBXML * pWbxml); 136void WBXML_DOM_Rewind(WBXML * pWbxml); 137void WBXML_DOM_Seek(WBXML * pWbxml, int32_t offset); 138int32_t WBXML_GetUintVar(const uint8_t *const buffer, int32_t *len); 139 140#endif /* WBXML_DOM_PARSER */ 141 142#ifdef XML_TREE_STRUCTURE 143 144typedef struct _XML_TREE_ATTR XML_TREE_ATTR; 145struct _XML_TREE_ATTR { 146 uint8_t name[XML_MAX_ATTR_VALUE_LEN]; 147 uint8_t value[XML_MAX_ATTR_VALUE_LEN]; 148 XML_TREE_ATTR *next; 149}; 150 151typedef struct _XML_TREE XML_TREE; 152struct _XML_TREE { 153 uint8_t tag[XML_MAX_PROPERTY_LEN]; 154 uint8_t value[XML_MAX_VALUE_LEN]; 155 XML_TREE_ATTR *attr; 156 XML_TREE_ATTR *last_attr; 157 XML_TREE *brother; 158 XML_TREE *last_brother; 159 XML_TREE *child; 160}; 161 162XML_TREE *XML_makeTree(uint8_t **buf); 163void XML_freeTree(XML_TREE * pTree); 164 165#endif /* XML_TREE_STRUCTURE */ 166 167#ifdef __cplusplus 168} 169#endif 170 171#endif /* __XML_TINYPARSER_H__ */ 172