Skip to content

Commit

Permalink
Add: Add Note/Override excerpt size setting
Browse files Browse the repository at this point in the history
A new setting for the size limit of Note and Override text shown in
results has been added and set to a default of 300.

This allows using more descriptive text for notes and overrides than
with the old hardcoded limit of 60 characters.
  • Loading branch information
timopollmeier committed Aug 3, 2023
1 parent 66d6deb commit 81b9aaa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8026,7 +8026,8 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
if (include_notes_details == 0)
{
const char *text = note_iterator_text (notes);
gchar *excerpt = utf8_substring (text, 0, 60);
gchar *excerpt = utf8_substring (text, 0,
setting_excerpt_size_int ());
/* This must match send_get_common. */
buffer_xml_append_printf (buffer,
"<owner><name>%s</name></owner>"
Expand Down Expand Up @@ -8288,7 +8289,8 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
if (include_overrides_details == 0)
{
const char *text = override_iterator_text (overrides);
gchar *excerpt = utf8_substring (text, 0, 60);
gchar *excerpt = utf8_substring (text, 0,
setting_excerpt_size_int ());
/* This must match send_get_common. */
buffer_xml_append_printf (buffer,
"<owner><name>%s</name></owner>"
Expand Down
10 changes: 10 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,13 @@ result_detection_reference (result_t, report_t, const char *, const char *,
*/
#define MIN_QOD_DEFAULT 70

/**
* @brief Default size to limit note and override text to in reports.
*/
#define EXCERPT_SIZE_DEFAULT 300



void
reports_clear_count_cache_for_override (override_t, int);

Expand Down Expand Up @@ -3299,6 +3306,9 @@ setting_is_default_ca_cert (const gchar *);
char *
setting_filter (const char *);

int
setting_excerpt_size_int ();

void
init_setting_iterator (iterator_t *, const char *, const char *, int, int, int,
const char *);
Expand Down
40 changes: 40 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -15785,6 +15785,19 @@ check_db_settings ()
" 'Whether to rebuild report caches on changes affecting severity.',"
" '1');");

if (sql_int ("SELECT count(*) FROM settings"
" WHERE uuid = '9246a0f6-c6ad-44bc-86c2-557a527c8fb3'"
" AND " ACL_IS_GLOBAL () ";")
== 0)
sql ("INSERT into settings (uuid, owner, name, comment, value)"
" VALUES"
" ('9246a0f6-c6ad-44bc-86c2-557a527c8fb3', NULL,"
" 'Note/Override Excerpt Size',"
" 'The maximum length of notes and override text shown in' ||"
" ' reports without enabling note/override details.',"
" '%d');",
EXCERPT_SIZE_DEFAULT);

if (sql_int ("SELECT count(*) FROM settings"
" WHERE uuid = '" SETTING_UUID_LSC_DEB_MAINTAINER "'"
" AND " ACL_IS_GLOBAL () ";")
Expand Down Expand Up @@ -17148,6 +17161,13 @@ credentials_setup (credentials_t *credentials)
" ORDER BY coalesce (owner, 0) DESC LIMIT 1;",
credentials->uuid);

credentials->excerpt_size
= sql_int ("SELECT value FROM settings"
" WHERE name = 'Note/Override Excerpt Size'"
" AND " ACL_GLOBAL_OR_USER_OWNS ()
" ORDER BY coalesce (owner, 0) DESC LIMIT 1;",
credentials->uuid);

return 0;
}

Expand Down Expand Up @@ -50132,6 +50152,19 @@ setting_filter (const char *resource)
current_credentials.uuid);
}

/**
* @brief Return the Note/Override Excerpt Size user setting as an int.
*
* @return The excerpt size.
*/
int
setting_excerpt_size_int ()
{
if (current_credentials.excerpt_size <= 0)
return EXCERPT_SIZE_DEFAULT;
return current_credentials.excerpt_size;
}

/**
* @brief Return the Dynamic Severity user setting as an int.
*
Expand Down Expand Up @@ -50474,6 +50507,7 @@ modify_setting (const gchar *uuid, const gchar *name,
}

if (uuid && (strcmp (uuid, SETTING_UUID_ROWS_PER_PAGE) == 0
|| strcmp (uuid, SETTING_UUID_EXCERPT_SIZE) == 0
|| strcmp (uuid, "6765549a-934e-11e3-b358-406186ea4fc5") == 0
|| strcmp (uuid, "77ec2444-e7f2-4a80-a59b-f4237782d93f") == 0
|| strcmp (uuid, "7eda49c5-096c-4bef-b1ab-d080d87300df") == 0
Expand Down Expand Up @@ -50586,6 +50620,12 @@ modify_setting (const gchar *uuid, const gchar *name,
reports_clear_count_cache (current_credentials.uuid);
}

if (strcmp (uuid, SETTING_UUID_EXCERPT_SIZE) == 0)
{
/* Note/Override Excerpt Size */
current_credentials.excerpt_size = atoi (value);
}

if (strcmp (uuid, "7eda49c5-096c-4bef-b1ab-d080d87300df") == 0)
{
double severity_dbl;
Expand Down
5 changes: 5 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
*/
#define SETTING_UUID_MAX_ROWS_PER_PAGE "76374a7a-0569-11e6-b6da-28d24461215b"

/**
* @brief UUID of 'Note/Override Excerpt Size' setting.
*/
#define SETTING_UUID_EXCERPT_SIZE "9246a0f6-c6ad-44bc-86c2-557a527c8fb3"

/**
* @brief UUID of 'Default CA Cert' setting.
*/
Expand Down

0 comments on commit 81b9aaa

Please sign in to comment.