Greenbone Vulnerability Management Libraries  11.0.1
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>
Include dependency graph for xmlutils.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "lib xml"
 GLib log domain. More...
 
#define BUFFER_SIZE   1048576
 Size of the buffer for reading from the manager. More...
 
#define XML_FILE_BUFFER_SIZE   1048576
 

Functions

entity_t make_entity (const char *name, const char *text)
 Create an entity. More...
 
entities_t next_entities (entities_t entities)
 Return all the entities from an entities_t after the first. More...
 
entity_t first_entity (entities_t entities)
 Return the first entity from an entities_t. More...
 
entity_t add_entity (entities_t *entities, const char *name, const char *text)
 Add an XML entity to a tree of entities. More...
 
void free_entity (entity_t entity)
 Free an entity, recursively. More...
 
char * entity_text (entity_t entity)
 Get the text an entity. More...
 
char * entity_name (entity_t entity)
 Get the name an entity. More...
 
int compare_entity_with_name (gconstpointer entity, gconstpointer name)
 Compare a given name with the name of a given entity. More...
 
entity_t entity_child (entity_t entity, const char *name)
 Get a child of an entity. More...
 
const char * entity_attribute (entity_t entity, const char *name)
 Get an attribute of an entity. More...
 
void add_attributes (entity_t entity, const gchar **names, const gchar **values)
 Add attributes from an XML callback to an entity. More...
 
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. More...
 
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. More...
 
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. More...
 
static void ignore_end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)
 Handle the end of an XML element. More...
 
static void handle_end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)
 Handle the end of an XML element. More...
 
void xml_handle_end_element (context_data_t *context, const gchar *element_name)
 Handle the end of an XML element. More...
 
static void ignore_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
 Handle additional text of an XML element. More...
 
static void handle_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
 Handle additional text of an XML element. More...
 
void xml_handle_text (context_data_t *context, const gchar *text, gsize text_len)
 Handle additional text of an XML element. More...
 
void handle_error (GMarkupParseContext *context, GError *error, gpointer user_data)
 Handle an OMP XML parsing error. More...
 
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. More...
 
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. More...
 
int read_entity_and_string (gnutls_session_t *session, entity_t *entity, GString **string_return)
 Try read an XML entity tree from the manager. More...
 
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. More...
 
int read_entity_and_text (gnutls_session_t *session, entity_t *entity, char **text)
 Read an XML entity tree from the manager. More...
 
int read_entity_and_text_c (gvm_connection_t *connection, entity_t *entity, char **text)
 Read an XML entity tree from the manager. More...
 
int read_string (gnutls_session_t *session, GString **string)
 Read entity and text. Free the entity immediately. More...
 
int read_string_c (gvm_connection_t *connection, GString **string)
 Read entity and text. Free the entity immediately. More...
 
int try_read_entity (gnutls_session_t *session, int timeout, entity_t *entity)
 Try read an XML entity tree from the manager. More...
 
int try_read_entity_c (gvm_connection_t *connection, int timeout, entity_t *entity)
 Try read an XML entity tree from the manager. More...
 
int read_entity (gnutls_session_t *session, entity_t *entity)
 Read an XML entity tree from the manager. More...
 
int read_entity_s (int socket, entity_t *entity)
 Read an XML entity tree from the socket. More...
 
int read_entity_c (gvm_connection_t *connection, entity_t *entity)
 Read an XML entity tree from the manager. More...
 
int parse_entity (const char *string, entity_t *entity)
 Read an XML entity tree from a string. More...
 
static void foreach_print_entity_to_string (gpointer entity, gpointer string)
 Print an XML entity for g_slist_foreach to a GString. More...
 
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. More...
 
void print_entity_to_string (entity_t entity, GString *string)
 Print an XML entity tree to a GString, appending it if string is not. More...
 
static void foreach_print_entity (gpointer entity, gpointer stream)
 Print an XML entity for g_slist_foreach. More...
 
static void foreach_print_attribute (gpointer name, gpointer value, gpointer stream)
 Print an XML attribute for g_hash_table_foreach. More...
 
void print_entity (FILE *stream, entity_t entity)
 Print an XML entity. More...
 
static void foreach_print_attribute_format (gpointer name, gpointer value, gpointer none)
 Print an XML attribute for g_hash_table_foreach to stdout. More...
 
void print_entity_format (entity_t entity, gpointer indent)
 Print an XML entity to stdout, recursively printing its children. More...
 
gboolean compare_find_attribute (gpointer key, gpointer value, gpointer attributes2)
 Look for a key-value pair in a hash table. More...
 
int compare_entities (entity_t entity1, entity_t entity2)
 Compare two XML entity. More...
 
int xml_count_entities (entities_t entities)
 Count the number of entities. More...
 
void xml_string_append (GString *xml, const char *format,...)
 Append formatted escaped XML to a string. More...
 
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. More...
 
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. More...
 
int parse_element (const gchar *string, element_t *element)
 Read an XML element tree from a string. More...
 
void element_free (element_t element)
 Free an entire element tree. More...
 
const gchar * element_name (element_t element)
 Get the name of an element. More...
 
static element_t find_child (element_t element, const gchar *name)
 Find child in an element. More...
 
element_t element_child (element_t element, const gchar *name)
 Get a child of an element. More...
 
gchar * element_text (element_t element)
 Get text of an element. More...
 
gchar * element_attribute (element_t element, const gchar *name)
 Get an attribute of an element. More...
 
element_t element_first_child (element_t element)
 Get the first child of an element. More...
 
element_t element_next (element_t element)
 Get the next sibling of an element. More...
 

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.

Definition in file xmlutils.c.

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   1048576

Size of the buffer for reading from the manager.

Definition at line 51 of file xmlutils.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib xml"

GLib log domain.

Definition at line 46 of file xmlutils.c.

◆ XML_FILE_BUFFER_SIZE

#define XML_FILE_BUFFER_SIZE   1048576

Definition at line 1609 of file xmlutils.c.

Function Documentation

◆ add_attributes()

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

Add attributes from an XML callback to an entity.

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

Definition at line 248 of file xmlutils.c.

249 {
250  if (names && values && *names && *values)
251  {
252  if (entity->attributes == NULL)
253  entity->attributes =
254  g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
255  while (*names && *values)
256  {
257  if (*values)
258  g_hash_table_insert (entity->attributes, g_strdup (*names),
259  g_strdup (*values));
260  names++;
261  values++;
262  }
263  }
264 }

References entity_s::attributes.

Referenced by handle_start_element().

Here is the caller graph for this function:

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

Definition at line 115 of file xmlutils.c.

116 {
117  entity_t entity = make_entity (name, text);
118  if (entities)
119  *entities = g_slist_append (*entities, entity);
120  return entity;
121 }

References make_entity().

Referenced by handle_start_element().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1441 of file xmlutils.c.

