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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 9 12:33:32 CEST 2009


Author: jan
Date: 2009-10-09 12:33:31 +0200 (Fri, 09 Oct 2009)
New Revision: 5458

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/openvas/comm.c
Log:
Replaced self-made list "struct missing_plugins_list" by a GSList.
missing_plugin_list was actually a struct with a array inside, thats
why some protos change here as well.

* openvas/comm.c (comm_get_plugins_md5, add_md5sum_to_plugin): Changed
data pointer from void * to void **.
(struct missing_plugins_list, missing_plugins_list_init,
missing_plugins_list_add, missing_plugins_list_free): Removed.
(update_existing_plugin): Changed data pointer from
void * to void **. Handle the GSList instead of struct missing_plugins_list.
(fetch_new_plugins, update_individual_plugins): Handle the GSList instead
of struct missing_plugins_list.



Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-10-09 10:18:16 UTC (rev 5457)
+++ trunk/openvas-client/ChangeLog	2009-10-09 10:33:31 UTC (rev 5458)
@@ -1,3 +1,18 @@
+2009-10-09  Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
+
+	Replaced self-made list "struct missing_plugins_list" by a GSList.
+	missing_plugin_list was actually a struct with a array inside, thats
+	why some protos change here as well.
+
+	* openvas/comm.c (comm_get_plugins_md5, add_md5sum_to_plugin): Changed
+	data pointer from void * to void **.
+	(struct missing_plugins_list, missing_plugins_list_init,
+	missing_plugins_list_add, missing_plugins_list_free): Removed.
+	(update_existing_plugin): Changed data pointer from
+	void * to void **. Handle the GSList instead of struct missing_plugins_list.
+	(fetch_new_plugins, update_individual_plugins): Handle the GSList instead
+	of struct missing_plugins_list.
+
 2009-10-09  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
 	* openvas/preferences.c (preferences_init): Reformatted.

Modified: trunk/openvas-client/openvas/comm.c
===================================================================
--- trunk/openvas-client/openvas/comm.c	2009-10-09 10:18:16 UTC (rev 5457)
+++ trunk/openvas-client/openvas/comm.c	2009-10-09 10:33:31 UTC (rev 5458)
@@ -1482,8 +1482,8 @@
 comm_get_plugins_md5(struct context *context, char * buf, int bufsz,
     int (callback)(struct context *context, const char * oid,
                    const char * md5sum, struct openvas_plugin * plugin,
-                   void * data),
-    void * data)
+                   void ** data),
+    void ** data)
 {
 #ifdef USE_OMP
   if (context->protocol == PROTOCOL_OMP)
@@ -1591,71 +1591,14 @@
   return 0;
 }
 
-/* Manage a list (well actually an array) of missing or outdated
- * plugins.  The list contains the ids and md5sums of the plugins */
-
+/* This struct aids the list of missing plugins */
 struct missing_plugin {
   char * oid;
   char * md5sum;
 };
 
-struct missing_plugins_list {
-  int allocated;
-  int length;
-  struct missing_plugin * plugins;
-};
 
 /**
- * @brief Initialize a missing_plugins_list struct.
- */
-static void
-missing_plugins_list_init (struct missing_plugins_list * missing)
-{
-  missing->length = missing->allocated = 0;
-  missing->plugins = NULL;
-}
-
-/**
- * @brief Add an entry to the list of missing/outdated plugins.
- */
-static void
-missing_plugins_list_add (struct missing_plugins_list * missing,
-                          const char * oid, const char * md5sum)
-{
-  if (missing->length == missing->allocated)
-  {
-    int new_length = missing->allocated + 1000;
-    if (missing->plugins != NULL)
-      missing->plugins = erealloc(missing->plugins,
-	  sizeof(struct missing_plugin) * new_length);
-    else
-      missing->plugins = emalloc(sizeof(struct missing_plugin) * new_length);
-    missing->allocated = new_length;
-  }
-
-  missing->plugins[missing->length].oid = estrdup(oid);
-  missing->plugins[missing->length].md5sum = estrdup(md5sum);
-  missing->length += 1;
-}
-
-
-/**
- * @brief Free the list (and only the list) of missing plugins.
- *
- * Does not free the struct itself.
- */
-static void
-missing_plugins_list_free(struct missing_plugins_list * missing)
-{
-  int i;
-  for (i = 0; i < missing->length; i++)
-    efree(&missing->plugins[i].md5sum);
-  efree(&missing->plugins);
-  missing_plugins_list_init(missing);
-}
-
-
-/**
  * @brief Callback for comm_get_plugins_md5 that checks the md5sum of an
  * @brief existing plugin.
  *
@@ -1669,7 +1612,7 @@
 static int
 update_existing_plugin (struct context *context,
                         const char * oid, const char * md5sum,
-                        struct openvas_plugin * plugin, void * data)
+                        struct openvas_plugin * plugin, void ** data)
 {
   if (plugin && strcmp(plugin->md5sum, md5sum) == 0)
     {
@@ -1677,7 +1620,10 @@
     }
   else
     {
-      missing_plugins_list_add((struct missing_plugins_list*)data, oid, md5sum);
+      struct missing_plugin * p = g_malloc0(sizeof (struct missing_plugin));
+      p->oid = g_strdup(oid);
+      p->md5sum = g_strdup(md5sum);
+      *data = g_slist_prepend((GSList *)(*data), p);
     }
 
   return 0;
@@ -1735,7 +1681,7 @@
  * @return 0 on success, -1 on errors.
  */
 static int
