Greenbone Vulnerability Management Libraries 22.12.2
xmlutils.c File Reference

Simple XML reader. More...

#include "xmlutils.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <glib/gtypes.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  xml_file_iterator_struct
 Opaque data structure for XML file iterator. More...
 

Macros

#define G_LOG_DOMAIN   "libgvm util"
 GLib logging domain.
 
#define BUFFER_SIZE   1048576
 Size of the buffer for reading from the manager.
 
#define XML_FILE_BUFFER_SIZE   1048576
 
#define XML_FILE_ITERATOR_BUFFER_SIZE   8192
 File read buffer size for an XML file iterator.
 

Functions

static entity_t make_entity (const char *name, const char *text)
 Create an entity.
 
entities_t next_entities (entities_t entities)
 Return all the entities from an entities_t after the first.
 
entity_t first_entity (entities_t entities)
 Return the first entity from an entities_t.
 
entity_t add_entity (entities_t *entities, const char *name, const char *text)
 Add an XML entity to a tree of entities.
 
void free_entity (entity_t entity)
 Free an entity, recursively.
 
char * entity_text (entity_t entity)
 Get the text an entity.
 
char * entity_name (entity_t entity)
 Get the name an entity.
 
static int compare_entity_with_name (gconstpointer entity, gconstpointer name)
 Compare a given name with the name of a given entity.
 
entity_t entity_child (entity_t entity, const char *name)
 Get a child of an entity.
 
const char * entity_attribute (entity_t entity, const char *name)
 Get an attribute of an entity.
 
static void add_attributes (entity_t entity, const gchar **names, const gchar **values)
 Add attributes from an XML callback to an entity.
 
static void ignore_start_element (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error)
 Handle the start of an OMP XML element.
 
static void handle_start_element (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error)
 Handle the start of an OMP XML element.
 
void xml_handle_start_element (context_data_t *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values)
 Handle the start of an OMP XML element.
 
static void ignore_end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)
 Handle the end of an XML element.
 
static void handle_end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)
 Handle the end of an XML element.
 
void xml_handle_end_element (context_data_t *context, const gchar *element_name)
 Handle the end of an XML element.
 
static void ignore_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
 Handle additional text of an XML element.
 
static void handle_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
 Handle additional text of an XML element.
 
void xml_handle_text (context_data_t *context, const gchar *text, gsize text_len)
 Handle additional text of an XML element.
 
static void handle_error (GMarkupParseContext *context, GError *error, gpointer user_data)
 Handle an OMP XML parsing error.
 
int try_read_entity_and_string (gnutls_session_t *session, int timeout, entity_t *entity, GString **string_return)
 Try read an XML entity tree from the manager.
 
static int try_read_string (gnutls_session_t *session, int timeout, GString **string_return)
 Try read a response from a TLS session.
 
static int try_read_string_s (int socket, int timeout, GString **string_return)
 Try read an XML entity tree from the socket.
 
static int try_read_entity_and_string_s (int socket, int timeout, entity_t *entity, GString **string_return)
 Try read an XML entity tree from the socket.
 
int read_entity_and_string (gnutls_session_t *session, entity_t *entity, GString **string_return)
 Try read an XML entity tree from the manager.
 
int read_entity_and_string_c (gvm_connection_t *connection, entity_t *entity, GString **string_return)
 Try read an XML entity tree from the manager.
 
int read_entity_and_text (gnutls_session_t *session, entity_t *entity, char **text)
 Read an XML entity tree from the manager.
 
int read_entity_and_text_c (gvm_connection_t *connection, entity_t *entity, char **text)
 Read an XML entity tree from the manager.
 
int read_text_c (gvm_connection_t *connection, char **text)
 Read text from the server.
 
int read_string (gnutls_session_t *session, GString **string)
 Read entity and text. Free the entity immediately.
 
int read_string_c (gvm_connection_t *connection, GString **string)
 Read entity and text. Free the entity immediately.
 
int try_read_entity (gnutls_session_t *session, int timeout, entity_t *entity)
 Try read an XML entity tree from the manager.
 
int try_read_entity_c (gvm_connection_t *connection, int timeout, entity_t *entity)
 Try read an XML entity tree from the manager.
 
int read_entity (gnutls_session_t *session, entity_t *entity)
 Read an XML entity tree from the manager.
 
int read_entity_s (int socket, entity_t *entity)
 Read an XML entity tree from the socket.
 
int read_entity_c (gvm_connection_t *connection, entity_t *entity)
 Read an XML entity tree from the manager.
 
int parse_entity (const char *string, entity_t *entity)
 Read an XML entity tree from a string.
 
static void foreach_print_entity_to_string (gpointer entity, gpointer string)
 Print an XML entity for g_slist_foreach to a GString.
 
static void foreach_print_attribute_to_string (gpointer name, gpointer value, gpointer string)
 Print an XML attribute for g_hash_table_foreach to a GString.
 
