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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Oct 24 13:06:20 CEST 2009


Author: mattm
Date: 2009-10-24 13:06:20 +0200 (Sat, 24 Oct 2009)
New Revision: 5703

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/tasks_sql.h
Log:
	* src/tasks_sql.h (collate_message_type): New function.
	(init_manage_process): Create collate_message_type collation.
	(init_result_iterator): Order types with collation collate_message_type.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-10-23 21:45:30 UTC (rev 5702)
+++ trunk/openvas-manager/ChangeLog	2009-10-24 11:06:20 UTC (rev 5703)
@@ -1,5 +1,11 @@
 2009-10-23  Matthew Mundell <matthew.mundell at intevation.de>
 
+	* src/tasks_sql.h (collate_message_type): New function.
+	(init_manage_process): Create collate_message_type collation.
+	(init_result_iterator): Order types with collation collate_message_type.
+
+2009-10-23  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/omp.c (print_report_latex): Skip Log and Debug messages.
 
 2009-10-23  Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-10-23 21:45:30 UTC (rev 5702)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-10-24 11:06:20 UTC (rev 5703)
@@ -654,6 +654,73 @@
 }
 
 
+/* Collation. */
+
+/**
+ * @brief Collate two message type strings.
+ *
+ * Callback for SQLite "collate_message_type" collation.
+ *
+ * @param[in]  data     Dummy for callback.
+ * @param[in]  one_len  Length of first string.
+ * @param[in]  arg_one  First string.
+ * @param[in]  two_len  Length of second string.
+ * @param[in]  arg_two  Second string.
+ *
+ * @return -1, 0 or 1 if first is less than, equal to or greater than second.
+ */
+int
+collate_message_type (void* data,
+                      int one_len, const void* arg_one,
+                      int two_len, const void* arg_two)
+{
+  const char* one = (const char*) arg_one;
+  const char* two = (const char*) arg_two;
+
+  if (strcmp (one, "Security Hole") == 0)
+    {
+      if (strcmp (two, "Security Hole") == 0)
+        return 0;
+      return -1;
+    }
+  if (strcmp (two, "Security Hole") == 0) return 1;
+
+  if (strcmp (one, "Security Warning") == 0)
+    {
+      if (strcmp (two, "Security Warning") == 0)
+        return 0;
+      return -1;
+    }
+  if (strcmp (two, "Security Warning") == 0) return 1;
+
+  if (strcmp (one, "Security Note") == 0)
+    {
+      if (strcmp (two, "Security Note") == 0)
+        return 0;
+      return -1;
+    }
+  if (strcmp (two, "Security Note") == 0) return 1;
+
+  if (strcmp (one, "Log Message") == 0)
+    {
+      if (strcmp (two, "Log Message") == 0)
+        return 0;
+      return -1;
+    }
+  if (strcmp (two, "Log Message") == 0) return 1;
+
+  if (strcmp (one, "Debug Message") == 0)
+    {
+      if (strcmp (two, "Debug Message") == 0)
+        return 0;
+      return -1;
+    }
+  if (strcmp (two, "Debug Message") == 0) return 1;
+
+  return strcmp (one, two);
+}
+
+
 /* Task functions. */
 
 void
@@ -854,6 +921,21 @@
       sql ("DELETE FROM meta WHERE name = 'nvts_checksum';");
       sql ("COMMIT;");
     }
+  else
+    {
+      /* Create the collate functions. */
+
+      if (sqlite3_create_collation (task_db,
+                                    "collate_message_type",
+                                    SQLITE_UTF8,
+                                    NULL,
+                                    collate_message_type)
+          != SQLITE_OK)
+        {
+          g_message ("%s: failed to create collate_message_type", __FUNCTION__);
+          abort ();
+        }
+    }
 }
 
 /**
@@ -2226,7 +2308,8 @@
                                " WHERE report_results.report = %llu"
                                " AND report_results.result = results.ROWID"
                                " AND results.host = '%s'"
-                               " ORDER BY port, type"
+                               " ORDER BY port,"
+                               " type COLLATE collate_message_type DESC"
                                " LIMIT %i OFFSET %i;",
                                report, host, max_results, first_result);
       else
@@ -2234,7 +2317,8 @@
                                " FROM results, report_results"
                                " WHERE report_results.report = %llu"
                                " AND report_results.result = results.ROWID"
-                               " ORDER BY host, port, type"
+                               " ORDER BY host, port,"
+                               " type COLLATE collate_message_type DESC"
                                " LIMIT %i OFFSET %i;",
                                report, max_results, first_result);
     }



More information about the Openvas-commits mailing list