1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
/*****************************************************************************
**
** Name: xml_pars_api.h
**
** File: XML Parser
**
** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved.
** WIDCOMM Bluetooth Core. Proprietary and confidential.
**
*****************************************************************************/
#ifndef XML_PARS_API_H
#define XML_PARS_API_H
#include "data_types.h"
#define XML_STACK_SIZE 7
#ifndef XML_UI_ENTRY_MAX_NAME_LEN
#define XML_UI_ENTRY_MAX_NAME_LEN 256
#endif
/*****************************************************************************
** Type Definitions
*****************************************************************************/
/* Definition of XML events */
enum
{
XML_XMLDECL,
XML_TAG, /* 1 For STag (Start Tag) and EmptyElemTag */
XML_TAG_END, /* 2 When STag or EmptyElemTag ends */
XML_ATTRIBUTE, /* 3 */
XML_CHARDATA, /* 4 */
XML_ETAG, /* 5 For End Tag */
XML_PARTIAL, /* 6 notify XML user that the parse does not end properly */
XML_COPY, /* 7 notify XML user to copy till end of a token */
XML_QUERY, /* 8 query if the XML object has ended */
XML_TOP /* 9 */
};
typedef UINT16 tXML_EVENT;
#define XML_LAST_XE XML_ETAG
enum
{
XML_SUCCESS,
XML_WARNING,
XML_OBJ_ST_EMPTY,
XML_NO_MEM, /* no p_last_bfr, and the tXML_MUL_STATE is not in init */
XML_NO_PROP, /* run out of tXML_PROP */
XML_ERR, /* generic error */
XML_NO_END /* to be continued */
};
typedef UINT16 tXML_RESULT;
/* Definitions of different event data */
typedef struct
{
UINT8 *p_version;
UINT8 *p_enc_name;
BOOLEAN *p_standalone; /* NULL if no standalone decl was found */
} tXML_DECL;
/* for parser that expand multi-sessions */
/* tag stack */
typedef struct
{
UINT8 stack[XML_STACK_SIZE];
UINT8 top;
tXML_EVENT event; /* last XML event */
} tXML_STACK;
typedef struct
{
UINT8 *p;
UINT16 len;
} tXML_STR;
typedef struct
{
tXML_STACK stack;
tXML_STR prefix;
tXML_STR name;
UINT8 *p_last_stm;
} tXML_MTAG;
typedef struct
{
tXML_STACK stack;
BOOLEAN end; /* true if end of EmptyElemTag */
/* false if end of STag */
} tXML_MTAG_END;
typedef struct
{
tXML_STACK stack;
tXML_STR prefix;
tXML_STR name;
tXML_STR value;
} tXML_MATTR;
/* There may be several XML_CHARDATA events dispatched for one CHARDATA
** string in the XML document. In each XML_CHARDATA only a segment of the
** total string is provided. For the last segement the field last is true.
*/
typedef struct
{
tXML_STACK stack;
tXML_STR value;
BOOLEAN last;
} tXML_MCH_DATA;
typedef struct
{
tXML_STACK stack;
tXML_STR prefix;
tXML_STR name;
} tXML_METAG;
typedef struct
{
tXML_STACK stack;
UINT8 *p_begin;
tXML_STR last;
} tXML_MCOPY;
typedef struct
{
tXML_STACK stack;
tXML_RESULT parse;
UINT8 *p_keep;
} tXML_MPART;
typedef union
{
tXML_STACK stack;
tXML_DECL decl;
tXML_MTAG tag;
tXML_MTAG_END empty_elem;
tXML_MATTR attr;
tXML_MCH_DATA ch_data;
tXML_METAG etag;
tXML_MCOPY copy;
tXML_MPART part;
} tXML_MEVT_DATA;
typedef struct
{
UINT8 *p_data; /* Pointer to property data. */
UINT16 len; /* Length of data. */
UINT8 prefix; /* Property prefix. */
UINT8 name; /* Property name. */
UINT8 level; /* 0 as top level */
} tXML_PROP;
/* Definitions of different error actions.
** At present there is only one.
*/
enum
{
XML_NEXT_TAG /* tries to find beginning of next tag */
};
typedef UINT16 tXML_ERR_ACTION;
enum
{
XML_STS_INIT,
XML_STS_1STM, /* got the first < */
XML_STS_1TAG, /* got the first tag element */
XML_STS_DONE
};
typedef UINT8 tXML_STATUS;
typedef struct
{
UINT8 *p_hdr; /* the beginning of GKI buffer */
UINT8 *p_begin;/* the beginning of XML data */
UINT8 *p_end; /* the end of XML data */
} tXML_OS;
/*****************************************************************************
**
** Callback tXML_CBACK
**
** Description
** Called repeatedly from the XML parser for each XML construct parsed.
** The parsed XML construct is reported as an XML event in the event
** in-parameter. The parser provides event data specific for each event
** in the callback through the p_event_data param which should be casted
** to the proper type by the user implemented tXML_CBACK function.
** The p_event_data should be casted to a pointer of a type with the same
** name as the event but prefixed with t. For example when the event is
** XML_TAG, p_event_data should be casted to tXML_TAG*. Alternatively,
** p_event_data can be casted to a tEVENT_DATA* (pointer to union) type
** for all events. The memory behind the p_event_data is provided by the
** parser and is only valid during the callback, i.e. the memory is not
** valid after the callback. No pointer inside the event structures may
** be NULL unless explicitly stated so above for some specific event.
** The p_usr_data parameter is the same p_usr_data pointer the
** API user passed in the XML_Parse. It is only declared as a mean for
** the API user to pass any user data to its callback function.
**
**
** Parameters
** event (in) : the XML event or XML contruct just parsed,
** p_event_data (in) : data, i.e. names values etc, found in the XML
** construct. The data is specific for the XML
** construct and should be casted to the
** proper type as descibed above. May not be NULL.
** p_usr_data (in) : Same p_usr_data as passed in XML_Parse.
**
** Returns
** TRUE : if parsing should continue
** FALSE : if parsing should stop
**
*****************************************************************************/
typedef BOOLEAN (*tXML_CBACK)(tXML_EVENT event, void *p_event_data,
void *p_usr_data);
typedef struct
{
UINT8 p[512];
UINT16 len;
} tXML_STR_PARTIAL;
typedef struct
{
tXML_STR_PARTIAL last_bfr;
UINT16 used_last_bfr;
tXML_MEVT_DATA event_data;
}
tXML_PARTIAL;
/* tXML_STATE stores state during the XML_Parse call not between
** XML_Parse calls. It is used in most static functions in this file
** and passed in as first parameter to these.
*/
typedef struct
{
/* input from XML_Parse caller */
tXML_OS xml_os;
UINT8 *p_cur;
tXML_CBACK cback;
void *p_usr_data;
tXML_MEVT_DATA event_data;
/* handling of data buffers for prefix, name and value */
UINT8 *p_data_bfr;
UINT8 *p_last_stm; /* last '<' */
UINT8 *p_copy;
tXML_STR last_bfr;
tXML_STR value;
tXML_STR prefix;
tXML_STR name;
/* token and result handling */
INT16 curr_res;
tXML_RESULT pars_res;
UINT8 next_token;
BOOLEAN skip_next_nl;
UINT16 used_last_bfr; /* the actual data size in p_last_bfr */
tXML_STATUS status;
/* structure used to store partial data */
tXML_PARTIAL partial_st;
} tXML_MUL_STATE;
/*****************************************************************************
** External Function Declarations
*****************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/*****************************************************************************
**
** Function XML_Parse
**
** Description
** Parses an XML message/document in utf8. The message is read from
** an object store which must have been initialised and an object
** (file) must have been opened so the parser can start directly with
** reading the first byte using the GOEP_Read function and passing
** the h_obj_store in-param.
** The parser will call the xml_cback callback for each basic
** XML-construct parsed. If the parser encounters an error it will
** try to act according to the err_action in-param and report any
** errors through the err_handle. The parser is non-validating.
**
** Parameters
** h_obj_store (in) : a handle to an opened object (file) in
** the Object Store. The object must be
** ready for reading.
** xml_cback (in) : the user provided function to call back
** for each XML-construct (XML event) parsed.
** err_action (in) : the action the parser will try if it finds
** an error.
** err_handle (in) : a handle to some error recording object to
** which the parser may report errors. This is
** a place holder to connect any type of error
** recording object.
** p_usr_data (in) : any user data that will be passed on
** unchanged to the callback function.
**
** Returns
** 0 if the parsing was successfull without errors
** non-zero error or warning code otherwise
**
*****************************************************************************/
tXML_RESULT XML_Parse(tXML_OS *p_os, tXML_CBACK xml_cback,
tXML_ERR_ACTION err_action, UINT32 err_handle,
void *p_usr_data);
/*****************************************************************************
**
** Function XML_MulParse
**
** Description Initialize XML parser state machine.
**
** Parameters
** p_st (in) : xml state machine.
** p_os (in) : xml data storage
**
*****************************************************************************/
tXML_RESULT XML_MulParse(tXML_MUL_STATE *p_st, tXML_OS *p_os);
/*****************************************************************************
**
** Function XML_InitPars
**
** Description Initialize XML parser state machine.
**
** Parameters
** p_st (in) : xml state machine.
** xml_cback (in) : the user provided function to call back
** p_usr_data : user defined data.
**
*****************************************************************************/
void XML_InitPars(tXML_MUL_STATE *p_st, tXML_CBACK xml_cback, void *p_usr_data);
#ifdef __cplusplus
}
#endif
#endif /* ifndef XML_PARS_API_H */
|