1442 {
1443  if (entity1 == NULL)
1444  return entity2 == NULL ? 0 : 1;
1445  if (entity2 == NULL)
1446  return 1;
1447 
1448  if (strcmp (entity1->name, entity2->name))
1449  {
1450  g_debug (" compare failed name: %s vs %s\n", entity1->name,
1451  entity2->name);
1452  return 1;
1453  }
1454  if (strcmp (entity1->text, entity2->text))
1455  {
1456  g_debug (" compare failed text %s vs %s (%s)\n", entity1->text,
1457  entity2->text, entity1->name);
1458  return 1;
1459  }
1460 
1461  if (entity1->attributes == NULL)
1462  {
1463  if (entity2->attributes)
1464  return 1;
1465  }
1466  else
1467  {
1468  if (entity2->attributes == NULL)
1469  return 1;
1470  if (g_hash_table_find (entity1->attributes, compare_find_attribute,
1471  (gpointer) entity2->attributes))
1472  {
1473  g_debug (" compare failed attributes\n");
1474  return 1;
1475  }
1476  }
1477 
1478  // FIX entities can be in any order
1479  GSList *list1 = entity1->entities;
1480  GSList *list2 = entity2->entities;
1481  while (list1 && list2)
1482  {
1483  if (compare_entities (list1->data, list2->data))
1484  {
1485  g_debug (" compare failed subentity\n");
1486  return 1;
1487  }
1488  list1 = g_slist_next (list1);
1489  list2 = g_slist_next (list2);
1490  }
1491  if (list1 == list2)
1492  return 0;
1493  /* More entities in one of the two. */
1494  g_debug (" compare failed number of entities (%s)\n", entity1->name);
1495  return 1;
1496 }

References entity_s::attributes, compare_entities(), compare_find_attribute(), entity_s::entities, entity_s::name, and entity_s::text.

Referenced by compare_entities().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_entity_with_name()

int compare_entity_with_name ( gconstpointer  entity,
gconstpointer  name 
)

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.

Definition at line 193 of file xmlutils.c.

194 {
195  return strcmp (entity_name ((entity_t) entity), (char *) name);
196 }

References entity_name().

Referenced by entity_child().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_find_attribute()

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

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.

Definition at line 1423 of file xmlutils.c.

1424 {
1425  gchar *value2 = g_hash_table_lookup (attributes2, key);
1426  if (value2 && strcmp (value, value2) == 0)
1427  return FALSE;
1428  g_debug (" compare failed attribute: %s\n", (char *) value);
1429  return TRUE;
1430 }

Referenced by compare_entities().

Here is the caller graph for this function:

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

Definition at line 1840 of file xmlutils.c.

1841 {
1842  const gchar *stripped_name;
1843 
1844  if (!element)
1845  return NULL;
1846 
1847  stripped_name = strchr (name, ':');
1848  if (stripped_name)
1849  {
1850  gchar *attribute;
1851 
1852  /* There was a namespace in the name.
1853  *
1854  * First try without the namespace, because libxml2 doesn't consider the
1855  * namespace in the name when the namespace is defined. */
1856 
1857  stripped_name++;
1858 
1859  if (*stripped_name == '\0')
1860  /* Don't search for child with empty stripped name, because we'll
1861  * find text nodes. But search with just the namespace for glib
1862  * compatibility. */
1863  return (gchar *) xmlGetProp (element, (const xmlChar *) name);
1864 
1865  attribute = (gchar *) xmlGetProp (element, (const xmlChar *) stripped_name);
1866  if (attribute)
1867  return attribute;
1868 
1869  /* Didn't find anything. */
1870  }
1871 
1872  /* There was no namespace, or we didn't find anything without the namespace.
1873  *
1874  * Try with the full name. */
1875 
1876  return (gchar *) xmlGetProp (element, (const xmlChar *) name);
1877 }

Referenced by Ensure().

Here is the caller graph for this function:

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

Definition at line 1765 of file xmlutils.c.

1766 {
1767  const gchar *stripped_name;
1768 
1769  if (!element)
1770  return NULL;
1771 
1772  stripped_name = strchr (name, ':');
1773  if (stripped_name)
1774  {
1775  element_t child;
1776 
1777  /* There was a namespace in the name.
1778  *
1779  * First try without the namespace, because libxml2 doesn't consider the
1780  * namespace in the name when the namespace is defined. */
1781 
1782  stripped_name++;
1783 
1784  if (*stripped_name == '\0')
1785  /* Don't search for child with empty stripped name, because we'll
1786  * find text nodes. But search with just the namespace for glib
1787  * compatibility. */
1788  return find_child (element, name);
1789 
1790  child = find_child (element, stripped_name);
1791  if (child)
1792  return child;
1793 
1794  /* Didn't find anything. */
1795  }
1796 
1797  /* There was no namespace, or we didn't find anything without the namespace.
1798  *
1799  * Try with the full name. */
1800 
1801  return find_child (element, name);
1802 }

References find_child().

Referenced by Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1887 of file xmlutils.c.

1888 {
1889  if (element)
1890  return element->children;
1891  return NULL;
1892 }

Referenced by Ensure().

Here is the caller graph for this function:

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

Definition at line 1713 of file xmlutils.c.

1714 {
1715  if (element)
1716  {
1717  assert (element->doc);
1718  xmlFreeDoc (element->doc);
1719  }
1720 }

Referenced by Ensure().

Here is the caller graph for this function:

◆ element_name()

const gchar* element_name ( element_t  element)

Get the name of an element.

Parameters
[in]elementElement.
Returns
Element name.

Definition at line 1730 of file xmlutils.c.

1731 {
1732  if (element
1733  && (element->type == XML_ELEMENT_NODE))
1734  return (const gchar *) element->name;
1735 
1736  return "";
1737 }

Referenced by Ensure(), handle_end_element(), handle_start_element(), ignore_end_element(), ignore_start_element(), xml_handle_end_element(), xml_handle_start_element(), and xml_search_handle_start_element().

Here is the caller graph for this function:

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

Definition at line 1902 of file xmlutils.c.

1903 {
1904  if (element)
1905  return element->next;
1906  return NULL;
1907 }

Referenced by Ensure().

Here is the caller graph for this function:

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

Definition at line 1816 of file xmlutils.c.

1817 {
1818  gchar *string;
1819 
1820  if (!element)
1821  return NULL;
1822 
1823  string = (gchar *) xmlNodeListGetString (element->doc, element->xmlChildrenNode, 1);
1824  if (string)
1825  return string;
1826  string = xmlMalloc (1);
1827  string[0] = '\0';
1828  return string;
1829 }

Referenced by Ensure().

Here is the caller graph for this function:

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

Definition at line 230 of file xmlutils.c.

231 {
232  if (!entity)
233  return NULL;
234 
235  if (entity->attributes)
236  return (const char *) g_hash_table_lookup (entity->attributes, name);
237  return NULL;
238 }

References entity_s::attributes.

Referenced by Ensure(), gmp_authenticate_info_ext(), gmp_authenticate_info_ext_c(), gmp_check_response(), gmp_check_response_c(), gmp_get_report_ext(), gmp_get_tasks_ext(), gmp_ping(), gmp_ping_c(), gmp_read_create_response(), gmp_resume_task_report_c(), gmp_start_task_report_c(), osp_delete_scan(), osp_get_performance_ext(), osp_get_scan_pop(), osp_get_scan_status_ext(), osp_get_scanner_details(), osp_start_scan(), osp_start_scan_ext(), and osp_stop_scan().

Here is the caller graph for this function:

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

Definition at line 207 of file xmlutils.c.

208 {
209  if (!entity)
210  return NULL;
211 
212  if (entity->entities)
213  {
214  entities_t match =
215  g_slist_find_custom (entity->entities, name, compare_entity_with_name);
216  return match ? (entity_t) match->data : NULL;
217  }
218  return NULL;
219 }

