Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: move GET iterator time conversion out of SQL #2112

Merged
merged 23 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d18e6c1
Change: move GET iterator time conversion out of SQL
mattmundell Nov 20, 2023
82b6b6d
Free returns from time accessors
mattmundell Nov 20, 2023
ab20369
Remove iso_time from iterators that use the GET accessors
mattmundell Nov 20, 2023
8f52e13
Move iso_time to C for result_iterator_delta_creation_time
mattmundell Nov 22, 2023
b10666a
Move iso_time to C for result_iterator_delta_modification_time
mattmundell Nov 22, 2023
f06311c
Fix column keyword types
mattmundell Nov 22, 2023
5d0dfe6
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 1, 2023
0b1edec
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 11, 2023
1e1e147
Return time from get_iterator_creation_time and get_iterator_modifica…
mattmundell Dec 12, 2023
c1aa6f2
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 12, 2023
70ed2c2
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Dec 18, 2023
05ae3c9
Remove creation and modification iso_time from result iterator
mattmundell Dec 18, 2023
03a951d
Remove creation and modification iso_time from note and override iter…
mattmundell Dec 18, 2023
3472888
Use integer for creation and modification columns in iterators
mattmundell Dec 18, 2023
f62db89
Keep columns unique
mattmundell Dec 18, 2023
cb983df
Work around clang-format limitation
mattmundell Jan 2, 2024
7a3c7ae
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Jan 15, 2024
59e2ef4
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Jan 22, 2024
a018f55
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Jan 22, 2024
a2d065f
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Feb 26, 2024
7c4373a
Merge branch 'main' into move-iterator-iso-time-2
mattmundell Feb 27, 2024
469a03d
In iso_if_time also return empty if iso_time returns NULL
mattmundell Feb 27, 2024
be66e2e
Move iso_time to C for report_config iterator
mattmundell Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 136 additions & 83 deletions src/gmp.c

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/gmp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,7 @@ send_get_common (const char *type, get_data_t *get, iterator_t *iterator,
"<%s id=\"%s\">"
"<owner><name>%s</name></owner>"
"<name>%s</name>"
"<comment>%s</comment>"
"<creation_time>%s</creation_time>"
"<modification_time>%s</modification_time>"
"<writable>%i</writable>"
"<in_use>%i</in_use>"
"<permissions>",
"<comment>%s</comment>",
type,
get_iterator_uuid (iterator)
? get_iterator_uuid (iterator)
Expand All @@ -341,13 +336,18 @@ send_get_common (const char *type, get_data_t *get, iterator_t *iterator,
: "",
get_iterator_comment (iterator)
? get_iterator_comment (iterator)
: "",
get_iterator_creation_time (iterator)
? get_iterator_creation_time (iterator)
: "",
get_iterator_modification_time (iterator)
? get_iterator_modification_time (iterator)
: "",
: "");

buffer_xml_append_printf (buffer,
"<creation_time>%s</creation_time>",
iso_if_time (get_iterator_creation_time (iterator)));

buffer_xml_append_printf (buffer,
"<modification_time>%s</modification_time>"
"<writable>%i</writable>"
"<in_use>%i</in_use>"
"<permissions>",
iso_if_time (get_iterator_modification_time (iterator)),
writable,
in_use);

Expand Down
18 changes: 10 additions & 8 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -5829,11 +5829,18 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
nvt_iterator_detection (nvts));
}

g_string_append_printf (buffer,
"<creation_time>%s</creation_time>",
iso_if_time (get_iterator_creation_time (nvts)));

g_string_append_printf (buffer,
"<modification_time>%s</modification_time>",
iso_if_time (get_iterator_modification_time (nvts)));

default_timeout = nvt_default_timeout (oid);

g_string_append_printf (buffer,
"<default_timeout>%s</default_timeout>"
"<creation_time>%s</creation_time>"
"<modification_time>%s</modification_time>"
"<category>%d</category>"
"<family>%s</family>"
"<qod>"
Expand All @@ -5843,18 +5850,13 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
"<refs>%s</refs>"
"<tags>%s</tags>",
default_timeout ? default_timeout : "",
get_iterator_creation_time (nvts)
? get_iterator_creation_time (nvts)
: "",
get_iterator_modification_time (nvts)
? get_iterator_modification_time (nvts)
: "",
nvt_iterator_category (nvts),
family_text,
nvt_iterator_qod (nvts),
nvt_iterator_qod_type (nvts),
refs_str->str,
nvt_tags->str);

free (default_timeout);