void print_entity_to_string (entity_t entity, GString *string)
 Print an XML entity tree to a GString, appending it if string is not.
 
static void foreach_print_entity (gpointer entity, gpointer stream)
 Print an XML entity for g_slist_foreach.
 
static void foreach_print_attribute (gpointer name, gpointer value, gpointer stream)
 Print an XML attribute for g_hash_table_foreach.
 
void print_entity (FILE *stream, entity_t entity)
 Print an XML entity.
 
static void foreach_print_attribute_format (gpointer name, gpointer value, gpointer none)
 Print an XML attribute for g_hash_table_foreach to stdout.
 
void print_entity_format (entity_t entity, gpointer indent)
 Print an XML entity to stdout, recursively printing its children.
 
static gboolean compare_find_attribute (gpointer key, gpointer value, gpointer attributes2)
 Look for a key-value pair in a hash table.
 
int compare_entities (entity_t entity1, entity_t entity2)
 Compare two XML entity.
 
int xml_count_entities (entities_t entities)
 Count the number of entities.
 
void xml_string_append (GString *xml, const char *format,...)
 Append formatted escaped XML to a string.
 
static void xml_search_handle_start_element (GMarkupParseContext *ctx, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error)
 Handle the opening tag of an element in an XML search.
 
int find_element_in_xml_file (gchar *file_path, gchar *find_element, GHashTable *find_attributes)
 Tests if an XML file contains an element with given attributes.
 
int parse_element (const gchar *string, element_t *element)
 Read an XML element tree from a string.
 
void element_free (element_t element)
 Free an entire element tree.
 
const gchar * element_name (element_t element)
 Get the name of an element.
 
static element_t find_child (element_t element, const gchar *name)
 Find child in an element.
 
element_t element_child (element_t element, const gchar *name)
 Get a child of an element.
 
gchar * element_text (element_t element)
 Get text of an element.
 
gchar * element_attribute (element_t element, const gchar *name)
 Get an attribute of an element.
 
element_t element_first_child (element_t element)
 Get the first child of an element.
 
element_t element_next (element_t element)
 Get the next sibling of an element.
 
gchar * element_to_string (element_t element)
 Output the XML element as a 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.
 
static void xml_file_iterator_start_element_ns (void *ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, int nb_attributes, int nb_defaulted, const xmlChar **attributes)
 XML file iterator parser callback for element start.
 
static void xml_file_iterator_end_element_ns (void *ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI)
 XML file iterator parser callback for element end.
 
static void xml_file_iterator_internal_subset (void *ctx, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID)
 XML file iterator parser callback for internal subset declaration.
 
static void xml_file_iterator_external_subset (void *ctx, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID)
 XML file iterator parser callback for external subset declaration.
 
static int xml_file_iterator_is_standalone (void *ctx)
 XML file iterator parser callback for checking if doc is standalone.
 
static int xml_file_iterator_has_internal_subset (void *ctx)
 XML file iterator parser callback for checking if doc has an internal subset.
 
static int xml_file_iterator_has_external_subset (void *ctx)
 XML file iterator parser callback for checking if doc has an external subset.
 
static xmlParserInputPtr xml_file_iterator_resolve_entity (void *ctx, const xmlChar *publicId, const xmlChar *systemId)
 XML file iterator parser callback for resolving an entity.
 
static xmlEntityPtr xml_file_iterator_get_entity (void *ctx, const xmlChar *name)
 XML file iterator parser callback for getting an entity by name.
 
static xmlEntityPtr xml_file_iterator_get_parameter_entity (void *ctx, const xmlChar *name)
 XML file iterator parser callback for getting a parameter entity by name.
 
