new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_xml / os_xml.h
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All rights reserved.
3  *
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
7  * Foundation
8  */
9
10 /* os_xml C Library */
11
12 #ifndef __OS_XML_H
13 #define __OS_XML_H
14
15 /* XML Node structure */
16 typedef struct _xml_node {
17     unsigned int key;
18     char *element;
19     char *content;
20     char **attributes;
21     char **values;
22 } xml_node;
23
24 #define XML_ERR_LENGTH  128
25 typedef enum _XML_TYPE { XML_ATTR, XML_ELEM, XML_VARIABLE_BEGIN = '$' } XML_TYPE;
26
27 /* XML structure */
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 */
39 } OS_XML;
40
41 typedef xml_node **XML_NODE;
42
43 /* Start the XML structure reading a file */
44 int OS_ReadXML(const char *file, OS_XML *lxml) __attribute__((nonnull));
45
46 /* Clear the XML structure memory */
47 void OS_ClearXML(OS_XML *_lxml) __attribute__((nonnull));
48
49 /* Clear a node */
50 void OS_ClearNode(xml_node **node);
51
52
53 /* Functions to read the XML */
54
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));
57
58 /* Return 1 if the element_name exists */
59 unsigned int OS_ElementExist(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
60
61 /* Return the elements "children" of the element_name */
62 char **OS_GetElements(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
63
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)));
66
67 /* Return the attributes of the element name */
68 char **OS_GetAttributes(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
69
70 /* Return one value from element_name */
71 char *OS_GetOneContentforElement(OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
72
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));
75
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)));
78
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)));
82
83 /* Apply the variables to the xml */
84 int OS_ApplyVariables(OS_XML *_lxml) __attribute__((nonnull));
85
86 /* Error from writer */
87 #define XMLW_ERROR              006
88 #define XMLW_NOIN               007
89 #define XMLW_NOOUT              010
90
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)));
94
95 #endif /* __OS_XML_H */
96