g_string_free (nvt_tags, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,10 @@ result_iterator_delta_uuid (iterator_t*);
const char *
result_iterator_delta_qod_type (iterator_t*);

const char *
time_t
result_iterator_delta_creation_time (iterator_t*);

const char *
time_t
result_iterator_delta_modification_time (iterator_t*);

task_t
Expand Down
18 changes: 14 additions & 4 deletions src/manage_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,28 @@ get_iterator_comment (iterator_t* iterator)
*
* @param[in] iterator Iterator.
*
* @return Creation time of the resource or NULL if iteration is complete.
* @return Creation time, or 0 if iteration is complete.
*/
DEF_ACCESS (get_iterator_creation_time, 4);
time_t
get_iterator_creation_time (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_int64 (iterator, 4);
}

/**
* @brief Get the modification time of the resource from a GET iterator.
*
* @param[in] iterator Iterator.
*
* @return Modification time of the resource or NULL if iteration is complete.
* @return Modification time, or 0 if iteration is complete.
*/
DEF_ACCESS (get_iterator_modification_time, 5);
time_t
get_iterator_modification_time (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_int64 (iterator, 5);
}

/**
* @brief Get the owner name of the resource from a GET iterator.
Expand Down
4 changes: 2 additions & 2 deletions src/manage_get.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ get_iterator_name (iterator_t*);
const char*
get_iterator_comment (iterator_t*);

const char*
time_t
get_iterator_creation_time (iterator_t*);

const char*
time_t
get_iterator_modification_time (iterator_t*);

const char*
Expand Down
86 changes: 43 additions & 43 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -21670,8 +21670,8 @@ report_add_results_array (report_t report, GArray *results)
{ "uuid", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (creation_time)", "name", KEYWORD_TYPE_STRING }, \
{ "''", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "creation_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "modification_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ "(SELECT name FROM users WHERE users.id = reports.owner)", \
Expand Down Expand Up @@ -22143,12 +22143,12 @@ where_qod (int min_qod)
"name", \
KEYWORD_TYPE_STRING }, \
{ "''", "comment", KEYWORD_TYPE_STRING }, \
{ " iso_time (date, opts.user_zone)", \
{ "date", \
"creation_time", \
KEYWORD_TYPE_STRING }, \
{ " iso_time (date, opts.user_zone)", \
KEYWORD_TYPE_INTEGER }, \
{ "date", \
"modification_time", \
KEYWORD_TYPE_STRING }, \
KEYWORD_TYPE_INTEGER }, \
{ "date", "created", KEYWORD_TYPE_INTEGER }, \
{ "date", "modified", KEYWORD_TYPE_INTEGER }, \
{ "(SELECT name FROM users WHERE users.id = results.owner)", \
Expand Down Expand Up @@ -22296,12 +22296,12 @@ where_qod (int min_qod)
"name", \
KEYWORD_TYPE_STRING }, \
{ "''", "comment", KEYWORD_TYPE_STRING }, \
{ " iso_time (date, opts.user_zone)", \
{ "date", \
"creation_time", \
KEYWORD_TYPE_STRING }, \
{ " iso_time (date, opts.user_zone)", \
KEYWORD_TYPE_INTEGER }, \
{ "date", \
"modification_time", \
KEYWORD_TYPE_STRING }, \
KEYWORD_TYPE_INTEGER }, \
{ "date", "created", KEYWORD_TYPE_INTEGER }, \
{ "date", "modified", KEYWORD_TYPE_INTEGER }, \
{ "(SELECT name FROM users WHERE users.id = results.owner)", \
Expand Down Expand Up @@ -22458,12 +22458,12 @@ where_qod (int min_qod)
{ "comparison.delta_qod", NULL, KEYWORD_TYPE_INTEGER }, \
{ "comparison.delta_uuid", NULL, KEYWORD_TYPE_STRING }, \
{ "delta_qod_type", NULL, KEYWORD_TYPE_STRING }, \
{ " iso_time (delta_date, opts.user_zone)", \
{ "delta_date", \
"delta_creation_time", \
KEYWORD_TYPE_STRING }, \
{ " iso_time (delta_date, opts.user_zone)", \
KEYWORD_TYPE_INTEGER }, \
{ "delta_date", \
"delta_modification_time", \
KEYWORD_TYPE_STRING }, \
KEYWORD_TYPE_INTEGER }, \
{ "delta_task", NULL, KEYWORD_TYPE_INTEGER }, \
{ "delta_report", NULL, KEYWORD_TYPE_INTEGER }, \
{ "(SELECT name FROM users WHERE users.id = results.owner)", \
Expand Down Expand Up @@ -23897,27 +23897,27 @@ result_iterator_delta_qod_type (iterator_t* iterator)
*
* @param[in] iterator Iterator.
*
* @return delta creation time if any, else NULL.
* @return Time, or 0 if iteration is complete.
*/
const char *
time_t
result_iterator_delta_creation_time (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_string (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 6);
return iterator_int64 (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 6);
}

/**
* @brief Get delta modification time from a result iterator.
*
* @param[in] iterator Iterator.
*
* @return delta modification time if any, else NULL.
* @return Time, or 0 if iteration is complete.
*/
const char *
time_t
result_iterator_delta_modification_time (iterator_t* iterator)
{
if (iterator->done) return 0;
return iterator_string (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 7);
return iterator_int64 (iterator, RESULT_ITERATOR_DELTA_COLUMN_OFFSET + 7);
}

/**
Expand Down Expand Up @@ -38521,8 +38521,8 @@ modify_note (const gchar *note_id, const char *active, const char *nvt,
KEYWORD_TYPE_STRING \
}, \
{ "CAST ('' AS TEXT)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (notes.creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (notes.modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "notes.creation_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "notes.modification_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "notes.creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "notes.modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ "(SELECT name FROM users WHERE users.id = notes.owner)", \
Expand Down Expand Up @@ -38576,8 +38576,8 @@ modify_note (const gchar *note_id, const char *active, const char *nvt,
{ "notes_trash.uuid", "uuid", KEYWORD_TYPE_STRING }, \
{ "CAST ('' AS TEXT)", NULL, KEYWORD_TYPE_STRING }, \
{ "CAST ('' AS TEXT)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (notes_trash.creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (notes_trash.modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "notes_trash.creation_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "notes_trash.modification_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "notes_trash.creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "notes_trash.modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ "(SELECT name FROM users WHERE users.id = notes_trash.owner)", \
Expand Down Expand Up @@ -39758,8 +39758,8 @@ modify_override (const gchar *override_id, const char *active, const char *nvt,
KEYWORD_TYPE_STRING \
}, \
{ "CAST ('' AS TEXT)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (overrides.creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (overrides.modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "overrides.creation_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "overrides.modification_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "overrides.creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "overrides.modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ \
Expand Down Expand Up @@ -39826,12 +39826,12 @@ modify_override (const gchar *override_id, const char *active, const char *nvt,
{ "overrides_trash.uuid", "uuid", KEYWORD_TYPE_STRING }, \
{ "CAST ('' AS TEXT)", NULL, KEYWORD_TYPE_STRING }, \
{ "CAST ('' AS TEXT)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (overrides_trash.creation_time)", \
{ "overrides_trash.creation_time", \
NULL, \
KEYWORD_TYPE_STRING }, \
{ "iso_time (overrides_trash.modification_time)", \
KEYWORD_TYPE_INTEGER }, \
{ "overrides_trash.modification_time", \
NULL, \
KEYWORD_TYPE_STRING }, \
KEYWORD_TYPE_INTEGER }, \
{ "overrides_trash.creation_time", \
"created", \
KEYWORD_TYPE_INTEGER }, \
Expand Down Expand Up @@ -50135,9 +50135,9 @@ init_host_identifier_iterator (iterator_t* iterator, host_t host,

if (host)
init_iterator (iterator,
"SELECT id, uuid, name, comment, iso_time (creation_time),"
" iso_time (modification_time), creation_time,"
" modification_time, owner, owner, value,"
"SELECT id, uuid, name, comment, creation_time,"
" modification_time, creation_time AS created,"
" modification_time AS modified, owner, owner, value,"
" source_type, source_id, source_data,"
" (CASE WHEN source_type LIKE 'Report%%'"
" THEN NOT EXISTS (SELECT * FROM reports"
Expand All @@ -50148,9 +50148,9 @@ init_host_identifier_iterator (iterator_t* iterator, host_t host,
" FROM host_identifiers"
" WHERE host = %llu"
" UNION"
" SELECT id, uuid, name, comment, iso_time (creation_time),"
" iso_time (modification_time), creation_time,"
" modification_time, owner, owner,"
" SELECT id, uuid, name, comment, creation_time,"
" modification_time, creation_time AS created,"
" modification_time AS modified, owner, owner,"
" (SELECT name FROM oss WHERE id = os),"
" source_type, source_id, source_data,"
" (CASE WHEN source_type LIKE 'Report%%'"
Expand All @@ -50169,9 +50169,9 @@ init_host_identifier_iterator (iterator_t* iterator, host_t host,
ascending ? "ASC" : "DESC");
else
init_iterator (iterator,
"SELECT id, uuid, name, comment, iso_time (creation_time),"
" iso_time (modification_time), creation_time,"
" modification_time, owner, owner, value,"
"SELECT id, uuid, name, comment, creation_time,"
" modification_time, creation_time AS created,"
" modification_time AS modified, owner, owner, value,"
" source_type, source_id, source_data, 0, '', ''"
" FROM host_identifiers"
" ORDER BY %s %s;",
Expand Down Expand Up @@ -50901,8 +50901,8 @@ init_os_host_iterator (iterator_t* iterator, resource_t os)
{
assert (os);
init_iterator (iterator,
"SELECT id, uuid, name, comment, iso_time (creation_time),"
" iso_time (modification_time), creation_time,"
"SELECT id, uuid, name, comment, creation_time,"
" modification_time, creation_time,"
" modification_time, owner, owner,"
" (SELECT round (CAST (severity AS numeric), 1)"
" FROM host_max_severities"
Expand Down Expand Up @@ -55258,8 +55258,8 @@ user_resources_in_use (user_t user,
{ "uuid", "uuid", KEYWORD_TYPE_STRING }, \
{ "name", "name", KEYWORD_TYPE_STRING }, \
{ "''", "comment", KEYWORD_TYPE_STRING }, \
{ "iso_time (creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "creation_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "modification_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ "cast (null AS text)", "_owner", KEYWORD_TYPE_INTEGER }, \
Expand Down
Loading