xref: /dragonfly/usr.bin/evtranalyze/xml.h (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  * Copyright (c) 2009, 2010 Aggelos Economopoulos.  All rights reserved.
3*86d7f5d3SJohn Marino  *
4*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
5*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
6*86d7f5d3SJohn Marino  * are met:
7*86d7f5d3SJohn Marino  *
8*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
11*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in
12*86d7f5d3SJohn Marino  *    the documentation and/or other materials provided with the
13*86d7f5d3SJohn Marino  *    distribution.
14*86d7f5d3SJohn Marino  * 3. Neither the name of The DragonFly Project nor the names of its
15*86d7f5d3SJohn Marino  *    contributors may be used to endorse or promote products derived
16*86d7f5d3SJohn Marino  *    from this software without specific, prior written permission.
17*86d7f5d3SJohn Marino  *
18*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*86d7f5d3SJohn Marino  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*86d7f5d3SJohn Marino  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21*86d7f5d3SJohn Marino  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
22*86d7f5d3SJohn Marino  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23*86d7f5d3SJohn Marino  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24*86d7f5d3SJohn Marino  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*86d7f5d3SJohn Marino  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26*86d7f5d3SJohn Marino  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27*86d7f5d3SJohn Marino  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28*86d7f5d3SJohn Marino  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*86d7f5d3SJohn Marino  * SUCH DAMAGE.
30*86d7f5d3SJohn Marino  */
31*86d7f5d3SJohn Marino 
32*86d7f5d3SJohn Marino #ifndef _EVTRANALYZE_XML_H_
33*86d7f5d3SJohn Marino #define _EVTRANALYZE_XML_H_
34*86d7f5d3SJohn Marino 
35*86d7f5d3SJohn Marino #include <stdio.h>
36*86d7f5d3SJohn Marino #include <sys/queue.h>
37*86d7f5d3SJohn Marino 
38*86d7f5d3SJohn Marino 
39*86d7f5d3SJohn Marino typedef struct xml_attribute {
40*86d7f5d3SJohn Marino 	const char    *name;
41*86d7f5d3SJohn Marino 	const char    *value;
42*86d7f5d3SJohn Marino 	STAILQ_ENTRY(xml_attribute) next;
43*86d7f5d3SJohn Marino } *xml_attribute_t;
44*86d7f5d3SJohn Marino 
45*86d7f5d3SJohn Marino typedef struct xml_element {
46*86d7f5d3SJohn Marino 	const char    *name;
47*86d7f5d3SJohn Marino 	const char    *value;
48*86d7f5d3SJohn Marino 	STAILQ_HEAD(, xml_attribute) attributes;
49*86d7f5d3SJohn Marino 	STAILQ_ENTRY(xml_element) link;
50*86d7f5d3SJohn Marino } *xml_element_t;
51*86d7f5d3SJohn Marino 
52*86d7f5d3SJohn Marino typedef struct xml_document {
53*86d7f5d3SJohn Marino 	FILE    *file;
54*86d7f5d3SJohn Marino 	STAILQ_HEAD(, xml_element) open_elems;
55*86d7f5d3SJohn Marino 	int nr_open;
56*86d7f5d3SJohn Marino 	const char *errmsg;
57*86d7f5d3SJohn Marino } *xml_document_t;
58*86d7f5d3SJohn Marino 
59*86d7f5d3SJohn Marino static inline
60*86d7f5d3SJohn Marino void
xml_elem_init(xml_element_t el,const char * name)61*86d7f5d3SJohn Marino xml_elem_init(xml_element_t el, const char *name)
62*86d7f5d3SJohn Marino {
63*86d7f5d3SJohn Marino 	el->name = name;
64*86d7f5d3SJohn Marino 	el->value = NULL;
65*86d7f5d3SJohn Marino 	STAILQ_INIT(&el->attributes);
66*86d7f5d3SJohn Marino }
67*86d7f5d3SJohn Marino 
68*86d7f5d3SJohn Marino static inline
69*86d7f5d3SJohn Marino void
xml_elem_set_value(xml_element_t el,const char * value)70*86d7f5d3SJohn Marino xml_elem_set_value(xml_element_t el, const char *value)
71*86d7f5d3SJohn Marino {
72*86d7f5d3SJohn Marino 	el->value = value;
73*86d7f5d3SJohn Marino }
74*86d7f5d3SJohn Marino 
75*86d7f5d3SJohn Marino static inline
76*86d7f5d3SJohn Marino void
xml_attribute_init(xml_attribute_t at,const char * name,const char * value)77*86d7f5d3SJohn Marino xml_attribute_init(xml_attribute_t at, const char *name, const char *value)
78*86d7f5d3SJohn Marino {
79*86d7f5d3SJohn Marino 	at->name = name;
80*86d7f5d3SJohn Marino 	at->value = value;
81*86d7f5d3SJohn Marino }
82*86d7f5d3SJohn Marino 
83*86d7f5d3SJohn Marino static inline
84*86d7f5d3SJohn Marino void
xml_attribute_set_value(xml_attribute_t at,const char * value)85*86d7f5d3SJohn Marino xml_attribute_set_value(xml_attribute_t at, const char *value)
86*86d7f5d3SJohn Marino {
87*86d7f5d3SJohn Marino 	at->value = value;
88*86d7f5d3SJohn Marino }
89*86d7f5d3SJohn Marino 
90*86d7f5d3SJohn Marino static inline
91*86d7f5d3SJohn Marino void
xml_elem_set_attribute(xml_element_t el,xml_attribute_t at)92*86d7f5d3SJohn Marino xml_elem_set_attribute(xml_element_t el, xml_attribute_t at)
93*86d7f5d3SJohn Marino {
94*86d7f5d3SJohn Marino 	STAILQ_INSERT_TAIL(&el->attributes, at, next);
95*86d7f5d3SJohn Marino }
96*86d7f5d3SJohn Marino 
97*86d7f5d3SJohn Marino 
98*86d7f5d3SJohn Marino xml_document_t xml_document_create(const char *);
99*86d7f5d3SJohn Marino int xml_document_close(xml_document_t);
100*86d7f5d3SJohn Marino int xml_elem_closed(xml_document_t, xml_element_t);
101*86d7f5d3SJohn Marino int xml_elem_begin(xml_document_t, xml_element_t);
102*86d7f5d3SJohn Marino int xml_elem_close(xml_document_t, xml_element_t);
103*86d7f5d3SJohn Marino 
104*86d7f5d3SJohn Marino #endif /* !_EVTRANALYZE_XML_H_ */
105