[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openvas-cvs
Subject:    [Openvas-commits] r5339 - in trunk/openvas-client: .
From:       scm-commit () wald ! intevation ! org
Date:       2009-09-30 14:35:59
Message-ID: 20090930143559.D5E7285D9F74 () pyrosoma ! intevation ! org
[Download RAW message or body]

Author: mattm
Date: 2009-09-30 16:35:58 +0200 (Wed, 30 Sep 2009)
New Revision: 5339

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c
Log:
	Make Scope->New behave like the new button, for OMP.

	* openvas/prefs_dialog/prefs_scope_tree.c [USE_OMP]
	(ensure_context_connected): Move up.
	(scopetree_add_new_with_parent) [USE_OMP]: Move the body of
	server_menu_new here for new scope case.
	(server_menu_new) [USE_OMP]: For CONTEXT_SERVER call scopetree_new like
	the other cases do.

Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-09-30 13:52:13 UTC (rev 5338)
+++ trunk/openvas-client/ChangeLog	2009-09-30 14:35:58 UTC (rev 5339)
@@ -1,5 +1,16 @@
 2009-09-30  Matthew Mundell <matthew.mundell@intevation.de>
 
+	Make Scope->New behave like the new button, for OMP.
+
+	* openvas/prefs_dialog/prefs_scope_tree.c [USE_OMP]
+	(ensure_context_connected): Move up.
+	(scopetree_add_new_with_parent) [USE_OMP]: Move the body of
+	server_menu_new here for new scope case.
+	(server_menu_new) [USE_OMP]: For CONTEXT_SERVER call scopetree_new like
+	the other cases do.
+
+2009-09-30  Matthew Mundell <matthew.mundell@intevation.de>
+
 	* openvas/context.c: Correct comment typo.
 
 2009-09-30  Matthew Mundell <matthew.mundell@intevation.de>

Modified: trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c
===================================================================
--- trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c	2009-09-30 13:52:13 UTC (rev 5338)
+++ trunk/openvas-client/openvas/prefs_dialog/prefs_scope_tree.c	2009-09-30 14:35:58 UTC (rev 5339)
@@ -74,6 +74,29 @@
   NUM_COLS
 };
 
+#ifdef USE_OMP
+static int scopetree_refresh (context_type, int);
+
+static void scopetree_delete_recurse (struct context *);
+
+static int
+ensure_context_connected (struct context *context, gboolean writable_settings)
+{
+  if (context->protocol == PROTOCOL_OMP)
+    {
+      int ret;
+      gboolean previous = prefs_dialog_auth_writable_settings;
+
+      prefs_dialog_auth_writable_settings = writable_settings;
+      ret = prefs_dialog_auth_omp_connection (context);
+      prefs_dialog_auth_writable_settings = previous;
+      if (!ret)
+        return -1;
+    }
+  return 0;
+}
+#endif /* USE_OMP */
+
 void
 scopetree_save_treerowref (struct context* context, GtkTreeModel *model,
                            GtkTreeIter iter)
@@ -249,7 +272,7 @@
 #ifdef USE_OMP
 /* The OMP option adds a function called scopetree_add_with_parent.
  * refresh_reports in ../monitor_dialog.c uses it.  scopetree_add_with_parent
- * calls the original scopetree_new_with_parent, which is rename
+ * calls the original scopetree_new_with_parent, which is renamed
  * scopetree_add_new_with_parent to cater for both a scopetree_add_with_parent
  * and a scopetree_new_with_parent. */
 
@@ -328,7 +351,96 @@
 
 #ifdef USE_OMP
   if (new)
-  context = context_new(context, name, filename);
+    {
+      if (context->protocol == PROTOCOL_OTP || type == CONTEXT_SERVER)
+        context = context_new (context, name, filename);
+      else if (type == CONTEXT_SCOPE)
+        {
+          struct context *server = context;
+          struct context *scope;
+
+          if (type == CONTEXT_REPORT) abort ();
+
+          char* id;
+          gchar *rcfile, *rc;
+          GError* error;
+          gsize rc_len;
+
+          if (ensure_context_connected (server, FALSE))
+            {
+              show_error (_("%s: Failed to connect to manager"), __FUNCTION__);
+              return NULL;
+            }
+
+          /* Create the task. */
+
+          // FIX handle error
+          // FIX create_omp_task
+          if (omp_create_task_rc (&server->session,
+                                  "targets = localhost\n",
+                                  strlen ("targets = localhost\n"),
+                                  "unnamed scope",
+                                  "",
+                                  &id))
+            {
+              openvas_server_close (server->socket, server->session);
+              server->socket = 0;
+              show_error (_("%s: Failed to create scope on manager"),
+                          __FUNCTION__);
+              return NULL;
+            }
+
+          /* Create the context in the scope tree. */
+
+          scope = context_new (server, name, filename);
+
+          /* FIX "Context" is now "scope".  Transfer the GUI values into the file.  */
+          //prefs_context_update (scope);
+          //prefs_dialog_apply(Context, MainDialog);
+
+          /* Set ID in prefs/rcfile. */
+
+          rcfile = preferences_get_altname (scope, NULL);
+
+          prefs_set_string (scope, "id", id);
+          /* Using prefs_set_value ensures that the value always goes in the rc. */
+          //prefs_set_value (scope, "targets", (void*) "localhost", ARG_STRING);
+          // FIX sync tabs w prefs?
+          //         stuff in prefs_context_update (scope);
+          preferences_save (scope);
+
+          /* Set rcfile on task in the manager. */
+
+          error = NULL;
+          g_file_get_contents (rcfile, &rc, &rc_len, &error);
+          if (error)
+            {
+              // FIX note error
+              g_error_free (error);
+              openvas_server_close (server->socket, server->session);
+              server->socket = 0;
+              free (id);
+              show_error (_("%s: Failed to get scope RC file"), __FUNCTION__);
+              return NULL;
+            }
+
+          // FIX check error
+          omp_modify_task (&server->session, id, rc, NULL, NULL);
+          g_free (rc);
+
+          openvas_server_close (server->socket, server->session);
+          server->socket = 0;
+
+          free (id);
+
+          context = scope;
+        }
+      else
+        {
+          show_error (_("%: called with illegal type"), __FUNCTION__);
+          return NULL;
+        }
+    }
   else
     context = context_add(context, name, filename);
 #else
