Skip to content

Commit

Permalink
Add: Added ports logic and output to delta reports version 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelmold authored and timopollmeier committed Mar 14, 2024
1 parent 1f623dc commit e109bf9
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -27980,7 +27980,7 @@ init_v2_delta_iterator (report_t report, iterator_t *results, report_t delta,
" r2.path) AS state,"
" r2.description AS delta_description,"
" r2.new_severity AS delta_new_severity,"
" r2.severity AS delta_severity,"
" r2.severity AS delta_severity,"
" r2.qod AS delta_qod,"
" r2.qod_type AS delta_qod_type,"
" r2.uuid AS delta_uuid,"
Expand Down Expand Up @@ -28812,6 +28812,7 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results,
array_t *result_hosts)
{
GString *buffer = g_string_new ("");
GTree *ports;

*orig_f_holes = *f_holes;
*orig_f_infos = *f_infos;
Expand All @@ -28820,6 +28821,9 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results,
*orig_f_false_positives = *f_false_positives;
*orig_filtered_result_count = *filtered_result_count;

ports = g_tree_new_full ((GCompareDataFunc) strcmp, NULL, g_free,
(GDestroyNotify) free_host_ports);

while (next (results)) {

const char *state = result_iterator_delta_state (results);
Expand Down Expand Up @@ -28878,15 +28882,53 @@ print_v2_report_delta_xml (FILE *out, iterator_t *results,
if (fprintf (out, "%s", buffer->str) < 0)
{
g_string_free (buffer, TRUE);
g_tree_destroy (ports);
return -1;
}
if (result_hosts_only)
array_add_new_string (result_hosts,
result_iterator_host (results));
add_port (ports, results);
g_string_truncate (buffer, 0);
}
g_string_free (buffer, TRUE);
if (fprintf (out, "</results>") < 0)
{
g_tree_destroy (ports);
return -1;
}

gchar *msg;
msg = g_markup_printf_escaped ("<ports"
" start=\"%i\""
" max=\"%i\">",
/* Add 1 for 1 indexing. */
first_result + 1,
max_results);
if (fprintf (out, "%s", msg) < 0)
{
g_tree_destroy (ports);
g_free (msg);
return -1;
}
g_free (msg);
if (sort_field == NULL || strcmp (sort_field, "port"))
{
if (sort_order)
g_tree_foreach (ports, print_host_ports_by_severity_asc, out);
else
g_tree_foreach (ports, print_host_ports_by_severity_desc, out);
}
else if (sort_order)
g_tree_foreach (ports, print_host_ports, out);
else
g_tree_foreach (ports, print_host_ports_desc, out);
g_tree_destroy (ports);
if (fprintf (out, "</ports>") < 0)
{
return -1;
}

return 0;
}

Expand Down

0 comments on commit e109bf9

Please sign in to comment.