static void xml_file_iterator_entity_decl (void *ctx, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
 XML file iterator parser callback for when an entity definition has been parsed.
 
static void xml_file_iterator_attribute_decl (void *ctx, const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree)
 XML file iterator parser callback for when an attribute definition has been parsed.
 
static void xml_file_iterator_element_decl (void *ctx, const xmlChar *name, int type, xmlElementContentPtr content)
 XML file iterator parser callback for when an element definition has been parsed.
 
static void xml_file_iterator_notation_decl (void *ctx, const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId)
 XML file iterator parser callback for when a notation definition has been parsed.
 
static void xml_file_iterator_unparsed_entity_decl (void *ctx, const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName)
 XML file iterator parser callback for when an unparsed entity declaration has been parsed.
 
static void xml_file_iterator_set_document_locator (void *ctx, xmlSAXLocatorPtr loc)
 XML file iterator parser callback for setting the document locator.
 
static void xml_file_iterator_start_document (void *ctx)
 XML file iterator parser callback at the document start.
 
static void xml_file_iterator_end_document (void *ctx)
 XML file iterator parser callback at the document end.
 
static void xml_file_iterator_characters (void *ctx, const xmlChar *ch, int len)
 XML file iterator parser callback when receiving some chars from the parser.
 
static void xml_file_iterator_cdata_block (void *ctx, const xmlChar *ch, int len)
 XML file iterator parser callback when a cdata block has been parsed.
 
static void xml_file_iterator_processing_instruction (void *ctx, const xmlChar *target, const xmlChar *data)
 XML file iterator parser callback when a processing instruction has been parsed.
 
static void xml_file_iterator_comment (void *ctx, const xmlChar *value)
 XML file iterator parser callback when a comment has been parsed.
 
static void xml_file_iterator_init_sax_handler (xmlSAXHandlerPtr hdlr)
 Initializes a xmlSAXHandler data structure for SAX version 2 parsing, assigning all the XML file iterator callback functions.
 
xml_file_iterator_t xml_file_iterator_new (void)
 Allocates a new, uninitialized XML file iterator.
 
int xml_file_iterator_init_from_file_path (xml_file_iterator_t iterator, const char *file_path, int output_depth)
 Initializes an XML file iterator to read from a given path.
 
void xml_file_iterator_free (xml_file_iterator_t iterator)
 Frees an XML file iterator and all of its internal data structures.
 
int xml_file_iterator_rewind (xml_file_iterator_t iterator)
 Rewinds an XML file iterator by rewinding the file and creating a new XML parser context.
 
element_t xml_file_iterator_next (xml_file_iterator_t iterator, gchar **error)
 Get the next subelement from a XML file iterator.
 

Detailed Description

Simple XML reader.

This is a generic XML interface. The key function is read_entity.

There are examples of using this interface in omp.c.

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   1048576

Size of the buffer for reading from the manager.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "libgvm util"

GLib logging domain.

◆ XML_FILE_BUFFER_SIZE

#define XML_FILE_BUFFER_SIZE   1048576

◆ XML_FILE_ITERATOR_BUFFER_SIZE

#define XML_FILE_ITERATOR_BUFFER_SIZE   8192

File read buffer size for an XML file iterator.

Function Documentation

◆ add_attributes()

static void add_attributes ( entity_t entity,
const gchar ** names,
const gchar ** values )
static

Add attributes from an XML callback to an entity.

Parameters
[in]entityThe entity.
[in]namesList of attribute names.
[in]valuesList of attribute values.

◆ add_entity()

entity_t add_entity ( entities_t * entities,
const char * name,
const char * text )

Add an XML entity to a tree of entities.

Parameters
[in]entitiesThe tree of entities
[in]nameName of the entity. Copied, copy is freed by free_entity.
[in]textText of the entity. Copied, copy is freed by free_entity.
Returns
The new entity.

◆ compare_entities()

int compare_entities ( entity_t entity1,
entity_t entity2 )

Compare two XML entity.

Parameters
[in]entity1First entity.
[in]entity2First entity.
Returns
0 if equal, 1 otherwise.

◆ compare_entity_with_name()

static int compare_entity_with_name ( gconstpointer entity,
gconstpointer name )
static

Compare a given name with the name of a given entity.

Parameters
[in]entityEntity.
[in]nameName.
Returns
Zero if entity name matches name, otherwise a positive or negative number as from strcmp.

◆ compare_find_attribute()

static gboolean compare_find_attribute ( gpointer key,
gpointer value,
gpointer attributes2 )
static

Look for a key-value pair in a hash table.

Parameters
[in]keyKey.
[in]valueValue.
[in]attributes2The hash table.
Returns
FALSE if found, TRUE otherwise.

◆ element_attribute()

gchar * element_attribute ( element_t element,
const gchar * name )

Get an attribute of an element.

Parameters
[in]elementElement.
[in]nameName of the attribute.
Returns
Attribute value if found, else NULL. Caller must g_free.

◆ element_child()

element_t element_child ( element_t element,
const gchar * name )

Get a child of an element.

Parameters
[in]elementElement.
[in]nameName of the child.
Returns
Element if found, else NULL.

◆ element_first_child()

element_t element_first_child ( element_t element)

Get the first child of an element.

Parameters
[in]elementElement.
Returns
Child if there is one, else NULL.

◆ element_free()

void element_free ( element_t element)

Free an entire element tree.

Beware that this frees the entire tree that element is part of, including any ancestors.

Parameters
[in]elementElement.

◆ element_name()

const gchar * element_name ( element_t element)

Get the name of an element.

Parameters
[in]elementElement.
Returns
Element name.

◆ element_next()

element_t element_next ( element_t element)

Get the next sibling of an element.

Parameters
[in]elementElement.
Returns
Next sibling element if there is one, else NULL.

◆ element_text()

gchar * element_text ( element_t element)

Get text of an element.

If element is not NULL then the return is guaranteed to be a string. So if the caller has NULL checked element then there is no need for the caller to NULL check the return.

Parameters
[in]elementElement.
Returns
NULL if element is NULL, else the text. Caller must g_free.

◆ element_to_string()

gchar * element_to_string ( element_t element)

Output the XML element as a string.

The generated XML string will include namespace definitions from ancestor elements.

Parameters
[in]elementThe element to output as a string.
Returns
The newly allocated XML string.

◆ entity_attribute()

const char * entity_attribute ( entity_t entity,
const char * name )

Get an attribute of an entity.

Parameters
[in]entityEntity.
[in]nameName of the attribute.
Returns
Attribute if found, else NULL.

◆ entity_child()

entity_t entity_child ( entity_t entity,
const char * name )

Get a child of an entity.

Parameters
[in]entityEntity.
[in]nameName of the child.
Returns
Entity if found, else NULL.

◆ entity_name()

char * entity_name ( entity_t entity)

Get the name an entity.

Parameters
[in]entityEntity.
Returns
Entity name, which is freed by free_entity.

◆ entity_text()

char * entity_text ( entity_t entity)

Get the text an entity.

Parameters
[in]entityEntity.
Returns
Entity text, which is freed by free_entity.

◆ find_child()

static element_t find_child ( element_t element,
const gchar * name )
static

Find child in an element.

Parameters
[in]elementElement.
[in]nameName of child.
Returns
Child if found, else NULL.

◆ find_element_in_xml_file()

int find_element_in_xml_file ( gchar * file_path,
gchar * find_element,
GHashTable * find_attributes )

Tests if an XML file contains an element with given attributes.

Parameters
[in]file_pathPath of the XML file.
[in]find_elementName of the element to find.
[in]find_attributesGHashTable of attributes to find.
Returns
1 if element was found, 0 if not.

◆ first_entity()

entity_t first_entity ( entities_t entities)

Return the first entity from an entities_t.

Parameters
[in]entitiesThe list of entities.
Returns
The first entity.

◆ foreach_print_attribute()

static void foreach_print_attribute ( gpointer name,
gpointer value,
gpointer stream )
static

Print an XML attribute for g_hash_table_foreach.

Parameters
[in]nameThe attribute name.
[in]valueThe attribute value.
[in]streamThe stream to which to print.

◆ foreach_print_attribute_format()

static void foreach_print_attribute_format ( gpointer name,
gpointer value,
gpointer none )
static

Print an XML attribute for g_hash_table_foreach to stdout.

Parameters
[in]nameThe attribute name.
[in]valueThe attribute value.
[in]none(ignored).

◆ foreach_print_attribute_to_string()

static void foreach_print_attribute_to_string ( gpointer name,
gpointer value,
gpointer string )
static

Print an XML attribute for g_hash_table_foreach to a GString.

Parameters
[in]nameThe attribute name.
[in]valueThe attribute value.
[in]stringThe string to which to print.

◆ foreach_print_entity()

static void foreach_print_entity ( gpointer entity,
gpointer stream )
static

Print an XML entity for g_slist_foreach.

Parameters
[in]entityThe entity, as a gpointer.
[in]streamThe stream to which to print, as a gpointer.

◆ foreach_print_entity_to_string()

static void foreach_print_entity_to_string ( gpointer entity,
gpointer string )
static

Print an XML entity for g_slist_foreach to a GString.

Parameters
[in]entityThe entity, as a gpointer.
[in]stringThe stream to which to print, as a gpointer.

◆ free_entity()

void free_entity ( entity_t entity)

Free an entity, recursively.

Parameters
[in]entityThe entity, can be NULL.

◆ handle_end_element()

static void handle_end_element ( GMarkupParseContext * context,
const gchar * element_name,
gpointer user_data,
GError ** error )
static

Handle the end of an XML element.

Parameters
[in]contextParser context.
[in]element_nameXML element name.
[in]user_dataDummy parameter.
[in]errorError parameter.

◆ handle_error()

static void handle_error ( GMarkupParseContext * context,
GError * error,
gpointer user_data )
static

Handle an OMP XML parsing error.

Parameters
[in]contextParser context.
[in]errorThe error.
[in]user_dataDummy parameter.

◆ handle_start_element()

static void handle_start_element ( GMarkupParseContext * context,
const gchar * element_name,
const gchar ** attribute_names,
const gchar ** attribute_values,
gpointer user_data,
GError ** error )
static

Handle the start of an OMP XML element.

Parameters
[in]contextParser context.
[in]element_nameXML element name.
[in]attribute_namesXML attribute name.
[in]attribute_valuesXML attribute values.
[in]user_dataDummy parameter.
[in]errorError parameter.

◆ handle_text()

static void handle_text ( GMarkupParseContext * context,
const gchar * text,
gsize text_len,
gpointer user_data,
GError ** error )
static

Handle additional text of an XML element.

Parameters
[in]contextParser context.
[in]textThe text.
[in]text_lenLength of the text.
[in]user_dataDummy parameter.
[in]errorError parameter.

◆ ignore_end_element()

static void ignore_end_element ( GMarkupParseContext * context,
const gchar * element_name,
gpointer user_data,
GError ** error )
static

Handle the end of an XML element.

Parameters
[in]contextParser context.
[in]element_nameXML element name.
[in]user_dataDummy parameter.
[in]errorError parameter.

◆ ignore_start_element()

static void ignore_start_element ( GMarkupParseContext * context,
const gchar * element_name,
const gchar ** attribute_names,
const gchar ** attribute_values,
gpointer user_data,
GError ** error )
static

Handle the start of an OMP XML element.

Parameters
[in]contextParser context.
[in]element_nameXML element name.
[in]attribute_namesXML attribute name.
[in]attribute_valuesXML attribute values.
[in]user_dataDummy parameter.
[in]errorError parameter.

◆ ignore_text()

static void ignore_text ( GMarkupParseContext * context,
const gchar * text,
gsize text_len,
gpointer user_data,
GError ** error )
static

Handle additional text of an XML element.

Parameters
[in]contextParser context.
[in]textThe text.
[in]text_lenLength of the text.
[in]user_dataDummy parameter.
[in]errorError parameter.

◆ make_entity()

static entity_t make_entity ( const char * name,
const char * text )
static

Create an entity.

Parameters
[in]nameName of the entity. Copied, freed by free_entity.
[in]textText of the entity. Copied, freed by free_entity.
Returns
A newly allocated entity.

◆ next_entities()

entities_t next_entities ( entities_t entities)

Return all the entities from an entities_t after the first.

Parameters
[in]entitiesThe list of entities.
Returns
All the entities that follow the first.

◆ parse_element()

int parse_element ( const gchar * string,
element_t * element )

Read an XML element tree from a string.

Caller must not free string until caller is finished using element.

Parameters
[in]stringInput string.
[out]elementLocation for parsed element tree, or NULL if not required. If given, set to NULL on failure. Free with element_free.
Returns
0 success, -1 read error, -2 parse error, -3 XML ended prematurely, -4 setup error.

◆ parse_entity()

int parse_entity ( const char * string,
entity_t * entity )

Read an XML entity tree from a string.

Parameters
[in]stringInput string.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 XML ended prematurely.

◆ 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.

empty.

Parameters
[in]elementElement tree to print to string.
[in,out]stringString to write to.

◆ print_entity()

void print_entity ( FILE * stream,
entity_t entity )

Print an XML entity.

Parameters
[in]entityThe entity.
[in]streamThe stream to which to print.

◆ print_entity_format()

void print_entity_format ( entity_t entity,
gpointer indent )

Print an XML entity to stdout, recursively printing its children.

Does very basic indentation for pretty printing.

This function is used as the (callback) GFunc in g_slist_foreach.

Parameters
[in]entityThe entity.
[in]indentIndentation level, indentation width is 2 spaces. Use GINT_TO_POINTER to convert a integer value when passing this parameter.

◆ 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.

empty.

Parameters
[in]entityEntity tree to print to string.
[in,out]stringString to write to.

◆ read_entity()

int read_entity ( gnutls_session_t * session,
entity_t * entity )

Read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_string()

int read_entity_and_string ( gnutls_session_t * session,
entity_t * entity,
GString ** string_return )

Try read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
[out]string_returnAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_string_c()

int read_entity_and_string_c ( gvm_connection_t * connection,
entity_t * entity,
GString ** string_return )

Try read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[out]entityPointer to an entity tree.
[out]string_returnAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_text()

int read_entity_and_text ( gnutls_session_t * session,
entity_t * entity,
char ** text )

Read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
[out]textA pointer to a pointer, at which to store the address of a newly allocated string holding the text read from the session, if the text is required, else NULL.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_text_c()

int read_entity_and_text_c ( gvm_connection_t * connection,
entity_t * entity,
char ** text )

Read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[out]entityEntity tree.
[out]textA pointer to a pointer, at which to store the address of a newly allocated string holding the text read from the session, if the text is required, else NULL.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_c()

int read_entity_c ( gvm_connection_t * connection,
entity_t * entity )

Read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_s()

int read_entity_s ( int socket,
entity_t * entity )

Read an XML entity tree from the socket.

Parameters
[in]socketSocket to read from.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_string()

int read_string ( gnutls_session_t * session,
GString ** string )

Read entity and text. Free the entity immediately.

Parameters
[in]sessionPointer to GNUTLS session to read from.
[out]stringReturn location for the string.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_string_c()

int read_string_c ( gvm_connection_t * connection,
GString ** string )

Read entity and text. Free the entity immediately.

Parameters
[in]connectionConnection.
[out]stringReturn location for the string.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_text_c()

int read_text_c ( gvm_connection_t * connection,
char ** text )

Read text from the server.

Parameters
[in]connectionConnection.
[out]textA pointer to a pointer, at which to store the address of a newly allocated string holding the text read from the session.
Returns
0 success, -1 read error, -2 argument error.

◆ try_read_entity()

int try_read_entity ( gnutls_session_t * session,
int timeout,
entity_t * entity )

Try read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout.

◆ try_read_entity_and_string()

int try_read_entity_and_string ( gnutls_session_t * session,
int timeout,
entity_t * entity,
GString ** string_return )

Try read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
[out]string_returnAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout, -5 null buffer.

◆ try_read_entity_and_string_s()

static int try_read_entity_and_string_s ( int socket,
int timeout,
entity_t * entity,
GString ** string_return )
static

Try read an XML entity tree from the socket.

Parameters
[in]socketSocket to read from.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
[out]string_returnAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout, -5 null buffer.

◆ try_read_entity_c()

int try_read_entity_c ( gvm_connection_t * connection,
int timeout,
entity_t * entity )

Try read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout.

◆ try_read_string()

static int try_read_string ( gnutls_session_t * session,
int timeout,
GString ** string_return )
static

Try read a response from a TLS session.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]string_returnAn optional return location for the text read from the session.