References compare_entity_with_name(), and entity_s::entities.

Referenced by Ensure(), gmp_authenticate_info_ext(), gmp_authenticate_info_ext_c(), gmp_ping_c(), gmp_resume_task_report(), gmp_resume_task_report_c(), gmp_start_task_report(), gmp_start_task_report_c(), gmp_task_status(), osp_get_scan_pop(), osp_get_scan_status_ext(), osp_get_scanner_details(), osp_get_version(), and osp_get_vts_version().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 175 of file xmlutils.c.

176 {
177  if (!entity)
178  return NULL;
179 
180  return entity->name;
181 }

References entity_s::name.

Referenced by compare_entity_with_name(), and Ensure().

Here is the caller graph for this function:

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

Definition at line 159 of file xmlutils.c.

160 {
161  if (!entity)
162  return NULL;
163 
164  return entity->text;
165 }

References entity_s::text.

Referenced by Ensure(), gmp_authenticate_info_ext(), gmp_authenticate_info_ext_c(), gmp_ping_c(), gmp_resume_task_report(), gmp_resume_task_report_c(), gmp_start_task_report(), gmp_start_task_report_c(), gmp_task_status(), osp_get_performance_ext(), osp_get_scanner_details(), osp_get_version(), and osp_get_vts_version().

Here is the caller graph for this function:

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

Definition at line 1748 of file xmlutils.c.

1749 {
1750  for (xmlNode *node = element->children; node; node = node->next)
1751  if (xmlStrcmp (node->name, (const xmlChar *) name) == 0)
1752  return node;
1753  return NULL;
1754 }

Referenced by element_child().

Here is the caller graph for this function:

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

Definition at line 1620 of file xmlutils.c.

1622 {
1623  gchar buffer[XML_FILE_BUFFER_SIZE];
1624  FILE *file;
1625  int read_len;
1626  GMarkupParser xml_parser;
1627  GMarkupParseContext *xml_context;
1628  xml_search_data_t search_data;
1629  GError *error = NULL;
1630 
1631  search_data.find_element = find_element;
1632  search_data.find_attributes = find_attributes;
1633  search_data.found = 0;
1634 
1635  /* Create the XML parser. */
1636  xml_parser.start_element = xml_search_handle_start_element;
1637  xml_parser.end_element = NULL;
1638  xml_parser.text = NULL;
1639  xml_parser.passthrough = NULL;
1640  xml_parser.error = NULL;
1641  xml_context = g_markup_parse_context_new (&xml_parser, 0, &search_data, NULL);
1642 
1643  file = fopen (file_path, "r");
1644  if (file == NULL)
1645  {
1646  g_markup_parse_context_free (xml_context);
1647  g_warning ("%s: Failed to open '%s':", __FUNCTION__, strerror (errno));
1648  return 0;
1649  }
1650 
1651  while ((read_len = fread (&buffer, sizeof (char), XML_FILE_BUFFER_SIZE, file))
1652  && g_markup_parse_context_parse (xml_context, buffer, read_len, &error)
1653  && error == NULL)
1654  {
1655  }
1656  g_markup_parse_context_end_parse (xml_context, &error);
1657 
1658  fclose (file);
1659 
1660  g_markup_parse_context_free (xml_context);
1661  return search_data.found;
1662 }

References xml_search_data_t::find_attributes, xml_search_data_t::find_element, xml_search_data_t::found, XML_FILE_BUFFER_SIZE, and xml_search_handle_start_element().

Here is the call graph for this function:

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

Definition at line 96 of file xmlutils.c.

97 {
98  if (entities)
99  return (entity_t) entities->data;
100  return NULL;
101 }

Referenced by Ensure(), and xml_count_entities().

Here is the caller graph for this function:

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

Definition at line 1327 of file xmlutils.c.

1328 {
1329  fprintf ((FILE *) stream, " %s=\"%s\"", (char *) name, (char *) value);
1330 }

Referenced by print_entity().

Here is the caller graph for this function:

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

Definition at line 1364 of file xmlutils.c.

1365 {
1366  (void) none;
1367  printf (" %s=\"%s\"", (char *) name, (char *) value);
1368 }

Referenced by print_entity_format().

Here is the caller graph for this function:

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

Definition at line 1274 of file xmlutils.c.

1276 {
1277  gchar *text_escaped;
1278  text_escaped = g_markup_escape_text ((gchar *) value, -1);
1279  g_string_append_printf ((GString *) string, " %s=\"%s\"", (char *) name,
1280  text_escaped);
1281  g_free (text_escaped);
1282 }

Referenced by print_entity_to_string().

Here is the caller graph for this function:

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

Definition at line 1314 of file xmlutils.c.

1315 {
1316  print_entity ((FILE *) stream, (entity_t) entity);
1317 }

References print_entity().

Referenced by print_entity().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1261 of file xmlutils.c.

1262 {
1263  print_entity_to_string ((entity_t) entity, (GString *) string);
1264 }

References print_entity_to_string().

Referenced by print_entity_to_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_entity()

void free_entity ( entity_t  entity)

Free an entity, recursively.

Parameters
[in]entityThe entity, can be NULL.

Definition at line 129 of file xmlutils.c.

130 {
131  if (entity)
132  {
133  g_free (entity->name);
134  g_free (entity->text);
135  if (entity->attributes)
136  g_hash_table_destroy (entity->attributes);
137  if (entity->entities)
138  {
139  GSList *list = entity->entities;
140  while (list)
141  {
142  free_entity (list->data);
143  list = list->next;
144  }
145  g_slist_free (entity->entities);
146  }
147  g_free (entity);
148  }
149 }

References entity_s::attributes, entity_s::entities, free_entity(), entity_s::name, and entity_s::text.

Referenced by free_entity(), gmp_authenticate(), gmp_authenticate_info_ext(), gmp_authenticate_info_ext_c(), gmp_check_response(), gmp_check_response_c(), gmp_delete_config_ext(), gmp_delete_lsc_credential_ext(), gmp_delete_port_list_ext(), gmp_delete_report(), gmp_delete_target_ext(), gmp_delete_task(), gmp_delete_task_ext(), gmp_get_report_ext(), gmp_get_tasks_ext(), gmp_modify_task_file(), gmp_ping(), gmp_ping_c(), gmp_read_create_response(), gmp_resume_task_report(), gmp_resume_task_report_c(), gmp_start_task_report(), gmp_start_task_report_c(), gmp_stop_task(), osp_delete_scan(), osp_get_performance_ext(), osp_get_scan_pop(), osp_get_scan_status_ext(), osp_get_scanner_details(), osp_get_version(), osp_get_vts_version(), osp_start_scan(), osp_start_scan_ext(), osp_stop_scan(), parse_entity(), read_string(), try_read_entity_and_string(), and try_read_entity_and_string_s().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 380 of file xmlutils.c.

382 {
383  context_data_t *data = (context_data_t *) user_data;
384 
385  (void) context;
386  (void) error;
387  (void) element_name;
388  assert (data->current && data->first);
389  if (data->current == data->first)
390  {
391  assert (strcmp (element_name,
392  /* The name of the very first entity. */
393  ((entity_t) (data->first->data))->name)
394  == 0);
395  data->done = TRUE;
396  /* "Pop" the element. */
397  data->current = g_slist_next (data->current);
398  }
399  else if (data->current)
400  {
401  GSList *front;
402  /* "Pop" and free the element. */
403  front = data->current;
404  data->current = g_slist_next (data->current);
405  g_slist_free_1 (front);
406  }
407 }

