xmlutils.h
Go to the documentation of this file.
/* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef _GVM_XMLUTILS_H
#define _GVM_XMLUTILS_H
#include "serverutils.h"
#include <glib.h>
#include <gnutls/gnutls.h>
#include <stdio.h>
typedef struct
{
GSList *first;
GSList *current;
gboolean done;
} context_data_t;
void
xml_handle_start_element (context_data_t *, const gchar *, const gchar **,
const gchar **);
void
xml_handle_end_element (context_data_t *, const gchar *);
void
xml_handle_text (context_data_t *, const gchar *, gsize);
typedef GSList *entities_t;
struct entity_s
{
char *name;
char *text;
GHashTable *attributes;
entities_t entities;
};
typedef struct entity_s *entity_t;
typedef struct
{
int found;
int done;
gchar *find_element;
GHashTable *find_attributes;
} xml_search_data_t;
entities_t next_entities (entities_t);
entity_t first_entity (entities_t);
entity_t
add_entity (entities_t *, const char *, const char *);
int compare_entities (entity_t, entity_t);
entity_t
entity_child (entity_t, const char *);
const char *
entity_attribute (entity_t, const char *);
char *
entity_name (entity_t entity);
char *
entity_text (entity_t entity);
void free_entity (entity_t);
void
print_entity (FILE *, entity_t);
void
print_entity_format (entity_t, gpointer indentation);
int
try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **);
int
read_entity_and_string (gnutls_session_t *, entity_t *, GString **);
int
read_entity_and_string_c (gvm_connection_t *, entity_t *, GString **);
int
read_entity_and_text (gnutls_session_t *, entity_t *, char **);
int
read_entity_and_text_c (gvm_connection_t *, entity_t *, char **);
int
try_read_entity (gnutls_session_t *, int, entity_t *);
int
try_read_entity_c (gvm_connection_t *, int, entity_t *);
int
read_entity (gnutls_session_t *, entity_t *);
int
read_entity_s (int, entity_t *);
int
read_entity_c (gvm_connection_t *, entity_t *);
int
read_string (gnutls_session_t *, GString **);
int
read_string_c (gvm_connection_t *, GString **);
int
read_text_c (gvm_connection_t *, char **);
int
parse_entity (const char *, entity_t *);
void
print_entity_to_string (entity_t entity, GString *string);
int xml_count_entities (entities_t);
void
xml_string_append (GString *, const char *, ...);
/* XML file utilities */
int
find_element_in_xml_file (gchar *, gchar *, GHashTable *);
/* The new faster parser that uses libxml2. */
typedef struct _xmlNode *element_t;
int
parse_element (const gchar *, element_t *);
void element_free (element_t);
const gchar *element_name (element_t);
gchar *
element_attribute (element_t, const gchar *);
gchar *element_text (element_t);
element_t
element_child (element_t, const gchar *);
element_t element_first_child (element_t);
element_t element_next (element_t);
gchar *
element_to_string (element_t element);
void
print_element_to_string (element_t element, GString *string);
/* XML file iterator
* for reading subelements from large files without building the whole DOM
*/
typedef struct xml_file_iterator_struct *xml_file_iterator_t;
xml_file_iterator_t
xml_file_iterator_new (void);
int
xml_file_iterator_init_from_file_path (xml_file_iterator_t, const char *, int);
void xml_file_iterator_free (xml_file_iterator_t);
int xml_file_iterator_rewind (xml_file_iterator_t);
element_t
xml_file_iterator_next (xml_file_iterator_t, gchar **);
#endif /* not _GVM_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:2327
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:2990
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:2947
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:2048
xml_count_entities
int xml_count_entities(entities_t)
Count the number of entities.
Definition xmlutils.c:1826
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:1761
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:2133
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:2853
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:2276
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:1938
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:2870
element_next
element_t element_next(element_t)
Get the next sibling of an element.
Definition xmlutils.c:2226
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:2082
print_entity_format
void print_entity_format(entity_t, gpointer indentation)
Print an XML entity to stdout, recursively printing its children.
Definition xmlutils.c:1702
element_attribute
gchar * element_attribute(element_t, const gchar *)
Get an attribute of an element.
Definition xmlutils.c:2158
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:2249
print_entity
void print_entity(FILE *, entity_t)
Print an XML entity.
Definition xmlutils.c:1659
element_free
void element_free(element_t)
Free an entire element tree.
Definition xmlutils.c:2031
element_first_child
element_t element_first_child(element_t)
Get the first child of an element.
Definition xmlutils.c:2206
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:2912
parse_element
int parse_element(const gchar *, element_t *)
Read an XML element tree from a string.
Definition xmlutils.c:1999
xml_string_append
void xml_string_append(GString *, const char *,...)
Append formatted escaped XML to a string.
Definition xmlutils.c:1845
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:1612
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