Greenbone Vulnerability Management Libraries  10.0.0
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 /* XML file utilities */
162 
163 int
164 find_element_in_xml_file (gchar *, gchar *, GHashTable *);
165 
166 #endif /* not _GVM_XMLUTILS_H */
int read_entity(gnutls_session_t *, entity_t *)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1057
struct entity_s * entity_t
Definition: xmlutils.h:72
void free_entity(entity_t)
Free an entity, recursively.
Definition: xmlutils.c:127
Data for xml search functions.
Definition: xmlutils.h:77
GHashTable * attributes
Attributes.
Definition: xmlutils.h:69
int try_read_entity(gnutls_session_t *, int, entity_t *)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1024
int read_entity_and_string(gnutls_session_t *, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:880
GSList * first
The very first entity.
Definition: xmlutils.h:42
int xml_count_entities(entities_t)
Count the number of entities.
Definition: xmlutils.c:1411
int read_entity_and_text(gnutls_session_t *, entity_t *, char **)
Read an XML entity tree from the manager.
Definition: xmlutils.c:923
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:311
int done
Definition: xmlutils.h:80
void print_entity_format(entity_t, gpointer indentation)
Print an XML entity to stdout, recursively printing its children.
Definition: xmlutils.c:1287
void xml_string_append(GString *, const char *,...)
Append formatted escaped XML to a string.
Definition: xmlutils.c:1432
GHashTable * find_attributes
Definition: xmlutils.h:82
XML element.
Definition: xmlutils.h:65
entities_t next_entities(entities_t)
Return all the entities from an entities_t after the first.
Definition: xmlutils.c:79
entities_t entities
Children.
Definition: xmlutils.h:70
GSList * current
The element currently being parsed.
Definition: xmlutils.h:43
entity_t add_entity(entities_t *, const char *, const char *)
Add an XML entity to a tree of entities.
Definition: xmlutils.c:113
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:442
int compare_entities(entity_t, entity_t)
Compare two XML entity.
Definition: xmlutils.c:1346
int read_entity_and_string_c(gvm_connection_t *, entity_t *, GString **)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:900
XML context.
Definition: xmlutils.h:40
gboolean done
Flag which is true when the first element is closed.
Definition: xmlutils.h:44
int try_read_entity_c(gvm_connection_t *, int, entity_t *)
Try read an XML entity tree from the manager.
Definition: xmlutils.c:1040
void xml_handle_end_element(context_data_t *, const gchar *)
Handle the end of an XML element.
Definition: xmlutils.c:364
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xmlutils.c:157
char * name
Name.
Definition: xmlutils.h:67
int read_string_c(gvm_connection_t *, GString **)
Read entity and text. Free the entity immediately.
Definition: xmlutils.c:1002
int read_entity_s(int, entity_t *)
Read an XML entity tree from the socket.
Definition: xmlutils.c:1071
const char * entity_attribute(entity_t, const char *)
Get an attribute of an entity.
Definition: xmlutils.c:228
int read_entity_and_text_c(gvm_connection_t *, entity_t *, char **)
Read an XML entity tree from the manager.
Definition: xmlutils.c:954
int read_entity_c(gvm_connection_t *, entity_t *)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1085
entity_t first_entity(entities_t)
Return the first entity from an entities_t.
Definition: xmlutils.c:94
Connection.
Definition: serverutils.h:43
int find_element_in_xml_file(gchar *, gchar *, GHashTable *)
Tests if an XML file contains an element with given attributes.
Definition: xmlutils.c:1525
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:1197
gchar * find_element
Definition: xmlutils.h:81
int found
Definition: xmlutils.h:79
void print_entity(FILE *, entity_t)
Print an XML entity.
Definition: xmlutils.c:1244
GSList * entities_t
Entities.
Definition: xmlutils.h:60
char * text
Text.
Definition: xmlutils.h:68
int read_string(gnutls_session_t *, GString **)
Read entity and text. Free the entity immediately.
Definition: xmlutils.c:982
int parse_entity(const char *, entity_t *)
Read an XML entity tree from a string.
Definition: xmlutils.c:1099
GnuTLS based functions for server communication - header file.
entity_t entity_child(entity_t, const char *)
Get a child of an entity.
Definition: xmlutils.c:205
char * entity_name(entity_t entity)
Get the name an entity.
Definition: xmlutils.c:173
void xml_handle_text(context_data_t *, const gchar *, gsize)
Handle additional text of an XML element.
Definition: xmlutils.c:406