[Openvas-commits] r5638 - in trunk/openvas-client: . openvas

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 20 09:59:19 CEST 2009


Author: felix
Date: 2009-10-20 09:59:18 +0200 (Tue, 20 Oct 2009)
New Revision: 5638

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/openvas/attack.c
   trunk/openvas-client/openvas/openvas_plugin.c
   trunk/openvas-client/openvas/openvas_plugin.h
Log:
* openvas/openvas_plugin.c (openvas_plugin_list_length): New. Counts
the number of plugins in a list.

* openvas/openvas_plugin.h: Added proto, minor doc.

* openvas/attack.c (attack_host, restore_attack): Use new function,
resolved todo.


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-10-20 07:51:23 UTC (rev 5637)
+++ trunk/openvas-client/ChangeLog	2009-10-20 07:59:18 UTC (rev 5638)
@@ -1,5 +1,15 @@
 2009-10-20  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
+	* openvas/openvas_plugin.c (openvas_plugin_list_length): New. Counts
+	the number of plugins in a list.
+
+	* openvas/openvas_plugin.h: Added proto, minor doc.
+
+	* openvas/attack.c (attack_host, restore_attack): Use new function,
+	resolved todo.
+
+2009-10-20  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
 	* openvas/openvas_plugin.c: Cosmetics.
 
 2009-10-20  Felix Wolfsteller <felix.wolfsteller at intevation.de>

Modified: trunk/openvas-client/openvas/attack.c
===================================================================
--- trunk/openvas-client/openvas/attack.c	2009-10-20 07:51:23 UTC (rev 5637)
+++ trunk/openvas-client/openvas/attack.c	2009-10-20 07:59:18 UTC (rev 5638)
@@ -44,24 +44,12 @@
 {
   struct arglist * preferences = context->prefs;
   char * plug_list, * old_plug_list;
-  struct openvas_plugin * plugs = context->plugins;
-  struct openvas_plugin * scans = context->scanners;
   struct arglist * serv_prefs;
-  int num_plug = 0;
-  int num_scanners = 0;
 
   /* Count how many plugins we have */
-  while(plugs != NULL ){
-    num_plug++;
-    plugs = plugs->next;
-  }
+  int num_plug     = openvas_plugin_list_length (context->plugins);
+  int num_scanners = openvas_plugin_list_length (context->scanners);
 
-  while(scans != NULL )
-  {
-   num_scanners++;
-   scans = scans->next;
-  }
-
   /* Set up the plugin list, according to the
    * OpenVAS Transfer Protocol version 1.1 / OTP */
   plug_list = emalloc(num_plug*100+1+num_scanners*100+1);
@@ -102,8 +90,6 @@
 {
   struct arglist * preferences = context->prefs;
   char * plug_list, * old_plug_list;
-  struct openvas_plugin * plugs = context->plugins;
-  struct openvas_plugin * scans = context->scanners;
   struct arglist * serv_prefs;
   int num_plug = 0;
   int num_scanners = 0;
@@ -205,20 +191,10 @@
       efree (&fileloc);
     }
 
-  /** @TODO Use counting function */
   /* Count how many plugins we have */
-  while (plugs != NULL)
-    {
-      num_plug++;
-      plugs = plugs->next;
-    }
+  num_plug     = openvas_plugin_list_length (context->plugins);
+  num_scanners = openvas_plugin_list_length (context->scanners);
 
-  while (scans != NULL)
-    {
-      num_scanners++;
-      scans = scans->next;
-    }
-
   /* Set up the plugin list, according to the
    * OpenVAS Transfer Protocol version 1.1 / OTP */
   plug_list = emalloc(num_plug*100+1+num_scanners*100+1);

Modified: trunk/openvas-client/openvas/openvas_plugin.c
===================================================================
--- trunk/openvas-client/openvas/openvas_plugin.c	2009-10-20 07:51:23 UTC (rev 5637)
+++ trunk/openvas-client/openvas/openvas_plugin.c	2009-10-20 07:59:18 UTC (rev 5638)
@@ -94,6 +94,29 @@
 
 
 /**
+ * @brief Traverses a list of NVT and returns the count.
+ *
+ * @param list List of NVTs, if NULL, returns 0.
+ *
+ * @return Number of NVTs in list (0 if \ref list equals NULL).
+ */
+int
+openvas_plugin_list_length (struct openvas_plugin* list)
+{
+  int count = 0;
+  struct openvas_plugin * nvt = list;
+
+  while (nvt != NULL)
+    {
+      ++count;
+      nvt = nvt->next;
+    }
+
+  return count;
+}
+
+
+/**
  * @brief Set the md5 sum of the plugin (parameter is copied).
  * 
  * @param plugin The NVT to get a new md5sum.

Modified: trunk/openvas-client/openvas/openvas_plugin.h
===================================================================
--- trunk/openvas-client/openvas/openvas_plugin.h	2009-10-20 07:51:23 UTC (rev 5637)
+++ trunk/openvas-client/openvas/openvas_plugin.h	2009-10-20 07:59:18 UTC (rev 5638)
@@ -21,8 +21,8 @@
 #include <openvas/base/nvti.h> /* for nvti_t */
 
 /**
- * @brief Basic openvas_plugin struct, describing a NVT and eventual preferences
- *        in their user-modified state.
+ * @brief Basic openvas_plugin struct, describing a NVT and maybe preferences
+ * @brief in their user-modified state.
  * 
  * Implements a single-linked list (through a 'next' pointer).
  */
@@ -51,4 +51,6 @@
 
 struct openvas_plugin* openvas_plugin_duplicate(struct openvas_plugin *);
 
+int openvas_plugin_list_length (struct openvas_plugin*);
+
 #endif /* _OPENVAS_OPENVAS_PLUGIN */



More information about the Openvas-commits mailing list