[Openvas-commits] r5538 - in trunk/openvas-client: . openvas openvas/prefs_dialog

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 14 12:21:22 CEST 2009


Author: mattm
Date: 2009-10-14 12:21:19 +0200 (Wed, 14 Oct 2009)
New Revision: 5538

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/openvas/monitor_dialog.c
   trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c
   trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.h
Log:
	Remove reports in scope tree before refreshing.

	* openvas/prefs_dialog/prefs_scope_tree.c (copy_plugins): New function.
	(scopetree_refresh_reports): New function, was refresh_reports in
	monitor_dialog.c.  Remove reports before refreshing.

	* openvas/prefs_dialog/prefs_scope_tree.h: Add header.

	* openvas/monitor_dialog.c (copy_plugins, refresh_reports): Remove.  Move
	to prefs_scope_tree.c.

Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-10-14 09:16:14 UTC (rev 5537)
+++ trunk/openvas-client/ChangeLog	2009-10-14 10:21:19 UTC (rev 5538)
@@ -1,5 +1,18 @@
 2009-10-14  Matthew Mundell <matthew.mundell at intevation.de>
 
+	Remove reports in scope tree before refreshing.
+
+	* openvas/prefs_dialog/prefs_scope_tree.c (copy_plugins): New function.
+	(scopetree_refresh_reports): New function, was refresh_reports in
+	monitor_dialog.c.  Remove reports before refreshing.
+
+	* openvas/prefs_dialog/prefs_scope_tree.h: Add header.
+
+	* openvas/monitor_dialog.c (copy_plugins, refresh_reports): Remove.  Move
+	to prefs_scope_tree.c.
+
+2009-10-14  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* openvas/monitor_dialog.c (monitor_dialog_setup) [USE_OMP]: Only show the
 	checkboxes for OTP tasks.  Add OMP specific button text.  Only set action
 	for OMP contexts.

Modified: trunk/openvas-client/openvas/monitor_dialog.c
===================================================================
--- trunk/openvas-client/openvas/monitor_dialog.c	2009-10-14 09:16:14 UTC (rev 5537)
+++ trunk/openvas-client/openvas/monitor_dialog.c	2009-10-14 10:21:19 UTC (rev 5538)
@@ -100,152 +100,6 @@
 	return 1;
 }
 
