21#include <glib/gtypes.h>
22#include <libxml/parser.h>
23#include <libxml/tree.h>
32#define G_LOG_DOMAIN "libgvm util"
37#define BUFFER_SIZE 1048576
51 entity = g_malloc (
sizeof (*entity));
52 entity->
name = g_strdup (name ? name :
"");
53 entity->
text = g_strdup (text ? text :
"");
105 *entities = g_slist_append (*entities, entity);
119 g_free (entity->
name);
120 g_free (entity->
text);
202 return match ? (
entity_t) match->data : NULL;
222 return (
const char *) g_hash_table_lookup (entity->
attributes, name);
236 if (names && values && *names && *values)
240 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
241 while (*names && *values)
244 g_hash_table_insert (entity->
attributes, g_strdup (*names),
264 const gchar **attribute_names,
265 const gchar **attribute_values, gpointer user_data,
272 (void) attribute_names;
273 (void) attribute_values;
276 data->
current = GINT_TO_POINTER (GPOINTER_TO_INT (data->
current) + 1);
291 const gchar **attribute_names,
292 const gchar **attribute_values, gpointer user_data,
311 if (data->
first == NULL)
312 data->
current = data->
first = g_slist_prepend (NULL, entity);
327 const gchar **attribute_names,
328 const gchar **attribute_values)
344 gpointer user_data, GError **error)
352 data->
current = GINT_TO_POINTER (GPOINTER_TO_INT (data->
current) - 1);
367 gpointer user_data, GError **error)
391 g_slist_free_1 (front);
417ignore_text (GMarkupParseContext *context,
const gchar *text, gsize text_len,
418 gpointer user_data, GError **error)
437handle_text (GMarkupParseContext *context,
const gchar *text, gsize text_len,
438 gpointer user_data, GError **error)
448 gchar *old = current->
text;
449 current->
text = g_strconcat (current->
text, text, NULL);
453 current->
text = g_strdup (text);
477handle_error (GMarkupParseContext *context, GError *error, gpointer user_data)
481 g_message (
" Error: %s\n", error->message);
502 entity_t *entity, GString **string_return)
504 GMarkupParser xml_parser;
505 GError *error = NULL;
506 GMarkupParseContext *xml_context;
516 if (time (&last_time) == -1)
518 g_warning (
" failed to get current time: %s\n", strerror (errno));
526 socket = GPOINTER_TO_INT (gnutls_transport_get_ptr (*session));
527 if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
540 if (string_return == NULL)
542 else if (*string_return == NULL)
543 string = g_string_new (
"");
545 string = *string_return;
561 xml_parser.passthrough = NULL;
565 context_data.
done = FALSE;
566 context_data.
first = NULL;
572 g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
583 count = gnutls_record_recv (*session, buffer,
BUFFER_SIZE);
586 if (count == GNUTLS_E_INTERRUPTED)
589 if ((timeout > 0) && (count == GNUTLS_E_AGAIN))
592 if ((timeout - (time (NULL) - last_time)) <= 0)
594 g_warning (
" timeout\n");
595 if (fcntl (socket, F_SETFL, 0L) < 0)
596 g_warning (
"%s :failed to set socket flag: %s",
597 __func__, strerror (errno));
598 g_markup_parse_context_free (xml_context);
604 else if ((timeout == 0) && (count == GNUTLS_E_AGAIN))
612 retries = retries - 1;
617 if (count == GNUTLS_E_REHANDSHAKE)
620 if (context_data.
first && context_data.
first->data)
623 g_slist_free_1 (context_data.
first);
625 if (
string && *string_return == NULL)
626 g_string_free (
string, TRUE);
629 if (fcntl (socket, F_SETFL, 0L) < 0)
630 g_warning (
"%s :failed to set socket flag: %s", __func__,
633 g_markup_parse_context_free (xml_context);
640 g_markup_parse_context_end_parse (xml_context, &error);
643 g_warning (
" End error: %s\n", error->message);
644 g_error_free (error);
646 if (context_data.
first && context_data.
first->data)
649 g_slist_free_1 (context_data.
first);
651 if (
string && *string_return == NULL)
652 g_string_free (
string, TRUE);
655 if (fcntl (socket, F_SETFL, 0L) < 0)
656 g_warning (
"%s :failed to set socket flag: %s", __func__,
659 g_markup_parse_context_free (xml_context);
666 g_debug (
"<= %.*s\n", (
int) count, buffer);
669 g_string_append_len (
string, buffer, count);
671 g_markup_parse_context_parse (xml_context, buffer, count, &error);
674 g_error_free (error);
675 if (context_data.
first && context_data.
first->data)
678 g_slist_free_1 (context_data.
first);
680 if (
string && *string_return == NULL)
681 g_string_free (
string, TRUE);
684 if (fcntl (socket, F_SETFL, 0L) < 0)
685 g_warning (
"%s :failed to set socket flag: %s", __func__,
688 g_markup_parse_context_free (xml_context);
692 if (context_data.
done)
694 g_markup_parse_context_end_parse (xml_context, &error);
697 g_warning (
" End error: %s\n", error->message);
698 g_error_free (error);
699 if (context_data.
first && context_data.
first->data)
702 g_slist_free_1 (context_data.
first);
705 fcntl (socket, F_SETFL, 0L);
706 g_markup_parse_context_free (xml_context);
713 *string_return = string;
715 fcntl (socket, F_SETFL, 0L);
716 g_markup_parse_context_free (xml_context);
721 if ((timeout > 0) && (time (&last_time) == -1))
723 g_warning (
" failed to get current time (1): %s\n",
725 if (fcntl (socket, F_SETFL, 0L) < 0)
726 g_warning (
"%s :failed to set socket flag: %s", __func__,
728 g_markup_parse_context_free (xml_context);
753 GString **string_return)
762 if (time (&last_time) == -1)
764 g_warning (
" failed to get current time: %s\n", strerror (errno));
772 socket = GPOINTER_TO_INT (gnutls_transport_get_ptr (*session));
773 if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
786 if (string_return == NULL)
788 else if (*string_return == NULL)
789 string = g_string_new (
"");
791 string = *string_return;
802 count = gnutls_record_recv (*session, buffer,
BUFFER_SIZE);
805 if (count == GNUTLS_E_INTERRUPTED)
808 if ((timeout > 0) && (count == GNUTLS_E_AGAIN))
811 if ((timeout - (time (NULL) - last_time)) <= 0)
813 g_warning (
" timeout\n");
814 if (fcntl (socket, F_SETFL, 0L) < 0)
815 g_warning (
"%s: failed to set socket flag: %s",
816 __func__, strerror (errno));
822 else if ((timeout == 0) && (count == GNUTLS_E_AGAIN))
830 retries = retries - 1;
835 if (count == GNUTLS_E_REHANDSHAKE)
838 if (
string && (*string_return == NULL))
839 g_string_free (
string, TRUE);
842 if (fcntl (socket, F_SETFL, 0L) < 0)
843 g_warning (
"%s: failed to set socket flag: %s", __func__,
854 if (fcntl (socket, F_SETFL, 0L) < 0)
855 g_warning (
"%s :failed to set socket flag: %s", __func__,
859 *string_return = string;
866 g_debug (
"<= %.*s\n", (
int) count, buffer);
869 g_string_append_len (
string, buffer, count);
871 if ((timeout > 0) && (time (&last_time) == -1))
873 g_warning (
" failed to get current time (1): %s\n",
875 if (fcntl (socket, F_SETFL, 0L) < 0)
876 g_warning (
"%s :failed to set socket flag: %s", __func__,
910 if (time (&last_time) == -1)
912 g_warning (
" failed to get current time: %s\n", strerror (errno));
920 if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
930 if (string_return == NULL)
932 else if (*string_return == NULL)
933 string = g_string_sized_new (8192);
935 string = *string_return;
956 if ((timeout - (time (NULL) - last_time)) <= 0)
958 g_warning (
" timeout\n");
959 if (fcntl (socket, F_SETFL, 0L) < 0)
960 g_warning (
"%s :failed to set socket flag: %s",
961 __func__, strerror (errno));
963 if (
string && *string_return == NULL)
964 g_string_free (
string, TRUE);
970 if (
string && *string_return == NULL)
971 g_string_free (
string, TRUE);
973 fcntl (socket, F_SETFL, 0L);
982 if (fcntl (socket, F_SETFL, 0L) < 0)
983 g_warning (
"%s :failed to set socket flag: %s", __func__,
987 *string_return = string;
994 g_debug (
"<= %.*s\n", (
int) count, buffer);
997 g_string_append_len (
string, buffer, count);
999 if ((timeout > 0) && (time (&last_time) == -1))
1001 g_warning (
" failed to get current time (1): %s\n",
1003 if (fcntl (socket, F_SETFL, 0L) < 0)
1004 g_warning (
"%s :failed to set server socket flag: %s", __func__,
1007 if (
string && *string_return == NULL)
1008 g_string_free (
string, TRUE);
1032 GString **string_return)
1034 GMarkupParser xml_parser;
1035 GError *error = NULL;
1036 GMarkupParseContext *xml_context;
1044 if (time (&last_time) == -1)
1046 g_warning (
" failed to get current time: %s\n", strerror (errno));
1054 if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
1064 if (string_return == NULL)
1066 else if (*string_return == NULL)
1067 string = g_string_new (
"");
1069 string = *string_return;
1085 xml_parser.passthrough = NULL;
1089 context_data.
done = FALSE;
1090 context_data.
first = NULL;
1096 g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
1114 if (errno == EAGAIN)
1117 if ((timeout - (time (NULL) - last_time)) <= 0)
1119 g_warning (
" timeout\n");
1120 if (fcntl (socket, F_SETFL, 0L) < 0)
1121 g_warning (
"%s :failed to set socket flag: %s",
1122 __func__, strerror (errno));
1123 g_markup_parse_context_free (xml_context);
1125 if (
string && *string_return == NULL)
1126 g_string_free (
string, TRUE);
1132 if (context_data.
first && context_data.
first->data)
1135 g_slist_free_1 (context_data.
first);
1137 if (
string && *string_return == NULL)
1138 g_string_free (
string, TRUE);
1140 fcntl (socket, F_SETFL, 0L);
1141 g_markup_parse_context_free (xml_context);
1148 g_markup_parse_context_end_parse (xml_context, &error);
1151 g_warning (
" End error: %s\n", error->message);
1152 g_error_free (error);
1154 if (context_data.
first && context_data.
first->data)
1157 g_slist_free_1 (context_data.
first);
1159 if (
string && *string_return == NULL)
1160 g_string_free (
string, TRUE);
1163 if (fcntl (socket, F_SETFL, 0L) < 0)
1164 g_warning (
"%s :failed to set socket flag: %s", __func__,
1167 g_markup_parse_context_free (xml_context);
1174 g_debug (
"<= %.*s\n", (
int) count, buffer);
1177 g_string_append_len (
string, buffer, count);
1179 g_markup_parse_context_parse (xml_context, buffer, count, &error);
1182 g_error_free (error);
1184 if (context_data.
first && context_data.
first->data)
1187 g_slist_free_1 (context_data.
first);
1189 if (
string && *string_return == NULL)
1190 g_string_free (
string, TRUE);
1193 if (fcntl (socket, F_SETFL, 0L) < 0)
1194 g_warning (
"%s :failed to set socket flag: %s", __func__,
1197 g_markup_parse_context_free (xml_context);
1201 if (context_data.
done)
1203 g_markup_parse_context_end_parse (xml_context, &error);
1206 g_warning (
" End error: %s\n", error->message);
1207 g_error_free (error);
1208 if (context_data.
first && context_data.
first->data)
1211 g_slist_free_1 (context_data.
first);
1214 fcntl (socket, F_SETFL, 0L);
1215 g_markup_parse_context_free (xml_context);
1217 if (
string && *string_return == NULL)
1218 g_string_free (
string, TRUE);
1224 *string_return = string;
1226 fcntl (socket, F_SETFL, 0L);
1227 g_slist_free (context_data.
first);
1228 g_markup_parse_context_free (xml_context);
1233 if ((timeout > 0) && (time (&last_time) == -1))
1235 g_warning (
" failed to get current time (1): %s\n",
1237 if (fcntl (socket, F_SETFL, 0L) < 0)
1238 g_warning (
"%s :failed to set server socket flag: %s", __func__,
1240 g_markup_parse_context_free (xml_context);
1242 if (
string && *string_return == NULL)
1243 g_string_free (
string, TRUE);
1264 GString **string_return)
1284 GString **string_return)
1286 if (connection->
tls)
1310 GString *
string = NULL;
1315 g_string_free (
string, TRUE);
1318 *text = g_string_free (
string, FALSE);
1342 GString *
string = NULL;
1347 g_string_free (
string, TRUE);
1350 *text = g_string_free (
string, FALSE);
1377 if (connection->
tls)
1385 g_string_free (
string, TRUE);
1388 *text = g_string_free (
string, FALSE);
1455 if (connection->
tls)
1514 GMarkupParser xml_parser;
1515 GError *error = NULL;
1516 GMarkupParseContext *xml_context;
1524 xml_parser.passthrough = NULL;
1527 context_data.
done = FALSE;
1528 context_data.
first = NULL;
1534 g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
1538 g_markup_parse_context_parse (xml_context,
string, strlen (
string), &error);
1541 g_error_free (error);
1542 if (context_data.
first && context_data.
first->data)
1545 g_slist_free_1 (context_data.
first);
1549 if (context_data.
done)
1551 g_markup_parse_context_end_parse (xml_context, &error);
1554 g_warning (
" End error: %s\n", error->message);
1555 g_error_free (error);
1556 if (context_data.
first && context_data.
first->data)
1559 g_slist_free_1 (context_data.
first);
1564 g_slist_free_1 (context_data.
first);
1567 if (context_data.
first && context_data.
first->data)
1570 g_slist_free_1 (context_data.
first);
1598 gchar *text_escaped;
1599 text_escaped = g_markup_escape_text ((gchar *) value, -1);
1600 g_string_append_printf ((GString *)
string,
" %s=\"%s\"", (
char *) name,
1602 g_free (text_escaped);
1615 gchar *text_escaped = NULL;
1616 g_string_append_printf (
string,
"<%s", entity->
name);
1620 g_string_append_printf (
string,
">");
1621 text_escaped = g_markup_escape_text (entity->
text, -1);
1622 g_string_append_printf (
string,
"%s", text_escaped);
1623 g_free (text_escaped);
1625 g_string_append_printf (
string,
"</%s>", entity->
name);
1650 fprintf ((FILE *) stream,
" %s=\"%s\"", (
char *) name, (
char *) value);
1662 gchar *text_escaped = NULL;
1663 fprintf (stream,
"<%s", entity->
name);
1666 fprintf (stream,
">");
1667 text_escaped = g_markup_escape_text (entity->
text, -1);
1668 fprintf (stream,
"%s", text_escaped);
1669 g_free (text_escaped);
1671 fprintf (stream,
"</%s>", entity->
name);
1688 printf (
" %s=\"%s\"", (
char *) name, (
char *) value);
1706 int indentation = GPOINTER_TO_INT (indent);
1707 gchar *text_escaped = NULL;
1709 for (i = 0; i < indentation; i++)
1712 printf (
"<%s", entity->
name);
1718 text_escaped = g_markup_escape_text (entity->
text, -1);
1719 printf (
"%s", text_escaped);
1720 g_free (text_escaped);
1726 GINT_TO_POINTER (indentation + 1));
1727 for (i = 0; i < indentation; i++)
1731 printf (
"</%s>\n", entity->
name);
1746 gchar *value2 = g_hash_table_lookup (attributes2, key);
1747 if (value2 && strcmp (value, value2) == 0)
1749 g_debug (
" compare failed attribute: %s\n", (
char *) value);
1764 if (entity1 == NULL)
1765 return entity2 == NULL ? 0 : 1;
1766 if (entity2 == NULL)
1769 if (strcmp (entity1->
name, entity2->
name))
1771 g_debug (
" compare failed name: %s vs %s\n", entity1->
name,
1775 if (strcmp (entity1->
text, entity2->
text))
1777 g_debug (
" compare failed text %s vs %s (%s)\n", entity1->
text,
1794 g_debug (
" compare failed attributes\n");
1802 while (list1 && list2)
1806 g_debug (
" compare failed subentity\n");
1809 list1 = g_slist_next (list1);
1810 list2 = g_slist_next (list2);
1815 g_debug (
" compare failed number of entities (%s)\n", entity1->
name);
1853 va_start (args, format);
1854 piece = g_markup_vprintf_escaped (format, args);
1856 g_string_append (xml, piece);
1875 const gchar **attribute_names,
1876 const gchar **attribute_values, gpointer data,
1885 && search_data->
found == 0)
1887 g_debug (
"%s: Found element <%s>", __func__,
element_name);
1893 GHashTable *found_attributes;
1895 g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
1897 while (attribute_names[index])
1899 gchar *searched_value;
1900 searched_value = g_hash_table_lookup (
1903 && strcmp (searched_value, attribute_values[index]) == 0)
1905 g_debug (
"%s: Found attribute %s=\"%s\"", __func__,
1906 attribute_names[index], searched_value);
1907 g_hash_table_add (found_attributes, searched_value);
1911 g_debug (
"%s: Found %d of %d attributes", __func__,
1912 g_hash_table_size (found_attributes),
1915 if (g_hash_table_size (found_attributes)
1918 search_data->
found = 1;
1921 g_hash_table_destroy (found_attributes);
1925 search_data->
found = 1;
1930#define XML_FILE_BUFFER_SIZE 1048576
1942 GHashTable *find_attributes)
1947 GMarkupParser xml_parser;
1948 GMarkupParseContext *xml_context;
1950 GError *error = NULL;
1954 search_data.
found = 0;
1958 xml_parser.end_element = NULL;
1959 xml_parser.text = NULL;
1960 xml_parser.passthrough = NULL;
1961 xml_parser.error = NULL;
1962 xml_context = g_markup_parse_context_new (&xml_parser, 0, &search_data, NULL);
1964 file = fopen (file_path,
"r");
1967 g_markup_parse_context_free (xml_context);
1968 g_warning (
"%s: Failed to open '%s':", __func__, strerror (errno));
1973 && g_markup_parse_context_parse (xml_context, buffer, read_len, &error)
1977 g_markup_parse_context_end_parse (xml_context, &error);
1981 g_markup_parse_context_free (xml_context);
1982 return search_data.
found;
1984#undef XML_FILE_BUFFER_SIZE
2011 if (xmlMemSetup (g_free, g_malloc, g_realloc, g_strdup))
2015 xmlReadMemory (
string, strlen (
string),
"noname.xml", NULL, XML_PARSE_HUGE);
2020 *element = xmlDocGetRootElement (doc);
2038 assert (element->doc);
2039 xmlFreeDoc (element->doc);
2053 if (element && (element->type == XML_ELEMENT_NODE))
2054 return (
const gchar *) element->name;
2070 for (xmlNode *node = element->children; node; node = node->next)
2071 if (xmlStrcmp (node->name, (
const xmlChar *) name) == 0)
2087 const gchar *stripped_name;
2092 stripped_name = strchr (name,
':');
2104 if (*stripped_name ==
'\0')
2144 (gchar *) xmlNodeListGetString (element->doc, element->xmlChildrenNode, 1);
2147 string = xmlMalloc (1);
2163 const gchar *stripped_name;
2168 stripped_name = strchr (name,
':');
2180 if (*stripped_name ==
'\0')
2184 return (gchar *) xmlGetProp (element, (
const xmlChar *) name);
2187 (gchar *) xmlGetProp (element, (
const xmlChar *) stripped_name);
2198 return (gchar *) xmlGetProp (element, (
const xmlChar *) name);
2213 element = element->children;
2214 while (element && (element->type != XML_ELEMENT_NODE))
2215 element = element->next;
2233 element = element->next;
2234 while (element && (element->type != XML_ELEMENT_NODE))
2235 element = element->next;
2254 xmlBufferPtr buffer;
2259 element_copy = xmlCopyNode (element, 1);
2261 buffer = xmlBufferCreate ();
2262 xmlNodeDump (buffer, element_copy->doc, element_copy, 0, 0);
2263 xmlFreeNode (element_copy);
2265 xml_string = g_strdup ((
char *) xmlBufferContent (buffer));
2267 xmlBufferFree (buffer);
2281 gchar *text_escaped, *text;
2285 text_escaped = NULL;
2287 g_string_append_printf (
string,
"<%s",
element_name (element));
2289 attribute = element->properties;
2294 value = xmlNodeListGetString (element->doc, attribute->children, 1);
2296 text_escaped = g_markup_escape_text ((gchar *) value, -1);
2297 g_string_append_printf (
string,
" %s=\"%s\"", attribute->name,
2299 g_free (text_escaped);
2303 attribute = attribute->next;
2306 g_string_append_printf (
string,
">");
2309 text_escaped = g_markup_escape_text (text, -1);
2311 g_string_append_printf (
string,
"%s", text_escaped);
2312 g_free (text_escaped);
2321 g_string_append_printf (
string,
"</%s>",
element_name (element));
XML context.
Definition xmlutils.h:27
GSList * first
The very first entity.
Definition xmlutils.h:28
GSList * current
The element currently being parsed.
Definition xmlutils.h:29
gboolean done
Flag which is true when the first element is closed.
Definition xmlutils.h:30
XML element.
Definition xmlutils.h:52
entities_t entities
Children.
Definition xmlutils.h:56
char * text
Text.
Definition xmlutils.h:54
GHashTable * attributes
Attributes.
Definition xmlutils.h:55
char * name
Name.
Definition xmlutils.h:53
Connection.
Definition serverutils.h:30
int tls
Whether uses TCP-TLS (vs UNIX socket).
Definition serverutils.h:31
int socket
Socket.
Definition serverutils.h:32
gnutls_session_t session
Session.
Definition serverutils.h:33
Data for xml search functions.
Definition xmlutils.h:64
gchar * find_element
Definition xmlutils.h:67
GHashTable * find_attributes
Definition xmlutils.h:68
int found
Definition xmlutils.h:65
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:437
static int try_read_string_s(int socket, int timeout, GString **string_return)
Try read an XML entity tree from the socket.
Definition xmlutils.c:901
void element_free(element_t element)
Free an entire element tree.
Definition xmlutils.c:2034
int read_entity_c(gvm_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1498
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.
Definition xmlutils.c:326
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition xmlutils.c:216
int read_string(gnutls_session_t *session, GString **string)
Read entity and text. Free the entity immediately.
Definition xmlutils.c:1401
int read_string_c(gvm_connection_t *connection, GString **string)
Read entity and text. Free the entity immediately.
Definition xmlutils.c:1421
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:417
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.
Definition xmlutils.c:1941
char * entity_name(entity_t entity)
Get the name an entity.
Definition xmlutils.c:161
char * entity_text(entity_t entity)
Get the text an entity.
Definition xmlutils.c:145
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:366
const gchar * element_name(element_t element)
Get the name of an element.
Definition xmlutils.c:2051
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:1873
static int try_read_entity_and_string_s(int socket, int timeout, entity_t *entity, GString **string_return)
Try read an XML entity tree from the socket.
Definition xmlutils.c:1031
static int try_read_string(gnutls_session_t *session, int timeout, GString **string_return)
Try read a response from a TLS session.
Definition xmlutils.c:752
entity_t first_entity(entities_t entities)
Return the first entity from an entities_t.
Definition xmlutils.c:82
gchar * element_text(element_t element)
Get text of an element.
Definition xmlutils.c:2136
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:1283
static void handle_error(GMarkupParseContext *context, GError *error, gpointer user_data)
Handle an OMP XML parsing error.
Definition xmlutils.c:477
void print_element_to_string(element_t element, GString *string)
Print an XML element tree to a GString, appending it if string is not.
Definition xmlutils.c:2279
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1470
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:1263
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:1582
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:1437
static void foreach_print_entity(gpointer entity, gpointer stream)
Print an XML entity for g_slist_foreach.
Definition xmlutils.c:1635
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
Definition xmlutils.c:67
#define BUFFER_SIZE
Size of the buffer for reading from the manager.
Definition xmlutils.c:37
gchar * element_attribute(element_t element, const gchar *name)
Get an attribute of an element.
Definition xmlutils.c:2161
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:1685
element_t element_first_child(element_t element)
Get the first child of an element.
Definition xmlutils.c:2209
void print_entity_format(entity_t entity, gpointer indent)
Print an XML entity to stdout, recursively printing its children.
Definition xmlutils.c:1703
void free_entity(entity_t entity)
Free an entity, recursively.
Definition xmlutils.c:115
static gboolean compare_find_attribute(gpointer key, gpointer value, gpointer attributes2)
Look for a key-value pair in a hash table.
Definition xmlutils.c:1744
static element_t find_child(element_t element, const gchar *name)
Find child in an element.
Definition xmlutils.c:2068
int read_text_c(gvm_connection_t *connection, char **text)
Read text from the server.
Definition xmlutils.c:1367
int read_entity_and_text_c(gvm_connection_t *connection, entity_t *entity, char **text)
Read an XML entity tree from the manager.
Definition xmlutils.c:1337
int parse_element(const gchar *string, element_t *element)
Read an XML element tree from a string.
Definition xmlutils.c:2002
int read_entity_and_text(gnutls_session_t *session, entity_t *entity, char **text)
Read an XML entity tree from the manager.
Definition xmlutils.c:1306
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:501
static int compare_entity_with_name(gconstpointer entity, gconstpointer name)
Compare a given name with the name of a given entity.
Definition xmlutils.c:179
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:101
int xml_count_entities(entities_t entities)
Count the number of entities.
Definition xmlutils.c:1827
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition xmlutils.c:193
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:290
void xml_handle_end_element(context_data_t *context, const gchar *element_name)
Handle the end of an XML element.
Definition xmlutils.c:402
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:263
static entity_t make_entity(const char *name, const char *text)
Create an entity.
Definition xmlutils.c:48
element_t element_next(element_t element)
Get the next sibling of an element.
Definition xmlutils.c:2229
gchar * element_to_string(element_t element)
Output the XML element as a string.
Definition xmlutils.c:2252
element_t element_child(element_t element, const gchar *name)
Get a child of an element.
Definition xmlutils.c:2085
int parse_entity(const char *string, entity_t *entity)
Read an XML entity tree from a string.
Definition xmlutils.c:1512
#define XML_FILE_BUFFER_SIZE
Definition xmlutils.c:1930
int compare_entities(entity_t entity1, entity_t entity2)
Compare two XML entity.
Definition xmlutils.c:1762
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:1453
static void foreach_print_attribute(gpointer name, gpointer value, gpointer stream)
Print an XML attribute for g_hash_table_foreach.
Definition xmlutils.c:1648
int read_entity_s(int socket, entity_t *entity)
Read an XML entity tree from the socket.
Definition xmlutils.c:1484
void print_entity(FILE *stream, entity_t entity)
Print an XML entity.
Definition xmlutils.c:1660
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:343
static void add_attributes(entity_t entity, const gchar **names, const gchar **values)
Add attributes from an XML callback to an entity.
Definition xmlutils.c:234
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:1595
void xml_handle_text(context_data_t *context, const gchar *text, gsize text_len)
Handle additional text of an XML element.
Definition xmlutils.c:464
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition xmlutils.c:1848
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:1613
Headers for simple XML reader.
struct entity_s * entity_t
Definition xmlutils.h:58
struct _xmlNode * element_t
Definition xmlutils.h:157
GSList * entities_t
Entities.
Definition xmlutils.h:46