Annotation of embedaddon/libpdel/structs/xml.h, revision 1.1.1.1
1.1 misho 1:
2: /*
3: * Copyright (c) 2001-2002 Packet Design, LLC.
4: * All rights reserved.
5: *
6: * Subject to the following obligations and disclaimer of warranty,
7: * use and redistribution of this software, in source or object code
8: * forms, with or without modifications are expressly permitted by
9: * Packet Design; provided, however, that:
10: *
11: * (i) Any and all reproductions of the source or object code
12: * must include the copyright notice above and the following
13: * disclaimer of warranties; and
14: * (ii) No rights are granted, in any manner or form, to use
15: * Packet Design trademarks, including the mark "PACKET DESIGN"
16: * on advertising, endorsements, or otherwise except as such
17: * appears in the above copyright notice or in the software.
18: *
19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
36: * THE POSSIBILITY OF SUCH DAMAGE.
37: *
38: * Author: Archie Cobbs <archie@freebsd.org>
39: */
40:
41: #ifndef _PDEL_STRUCTS_XML_H_
42: #define _PDEL_STRUCTS_XML_H_
43:
44: /*
45: * Callback function type used by structs_xml_input()
46: */
47: typedef void structs_xmllog_t(int sev, const char *fmt, ...);
48:
49: /* Special pre-defined loggers for structs_xml_input() */
50: #define STRUCTS_LOGGER_NONE ((structs_xmllog_t *)0) /* discard output */
51: #define STRUCTS_LOGGER_STDERR ((structs_xmllog_t *)1) /* log to stderr */
52: #define STRUCTS_LOGGER_ALOG ((structs_xmllog_t *)2) /* log to alog() */
53:
54: /* Flags to structs_xml_input() */
55: #define STRUCTS_XML_UNINIT 0x0001 /* data object needs initialization */
56: #define STRUCTS_XML_LOOSE 0x0002 /* unknown tags, nested attrib. ok */
57: #define STRUCTS_XML_SCAN 0x0004 /* don't try to decode data structure */
58: #define STRUCTS_XML_COMB_TAGS 0x0008 /* allow combined tags */
59:
60: /* Flags to structs_xml_output() */
61: #define STRUCTS_XML_FULL 0x0001 /* even output default values */
62:
63: __BEGIN_DECLS
64:
65: /*
66: * Create a data structure instance from XML input.
67: *
68: * The XML document element must match "elem_tag" and may have attributes.
69: * No other tags may have attributes.
70: *
71: * If "attrp" is not NULL, any attributes associated with "elem_tag"
72: * are stored there in a string allocated with memory type "attr_mtype".
73: * Attributes are stored in a single buffer like so:
74: *
75: * name1 '\0' value1 '\0'
76: * name2 '\0' value2 '\0'
77: * ...
78: * nameN '\0' valueN '\0'
79: * '\0'
80: *
81: * It is assumed that "data" points to enough space to hold an item
82: * of type "type".
83: *
84: * If successful (only), "data" must eventually be freed e.g., by calling
85: * structs_free(type, NULL, data).
86: *
87: * "flags" bits are defined above. STRUCTS_XML_UNINIT means that the item
88: * is not initialized and must be initialized first; otherwise it is
89: * assumed to be already initialized and only those subfields specified
90: * in the XML will be changed. STRUCTS_XML_LOOSE means any XML tags that
91: * are unrecognized or nested (non-top level) attributes cause a warning
92: * to be emitted but are otherwise ignored and non-fatal. Without it, these
93: * will cause a fatal error.
94: *
95: * Returns 0 if successful, otherwise -1 and sets errno.
96: */
97: extern int structs_xml_input(const struct structs_type *type,
98: const char *elem_tag, char **attrp,
99: const char *attr_mtype, FILE *fp, void *data,
100: int flags, structs_xmllog_t *logger);
101:
102: /*
103: * Output a data structure as XML.
104: *
105: * The XML document element is an "elem_tag" element with attributes
106: * supplied by "attrs" (if non NULL) as described above.
107: *
108: * If "elems" is non-NULL, it must point to a NULL terminated list of
109: * elements to output. Only elements appearing in the list are output.
110: *
111: * If STRUCTS_XML_FULL is not included in flags, then elements are omitted
112: * if they are equal to their initialized (i.e., default) values.
113: *
114: * Returns 0 if successful, otherwise -1 and sets errno.
115: */
116: extern int structs_xml_output(const struct structs_type *type,
117: const char *elem_tag, const char *attrs,
118: const void *data, FILE *fp, const char **elems,
119: int flags);
120:
121: __END_DECLS
122:
123: #endif /* _PDEL_STRUCTS_XML_H_ */
124:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>