[Openvas-commits] r3385 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 15 15:43:09 CEST 2009


Author: mattm
Date: 2009-05-15 15:43:07 +0200 (Fri, 15 May 2009)
New Revision: 3385

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.c
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/otp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	Add an intermediate "delete requested" task state, and delete the task
	only after receiving the SCAN_END message from the server.

	* src/manage.h (task_status_t): Add TASK_STATUS_DELETE_REQUESTED.
	(request_delete_task): New header.
	(delete_task): Update header.

	* src/manage.c (task_run_status_name): Add TASK_STATUS_DELETE_REQUESTED.

	* src/tasks_sql.c (request_delete_task): New function.
	(delete_task): Move request parts to request_delete_task.

	* src/omp.c (omp_xml_handle_end_element): In CLIENT_DELETE_TASK call
	request_delete_task instead of delete_task.

	* src/otp.c (process_otp_server_input): In SERVER_TIME_SCAN_END call
	delete_task if a delete was requested.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-05-15 12:49:25 UTC (rev 3384)
+++ trunk/openvas-manager/ChangeLog	2009-05-15 13:43:07 UTC (rev 3385)
@@ -1,5 +1,25 @@
 2009-05-15  Matthew Mundell <mmundell at intevation.de>
 
+	Add an intermediate "delete requested" task state, and delete the task
+	only after receiving the SCAN_END message from the server.
+
+	* src/manage.h (task_status_t): Add TASK_STATUS_DELETE_REQUESTED.
+	(request_delete_task): New header.
+	(delete_task): Update header.
+
+	* src/manage.c (task_run_status_name): Add TASK_STATUS_DELETE_REQUESTED.
+
+	* src/tasks_sql.c (request_delete_task): New function.
+	(delete_task): Move request parts to request_delete_task.
+
+	* src/omp.c (omp_xml_handle_end_element): In CLIENT_DELETE_TASK call
+	request_delete_task instead of delete_task.
+
+	* src/otp.c (process_otp_server_input): In SERVER_TIME_SCAN_END call
+	delete_task if a delete was requested.
+
+2009-05-15  Matthew Mundell <mmundell at intevation.de>
+
 	Add an intermediate "stop requested" task state, and set the task
 	to "done" or "stopped" only when receiving the SCAN_END message
 	from the server.

Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c	2009-05-15 12:49:25 UTC (rev 3384)
+++ trunk/openvas-manager/src/manage.c	2009-05-15 13:43:07 UTC (rev 3385)
@@ -484,12 +484,13 @@
 {
   switch (task_run_status (task))
     {
-      case TASK_STATUS_DONE:           return "Done";
-      case TASK_STATUS_NEW:            return "New";
-      case TASK_STATUS_REQUESTED:      return "Requested";
-      case TASK_STATUS_RUNNING:        return "Running";
-      case TASK_STATUS_STOP_REQUESTED: return "Stop Requested";
-      default:                         return "Internal Error";
+      case TASK_STATUS_DELETE_REQUESTED: return "Delete requested";
+      case TASK_STATUS_DONE:             return "Done";
+      case TASK_STATUS_NEW:              return "New";
+      case TASK_STATUS_REQUESTED:        return "Requested";
+      case TASK_STATUS_RUNNING:          return "Running";
+      case TASK_STATUS_STOP_REQUESTED:   return "Stop requested";
+      default:                           return "Internal Error";
     }
 }
 
@@ -1070,6 +1071,7 @@
 stop_task (task_t task)
 {
   tracef ("   request task stop %u\n", task_id (task));
+  // FIX something should check safety credential before this
   task_status_t run_status = task_run_status (task);
   if (run_status == TASK_STATUS_REQUESTED
       || run_status == TASK_STATUS_RUNNING)

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-05-15 12:49:25 UTC (rev 3384)
+++ trunk/openvas-manager/src/manage.h	2009-05-15 13:43:07 UTC (rev 3385)
@@ -101,12 +101,13 @@
 
 typedef enum
 {
+  TASK_STATUS_DELETE_REQUESTED,
+  TASK_STATUS_DONE,
   TASK_STATUS_NEW,
   TASK_STATUS_REQUESTED,
   TASK_STATUS_RUNNING,
   TASK_STATUS_STOP_REQUESTED,
-  TASK_STATUS_STOPPED,
-  TASK_STATUS_DONE
+  TASK_STATUS_STOPPED
 } task_status_t;
 
 #ifdef TASKS_FS
@@ -283,9 +284,12 @@
                     /*@null@*/ /*@only@*/ char*);
 
 int
