[prev in list] [next in list] [prev in thread] [next in thread]
List: openvas-cvs
Subject: [Openvas-commits] r16506 - in trunk/openvas-manager: . src
From: scm-commit () wald ! intevation ! org
Date: 2013-05-30 9:37:01
Message-ID: 20130530093701.B91FA9A1907E () wald ! intevation ! org
[Download RAW message or body]
Author: kroosec
Date: 2013-05-30 11:37:01 +0200 (Thu, 30 May 2013)
New Revision: 16506
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage_sql.c
Log:
* src/manage_sql.c (print_report_port_xml): New function.
(print_report_xml): Refactor code for port summary into
print_rpeort_port_xml.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2013-05-30 09:05:25 UTC (rev 16505)
+++ trunk/openvas-manager/ChangeLog 2013-05-30 09:37:01 UTC (rev 16506)
@@ -1,3 +1,9 @@
+2013-05-30 Hani Benhabiles <hani.benhabiles@greenbone.net>
+
+ * src/manage_sql.c (print_report_port_xml): New function.
+ (print_report_xml): Refactor code for port summary into
+ print_rpeort_port_xml.
+
2013-05-29 Hani Benhabiles <hani.benhabiles@greenbone.net>
* src/manage_sql.c (prognostic_report_result_total): New function.
Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c 2013-05-30 09:05:25 UTC (rev 16505)
+++ trunk/openvas-manager/src/manage_sql.c 2013-05-30 09:37:01 UTC (rev 16506)
@@ -26664,6 +26664,174 @@
}
/**
+ * @brief Print the XML for a report port summary to a file.
+ *
+ * @param[in] report The report.
+ * @param[in] out File stream.
+ * @param[in] first_result The result to start from. The results are 0
+ * indexed.
+ * @param[in] max_results The maximum number of results returned.
+ * @param[in] sort_order Whether to sort ascending or descending.
+ * @param[in] sort_field Field to sort on, or NULL for "type".
+ * @param[in] levels String describing threat levels (message types)
+ * @param[in] autofp Whether to apply the auto FP filter.
+ * @param[in] search_phrase Phrase that results must include. All
+ * results if NULL or "".
+ * @param[in] search_phrase_exact Whether search phrase is exact.
+ * @param[in] min_cvss_base Minimum CVSS base of included results. All
+ * results if NULL.
+ * @param[in] apply_overrides Whether to apply overrides.
+ *
+ * @return 0 on success, -1 error.
+ */
+static int
+print_report_port_xml (report_t report, FILE *out, int first_result,
+ int max_results, int sort_order, const char *sort_field,
+ const char *levels, int autofp,
+ const char *search_phrase, int search_phrase_exact,
+ const char *min_cvss_base, int apply_overrides)
+{
+ iterator_t results;
+ gchar *last_port, *last_host;
+ GArray *ports = g_array_new (TRUE, FALSE, sizeof (gchar*));
+
+ init_result_iterator
+ (&results, report, 0,
+ first_result,
+ max_results,
+ /* Sort by the requested field in the requested order, in case there is
+ * a first_result and/or max_results (these are applied after the
+ * sorting). */
+ sort_order,
+ sort_field,
+ levels,
+ autofp,
+ search_phrase,
+ search_phrase_exact,
+ min_cvss_base,
+ apply_overrides);
+
+ /* Buffer the results, removing duplicates. */
+
+ last_port = NULL;
+ last_host = NULL;
+ while (next (&results))
+ {
+ const char *port = result_iterator_port (&results);
+ const char *host = result_iterator_host (&results);
+
+ if (last_port == NULL || strcmp (port, last_port)
+ || strcmp (host, last_host))
+ {
+ const char *type;
+ gchar *item;
+ int port_len, type_len;
+
+ g_free (last_port);
+ last_port = g_strdup (port);
+ g_free (last_host);
+ last_host = g_strdup (host);
+
+ type = result_iterator_type (&results);
+ port_len = strlen (port);
+ type_len = strlen (type);
+ item = g_malloc (port_len
+ + type_len
+ + strlen (host)
+ + 3);
+ g_array_append_val (ports, item);
+ strcpy (item, port);
+ strcpy (item + port_len + 1, type);
+ strcpy (item + port_len + type_len + 2, host);
+ }
+
+ }
+ g_free (last_port);
+ g_free (last_host);
+
+ /* Handle sorting by threat and ROWID. */
+
+ if (sort_field == NULL || strcmp (sort_field, "port"))
+ {
+ int index, length;
+
+ /** @todo Sort by ROWID if was requested. */
+
+ /* Sort by port then threat. */
+
+ g_array_sort (ports, compare_port_threat);
+
+ /* Remove duplicates. */
+
+ last_port = NULL;
+ last_host = NULL;
+ for (index = 0, length = ports->len; index < length; index++)
+ {
+ char *port = g_array_index (ports, char*, index);
+ char *host = port + strlen (port) + 1;
+ host += strlen (host) + 1;
+ if (last_port
+ && (strcmp (port, last_port) == 0)
+ && (strcmp (host, last_host) == 0))
+ {
+ g_array_remove_index (ports, index);
+ length = ports->len;
+ index--;
+ }
+ else
+ {
+ last_port = port;
+ last_host = host;
+ }
+ }
+
+ /* Sort by threat. */
+
+ if (sort_order)
+ g_array_sort (ports, compare_message_types_asc);
+ else
+ g_array_sort (ports, compare_message_types_desc);
+ }
+
+ /* Write to file from the buffer. */
+
+ PRINT (out,
+ "<ports"
+ " start=\"%i\""
+ " max=\"%i\">"
+ "<count>%i</count>",
+ /* Add 1 for 1 indexing. */
+ first_result + 1,
+ max_results,
+ report_port_count (report));
+ {
+ gchar *item;
+ int index = 0;
+
+ while ((item = g_array_index (ports, gchar*, index++)))
+ {
+ int port_len = strlen (item);
+ int type_len = strlen (item + port_len + 1);
+ PRINT (out,
+ "<port>"
+ "<host>%s</host>"
+ "%s"
+ "<threat>%s</threat>"
+ "</port>",
+ item + port_len + type_len + 2,
+ item,
+ manage_result_type_threat (item + port_len + 1));
+ g_free (item);
+ }
+ g_array_free (ports, TRUE);
+ }
+ PRINT (out, "</ports>");
+ cleanup_iterator (&results);
+
+ return 0;
+}
+
+/**
* @brief Print the XML for a report to a file.
*
* @param[in] report The report.
@@ -27478,141 +27646,11 @@
if (delta == 0)
{
- gchar *last_port, *last_host;
- GArray *ports = g_array_new (TRUE, FALSE, sizeof (gchar*));
-
- init_result_iterator
- (&results, report, 0,
- first_result,
- max_results,
- /* Sort by the requested field in the requested order, in case there is
- * a first_result and/or max_results (these are applied after the
- * sorting). */
- sort_order,
- sort_field,
- levels,
- autofp,
- search_phrase,
- search_phrase_exact,
- min_cvss_base,
- apply_overrides);
-
- /* Buffer the results, removing duplicates. */
-
- last_port = NULL;
- last_host = NULL;
- while (next (&results))
- {
- const char *port = result_iterator_port (&results);
- const char *host = result_iterator_host (&results);
-
- if (last_port == NULL || strcmp (port, last_port)
- || strcmp (host, last_host))
- {
- const char *type;
- gchar *item;
- int port_len, type_len;
-
- g_free (last_port);
- last_port = g_strdup (port);
- g_free (last_host);
- last_host = g_strdup (host);
-
- type = result_iterator_type (&results);
- port_len = strlen (port);
- type_len = strlen (type);
- item = g_malloc (port_len
- + type_len
- + strlen (host)
- + 3);
- g_array_append_val (ports, item);
- strcpy (item, port);
- strcpy (item + port_len + 1, type);
- strcpy (item + port_len + type_len + 2, host);
- }
-
- }
- g_free (last_port);
- g_free (last_host);
-
- /* Handle sorting by threat and ROWID. */
-
- if (sort_field == NULL || strcmp (sort_field, "port"))
- {
- int index, length;
-
- /** @todo Sort by ROWID if was requested. */
-
- /* Sort by port then threat. */
-
- g_array_sort (ports, compare_port_threat);
-
- /* Remove duplicates. */
-
- last_port = NULL;
- last_host = NULL;
- for (index = 0, length = ports->len; index < length; index++)
- {
- char *port = g_array_index (ports, char*, index);
- char *host = port + strlen (port) + 1;
- host += strlen (host) + 1;
- if (last_port
- && (strcmp (port, last_port) == 0)
- && (strcmp (host, last_host) == 0))
- {
- g_array_remove_index (ports, index);
- length = ports->len;
- index--;
- }
- else
- {
- last_port = port;
- last_host = host;
- }
- }
-
- /* Sort by threat. */
-
- if (sort_order)
- g_array_sort (ports, compare_message_types_asc);
- else
- g_array_sort (ports, compare_message_types_desc);
- }
-
- /* Write to file from the buffer. */
-
- PRINT (out,
- "<ports"
- " start=\"%i\""
- " max=\"%i\">"
- "<count>%i</count>",
- /* Add 1 for 1 indexing. */
- first_result + 1,
- max_results,
- report_port_count (report));
- {
- gchar *item;
- int index = 0;
-
- while ((item = g_array_index (ports, gchar*, index++)))
- {
- int port_len = strlen (item);
- int type_len = strlen (item + port_len + 1);
- PRINT (out,
- "<port>"
- "<host>%s</host>"
- "%s"
- "<threat>%s</threat>"
- "</port>",
- item + port_len + type_len + 2,
- item,
- manage_result_type_threat (item + port_len + 1));
- g_free (item);
- }
- g_array_free (ports, TRUE);
- }
- PRINT (out, "</ports>");
- cleanup_iterator (&results);
+ if(print_report_port_xml (report, out, first_result, max_results,
+ sort_order, sort_field, levels, autofp,
+ search_phrase, search_phrase_exact,
+ min_cvss_base, apply_overrides))
+ return -1;
}
/* Prepare result counts. */
_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic