Imported Upstream version 2.7
[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 #ifndef XML_MAXSIZE
21    #define XML_MAXSIZE          2048
22 #endif /* XML_MAXSIZE */
23
24 #ifndef XML_VAR
25    #define XML_VAR              "xml_var"
26 #endif /* XML_VAR */
27
28 #define XML_ELEM                101
29 #define XML_ATTR                102
30 #define XML_VARIABLE_BEGIN      '$'
31
32 /* XML Node structure */
33 typedef struct _xml_node
34 {
35     int key;
36     int line;
37     char *element;
38     char *content;
39     char **attributes;
40     char **values;
41 }xml_node;
42
43 /* XML structure */
44 typedef struct _OS_XML
45 {
46     int cur;            /* Currently position (and last after reading) */
47     int fol;            /* Currently position for the xml_access */
48     int *tp;            /* Item type    */
49     int *rl;            /* Relation in the XML */
50     int *ck;            /* If the item was closed or not */
51     int *ln;        /* Currently xml file line */
52     int err_line;   /* Line number of the possible error */
53     char **ct;          /* Content is stored */
54     char **el;          /* The element/attribute name is stored */
55     char err[128];      /* Error messages are stored in here */
56 }OS_XML;
57
58 typedef xml_node ** XML_NODE;
59
60 /* Start the XML structure reading a file */
61 int OS_ReadXML(char *file, OS_XML *lxml);
62
63 /* Clear the XML strucute memory */
64 void OS_ClearXML(OS_XML *_lxml);
65
66 /* clear a node */
67 void OS_ClearNode(xml_node **node);
68
69
70 /* Functions to read the XML */
71
72 /* Return 1 if element_name is a root element */
73 int OS_RootElementExist(OS_XML *_lxml, char *element_name);
74
75 /* Return 1 if the element_name exists */
76 int OS_ElementExist(OS_XML *_lxml, char **element_name);
77
78 /* Return the elements "children" of the element_name */
79 char **OS_GetElements(OS_XML *_lxml, char **element_name);
80
81 /* Return the elements "children" of the element_name */
82 xml_node **OS_GetElementsbyNode(OS_XML *_lxml, xml_node *node);
83
84 /* Return the attributes of the element name */
85 char **OS_GetAttributes(OS_XML *_lxml, char **element_name);
86
87 /* Return one value from element_name */
88 char *OS_GetOneContentforElement(OS_XML *_lxml, char **element_name);
89
90 /* Return an array with the content of all entries of element_name */
91 char **OS_GetElementContent(OS_XML *_lxml, char **element_name);
92
93 /* Return an array with the contents of an element_nane */
94 char **OS_GetContents(OS_XML *_lxml, char **element_name);
95
96 /* Return the value of a specific attribute of the element_name */
97 char *OS_GetAttributeContent(OS_XML *_lxml, char **element_name,
98         char *attribute_name);
99
100 /* Apply the variables to the xml */
101 int OS_ApplyVariables(OS_XML *_lxml);
102
103 #endif
104
105 /* EOF */