-delete_task (task_t*);
+request_delete_task (task_t*);
 
 int
+delete_task (task_t);
+
+int
 append_to_task_comment (task_t, const char*, int);
 
 int

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-05-15 12:49:25 UTC (rev 3384)
+++ trunk/openvas-manager/src/omp.c	2009-05-15 13:43:07 UTC (rev 3385)
@@ -1334,7 +1334,7 @@
               SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
                                       "<status>407</status>"
                                       "</delete_task_response>");
-            else if (delete_task (&task))
+            else if (request_delete_task (&task))
               {
                 /* to_server is full. */
                 // FIX or some other error

Modified: trunk/openvas-manager/src/otp.c
===================================================================
--- trunk/openvas-manager/src/otp.c	2009-05-15 12:49:25 UTC (rev 3384)
+++ trunk/openvas-manager/src/otp.c	2009-05-15 13:43:07 UTC (rev 3385)
@@ -1885,13 +1885,19 @@
                 {
                   if (current_server_task)
                     {
-                      if (task_run_status (current_server_task)
-                          == TASK_STATUS_STOP_REQUESTED)
-                        set_task_run_status (current_server_task,
-                                             TASK_STATUS_STOPPED);
-                      else
-                        set_task_run_status (current_server_task,
-                                             TASK_STATUS_DONE);
+                      switch (task_run_status (current_server_task))
+                        {
+                          case TASK_STATUS_STOP_REQUESTED:
+                            set_task_run_status (current_server_task,
+                                                 TASK_STATUS_STOPPED);
+                            break;
+                          case TASK_STATUS_DELETE_REQUESTED:
+                            delete_task (current_server_task);
+                            break;
+                          default:
+                            set_task_run_status (current_server_task,
+                                                 TASK_STATUS_DONE);
+                        }
                       append_timestamp (current_server_task,
                                         "",
                                         "scan_end",

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-05-15 12:49:25 UTC (rev 3384)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-05-15 13:43:07 UTC (rev 3385)
@@ -923,30 +923,50 @@
 }
 
 /**
- * @brief Delete a task.
+ * @brief Request deletion of a task.
  *
  * Stop the task beforehand with \ref stop_task, if it is running.
  *
  * @param[in]  task  A pointer to the task.
  *
- * @return 0 on success, -1 if out of space in \ref to_server buffer.
+ * @return 0 on success, -1 if error.
  */
 int
-delete_task (task_t* task_pointer)
+request_delete_task (task_t* task_pointer)
 {
+  task_t task = *task_pointer;
+
+  tracef ("   request delete task %u\n", task_id (task));
+
+  if (current_credentials.username == NULL) return -1;
+
+  if (stop_task (task) == -1) return -1;
+
+  set_task_run_status (task, TASK_STATUS_DELETE_REQUESTED);
+
+  return 0;
+}
+
+/**
+ * @brief Complete deletion of a task.
+ *
+ * @param[in]  task  A pointer to the task.
+ *
+ * @return 0 on success, -1 on error.
+ */
+int
+delete_task (task_t task)
+{
   gboolean success;
   const char* id;
   gchar* name;
   GError* error;
-  task_t task = *task_pointer;
 
   tracef ("   delete task %u\n", task_id (task));
 
-  if (task_id_string (task, &id)) return -1;
-
   if (current_credentials.username == NULL) return -1;
 
-  if (stop_task (task) == -1) return -1;
+  if (task_id_string (task, &id)) return -1;
 
   // FIX may be atomic problems here
 



More information about the Openvas-commits mailing list