[Openvas-commits] r10594 - in trunk/openvas-libraries: . omp
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Mar 19 07:29:24 CET 2011
Author: mattm
Date: 2011-03-19 07:29:24 +0100 (Sat, 19 Mar 2011)
New Revision: 10594
Modified:
trunk/openvas-libraries/ChangeLog
trunk/openvas-libraries/omp/xml.c
trunk/openvas-libraries/omp/xml.h
Log:
* omp/xml.c (parse_entity): New function.
* omp/xml.h: Add header accordingly.
Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog 2011-03-18 19:52:52 UTC (rev 10593)
+++ trunk/openvas-libraries/ChangeLog 2011-03-19 06:29:24 UTC (rev 10594)
@@ -1,3 +1,9 @@
+2011-03-19 Matthew Mundell <matthew.mundell at greenbone.net>
+
+ * omp/xml.c (parse_entity): New function.
+
+ * omp/xml.h: Add header accordingly.
+
2011-03-09 Michael Wiegand <michael.wiegand at greenbone.net>
* misc/plugutils.c (kb_get_port_state_proto): Honor unscanned_closed
@@ -6,7 +12,7 @@
2011-03-07 Matthew Mundell <matthew.mundell at greenbone.net>
* omp/xml.c (handle_end_element, read_entity_and_string): Free context
- data list elements.
+ data list elements. From valgrind by Pavel Sejnoha.
2011-03-07 Michael Wiegand <michael.wiegand at greenbone.net>
Modified: trunk/openvas-libraries/omp/xml.c
===================================================================
--- trunk/openvas-libraries/omp/xml.c 2011-03-18 19:52:52 UTC (rev 10593)
+++ trunk/openvas-libraries/omp/xml.c 2011-03-19 06:29:24 UTC (rev 10594)
@@ -604,6 +604,78 @@
}
/**
+ * @brief Read an XML entity tree from a string.
+ *
+ * @param[in] string Input string.
+ * @param[out] entity Pointer to an entity tree.
+ *
+ * @return 0 success, -1 read error, -2 parse error, -3 XML ended prematurely.
+ */
+int
+parse_entity (const char *string, entity_t * entity)
+{
+ GMarkupParser xml_parser;
+ GError *error = NULL;
+ GMarkupParseContext *xml_context;
+ context_data_t context_data;
+
+ /* Create the XML parser. */
+
+ xml_parser.start_element = handle_start_element;
+ xml_parser.end_element = handle_end_element;
+ xml_parser.text = handle_text;
+ xml_parser.passthrough = NULL;
+ xml_parser.error = handle_error;
+
+ context_data.done = FALSE;
+ context_data.first = NULL;
+ context_data.current = NULL;
+
+ /* Setup the XML context. */
+
+ xml_context =
+ g_markup_parse_context_new (&xml_parser, 0, &context_data, NULL);
+
+ /* Parse the string. */
+
+ g_markup_parse_context_parse (xml_context, string, strlen (string), &error);
+ if (error)
+ {
+ g_error_free (error);
+ if (context_data.first && context_data.first->data)
+ {
+ free_entity (context_data.first->data);
+ g_slist_free_1 (context_data.first);
+ }
+ return -2;
+ }
+ if (context_data.done)
+ {
+ g_markup_parse_context_end_parse (xml_context, &error);
+ if (error)
+ {
+ g_message (" End error: %s\n", error->message);
+ g_error_free (error);
+ if (context_data.first && context_data.first->data)
+ {
+ free_entity (context_data.first->data);
+ g_slist_free_1 (context_data.first);
+ }
+ return -2;
+ }
+ *entity = (entity_t) context_data.first->data;
+ g_slist_free_1 (context_data.first);
+ return 0;
+ }
+ if (context_data.first && context_data.first->data)
+ {
+ free_entity (context_data.first->data);
+ g_slist_free_1 (context_data.first);
+ }
+ return -3;
+}
+
+/**
* @brief Print an XML entity for g_slist_foreach to a GString.
*
* @param[in] entity The entity, as a gpointer.
Modified: trunk/openvas-libraries/omp/xml.h
===================================================================
--- trunk/openvas-libraries/omp/xml.h 2011-03-18 19:52:52 UTC (rev 10593)
+++ trunk/openvas-libraries/omp/xml.h 2011-03-19 06:29:24 UTC (rev 10594)
@@ -88,6 +88,8 @@
int read_string (gnutls_session_t *, GString **);
+int parse_entity (const char *, entity_t *);
+
void print_entity_to_string (entity_t entity, GString * string);
void print_entities_to_string (GString * string, entities_t entities);
More information about the Openvas-commits
mailing list