-fetch_new_plugins(struct context *context, struct missing_plugins_list* missing,
+fetch_new_plugins(struct context *context, GSList * missing,
     char * buf, int bufsz)
 {
   int i;
@@ -1745,17 +1691,17 @@
 #ifdef USE_OMP
   if (context->protocol == PROTOCOL_OMP)
     {
-      for (i = 0; i < missing->length; i++)
+      for (i = 0; i < g_slist_length(missing); i++)
         {
 #if 0
           entity_t response;
           // FIX
-          response = omp_get_nvt_details (missing->plugins[i].oid);
+          response = omp_get_nvt_details (g_slist_nth_data(missing, i)->oid);
           // FIX get nvt from response
           plugin = parse_omp_plugin (nvt);
           if (plugin != NULL)
             {
-              openvas_plugin_set_md5sum (plugin, missing->plugins[i].md5sum);
+              openvas_plugin_set_md5sum (plugin, g_slist_nth_data(missing, i)->md5sum);
               /* Count new plugins to inform user */
               if (context_add_plugin (context, plugin))
                 ++n_new_plugins;
@@ -1772,16 +1718,16 @@
     }
   else
 #endif /* USE_OMP */
-  for (i = 0; i < missing->length; i++)
+  for (i = 0; i < g_slist_length(missing); i++)
   {
     network_printf(context->socket,
-	"CLIENT <|> PLUGIN_INFO <|> %s <|> CLIENT\n", missing->plugins[i].oid);
+      "CLIENT <|> PLUGIN_INFO <|> %s <|> CLIENT\n", ((struct missing_plugin *)g_slist_nth_data(missing, i))->oid);
     network_gets(context->socket, buf, bufsz);
 
     plugin = parse_plugin(buf);
     if (plugin != NULL)
     {
-      openvas_plugin_set_md5sum(plugin, missing->plugins[i].md5sum);
+      openvas_plugin_set_md5sum(plugin, ((struct missing_plugin *)g_slist_nth_data(missing, i))->md5sum);
       /* Count new plugins to inform user */
       if(context_add_plugin(context, plugin))
         {
@@ -1836,23 +1782,31 @@
 static int
 update_individual_plugins(struct context *context, char * buf, int bufsz)
 {
-  struct missing_plugins_list missing;
+  GSList * missing;
   int result = 0;
 
-  missing_plugins_list_init(&missing);
-
   result = comm_get_plugins_md5(context, buf, bufsz, update_existing_plugin,
-      &missing);
+      (void **)&missing);
   if (result)
     goto fail;
 
   context->plugins = remove_outdated_plugins(context->plugins);
   context->scanners = remove_outdated_plugins(context->scanners);
 
-  result = fetch_new_plugins(context, &missing, buf, bufsz);
+  result = fetch_new_plugins(context, missing, buf, bufsz);
 
 fail:
-  missing_plugins_list_free(&missing);
+  if (missing) { /* free the whole list */
+    guint len = g_slist_length(missing);
+    int i;
+    for (i = 0;i < len;i ++) {
+      struct missing_plugin * p = g_slist_nth_data(missing, i);
+      g_free(p->oid);
+      g_free(p->md5sum);
+      g_free(p);
+    }
+    g_slist_free(missing);
+  }
   return result;
 }
 
@@ -1866,7 +1820,7 @@
 static int
 add_md5sum_to_plugin (struct context *context, const char * oid,
                       const char * md5sum, struct openvas_plugin * plugin,
-                      void * data)
+                      void ** dummy)
 {
   if (plugin != NULL)
     {



More information about the Openvas-commits mailing list