If string_return is NULL then it simply remains NULL. If it is pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it must point to an existing GString onto which the text is appended.

Returns
0 success, -1 read error, -4 timeout, -5 null buffer.

◆ try_read_string_s()

static int try_read_string_s ( int socket,
int timeout,
GString ** string_return )
static

Try read an XML entity tree from the socket.

Parameters
[in]socketSocket to read from.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]string_returnAn optional return location for the text read from the socket. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout, -5 null buffer.

◆ xml_count_entities()

int xml_count_entities ( entities_t entities)

Count the number of entities.

Parameters
[in]entitiesEntities.
Returns
Number of entities.

◆ xml_file_iterator_attribute_decl()

static void xml_file_iterator_attribute_decl ( void * ctx,
const xmlChar * elem,
const xmlChar * fullname,
int type,
int def,
const xmlChar * defaultValue,
xmlEnumerationPtr tree )
static

XML file iterator parser callback for when an attribute definition has been parsed.

This is just a wrapper for the libXML xmlSAX2AttributeDecl getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]namethe name of the element
[in]fullnamethe attribute name
[in]typethe attribute type
[in]defthe type of default value
[in]defaultValuethe attribute default value
[in]treethe tree of enumerated value set

◆ xml_file_iterator_cdata_block()

static void xml_file_iterator_cdata_block ( void * ctx,
const xmlChar * ch,
int len )
static