-#ifdef USE_OMP
-#include "plugin_cache.h"
-// copy from report.c
-static void
-copy_plugins (struct context *context, struct openvas_plugin *plugin)
-{
-  while (plugin)
-  {
-    context_add_plugin (context, openvas_plugin_duplicate(plugin));
-    plugin = plugin->next;
-  }
-}
-
-static void
-refresh_reports (struct context *context)
-{
-  entity_t status, task;
-  entities_t reports;
-  char* scope_dir_name = context->dir;
-
-  if (!check_is_dir (scope_dir_name))
-    {
-      show_error (_("%s: scope dir missing"), __FUNCTION__);
-      return;
-    }
-
-  /* Get the list of reports. */
-
-  if (omp_get_status (&context->session,
-                      prefs_get_string (context, "id"),
-                      0,
-                      &status))
-    {
-      show_error (_("scopetree_refresh(): OMP get_status by id failed"));
-      return;
-    }
-
-  task = entity_child (status, "task");
-  if (task == NULL)
-    {
-      show_error (_("scopetree_refresh(): OMP response missing task"));
-      free_entity (status);
-      return;
-    }
-
-  /* Get each report. */
-
-  for (reports = task->entities;
-       reports;
-       reports = next_entities (reports))
-    {
-      entity_t report_summary = first_entity (reports);
-      const char* id;
-      entity_t response, report;
-      char* report_dir;
-
-      if (strcmp (entity_name (report_summary), "report"))
-        continue;
-
-      id = entity_attribute (report_summary, "id");
-      if (id == NULL)
-        {
-          show_error (_("scopetree_refresh(): OMP get_status missing report id"));
-          return;
-        }
-
-      /* Get and save the report. */
-
-      if (omp_get_report (&context->session, id, &response))
-        {
-          show_error (_("scopetree_refresh(): OMP get_report failed"));
-          return;
-        }
-
-      report = entity_child (response, "report");
-      if (report == NULL)
-        {
-          show_error (_("scopetree_refresh(): OMP response missing report"));
-          free_entity (response);
-          return;
-        }
-      // FIX what free's "report" and "report" prefs
-
-      // FIX OMP should have report names? (name is in rc)
-      // FIX report rcfile
-      report_dir = NULL;
-      if (create_omp_report (scope_dir_name,
-                             id,
-                             entity_text (report),
-                             &report_dir))
-        {
-          show_error (_("scopetree_refresh(): Failed to create report"));
-          free_entity (response);
-          return;
-        }
-
-      if (report_dir)
-        {
-          struct context *report_context;
-          gchar* report_rc;
-
-          report_rc = g_build_filename (report_dir, "openvasrc", NULL);
-          report_context = scopetree_add_with_parent (context, CONTEXT_REPORT,
-                                                      id, report_rc);
-          g_free (report_rc);
-
-          prefs_set_string (report_context, "name", id);
-          prefs_set_string (report_context, "id", id);
-          preferences_save (report_context);
-
-          if (prefs_get_int(Global, "reports_use_plugin_cache"))
-          {
-            int error;
-
-            copy_plugins(report_context, context->plugins);
-            copy_plugins(report_context, context->scanners);
-
-            error = plugin_cache_write(report_context, "");
-            if(error)
-            {
-              show_error(_("report_save() couldn't save the plugin information"));
-              return;
-            }
-
-            /* by the time we get here, the report_context may already have got a
-             * plugin tree because scopetree_new_with_parent may trigger GUI
-             * updates, so we have to reset the tree. */
-            context_reset_plugin_tree(report_context);
-          }
-
-          // FIX report.c has save,load certificate here
-
-          prefs_context_update(report_context);
-// --
-
-          efree (&report_dir);
-        }
-
-
-      free_entity (response);
-    }
-
-  free_entity (status);
-}
-#endif /* USE_OMP */
-
 /**
  * @brief Function called when the UI is idle, which checks whether the server
  * @brief sent us anything.
@@ -289,7 +143,7 @@
           gtk_widget_hide (arg_get_value(ctrls, "WINDOW"));
           gtk_idle_remove (GPOINTER_TO_SIZE(arg_get_value(ctrls, "TAG")));
           gtk_widget_destroy (arg_get_value(ctrls, "WINDOW"));
-          refresh_reports (context);
+          scopetree_refresh_reports (context);
           context->action = CONTEXT_IDLE;
           prefs_context_update (context);
         }
@@ -694,7 +548,7 @@
                          prefs_get_string (context, "id")))
        show_error(_("%s: omp_abort_task failed"), __FUNCTION__);
      else
-       refresh_reports (context);
+       scopetree_refresh_reports (context);
    }
  else
 #endif /* USE_OMP */

Modified: trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c
===================================================================
--- trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c	2009-10-14 09:16:14 UTC (rev 5537)
+++ trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c	2009-10-14 10:21:19 UTC (rev 5538)
@@ -1464,6 +1464,164 @@
   return 0;
 }
 
