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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Dec 27 20:53:25 CET 2009


Author: mattm
Date: 2009-12-27 20:53:24 +0100 (Sun, 27 Dec 2009)
New Revision: 6262

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/tasks_sql.h
Log:
	* src/tasks_sql.h (collate_threat): New function.
	(condition_met): Call collate_threat to compare threats.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-12-27 18:24:13 UTC (rev 6261)
+++ trunk/openvas-manager/ChangeLog	2009-12-27 19:53:24 UTC (rev 6262)
@@ -1,5 +1,10 @@
 2009-12-27  Matthew Mundell <matthew.mundell at intevation.de>
 
+	* src/tasks_sql.h (collate_threat): New function.
+	(condition_met): Call collate_threat to compare threats.
+
+2009-12-27  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/tasks_sql.h (init_target_iterator): Add name arg.
 	(init_target_task_iterator, target_task_iterator_name)
 	(target_task_iterator_uuid): New functions.

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-12-27 18:24:13 UTC (rev 6261)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-12-27 19:53:24 UTC (rev 6262)
@@ -1916,6 +1916,71 @@
   return strncmp (one, two, MIN (one_len, two_len));
 }
 
+/**
+ * @brief Collate two threat levels.
+ *
+ * A lower threat is considered less than a higher threat, so Medium is
+ * less than High.
+ *
+ * @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_threat (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 (strncmp (one, "High", one_len) == 0)
+    {
+      if (strncmp (two, "High", two_len) == 0)
+        return 0;
+      return 1;
+    }
+  if (strncmp (two, "High", two_len) == 0) return -1;
+
+  if (strncmp (one, "Medium", one_len) == 0)
+    {
+      if (strncmp (two, "Medium", two_len) == 0)
+        return 0;
+      return 1;
+    }
+  if (strncmp (two, "Medium", two_len) == 0) return -1;
+
+  if (strncmp (one, "Low", one_len) == 0)
+    {
+      if (strncmp (two, "Low", two_len) == 0)
+        return 0;
+      return 1;
+    }
+  if (strncmp (two, "Low", two_len) == 0) return -1;
+
+  if (strncmp (one, "Log", one_len) == 0)
+    {
+      if (strncmp (two, "Log", two_len) == 0)
+        return 0;
+      return 1;
+    }
+  if (strncmp (two, "Log", two_len) == 0) return -1;
+
+  if (strncmp (one, "Debug", one_len) == 0)
+    {
+      if (strncmp (two, "Debug", two_len) == 0)
+        return 0;
+      return 1;
+    }
+  if (strncmp (two, "Debug", two_len) == 0) return -1;
+
+  return strncmp (one, two, MIN (one_len, two_len));
+}
+
 
 /* Events and Escalators. */
 
@@ -2496,11 +2561,11 @@
           report_level = task_threat_level (task);
           if (condition_level
               && report_level
-              && (collate_message_type (NULL,
-                                        strlen (report_level),
-                                        report_level,
-                                        strlen (condition_level),
-                                        condition_level)
+              && (collate_threat (NULL,
+                                  strlen (report_level),
+                                  report_level,
+                                  strlen (condition_level),
+                                  condition_level)
                   > -1))
             {
               free (condition_level);



More information about the Openvas-commits mailing list