[Openvas-commits] r3109 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Apr 16 16:01:20 CEST 2009
Author: mattm
Date: 2009-04-16 16:01:19 +0200 (Thu, 16 Apr 2009)
New Revision: 3109
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.c
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/omp.c
Log:
Improve the task abstraction by moving parsing of the task ID into
find_task. Separate out task code specific to the task representation.
* src/manage.c: Reorder code to separate out representation-specific
parts.
(task_comment): New function.
(free_task): Free attack_state.
(make_task): Init start_time and end_time.
(find_task): Update to take the ID as a string.
(set_task_parameter): Replace IDENTIFIER parameter with NAME.
* src/manage.h: Reorder headers.
(find_task): Adjust header.
* src/omp.c: Update find_task callers.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-04-16 11:25:59 UTC (rev 3108)
+++ trunk/openvas-manager/ChangeLog 2009-04-16 14:01:19 UTC (rev 3109)
@@ -1,3 +1,21 @@
+2009-04-16 Matthew Mundell <matt at mundell.ukfsn.org>
+
+ Improve the task abstraction by moving parsing of the task ID into
+ find_task. Separate out task code specific to the task representation.
+
+ * src/manage.c: Reorder code to separate out representation-specific
+ parts.
+ (task_comment): New function.
+ (free_task): Free attack_state.
+ (make_task): Init start_time and end_time.
+ (find_task): Update to take the ID as a string.
+ (set_task_parameter): Replace IDENTIFIER parameter with NAME.
+
+ * src/manage.h: Reorder headers.
+ (find_task): Adjust header.
+
+ * src/omp.c: Update find_task callers.
+
2009-04-14 Matthew Mundell <matt at mundell.ukfsn.org>
Improve the task abstraction by accessing all task fields via functions
Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c 2009-04-16 11:25:59 UTC (rev 3108)
+++ trunk/openvas-manager/src/manage.c 2009-04-16 14:01:19 UTC (rev 3109)
@@ -280,14 +280,13 @@
g_free (report_path);
return NULL;
}
- {
- unsigned int id;
- gchar* task_name = report_path_task_name (report_path);
- int ret = sscanf (task_name, "%u", &id);
- g_free (report_path);
- g_free (task_name);
- if (ret == 1) return find_task (id);
- }
+ gchar* task_name = report_path_task_name (report_path);
+ task_t task;
+ int err = find_task (task_name, &task);
+ g_free (report_path);
+ g_free (task_name);
+ if (err) return NULL;
+ return task;
}
else
g_free (link_name);
@@ -420,9 +419,28 @@
}
-/* Tasks. */
+/* Task globals. */
/**
+ * @brief The task currently running on the server.
+ */
+/*@null@*/ task_t current_server_task = NULL;
+
+/**
+ * @brief Report stream of the current task.
+ */
+FILE* current_report = NULL;
+
+
+/* Task code specific to the representation of tasks. */
+
+/* Headers of functions in the next page. */
+static int
+delete_reports (task_t);
+static void
+print_tasks ();
+
+/**
* @brief Reallocation increment for the tasks array.
*/
#define TASKS_INCREMENT 1024
@@ -443,16 +461,6 @@
unsigned int num_tasks = 0;
/**
- * @brief The task currently running on the server.
- */
-/*@null@*/ task_t current_server_task = NULL;
-
-/**
- * @brief Report stream of the current task.
- */
-FILE* current_report = NULL;
-
-/**
* @brief Return the number of tasks associated with the current user.
*
* @return The number of tasks associated with the current user.
@@ -549,6 +557,19 @@
}
/**
+ * @brief Return the comment of a task.
+ *
+ * @param[in] task Task.
+ *
+ * @return Task comment.
+ */
+char*
+task_comment (task_t task)
+{
+ return task->comment;
+}
+
+/**
* @brief Return the description of a task.
*
* @param[in] task Task.
@@ -813,39 +834,7 @@
task->notes_size++;
}
-#if TRACE
/**
- * @brief Print the server tasks.
- */
-static void
-print_tasks ()
-{
- task_t index = tasks;
-
- if (index == NULL)
- tracef (" Task array still to be created.\n\n");
- else
- {
- tracef (" tasks: %p\n", tasks);
- tracef (" tasks end: %p\n", tasks + tasks_size);
- while (index < tasks + tasks_size)
- {
- //tracef (" index: %p\n", index);
- if (index->name)
- {
- tracef (" Task %u: \"%s\" %s\n%s\n\n",
- index->id,
- index->name,
- index->comment ? index->comment : "",
- index->description ? index->description : "");
- }
- index++;
- }
- }
-}
-#endif
-
-/**
* @brief Grow the array of tasks.
*
* @return TRUE on success, FALSE on error (out of memory).
@@ -904,6 +893,7 @@
if (task->description) free (task->description);
if (task->start_time) free (task->start_time);
if (task->end_time) free (task->end_time);
+ if (task->attack_state) free (task->attack_state);
if (current_report)
{
(void) fclose (current_report); // FIX check for error
@@ -981,7 +971,10 @@
index->description = NULL;
index->description_size = 0;
index->run_status = TASK_STATUS_NEW;
+ index->start_time = NULL;
+ index->end_time = NULL;
index->report_count = 0;
+ index->attack_state = NULL;
index->open_ports = NULL;
/*@=mustfreeonly@*/
tracef (" Made task %u at %p\n", index->id, index);
@@ -1386,32 +1379,42 @@
}
/**
- * @brief Find a task given an identifier.
+ * @brief Find a task from a task identifier string.
*
- * @param[in] id A task identifier.
+ * @param[in] id_string A task identifier string.
+ * @param[out] task The task, if found.
*
- * @return A pointer to the task with the given ID.
+ * @return 0 if task found, else -1.
*/
-task_t
-find_task (unsigned int id)
+int
+find_task (const char* id_string, task_t* task)
{
if (tasks)
{
- task_t index = tasks;
- task_t end = tasks + tasks_size;
- while (index < end)
+ unsigned int id;
+
+ if (sscanf (id_string, "%u", &id) == 1)
{
- if (index->name) tracef (" %u vs %u\n", index->id, id);
+ task_t index = tasks;
+ task_t end = tasks + tasks_size;
+ while (index < end)
+ {
+ if (index->name) tracef (" %u vs %u\n", index->id, id);
- if (index->name == NULL)
- index++;
- else if (index->id == id)
- return index;
- else
- index++;
+ if (index->name == NULL)
+ index++;
+ else if (index->id == id)
+ {
+ tracef ("Found task %s at %p\n", id_string, index);
+ *task = index;
+ return 0;
+ }
+ else
+ index++;
+ }
}
}
- return NULL;
+ return -1;
}
/**
@@ -1451,13 +1454,10 @@
task->description = (char*) out;
task->description_length = task->description_size = out_len;
}
- else if (strncasecmp ("IDENTIFIER", parameter, 10) == 0)
+ else if (strncasecmp ("NAME", parameter, 4) == 0)
{
- unsigned int id;
- int ret = sscanf (value, "%u", &id);
- free (value);
- if (ret != 1) return -1;
- task->id = id;
+ free (task->name);
+ task->name = value;
}
else if (strncasecmp ("COMMENT", parameter, 7) == 0)
{
@@ -1473,6 +1473,242 @@
}
/**
+ * @brief Delete 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.
+ */
+int
+delete_task (task_t* task_pointer)
+{
+ gboolean success;
+ const char* id;
+ gchar* name;
+ GError* error;
+ task_t task = *task_pointer;
+
+ tracef (" delete task %u\n", task->id);
+
+ if (task_id_string (task, &id)) return -1;
+
+ if (current_credentials.username == NULL) return -1;
+
+ if (stop_task (task) == -1) return -1;
+
+ // FIX may be atomic problems here
+
+ if (delete_reports (task)) return -1;
+
+ name = g_build_filename (PREFIX
+ "/var/lib/openvas/mgr/users/",
+ current_credentials.username,
+ "tasks",
+ id,
+ NULL);
+ error = NULL;
+ success = rmdir_recursively (name, &error);
+ if (success == FALSE)
+ {
+ if (error)
+ {
+ fprintf (stderr, "Failed to remove task dir %s: %s\n",
+ name,
+ error->message);
+ g_error_free (error);
+ }
+ g_free (name);
+ return -1;
+ }
+ g_free (name);
+
+ free_task (task);
+ *task_pointer = NULL;
+
+ return 0;
+}
+
+/**
+ * @brief Append text to the comment associated with a task.
+ *
+ * @param[in] task A pointer to the task.
+ * @param[in] text The text to append.
+ * @param[in] length Length of the text.
+ *
+ * @return 0 on success, -1 if out of memory.
+ */
+int
+append_to_task_comment (task_t task, const char* text, /*@unused@*/ int length)
+{
+ char* new;
+ if (task->comment)
+ {
+ // FIX
+ new = g_strconcat (task->comment, text, NULL);
+ free (task->comment);
+ task->comment = new;
+ return 0;
+ }
+ new = strdup (text);
+ if (new == NULL) return -1;
+ task->comment = new;
+ return 0;
+}
+
+/**
+ * @brief Append text to the identifier associated with a task.
+ *
+ * @param[in] task A pointer to the task.
+ * @param[in] text The text to append.
+ * @param[in] length Length of the text.
+ *
+ * @return 0 on success, -1 if out of memory.
+ */
+int
+append_to_task_identifier (task_t task, const char* text,
+ /*@unused@*/ int length)
+{
+ char* new;
+ if (task->name)
+ {
+ new = g_strconcat (task->name, text, NULL);
+ g_free (task->name);
+ task->name = new;
+ return 0;
+ }
+ new = strdup (text);
+ if (new == NULL) return -1;
+ task->name = new;
+ return 0;
+}
+
+/**
+ * @brief Reallocation increment for a task description.
+ */
+#define DESCRIPTION_INCREMENT 4096
+
+/**
+ * @brief Increase the memory allocated for a task description.
+ *
+ * @param[in] task A pointer to the task.
+ * @param[in] increment Minimum number of bytes to increase memory.
+ *
+ * @return 0 on success, -1 if out of memory.
+ */
+static int
+grow_description (task_t task, size_t increment)
+{
+ size_t new_size = task->description_size
+ + (increment < DESCRIPTION_INCREMENT
+ ? DESCRIPTION_INCREMENT : increment);
+ /* RATS: ignore *//* Memory cleared below. */
+ char* new = realloc (task->description, new_size);
+ if (new == NULL) return -1;
+ memset (new, (int) '\0', new_size - task->description_size);
+ task->description = new;
+ task->description_size = new_size;
+ return 0;
+}
+
+/**
+ * @brief Add a line to a task description.
+ *
+ * @param[in] task A pointer to the task.
+ * @param[in] line The line.
+ * @param[in] line_length The length of the line.
+ */
+int
+add_task_description_line (task_t task, const char* line, size_t line_length)
+{
+ char* description;
+ if (task->description_size - task->description_length < line_length
+ && grow_description (task, line_length) < 0)
+ return -1;
+ description = task->description;
+ description += task->description_length;
+ strncpy (description, line, line_length);
+ task->description_length += line_length;
+ return 0;
+}
+
+/**
+ * @brief Set the ports of a task.
+ *
+ * @param[in] task The task.
+ * @param[in] current New value for port currently being scanned.
+ * @param[in] max New value for last port to be scanned.
+ */
+void
+set_task_ports (task_t task, unsigned int current, unsigned int max)
+{
+ task->current_port = current;
+ task->max_port = max;
+}
+
+/**
+ * @brief Add an open port to a task.
+ *
+ * @param[in] task The task.
+ * @param[in] number The port number.
+ * @param[in] protocol The port protocol.
+ */
+void
+append_task_open_port (task_t task, unsigned int number, char* protocol)
+{
+ assert (task->open_ports != NULL);
+ if (task->open_ports)
+ {
+ port_t port;
+
+ port.number = number;
+ if (strncasecmp ("udp", protocol, 3) == 0)
+ port.protocol = PORT_PROTOCOL_UDP;
+ else if (strncasecmp ("tcp", protocol, 3) == 0)
+ port.protocol = PORT_PROTOCOL_TCP;
+ else
+ port.protocol = PORT_PROTOCOL_OTHER;
+
+ (void) g_array_append_val (task->open_ports, port);
+ task->open_ports_size++;
+ }
+}
+
+
+/* General task facilities. */
+
+#if TRACE
+/**
+ * @brief Print the server tasks.
+ */
+static void
+print_tasks ()
+{
+ task_iterator_t iterator;
+ task_t index;
+
+ init_task_iterator (&iterator);
+ if (next_task (&iterator, &index))
+ {
+ do
+ {
+ char* comment = task_comment (index);
+ char* description = task_description (index);
+ tracef (" Task %u: \"%s\" %s\n%s\n\n",
+ task_id (index),
+ task_name (index),
+ comment ? comment : "",
+ description ? description : "");
+ }
+ while (next_task (&iterator, &index));
+ }
+ else
+ tracef (" Task array empty or still to be created.\n\n");
+}
+#endif
+
+/**
* @brief Create the current report file for a task.
*
* @param[in] task The task.
@@ -1756,206 +1992,3 @@
free (names);
return 0;
}
-
-/**
- * @brief Delete 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.
- */
-int
-delete_task (task_t* task_pointer)
-{
- gboolean success;
- const char* id;
- gchar* name;
- GError* error;
- task_t task = *task_pointer;
-
- tracef (" delete task %u\n", task->id);
-
- if (task_id_string (task, &id)) return -1;
-
- if (current_credentials.username == NULL) return -1;
-
- if (stop_task (task) == -1) return -1;
-
- // FIX may be atomic problems here
-
- if (delete_reports (task)) return -1;
-
- name = g_build_filename (PREFIX
- "/var/lib/openvas/mgr/users/",
- current_credentials.username,
- "tasks",
- id,
- NULL);
- error = NULL;
- success = rmdir_recursively (name, &error);
- if (success == FALSE)
- {
- if (error)
- {
- fprintf (stderr, "Failed to remove task dir %s: %s\n",
- name,
- error->message);
- g_error_free (error);
- }
- g_free (name);
- return -1;
- }
- g_free (name);
-
- free_task (task);
- *task_pointer = NULL;
-
- return 0;
-}
-
-/**
- * @brief Append text to the comment associated with a task.
- *
- * @param[in] task A pointer to the task.
- * @param[in] text The text to append.
- * @param[in] length Length of the text.
- *
- * @return 0 on success, -1 if out of memory.
- */
-int
-append_to_task_comment (task_t task, const char* text, /*@unused@*/ int length)
-{
- char* new;
- if (task->comment)
- {
- // FIX
- new = g_strconcat (task->comment, text, NULL);
- free (task->comment);
- task->comment = new;
- return 0;
- }
- new = strdup (text);
- if (new == NULL) return -1;
- task->comment = new;
- return 0;
-}
-
-/**
- * @brief Append text to the identifier associated with a task.
- *
- * @param[in] task A pointer to the task.
- * @param[in] text The text to append.
- * @param[in] length Length of the text.
- *
- * @return 0 on success, -1 if out of memory.
- */
-int
-append_to_task_identifier (task_t task, const char* text,
- /*@unused@*/ int length)
-{
- char* new;
- if (task->name)
- {
- new = g_strconcat (task->name, text, NULL);
- g_free (task->name);
- task->name = new;
- return 0;
- }
- new = strdup (text);
- if (new == NULL) return -1;
- task->name = new;
- return 0;
-}
-
-/**
- * @brief Reallocation increment for a task description.
- */
-#define DESCRIPTION_INCREMENT 4096
-
-/**
- * @brief Increase the memory allocated for a task description.
- *
- * @param[in] task A pointer to the task.
- * @param[in] increment Minimum number of bytes to increase memory.
- *
- * @return 0 on success, -1 if out of memory.
- */
-static int
-grow_description (task_t task, size_t increment)
-{
- size_t new_size = task->description_size
- + (increment < DESCRIPTION_INCREMENT
- ? DESCRIPTION_INCREMENT : increment);
- /* RATS: ignore *//* Memory cleared below. */
- char* new = realloc (task->description, new_size);
- if (new == NULL) return -1;
- memset (new, (int) '\0', new_size - task->description_size);
- task->description = new;
- task->description_size = new_size;
- return 0;
-}
-
-/**
- * @brief Add a line to a task description.
- *
- * @param[in] task A pointer to the task.
- * @param[in] line The line.
- * @param[in] line_length The length of the line.
- */
-int
-add_task_description_line (task_t task, const char* line, size_t line_length)
-{
- char* description;
- if (task->description_size - task->description_length < line_length
- && grow_description (task, line_length) < 0)
- return -1;
- description = task->description;
- description += task->description_length;
- strncpy (description, line, line_length);
- task->description_length += line_length;
- return 0;
-}
-
-/**
- * @brief Set the ports of a task.
- *
- * @param[in] task The task.
- * @param[in] current New value for port currently being scanned.
- * @param[in] max New value for last port to be scanned.
- */
-void
-set_task_ports (task_t task, unsigned int current, unsigned int max)
-{
- task->current_port = current;
- task->max_port = max;
-}
-
-/**
- * @brief Add an open port to a task.
- *
- * @param[in] task The task.
- * @param[in] number The port number.
- * @param[in] protocol The port protocol.
- */
-void
-append_task_open_port (task_t task, unsigned int number, char* protocol)
-{
- assert (task->open_ports != NULL);
- if (task->open_ports)
- {
- port_t port;
-
- port.number = number;
- if (strncasecmp ("udp", protocol, 3) == 0)
- port.protocol = PORT_PROTOCOL_UDP;
- else if (strncasecmp ("tcp", protocol, 3) == 0)
- port.protocol = PORT_PROTOCOL_TCP;
- else
- port.protocol = PORT_PROTOCOL_OTHER;
-
- (void) g_array_append_val (task->open_ports, port);
- task->open_ports_size++;
- }
-}
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2009-04-16 11:25:59 UTC (rev 3108)
+++ trunk/openvas-manager/src/manage.h 2009-04-16 14:01:19 UTC (rev 3109)
@@ -57,7 +57,7 @@
authenticate (credentials_t);
-/* Tasks. */
+/* Task structures. */
// FIX should be in otp.c/h
/**
@@ -140,6 +140,9 @@
task_t end;
} task_iterator_t;
+
+/* Task global variables. */
+
/**
* @brief The task currently running on the server.
*/
@@ -147,6 +150,9 @@
extern /*@null@*/ FILE* current_report;
+
+/* Task code specific to the representation of tasks. */
+
unsigned int
task_count ();
@@ -244,8 +250,8 @@
save_tasks ();
/*@dependent@*/
-task_t
-find_task (unsigned int id);
+gboolean
+find_task (const char* id, task_t*);
int
set_task_parameter (task_t,
@@ -253,12 +259,6 @@
/*@null@*/ /*@only@*/ char*);
int
-start_task (task_t);
-
-int
-stop_task (task_t);
-
-int
delete_task (task_t*);
int
@@ -277,6 +277,15 @@
append_task_open_port (task_t, unsigned int, char*);
+/* General task facilities. */
+
+int
+start_task (task_t);
+
+int
+stop_task (task_t);
+
+
/* Reports. */
// FIX how is this doc'd?
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-04-16 11:25:59 UTC (rev 3108)
+++ trunk/openvas-manager/src/omp.c 2009-04-16 14:01:19 UTC (rev 3109)
@@ -948,30 +948,22 @@
case CLIENT_ABORT_TASK:
if (current_task_task_id)
{
- unsigned int id;
assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
+ task_t task;
+ if (find_task (current_task_task_id, &task))
+ SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
+ "<status>407</status>"
+ "</abort_task_response>");
+ else if (stop_task (task))
{
- task_t task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
- "<status>407</status>"
- "</abort_task_response>");
- else if (stop_task (task))
- {
- /* to_server is full. */
- // FIX revert parsing for retry
- // process_omp_client_input must return -2
- abort ();
- }
- else
- SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
- "<status>201</status>"
- "</abort_task_response>");
+ /* to_server is full. */
+ // FIX revert parsing for retry
+ // process_omp_client_input must return -2
+ abort ();
}
else
SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
- "<status>40x</status>"
+ "<status>201</status>"
"</abort_task_response>");
free_string_var (¤t_task_task_id);
}
@@ -1289,32 +1281,24 @@
case CLIENT_DELETE_TASK:
if (current_task_task_id)
{
- unsigned int id;
assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
+ task_t task;
+ if (find_task (current_task_task_id, &task))
+ SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
+ "<status>407</status>"
+ "</delete_task_response>");
+ else if (delete_task (&task))
{
- task_t task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
- "<status>407</status>"
- "</delete_task_response>");
- else if (delete_task (&task))
- {
- /* to_server is full. */
- // FIX or some other error
- // FIX revert parsing for retry
- // process_omp_client_input must return -2
- tracef ("delete_task failed\n");
- abort ();
- }
- else
- SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
- "<status>201</status>"
- "</delete_task_response>");
+ /* to_server is full. */
+ // FIX or some other error
+ // FIX revert parsing for retry
+ // process_omp_client_input must return -2
+ tracef ("delete_task failed\n");
+ abort ();
}
else
SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
- "<status>40x</status>"
+ "<status>201</status>"
"</delete_task_response>");
free_string_var (¤t_task_task_id);
}
@@ -1382,43 +1366,35 @@
case CLIENT_MODIFY_TASK:
if (current_task_task_id)
{
- unsigned int id;
assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
+ task_t task;
+ if (find_task (current_task_task_id, &task))
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
+ "<status>407</status>"
+ "</modify_task_response>");
+ else
{
- task_t task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
- "<status>407</status>"
- "</modify_task_response>");
+ // FIX check if param,value else respond fail
+ int fail = set_task_parameter (task,
+ modify_task_parameter,
+ modify_task_value);
+ free (modify_task_parameter);
+ if (fail)
+ {
+ free (modify_task_value);
+ modify_task_value = NULL;
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
+ "<status>40x</status>"
+ "</modify_task_response>");
+ }
else
{
- // FIX check if param,value else respond fail
- int fail = set_task_parameter (task,
- modify_task_parameter,
- modify_task_value);
- free (modify_task_parameter);
- if (fail)
- {
- free (modify_task_value);
- modify_task_value = NULL;
- SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
- "<status>40x</status>"
- "</modify_task_response>");
- }
- else
- {
- modify_task_value = NULL;
- SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
- "<status>201</status>"
- "</modify_task_response>");
- }
+ modify_task_value = NULL;
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
+ "<status>201</status>"
+ "</modify_task_response>");
}
}
- else
- SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
- "<status>40x</status>"
- "</modify_task_response>");
free_string_var (¤t_task_task_id);
}
else
@@ -1486,30 +1462,22 @@
case CLIENT_START_TASK:
if (current_task_task_id)
{
- unsigned int id;
assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
+ task_t task;
+ if (find_task (current_task_task_id, &task))
+ SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
+ "<status>407</status>"
+ "</start_task_response>");
+ else if (start_task (task))
{
- task_t task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
- "<status>407</status>"
- "</start_task_response>");
- else if (start_task (task))
- {
- /* to_server is full. */
- // FIX revert parsing for retry
- // process_omp_client_input must return -2
- abort ();
- }
- else
- SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
- "<status>201</status>"
- "</start_task_response>");
+ /* to_server is full. */
+ // FIX revert parsing for retry
+ // process_omp_client_input must return -2
+ abort ();
}
else
SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
- "<status>40x</status>"
+ "<status>201</status>"
"</start_task_response>");
free_string_var (¤t_task_task_id);
}
@@ -1526,33 +1494,26 @@
assert (strncasecmp ("STATUS", element_name, 6) == 0);
if (current_task_task_id)
{
- unsigned int id;
- if (sscanf (current_task_task_id, "%u", &id) == 1)
+ task_t task;
+ if (find_task (current_task_task_id, &task))
+ SEND_TO_CLIENT_OR_FAIL ("<status_response>"
+ "<status>407</status>");
+ else
{
- task_t task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT_OR_FAIL ("<status_response>"
- "<status>407</status>");
- else
+ gchar* response;
+ SEND_TO_CLIENT_OR_FAIL ("<status_response><status>200</status>");
+ response = g_strdup_printf ("<report_count>%u</report_count>",
+ task_report_count (task));
+ if (send_to_client (response))
{
- gchar* response;
- SEND_TO_CLIENT_OR_FAIL ("<status_response><status>200</status>");
- response = g_strdup_printf ("<report_count>%u</report_count>",
- task_report_count (task));
- if (send_to_client (response))
- {
- g_free (response);
- error_send_to_client (error);
- return;
- }
g_free (response);
- // FIX need to handle err cases before send status
- (void) send_reports (task);
+ error_send_to_client (error);
+ return;
}
+ g_free (response);
+ // FIX need to handle err cases before send status
+ (void) send_reports (task);
}
- else
- SEND_TO_CLIENT_OR_FAIL ("<status_response>"
- "<status>40x</status>");
free_string_var (¤t_task_task_id);
}
else
More information about the Openvas-commits
mailing list