1 /* @(#) $Id: ./src/os_xml/os_xml.h, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
20 /* XML Node structure */
21 typedef struct _xml_node
30 #define XML_ERR_LENGTH 128
31 typedef enum _XML_TYPE { XML_ATTR, XML_ELEM, XML_VARIABLE_BEGIN = '$' } XML_TYPE;
34 typedef struct _OS_XML
36 unsigned int cur; /* Currently position (and last after reading) */
37 int fol; /* Currently position for the xml_access */
38 XML_TYPE *tp; /* Item type */
39 unsigned int *rl; /* Relation in the XML */
40 int *ck; /* If the item was closed or not */
41 unsigned int *ln; /* Currently xml file line */
42 unsigned int err_line; /* Line number of the possible error */
43 char **ct; /* Content is stored */
44 char **el; /* The element/attribute name is stored */
45 char err[XML_ERR_LENGTH]; /* Error messages are stored in here */
48 typedef xml_node ** XML_NODE;
50 /* Start the XML structure reading a file */
51 int OS_ReadXML(const char *file, OS_XML *lxml) __attribute__((nonnull));
53 /* Clear the XML strucute memory */
54 void OS_ClearXML(OS_XML *_lxml) __attribute__((nonnull));
57 void OS_ClearNode(xml_node **node);
60 /* Functions to read the XML */
62 /* Return 1 if element_name is a root element */
63 unsigned int OS_RootElementExist(const OS_XML *_lxml, const char *element_name) __attribute__((nonnull));
65 /* Return 1 if the element_name exists */
66 unsigned int OS_ElementExist(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
68 /* Return the elements "children" of the element_name */
69 char **OS_GetElements(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
71 /* Return the elements "children" of the element_name */
72 xml_node **OS_GetElementsbyNode(const OS_XML *_lxml, const xml_node *node) __attribute__((nonnull(1)));
74 /* Return the attributes of the element name */
75 char **OS_GetAttributes(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
77 /* Return one value from element_name */
78 char *OS_GetOneContentforElement(OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
80 /* Return an array with the content of all entries of element_name */
81 char **OS_GetElementContent(OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
83 /* Return an array with the contents of an element_nane */
84 char **OS_GetContents(OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
86 /* Return the value of a specific attribute of the element_name */
87 char *OS_GetAttributeContent(OS_XML *_lxml, const char **element_name,
88 const char *attribute_name) __attribute__((nonnull(1,2)));
90 /* Apply the variables to the xml */
91 int OS_ApplyVariables(OS_XML *_lxml) __attribute__((nonnull));
93 /* Error from writer */
94 #define XMLW_ERROR 006
96 #define XMLW_NOOUT 010
99 * Write an XML file, based on the input and values to change.
101 int OS_WriteXML(const char *infile, const char *outfile, const char **nodes,
102 const char *oldval, const char *newval) __attribute__((nonnull(1,2,3,5)));
104 #endif /* __OS_XML_H */