References context_data_t::current, context_data_t::done, element_name(), and context_data_t::first.

Referenced by parse_entity(), try_read_entity_and_string(), try_read_entity_and_string_s(), and xml_handle_end_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_error()

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

Handle an OMP XML parsing error.

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

Definition at line 491 of file xmlutils.c.

492 {
493  (void) context;
494  (void) user_data;
495  g_message (" Error: %s\n", error->message);
496 }

Referenced by parse_entity(), try_read_entity_and_string(), and try_read_entity_and_string_s().

Here is the caller graph for this function:

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

Definition at line 304 of file xmlutils.c.

308 {
309  entity_t entity;
310  context_data_t *data = (context_data_t *) user_data;
311 
312  (void) context;
313  (void) error;
314  if (data->current)
315  {
316  entity_t current = (entity_t) data->current->data;
317  entity = add_entity (&current->entities, element_name, NULL);
318  }
319  else
320  entity = add_entity (NULL, element_name, NULL);
321 
322  add_attributes (entity, attribute_names, attribute_values);
323 
324  /* "Push" the element. */
325  if (data->first == NULL)
326  data->current = data->first = g_slist_prepend (NULL, entity);
327  else
328  data->current = g_slist_prepend (data->current, entity);
329 }

References add_attributes(), add_entity(), context_data_t::current, element_name(), entity_s::entities, and context_data_t::first.

Referenced by parse_entity(), try_read_entity_and_string(), try_read_entity_and_string_s(), and xml_handle_start_element().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 451 of file xmlutils.c.

453 {
454  context_data_t *data = (context_data_t *) user_data;
455 
456  (void) context;
457  (void) text_len;
458  (void) error;
459  entity_t current = (entity_t) data->current->data;
460  if (current->text)
461  {
462  gchar *old = current->text;
463  current->text = g_strconcat (current->text, text, NULL);
464  g_free (old);
465  }
466  else
467  current->text = g_strdup (text);
468 }

References context_data_t::current, and entity_s::text.

Referenced by parse_entity(), try_read_entity_and_string(), try_read_entity_and_string_s(), and xml_handle_text().

Here is the caller graph for this function:

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

Definition at line 357 of file xmlutils.c.

359 {
360  context_data_t *data = (context_data_t *) user_data;
361 
362  (void) context;
363  (void) element_name;
364  (void) error;
365 
366  data->current = GINT_TO_POINTER (GPOINTER_TO_INT (data->current) - 1);
367  if (data->current == NULL)
368  data->done = TRUE;
369 }

References context_data_t::current, context_data_t::done, and element_name().

Referenced by try_read_entity_and_string(), and try_read_entity_and_string_s().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 277 of file xmlutils.c.

281 {
282  context_data_t *data = (context_data_t *) user_data;
283 
284  (void) context;
285  (void) element_name;
286  (void) attribute_names;
287  (void) attribute_values;
288  (void) error;
289 
290  data->current = GINT_TO_POINTER (GPOINTER_TO_INT (data->current) + 1);
291 }

References context_data_t::current, and element_name().

Referenced by try_read_entity_and_string(), and try_read_entity_and_string_s().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 431 of file xmlutils.c.

433 {
434  (void) context;
435  (void) text;
436  (void) text_len;
437  (void) user_data;
438  (void) error;
439 }

Referenced by try_read_entity_and_string(), and try_read_entity_and_string_s().

Here is the caller graph for this function:

◆ make_entity()

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

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.

Definition at line 62 of file xmlutils.c.

63 {
64  entity_t entity;
65  entity = g_malloc (sizeof (*entity));
66  entity->name = g_strdup (name ? name : "");
67  entity->text = g_strdup (text ? text : "");
68  entity->entities = NULL;
69  entity->attributes = NULL;
70  return entity;
71 }

References entity_s::attributes, entity_s::entities, entity_s::name, and entity_s::text.

Referenced by add_entity().

Here is the caller graph for this function:

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

Definition at line 81 of file xmlutils.c.

82 {
83  if (entities)
84  return (entities_t) entities->next;
85  return NULL;
86 }

Referenced by Ensure(), osp_get_scanner_details(), and xml_count_entities().

Here is the caller graph for this function:

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

Definition at line 1682 of file xmlutils.c.

1683 {
1684  xmlDocPtr doc;
1685 
1686  LIBXML_TEST_VERSION
1687 
1688  if (element)
1689  *element = NULL;
1690 
1691  if (xmlMemSetup (g_free, g_malloc, g_realloc, g_strdup))
1692  return -4;
1693 
1694  doc = xmlReadMemory (string, strlen (string), "noname.xml", NULL, 0);
1695  if (doc == NULL)
1696  return -2;
1697 
1698  if (element)
1699  *element = xmlDocGetRootElement (doc);
1700 
1701  return 0;
1702 }

Referenced by Ensure().

Here is the caller graph for this function:

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

Definition at line 1191 of file xmlutils.c.

1192 {
1193  GMarkupParser xml_parser;
1194  GError *error = NULL;
1195  GMarkupParseContext *xml_context;
1196  context_data_t context_data;
1197 
1198  /* Create the XML parser. */
1199 
1200  xml_parser.start_element = handle_start_element;
1201  xml_parser.end_element = handle_end_element;
1202  xml_parser.text = handle_text;
1203  xml_parser.passthrough = NULL;
1204  xml_parser.error = handle_error;
1205 
1206  context_data.done = FALSE;
1207  context_data.first = NULL;
1208  context_data.current = NULL;
1209 
1210  /* Setup the XML context. */
1211 
1212  xml_context =
1213  g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
1214 
1215  /* Parse the string. */
1216 
1217  g_markup_parse_context_parse (xml_context, string, strlen (string), &error);
1218  if (error)
1219  {
1220  g_error_free (error);
1221  if (context_data.first && context_data.first->data)
1222  {
1223  free_entity (context_data.first->data);
1224  g_slist_free_1 (context_data.first);
1225  }
1226  return -2;
1227  }
1228  if (context_data.done)
1229  {
1230  g_markup_parse_context_end_parse (xml_context, &error);
1231  if (error)
1232  {
1233  g_warning (" End error: %s\n", error->message);
1234  g_error_free (error);
1235  if (context_data.first && context_data.first->data)
1236  {
1237  free_entity (context_data.first->data);
1238  g_slist_free_1 (context_data.first);
1239  }
1240  return -2;
1241  }
1242  *entity = (entity_t) context_data.first->data;
1243  g_slist_free_1 (context_data.first);
1244  return 0;
1245  }
1246  if (context_data.first && context_data.first->data)
1247  {
1248  free_entity (context_data.first->data);
1249  g_slist_free_1 (context_data.first);
1250  }
1251  return -3;
1252 }

References context_data_t::current, context_data_t::done, context_data_t::first, free_entity(), handle_end_element(), handle_error(), handle_start_element(), and handle_text().

Referenced by Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1339 of file xmlutils.c.

