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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 14 23:00:32 CEST 2009


Author: mattm
Date: 2009-10-14 23:00:32 +0200 (Wed, 14 Oct 2009)
New Revision: 5546

Modified:
   trunk/openvas-libraries/ChangeLog
   trunk/openvas-libraries/omp/omp.c
   trunk/openvas-libraries/omp/omp.h
Log:
	* omp/omp.c (omp_get_report): Add a format arg.
	(omp_get_report_format): New function.

	* omp/omp.h: Update headers.

Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog	2009-10-14 20:54:49 UTC (rev 5545)
+++ trunk/openvas-libraries/ChangeLog	2009-10-14 21:00:32 UTC (rev 5546)
@@ -1,3 +1,10 @@
+2009-10-14  Matthew Mundell <matthew.mundell at intevation.de>
+
+	* omp/omp.c (omp_get_report): Add a format arg.
+	(omp_get_report_format): New function.
+
+	* omp/omp.h: Update headers.
+
 2009-10-14  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
 	Refactored hash_table_file to be able to parse text directly (in

Modified: trunk/openvas-libraries/omp/omp.c
===================================================================
--- trunk/openvas-libraries/omp/omp.c	2009-10-14 20:54:49 UTC (rev 5545)
+++ trunk/openvas-libraries/omp/omp.c	2009-10-14 21:00:32 UTC (rev 5546)
@@ -927,10 +927,14 @@
  * @return 0 on success, -1 or OMP response code on error.
  */
 int
-omp_get_report (gnutls_session_t* session, const char* id, entity_t* response)
+omp_get_report (gnutls_session_t* session,
+                const char* id,
+                const char* format,
+                entity_t* response)
 {
   if (openvas_server_sendf (session,
-                            "<get_report format=\"nbe\" report_id=\"%s\"/>",
+                            "<get_report format=\"%s\" report_id=\"%s\"/>",
+                            format ? format : "nbe",
                             id))
     return -1;
 
@@ -943,6 +947,83 @@
 }
 
 /**
+ * @brief Get a report in a given format.
+ *
+ * @param[in]  session      Pointer to GNUTLS session.
+ * @param[in]  id           ID of report.
+ * @param[in]  format       Required format.
+ * @param[out] report       Report.  On success contains the report.
+ * @param[out] report_size  Size of report in bytes.
+ *
+ * @return 0 on success, -1 on error.
+ */
+int
+omp_get_report_format (gnutls_session_t* session,
+                       const char* id,
+                       const char* format,
+                       void** report,
+                       gsize* report_size)
+{
+  char first;
+  const char* status;
+  entity_t entity;
+
+  if (openvas_server_sendf (session,
+                            "<get_report format=\"%s\" report_id=\"%s\"/>",
+                            format,
+                            id))
+    return -1;
+
+  /* Read the response. */
+
+  entity = NULL;
+  if (read_entity (session, &entity)) return -1;
+
+  /* Check the response. */
+
+  status = entity_attribute (entity, "status");
+  if (status == NULL)
+    {
+      free_entity (entity);
+      return -1;
+    }
+  if (strlen (status) == 0)
+    {
+      free_entity (entity);
+      return -1;
+    }
+  first = status[0];
+  if (first == '2')
+    {
+      const char* report_64;
+      entity_t report_xml;
+
+      report_xml = entity_child (entity, "report");
+      if (report_xml == NULL)
+        {
+          free_entity (entity);
+          return -1;
+        }
+
+      report_64 = entity_text (report_xml);
+      if (strlen (report_64) == 0)
+        {
+          *report = g_strdup ("");
+          *report_size = 0;
+        }
+      else
+        {
+          *report = (void*) g_base64_decode (report_64, report_size);
+        }
+
+      free_entity (entity);
+      return 0;
+    }
+  free_entity (entity);
+  return -1;
+}
+
+/**
  * @brief Remove a report.
  *
  * @param[in]  session   Pointer to GNUTLS session.

Modified: trunk/openvas-libraries/omp/omp.h
===================================================================
--- trunk/openvas-libraries/omp/omp.h	2009-10-14 20:54:49 UTC (rev 5545)
+++ trunk/openvas-libraries/omp/omp.h	2009-10-14 21:00:32 UTC (rev 5546)
@@ -73,9 +73,13 @@
 omp_get_status (gnutls_session_t*, const char*, int, entity_t*);
 
 int
-omp_get_report (gnutls_session_t*, const char*, entity_t*);
+omp_get_report (gnutls_session_t*, const char*, const char*, entity_t*);
 
 int
+omp_get_report_format (gnutls_session_t*, const char*, const char*,
+                       void**, gsize*);
+
+int
 omp_delete_report (gnutls_session_t*, const char*);
 
 int



More information about the Openvas-commits mailing list