Skip to content

Commit

Permalink
Address review comments for report configs
Browse files Browse the repository at this point in the history
This fixes several smaller issues found by @a-h-abdelsalam's review:
- several "report format" vs. "report config" mix-ups / copy-paste errors
- the "active" column in report format iterator
- copying report format parameters
- Some GMP attributes and elements
  • Loading branch information
timopollmeier authored and a-h-abdelsalam committed Feb 20, 2024
1 parent e4bdd58 commit d5f4ac4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/manage_report_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/

/**
* @file manage_report_formats.c
* @brief GVM management layer: Report formats.
* @file manage_report_configs.h
* @brief GVM management layer: Report configs.
*
* Non-SQL report format code for the GVM management layer.
* Non-SQL report config code for the GVM management layer.
*/

#ifndef _GVMD_MANAGE_REPORT_CONFIGS_H
Expand Down
32 changes: 17 additions & 15 deletions src/manage_sql_report_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* @file manage_sql_report_formats.c
* @file manage_sql_report_configs.c
* @brief GVM management layer: Report configs SQL.
*
* SQL report config code for the GVM management layer.
Expand Down Expand Up @@ -45,14 +45,14 @@
* @param[in] name Name of new Report Config. NULL to copy
* from existing.
* @param[in] source_uuid UUID of existing Report Config.
* @param[out] new_report_format New Report Config.
* @param[out] new_report_config New Report Config.
*
* @return 0 success, 1 Report Config exists already, 2 failed to find existing
* Report Config, 99 permission denied, -1 error.
*/
int
copy_report_config (const char* name, const char* source_uuid,
report_config_t* new_report_format)
report_config_t* new_report_config)
{
report_format_t new, old;
int ret;
Expand All @@ -70,18 +70,18 @@ copy_report_config (const char* name, const char* source_uuid,
return ret;
}

/* Copy report format parameters. */
/* Copy report config parameters. */

sql ("INSERT INTO report_config_params "
" (report_config, name, value)"
" SELECT %llu, name, value"
" FROM report_format_params WHERE report_format = %llu;",
" FROM report_config_params WHERE report_config = %llu;",
new,
old);

sql_commit ();

if (new_report_format) *new_report_format = new;
if (new_report_config) *new_report_config = new;
return 0;
}

