[Openvas-commits] r5762 - in trunk/openvas-libraries: . omp
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Oct 30 15:45:51 CET 2009
Author: mattm
Date: 2009-10-30 15:45:51 +0100 (Fri, 30 Oct 2009)
New Revision: 5762
Modified:
trunk/openvas-libraries/ChangeLog
trunk/openvas-libraries/omp/xml.c
trunk/openvas-libraries/omp/xml.h
Log:
* omp/omp.c (read_entity_and_string): New function. Body from
read_entity_and_text, with GString as return param.
(read_entity_and_text, read_entity): Call read_entity_and_text to do the
work.
* omp/omp.h: Add new header.
Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog 2009-10-30 13:42:19 UTC (rev 5761)
+++ trunk/openvas-libraries/ChangeLog 2009-10-30 14:45:51 UTC (rev 5762)
@@ -1,3 +1,12 @@
+2009-10-30 Matthew Mundell <matthew.mundell at intevation.de>
+
+ * omp/omp.c (read_entity_and_string): New function. Body from
+ read_entity_and_text, with GString as return param.
+ (read_entity_and_text, read_entity): Call read_entity_and_text to do the
+ work.
+
+ * omp/omp.h: Add new header.
+
2009-10-28 Felix Wolfsteller <felix.wolfsteller at intevation.de>
* omp/xml.x (print_entity, print_entity_format): Escape text of
Modified: trunk/openvas-libraries/omp/xml.c
===================================================================
--- trunk/openvas-libraries/omp/xml.c 2009-10-30 13:42:19 UTC (rev 5761)
+++ trunk/openvas-libraries/omp/xml.c 2009-10-30 14:45:51 UTC (rev 5762)
@@ -411,25 +411,30 @@
*
* @param[in] session Pointer to GNUTLS session.
* @param[out] entity Pointer to an entity tree.
- * @param[out] text A 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.
+ * @param[out] string An 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.
*
* @return 0 success, -1 read error, -2 parse error, -3 end of file.
*/
int
-read_entity_and_text (gnutls_session_t* session, entity_t* entity, char** text)
+read_entity_and_string (gnutls_session_t* session, entity_t* entity,
+ GString** string_return)
{
GMarkupParser xml_parser;
GError* error = NULL;
GMarkupParseContext *xml_context;
GString* string;
- if (text == NULL)
+ if (string_return == NULL)
string = NULL;
+ else if (*string_return == NULL)
+ string = g_string_new ("");
else
- string = g_string_new ("");
+ string = *string_return;
/* Create the XML parser. */
@@ -472,7 +477,8 @@
continue;
if (context_data.first && context_data.first->data)
free_entity (context_data.first->data);
- if (string) g_string_free (string, TRUE);
+ if (string && *string_return == NULL)
+ g_string_free (string, TRUE);
return -1;
}
if (count == 0)
@@ -486,7 +492,8 @@
}
if (context_data.first && context_data.first->data)
free_entity (context_data.first->data);
- if (string) g_string_free (string, TRUE);
+ if (string && *string_return == NULL)
+ g_string_free (string, TRUE);
return -3;
}
break;
@@ -505,7 +512,8 @@
g_error_free (error);
if (context_data.first && context_data.first->data)
free_entity (context_data.first->data);
- if (string) g_string_free (string, TRUE);
+ if (string && *string_return == NULL)
+ g_string_free (string, TRUE);
return -2;
}
if (context_data.done)
@@ -520,7 +528,7 @@
return -2;
}
*entity = (entity_t) context_data.first->data;
- if (string) *text = (char*) g_string_free (string, FALSE);
+ if (string) *string_return = string;
return 0;
}
}
@@ -531,13 +539,39 @@
*
* @param[in] session Pointer to GNUTLS session.
* @param[out] entity Pointer to an entity tree.
+ * @param[out] text A 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.
*
* @return 0 success, -1 read error, -2 parse error, -3 end of file.
*/
int
+read_entity_and_text (gnutls_session_t* session, entity_t* entity, char** text)
+{
+ if (text)
+ {
+ GString *string = NULL;
+ int ret = read_entity_and_string (session, entity, &string);
+ if (ret) return ret;
+ *text = g_string_free (string, FALSE);
+ return 0;
+ }
+ return read_entity_and_string (session, entity, NULL);
+}
+
+/**
+ * @brief Read an XML entity tree from the manager.
+ *
+ * @param[in] session Pointer to GNUTLS session.
+ * @param[out] entity Pointer to an entity tree.
+ *
+ * @return 0 success, -1 read error, -2 parse error, -3 end of file.
+ */
+int
read_entity (gnutls_session_t* session, entity_t* entity)
{
- return read_entity_and_text (session, entity, NULL);
+ return read_entity_and_string (session, entity, NULL);
}
/**
@@ -660,9 +694,10 @@
}
/**
- * @brief Print XML entities to stdout, recusively printing its children.
- * @brief Does very basic indentation for pretty printing.
+ * @brief Pretty print XML entities to stdout, recursively printing children.
*
+ * Does very basic indentation for pretty printing.
+ *
* @param[in] entity The entity.
* @param[in] indent Indentation level, indentation width is 2 spaces.
*/
Modified: trunk/openvas-libraries/omp/xml.h
===================================================================
--- trunk/openvas-libraries/omp/xml.h 2009-10-30 13:42:19 UTC (rev 5761)
+++ trunk/openvas-libraries/omp/xml.h 2009-10-30 14:45:51 UTC (rev 5762)
@@ -86,6 +86,9 @@
print_entities_format (entities_t, int indentation);
int
+read_entity_and_string (gnutls_session_t*, entity_t*, GString**);
+
+int
read_entity_and_text (gnutls_session_t*, entity_t*, char**);
int
More information about the Openvas-commits
mailing list