+#include "openvas_plugin.h"
+#include "plugin_cache.h"
+// FIX copy from report.c
+static void
+copy_plugins (struct context *context, struct openvas_plugin *plugin)
+{
+  while (plugin)
+  {
+    context_add_plugin (context, openvas_plugin_duplicate(plugin));
+    plugin = plugin->next;
+  }
+}
+
+void
+scopetree_refresh_reports (struct context *context)
+{
+  entity_t status, task;
+  entities_t reports;
+  char* scope_dir_name = context->dir;
+
+  if (!check_is_dir (scope_dir_name))
+    {
+      show_error (_("%s: scope dir missing"), __FUNCTION__);
+      return;
+    }
+
+  /* Get the list of reports. */
+
+  if (omp_get_status (&context->session,
+                      prefs_get_string (context, "id"),
+                      0,
+                      &status))
+    {
+      show_error (_("%s: OMP get_status by id failed"), __FUNCTION__);
+      return;
+    }
+
+  task = entity_child (status, "task");
+  if (task == NULL)
+    {
+      show_error (_("%s: OMP response missing task"), __FUNCTION__);
+      free_entity (status);
+      return;
+    }
+
+  /* Remove the children from the task in the scope tree. */
+
+  /** @todo Consider updating the existing entries. */
+
+  delete_in_client_only = 1;
+  while (context->children)
+    {
+      scopetree_delete_recurse (context->children);
+      context_delete (context->children);
+    }
+  delete_in_client_only = 0;
+
+  /* Get each report. */
+
+  for (reports = task->entities;
+       reports;
+       reports = next_entities (reports))
+    {
+      entity_t report_summary = first_entity (reports);
+      const char* id;
+      entity_t response, report;
+      char* report_dir;
+
+      if (strcmp (entity_name (report_summary), "report"))
+        continue;
+
+      id = entity_attribute (report_summary, "id");
+      if (id == NULL)
+        {
+          show_error (_("%s: OMP get_status missing report id"),
+                      __FUNCTION__);
+          return;
+        }
+
+      /* Get and save the report. */
+
+      if (omp_get_report (&context->session, id, &response))
+        {
+          show_error (_("%s: OMP get_report failed"), __FUNCTION__);
+          return;
+        }
+
+      report = entity_child (response, "report");
+      if (report == NULL)
+        {
+          show_error (_("%s: OMP response missing report"), __FUNCTION__);
+          free_entity (response);
+          return;
+        }
+      // FIX what free's "report" and "report" prefs
+
+      // FIX OMP should have report names? (name is in rc)
+      // FIX report rcfile
+      report_dir = NULL;
+      if (create_omp_report (scope_dir_name,
+                             id,
+                             entity_text (report),
+                             &report_dir))
+        {
+          show_error (_("%s: Failed to create report"), __FUNCTION__);
+          free_entity (response);
+          return;
+        }
+
+      if (report_dir)
+        {
+          struct context *report_context;
+          gchar* report_rc;
+
+          report_rc = g_build_filename (report_dir, "openvasrc", NULL);
+          report_context = scopetree_add_with_parent (context, CONTEXT_REPORT,
+                                                      id, report_rc);
+          g_free (report_rc);
+
+          prefs_set_string (report_context, "name", id);
+          prefs_set_string (report_context, "id", id);
+          preferences_save (report_context);
+
+          if (prefs_get_int(Global, "reports_use_plugin_cache"))
+          {
+            int error;
+
+            copy_plugins(report_context, context->plugins);
+            copy_plugins(report_context, context->scanners);
+
+            error = plugin_cache_write(report_context, "");
+            if(error)
+            {
+              show_error(_("report_save() couldn't save the plugin information"));
+              return;
+            }
+
+            /* by the time we get here, the report_context may already have got a
+             * plugin tree because scopetree_new_with_parent may trigger GUI
+             * updates, so we have to reset the tree. */
+            context_reset_plugin_tree(report_context);
+          }
+
+          // FIX report.c has save,load certificate here
+
+          prefs_context_update(report_context);
+// --
+
+          efree (&report_dir);
+        }
+
+
+      free_entity (response);
+    }
+
+  free_entity (status);
+}
+
 /**
  * @param user_data ignored (callback).
  */

Modified: trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.h
===================================================================
--- trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.h	2009-10-14 09:16:14 UTC (rev 5537)
+++ trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.h	2009-10-14 10:21:19 UTC (rev 5538)
@@ -56,6 +56,7 @@
 void scope_menu_save(GtkMenuItem *, gpointer);
 
 #ifdef USE_OMP
+void scopetree_refresh_reports (struct context *);
 void server_menu_refresh(GtkMenuItem *, gpointer);
 #endif
 



More information about the Openvas-commits mailing list