1 /*************************************************************************/ 2 /* module: XML/WBXML scanner */ 3 /* file: XLTDecCom.h */ 4 /* target system: all */ 5 /* target OS: all */ 6 /*************************************************************************/ 7 8 /* 9 * Copyright Notice 10 * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication 11 * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc., 12 * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). 13 * All Rights Reserved. 14 * Implementation of all or part of any Specification may require 15 * licenses under third party intellectual property rights, 16 * including without limitation, patent rights (such a third party 17 * may or may not be a Supporter). The Sponsors of the Specification 18 * are not responsible and shall not be held responsible in any 19 * manner for identifying or failing to identify any or all such 20 * third party intellectual property rights. 21 * 22 * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED 23 * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM, 24 * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA, 25 * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML 26 * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 27 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 28 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 29 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 30 * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO., 31 * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY 32 * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF 33 * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF 34 * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL, 35 * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH 36 * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED 37 * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. 38 * 39 * The above notice and this paragraph must be included on all copies 40 * of this document that are made. 41 * 42 */ 43 /** 44 * Common header file for the WBXML and the XML scanner. 45 */ 46 47 /*************************************************************************/ 48 /* Definitions */ 49 /*************************************************************************/ 50 #ifndef _XLT_DEC_COM_H 51 #define _XLT_DEC_COM_H 52 53 #include <smldef.h> 54 #include <smldtd.h> 55 #include "xlttags.h" 56 57 #define DEC_ID XLT_DEC_ID + 0 58 #define WBXML_ID XLT_DEC_ID + 200 59 #define XML_ID XLT_DEC_ID + 400 60 #define STACK_ID XLT_DEC_ID + 600 61 62 #ifdef _cplusplus 63 extern "C" { 64 #endif 65 66 67 /* Token types returned by the scanner */ 68 typedef enum { 69 TOK_UNDEF = 0, 70 TOK_TAG_START, 71 TOK_TAG_END, 72 TOK_TAG_EMPTY, 73 TOK_CONT 74 } XltTokType_t; 75 76 /** 77 * Struct containing a token returned by the scanner 78 */ 79 typedef struct 80 { 81 XltTokType_t type; /* XLT_TOK_TAG_START, etc. */ 82 XltTagID_t tagid; /* TN_SYNCHDR, etc. - valid for token of type 83 XLT_TOK_TAG_xxx */ 84 SmlPcdataExtension_t ext; /* type of extension this tag belongs to - 85 valid for token of type XLT_TOK_TAG_xxx */ 86 SmlPcdataPtr_t pcdata; /* valid for token of type XLT_TOK_CONT_xxx */ 87 MemPtr_t start; /* pointer to the start of this token within 88 the document - needed for pushback */ 89 } XltDecToken_t, *XltDecTokenPtr_t; 90 91 /** 92 * Public interface for the XML/WBXML scanner components. 93 * 94 * The struct used for holding the XML and WBXML scanner state information 95 * are the same - function pointers are used to map the "objects" public 96 * methods to the right functions for scanning XML and WBXML documents. 97 * This object-oriented interface enables the parser component to use the 98 * two scanners interchangeably. 99 * The interface contains serveral public methods and attributes: 100 * 101 * FUNCTION: nextTok 102 * 103 * Decodes the next valid token at the current position within the 104 * document. Information about this token is placed into the curtok 105 * attribute of the scanner object. 106 * 107 * PRE-Condition: 108 * 109 * POST-Condition: 110 * curtok contains the last valid token. 111 * 112 * IN: 113 * 114 * OUT: 115 * 116 * IN/OUT: the scanner 117 * 118 * RETURNS: SML_ERR_OK or an appropriate error code 119 * 120 * 121 * FUNCTION: destroy 122 * 123 * Free the memory allocated by the scanner. 124 * 125 * PRE-Condition: 126 * POST-Condition: 127 * 128 * IN: 129 * 130 * OUT: 131 * 132 * IN/OUT: the scanner 133 * 134 * RETURNS: SML_ERR_OK or an appropriate error code 135 * 136 * 137 * FUNCTION: pushTok 138 * 139 * Resets the scanner to the beginning position within the document of the 140 * last valid token stored in curtok. Only the last found token can be 141 * pushed back. It is not possible to go back more than one token. 142 * 143 * PRE-Condition: 144 * curtok contains a valid token. 145 * 146 * POST-Condition: 147 * the next call of nextTok will find the token that was 148 * pushed back. 149 * 150 * IN/OUT: the scanner 151 * 152 * RETURNS: SML_ERR_OK or an appropriate error code 153 * 154 * FUNCITON: setBuf 155 * 156 * Set the buffer the scanner works on. 157 * 158 * FUNCTION: getPos 159 * 160 * Get the current position of the scanner within the working buffer. 161 * 162 * ATTRIBUTE: curtok 163 * 164 * Contains the last valid token found by a call to nextTok. 165 * 166 * ATTRIBUTE: charset 167 * 168 * The charset information as specified in the XML/WBXML document. This is 169 * the IANA assigned MIBEnum value. 170 171 * ATTRIBUTE: charsetStr 172 * 173 * String representation of the charset. This attribute is valid only when 174 * charset equals zero. Otherwise charsetStr will be NULL. 175 * 176 * ATTRIBUTE: pubID 177 * 178 * The document public identifier as specified in the XML/WBXML document. 179 * This is the numeric identifier assigned by the WAP Forum. If this value 180 * is zero, the public ID is instead specified as a string contained in the 181 * pubIDStr public attribute. 182 * 183 * ATTRIBUTE: pubIDStr 184 * 185 * The string representation of the document public identifier as specified 186 * in the XML/WBXML document (e.g. "-//WAPFORUM//DTD WML 1.0//EN"). This 187 * attribute is valid only when pubID equals zero. Otherwise pubIDStr will 188 * be NULL. 189 * 190 * ATTRIBUTE: finished 191 * 192 * This flag is set by the nextTok method when the scanner reaches the end 193 * of the buffer. 194 */ 195 typedef struct XltDecScanner_s XltDecScanner_t, *XltDecScannerPtr_t; 196 struct XltDecScanner_s 197 { 198 /* public methods */ 199 Ret_t (*nextTok)(XltDecScannerPtr_t pScanner); 200 Ret_t (*destroy)(XltDecScannerPtr_t pScanner); 201 Ret_t (*pushTok)(XltDecScannerPtr_t pScanner); 202 void (*setBuf)(XltDecScannerPtr_t pScanner, const MemPtr_t pBufStart, const MemPtr_t pBufEnd); 203 MemPtr_t (*getPos)(XltDecScannerPtr_t pScanner); 204 205 /* public attributes */ 206 XltDecTokenPtr_t curtok; 207 Long_t charset; 208 String_t charsetStr; 209 Long_t pubID; 210 String_t pubIDStr; 211 Flag_t finished; 212 }; 213 214 /** 215 * FUNCTION: xltDecWbxmlInit, xltDecXmlInit 216 * 217 * Initialize a new WBXML/XML scanner. 218 * 219 * PRE-Condition: 220 * ppScanner is NULL 221 * 222 * POST-Condition: 223 * ppScanner points to an initialized scanner status object 224 * 225 * IN: pBufEnd, buffer containing the WBXML/XML document 226 * 227 * IN/OUT: pBufPos, pointer to the current position within the 228 * buffer 229 * 230 * OUT: ppScanner, a new WBXML/XML scanner status object 231 * 232 * RETURNS: SML_ERR_OK or an appropriate error code 233 */ 234 Ret_t xltDecWbxmlInit(const MemPtr_t pBufEnd, MemPtr_t *ppBufPos, XltDecScannerPtr_t *ppScanner); 235 Ret_t xltDecXmlInit(const MemPtr_t pBufEnd, MemPtr_t *ppBufPos, XltDecScannerPtr_t *ppScanner); 236 237 #ifdef _cplusplus 238 } 239 #endif 240 241 #endif 242