@@ -382,27 +494,6 @@
 }
 
 #ifdef USE_OMP
-static int scopetree_refresh (context_type, int);
-
-static void scopetree_delete_recurse (struct context *);
-
-static int
-ensure_context_connected (struct context *context, gboolean writable_settings)
-{
-  if (context->protocol == PROTOCOL_OMP)
-    {
-      int ret;
-      gboolean previous = prefs_dialog_auth_writable_settings;
-
-      prefs_dialog_auth_writable_settings = writable_settings;
-      ret = prefs_dialog_auth_omp_connection (context);
-      prefs_dialog_auth_writable_settings = previous;
-      if (!ret)
-        return -1;
-    }
-  return 0;
-}
-
 void
 server_menu_new (GtkMenuItem *menuitem, gpointer user_data)
 {
@@ -488,127 +579,7 @@
   else if (Context->type == CONTEXT_GLOBAL)
     scopetree_new(CONTEXT_TASK, NULL, NULL);
   else if (Context->type >= CONTEXT_SERVER)
-    {
-      struct context *server = Context;
-      struct context *scope;
-
-      char* id;
-      gchar *rcfile, *rc;
-      GError* error;
-      gsize rc_len;
-
-      if (ensure_context_connected (server, FALSE))
-        {
-          return;
-        }
-
-      /* Create the task. */
-
-      // FIX handle error
-      // FIX create_omp_task
-      if (omp_create_task_rc (&server->session,
-                              "targets = localhost\n",
-                              strlen ("targets = localhost\n"),
-                              "unnamed scope",
-                              "",
-                              &id))
-        {
-          openvas_server_close (server->socket, server->session);
-          return;
-        }
-
-      /* Create the context in the scope tree. */
-
-      scope = scopetree_new_with_parent (Context, CONTEXT_SCOPE, NULL, NULL);
-
-      /* FIX "Context" is now "scope".  Transfer the GUI values into the file.  */
-      //prefs_context_update (scope);
-      //prefs_dialog_apply(Context, MainDialog);
-
-      /* Set ID in prefs/rcfile. */
-
-      rcfile = preferences_get_altname (scope, NULL);
-
-#if 0
-      /* Hack ID into openvasrc. */
-
-      {
-        char *pos;
-        gchar *rc, *rc2;
-        gsize rc_len;
-        GString *string;
-        GError *error;
-
-        error = NULL;
-        g_file_get_contents (rcfile, &rc, &rc_len, &error);
-        if (error)
-          {
-            show_error (_("%s: g_file_get_contents", __FUNCTION__));
-            // FIX note error
-            g_error_free (error);
-            goto fail;
-          }
-
-        pos = strchr (rc, '\n');
-        if (pos)
-          {
-            string = g_string_new_len (rc, rc - pos);
-            /* The first \n ensures that "id" begins a line. */
-            g_string_append_printf (string, "\nid = %s\n", id);
-            g_string_append (string, pos);
-          }
-        else
-          {
-            string = g_string_new (rc);
-            /* The first \n ensures that "id" begins a line. */
-            g_string_append_printf (string, "\nid = %s\n", id);
-          }
-
-        rc2 = g_string_free (string, FALSE);
-
-        error = NULL;
-        g_file_set_contents (rcfile, (gchar*) rc2, strlen (rc2), &error);
-        if (error)
-          {
-            show_error (_("%s: g_file_get_contents", __FUNCTION__));
-            // FIX note error
-            g_error_free (error);
-            goto fail;
-          }
-      }
-#endif /* 0 */
-
-      prefs_set_string (scope, "id", id);
-      /* Using prefs_set_value ensures that the value always goes in the rc. */
-      //prefs_set_value (scope, "targets", (void*) "localhost", ARG_STRING);
-      // FIX sync tabs w prefs?
-      //         stuff in prefs_context_update (scope);
-      preferences_save (scope);
-
-      /* Set rcfile on task in the manager. */
-
-      error = NULL;
-      g_file_get_contents (rcfile, &rc, &rc_len, &error);
-      if (error)
-        {
-          // FIX note error
-          g_error_free (error);
-          openvas_server_close (server->socket, server->session);
-          free (id);
-          return;
-        }
-
-      // FIX check error
-      omp_modify_task (&server->session, id, rc, NULL, NULL);
-      g_free (rc);
-
-#if 0
- fail:
-#endif
-      openvas_server_close (server->socket, server->session);
-
-      free (id);
-    }
+    scopetree_new(CONTEXT_SCOPE, NULL, NULL);
 #endif /* USE_OMP */
   else
     scopetree_new(CONTEXT_TASK, NULL, NULL);

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
http://lists.wald.intevation.org/mailman/listinfo/openvas-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic