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__,
909 if (time (&last_time) == -1)
911 g_warning (
" failed to get current time: %s\n", strerror (errno));
919 if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
929 if (string_return == NULL)
931 else if (*string_return == NULL)
932 string = g_string_sized_new (8192);
934 string = *string_return;
955 if ((timeout - (time (NULL) - last_time)) <= 0)
957 g_warning (
" timeout\n");
958 if (fcntl (socket, F_SETFL, 0L) < 0)
959 g_warning (
"%s :failed to set socket flag: %s",
960 __func__, strerror (errno));
962 if (
string && *string_return == NULL)
963 g_string_free (
string, TRUE);
969 if (
string && *string_return == NULL)
970 g_string_free (
string, TRUE);
972 fcntl (socket, F_SETFL, 0L);
981 if (fcntl (socket, F_SETFL, 0L) < 0)
982 g_warning (
"%s :failed to set socket flag: %s", __func__,
986 *string_return = string;
993 g_debug (
"<= %.*s\n", (
int) count, buffer);
996 g_string_append_len (
string, buffer, count);
998 if ((timeout > 0) && (time (&last_time) == -1))
1000 g_warning (
" failed to get current time (1): %s\n",
1002 if (fcntl (socket, F_SETFL, 0L) < 0)
1003 g_warning (
"%s :failed to set server socket flag: %s", __func__,
1006 if (
string && *string_return == NULL)
1007 g_string_free (
string, TRUE);
1031 GString **string_return)
1033 GMarkupParser xml_parser;
1034 GError *error = NULL;
1035 GMarkupParseContext *xml_context;
1043 if (time (&last_time) == -1)
1045 g_warning (
" failed to get current time: %s\n", strerror (errno));
1053 if (fcntl (socket, F_SETFL, O_NONBLOCK) == -1)
1063 if (string_return == NULL)
1065 else if (*string_return == NULL)
1066 string = g_string_new (
"");
1068 string = *string_return;
1084 xml_parser.passthrough = NULL;
1088 context_data.
done = FALSE;
1089 context_data.
first = NULL;
1095 g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
1113 if (errno == EAGAIN)
1116 if ((timeout - (time (NULL) - last_time)) <= 0)
1118 g_warning (
" timeout\n");
1119 if (fcntl (socket, F_SETFL, 0L) < 0)
1120 g_warning (
"%s :failed to set socket flag: %s",
1121 __func__, strerror (errno));
1122 g_markup_parse_context_free (xml_context);
1124 if (
string && *string_return == NULL)
1125 g_string_free (
string, TRUE);
1131 if (context_data.
first && context_data.
first->data)
1134 g_slist_free_1 (context_data.
first);
1136 if (
string && *string_return == NULL)
1137 g_string_free (
string, TRUE);
1139 fcntl (socket, F_SETFL, 0L);
1140 g_markup_parse_context_free (xml_context);
1147 g_markup_parse_context_end_parse (xml_context, &error);
1150 g_warning (
" End error: %s\n", error->message);
1151 g_error_free (error);
1153 if (context_data.
first && context_data.
first->data)
1156 g_slist_free_1 (context_data.
first);
1158 if (
string && *string_return == NULL)
1159 g_string_free (
string, TRUE);
1162 if (fcntl (socket, F_SETFL, 0L) < 0)
1163 g_warning (
"%s :failed to set socket flag: %s", __func__,
1166 g_markup_parse_context_free (xml_context);
1173 g_debug (
"<= %.*s\n", (
int) count, buffer);
1176 g_string_append_len (
string, buffer, count);
1178 g_markup_parse_context_parse (xml_context, buffer, count, &error);
1181 g_error_free (error);
1183 if (context_data.
first && context_data.
first->data)
1186 g_slist_free_1 (context_data.
first);
1188 if (
string && *string_return == NULL)
1189 g_string_free (
string, TRUE);
1192 if (fcntl (socket, F_SETFL, 0L) < 0)
1193 g_warning (
"%s :failed to set socket flag: %s", __func__,
1196 g_markup_parse_context_free (xml_context);
1200 if (context_data.
done)
1202 g_markup_parse_context_end_parse (xml_context, &error);
1205 g_warning (
" End error: %s\n", error->message);
1206 g_error_free (error);
1207 if (context_data.
first && context_data.
first->data)
1210 g_slist_free_1 (context_data.
first);
1213 fcntl (socket, F_SETFL, 0L);
1214 g_markup_parse_context_free (xml_context);
1216 if (
string && *string_return == NULL)
1217 g_string_free (
string, TRUE);
1223 *string_return = string;
1225 fcntl (socket, F_SETFL, 0L);
1226 g_slist_free (context_data.
first);
1227 g_markup_parse_context_free (xml_context);
1232 if ((timeout > 0) && (time (&last_time) == -1))
1234 g_warning (
" failed to get current time (1): %s\n",
1236 if (fcntl (socket, F_SETFL, 0L) < 0)
1237 g_warning (
"%s :failed to set server socket flag: %s", __func__,
1239 g_markup_parse_context_free (xml_context);
1241 if (
string && *string_return == NULL)
1242 g_string_free (
string, TRUE);
1263 GString **string_return)
1283 GString **string_return)
1285 if (connection->
tls)
1309 GString *
string = NULL;
1314 g_string_free (
string, TRUE);
1317 *text = g_string_free (
string, FALSE);
1341 GString *
string = NULL;
1346 g_string_free (
string, TRUE);
1349 *text = g_string_free (
string, FALSE);
1376 if (connection->
tls)
1384 g_string_free (
string, TRUE);
1387 *text = g_string_free (
string, FALSE);
1454 if (connection->
tls)
1513 GMarkupParser xml_parser;
1514 GError *error = NULL;
1515 GMarkupParseContext *xml_context;
1523 xml_parser.passthrough = NULL;
1526 context_data.
done = FALSE;
1527 context_data.
first = NULL;
1533 g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
1537 g_markup_parse_context_parse (xml_context,
string, strlen (
string), &error);
1540 g_error_free (error);
1541 if (context_data.
first && context_data.
first->data)
1544 g_slist_free_1 (context_data.
first);
1548 if (context_data.
done)
1550 g_markup_parse_context_end_parse (xml_context, &error);
1553 g_warning (
" End error: %s\n", error->message);
1554 g_error_free (error);
1555 if (context_data.
first && context_data.
first->data)
1558 g_slist_free_1 (context_data.
first);
1563 g_slist_free_1 (context_data.
first);
1566 if (context_data.
first && context_data.
first->data)
1569 g_slist_free_1 (context_data.
first);
1597 gchar *text_escaped;
1598 text_escaped = g_markup_escape_text ((gchar *) value, -1);
1599 g_string_append_printf ((GString *)
string,
" %s=\"%s\"", (
char *) name,
1601 g_free (text_escaped);
1614 gchar *text_escaped = NULL;
1615 g_string_append_printf (
string,
"<%s", entity->
name);
1619 g_string_append_printf (
string,
">");
1620 text_escaped = g_markup_escape_text (entity->
text, -1);
1621 g_string_append_printf (
string,
"%s", text_escaped);
1622 g_free (text_escaped);
1624 g_string_append_printf (
string,
"</%s>", entity->
name);
1649 fprintf ((FILE *) stream,
" %s=\"%s\"", (
char *) name, (
char *) value);
1661 gchar *text_escaped = NULL;
1662 fprintf (stream,
"<%s", entity->
name);
1665 fprintf (stream,
">");
1666 text_escaped = g_markup_escape_text (entity->
text, -1);
1667 fprintf (stream,
"%s", text_escaped);
1668 g_free (text_escaped);
1670 fprintf (stream,
"</%s>", entity->
name);
1687 printf (
" %s=\"%s\"", (
char *) name, (
char *) value);
1705 int indentation = GPOINTER_TO_INT (indent);
1706 gchar *text_escaped = NULL;
1708 for (i = 0; i < indentation; i++)
1711 printf (
"<%s", entity->
name);
1717 text_escaped = g_markup_escape_text (entity->
text, -1);
1718 printf (
"%s", text_escaped);
1719 g_free (text_escaped);
1725 GINT_TO_POINTER (indentation + 1));
1726 for (i = 0; i < indentation; i++)
1730 printf (
"</%s>\n", entity->
name);
1745 gchar *value2 = g_hash_table_lookup (attributes2, key);
1746 if (value2 && strcmp (value, value2) == 0)
1748 g_debug (
" compare failed attribute: %s\n", (
char *) value);
1763 if (entity1 == NULL)
1764 return entity2 == NULL ? 0 : 1;
1765 if (entity2 == NULL)
1768 if (strcmp (entity1->
name, entity2->
name))
1770 g_debug (
" compare failed name: %s vs %s\n", entity1->
name,
1774 if (strcmp (entity1->
text, entity2->
text))
1776 g_debug (
" compare failed text %s vs %s (%s)\n", entity1->
text,
1793 g_debug (
" compare failed attributes\n");
1801 while (list1 && list2)
1805 g_debug (
" compare failed subentity\n");
1808 list1 = g_slist_next (list1);
1809 list2 = g_slist_next (list2);
1814 g_debug (
" compare failed number of entities (%s)\n", entity1->
name);
1850 va_start (args, format);
1851 piece = g_markup_vprintf_escaped (format, args);
1853 g_string_append (xml, piece);
1872 const gchar **attribute_names,
1873 const gchar **attribute_values, gpointer data,
1882 && search_data->
found == 0)
1884 g_debug (
"%s: Found element <%s>", __func__,
element_name);
1890 GHashTable *found_attributes;
1892 g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
1894 while (attribute_names[index])
1896 gchar *searched_value;
1897 searched_value = g_hash_table_lookup (
1900 && strcmp (searched_value, attribute_values[index]) == 0)
1902 g_debug (
"%s: Found attribute %s=\"%s\"", __func__,
1903 attribute_names[index], searched_value);
1904 g_hash_table_add (found_attributes, searched_value);
1908 g_debug (
"%s: Found %d of %d attributes", __func__,
1909 g_hash_table_size (found_attributes),
1912 if (g_hash_table_size (found_attributes)
1915 search_data->
found = 1;
1918 g_hash_table_destroy (found_attributes);
1922 search_data->
found = 1;
1927#define XML_FILE_BUFFER_SIZE 1048576
1939 GHashTable *find_attributes)
1944 GMarkupParser xml_parser;
1945 GMarkupParseContext *xml_context;
1947 GError *error = NULL;
1951 search_data.
found = 0;
1955 xml_parser.end_element = NULL;
1956 xml_parser.text = NULL;
1957 xml_parser.passthrough = NULL;
1958 xml_parser.error = NULL;
1959 xml_context = g_markup_parse_context_new (&xml_parser, 0, &search_data, NULL);
1961 file = fopen (file_path,
"r");
1964 g_markup_parse_context_free (xml_context);
1965 g_warning (
"%s: Failed to open '%s':", __func__, strerror (errno));
1970 && g_markup_parse_context_parse (xml_context, buffer, read_len, &error)
1974 g_markup_parse_context_end_parse (xml_context, &error);
1978 g_markup_parse_context_free (xml_context);
1979 return search_data.
found;
1981#undef XML_FILE_BUFFER_SIZE
2008 if (xmlMemSetup (g_free, g_malloc, g_realloc, g_strdup))
2012 xmlReadMemory (
string, strlen (
string),
"noname.xml", NULL, XML_PARSE_HUGE);
2017 *element = xmlDocGetRootElement (doc);
2035 assert (element->doc);
2036 xmlFreeDoc (element->doc);
2050 if (element && (element->type == XML_ELEMENT_NODE))
2051 return (
const gchar *) element->name;
2067 for (xmlNode *node = element->children; node; node = node->next)
2068 if (xmlStrcmp (node->name, (
const xmlChar *) name) == 0)
2084 const gchar *stripped_name;
2089 stripped_name = strchr (name,
':');
2101 if (*stripped_name ==
'\0')
2141 (gchar *) xmlNodeListGetString (element->doc, element->xmlChildrenNode, 1);
2144 string = xmlMalloc (1);
2160 const gchar *stripped_name;
2165 stripped_name = strchr (name,
':');
2177 if (*stripped_name ==
'\0')
2181 return (gchar *) xmlGetProp (element, (
const xmlChar *) name);
2184 (gchar *) xmlGetProp (element, (
const xmlChar *) stripped_name);
2195 return (gchar *) xmlGetProp (element, (
const xmlChar *) name);
2210 element = element->children;
2211 while (element && (element->type != XML_ELEMENT_NODE))
2212 element = element->next;
2230 element = element->next;
2231 while (element && (element->type != XML_ELEMENT_NODE))
2232 element = element->next;
2251 xmlBufferPtr buffer;
2256 element_copy = xmlCopyNode (element, 1);
2258 buffer = xmlBufferCreate ();
2259 xmlNodeDump (buffer, element_copy->doc, element_copy, 0, 0);
2260 xmlFreeNode (element_copy);
2262 xml_string = g_strdup ((
char *) xmlBufferContent (buffer));
2264 xmlBufferFree (buffer);
2278 gchar *text_escaped, *text;
2282 text_escaped = NULL;
2284 g_string_append_printf (
string,
"<%s",
element_name (element));
2286 attribute = element->properties;
2291 value = xmlNodeListGetString (element->doc, attribute->children, 1);
2293 text_escaped = g_markup_escape_text ((gchar *) value, -1);
2294 g_string_append_printf (
string,
" %s=\"%s\"", attribute->name,
2296 g_free (text_escaped);
2300 attribute = attribute->next;
2303 g_string_append_printf (
string,
">");
2306 text_escaped = g_markup_escape_text (text, -1);
2308 g_string_append_printf (
string,
"%s", text_escaped);
2309 g_free (text_escaped);
2318 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:900
void element_free(element_t element)
Free an entire element tree.
Definition xmlutils.c:2031
int read_entity_c(gvm_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1497
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:1400
int read_string_c(gvm_connection_t *connection, GString **string)
Read entity and text. Free the entity immediately.
Definition xmlutils.c:1420
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:1938
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:2048
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:1870
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:1030
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:2133
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:1282
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:2276
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1469
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:1262
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:1581
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:1436
static void foreach_print_entity(gpointer entity, gpointer stream)
Print an XML entity for g_slist_foreach.
Definition xmlutils.c:1634
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:2158
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:1684
element_t element_first_child(element_t element)
Get the first child of an element.
Definition xmlutils.c:2206
void print_entity_format(entity_t entity, gpointer indent)
Print an XML entity to stdout, recursively printing its children.
Definition xmlutils.c:1702
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:1743
static element_t find_child(element_t element, const gchar *name)
Find child in an element.
Definition xmlutils.c:2065
int read_text_c(gvm_connection_t *connection, char **text)
Read text from the server.
Definition xmlutils.c:1366
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:1336
int parse_element(const gchar *string, element_t *element)
Read an XML element tree from a string.
Definition xmlutils.c:1999
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:1305
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:1826
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:2226
gchar * element_to_string(element_t element)
Output the XML element as a string.
Definition xmlutils.c:2249
element_t element_child(element_t element, const gchar *name)
Get a child of an element.
Definition xmlutils.c:2082
int parse_entity(const char *string, entity_t *entity)
Read an XML entity tree from a string.
Definition xmlutils.c:1511
#define XML_FILE_BUFFER_SIZE
Definition xmlutils.c:1927
int compare_entities(entity_t entity1, entity_t entity2)
Compare two XML entity.
Definition xmlutils.c:1761
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:1452
static void foreach_print_attribute(gpointer name, gpointer value, gpointer stream)
Print an XML attribute for g_hash_table_foreach.
Definition xmlutils.c:1647
int read_entity_s(int socket, entity_t *entity)
Read an XML entity tree from the socket.
Definition xmlutils.c:1483
void print_entity(FILE *stream, entity_t entity)
Print an XML entity.
Definition xmlutils.c:1659
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:1594
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:1845
void print_entity_to_string(entity_t entity, GString *string)
Print an XML entity tree to a GString, appending it if string is not.
Definition xmlutils.c:1612
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