Expand Down Expand Up @@ -268,10 +268,9 @@ create_report_config (const char *name, const char *comment,
* @brief Modify a report config.
*
* @param[in] report_config_id UUID of report config to modify.
* @param[in] name Name of report config.
* @param[in] comment Comment of report config.
* @param[in] new_name Name of report config.
* @param[in] new_comment Comment of report config.
* @param[in] params Array of params.
* @param[out] report_config Created report config.
* @param[out] error_message Message for some errors like invalid params.
*
* @return 0 success,
Expand Down Expand Up @@ -301,7 +300,7 @@ modify_report_config (const char *report_config_id,

report_config = 0;
if (find_report_config_with_permission (report_config_id, &report_config,
"modify_report_format"))
"modify_report_config"))
{
sql_rollback ();
return -1;
Expand Down Expand Up @@ -347,7 +346,7 @@ modify_report_config (const char *report_config_id,
" FROM report_configs"
" WHERE id = %llu)",
report_config);
if (report_config == 0)
if (report_format == 0)
{
sql_rollback ();
return 3;
Expand Down Expand Up @@ -567,7 +566,8 @@ delete_report_configs_user (user_t user)
* @param[in] report_config_id UUID of resource.
*
* @return 0 success, 1 fail because resource is in use, 2 failed to find
* resource, 4 fail because resource with UUID exists, -1 error.
* resource, 3 fail because resource with same name exists,
* 4 fail because resource with same UUID exists, -1 error.
*/
int
restore_report_config (const char *report_config_id)
Expand Down Expand Up @@ -643,7 +643,7 @@ restore_report_config (const char *report_config_id)
}


/* GET_REPORT_FORMATS */
/* GET_REPORT_CONFIGS */

/**
* @brief Filter columns for Report Config iterator.
Expand Down Expand Up @@ -681,7 +681,7 @@ restore_report_config (const char *report_config_id)
{ \
"(SELECT id FROM report_formats" \
" WHERE report_formats.uuid = report_format_id)", \
"report_format", \
"report_format_rowid", \
KEYWORD_TYPE_INTEGER, \
}, \
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
Expand Down Expand Up @@ -716,7 +716,7 @@ restore_report_config (const char *report_config_id)
{ \
"(SELECT id FROM report_formats" \
" WHERE report_formats.uuid = report_format_id)", \
"report_format", \
"report_format_rowid", \
KEYWORD_TYPE_INTEGER, \
}, \
}
Expand Down Expand Up @@ -1072,6 +1072,7 @@ report_config_report_format (report_config_t report_config)
int
report_config_in_use (report_config_t report_config)
{
// TODO: Check for alerts using the report config
return 0;
}

Expand All @@ -1085,6 +1086,7 @@ report_config_in_use (report_config_t report_config)
int
trash_report_config_in_use (report_config_t report_config)
{
// TODO: Check for alerts using the report config
return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions src/manage_sql_report_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @file manage_sql_report_configs.h
* @brief GVM management layer: Report configs SQL.
*
* SQL report config code for the GVM management layer.
*/

#ifndef _GVMD_MANAGE_SQL_REPORT_CONFIGS_H
#define _GVMD_MANAGE_SQL_REPORT_CONFIGS_H

Expand Down
6 changes: 3 additions & 3 deletions src/manage_sql_report_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ int
report_format_iterator_active (iterator_t* iterator)
{
if (iterator->done) return -1;
return (iterator_int64 (iterator, GET_ITERATOR_COLUMN_COUNT + 7)
return (iterator_int64 (iterator, GET_ITERATOR_COLUMN_COUNT + 8)
& REPORT_FORMAT_FLAG_ACTIVE) ? 1 : 0;
}

Expand Down Expand Up @@ -2981,9 +2981,9 @@ report_format_alert_iterator_readable (iterator_t* iterator)
}

/**
* @brief Initialise a Report Format alert iterator.
* @brief Initialise a Report Format config iterator.
*
* Iterates over all alerts that use the Report Format.
* Iterates over all report configs that use the Report Format.
*
* @param[in] iterator Iterator.
* @param[in] report_format Report Format.
Expand Down
50 changes: 49 additions & 1 deletion src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -16359,6 +16359,11 @@ END:VCALENDAR
<summary>Whether to include report format parameters</summary>
<type>boolean</type>
</attrib>
<attrib>
<name>report_configs</name>
<summary>Whether to include report configs that use the report format</summary>
<type>boolean</type>
</attrib>
<attrib>
<name>details</name>
<summary>Include report format file, signature and parameters</summary>
Expand Down Expand Up @@ -16404,6 +16409,9 @@ END:VCALENDAR
<e>summary</e>
<e>description</e>
<o><e>alerts</e></o>
<o><e>invisible_alerts</e></o>
<o><e>report_configs</e></o>
<o><e>invisible_report_configs</e></o>
<o>
<g>
<any><e>file</e></any>
Expand Down Expand Up @@ -16564,6 +16572,46 @@ END:VCALENDAR
</ele>
</ele>
</ele>
<ele>
<name>invisible_alerts</name>
<summary>Number of alerts only visible to other users</summary>
<pattern><t>integer</t></pattern>
</ele>
<ele>
<name>report_configs</name>
<summary>Report configs using the report format</summary>
<pattern>
<any><e>report_config</e></any>
</pattern>
<ele>
<name>report_config</name>
<pattern>
<attrib>
<name>id</name>
<type>uuid</type>
<summary>UUID of the report config</summary>
<required>1</required>
</attrib>
<e>name</e>
<o><e>permissions</e></o>
</pattern>
<ele>
<name>name</name>
<summary>Name of the report config</summary>
<pattern><t>name</t></pattern>
</ele>
<ele>
<name>permissions</name>
<summary>Permissions the user has on the report config</summary>
<pattern></pattern>
</ele>
</ele>
</ele>
<ele>
<name>invisible_report_configs</name>
<summary>Number of report configs only visible to other users</summary>
<pattern><t>integer</t></pattern>
</ele>
<ele>
<name>param</name>
<pattern>
Expand Down Expand Up @@ -26518,7 +26566,7 @@ END:VCALENDAR
<summary>Modify an existing report config</summary>
<description>
<p>
The client uses the create_report_config command to change an existing
The client uses the modify_report_config command to change an existing
report config.
</p>
</description>
Expand Down

0 comments on commit d5f4ac4

Please sign in to comment.