XML file iterator parser callback when a cdata block has been parsed.

This is just a wrapper for the libXML xmlSAX2CDataBlock getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]chThe cdata content
[in]lenthe block length

◆ xml_file_iterator_characters()

static void xml_file_iterator_characters ( void * ctx,
const xmlChar * ch,
int len )
static

XML file iterator parser callback when receiving some chars from the parser.

This is just a wrapper for the libXML xmlSAX2Characters getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]cha xmlChar string
[in]lenthe number of xmlChar

◆ xml_file_iterator_comment()

static void xml_file_iterator_comment ( void * ctx,
const xmlChar * value )
static

XML file iterator parser callback when a comment has been parsed.

This is just a wrapper for the libXML xmlSAX2Comment getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]valuethe comment content

◆ xml_file_iterator_element_decl()

static void xml_file_iterator_element_decl ( void * ctx,
const xmlChar * name,
int type,
xmlElementContentPtr content )
static

XML file iterator parser callback for when an element definition has been parsed.

This is just a wrapper for the libXML xmlSAX2ElementDecl getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]namethe element name
[in]typethe element type
[in]defthe type of default value
[in]defaultValuethe attribute default value
[in]contentthe element value tree

◆ xml_file_iterator_end_document()

static void xml_file_iterator_end_document ( void * ctx)
static

