[Openvas-commits] r5572 - in trunk/openvas-libraries: . omp

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 16 10:45:17 CEST 2009


Author: felix
Date: 2009-10-16 10:45:16 +0200 (Fri, 16 Oct 2009)
New Revision: 5572

Modified:
   trunk/openvas-libraries/ChangeLog
   trunk/openvas-libraries/omp/xml.c
   trunk/openvas-libraries/omp/xml.h
Log:
* omp/xml.c, omp/xml.h (print_entity_format),
(foreach_print_attribute_format, print_entity_format),
(print_entities_format): New. Very basic pretty printing of xml trees.
(foreach_print_attribute, foreach_print_entity): Declared static.


Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog	2009-10-16 06:41:01 UTC (rev 5571)
+++ trunk/openvas-libraries/ChangeLog	2009-10-16 08:45:16 UTC (rev 5572)
@@ -1,3 +1,10 @@
+2009-10-16  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
+	* omp/xml.c, omp/xml.h (print_entity_format),
+	(foreach_print_attribute_format, print_entity_format),
+	(print_entities_format): New. Very basic pretty printing of xml trees.
+	(foreach_print_attribute, foreach_print_entity): Declared static.
+
 2009-10-15  Matthew Mundell <matthew.mundell at intevation.de>
 
 	* misc/openvas_server.c (openvas_server_open, openvas_server_close)
@@ -20,6 +27,11 @@
 
 2009-10-15  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
+	* base/openvas_certificate_file.c, base/openvas_certificate_file.h:
+	Reverted last commit.
+
+2009-10-15  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
 	Refactored openvas_certificate_file to be able to parse text directly
 	(in contrast to reading it from a file).
 

Modified: trunk/openvas-libraries/omp/xml.c
===================================================================
--- trunk/openvas-libraries/omp/xml.c	2009-10-16 06:41:01 UTC (rev 5571)
+++ trunk/openvas-libraries/omp/xml.c	2009-10-16 08:45:16 UTC (rev 5572)
@@ -546,7 +546,7 @@
  * @param[in]  entity  The entity, as a gpointer.
  * @param[in]  stream  The stream to which to print, as a gpointer.
  */
-void
+static void
 foreach_print_entity (gpointer entity, gpointer stream)
 {
   print_entity ((FILE*) stream, (entity_t) entity);
@@ -559,7 +559,7 @@
  * @param[in]  value   The attribute value.
  * @param[in]  stream  The stream to which to print.
  */
-void
+static void
 foreach_print_attribute (gpointer name, gpointer value, gpointer stream)
 {
   fprintf ((FILE*) stream, " %s=\"%s\"", (char*) name, (char*) value);
@@ -598,7 +598,76 @@
   g_slist_foreach (entities, foreach_print_entity, stream);
 }
 
+/* "Formatted" (indented) output of entity_t */
+
 /**
+ * @brief Print an XML attribute for g_hash_table_foreach to stdout.
+ *
+ * @param[in]  name    The attribute name.
+ * @param[in]  value   The attribute value.
+ * @param[in]  none    (ignored).
+ */
+static void
+foreach_print_attribute_format (gpointer name, gpointer value, gpointer none)
+{
+  printf (" %s=\"%s\"", (char*) name, (char*) value);
+}
+
+/**
+ * @brief Print an XML entity to stdout, recusively printing its children.
+ * @brief Does very basic indentation for pretty printing.
+ *
+ * This function is used as the (callback) GFunc in g_slist_foreach.
+ *
+ * @param[in]  entity  The entity.
+ * @param[in]  indent  Indentation level, indentation width is 2 spaces.
+ *                     use GINT_TO_POINTER to convert a integer value when
+ *                     passing this parameter.
+ */
+void
+print_entity_format (entity_t entity, gpointer indent)
+{
+  int i = 0;
+  int indentation = GPOINTER_TO_INT (indent);
+
+  for (i = 0; i < indentation; i++)
+    printf ("  ");
+
+  printf ("<%s", entity->name);
+  if (entity->attributes && g_hash_table_size (entity->attributes))
+    g_hash_table_foreach (entity->attributes,
+                          foreach_print_attribute_format,
+                          indent);
+  printf (">");
+
+  printf ("%s", entity->text);
+
+  if (entity->entities)
+    {
+      printf ("\n");
+      g_slist_foreach (entity->entities, (GFunc) print_entity_format, GINT_TO_POINTER (indentation+1));
+      for (i = 0; i < indentation; i++)
+        printf ("  ");
+    }
+
+  printf ("</%s>\n", entity->name);
+}
+
+/**
+ * @brief Print XML entities to stdout, recusively printing its children.
+ * @brief Does very basic indentation for pretty printing.
+ *
+ * @param[in]  entity  The entity.
+ * @param[in]  indent  Indentation level, indentation width is 2 spaces.
+ */
+void
+print_entities_format (entities_t entities, int indent)
+{
+  g_slist_foreach (entities, (GFunc) print_entity_format,
+                   GINT_TO_POINTER (indent));
+}
+
+/**
  * @brief Look for a key-value pair in a hash table.
  *
  * @param[in]  key          Key.

Modified: trunk/openvas-libraries/omp/xml.h
===================================================================
--- trunk/openvas-libraries/omp/xml.h	2009-10-16 06:41:01 UTC (rev 5571)
+++ trunk/openvas-libraries/omp/xml.h	2009-10-16 08:45:16 UTC (rev 5572)
@@ -79,6 +79,12 @@
 void
 print_entities (FILE*, entities_t);
 
+void
+print_entity_format (entity_t, gpointer indentation);
+
+void
+print_entities_format (entities_t, int indentation);
+
 int
 read_entity_and_text (gnutls_session_t*, entity_t*, char**);
 



More information about the Openvas-commits mailing list