[Openvas-commits] r6779 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Feb 18 17:37:02 CET 2010
Author: mattm
Date: 2010-02-18 17:37:01 +0100 (Thu, 18 Feb 2010)
New Revision: 6779
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tasks_sql.h
Log:
Add TASK to OMP GET_NOTES.
* src/omp.c (get_notes_data_t): Add task_id.
(get_notes_data_reset): Free task_id.
(client_state_t): Add CLIENT_GET_NOTES_TASK.
(omp_xml_handle_start_element, omp_xml_handle_end_element): Add NVT to
GET_NOTES.
* src/tasks_sql.h (NOTE_COLUMNS): New define.
(init_note_iterator): If result is 0 and task is above 0, then select
all notes on the task, otherwise select all notes on the result as before.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2010-02-18 15:49:21 UTC (rev 6778)
+++ trunk/openvas-manager/ChangeLog 2010-02-18 16:37:01 UTC (rev 6779)
@@ -1,5 +1,19 @@
2010-02-18 Matthew Mundell <matthew.mundell at intevation.de>
+ Add TASK to OMP GET_NOTES.
+
+ * src/omp.c (get_notes_data_t): Add task_id.
+ (get_notes_data_reset): Free task_id.
+ (client_state_t): Add CLIENT_GET_NOTES_TASK.
+ (omp_xml_handle_start_element, omp_xml_handle_end_element): Add NVT to
+ GET_NOTES.
+
+ * src/tasks_sql.h (NOTE_COLUMNS): New define.
+ (init_note_iterator): If result is 0 and task is above 0, then select
+ all notes on the task, otherwise select all notes on the result as before.
+
+2010-02-18 Matthew Mundell <matthew.mundell at intevation.de>
+
* ChangeLog: Restore overwritten entry.
2010-02-18 Matthew Mundell <matthew.mundell at intevation.de>
@@ -34,7 +48,7 @@
* src/manage.h: Update header accordingly.
* src/omp.c: Update init_note_iterator callers.
- (get_results_data_t): Add nvt_oid.
+ (get_notes_data_t): Add nvt_oid.
(get_notes_data_reset): Free nvt_oid.
(client_state_t): Add CLIENT_GET_NOTES_NVT.
(omp_xml_handle_start_element, omp_xml_handle_end_element): Add NVT to
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2010-02-18 15:49:21 UTC (rev 6778)
+++ trunk/openvas-manager/src/omp.c 2010-02-18 16:37:01 UTC (rev 6779)
@@ -574,6 +574,7 @@
{
char *note_id;
char *nvt_oid;
+ char *task_id;
char *sort_field;
int sort_order;
int details;
@@ -584,6 +585,7 @@
{
free (data->note_id);
free (data->nvt_oid);
+ free (data->task_id);
memset (data, 0, sizeof (get_notes_data_t));
}
@@ -960,6 +962,7 @@
CLIENT_GET_LSC_CREDENTIALS,
CLIENT_GET_NOTES,
CLIENT_GET_NOTES_NVT,
+ CLIENT_GET_NOTES_TASK,
CLIENT_GET_NVT_ALL,
CLIENT_GET_NVT_DETAILS,
CLIENT_GET_NVT_FAMILIES,
@@ -2195,6 +2198,14 @@
openvas_append_string (&get_notes_data->nvt_oid, attribute);
set_client_state (CLIENT_GET_NOTES_NVT);
}
+ else if (strcasecmp ("TASK", element_name) == 0)
+ {
+ const gchar* attribute;
+ if (find_attribute (attribute_names, attribute_values,
+ "id", &attribute))
+ openvas_append_string (&get_notes_data->task_id, attribute);
+ set_client_state (CLIENT_GET_NOTES_TASK);
+ }
else
{
if (send_element_error_to_client ("get_notes", element_name))
@@ -2221,6 +2232,18 @@
G_MARKUP_ERROR_UNKNOWN_ELEMENT,
"Error");
break;
+ case CLIENT_GET_NOTES_TASK:
+ if (send_element_error_to_client ("get_notes", element_name))
+ {
+ error_send_to_client (error);
+ return;
+ }
+ set_client_state (CLIENT_AUTHENTIC);
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "Error");
+ break;
case CLIENT_GET_NVT_ALL:
{
@@ -4834,13 +4857,20 @@
{
note_t note = 0;
nvt_t nvt = 0;
+ task_t task = 0;
assert (strcasecmp ("GET_NOTES", element_name) == 0);
if (get_notes_data->note_id && get_notes_data->nvt_oid)
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("get_notes",
- "Only one of NVT and the note attribute may be given"));
+ "Only one of NVT and the note_id attribute"
+ " may be given"));
+ else if (get_notes_data->note_id && get_notes_data->task_id)
+ SEND_TO_CLIENT_OR_FAIL
+ (XML_ERROR_SYNTAX ("get_notes",
+ "Only one of the note_id and task_id"
+ " attributes may be given"));
else if (get_notes_data->note_id
&& find_note (get_notes_data->note_id, ¬e))
SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_notes"));
@@ -4854,6 +4884,19 @@
return;
}
}
+ else if (get_notes_data->task_id
+ && find_task (get_notes_data->task_id, &task))
+ SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_notes"));
+ else if (get_notes_data->task_id && task == 0)
+ {
+ if (send_find_error_to_client ("get_notes",
+ "task",
+ get_notes_data->task_id))
+ {
+ error_send_to_client (error);
+ return;
+ }
+ }
else if (get_notes_data->nvt_oid
&& find_nvt (get_notes_data->nvt_oid, &nvt))
SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_notes"));
@@ -4882,7 +4925,7 @@
note,
nvt,
0,
- 0,
+ task,
get_notes_data->sort_order,
get_notes_data->sort_field);
buffer_notes_xml (buffer, ¬es, get_notes_data->details);
@@ -4902,6 +4945,10 @@
assert (strcasecmp ("NVT", element_name) == 0);
set_client_state (CLIENT_GET_NOTES);
break;
+ case CLIENT_GET_NOTES_TASK:
+ assert (strcasecmp ("TASK", element_name) == 0);
+ set_client_state (CLIENT_GET_NOTES);
+ break;
case CLIENT_GET_NVT_FEED_CHECKSUM:
{
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2010-02-18 15:49:21 UTC (rev 6778)
+++ trunk/openvas-manager/src/tasks_sql.h 2010-02-18 16:37:01 UTC (rev 6779)
@@ -11577,13 +11577,20 @@
return 0;
}
+#define NOTE_COLUMNS "notes.ROWID, notes.uuid, notes.nvt," \
+ " notes.creation_time, notes.modification_time," \
+ " notes.text, notes.hosts, notes.port, notes.threat," \
+ " notes.task, notes.result"
+
/**
* @brief Initialise a note iterator.
*
* @param[in] iterator Iterator.
* @param[in] note Single note to iterate, 0 for all.
* @param[in] result Result to limit notes to, 0 for all.
- * @param[in] task Task to limit notes to, 0 for all.
+ * @param[in] task If result is > 0, task whose notes on result to
+ * include, otherwise task to limit notes to. 0 for
+ * all tasks.
* @param[in] nvt NVT to limit notes to, 0 for all.
* @param[in] ascending Whether to sort ascending or descending.
* @param[in] sort_field Field to sort on, or NULL for "ROWID".
@@ -11593,10 +11600,11 @@
result_t result, task_t task, int ascending,
const char* sort_field)
{
- gchar *result_clause;
+ gchar *result_clause, *join_clause = NULL;
assert (current_credentials.uuid);
assert ((nvt && note) == 0);
+ assert ((task && note) == 0);
if (result)
result_clause = g_strdup_printf (" AND"
@@ -11626,13 +11634,27 @@
result,
result,
task);
+ else if (task)
+ {
+ result_clause = g_strdup_printf
+ (" AND (notes.task = %llu OR notes.task = 0)"
+ " AND reports.task = %llu"
+ " AND reports.ROWID = report_results.report"
+ " AND report_results.result = results.ROWID"
+ " AND results.nvt = notes.nvt"
+ " AND"
+ " (notes.result = 0"
+ " OR report_results.result = notes.result)",
+ task,
+ task);
+ join_clause = g_strdup (", reports, report_results, results");
+ }
else
result_clause = NULL;
if (note)
init_iterator (iterator,
- "SELECT ROWID, uuid, nvt, creation_time, modification_time,"
- " text, hosts, port, threat, task, result"
+ "SELECT " NOTE_COLUMNS
" FROM notes"
" WHERE ROWID = %llu"
" AND ((owner IS NULL) OR (owner ="
@@ -11646,14 +11668,15 @@
ascending ? "ASC" : "DESC");
else if (nvt)
init_iterator (iterator,
- "SELECT ROWID, uuid, nvt, creation_time, modification_time,"
- " text, hosts, port, threat, task, result"
- " FROM notes"
- " WHERE (nvt = (SELECT oid FROM nvts WHERE ROWID = %llu))"
- " AND ((owner IS NULL) OR (owner ="
+ "SELECT DISTINCT " NOTE_COLUMNS
+ " FROM notes%s"
+ " WHERE (notes.nvt ="
+ " (SELECT oid FROM nvts WHERE nvts.ROWID = %llu))"
+ " AND ((notes.owner IS NULL) OR (notes.owner ="
" (SELECT ROWID FROM users WHERE users.uuid = '%s')))"
"%s"
- " ORDER BY %s %s;",
+ " ORDER BY notes.%s %s;",
+ join_clause ? join_clause : "",
nvt,
current_credentials.uuid,
result_clause ? result_clause : "",
@@ -11661,19 +11684,20 @@
ascending ? "ASC" : "DESC");
else
init_iterator (iterator,
- "SELECT ROWID, uuid, nvt, creation_time, modification_time,"
- " text, hosts, port, threat, task, result"
- " FROM notes"
- " WHERE ((owner IS NULL) OR (owner ="
+ "SELECT DISTINCT " NOTE_COLUMNS
+ " FROM notes%s"
+ " WHERE ((notes.owner IS NULL) OR (notes.owner ="
" (SELECT ROWID FROM users WHERE users.uuid = '%s')))"
"%s"
- " ORDER BY %s %s;",
+ " ORDER BY notes.%s %s;",
+ join_clause ? join_clause : "",
current_credentials.uuid,
result_clause ? result_clause : "",
sort_field ? sort_field : "ROWID",
ascending ? "ASC" : "DESC");
g_free (result_clause);
+ g_free (join_clause);
}
DEF_ACCESS (note_iterator_uuid, 1);
More information about the Openvas-commits
mailing list