Greenbone Vulnerability Management Libraries 21.4.4
xmlutils.h
Go to the documentation of this file.
1/* Copyright (C) 2009-2021 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
40typedef struct
41{
42 GSList *first;
43 GSList *current;
44 gboolean done;
46
47void
48xml_handle_start_element (context_data_t *, const gchar *, const gchar **,
49 const gchar **);
50
51void
52xml_handle_end_element (context_data_t *, const gchar *);
53
54void
55xml_handle_text (context_data_t *, const gchar *, gsize);
56
60typedef GSList *entities_t;
61
66{
67 char *name;
68 char *text;
69 GHashTable *attributes;
71};
72typedef struct entity_s *entity_t;
73
77typedef struct
78{
79 int found;
80 int done;
81 gchar *find_element;
82 GHashTable *find_attributes;
84
86
88
90add_entity (entities_t *, const char *, const char *);
91
93
95entity_child (entity_t, const char *);
96
97const char *
98entity_attribute (entity_t, const char *);
99
100char *
101entity_name (entity_t entity);
102
103char *
104entity_text (entity_t entity);
105
106void free_entity (entity_t);
107
108void
109print_entity (FILE *, entity_t);
110
111void
112print_entity_format (entity_t, gpointer indentation);
113
114int
115try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **);
116
117int
118read_entity_and_string (gnutls_session_t *, entity_t *, GString **);
119
120int
122
123int
124read_entity_and_text (gnutls_session_t *, entity_t *, char **);
125
126int
128
129int
130try_read_entity (gnutls_session_t *, int, entity_t *);
131
132int
134
135int
136read_entity (gnutls_session_t *, entity_t *);
137
138int
139read_entity_s (int, entity_t *);
140
141int
143
144int
145read_string (gnutls_session_t *, GString **);
146
147int
148read_string_c (gvm_connection_t *, GString **);
149
150int
151parse_entity (const char *, entity_t *);
152
153void
154print_entity_to_string (entity_t entity, GString *string);
155
157
158void
159xml_string_append (GString *, const char *, ...);
160
161/* XML file utilities */
162
163int
164find_element_in_xml_file (gchar *, gchar *, GHashTable *);
165
166/* The new faster parser that uses libxml2. */
167
168typedef struct _xmlNode *element_t;
169
170int
171parse_element (const gchar *, element_t *);
172
174
175const gchar *element_name (element_t);
176
177gchar *
178element_attribute (element_t, const gchar *);
179
180gchar *element_text (element_t);
181
183element_child (element_t, const gchar *);
184
186
188
189#endif /* not _GVM_XMLUTILS_H */
GnuTLS based functions for server communication - header file.
XML context.
Definition: xmlutils.h:41
GSList * first
The very first entity.
Definition: xmlutils.h:42
GSList * current
The element currently being parsed.
Definition: xmlutils.h:43
gboolean done
Flag which is true when the first element is closed.
Definition: xmlutils.h:44
XML element.
Definition: xmlutils.h:66
entities_t entities
Children.
Definition: xmlutils.h:70
char * text
Text.
Definition: xmlutils.h:68
GHashTable * attributes
Attributes.
Definition: xmlutils.h:69
char * name
Name.
Definition: xmlutils.h:67
Connection.
Definition: serverutils.h:44
Data for xml search functions.
Definition: xmlutils.h:78
int done
Definition: xmlutils.h:80
gchar * find_element
Definition: xmlutils.h:81
GHashTable * find_attributes
Definition: xmlutils.h:82
int found
Definition: xmlutils.h:79
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
struct entity_s * entity_t
Definition: xmlutils.h:72
int try_read_entity(gnutls_session_t *, int, entity_t *)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1130
const gchar * element_name(element_t)
Get the name of an element.
Definition: xmlutils.c:1743
int xml_count_entities(entities_t)
Count the number of entities.
Definition: xmlutils.c:1520
char * entity_name(entity_t entity)
Get the name an entity.
Definition: xmlutils.c:175
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xmlutils.c:159
int compare_entities(entity_t, entity_t)
Compare two XML entity.
Definition: xmlutils.c:1455
int parse_entity(const char *, entity_t *)
Read an XML entity tree from a string.
Definition: xmlutils.c:1205
gchar * element_text(element_t)
Get text of an element.
Definition: xmlutils.c:1828
entities_t next_entities(entities_t)
Return all the entities from an entities_t after the first.
Definition: xmlutils.c:81
int read_entity_and_text_c(gvm_connection_t *, entity_t *, char **)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1066
int read_entity_s(int, entity_t *)
Read an XML entity tree from the socket.
Definition: xmlutils.c:1177
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
const char * entity_attribute(entity_t, const char *)
Get an attribute of an entity.
Definition: xmlutils.c:230
struct _xmlNode * element_t
Definition: xmlutils.h:168
int try_read_entity_c(gvm_connection_t *, int, entity_t *)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1146
int find_element_in_xml_file(gchar *, gchar *, GHashTable *)
Tests if an XML file contains an element with given attributes.
Definition: xmlutils.c:1634
int read_string(gnutls_session_t *, GString **)
Read entity and text. Free the entity immediately.
Definition: xmlutils.c:1094
int read_entity(gnutls_session_t *, entity_t *)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1163
element_t element_next(element_t)
Get the next sibling of an element.
Definition: xmlutils.c:1916
void xml_handle_end_element(context_data_t *, const gchar *)
Handle the end of an XML element.
Definition: xmlutils.c:416
entity_t entity_child(entity_t, const char *)
Get a child of an entity.
Definition: xmlutils.c:207
int read_entity_c(gvm_connection_t *, entity_t *)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1191
int read_entity_and_string(gnutls_session_t *, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:992
GSList * entities_t
Entities.
Definition: xmlutils.h:60
element_t element_child(element_t, const gchar *)
Get a child of an element.
Definition: xmlutils.c:1777
void print_entity_format(entity_t, gpointer indentation)
Print an XML entity to stdout, recursively printing its children.
Definition: xmlutils.c:1396
gchar * element_attribute(element_t, const gchar *)
Get an attribute of an element.
Definition: xmlutils.c:1853
void xml_handle_text(context_data_t *, const gchar *, gsize)
Handle additional text of an XML element.
Definition: xmlutils.c:478
int read_entity_and_text(gnutls_session_t *, entity_t *, char **)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1035
entity_t first_entity(entities_t)
Return the first entity from an entities_t.
Definition: xmlutils.c:96
void print_entity(FILE *, entity_t)
Print an XML entity.
Definition: xmlutils.c:1353
void element_free(element_t)
Free an entire element tree.
Definition: xmlutils.c:1726
element_t element_first_child(element_t)
Get the first child of an element.
Definition: xmlutils.c:1901
void free_entity(entity_t)
Free an entity, recursively.
Definition: xmlutils.c:129
entity_t add_entity(entities_t *, const char *, const char *)
Add an XML entity to a tree of entities.
Definition: xmlutils.c:115
int parse_element(const gchar *, element_t *)
Read an XML element tree from a string.
Definition: xmlutils.c:1695
void xml_string_append(GString *, const char *,...)
Append formatted escaped XML to a string.
Definition: xmlutils.c:1541
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:1306
int read_string_c(gvm_connection_t *, GString **)
Read entity and text. Free the entity immediately.
Definition: xmlutils.c:1114
int read_entity_and_string_c(gvm_connection_t *, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1012