[Openvas-commits] r2857 - in trunk/openvas-client: . nessus
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Mar 20 09:12:57 CET 2009
Author: felix
Date: 2009-03-20 09:12:53 +0100 (Fri, 20 Mar 2009)
New Revision: 2857
Modified:
trunk/openvas-client/ChangeLog
trunk/openvas-client/nessus/data_mining.c
Log:
* nessus/data_mining.c : Cosmetics, doc, white-space removal, K&R style
replacements.
Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog 2009-03-20 08:00:48 UTC (rev 2856)
+++ trunk/openvas-client/ChangeLog 2009-03-20 08:12:53 UTC (rev 2857)
@@ -1,5 +1,10 @@
2009-03-20 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+ * nessus/data_mining.c : Cosmetics. Doc, white-space removal, K&R style
+ replacements.
+
+2009-03-20 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
* nessus/nessus.c (main): Fixed bug that caused global filter never to
be created if the xml file did not exist.
Modified: trunk/openvas-client/nessus/data_mining.c
===================================================================
--- trunk/openvas-client/nessus/data_mining.c 2009-03-20 08:00:48 UTC (rev 2856)
+++ trunk/openvas-client/nessus/data_mining.c 2009-03-20 08:12:53 UTC (rev 2857)
@@ -30,7 +30,9 @@
*/
/** @file
- * Functions to explore a report.
+ * Functions to explore a report. Module name is misleading (has nothing to do
+ * with data mining).
+ *
* Note that this code can easily be
* changed to be linked to any database instead of the simple
* flat files that are currently used.
@@ -148,13 +150,13 @@
field_add (struct hfield * h, struct field * f)
{
unsigned int idx = mkfhash(f->value);
-
+
f->next = h->hfield[idx];
h->hfield[idx] = f;
}
-int
+int
be_index_keywords (be)
{
int i;
@@ -213,11 +215,9 @@
{
struct field * f;
int flag = 0;
-
-
-
- if(!field[j])
- continue;
+
+ if(!field[j])
+ continue;
f = field_get(backends[be].fields[j], field[j]);
if ( f != NULL )
@@ -536,7 +536,7 @@
Subset sorting
--------------------------------------------------------------------------*/
-static struct subset *
+static struct subset *
merge_sort (struct subset * list, int n, int m, cmp_func_t* cmp)
{
struct subset * p, * q, * e, *tail;
@@ -807,27 +807,25 @@
struct condition {
- struct condition * next;
- int type;
- int operator;
- char value[1];
-};
+ struct condition * next;
+ int type;
+ int operator;
+ char value[1];
+};
struct query {
- char * table;
- int type[MAX_QUERIES];
- int num;
- int uniq;
- struct condition * conditions;
+ char * table;
+ int type[MAX_QUERIES];
+ int num;
+ int uniq;
+ struct condition * conditions;
};
#ifdef HAVE_MMAP
static u_short *
-requests2lines(be, requests)
- int be;
- char * requests[BE_NUM_FIELDS];
+requests2lines (int be, char * requests[BE_NUM_FIELDS])
{
u_short * ret = emalloc(backends[be].num_lines*sizeof(u_short));
int i;
@@ -853,12 +851,11 @@
}
return ret;
}
-#endif
-
+#endif /* HAVE_MMAP */
+
static int
-str2querytype(str)
- char * str;
+str2querytype (char * str)
{
int type;
@@ -882,12 +879,10 @@
type = -1;
return type;
-}
+}
static int
-str2querytypes(str, query)
- char * str;
- struct query * query;
+str2querytypes (char * str, struct query * query)
{
char * t;
query->num = 0;
@@ -908,8 +903,7 @@
}
static int
-str2querycondition(str)
- char * str;
+str2querycondition (char * str)
{
if(!strcmp(str, QUERY_OP_AND_ASC))
return QUERY_OP_AND;
@@ -921,8 +915,7 @@
* @brief Parses the condition(s) of a query (the whole part after 'where').
*/
static struct condition *
-compile_conditions(str)
- char * str;
+compile_conditions (char * str)
{
struct condition * ret = NULL;
int operator = QUERY_OP_AND;
@@ -1008,9 +1001,8 @@
return ret;
}
-static struct query *
-compile_query(str)
- char * str;
+static struct query *
+compile_query (char * str)
{
struct query * ret;
char * a, * b;
@@ -1097,8 +1089,7 @@
}
static void
-free_query(query)
- struct query * query;
+free_query (struct query * query)
{
struct condition * conditions = query->conditions;
while(conditions)
@@ -1126,31 +1117,30 @@
{
char * t;
*port = *plugin_id = *severity = *data = NULL;
-
+
*table = entry;
t = strchr(entry, '|');
if(t)
t[0] = '\0';
else
return 0;
-
- entry = &(t[1]);
+
+ entry = &(t[1]);
*subnet = entry;
t = strchr(entry, '|');
if(t)
t[0] = '\0';
else
return 0;
-
-
- entry = &(t[1]);
+
+ entry = &(t[1]);
*hostname = entry;
t = strchr(entry, '|');
if(t)
t[0] = '\0';
else
return 0;
-
+
entry = &(t[1]);
*port = entry;
t = strchr(entry, '|');
@@ -1158,7 +1148,7 @@
t[0] = '\0';
else
return 0;
-
+
entry = &(t[1]);
*plugin_id = entry;
t = strchr(entry, '|');
@@ -1166,24 +1156,24 @@
t[0] = '\0';
else
return 0;
-
+
entry = &(t[1]);
*severity = entry;
if(t)
t[0] = '\0';
else
return 0;
-
+
t = strchr(entry, '|');
if(t)
t[0] = '\0';
else
return 0;
-
+
if (Context->is_severity_mapped)
{
- char * prio = severity_filter_apply (*hostname, *port, *plugin_id, *severity);
- if (prio) *severity = prio;
+ const char * prio = severity_filter_apply (*hostname, *port, *plugin_id, *severity);
+ if (prio) *severity = g_strdup (prio);
}
entry = &(t[1]);
@@ -1200,28 +1190,22 @@
}
}
#endif
-
+
return 0;
}
-
-
-/*
- * Executes a compiled query and returns the result as a subset.
+/**
+ * @brief Executes a compiled query and returns the result as a subset.
*
* This is god damn ugly and you probably want to use a real
* sql backend if you want performances
*
*/
-
-
-static struct subset *
-execute_query_flatfile(be, query)
- int be;
- struct query * query;
+static struct subset *
+execute_query_flatfile (int be, struct query * query)
{
struct subset * ret = NULL;
static char *buf = NULL;
@@ -1241,7 +1225,7 @@
perror("lseek ");
}
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP
if(backends[be].fields)
{
char * requests[BE_NUM_FIELDS];
@@ -1297,7 +1281,6 @@
default:
fprintf(stderr, "data_mining.c: invalid switch value\n");
break;
-
}
if(val)
{
@@ -1350,7 +1333,7 @@
case QUERY_TYPE_SEVERITY :
candidate = severity;
break;
-
+
case QUERY_TYPE_REPORT :
candidate = data;
break;
@@ -1360,17 +1343,17 @@
!strcmp(candidate, conditions->value))
{
selected = 1;
- }
+ }
else if(conditions->operator == QUERY_OP_AND)
{
selected = 0;
break;
}
-
- conditions = conditions->next;
+
+ conditions = conditions->next;
}
-
+
if(selected)
{
int i;
@@ -1394,7 +1377,7 @@
break;
case QUERY_TYPE_SEVERITY :
val = severity;
- break;
+ break;
case QUERY_TYPE_REPORT :
val = data;
break;
@@ -1420,7 +1403,7 @@
ret = subset_add(ret, val);
}
else ret = subset_add_again(ret, val);
- }
+ }
else
{
if(!i) ret = subset_add(ret, val);
@@ -1437,8 +1420,16 @@
}
+/**
+ * @brief Builds a query struct str (printf-like) and executes it against a flat
+ * @brief file.
+ *
+ * @param str Query in printf- format.
+ *
+ * @return Result (subset) of the query (not sure if it can be NULL) or NULL if failed.
+ */
struct subset *
-query_backend(int be,char* str, ...)
+query_backend (int be, char* str, ...)
{
struct query * query;
struct subset * ret;
@@ -1461,11 +1452,10 @@
va_end(param);
efree(&ptr);
-
+
if(!query)
return NULL;
-
-
+
ret = execute_query_flatfile(be, query);
free_query(query);
return ret;
More information about the Openvas-commits
mailing list