Imported Upstream version 2.5.1
[ossec-hids.git] / src / os_xml / os_xml.h
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All rights reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12 /* os_xml C Library.
13  */
14
15
16 #ifndef __OS_XML_H
17 #define __OS_XML_H
18
19 #ifndef XML_MAXSIZE
20    #define XML_MAXSIZE          2048
21 #endif /* XML_MAXSIZE */
22
23 #ifndef XML_VAR
24    #define XML_VAR              "xml_var"
25 #endif /* XML_VAR */
26
27 #define XML_ELEM                101
28 #define XML_ATTR                102
29 #define XML_VARIABLE_BEGIN      '$'
30
31 /* XML Node structure */
32 typedef struct _xml_node
33 {
34     int key;
35     int line;
36     char *element;
37     char *content;
38     char **attributes;
39     char **values;
40 }xml_node;
41
42 /* XML structure */
43 typedef struct _OS_XML
44 {
45     int cur;            /* Currently position (and last after reading) */
46     int fol;            /* Currently position for the xml_access */
47     int *tp;            /* Item type    */
48     int *rl;            /* Relation in the XML */
49     int *ck;            /* If the item was closed or not */
50     int *ln;        /* Currently xml file line */
51     int err_line;   /* Line number of the possible error */
52     char **ct;          /* Content is stored */
53     char **el;          /* The element/attribute name is stored */
54     char err[128];      /* Error messages are stored in here */
55 }OS_XML;
56
57 typedef xml_node ** XML_NODE;
58
59 /* Start the XML structure reading a file */
60 int OS_ReadXML(char *file, OS_XML *lxml);
61
62 /* Clear the XML strucute memory */
63 void OS_ClearXML(OS_XML *_lxml);
64
65 /* clear a node */
66 void OS_ClearNode(xml_node **node);
67
68
69 /* Functions to read the XML */
70
71 /* Return 1 if element_name is a root element */
72 int OS_RootElementExist(OS_XML *_lxml, char *element_name);
73
74 /* Return 1 if the element_name exists */
75 int OS_ElementExist(OS_XML *_lxml, char **element_name);
76
77 /* Return the elements "children" of the element_name */
78 char **OS_GetElements(OS_XML *_lxml, char **element_name);
79
80 /* Return the elements "children" of the element_name */
81 xml_node **OS_GetElementsbyNode(OS_XML *_lxml, xml_node *node);
82
83 /* Return the attributes of the element name */
84 char **OS_GetAttributes(OS_XML *_lxml, char **element_name);
85
86 /* Return one value from element_name */
87 char *OS_GetOneContentforElement(OS_XML *_lxml, char **element_name);
88
89 /* Return an array with the content of all entries of element_name */
90 char **OS_GetElementContent(OS_XML *_lxml, char **element_name);
91
92 /* Return an array with the contents of an element_nane */
93 char **OS_GetContents(OS_XML *_lxml, char **element_name);
94
95 /* Return the value of a specific attribute of the element_name */
96 char *OS_GetAttributeContent(OS_XML *_lxml, char **element_name,
97         char *attribute_name);
98
99 /* Apply the variables to the xml */
100 int OS_ApplyVariables(OS_XML *_lxml);
101
102 #endif
103
104 /* EOF */