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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Dec 29 14:45:16 CET 2009


Author: mattm
Date: 2009-12-29 14:45:12 +0100 (Tue, 29 Dec 2009)
New Revision: 6272

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	* src/tasks_sql.h (init_escalator_iterator): Add name arg.  Update caller.
	(init_escalator_task_iterator, escalator_task_iterator_name)
	(escalator_task_iterator_uuid): New functions.

	* src/manage.h: Update headers accordingly.

	* src/omp.c (omp_xml_handle_start_element): Get name attrib for
	GET_ESCALATORS.
	(omp_xml_handle_end_element): In CLIENT_GET_ESCALATORS return task list
	if name attribute is present.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-12-29 12:41:58 UTC (rev 6271)
+++ trunk/openvas-manager/ChangeLog	2009-12-29 13:45:12 UTC (rev 6272)
@@ -1,5 +1,18 @@
 2009-12-29  Matthew Mundell <matthew.mundell at intevation.de>
 
+	* src/tasks_sql.h (init_escalator_iterator): Add name arg.  Update caller.
+	(init_escalator_task_iterator, escalator_task_iterator_name)
+	(escalator_task_iterator_uuid): New functions.
+
+	* src/manage.h: Update headers accordingly.
+
+	* src/omp.c (omp_xml_handle_start_element): Get name attrib for
+	GET_ESCALATORS.
+	(omp_xml_handle_end_element): In CLIENT_GET_ESCALATORS return task list
+	if name attribute is present.
+
+2009-12-29  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/tasks_sql.h (manage_set_config_preference)
 	(manage_set_config_nvts, manage_set_config_families): Return 1 if the
 	config is in use.

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-12-29 12:41:58 UTC (rev 6271)
+++ trunk/openvas-manager/src/manage.h	2009-12-29 13:45:12 UTC (rev 6272)
@@ -193,7 +193,7 @@
 #endif /* not TASKS_SQL */
 
 