XML file iterator parser callback at the document end.

This is just a wrapper for the libXML xmlSAX2EndDocument getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure

◆ xml_file_iterator_end_element_ns()

static void xml_file_iterator_end_element_ns ( void * ctx,
const xmlChar * localname,
const xmlChar * prefix,
const xmlChar * URI )
static

XML file iterator parser callback for element end.

This uses xmlSAX2EndElementNs to finish parsing the element to the document in the libXML parser context of the iterator. If the element is at the output tree depth defined in the iterator then it is removed from the document and added to the element queue of the iterator.

Parameters
[in]ctxparser context data / iterator data structure
[in]localnamethe local name of the element
[in]prefixthe element namespace prefix if available
[in]URIthe element namespace name if available

◆ xml_file_iterator_entity_decl()

static void xml_file_iterator_entity_decl ( void * ctx,
const xmlChar * name,
int type,
const xmlChar * publicId,
const xmlChar * systemId,
xmlChar * content )
static

XML file iterator parser callback for when an entity definition has been parsed.

This is just a wrapper for the libXML xmlSAX2EntityDecl getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]namethe entity name
[in]typethe entity type
[in]publicIdThe public ID of the entity
[in]systemIdThe system ID of the entity
[in]contentthe entity value (without processing)

◆ xml_file_iterator_external_subset()

