izmjene licence
[ossec-hids.git] / src / os_xml / os_xml.h
1 /* @(#) $Id: ./src/os_xml/os_xml.h, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
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
10  * Foundation
11  */
12
13 /* os_xml C Library.
14  */
15
16
17 #ifndef __OS_XML_H
18 #define __OS_XML_H
19
20 /* XML Node structure */
21 typedef struct _xml_node
22 {
23     unsigned int key;
24     char *element;
25     char *content;
26     char **attributes;
27     char **values;
28 }xml_node;
29
30 #define XML_ERR_LENGTH  128
31 typedef enum _XML_TYPE { XML_ATTR, XML_ELEM, XML_VARIABLE_BEGIN = '$' } XML_TYPE;
32
33 /* XML structure */
34 typedef struct _OS_XML
35 {
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 */
46 }OS_XML;
47
48 typedef xml_node ** XML_NODE;
49
50 /* Start the XML structure reading a file */
51 int OS_ReadXML(const char *file, OS_XML *lxml) __attribute__((nonnull));
52
53 /* Clear the XML strucute memory */
54 void OS_ClearXML(OS_XML *_lxml) __attribute__((nonnull));
55
56 /* clear a node */
57 void OS_ClearNode(xml_node **node);
58
59
60 /* Functions to read the XML */
61
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));
64
65 /* Return 1 if the element_name exists */
66 unsigned int OS_ElementExist(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
67
68 /* Return the elements "children" of the element_name */
69 char **OS_GetElements(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
70
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)));
73
74 /* Return the attributes of the element name */
75 char **OS_GetAttributes(const OS_XML *_lxml, const char **element_name) __attribute__((nonnull(1)));
76
77 /* Return one value from element_name */
78 char *OS_GetOneContentforElement(OS_XML *_lxml, const char **element_name) __attribute__((nonnull));
79
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));
82
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)));
85
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)));
89
90 /* Apply the variables to the xml */
91 int OS_ApplyVariables(OS_XML *_lxml) __attribute__((nonnull));
92
93 /* Error from writer */
94 #define XMLW_ERROR              006
95 #define XMLW_NOIN               007
96 #define XMLW_NOOUT              010
97
98 /* OS_WriteXML
99  * Write an XML file, based on the input and values to change.
100  */
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)));
103
104 #endif /* __OS_XML_H */
105
106 /* EOF */