[Openvas-commits] r1350 - in trunk/openvas-server: . openvasd

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 16 11:59:29 CEST 2008


Author: mwiegand
Date: 2008-09-16 11:59:29 +0200 (Tue, 16 Sep 2008)
New Revision: 1350

Modified:
   trunk/openvas-server/ChangeLog
   trunk/openvas-server/openvasd/comm.c
Log:
Optimized plugin selection with OIDs. Selection is now considerably
faster.

* openvasd/comm.c: (qsort_cmp) Comparator now compares OIDs instead of
IDs. (_get_plug_by_id) Removed. (_get_plug_by_oid) Adapted from
_get_plug_by_id to use OIDs. (get_plug_by_id) Removed. (get_plug_by_oid)
Adapted from get_plug_by_id to use OIDs. (comm_setup_plugins) Re-enabled
plugin sorting.


Modified: trunk/openvas-server/ChangeLog
===================================================================
--- trunk/openvas-server/ChangeLog	2008-09-15 21:36:38 UTC (rev 1349)
+++ trunk/openvas-server/ChangeLog	2008-09-16 09:59:29 UTC (rev 1350)
@@ -1,3 +1,14 @@
+2008-09-16  Michael Wiegand <michael.wiegand at intevation.de>
+
+	Optimized plugin selection with OIDs. Selection is now considerably
+	faster.
+
+	* openvasd/comm.c: (qsort_cmp) Comparator now compares OIDs instead of
+	IDs. (_get_plug_by_id) Removed. (_get_plug_by_oid) Adapted from
+	_get_plug_by_id to use OIDs. (get_plug_by_id) Removed. (get_plug_by_oid)
+	Adapted from get_plug_by_id to use OIDs. (comm_setup_plugins) Re-enabled
+	plugin sorting.
+
 2008-09-15  Michael Wiegand <michael.wiegand at intevation.de>
 
 	Fixes to re-enable plugin loading after the OID changes. Please note

Modified: trunk/openvas-server/openvasd/comm.c
===================================================================
--- trunk/openvas-server/openvasd/comm.c	2008-09-15 21:36:38 UTC (rev 1349)
+++ trunk/openvas-server/openvasd/comm.c	2008-09-16 09:59:29 UTC (rev 1350)
@@ -459,56 +459,42 @@
  struct arglist ** plugin_a = (struct arglist**) a;
  struct arglist ** plugin_b = (struct arglist**) b;
 
- int id_a = plug_get_id((*plugin_a)->value);
- int id_b = plug_get_id((*plugin_b)->value);
-
- return id_a - id_b;
+ return(strcmp(plug_get_oid((*plugin_a)->value), plug_get_oid((*plugin_b)->value)));
 }
 
-static struct arglist * _get_plug_by_id(struct arglist ** array, int id, int start, int end, int rend )
+static struct arglist * _get_plug_by_oid(struct arglist ** array, char * oid, int start, int end, int rend )
 {
   int mid;
-  int plugin_id;
+  char * plugin_oid;
 
   if ( start >= rend ) 
-	return NULL;
+    return NULL;
 
   if ( start == end )
   {
-  plugin_id = plug_get_id(array[start]->value);
-   if ( plugin_id == id ) 
-        return array[start];
-   else 
-        return NULL;
+    plugin_oid = plug_get_oid(array[start]->value);
+    if (strcmp(plugin_oid, oid) == 0 )
+      return array[start];
+    else 
+      return NULL;
   }
 
   mid = ( start + end ) / 2;
-  plugin_id = plug_get_id(array[mid]->value);
-  if ( plugin_id > id ) 
-	return _get_plug_by_id(array, id, start, mid, rend );
-  else if ( plugin_id < id )
-	return _get_plug_by_id(array, id, mid + 1, end, rend );
+  plugin_oid = plug_get_oid(array[mid]->value);
+  if ( strcmp(plugin_oid, oid) > 0 ) 
+    return _get_plug_by_oid(array, oid, start, mid, rend );
+  else if ( strcmp(plugin_oid, oid) < 0 )
+    return _get_plug_by_oid(array, oid, mid + 1, end, rend );
 
   return array[mid];
 }
 
 
-static struct arglist * get_plug_by_id(struct arglist ** array, int id, int num_plugins )
+static struct arglist * get_plug_by_oid(struct arglist ** array, char * oid, int num_plugins )
 {
- return _get_plug_by_id(array, id, 0, num_plugins, num_plugins); 
+  return _get_plug_by_oid(array, oid, 0, num_plugins, num_plugins);
 }
 
-static struct arglist * get_plug_by_oid(struct arglist * plugins, char * oid)
-{
-  while(plugins != NULL)
-  {
-    if (!strcmp(plug_get_oid(plugins->value), oid)) return plugins;
-    plugins = plugins->next;
-  }
-
-  return NULL;
-}
-
 /*-------------------------------------------------------------------------------*/
 
 
@@ -517,7 +503,6 @@
  */
 void comm_setup_plugins( struct arglist * globals, char * list )
 {
-  int id;
   int num_plugins=0;
   struct arglist * plugins = arg_get_value(globals, "plugins");
   struct arglist * p = plugins;
@@ -544,34 +529,32 @@
   
   /* Store the plugins in an array for quick access */
   p = plugins;
-/*  i = 0;
+  i = 0;
   array = emalloc ( num_plugins * sizeof(struct arglist ** ));
   while ( p->next != NULL ) 
   {
    array[i++] = p;
    p = p->next;
   }
+
+  qsort( array, num_plugins, sizeof(struct arglist * ), qsort_cmp);
  
-  qsort( array, num_plugins, sizeof(struct arglist * ), qsort_cmp);*/
- 
   t = list;
   oid = strtok(t, ";");
 
   /* Read the list provided by the user and enable the plugins accordingly */
   while (oid != NULL)
   {
-    p = get_plug_by_oid(plugins, oid);
+    p = get_plug_by_oid(array, oid, num_plugins);
     if(p != NULL)
-    {
       plug_set_launch(p->value, LAUNCH_RUN);
-    }
 #ifdef DEBUG
     else log_write("PLUGIN ID %s NOT FOUND!!!\n", oid);
 #endif
     oid = strtok(NULL, ";");
   }
 
-//   efree(&array);
+  efree(&array);
 }
 
 void



More information about the Openvas-commits mailing list