Greenbone Vulnerability Management Libraries  11.0.1
xmlutils.h File Reference

Headers for simple XML reader. More...

#include "serverutils.h"
#include <glib.h>
#include <gnutls/gnutls.h>
#include <stdio.h>
Include dependency graph for xmlutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  context_data_t
 XML context. More...
 
struct  entity_s
 XML element. More...
 
struct  xml_search_data_t
 Data for xml search functions. More...
 

Typedefs

typedef GSList * entities_t
 Entities. More...
 
typedef struct entity_sentity_t
 
typedef struct _xmlNode * element_t
 

Functions

void xml_handle_start_element (context_data_t *, const gchar *, const gchar **, const gchar **)
 Handle the start of an OMP XML element. More...
 
void xml_handle_end_element (context_data_t *, const gchar *)
 Handle the end of an XML element. More...
 
void xml_handle_text (context_data_t *, const gchar *, gsize)
 Handle additional text of an XML element. More...
 
entities_t next_entities (entities_t)
 Return all the entities from an entities_t after the first. More...
 
entity_t first_entity (entities_t)
 Return the first entity from an entities_t. More...
 
entity_t add_entity (entities_t *, const char *, const char *)
 Add an XML entity to a tree of entities. More...
 
int compare_entities (entity_t, entity_t)
 Compare two XML entity. More...
 
entity_t entity_child (entity_t, const char *)
 Get a child of an entity. More...
 
const char * entity_attribute (entity_t, const char *)
 Get an attribute of an entity. More...
 
char * entity_name (entity_t entity)
 Get the name an entity. More...
 
char * entity_text (entity_t entity)
 Get the text an entity. More...
 
void free_entity (entity_t)
 Free an entity, recursively. More...
 
void print_entity (FILE *, entity_t)
 Print an XML entity. More...
 
void print_entity_format (entity_t, gpointer indentation)
 Print an XML entity to stdout, recursively printing its children. More...
 
int try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int read_entity_and_string (gnutls_session_t *, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int read_entity_and_string_c (gvm_connection_t *, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int read_entity_and_text (gnutls_session_t *, entity_t *, char **)
 Read an XML entity tree from the manager. More...
 
int read_entity_and_text_c (gvm_connection_t *, entity_t *, char **)
 Read an XML entity tree from the manager. More...
 
int try_read_entity (gnutls_session_t *, int, entity_t *)
 Try read an XML entity tree from the manager. More...
 
int try_read_entity_c (gvm_connection_t *, int, entity_t *)
 Try read an XML entity tree from the manager. More...
 
int read_entity (gnutls_session_t *, entity_t *)
 Read an XML entity tree from the manager. More...
 
int read_entity_s (int, entity_t *)
 Read an XML entity tree from the socket. More...
 
int read_entity_c (gvm_connection_t *, entity_t *)
 Read an XML entity tree from the manager. More...
 
int read_string (gnutls_session_t *, GString **)
 Read entity and text. Free the entity immediately. More...
 
int read_string_c (gvm_connection_t *, GString **)
 Read entity and text. Free the entity immediately. More...
 
int parse_entity (const char *, entity_t *)
 Read an XML entity tree from a string. 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...
 
int xml_count_entities (entities_t)
 Count the number of entities. More...
 
void xml_string_append (GString *, const char *,...)
 Append formatted escaped XML to a string. More...
 
int find_element_in_xml_file (gchar *, gchar *, GHashTable *)
 Tests if an XML file contains an element with given attributes. More...
 
int parse_element (const gchar *, element_t *)
 Read an XML element tree from a string. More...
 
void element_free (element_t)
 Free an entire element tree. More...
 
const gchar * element_name (element_t)
 Get the name of an element. More...
 
gchar * element_attribute (element_t, const gchar *)
 Get an attribute of an element. More...
 
gchar * element_text (element_t)
 Get text of an element. More...
 
element_t element_child (element_t, const gchar *)
 Get a child of an element. More...
 
element_t element_first_child (element_t)
 Get the first child of an element. More...
 
element_t element_next (element_t)
 Get the next sibling of an element. More...
 

Detailed Description

Headers for simple XML reader.

Definition in file xmlutils.h.

Typedef Documentation

◆ element_t

typedef struct _xmlNode* element_t

Definition at line 170 of file xmlutils.h.

◆ entities_t

typedef GSList* entities_t

Entities.

Definition at line 60 of file xmlutils.h.

◆ entity_t

typedef struct entity_s* entity_t

Definition at line 72 of file xmlutils.h.

Function Documentation

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

◆ 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_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:

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

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