1340 {
1341  gchar *text_escaped = NULL;
1342  fprintf (stream, "<%s", entity->name);
1343  if (entity->attributes && g_hash_table_size (entity->attributes))
1344  g_hash_table_foreach (entity->attributes, foreach_print_attribute, stream);
1345  fprintf (stream, ">");
1346  text_escaped = g_markup_escape_text (entity->text, -1);
1347  fprintf (stream, "%s", text_escaped);
1348  g_free (text_escaped);
1349  g_slist_foreach (entity->entities, foreach_print_entity, stream);
1350  fprintf (stream, "</%s>", entity->name);
1351  fflush (stream);
1352 }

References entity_s::attributes, entity_s::entities, foreach_print_attribute(), foreach_print_entity(), entity_s::name, and entity_s::text.

Referenced by foreach_print_entity().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1382 of file xmlutils.c.

1383 {
1384  int i = 0;
1385  int indentation = GPOINTER_TO_INT (indent);
1386  gchar *text_escaped = NULL;
1387 
1388  for (i = 0; i < indentation; i++)
1389  printf (" ");
1390 
1391  printf ("<%s", entity->name);
1392  if (entity->attributes && g_hash_table_size (entity->attributes))
1393  g_hash_table_foreach (entity->attributes, foreach_print_attribute_format,
1394  indent);
1395  printf (">");
1396 
1397  text_escaped = g_markup_escape_text (entity->text, -1);
1398  printf ("%s", text_escaped);
1399  g_free (text_escaped);
1400 
1401  if (entity->entities)
1402  {
1403  printf ("\n");
1404  g_slist_foreach (entity->entities, (GFunc) print_entity_format,
1405  GINT_TO_POINTER (indentation + 1));
1406  for (i = 0; i < indentation; i++)
1407  printf (" ");
1408  }
1409 
1410  printf ("</%s>\n", entity->name);
1411 }

References entity_s::attributes, entity_s::entities, foreach_print_attribute_format(), entity_s::name, print_entity_format(), and entity_s::text.

Referenced by print_entity_format().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1292 of file xmlutils.c.

1293 {
1294  gchar *text_escaped = NULL;
1295  g_string_append_printf (string, "<%s", entity->name);
1296  if (entity->attributes && g_hash_table_size (entity->attributes))
1297  g_hash_table_foreach (entity->attributes, foreach_print_attribute_to_string,
1298  string);
1299  g_string_append_printf (string, ">");
1300  text_escaped = g_markup_escape_text (entity->text, -1);
1301  g_string_append_printf (string, "%s", text_escaped);
1302  g_free (text_escaped);
1303  g_slist_foreach (entity->entities, foreach_print_entity_to_string, string);
1304  g_string_append_printf (string, "</%s>", entity->name);
1305 }

References entity_s::attributes, entity_s::entities, foreach_print_attribute_to_string(), foreach_print_entity_to_string(), entity_s::name, and entity_s::text.

Referenced by foreach_print_entity_to_string(), and osp_get_scan_pop().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1149 of file xmlutils.c.

1150 {
1151  return try_read_entity (session, 0, entity);
1152 }

References try_read_entity().

Referenced by gmp_check_response(), and gmp_read_create_response().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 978 of file xmlutils.c.

980 {
981  return try_read_entity_and_string (session, 0, entity, string_return);
982 }

References try_read_entity_and_string().

Referenced by read_entity_and_text(), and read_string().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 998 of file xmlutils.c.

1000 {
1001  if (connection->tls)
1002  return try_read_entity_and_string (&connection->session, 0, entity,
1003  string_return);
1004  return try_read_entity_and_string_s (connection->socket, 0, entity,
1005  string_return);
1006 }

References gvm_connection_t::session, gvm_connection_t::socket, gvm_connection_t::tls, try_read_entity_and_string(), and try_read_entity_and_string_s().

Referenced by read_entity_and_text_c(), and read_string_c().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1021 of file xmlutils.c.

1022 {
1023  if (text)
1024  {
1025  GString *string = NULL;
1026  int ret = read_entity_and_string (session, entity, &string);
1027  if (ret)
1028  {
1029  if (string)
1030  g_string_free (string, TRUE);
1031  return ret;
1032  }
1033  *text = g_string_free (string, FALSE);
1034  return 0;
1035  }
1036  return read_entity_and_string (session, entity, NULL);
1037 }

References read_entity_and_string().

Here is the call graph for this function:

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

Definition at line 1052 of file xmlutils.c.

1054 {
1055  if (text)
1056  {
1057  GString *string = NULL;
1058  int ret = read_entity_and_string_c (connection, entity, &string);
1059  if (ret)
1060  {
1061  if (string)
1062  g_string_free (string, TRUE);
1063  return ret;
1064  }
1065  *text = g_string_free (string, FALSE);
1066  return 0;
1067  }
1068  return read_entity_and_string_c (connection, entity, NULL);
1069 }

References read_entity_and_string_c().

Here is the call graph for this function:

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

Definition at line 1177 of file xmlutils.c.

1178 {
1179  return try_read_entity_c (connection, 0, entity);
1180 }

References try_read_entity_c().

Referenced by gmp_check_response_c(), gmp_resume_task_report_c(), and gmp_start_task_report_c().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1163 of file xmlutils.c.

1164 {
1165  return try_read_entity_and_string_s (socket, 0, entity, NULL);
1166 }

References try_read_entity_and_string_s().

Here is the call graph for this function:

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

Definition at line 1080 of file xmlutils.c.

1081 {
1082  int ret = 0;
1083  entity_t entity;
1084 
1085  if (!(ret = read_entity_and_string (session, &entity, string)))
1086  free_entity (entity);
1087 
1088  return ret;
1089 }

References free_entity(), and read_entity_and_string().

Here is the call graph for this function:

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

Definition at line 1100 of file xmlutils.c.

1101 {
1102  return read_entity_and_string_c (connection, NULL, string);
1103 }

References read_entity_and_string_c().

Here is the call graph for this function:

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

Definition at line 1116 of file xmlutils.c.

1117 {
1118  return try_read_entity_and_string (session, timeout, entity, NULL);
1119 }

References try_read_entity_and_string().

Referenced by gmp_authenticate_info_ext(), gmp_get_report_ext(), gmp_get_tasks_ext(), gmp_ping(), and read_entity().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 514 of file xmlutils.c.

