Process Hacker
Main Page
Namespaces
Data Structures
Files
File List
Globals
mxml.h
Go to the documentation of this file.
1
/*
2
* "$Id: mxml.h 385 2009-03-19 05:38:52Z mike $"
3
*
4
* Header file for Mini-XML, a small XML-like file parsing library.
5
*
6
* Copyright 2003-2009 by Michael Sweet.
7
*
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*/
18
19
// This release of Mini-XML has been modified for Process Hacker in the following ways:
20
// * Memory allocations are done through Process Hacker's PhAllocate*/PhFree* functions.
21
// * The file descriptor functions now use file handles.
22
23
/*
24
* Prevent multiple inclusion...
25
*/
26
27
#ifndef _mxml_h_
28
# define _mxml_h_
29
30
/*
31
* Include necessary headers...
32
*/
33
34
# include <stdio.h>
35
# include <stdlib.h>
36
# include <string.h>
37
# include <ctype.h>
38
# include <errno.h>
39
# include <windows.h>
40
41
#ifdef PHAPP_EXPORT
42
#define PHMXMLAPI __declspec(dllexport)
43
#else
44
#define PHMXMLAPI
45
#endif
46
47
48
/*
49
* Constants...
50
*/
51
52
# define MXML_TAB 8
/* Tabs every N columns */
53
54
# define MXML_NO_CALLBACK 0
/* Don't use a type callback */
55
# define MXML_INTEGER_CALLBACK mxml_integer_cb
56
/* Treat all data as integers */
57
# define MXML_OPAQUE_CALLBACK mxml_opaque_cb
58
/* Treat all data as opaque */
59
# define MXML_REAL_CALLBACK mxml_real_cb
60
/* Treat all data as real numbers */
61
# define MXML_TEXT_CALLBACK 0
/* Treat all data as text */
62
# define MXML_IGNORE_CALLBACK mxml_ignore_cb
63
/* Ignore all non-element content */
64
65
# define MXML_NO_PARENT 0
/* No parent for the node */
66
67
# define MXML_DESCEND 1
/* Descend when finding/walking */
68
# define MXML_NO_DESCEND 0
/* Don't descend when finding/walking */
69
# define MXML_DESCEND_FIRST -1
/* Descend for first find */
70
71
# define MXML_WS_BEFORE_OPEN 0
/* Callback for before open tag */
72
# define MXML_WS_AFTER_OPEN 1
/* Callback for after open tag */
73
# define MXML_WS_BEFORE_CLOSE 2
/* Callback for before close tag */
74
# define MXML_WS_AFTER_CLOSE 3
/* Callback for after close tag */
75
76
# define MXML_ADD_BEFORE 0
/* Add node before specified node */
77
# define MXML_ADD_AFTER 1
/* Add node after specified node */
78
# define MXML_ADD_TO_PARENT NULL
/* Add node relative to parent */
79
80
81
/*
82
* Data types...
83
*/
84
85
typedef
enum
mxml_sax_event_e
/**** SAX event type. ****/
86
{
87
MXML_SAX_CDATA
,
/* CDATA node */
88
MXML_SAX_COMMENT
,
/* Comment node */
89
MXML_SAX_DATA
,
/* Data node */
90
MXML_SAX_DIRECTIVE
,
/* Processing directive node */
91
MXML_SAX_ELEMENT_CLOSE
,
/* Element closed */
92
MXML_SAX_ELEMENT_OPEN
/* Element opened */
93
}
mxml_sax_event_t
;
94
95
typedef
enum
mxml_type_e
/**** The XML node type. ****/
96
{
97
MXML_IGNORE
= -1,
/* Ignore/throw away node @since Mini-XML 2.3@ */
98
MXML_ELEMENT
,
/* XML element with attributes */
99
MXML_INTEGER
,
/* Integer value */
100
MXML_OPAQUE
,
/* Opaque string */
101
MXML_REAL
,
/* Real value */
102
MXML_TEXT
,
/* Text fragment */
103
MXML_CUSTOM
/* Custom data @since Mini-XML 2.1@ */
104
}
mxml_type_t
;
105
106
typedef
void (*
mxml_custom_destroy_cb_t
)(
void
*);
107
/**** Custom data destructor ****/
108
109
typedef
void (*
mxml_error_cb_t
)(
const
char
*);
110
/**** Error callback function ****/
111
112
typedef
struct
mxml_attr_s
/**** An XML element attribute value. ****/
113
{
114
char
*
name
;
/* Attribute name */
115
char
*
value
;
/* Attribute value */
116
}
mxml_attr_t
;
117
118
typedef
struct
mxml_element_s
/**** An XML element value. ****/
119
{
120
char
*
name
;
/* Name of element */
121
int
num_attrs
;
/* Number of attributes */
122
mxml_attr_t
*
attrs
;
/* Attributes */
123
}
mxml_element_t
;
124
125
typedef
struct
mxml_text_s
/**** An XML text value. ****/
126
{
127
int
whitespace
;
/* Leading whitespace? */
128
char
*
string
;
/* Fragment string */
129
}
mxml_text_t
;
130
131
typedef
struct
mxml_custom_s
/**** An XML custom value. @since Mini-XML 2.1@ ****/
132
{
133
void
*
data
;
/* Pointer to (allocated) custom data */
134
mxml_custom_destroy_cb_t
destroy
;
/* Pointer to destructor function */
135
}
mxml_custom_t
;
136
137
typedef
union
mxml_value_u
/**** An XML node value. ****/
138
{
139
mxml_element_t
element
;
/* Element */
140
int
integer
;
/* Integer number */
141
char
*
opaque
;
/* Opaque string */
142
double
real
;
/* Real number */
143
mxml_text_t
text
;
/* Text fragment */
144
mxml_custom_t
custom
;
/* Custom data @since Mini-XML 2.1@ */
145
}
mxml_value_t
;
146
147
typedef
struct
mxml_node_s
/**** An XML node. ****/
148
{
149
mxml_type_t
type
;
/* Node type */
150
struct
mxml_node_s
*
next
;
/* Next node under same parent */
151
struct
mxml_node_s
*
prev
;
/* Previous node under same parent */
152
struct
mxml_node_s
*
parent
;
/* Parent node */
153
struct
mxml_node_s
*
child
;
/* First child node */
154
struct
mxml_node_s
*
last_child
;
/* Last child node */
155
mxml_value_t
value
;
/* Node value */
156
int
ref_count
;
/* Use count */
157
void
*
user_data
;
/* User data */
158
}
mxml_node_t
;
159
160
typedef
struct
mxml_index_s
/**** An XML node index. ****/
161
{
162
char
*
attr
;
/* Attribute used for indexing or NULL */
163
int
num_nodes
;
/* Number of nodes in index */
164
int
alloc_nodes
;
/* Allocated nodes in index */
165
int
cur_node
;
/* Current node */
166
mxml_node_t
**
nodes
;
/* Node array */
167
}
mxml_index_t
;
168
169
typedef
int (*
mxml_custom_load_cb_t
)(
mxml_node_t
*,
const
char
*);
170
/**** Custom data load callback function ****/
171
172
typedef
char
*(*mxml_custom_save_cb_t)(
mxml_node_t
*);
173
/**** Custom data save callback function ****/
174
175
typedef
int (*
mxml_entity_cb_t
)(
const
char
*);
176
/**** Entity callback function */
177
178
typedef
mxml_type_t
(*
mxml_load_cb_t
)(
mxml_node_t
*);
179
/**** Load callback function ****/
180
181
typedef
const
char
*(*mxml_save_cb_t)(
mxml_node_t
*, int);
182
/**** Save callback function ****/
183
184
typedef
void (*
mxml_sax_cb_t
)(
mxml_node_t
*,
mxml_sax_event_t
,
void
*);
185
/**** SAX callback function ****/
186
187
188
/*
189
* C++ support...
190
*/
191
192
# ifdef __cplusplus
193
extern
"C"
{
194
# endif
/* __cplusplus */
195
196
/*
197
* Prototypes...
198
*/
199
200
PHMXMLAPI
extern
void
mxmlAdd
(
mxml_node_t
*parent,
int
where,
201
mxml_node_t
*child,
mxml_node_t
*node);
202
PHMXMLAPI
extern
void
mxmlDelete
(
mxml_node_t
*node);
203
PHMXMLAPI
extern
void
mxmlElementDeleteAttr
(
mxml_node_t
*node,
204
const
char
*name);
205
PHMXMLAPI
extern
const
char
*
mxmlElementGetAttr
(
mxml_node_t
*node,
const
char
*name);
206
PHMXMLAPI
extern
void
mxmlElementSetAttr
(
mxml_node_t
*node,
const
char
*name,
207
const
char
*value);
208
extern
void
mxmlElementSetAttrf
(
mxml_node_t
*node,
const
char
*name,
209
const
char
*format, ...)
210
# ifdef __GNUC__
211
__attribute__ ((__format__ (__printf__, 3, 4)))
212
# endif
/* __GNUC__ */
213
;
214
extern
int
mxmlEntityAddCallback
(
mxml_entity_cb_t
cb);
215
extern
const
char
*
mxmlEntityGetName
(
int
val);
216
extern
int
mxmlEntityGetValue
(
const
char
*name);
217
extern
void
mxmlEntityRemoveCallback
(
mxml_entity_cb_t
cb);
218
PHMXMLAPI
extern
mxml_node_t
*
mxmlFindElement
(
mxml_node_t
*node,
mxml_node_t
*top,
219
const
char
*name,
const
char
*attr,
220
const
char
*value,
int
descend);
221
extern
void
mxmlIndexDelete
(
mxml_index_t
*ind);
222
extern
mxml_node_t
*
mxmlIndexEnum
(
mxml_index_t
*ind);
223
extern
mxml_node_t
*
mxmlIndexFind
(
mxml_index_t
*ind,
224
const
char
*element,
225
const
char
*value);
226
extern
mxml_index_t
*
mxmlIndexNew
(
mxml_node_t
*node,
const
char
*element,
227
const
char
*attr);
228
extern
mxml_node_t
*
mxmlIndexReset
(
mxml_index_t
*ind);
229
PHMXMLAPI
extern
mxml_node_t
*
mxmlLoadFd
(
mxml_node_t
*top, HANDLE fd,
230
mxml_type_t
(*cb)(
mxml_node_t
*));
231
extern
mxml_node_t
*
mxmlLoadFile
(
mxml_node_t
*top, FILE *fp,
232
mxml_type_t
(*cb)(
mxml_node_t
*));
233
PHMXMLAPI
extern
mxml_node_t
*
mxmlLoadString
(
mxml_node_t
*top,
const
char
*s,
234
mxml_type_t
(*cb)(
mxml_node_t
*));
235
PHMXMLAPI
extern
mxml_node_t
*
mxmlNewCDATA
(
mxml_node_t
*parent,
const
char
*
string
);
236
PHMXMLAPI
extern
mxml_node_t
*
mxmlNewCustom
(
mxml_node_t
*parent,
void
*data,
237
mxml_custom_destroy_cb_t
destroy);
238
PHMXMLAPI
extern
mxml_node_t
*
mxmlNewElement
(
mxml_node_t
*parent,
const
char
*name);
239
extern
mxml_node_t
*
mxmlNewInteger
(
mxml_node_t
*parent,
int
integer);
240
PHMXMLAPI
extern
mxml_node_t
*
mxmlNewOpaque
(
mxml_node_t
*parent,
const
char
*opaque);
241
extern
mxml_node_t
*
mxmlNewReal
(
mxml_node_t
*parent,
double
real);
242
PHMXMLAPI
extern
mxml_node_t
*
mxmlNewText
(
mxml_node_t
*parent,
int
whitespace,
243
const
char
*
string
);
244
extern
mxml_node_t
*
mxmlNewTextf
(
mxml_node_t
*parent,
int
whitespace,
245
const
char
*format, ...)
246
# ifdef __GNUC__
247
__attribute__ ((__format__ (__printf__, 3, 4)))
248
# endif
/* __GNUC__ */
249
;
250
PHMXMLAPI
extern
mxml_node_t
*
mxmlNewXML
(
const
char
*version);
251
PHMXMLAPI
extern
int
mxmlRelease
(
mxml_node_t
*node);
252
PHMXMLAPI
extern
void
mxmlRemove
(
mxml_node_t
*node);
253
PHMXMLAPI
extern
int
mxmlRetain
(
mxml_node_t
*node);
254
PHMXMLAPI
extern
char
*
mxmlSaveAllocString
(
mxml_node_t
*node,
255
mxml_save_cb_t
cb);
256
PHMXMLAPI
extern
int
mxmlSaveFd
(
mxml_node_t
*node, HANDLE fd,
257
mxml_save_cb_t
cb);
258
extern
int
mxmlSaveFile
(
mxml_node_t
*node, FILE *fp,
259
mxml_save_cb_t
cb);
260
PHMXMLAPI
extern
int
mxmlSaveString
(
mxml_node_t
*node,
char
*buffer,
261
int
bufsize,
mxml_save_cb_t
cb);
262
extern
mxml_node_t
*
mxmlSAXLoadFd
(
mxml_node_t
*top, HANDLE fd,
263
mxml_type_t
(*cb)(
mxml_node_t
*),
264
mxml_sax_cb_t
sax,
void
*sax_data);
265
extern
mxml_node_t
*
mxmlSAXLoadFile
(
mxml_node_t
*top, FILE *fp,
266
mxml_type_t
(*cb)(
mxml_node_t
*),
267
mxml_sax_cb_t
sax,
void
*sax_data);
268
extern
mxml_node_t
*
mxmlSAXLoadString
(
mxml_node_t
*top,
const
char
*s,
269
mxml_type_t
(*cb)(
mxml_node_t
*),
270
mxml_sax_cb_t
sax,
void
*sax_data);
271
PHMXMLAPI
extern
int
mxmlSetCDATA
(
mxml_node_t
*node,
const
char
*data);
272
PHMXMLAPI
extern
int
mxmlSetCustom
(
mxml_node_t
*node,
void
*data,
273
mxml_custom_destroy_cb_t
destroy);
274
PHMXMLAPI
extern
void
mxmlSetCustomHandlers
(
mxml_custom_load_cb_t
load,
275
mxml_custom_save_cb_t
save);
276
PHMXMLAPI
extern
int
mxmlSetElement
(
mxml_node_t
*node,
const
char
*name);
277
PHMXMLAPI
extern
void
mxmlSetErrorCallback
(
mxml_error_cb_t
cb);
278
extern
int
mxmlSetInteger
(
mxml_node_t
*node,
int
integer);
279
PHMXMLAPI
extern
int
mxmlSetOpaque
(
mxml_node_t
*node,
const
char
*opaque);
280
extern
int
mxmlSetReal
(
mxml_node_t
*node,
double
real);
281
PHMXMLAPI
extern
int
mxmlSetText
(
mxml_node_t
*node,
int
whitespace,
282
const
char
*
string
);
283
extern
int
mxmlSetTextf
(
mxml_node_t
*node,
int
whitespace,
284
const
char
*format, ...)
285
# ifdef __GNUC__
286
__attribute__ ((__format__ (__printf__, 3, 4)))
287
# endif
/* __GNUC__ */
288
;
289
extern
void
mxmlSetWrapMargin
(
int
column);
290
PHMXMLAPI
extern
mxml_node_t
*
mxmlWalkNext
(
mxml_node_t
*node,
mxml_node_t
*top,
291
int
descend);
292
PHMXMLAPI
extern
mxml_node_t
*
mxmlWalkPrev
(
mxml_node_t
*node,
mxml_node_t
*top,
293
int
descend);
294
295
296
/*
297
* Semi-private functions...
298
*/
299
300
extern
void
mxml_error
(
const
char
*format, ...);
301
extern
mxml_type_t
mxml_ignore_cb
(
mxml_node_t
*node);
302
extern
mxml_type_t
mxml_integer_cb
(
mxml_node_t
*node);
303
extern
mxml_type_t
mxml_opaque_cb
(
mxml_node_t
*node);
304
extern
mxml_type_t
mxml_real_cb
(
mxml_node_t
*node);
305
306
307
/*
308
* C++ support...
309
*/
310
311
# ifdef __cplusplus
312
}
313
# endif
/* __cplusplus */
314
#endif
/* !_mxml_h_ */
315
316
317
/*
318
* End of "$Id: mxml.h 385 2009-03-19 05:38:52Z mike $".
319
*/
ProcessHacker
mxml
mxml.h
Generated by
1.8.2