[Openvas-commits] r6250 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Dec 24 19:25:41 CET 2009
Author: mattm
Date: 2009-12-24 19:25:38 +0100 (Thu, 24 Dec 2009)
New Revision: 6250
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tasks_sql.h
Log:
Switch the global OMP array variables to GPtrArrays.
* src/tasks_sql.h (member): Switch array to GPtrArray.
(manage_set_config_nvts): Switch selected_nvts to GPtrArray.
(manage_set_config_families): Switch families args to GPtrArray.
* src/manage.h: Update headers accordingly.
* src/omp.c (make_array, array_add, array_terminate): New functions.
(free_array): Switch arg to GPtrArray.
(current_array_1, current_array_2, current_array_3): Switch type to
GPtrArray.
(omp_xml_handle_start_element): Create arrays with make_array.
(omp_xml_handle_end_element): Terminate arrays before use. Free
arrays with free_array. Append to arrays with array_add.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-12-24 18:04:14 UTC (rev 6249)
+++ trunk/openvas-manager/ChangeLog 2009-12-24 18:25:38 UTC (rev 6250)
@@ -1,5 +1,23 @@
2009-12-24 Matthew Mundell <matthew.mundell at intevation.de>
+ Switch the global OMP array variables to GPtrArrays.
+
+ * src/tasks_sql.h (member): Switch array to GPtrArray.
+ (manage_set_config_nvts): Switch selected_nvts to GPtrArray.
+ (manage_set_config_families): Switch families args to GPtrArray.
+
+ * src/manage.h: Update headers accordingly.
+
+ * src/omp.c (make_array, array_add, array_terminate): New functions.
+ (free_array): Switch arg to GPtrArray.
+ (current_array_1, current_array_2, current_array_3): Switch type to
+ GPtrArray.
+ (omp_xml_handle_start_element): Create arrays with make_array.
+ (omp_xml_handle_end_element): Terminate arrays before use. Free
+ arrays with free_array. Append to arrays with array_add.
+
+2009-12-24 Matthew Mundell <matthew.mundell at intevation.de>
+
* src/omp.c (help_text): Sort. Correct article.
* src/tasks_sql.h (set_task_run_status): Neaten doc.
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2009-12-24 18:04:14 UTC (rev 6249)
+++ trunk/openvas-manager/src/manage.h 2009-12-24 18:25:38 UTC (rev 6250)
@@ -633,10 +633,11 @@
const char*);
int
-manage_set_config_nvts (const char*, const char*, GArray*);
+manage_set_config_nvts (const char*, const char*, GPtrArray*);
int
-manage_set_config_families (const char*, GArray*, GArray*, GArray*, int);
+manage_set_config_families (const char*, GPtrArray*, GPtrArray*, GPtrArray*,
+ int);
/* NVT's. */
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-12-24 18:04:14 UTC (rev 6249)
+++ trunk/openvas-manager/src/omp.c 2009-12-24 18:25:38 UTC (rev 6250)
@@ -128,14 +128,51 @@
strlen (two), two);
}
+/**
+ * @brief Make a global array.
+ *
+ * @return New array.
+ */
+static GPtrArray *
+make_array ()
+{
+ return g_ptr_array_new ();
+}
+
+/**
+ * @brief Push a string onto a global array.
+ *
+ * @param[in] array Array.
+ * @param[in] string String.
+ */
static void
-free_array (GArray *array)
+array_add (GPtrArray *array, gchar* string)
{
+ if (array) g_ptr_array_add (array, string);
+}
+
+/**
+ * @brief Terminate a global array.
+ */
+static void
+array_terminate (GPtrArray *array)
+{
+ if (array) g_ptr_array_add (array, NULL);
+}
+
+/**
+ * @brief Free global array value.
+ *
+ * @param[in] array Pointer to array.
+ */
+static void
+free_array (GPtrArray *array)
+{
int index = 0;
- void* item;
- while ((item = g_array_index (array, void*, index++)))
+ gpointer item;
+ while ((item = g_ptr_array_index (array, index++)))
g_free (item);
- g_array_free (array, TRUE);
+ g_ptr_array_free (array, TRUE);
}
/** @todo Duplicated from lsc_user.c. */
@@ -374,17 +411,17 @@
/**
* @brief Generic array variable for communicating between the callbacks.
*/
-GArray *current_array_1;
+GPtrArray *current_array_1;
/**
* @brief Generic array variable for communicating between the callbacks.
*/
-GArray *current_array_2;
+GPtrArray *current_array_2;
/**
* @brief Generic array variable for communicating between the callbacks.
*/
-GArray *current_array_3;
+GPtrArray *current_array_3;
/**
* @brief Generic integer variable for communicating between the callbacks.
@@ -1707,16 +1744,17 @@
{
assert (current_array_1 == NULL);
assert (current_array_2 == NULL);
- current_array_1 = g_array_new (TRUE, FALSE, sizeof (gchar*));
- current_array_2 = g_array_new (TRUE, FALSE, sizeof (gchar*));
- current_array_3 = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ assert (current_array_3 == NULL);
+ current_array_1 = make_array ();
+ current_array_2 = make_array ();
+ current_array_3 = make_array ();
current_int_3 = 0; /* For GROWING entity, in case missing. */
set_client_state (CLIENT_MODIFY_CONFIG_FAMILY_SELECTION);
}
else if (strcasecmp ("NVT_SELECTION", element_name) == 0)
{
assert (current_array_1 == NULL);
- current_array_1 = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ current_array_1 = make_array ();
set_client_state (CLIENT_MODIFY_CONFIG_NVT_SELECTION);
}
else if (strcasecmp ("PREFERENCE", element_name) == 0)
@@ -4788,11 +4826,9 @@
" an NVT_SELECTION or a FAMILY_SELECTION"));
else if (current_format)
{
- gchar *item;
- int index = 0;
-
assert (current_array_1);
+ array_terminate (current_array_1);
switch (manage_set_config_nvts (current_name,
current_format,
current_array_1))
@@ -4814,10 +4850,7 @@
break;
}
- while ((item = g_array_index (current_array_1, gchar*, index++)))
- g_free (item);
-
- g_array_free (current_array_1, TRUE);
+ free_array (current_array_1);
current_array_1 = NULL;
}
else if (current_array_2) /* Implies FAMILY_SELECTION. */
@@ -4825,6 +4858,9 @@
assert (current_array_1);
assert (current_array_3);
+ array_terminate (current_array_1);
+ array_terminate (current_array_2);
+ array_terminate (current_array_3);
switch (manage_set_config_families (current_name,
current_array_1,
current_array_2,
@@ -4911,16 +4947,16 @@
{
if (current_int_2)
/* Growing 1 and select all 1. */
- g_array_append_val (current_array_1, current_uuid);
+ array_add (current_array_1, current_uuid);
else
/* Growing 1 and select all 0. */
- g_array_append_val (current_array_3, current_uuid);
+ array_add (current_array_3, current_uuid);
}
else
{
if (current_int_2)
/* Growing 0 and select all 1. */
- g_array_append_val (current_array_2, current_uuid);
+ array_add (current_array_2, current_uuid);
/* Else growing 0 and select all 0. */
}
}
@@ -4973,7 +5009,7 @@
case CLIENT_MODIFY_CONFIG_NVT_SELECTION_NVT:
assert (strcasecmp ("NVT", element_name) == 0);
if (current_uuid)
- g_array_append_val (current_array_1, current_uuid);
+ array_add (current_array_1, current_uuid);
current_uuid = NULL;
set_client_state (CLIENT_MODIFY_CONFIG_NVT_SELECTION);
break;
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-12-24 18:04:14 UTC (rev 6249)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-12-24 18:25:38 UTC (rev 6250)
@@ -427,7 +427,6 @@
/* General helpers. */
-/** @todo Duplicated in gsa. */
/**
* @brief Test whether a string equal to a given string exists in an array.
*
@@ -437,11 +436,11 @@
* @return 1 if a string equal to \arg string exists in \arg array, else 0.
*/
static int
-member (GArray *array, const char *string)
+member (GPtrArray *array, const char *string)
{
const gchar *item;
int index = 0;
- while ((item = g_array_index (array, gchar*, index++)))
+ while ((item = (gchar*) g_ptr_array_index (array, index++)))
if (strcmp (item, string) == 0) return 1;
return 0;
}
@@ -6048,7 +6047,7 @@
*/
int
manage_set_config_nvts (const char* config, const char* family,
- GArray* selected_nvts)
+ GPtrArray* selected_nvts)
{
char *selector;
gchar *quoted_config, *quoted_family;
@@ -6131,7 +6130,8 @@
gchar *nvt;
new_nvt_count = 0;
- while ((nvt = g_array_index (selected_nvts, gchar*, new_nvt_count)))
+ while ((nvt = (gchar*) g_ptr_array_index (selected_nvts,
+ new_nvt_count)))
{
gchar *quoted_nvt = sql_quote (nvt);
sql ("INSERT INTO nvt_selectors"
@@ -7566,9 +7566,9 @@
*/
int
manage_set_config_families (const char* config,
- GArray* growing_all_families,
- GArray* static_all_families,
- GArray* growing_families,
+ GPtrArray* growing_all_families,
+ GPtrArray* static_all_families,
+ GPtrArray* growing_families,
int grow_families)
{
iterator_t families;
More information about the Openvas-commits
mailing list