516 {
517  GMarkupParser xml_parser;
518  GError *error = NULL;
519  GMarkupParseContext *xml_context;
520  GString *string;
521  int socket;
522  time_t last_time;
523 
524  // Buffer for reading from the manager.
525  char *buffer;
526 
527  /* Record the start time. */
528 
529  if (time (&last_time) == -1)
530  {
531  g_warning (" failed to get current time: %s\n", strerror (errno));
532  return -1;
533  }
534 
535  if (timeout > 0)
536  {
537  /* Turn off blocking. */
538 
539  socket = GPOINTER_TO_INT (gnutls_transport_get_ptr (*session));
540  if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
541  return -1;
542  }
543  else
544  /* Quiet compiler. */
545  socket = 0;
546 
547  buffer = g_malloc0 (BUFFER_SIZE);
548 
549  /* Setup return arg. */
550 
551  if (string_return == NULL)
552  string = NULL;
553  else if (*string_return == NULL)
554  string = g_string_new ("");
555  else
556  string = *string_return;
557 
558  /* Create the XML parser. */
559 
560  if (entity)
561  {
562  xml_parser.start_element = handle_start_element;
563  xml_parser.end_element = handle_end_element;
564  xml_parser.text = handle_text;
565  }
566  else
567  {
568  xml_parser.start_element = ignore_start_element;
569  xml_parser.end_element = ignore_end_element;
570  xml_parser.text = ignore_text;
571  }
572  xml_parser.passthrough = NULL;
573  xml_parser.error = handle_error;
574 
575  context_data_t context_data;
576  context_data.done = FALSE;
577  context_data.first = NULL;
578  context_data.current = NULL;
579 
580  /* Setup the XML context. */
581 
582  xml_context =
583  g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
584 
585  /* Read and parse, until encountering end of file or error. */
586 
587  while (1)
588  {
589  ssize_t count;
590  while (1)
591  {
592  g_debug (" asking for %i\n", BUFFER_SIZE);
593  count = gnutls_record_recv (*session, buffer, BUFFER_SIZE);
594  if (count < 0)
595  {
596  if (count == GNUTLS_E_INTERRUPTED)
597  /* Interrupted, try read again. */
598  continue;
599  if ((timeout > 0) && (count == GNUTLS_E_AGAIN))
600  {
601  /* Server still busy, either timeout or try read again. */
602  if ((timeout - (time (NULL) - last_time)) <= 0)
603  {
604  g_warning (" timeout\n");
605  if (fcntl (socket, F_SETFL, 0L) < 0)
606  g_warning ("%s :failed to set socket flag: %s",
607  __FUNCTION__, strerror (errno));
608  g_markup_parse_context_free (xml_context);
609  g_free (buffer);
610  return -4;
611  }
612  continue;
613  }
614  if (count == GNUTLS_E_REHANDSHAKE)
615  /* Try again. TODO Rehandshake. */
616  continue;
617  if (context_data.first && context_data.first->data)
618  {
619  free_entity (context_data.first->data);
620  g_slist_free_1 (context_data.first);
621  }
622  if (string && *string_return == NULL)
623  g_string_free (string, TRUE);
624  if (timeout > 0)
625  {
626  if (fcntl (socket, F_SETFL, 0L) < 0)
627  g_warning ("%s :failed to set socket flag: %s",
628  __FUNCTION__, strerror (errno));
629  }
630  g_markup_parse_context_free (xml_context);
631  g_free (buffer);
632  return -1;
633  }
634  if (count == 0)
635  {
636  /* End of file. */
637  g_markup_parse_context_end_parse (xml_context, &error);
638  if (error)
639  {
640  g_warning (" End error: %s\n", error->message);
641  g_error_free (error);
642  }
643  if (context_data.first && context_data.first->data)
644  {
645  free_entity (context_data.first->data);
646  g_slist_free_1 (context_data.first);
647  }
648  if (string && *string_return == NULL)
649  g_string_free (string, TRUE);
650  if (timeout > 0)
651  {
652  if (fcntl (socket, F_SETFL, 0L) < 0)
653  g_warning ("%s :failed to set socket flag: %s",
654  __FUNCTION__, strerror (errno));
655  }
656  g_markup_parse_context_free (xml_context);
657  g_free (buffer);
658  return -3;
659  }
660  break;
661  }
662 
663  g_debug ("<= %.*s\n", (int) count, buffer);
664 
665  if (string)
666  g_string_append_len (string, buffer, count);
667 
668  g_markup_parse_context_parse (xml_context, buffer, count, &error);
669  if (error)
670  {
671  g_error_free (error);
672  if (context_data.first && context_data.first->data)
673  {
674  free_entity (context_data.first->data);
675  g_slist_free_1 (context_data.first);
676  }
677  if (string && *string_return == NULL)
678  g_string_free (string, TRUE);
679  if (timeout > 0)
680  {
681  if (fcntl (socket, F_SETFL, 0L) < 0)
682  g_warning ("%s :failed to set socket flag: %s", __FUNCTION__,
683  strerror (errno));
684  }
685  g_markup_parse_context_free (xml_context);
686  g_free (buffer);
687  return -2;
688  }
689  if (context_data.done)
690  {
691  g_markup_parse_context_end_parse (xml_context, &error);
692  if (error)
693  {
694  g_warning (" End error: %s\n", error->message);
695  g_error_free (error);
696  if (context_data.first && context_data.first->data)
697  {
698  free_entity (context_data.first->data);
699  g_slist_free_1 (context_data.first);
700  }
701  if (timeout > 0)
702  fcntl (socket, F_SETFL, 0L);
703  g_markup_parse_context_free (xml_context);
704  g_free (buffer);
705  return -2;
706  }
707  if (entity)
708  *entity = (entity_t) context_data.first->data;
709  if (string)
710  *string_return = string;
711  if (timeout > 0)
712  fcntl (socket, F_SETFL, 0L);
713  g_markup_parse_context_free (xml_context);
714  g_free (buffer);
715  return 0;
716  }
717 
718  if ((timeout > 0) && (time (&last_time) == -1))
719  {
720  g_warning (" failed to get current time (1): %s\n",
721  strerror (errno));
722  if (fcntl (socket, F_SETFL, 0L) < 0)
723  g_warning ("%s :failed to set socket flag: %s", __FUNCTION__,
724  strerror (errno));
725  g_markup_parse_context_free (xml_context);
726  g_free (buffer);
727  return -1;
728  }
729  }
730 }

References BUFFER_SIZE, context_data_t::current, context_data_t::done, context_data_t::first, free_entity(), handle_end_element(), handle_error(), handle_start_element(), handle_text(), ignore_end_element(), ignore_start_element(), and ignore_text().

Referenced by read_entity_and_string(), read_entity_and_string_c(), try_read_entity(), and try_read_entity_c().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_read_entity_and_string_s()

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.

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.

Definition at line 748 of file xmlutils.c.