static void xml_file_iterator_external_subset ( void * ctx,
const xmlChar * name,
const xmlChar * ExternalID,
const xmlChar * SystemID )
static

XML file iterator parser callback for external subset declaration.

This is just a wrapper for the libXML xmlSAX2ExternalSubset getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]namethe root element name
[in]ExternalIDthe external ID
[in]SystemIDthe SYSTEM ID (e.g. filename or URL)

◆ xml_file_iterator_free()

void xml_file_iterator_free ( xml_file_iterator_t iterator)

Frees an XML file iterator and all of its internal data structures.

Parameters
[in]iteratorThe XML file iterator to free.

◆ xml_file_iterator_get_entity()

static xmlEntityPtr xml_file_iterator_get_entity ( void * ctx,
const xmlChar * name )
static

XML file iterator parser callback for getting an entity by name.

This is just a wrapper for the libXML xmlSAX2GetEntity getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]nameThe entity name
Returns
the xmlEntityPtr if found

◆ xml_file_iterator_get_parameter_entity()

static xmlEntityPtr xml_file_iterator_get_parameter_entity ( void * ctx,
const xmlChar * name )
static

XML file iterator parser callback for getting a parameter entity by name.

This is just a wrapper for the libXML xmlSAX2GetParameterEntity getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]nameThe entity name
Returns
the xmlEntityPtr if found

◆ xml_file_iterator_has_external_subset()

static int xml_file_iterator_has_external_subset ( void * ctx)
static

XML file iterator parser callback for checking if doc has an external subset.

This is just a wrapper for the libXML xmlSAX2HasExternalSubset getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
Returns
1 if true

◆ xml_file_iterator_has_internal_subset()

static int xml_file_iterator_has_internal_subset ( void * ctx)
static

XML file iterator parser callback for checking if doc has an internal subset.

This is just a wrapper for the libXML xmlSAX2HasInternalSubset getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
Returns
1 if true

◆ xml_file_iterator_init_from_file_path()

int xml_file_iterator_init_from_file_path ( xml_file_iterator_t iterator,
const char * file_path,
int output_depth )

Initializes an XML file iterator to read from a given path.

Parameters
[in]iteratorPointer to the iterator to initialize.
[in]file_pathPath to the file to read from.
[in]output_depthXML tree depth at which to return elements.
Returns
-1 error, 0 success, 1 already initialized, 2 error opening file (errno is set to reason), 3 error creating parser context

◆ xml_file_iterator_init_sax_handler()

static void xml_file_iterator_init_sax_handler ( xmlSAXHandlerPtr hdlr)
static

Initializes a xmlSAXHandler data structure for SAX version 2 parsing, assigning all the XML file iterator callback functions.

Parameters
[in]hdlrThe xmlSAXHandler to initialize

◆ xml_file_iterator_internal_subset()

static void xml_file_iterator_internal_subset ( void * ctx,
const xmlChar * name,
const xmlChar * ExternalID,
const xmlChar * SystemID )
static

XML file iterator parser callback for internal subset declaration.

This is just a wrapper for the libXML xmlSAX2InternalSubset getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]namethe root element name
[in]ExternalIDthe external ID
[in]SystemIDthe SYSTEM ID (e.g. filename or URL)

◆ xml_file_iterator_is_standalone()

static int xml_file_iterator_is_standalone ( void * ctx)
static

XML file iterator parser callback for checking if doc is standalone.

This is just a wrapper for the libXML xmlSAX2IsStandalone getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
Returns
1 if true

◆ xml_file_iterator_new()

xml_file_iterator_t xml_file_iterator_new ( void )

Allocates a new, uninitialized XML file iterator.

Free with xml_file_iterator_free.

Returns
Opaque pointer to the XML file iterator data structure.

◆ xml_file_iterator_next()

element_t xml_file_iterator_next ( xml_file_iterator_t iterator,
gchar ** error )

Get the next subelement from a XML file iterator.

Parameters
[in]iteratorThe XML file iterator to get the element from.
[out]errorError message output, set to NULL on success / EOF
Returns
The next subelement (free with element_free) or NULL if finished or on error.

◆ xml_file_iterator_notation_decl()

static void xml_file_iterator_notation_decl ( void * ctx,
const xmlChar * name,
const xmlChar * publicId,
const xmlChar * systemId )
static

XML file iterator parser callback for when a notation definition has been parsed.

This is just a wrapper for the libXML xmlSAX2NotationDecl getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]nameThe name of the notation
[in]publicIdThe public ID of the entity
[in]systemIdThe system ID of the entity

