1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
10 /* os_xml C Library */
15 /* XML Node structure */
16 typedef struct _xml_node {
24 #define XML_ERR_LENGTH 128
25 typedef enum _XML_TYPE { XML_ATTR, XML_ELEM, XML_VARIABLE_BEGIN = '$' } XML_TYPE;
28 typedef struct _OS_XML {
29 unsigned int cur; /* Current position (and last after reading) */
30 int fol; /* Current position for the xml_access */
31 XML_TYPE *tp; /* Item type */
32 unsigned int *rl; /* Relation in the XML */
33 int *ck; /* If the item was closed or not */
34 unsigned int *ln; /* Current xml file line */
35 unsigned int err_line; /* Line number of the possible error */
36 char **ct; /* Content is stored */
37 char **el; /* The element/attribute name is stored */
38 char err[XML_ERR_LENGTH]; /* Error messages are stored in here */
41 typedef xml_node **XML_NODE;
43 /* Start the XML structure reading a file */
44 int OS_ReadXML(const char *file, OS_XML *lxml) __attribute__((nonnull));
46 /* Clear the XML structure memory */
47 void OS_ClearXML(OS_XML *_lxml) __attribute__((nonnull));
50 void OS_ClearNode(xml_node **node);
53 /* Functions to read the XML */
55 /* Return 1 if element_name is a root element */
56 unsigned int OS_RootElementExist(const OS_XML *_lxml, const char *element_name) __attribute__((nonnull));
58 /* Return 1 if the element_name exists */
59 unsigned int OS_ElementExist(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
61 /* Return the elements "children" of the element_name */
62 char **OS_GetElements(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
64 /* Return the elements "children" of the element_name */
65 xml_node **OS_GetElementsbyNode(const OS_XML *_lxml, const xml_node *node) __attribute__((nonnull(1)));
67 /* Return the attributes of the element name */
68 char **OS_GetAttributes(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
70 /* Return one value from element_name */
71 char *OS_GetOneContentforElement(OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
73 /* Return an array with the content of all entries of element_name */
74 char **OS_GetElementContent(OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
76 /* Return an array with the contents of an element_nane */
77 char **OS_GetContents(OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
79 /* Return the value of a specific attribute of the element_name */
80 char *OS_GetAttributeContent(OS_XML *_lxml, const char **element_name,
81 const char *attribute_name) __attribute__((nonnull(1, 2)));
83 /* Apply the variables to the xml */
84 int OS_ApplyVariables(OS_XML *_lxml) __attribute__((nonnull));
86 /* Error from writer */
87 #define XMLW_ERROR 006
89 #define XMLW_NOOUT 010
91 /* Write an XML file, based on the input and values to change */
92 int OS_WriteXML(const char *infile, const char *outfile, const char **nodes,
93 const char *oldval, const char *newval) __attribute__((nonnull(1, 2, 3, 5)));
95 #endif /* __OS_XML_H */