750 {
751  GMarkupParser xml_parser;
752  GError *error = NULL;
753  GMarkupParseContext *xml_context;
754  GString *string;
755  time_t last_time;
756  /* Buffer for reading from the socket. */
757  char *buffer;
758 
759  /* Record the start time. */
760 
761  if (time (&last_time) == -1)
762  {
763  g_warning (" failed to get current time: %s\n", strerror (errno));
764  return -1;
765  }
766 
767  if (timeout > 0)
768  {
769  /* Turn off blocking. */
770 
771  if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
772  return -1;
773  }
774 
775  buffer = g_malloc0 (BUFFER_SIZE);
776 
777  /* Setup return arg. */
778 
779  if (string_return == NULL)
780  string = NULL;
781  else if (*string_return == NULL)
782  string = g_string_new ("");
783  else
784  string = *string_return;
785 
786  /* Create the XML parser. */
787 
788  if (entity)
789  {
790  xml_parser.start_element = handle_start_element;
791  xml_parser.end_element = handle_end_element;
792  xml_parser.text = handle_text;
793  }
794  else
795  {
796  xml_parser.start_element = ignore_start_element;
797  xml_parser.end_element = ignore_end_element;
798  xml_parser.text = ignore_text;
799  }
800  xml_parser.passthrough = NULL;
801  xml_parser.error = handle_error;
802 
803  context_data_t context_data;
804  context_data.done = FALSE;
805  context_data.first = NULL;
806  context_data.current = NULL;
807 
808  /* Setup the XML context. */
809 
810  xml_context =
811  g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
812 
813  /* Read and parse, until encountering end of file or error. */
814 
815  while (1)
816  {
817  int count;
818  while (1)
819  {
820  g_debug (" asking for %i\n", BUFFER_SIZE);
821  count = read (socket, buffer, BUFFER_SIZE);
822  if (count < 0)
823  {
824  if (errno == EINTR)
825  /* Interrupted, try read again. */
826  continue;
827  if (timeout > 0)
828  {
829  if (errno == EAGAIN)
830  {
831  /* Server still busy, either timeout or try read again. */
832  if ((timeout - (time (NULL) - last_time)) <= 0)
833  {
834  g_warning (" timeout\n");
835  if (fcntl (socket, F_SETFL, 0L) < 0)
836  g_warning ("%s :failed to set socket flag: %s",
837  __FUNCTION__, strerror (errno));
838  g_markup_parse_context_free (xml_context);
839  g_free (buffer);
840  if (string && *string_return == NULL)
841  g_string_free (string, TRUE);
842  return -4;
843  }
844  }
845  continue;
846  }
847  if (context_data.first && context_data.first->data)
848  {
849  free_entity (context_data.first->data);
850  g_slist_free_1 (context_data.first);
851  }
852  if (string && *string_return == NULL)
853  g_string_free (string, TRUE);
854  if (timeout > 0)
855  fcntl (socket, F_SETFL, 0L);
856  g_markup_parse_context_free (xml_context);
857  g_free (buffer);
858  return -1;
859  }
860  if (count == 0)
861  {
862  /* End of file. */
863  g_markup_parse_context_end_parse (xml_context, &error);
864  if (error)
865  {
866  g_warning (" End error: %s\n", error->message);
867  g_error_free (error);
868  }
869  if (context_data.first && context_data.first->data)
870  {
871  free_entity (context_data.first->data);
872  g_slist_free_1 (context_data.first);
873  }
874  if (string && *string_return == NULL)
875  g_string_free (string, TRUE);
876  if (timeout > 0)
877  {
878  if (fcntl (socket, F_SETFL, 0L) < 0)
879  g_warning ("%s :failed to set socket flag: %s",
880  __FUNCTION__, strerror (errno));
881  }
882  g_markup_parse_context_free (xml_context);
883  g_free (buffer);
884  return -3;
885  }
886  break;
887  }
888 
889  g_debug ("<= %.*s\n", (int) count, buffer);
890 
891  if (string)
892  g_string_append_len (string, buffer, count);
893 
894  g_markup_parse_context_parse (xml_context, buffer, count, &error);
895  if (error)
896  {
897  g_error_free (error);
898  // FIX there may be multiple entries in list
899  if (context_data.first && context_data.first->data)
900  {
901  free_entity (context_data.first->data);
902  g_slist_free_1 (context_data.first);
903  }
904  if (string && *string_return == NULL)
905  g_string_free (string, TRUE);
906  if (timeout > 0)
907  {
908  if (fcntl (socket, F_SETFL, 0L) < 0)
909  g_warning ("%s :failed to set socket flag: %s", __FUNCTION__,
910  strerror (errno));
911  }
912  g_markup_parse_context_free (xml_context);
913  g_free (buffer);
914  return -2;
915  }
916  if (context_data.done)
917  {
918  g_markup_parse_context_end_parse (xml_context, &error);
919  if (error)
920  {
921  g_warning (" End error: %s\n", error->message);
922  g_error_free (error);
923  if (context_data.first && context_data.first->data)
924  {
925  free_entity (context_data.first->data);
926  g_slist_free_1 (context_data.first);
927  }
928  if (timeout > 0)
929  fcntl (socket, F_SETFL, 0L);
930  g_markup_parse_context_free (xml_context);
931  g_free (buffer);
932  if (string && *string_return == NULL)
933  g_string_free (string, TRUE);
934  return -2;
935  }
936  if (entity)
937  *entity = (entity_t) context_data.first->data;
938  if (string)
939  *string_return = string;
940  if (timeout > 0)
941  fcntl (socket, F_SETFL, 0L);
942  g_slist_free (context_data.first);
943  g_markup_parse_context_free (xml_context);
944  g_free (buffer);
945  return 0;
946  }
947 
948  if ((timeout > 0) && (time (&last_time) == -1))
949  {
950  g_warning (" failed to get current time (1): %s\n",
951  strerror (errno));
952  if (fcntl (socket, F_SETFL, 0L) < 0)
953  g_warning ("%s :failed to set server socket flag: %s", __FUNCTION__,
954  strerror (errno));
955  g_markup_parse_context_free (xml_context);
956  g_free (buffer);
957  if (string && *string_return == NULL)
958  g_string_free (string, TRUE);
959  return -1;
960  }
961  }
962 }

References BUFFER_SIZE, context_data_t::current, context_data_t::done, context_data_t::first, free_entity(), handle_end_element(), handle_error(), handle_start_element(), handle_text(), ignore_end_element(), ignore_start_element(), and ignore_text().

Referenced by read_entity_and_string_c(), read_entity_s(), and try_read_entity_c().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 1132 of file xmlutils.c.

1133 {
1134  if (connection->tls)
1135  return try_read_entity_and_string (&connection->session, 0, entity, NULL);
1136  return try_read_entity_and_string_s (connection->socket, timeout, entity,
1137  NULL);
1138 }

References gvm_connection_t::session, gvm_connection_t::socket, gvm_connection_t::tls, try_read_entity_and_string(), and try_read_entity_and_string_s().

Referenced by gmp_authenticate_info_ext_c(), gmp_ping_c(), and read_entity_c().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xml_count_entities()

int xml_count_entities ( entities_t  entities)

Count the number of entities.

Parameters
[in]entitiesEntities.
Returns
Number of entities.

Definition at line 1506 of file xmlutils.c.

1507 {
1508  int count = 0;
1509  while (first_entity (entities))
1510  {
1511  entities = next_entities (entities);
1512  count++;
1513  }
1514  return count;
1515 }

References first_entity(), and next_entities().

Here is the call graph for this function:

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

Definition at line 416 of file xmlutils.c.

417 {
418  handle_end_element (NULL, element_name, context, NULL);
419 }

References element_name(), and handle_end_element().

Here is the call graph for this function:

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

Definition at line 340 of file xmlutils.c.

343 {
344  return handle_start_element (NULL, element_name, attribute_names,
345  attribute_values, context, NULL);
346 }

References element_name(), and handle_start_element().

Here is the call graph for this function:

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

Definition at line 478 of file xmlutils.c.

479 {
480  handle_text (NULL, text, text_len, context, NULL);
481 }

References handle_text().

Here is the call graph for this function:

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

Definition at line 1552 of file xmlutils.c.