-/* Events. */
+/* Events and Escalators. */
 
 /**
  * @brief Types of task events.
@@ -235,7 +235,8 @@
 find_escalator (const char*, escalator_t*);
 
 void
-init_escalator_iterator (iterator_t*, task_t, event_t, int, const char*);
+init_escalator_iterator (iterator_t*, const char*, task_t, event_t, int,
+                         const char*);
 
 escalator_t
 escalator_iterator_escalator (iterator_t*);
@@ -291,6 +292,15 @@
 const char*
 escalator_data_iterator_data (iterator_t*);
 
+void
+init_escalator_task_iterator (iterator_t*, const char *, int);
+
+const char*
+escalator_task_iterator_name (iterator_t*);
+
+const char*
+escalator_task_iterator_uuid (iterator_t*);
+
 
 /* Task global variables. */
 

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-12-29 12:41:58 UTC (rev 6271)
+++ trunk/openvas-manager/src/omp.c	2009-12-29 13:45:12 UTC (rev 6272)
@@ -1183,6 +1183,9 @@
           {
             const gchar* attribute;
             if (find_attribute (attribute_names, attribute_values,
+                                "name", &attribute))
+              openvas_append_string (&current_name, attribute);
+            if (find_attribute (attribute_names, attribute_values,
                                 "sort_field", &attribute))
               openvas_append_string (&current_format, attribute);
             if (find_attribute (attribute_names, attribute_values,
@@ -7434,6 +7437,7 @@
                                   " status=\"" STATUS_OK "\""
                                   " status_text=\"" STATUS_OK_TEXT "\">");
           init_escalator_iterator (&escalators,
+                                   current_name,
                                    (task_t) 0,
                                    (event_t) 0,
                                    current_int_2,   /* Attribute sort_order. */
@@ -7509,11 +7513,40 @@
               cleanup_iterator (&data);
               SEND_TO_CLIENT_OR_FAIL ("</method>");
 
+              /**
+               * @todo
+               * (OMP) For consistency, the operations should respond the
+               * same way if one, some or all elements are requested.  The
+               * level of details in the response should instead be controlled
+               * by some other mechanism, like a details flag.
+               */
+
+              if (current_name)
+                {
+                  iterator_t tasks;
+
+                  SEND_TO_CLIENT_OR_FAIL ("<tasks>");
+                  init_escalator_task_iterator (&tasks,
+                                                current_name,
+                                                /* Attribute sort_order. */
+                                                current_int_2);
+                  while (next (&tasks))
+                    SENDF_TO_CLIENT_OR_FAIL
+                     ("<task id=\"%s\">"
+                      "<name>%s</name>"
+                      "</task>",
+                      escalator_task_iterator_uuid (&tasks),
+                      escalator_task_iterator_name (&tasks));
+                  cleanup_iterator (&tasks);
+                  SEND_TO_CLIENT_OR_FAIL ("</tasks>");
+                }
+
               SEND_TO_CLIENT_OR_FAIL ("</escalator>");
             }
           cleanup_iterator (&escalators);
           SEND_TO_CLIENT_OR_FAIL ("</get_escalators_response>");
           openvas_free_string_var (&current_format);
+          openvas_free_string_var (&current_name);
           set_client_state (CLIENT_AUTHENTIC);
           break;
         }

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-12-29 12:41:58 UTC (rev 6271)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-12-29 13:45:12 UTC (rev 6272)
@@ -2222,6 +2222,7 @@
  * @brief Initialise an escalator iterator.
  *
  * @param[in]  iterator    Iterator.
+ * @param[in]  name        Name of single task to iterator over, NULL for all.
  * @param[in]  task        Iterate over escalators for this task.  0 for all.
  * @param[in]  event       Iterate over escalators handling this event.  0 for
  *                         all.
@@ -2229,10 +2230,30 @@
  * @param[in]  sort_field  Field to sort on, or NULL for "ROWID".
  */
 void
-init_escalator_iterator (iterator_t *iterator, task_t task, event_t event,
-                         int ascending, const char *sort_field)
+init_escalator_iterator (iterator_t *iterator, const char *name, task_t task,
+                         event_t event, int ascending, const char *sort_field)
 {
-  if (task)
+  assert (name ? task == 0 : (task ? name == NULL : 1));
+  assert (name ? event == 0 : (event ? name == NULL : 1));
+  assert (event ? task : 1);
+
+  if (name)
+    {
+      gchar *quoted_name = sql_quote (name);
+      init_iterator (iterator,
+                     "SELECT escalators.ROWID, name, comment,"
+                     " 0, event, condition, method,"
+                     " (SELECT count(*) > 0 FROM task_escalators"
+                     "  WHERE task_escalators.escalator = escalators.ROWID)"
+                     " FROM escalators"
+                     " WHERE name = '%s'"
+                     " ORDER BY %s %s;",
+                     quoted_name,
+                     sort_field ? sort_field : "escalators.ROWID",
+                     ascending ? "ASC" : "DESC");
+      g_free (quoted_name);
+    }
+  else if (task)
     init_iterator (iterator,
                    "SELECT escalators.ROWID, name, comment,"
                    " task_escalators.task, event, condition, method, 1"
@@ -2244,8 +2265,6 @@
                    event,
                    sort_field ? sort_field : "escalators.ROWID",
                    ascending ? "ASC" : "DESC");
-  else if (event)
-    abort (); /** @todo Complete. */
   else
     init_iterator (iterator,
                    "SELECT escalators.ROWID, name, comment,"
@@ -2660,7 +2679,7 @@
 {
   iterator_t escalators;
   tracef ("   EVENT %i on task %llu", event, task);
-  init_escalator_iterator (&escalators, task, event, 1, NULL);
+  init_escalator_iterator (&escalators, NULL, task, event, 1, NULL);
   while (next (&escalators))
     {
       escalator_t escalator = escalator_iterator_escalator (&escalators);
@@ -2681,6 +2700,59 @@
   cleanup_iterator (&escalators);
 }
 
+/**
+ * @brief Initialise an escalator task iterator.
+ *
+ * Iterate over all tasks that use the escalator.
+ *
+ * @param[in]  iterator   Iterator.
+ * @param[in]  name       Name of escalator.
+ * @param[in]  ascending  Whether to sort ascending or descending.
+ */
+void
+init_escalator_task_iterator (iterator_t* iterator, const char *name,
+                              int ascending)
+{
+  gchar *quoted_name = sql_quote (name);
+  init_iterator (iterator,
+                 "SELECT tasks.name, tasks.uuid FROM tasks, task_escalators"
+                 " WHERE tasks.ROWID = task_escalators.task"
+                 " AND task_escalators.escalator ="
+                 " (SELECT ROWID FROM escalators WHERE escalators.name = '%s')"
+                 " ORDER BY tasks.name %s;",
+                 quoted_name,
+                 ascending ? "ASC" : "DESC");
+  g_free (quoted_name);
+}
+
+/**
+ * @brief Return the name from an escalator task iterator.
+ *
+ * @param[in]  iterator  Iterator.
+ */
+const char*
+escalator_task_iterator_name (iterator_t* iterator)
+{
+  const char *ret;
+  if (iterator->done) return NULL;
+  ret = (const char*) sqlite3_column_text (iterator->stmt, 0);
+  return ret;
+}
+
+/**
+ * @brief Return the uuid from an escalator task iterator.
+ *
+ * @param[in]  iterator  Iterator.
+ */
+const char*
+escalator_task_iterator_uuid (iterator_t* iterator)
+{
+  const char *ret;
+  if (iterator->done) return NULL;
+  ret = (const char*) sqlite3_column_text (iterator->stmt, 1);
+  return ret;
+}
+
 
 /* Task functions. */
 



More information about the Openvas-commits mailing list