Greenbone Vulnerability Management Libraries: util/xmlutils.h Source File

Greenbone Vulnerability Management Libraries 23.1.1

xmlutils.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
10
11#ifndef _GVM_UTIL_XMLUTILS_H
12#define _GVM_UTIL_XMLUTILS_H
13
14#include "serverutils.h"
15
16#include <glib.h>
17#include <gnutls/gnutls.h>
18#include <stdio.h>
19
26 typedef struct
27{
28 GSList *first;
29 GSList *current;
30 gboolean done;
31} context_data_t;
32
33void
34 xml_handle_start_element (context_data_t *, const gchar *, const gchar **,
35 const gchar **);
36
37void
38 xml_handle_end_element (context_data_t *, const gchar *);
39
40void
41 xml_handle_text (context_data_t *, const gchar *, gsize);
42
46 typedef GSList *entities_t;
47
51 struct entity_s
52{
53 char *name;
54 char *text;
55 GHashTable *attributes;
56 entities_t entities;
57};
58 typedef struct entity_s *entity_t;
59
63 typedef struct
64{
65 int found;
66 int done;
67 gchar *find_element;
68 GHashTable *find_attributes;
69} xml_search_data_t;
70
71 entities_t next_entities (entities_t);
72
73 entity_t first_entity (entities_t);
74
75 entity_t
76 add_entity (entities_t *, const char *, const char *);
77
78int compare_entities (entity_t, entity_t);
79
80 entity_t
81 entity_child (entity_t, const char *);
82
83const char *
84 entity_attribute (entity_t, const char *);
85
86char *
87 entity_name (entity_t entity);
88
89char *
90 entity_text (entity_t entity);
91
92void free_entity (entity_t);
93
94void
95 print_entity (FILE *, entity_t);
96
97void
98 print_entity_format (entity_t, gpointer indentation);
99
100int
101 try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **);
102
103int
104 read_entity_and_string (gnutls_session_t *, entity_t *, GString **);
105
106int
107 read_entity_and_string_c (gvm_connection_t *, entity_t *, GString **);
108
109int
110 read_entity_and_text (gnutls_session_t *, entity_t *, char **);
111
112int
113 read_entity_and_text_c (gvm_connection_t *, entity_t *, char **);
114
115int
116 try_read_entity (gnutls_session_t *, int, entity_t *);
117
118int
119 try_read_entity_c (gvm_connection_t *, int, entity_t *);
120
121int
122 read_entity (gnutls_session_t *, entity_t *);
123
124int
125 read_entity_s (int, entity_t *);
126
127int
128 read_entity_c (gvm_connection_t *, entity_t *);
129
130int
131 read_string (gnutls_session_t *, GString **);
132
133int
134 read_string_c (gvm_connection_t *, GString **);
135
136int
137 read_text_c (gvm_connection_t *, char **);
138
139int
140 parse_entity (const char *, entity_t *);
141
142void
143 print_entity_to_string (entity_t entity, GString *string);
144
145int xml_count_entities (entities_t);
146
147void
148 xml_string_append (GString *, const char *, ...);
149
150/* XML file utilities */
151
152int
153 find_element_in_xml_file (gchar *, gchar *, GHashTable *);
154
155/* The new faster parser that uses libxml2. */
156
157 typedef struct _xmlNode *element_t;
158
159int
160 parse_element (const gchar *, element_t *);
161
162void element_free (element_t);
163
164const gchar *element_name (element_t);
165
166gchar *
167 element_attribute (element_t, const gchar *);
168
169gchar *element_text (element_t);
170
171 element_t
172 element_child (element_t, const gchar *);
173
174 element_t element_first_child (element_t);
175
176 element_t element_next (element_t);
177
178gchar *
179 element_to_string (element_t element);
180
181void
182 print_element_to_string (element_t element, GString *string);
183
184/* XML file iterator
185 * for reading subelements from large files without building the whole DOM
186 */
187
188 typedef struct xml_file_iterator_struct *xml_file_iterator_t;
189
190 xml_file_iterator_t
191 xml_file_iterator_new (void);
192
193int
194 xml_file_iterator_init_from_file_path (xml_file_iterator_t, const char *, int);
195
196void xml_file_iterator_free (xml_file_iterator_t);
197
198int xml_file_iterator_rewind (xml_file_iterator_t);
199
200 element_t
201 xml_file_iterator_next (xml_file_iterator_t, gchar **);
202
203#endif /* not _GVM_UTIL_XMLUTILS_H */
serverutils.h
GnuTLS based functions for server communication - header file.
context_data_t
XML context.
Definition xmlutils.h:27
context_data_t::first
GSList * first
The very first entity.
Definition xmlutils.h:28
context_data_t::current
GSList * current
The element currently being parsed.
Definition xmlutils.h:29
context_data_t::done
gboolean done
Flag which is true when the first element is closed.
Definition xmlutils.h:30
entity_s
XML element.
Definition xmlutils.h:52
entity_s::entities
entities_t entities
Children.
Definition xmlutils.h:56
entity_s::text
char * text
Text.
Definition xmlutils.h:54
entity_s::attributes
GHashTable * attributes
Attributes.
Definition xmlutils.h:55
entity_s::name
char * name
Name.
Definition xmlutils.h:53
gvm_connection_t
Connection.
Definition serverutils.h:30
xml_file_iterator_struct
Opaque data structure for XML file iterator.
Definition xmlutils.c:2331
xml_search_data_t
Data for xml search functions.
Definition xmlutils.h:64
xml_search_data_t::done
int done
Definition xmlutils.h:66
xml_search_data_t::find_element
gchar * find_element
Definition xmlutils.h:67
xml_search_data_t::find_attributes
GHashTable * find_attributes
Definition xmlutils.h:68
xml_search_data_t::found
int found
Definition xmlutils.h:65
xml_file_iterator_next
element_t xml_file_iterator_next(xml_file_iterator_t, gchar **)
Get the next subelement from a XML file iterator.
Definition xmlutils.c:3000
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:501
xml_file_iterator_rewind
int xml_file_iterator_rewind(xml_file_iterator_t)
Rewinds an XML file iterator by rewinding the file and creating a new XML parser context.
Definition xmlutils.c:2954
entity_t
struct entity_s * entity_t
Definition xmlutils.h:58
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:1436
element_name
const gchar * element_name(element_t)
Get the name of an element.
Definition xmlutils.c:2052
xml_count_entities
int xml_count_entities(entities_t)
Count the number of entities.
Definition xmlutils.c:1830
entity_name
char * entity_name(entity_t entity)
Get the name an entity.
Definition xmlutils.c:161
entity_text
char * entity_text(entity_t entity)
Get the text an entity.
Definition xmlutils.c:145
compare_entities
int compare_entities(entity_t, entity_t)
Compare two XML entity.
Definition xmlutils.c:1765
parse_entity
int parse_entity(const char *, entity_t *)
Read an XML entity tree from a string.
Definition xmlutils.c:1511
read_text_c
int read_text_c(gvm_connection_t *, char **)
Read text from the server.
Definition xmlutils.c:1366
element_text
gchar * element_text(element_t)
Get text of an element.
Definition xmlutils.c:2137
next_entities
entities_t next_entities(entities_t)
Return all the entities from an entities_t after the first.
Definition xmlutils.c:67
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:1336
xml_file_iterator_new
xml_file_iterator_t xml_file_iterator_new(void)
Allocates a new, uninitialized XML file iterator.
Definition xmlutils.c:2857
read_entity_s
int read_entity_s(int, entity_t *)
Read an XML entity tree from the socket.
Definition xmlutils.c:1483
xml_file_iterator_t
struct xml_file_iterator_struct * xml_file_iterator_t
Definition xmlutils.h:188
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:326
entity_attribute
const char * entity_attribute(entity_t, const char *)
Get an attribute of an entity.
Definition xmlutils.c:216
element_t
struct _xmlNode * element_t
Definition xmlutils.h:157
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:1452
print_element_to_string
void print_element_to_string(element_t element, GString *string)
Print an XML element tree to a GString, appending it if string is not.
Definition xmlutils.c:2280
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:1942
read_string
int read_string(gnutls_session_t *, GString **)
Read entity and text. Free the entity immediately.
Definition xmlutils.c:1400
read_entity
int read_entity(gnutls_session_t *, entity_t *)
Read an XML entity tree from the manager.
Definition xmlutils.c:1469
xml_file_iterator_init_from_file_path
int xml_file_iterator_init_from_file_path(xml_file_iterator_t, const char *, int)
Initializes an XML file iterator to read from a given path.
Definition xmlutils.c:2874
element_next
element_t element_next(element_t)
Get the next sibling of an element.
Definition xmlutils.c:2230
xml_handle_end_element
void xml_handle_end_element(context_data_t *, const gchar *)
Handle the end of an XML element.
Definition xmlutils.c:402
entity_child
entity_t entity_child(entity_t, const char *)
Get a child of an entity.
Definition xmlutils.c:193
read_entity_c
int read_entity_c(gvm_connection_t *, entity_t *)
Read an XML entity tree from the manager.
Definition xmlutils.c:1497
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:1262
entities_t
GSList * entities_t
Entities.
Definition xmlutils.h:46
element_child
element_t element_child(element_t, const gchar *)
Get a child of an element.
Definition xmlutils.c:2086
print_entity_format
void print_entity_format(entity_t, gpointer indentation)
Print an XML entity to stdout, recursively printing its children.
Definition xmlutils.c:1706
element_attribute
gchar * element_attribute(element_t, const gchar *)
Get an attribute of an element.
Definition xmlutils.c:2162
xml_handle_text
void xml_handle_text(context_data_t *, const gchar *, gsize)
Handle additional text of an XML element.
Definition xmlutils.c:464
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:1305
first_entity
entity_t first_entity(entities_t)
Return the first entity from an entities_t.
Definition xmlutils.c:82
element_to_string
gchar * element_to_string(element_t element)
Output the XML element as a string.
Definition xmlutils.c:2253
print_entity
void print_entity(FILE *, entity_t)
Print an XML entity.
Definition xmlutils.c:1663
element_free
void element_free(element_t)
Free an entire element tree.
Definition xmlutils.c:2035
element_first_child
element_t element_first_child(element_t)
Get the first child of an element.
Definition xmlutils.c:2210
free_entity
void free_entity(entity_t)
Free an entity, recursively.
Definition xmlutils.c:115
add_entity
entity_t add_entity(entities_t *, const char *, const char *)
Add an XML entity to a tree of entities.
Definition xmlutils.c:101
xml_file_iterator_free
void xml_file_iterator_free(xml_file_iterator_t)
Frees an XML file iterator and all of its internal data structures.
Definition xmlutils.c:2917
parse_element
int parse_element(const gchar *, element_t *)
Read an XML element tree from a string.
Definition xmlutils.c:2003
xml_string_append
void xml_string_append(GString *, const char *,...)
Append formatted escaped XML to a string.
Definition xmlutils.c:1849
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:1616
read_string_c
int read_string_c(gvm_connection_t *, GString **)
Read entity and text. Free the entity immediately.
Definition xmlutils.c:1420
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:1282