◆ xml_file_iterator_processing_instruction()

static void xml_file_iterator_processing_instruction ( void * ctx,
const xmlChar * target,
const xmlChar * data )
static

XML file iterator parser callback when a processing instruction has been parsed.

This is just a wrapper for the libXML xmlSAX2ProcessingInstruction getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]targetThe target name
[in]datathe PI data

◆ xml_file_iterator_resolve_entity()

static xmlParserInputPtr xml_file_iterator_resolve_entity ( void * ctx,
const xmlChar * publicId,
const xmlChar * systemId )
static

XML file iterator parser callback for resolving an entity.

This is just a wrapper for the libXML xmlSAX2ResolveEntity getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]publicIdThe public ID of the entity
[in]systemIdThe systemID of the entity
Returns
the xmlParserInputPtr if inlined or NULL for DOM behaviour

◆ xml_file_iterator_rewind()

int xml_file_iterator_rewind ( xml_file_iterator_t iterator)

Rewinds an XML file iterator by rewinding the file and creating a new XML parser context.

Parameters
[in]iteratorThe XML file iterator to rewind.
Returns
0 success, 1 error creating new parser context

◆ xml_file_iterator_set_document_locator()

static void xml_file_iterator_set_document_locator ( void * ctx,
xmlSAXLocatorPtr loc )
static

XML file iterator parser callback for setting the document locator.

This is just a wrapper for the libXML xmlSAX2SetDocumentLocator getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]locA SAX Locator

◆ xml_file_iterator_start_document()

static void xml_file_iterator_start_document ( void * ctx)
static

XML file iterator parser callback at the document start.

This is just a wrapper for the libXML xmlSAX2StartDocument getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure

◆ xml_file_iterator_start_element_ns()

static void xml_file_iterator_start_element_ns ( void * ctx,
const xmlChar * localname,
const xmlChar * prefix,
const xmlChar * URI,
int nb_namespaces,
const xmlChar ** namespaces,
int nb_attributes,
int nb_defaulted,
const xmlChar ** attributes )
static

XML file iterator parser callback for element start.

This is just a wrapper for the libXML xmlSAX2StartElementNs getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]localnamethe local name of the element
[in]prefixthe element namespace prefix if available
[in]URIthe element namespace name if available
[in]nb_namespacesnumber of namespace definitions on that node
[in]namespacespointer to the array of prefix/URI pairs namespace definitions
[in]nb_attributesthe number of attributes on that node
[in]nb_defaultedthe number of defaulted attributes
[in]attributespointer to the array of (localname/prefix/URI/value/end) attribute values

◆ xml_file_iterator_unparsed_entity_decl()

static void xml_file_iterator_unparsed_entity_decl ( void * ctx,
const xmlChar * name,
const xmlChar * publicId,
const xmlChar * systemId,
const xmlChar * notationName )
static

XML file iterator parser callback for when an unparsed entity declaration has been parsed.

This is just a wrapper for the libXML xmlSAX2UnparsedEntityDecl getting the libXML parser context from the iterator struct passed as user data.

Parameters
[in]ctxparser context data / iterator data structure
[in]nameThe name of the notation
[in]publicIdThe public ID of the entity
[in]systemIdThe system ID of the entity
[in]notationNameThe name of the notation

◆ xml_handle_end_element()

void xml_handle_end_element ( context_data_t * context,
const gchar * element_name )

Handle the end of an XML element.

Parameters
[in]contextParser context.
[in]element_nameXML element name.

◆ xml_handle_start_element()

void xml_handle_start_element ( context_data_t * context,
const gchar * element_name,
const gchar ** attribute_names,
const gchar ** attribute_values )

Handle the start of an OMP XML element.

Parameters
[in]contextParser context.
[in]element_nameXML element name.
[in]attribute_namesXML attribute name.
[in]attribute_valuesXML attribute values.

◆ xml_handle_text()

void xml_handle_text ( context_data_t * context,
const gchar * text,
gsize text_len )

Handle additional text of an XML element.

Parameters
[in]contextParser context.
[in]textThe text.
[in]text_lenLength of the text.

◆ xml_search_handle_start_element()

static void xml_search_handle_start_element ( GMarkupParseContext * ctx,
const gchar * element_name,
const gchar ** attribute_names,
const gchar ** attribute_values,
gpointer data,
GError ** error )
static

Handle the opening tag of an element in an XML search.

Parameters
[in]ctxThe parse context.
[in]element_nameThe name of the element.
[in]attribute_namesNULL-terminated array of attribute names.
[in]attribute_valuesNULL-terminated array of attribute values.
[in]dataThe search data struct.
[out]errorPointer to error output location.

◆ xml_string_append()

void xml_string_append ( GString * xml,
const char * format,
... )

Append formatted escaped XML to a string.

Parameters
[in]xmlXML string.
[in]formatFormat string.
[in]...Arguments for format string.