Greenbone Vulnerability Management Libraries  11.0.1
xmlutils.h
Go to the documentation of this file.
1 /* Copyright (C) 2009-2019 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
25 #ifndef _GVM_XMLUTILS_H
26 #define _GVM_XMLUTILS_H
27 
28 #include "serverutils.h"
29 
30 #include <glib.h>
31 #include <gnutls/gnutls.h>
32 #include <stdio.h>
33 
40 typedef struct
41 {
42  GSList *first;
43  GSList *current;
44  gboolean done;
46 
47 void
48 xml_handle_start_element (context_data_t *, const gchar *, const gchar **,
49  const gchar **);
50 
51 void
52 xml_handle_end_element (context_data_t *, const gchar *);
53 
54 void
55 xml_handle_text (context_data_t *, const gchar *, gsize);
56 
60 typedef GSList *entities_t;
61 
65 struct entity_s
66 {
67  char *name;
68  char *text;
69  GHashTable *attributes;
71 };
72 typedef struct entity_s *entity_t;
73 
77 typedef struct
78 {
79  int found;
80  int done;
81  gchar *find_element;
82  GHashTable *find_attributes;
84 
86 
88 
90 add_entity (entities_t *, const char *, const char *);
91 
93 
95 entity_child (entity_t, const char *);
96 
97 const char *
98 entity_attribute (entity_t, const char *);
99 
100 char *
101 entity_name (entity_t entity);
102 
103 char *
104 entity_text (entity_t entity);
105 
106 void free_entity (entity_t);
107 
108 void
109 print_entity (FILE *, entity_t);
110 
111 void
112 print_entity_format (entity_t, gpointer indentation);
113 
114 int
115 try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **);
116 
117 int
118 read_entity_and_string (gnutls_session_t *, entity_t *, GString **);
119 
120 int
122 
123 int
124 read_entity_and_text (gnutls_session_t *, entity_t *, char **);
125 
126 int
128 
129 int
130 try_read_entity (gnutls_session_t *, int, entity_t *);
131 
132 int
134 
135 int
136 read_entity (gnutls_session_t *, entity_t *);
137 
138 int
139 read_entity_s (int, entity_t *);
140 
141 int
143 
144 int
145 read_string (gnutls_session_t *, GString **);
146 
147 int
148 read_string_c (gvm_connection_t *, GString **);
149 
150 int
151 parse_entity (const char *, entity_t *);
152 
153 void
154 print_entity_to_string (entity_t entity, GString *string);
155 
157 
158 void
159 xml_string_append (GString *, const char *, ...);
160 
161 
162 /* XML file utilities */
163 
164 int
165 find_element_in_xml_file (gchar *, gchar *, GHashTable *);
166 
167 
168 /* The new faster parser that uses libxml2. */
169 
170 typedef struct _xmlNode *element_t;
171 
172 int
173 parse_element (const gchar *, element_t *);
174 
175 void
177 
178 const gchar *
180 
181 gchar *
182 element_attribute (element_t, const gchar *);
183 
184 gchar *
186 
187 element_t
188 element_child (element_t, const gchar *);
189 
190 element_t
192 
193 element_t
195 
196 #endif /* not _GVM_XMLUTILS_H */
compare_entities
int compare_entities(entity_t, entity_t)
Compare two XML entity.
Definition: xmlutils.c:1441
add_entity
entity_t add_entity(entities_t *, const char *, const char *)
Add an XML entity to a tree of entities.
Definition: xmlutils.c:115
entity_name
char * entity_name(entity_t entity)
Get the name an entity.
Definition: xmlutils.c:175
read_entity
int read_entity(gnutls_session_t *, entity_t *)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1149
context_data_t
XML context.
Definition: xmlutils.h:41
entity_text
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xmlutils.c:159
entity_s::entities
entities_t entities
Children.
Definition: xmlutils.h:70
read_string_c
int read_string_c(gvm_connection_t *, GString **)
Read entity and text. Free the entity immediately.
Definition: xmlutils.c:1100
entity_s::name
char * name
Name.
Definition: xmlutils.h:67
entity_attribute
const char * entity_attribute(entity_t, const char *)
Get an attribute of an entity.
Definition: xmlutils.c:230
xml_string_append
void xml_string_append(GString *, const char *,...)
Append formatted escaped XML to a string.
Definition: xmlutils.c:1527
read_entity_and_text
int read_entity_and_text(gnutls_session_t *, entity_t *, char **)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1021
parse_element
int parse_element(const gchar *, element_t *)
Read an XML element tree from a string.
Definition: xmlutils.c:1682
entity_s::attributes
GHashTable * attributes
Attributes.
Definition: xmlutils.h:69
xml_handle_start_element
void xml_handle_start_element(context_data_t *, const gchar *, const gchar **, const gchar **)
Handle the start of an OMP XML element.
Definition: xmlutils.c:340
first_entity
entity_t first_entity(entities_t)
Return the first entity from an entities_t.
Definition: xmlutils.c:96
print_entity
void print_entity(FILE *, entity_t)
Print an XML entity.
Definition: xmlutils.c:1339
xml_search_data_t::find_attributes
GHashTable * find_attributes
Definition: xmlutils.h:82
element_next
element_t element_next(element_t)
Get the next sibling of an element.
Definition: xmlutils.c:1902
xml_handle_text
void xml_handle_text(context_data_t *, const gchar *, gsize)
Handle additional text of an XML element.
Definition: xmlutils.c:478
element_text
gchar * element_text(element_t)
Get text of an element.
Definition: xmlutils.c:1816
element_attribute
gchar * element_attribute(element_t, const gchar *)
Get an attribute of an element.
Definition: xmlutils.c:1840
element_name
const gchar * element_name(element_t)
Get the name of an element.
Definition: xmlutils.c:1730
element_t
struct _xmlNode * element_t
Definition: xmlutils.h:170
read_string
int read_string(gnutls_session_t *, GString **)
Read entity and text. Free the entity immediately.
Definition: xmlutils.c:1080
try_read_entity
int try_read_entity(gnutls_session_t *, int, entity_t *)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1116
xml_search_data_t::find_element
gchar * find_element
Definition: xmlutils.h:81
xml_count_entities
int xml_count_entities(entities_t)
Count the number of entities.
Definition: xmlutils.c:1506
xml_search_data_t::done
int done
Definition: xmlutils.h:80
context_data_t::current
GSList * current
The element currently being parsed.
Definition: xmlutils.h:43
try_read_entity_and_string
int try_read_entity_and_string(gnutls_session_t *, int, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:514
element_first_child
element_t element_first_child(element_t)
Get the first child of an element.
Definition: xmlutils.c:1887
element_free
void element_free(element_t)
Free an entire element tree.
Definition: xmlutils.c:1713
read_entity_s
int read_entity_s(int, entity_t *)
Read an XML entity tree from the socket.
Definition: xmlutils.c:1163
context_data_t::done
gboolean done
Flag which is true when the first element is closed.
Definition: xmlutils.h:44
read_entity_and_string
int read_entity_and_string(gnutls_session_t *, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:978
read_entity_c
int read_entity_c(gvm_connection_t *, entity_t *)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1177
read_entity_and_string_c
int read_entity_and_string_c(gvm_connection_t *, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:998
try_read_entity_c
int try_read_entity_c(gvm_connection_t *, int, entity_t *)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1132
entity_s
XML element.
Definition: xmlutils.h:66
print_entity_format
void print_entity_format(entity_t, gpointer indentation)
Print an XML entity to stdout, recursively printing its children.
Definition: xmlutils.c:1382
serverutils.h
GnuTLS based functions for server communication - header file.
entity_s::text
char * text
Text.
Definition: xmlutils.h:68
xml_search_data_t
Data for xml search functions.
Definition: xmlutils.h:78
xml_handle_end_element
void xml_handle_end_element(context_data_t *, const gchar *)
Handle the end of an XML element.
Definition: xmlutils.c:416
entity_child
entity_t entity_child(entity_t, const char *)
Get a child of an entity.
Definition: xmlutils.c:207
next_entities
entities_t next_entities(entities_t)
Return all the entities from an entities_t after the first.
Definition: xmlutils.c:81
find_element_in_xml_file
int find_element_in_xml_file(gchar *, gchar *, GHashTable *)
Tests if an XML file contains an element with given attributes.
Definition: xmlutils.c:1620
xml_search_data_t::found
int found
Definition: xmlutils.h:79
parse_entity
int parse_entity(const char *, entity_t *)
Read an XML entity tree from a string.
Definition: xmlutils.c:1191
read_entity_and_text_c
int read_entity_and_text_c(gvm_connection_t *, entity_t *, char **)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1052
context_data_t::first
GSList * first
The very first entity.
Definition: xmlutils.h:42
print_entity_to_string
void print_entity_to_string(entity_t entity, GString *string)
Print an XML entity tree to a GString, appending it if string is not.
Definition: xmlutils.c:1292
element_child
element_t element_child(element_t, const gchar *)
Get a child of an element.
Definition: xmlutils.c:1765
entity_t
struct entity_s * entity_t
Definition: xmlutils.h:72
free_entity
void free_entity(entity_t)
Free an entity, recursively.
Definition: xmlutils.c:129
gvm_connection_t
Connection.
Definition: serverutils.h:44
entities_t
GSList * entities_t
Entities.
Definition: xmlutils.h:60