Greenbone Vulnerability Management Libraries  21.4.2
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 
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 /* XML file utilities */
162 
163 int
164 find_element_in_xml_file (gchar *, gchar *, GHashTable *);
165 
166 /* The new faster parser that uses libxml2. */
167 
168 typedef struct _xmlNode *element_t;
169 
170 int
171 parse_element (const gchar *, element_t *);
172 
173 void element_free (element_t);
174 
175 const gchar *element_name (element_t);
176 
177 gchar *
178 element_attribute (element_t, const gchar *);
179 
180 gchar *element_text (element_t);
181 
182 element_t
183 element_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
int xml_count_entities(entities_t)
Count the number of entities.
Definition: xmlutils.c:1520
gchar * element_text(element_t)
Get text of an element.
Definition: xmlutils.c:1828
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
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
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
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xmlutils.c:159
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
gchar * element_attribute(element_t, const gchar *)
Get an attribute of an element.
Definition: xmlutils.c:1853
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
const gchar * element_name(element_t)
Get the name of an element.
Definition: xmlutils.c:1743
char * entity_name(entity_t entity)
Get the name an entity.
Definition: xmlutils.c:175
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
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
const char * entity_attribute(entity_t, const char *)
Get an attribute of an entity.
Definition: xmlutils.c:230
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