Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
xparser.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: xparser.h 6657 2026-10-28 18:19:39Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2010-2026
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 * http://www.sharkssl.com
34 ****************************************************************************
35 * xparser.h : streaming xml parser
36 */
37
38#ifndef __xparser_h
39#define __xparser_h
40#include <stddef.h>
45#ifndef XPARSER_ALLOC
46#define XPARSER_ALLOC 2
47#endif
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
54 struct xparser_context;
55 typedef struct xparser_context xparser;
56
61 /*
62 these event flags are for pseudo-events, which have no
63 data attached to them.
64 */
69 /*
70 the following are all called from first xparser_parse()
71 name, attrs,data indicate which parameters will be returned.
72 */
82 };
83 typedef enum xparser_event xparser_event;
84
91 extern const char* const xparser_eventname[xparserLAST];
92
93
105 typedef int (*xparser_callback)(
106 xparser* parser,
107 void* userdata,
108 xparser_event event,
109 const char* name, /* start element/end element/empty element/PI : tag name. */
110 const char** attr, /* xml/start element/empty element : name,value pairs, as zero-terminated list. */
111 const char* data); /* comment/pi/text/cdata : content*/
112
113 typedef xparser_callback xparser_handlers[xparserLAST];
114
115
117 enum xparser_textmode {xparserPRESERVE=0,xparserSKIPBLANK=1,xparserTRIM=2};
118
122 xparser* xparser_create(void);
123
124
138 int xparser_init(xparser* parser, xparser_handlers* handlers, void* userdata,unsigned int options);
139
140
141
150 int xparser_term(xparser* parser);
151
152
157 void xparser_destroy(xparser* parser);
158
159
166 int xparser_reset(xparser* parser, int full);
167
168
181 int xparser_parse(xparser* parser,const char* pData, size_t datalen);
182
189 int xparser_finish(xparser* parser);
190
191/*
192 information functions
193*/
194 const char* xparser_errormsg(xparser* parser);
198 unsigned int xparser_line(xparser* parser);
202 unsigned int xparser_col(xparser* parser);
206 size_t xparser_count(xparser* parser);
210 unsigned int xparser_depth(xparser* parser);
214 unsigned int xparser_flags(xparser* parser);
218 int xparser_has_doc(xparser* parser);
222 void* xparser_userdata(xparser* parser);
228#ifdef __DOXYGEN__
243#else
244
245/* #define XPARSER_ALLOC 2 */ /* no allocation functions in library */
246
247#endif /* doxygen */
248
249#if XPARSER_ALLOC
252 typedef void * (*xparser_alloc) (
253 void *ud, /*< user token, supplied with allocator */
254 void *ptr, /*< pointer to realloc/free. NULL for alloc */
255 size_t osize, /*< current size : 0 to allocate */
256 size_t nsize); /*< new size. 0 to de-allocate */
257
265 xparser* xparser_createalloc(xparser_alloc pa, void* ud);
266
275
276#endif
277
278#ifdef __cplusplus
279}
280#endif
281
282
284#endif
int xparser_reset(xparser *parser, int full)
reset a parser to post-create state.
void xparser_setalloc(xparser_alloc pa, void *ud)
Install the default allocator for subsequent xparser_create calls.
xparser_textmode
flags for text handling
Definition: xparser.h:117
const char *const xparser_eventname[xparserLAST]
array lookup for event names
int xparser_finish(xparser *parser)
Check end of input without invoking callbacks.
xparser_event
events for user callbacks
Definition: xparser.h:58
unsigned int xparser_flags(xparser *parser)
Read whitespace-processing flags.
xparser * xparser_createalloc(xparser_alloc pa, void *ud)
Create a parser with its own allocator callback and context.
size_t xparser_count(xparser *parser)
Read the input position.
int(* xparser_callback)(xparser *parser, void *userdata, xparser_event event, const char *name, const char **attr, const char *data)
xparser user callback.
Definition: xparser.h:105
int xparser_parse(xparser *parser, const char *pData, size_t datalen)
parse a chunk of xml data.
int xparser_has_doc(xparser *parser)
Check whether the document node was parsed.
xparser * xparser_create(void)
create a parser.
void *(* xparser_alloc)(void *ud, void *ptr, size_t osize, size_t nsize)
define XPARSER_ALLOC non-zero to enable a user memory allocator.
Definition: xparser.h:252
unsigned int xparser_line(xparser *parser)
Read the source line.
const char * xparser_errormsg(xparser *parser)
Read the last parser error.
void * xparser_userdata(xparser *parser)
Retrieve the application context.
int xparser_term(xparser *parser)
destroy a parser, WITHOUT deallocating pointer.
unsigned int xparser_depth(xparser *parser)
Read the nesting depth.
unsigned int xparser_col(xparser *parser)
Read the source column.
void xparser_destroy(xparser *parser)
destroy a parser
int xparser_init(xparser *parser, xparser_handlers *handlers, void *userdata, unsigned int options)
initialise a parser.
@ xparserPI
processing instruction : <?name data?>
Definition: xparser.h:77
@ xparserEND_ELEMENT
end element : </name>
Definition: xparser.h:75
@ xparserCOMMENT
comment : <!–data-->
Definition: xparser.h:78
@ xparserCDATA
cdata : data
Definition: xparser.h:79
@ xparserINIT
called from xparser_init()
Definition: xparser.h:65
@ xparserSTART_ELEMENT
start element : <name attrs >
Definition: xparser.h:74
@ xparserSTART
called from xparser_parse(), on first call since init() or reset()
Definition: xparser.h:68
@ xparserXML
xml declaration : <?xml attrs ?>
Definition: xparser.h:73
@ xparserLAST
dummy for array sizing
Definition: xparser.h:81
@ xparserTERM
called from xparser_destroy()
Definition: xparser.h:67
@ xparserRESET
called from xparser_reset()
Definition: xparser.h:66
@ xparserNOEVENT
internal flag for no event set.
Definition: xparser.h:60
@ xparserEMPTY_ELEMENT
empty element : <name attrs />
Definition: xparser.h:76
@ xparserTEXT
text : data
Definition: xparser.h:80