1557 {
1558  (void) ctx;
1559  (void) error;
1560 
1561  xml_search_data_t *search_data = ((xml_search_data_t *) data);
1562 
1563  if (strcmp (element_name, search_data->find_element) == 0
1564  && search_data->found == 0)
1565  {
1566  g_debug ("%s: Found element <%s>", __FUNCTION__, element_name);
1567 
1568  if (search_data->find_attributes
1569  && g_hash_table_size (search_data->find_attributes))
1570  {
1571  int index;
1572  GHashTable *found_attributes;
1573  found_attributes =
1574  g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
1575  index = 0;
1576  while (attribute_names[index])
1577  {
1578  gchar *searched_value;
1579  searched_value = g_hash_table_lookup (
1580  search_data->find_attributes, attribute_names[index]);
1581  if (searched_value
1582  && strcmp (searched_value, attribute_values[index]) == 0)
1583  {
1584  g_debug ("%s: Found attribute %s=\"%s\"", __FUNCTION__,
1585  attribute_names[index], searched_value);
1586  g_hash_table_add (found_attributes, searched_value);
1587  }
1588  index++;
1589  }
1590  g_debug ("%s: Found %d of %d attributes", __FUNCTION__,
1591  g_hash_table_size (found_attributes),
1592  g_hash_table_size (search_data->find_attributes));
1593 
1594  if (g_hash_table_size (found_attributes)
1595  == g_hash_table_size (search_data->find_attributes))
1596  {
1597  search_data->found = 1;
1598  }
1599 
1600  g_hash_table_destroy (found_attributes);
1601  }
1602  else
1603  {
1604  search_data->found = 1;
1605  }
1606  }
1607 }

References element_name(), xml_search_data_t::find_attributes, xml_search_data_t::find_element, and xml_search_data_t::found.

Referenced by find_element_in_xml_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.
Returns
Result of XSL transformation.

Definition at line 1527 of file xmlutils.c.

1528 {
1529  gchar *piece;
1530  va_list args;
1531 
1532  va_start (args, format);
1533  piece = g_markup_vprintf_escaped (format, args);
1534  va_end (args);
1535  g_string_append (xml, piece);
1536  g_free (piece);
1537 }

Referenced by credential_append_as_xml(), gmp_get_system_reports_ext(), osp_start_scan_ext(), target_append_as_xml(), vt_group_append_as_xml(), vt_single_append_as_xml(), and vt_value_append_as_xml().

Here is the caller graph for this function:
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)
Handle the opening tag of an element in an XML search.
Definition: xmlutils.c:1552
BUFFER_SIZE
#define BUFFER_SIZE
Size of the buffer for reading from the manager.
Definition: xmlutils.c:51
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.
Definition: xmlutils.c:514
compare_find_attribute
gboolean compare_find_attribute(gpointer key, gpointer value, gpointer attributes2)
Look for a key-value pair in a hash table.
Definition: xmlutils.c:1423
context_data_t
XML context.
Definition: xmlutils.h:40
add_attributes
void add_attributes(entity_t entity, const gchar **names, const gchar **values)
Add attributes from an XML callback to an entity.
Definition: xmlutils.c:248
handle_end_element
static void handle_end_element(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)
Handle the end of an XML element.
Definition: xmlutils.c:380
first_entity
entity_t first_entity(entities_t entities)
Return the first entity from an entities_t.
Definition: xmlutils.c:96
entity_s::entities
entities_t entities
Children.
Definition: xmlutils.h:70
foreach_print_entity_to_string
static void foreach_print_entity_to_string(gpointer entity, gpointer string)
Print an XML entity for g_slist_foreach to a GString.
Definition: xmlutils.c:1261
entity_s::name
char * name
Name.
Definition: xmlutils.h:67
print_entity_format
void print_entity_format(entity_t entity, gpointer indent)
Print an XML entity to stdout, recursively printing its children.
Definition: xmlutils.c:1382
handle_text
static void handle_text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
Handle additional text of an XML element.
Definition: xmlutils.c:451
entity_name
char * entity_name(entity_t entity)
Get the name an entity.
Definition: xmlutils.c:175
entity_s::attributes
GHashTable * attributes
Attributes.
Definition: xmlutils.h:69
free_entity
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xmlutils.c:129
compare_entity_with_name
int compare_entity_with_name(gconstpointer entity, gconstpointer name)
Compare a given name with the name of a given entity.
Definition: xmlutils.c:193
XML_FILE_BUFFER_SIZE
#define XML_FILE_BUFFER_SIZE
Definition: xmlutils.c:1609
next_entities
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
Definition: xmlutils.c:81
foreach_print_attribute_to_string
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.
Definition: xmlutils.c:1274
xml_search_data_t::find_attributes
GHashTable * find_attributes
Definition: xmlutils.h:82
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.
Definition: xmlutils.c:998
foreach_print_attribute_format
static void foreach_print_attribute_format(gpointer name, gpointer value, gpointer none)
Print an XML attribute for g_hash_table_foreach to stdout.
Definition: xmlutils.c:1364
add_entity
entity_t add_entity(entities_t *entities, const char *name, const char *text)
Add an XML entity to a tree of entities.
Definition: xmlutils.c:115
handle_error
void handle_error(GMarkupParseContext *context, GError *error, gpointer user_data)
Handle an OMP XML parsing error.
Definition: xmlutils.c:491
gvm_connection_t::socket
int socket
Socket.
Definition: serverutils.h:46
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.
Definition: xmlutils.c:1116
element_t
struct _xmlNode * element_t
Definition: xmlutils.h:170
gvm_connection_t::tls
int tls
Whether uses TCP-TLS (vs UNIX socket).
Definition: serverutils.h:45
foreach_print_attribute
static void foreach_print_attribute(gpointer name, gpointer value, gpointer stream)
Print an XML attribute for g_hash_table_foreach.
Definition: xmlutils.c:1327
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)
Handle the start of an OMP XML element.
Definition: xmlutils.c:304
xml_search_data_t::find_element
gchar * find_element
Definition: xmlutils.h:81
context_data_t::current
GSList * current
The element currently being parsed.
Definition: xmlutils.h:43
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)
Handle the start of an OMP XML element.
Definition: xmlutils.c:277
context_data_t::done
gboolean done
Flag which is true when the first element is closed.
Definition: xmlutils.h:44
find_child
static element_t find_child(element_t element, const gchar *name)
Find child in an element.
Definition: xmlutils.c:1748
element_name
const gchar * element_name(element_t element)
Get the name of an element.
Definition: xmlutils.c:1730
foreach_print_entity
static void foreach_print_entity(gpointer entity, gpointer stream)
Print an XML entity for g_slist_foreach.
Definition: xmlutils.c:1314
entity_s
XML element.
Definition: xmlutils.h:65
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.
Definition: xmlutils.c:978
entity_s::text
char * text
Text.
Definition: xmlutils.h:68
xml_search_data_t
Data for xml search functions.
Definition: xmlutils.h:77
make_entity
entity_t make_entity(const char *name, const char *text)
Create an entity.
Definition: xmlutils.c:62
xml_search_data_t::found
int found
Definition: xmlutils.h:79
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.
Definition: xmlutils.c:1132
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:1292
ignore_text
static void ignore_text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
Handle additional text of an XML element.
Definition: xmlutils.c:431
ignore_end_element
static void ignore_end_element(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)
Handle the end of an XML element.
Definition: xmlutils.c:357
compare_entities
int compare_entities(entity_t entity1, entity_t entity2)
Compare two XML entity.
Definition: xmlutils.c:1441
context_data_t::first
GSList * first
The very first entity.
Definition: xmlutils.h:42
entity_t
struct entity_s * entity_t
Definition: xmlutils.h:72
gvm_connection_t::session
gnutls_session_t session
Session.
Definition: serverutils.h:47
print_entity
void print_entity(FILE *stream, entity_t entity)
Print an XML entity.
Definition: xmlutils.c:1339
try_read_entity_and_string_s
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.
Definition: xmlutils.c:748
entities_t
GSList * entities_t
Entities.
Definition: xmlutils.h:60