Skip to content

Commit

Permalink
Merge pull request #2112 from mattmundell/move-iterator-iso-time-2
Browse files Browse the repository at this point in the history
Change: move GET iterator time conversion out of SQL
  • Loading branch information
a-h-abdelsalam authored Feb 28, 2024
2 parents 07b89ac + be66e2e commit 75016ed
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 170 deletions.
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 @@ -5830,11 +5830,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 @@ -5844,18 +5851,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 @@ -1564,10 +1564,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 @@ -21679,8 +21679,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 @@ -22152,12 +22152,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 @@ -22305,12 +22305,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 @@ -22467,12 +22467,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 @@ -23906,27 +23906,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 @@ -38530,8 +38530,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 @@ -38585,8 +38585,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 @@ -39767,8 +39767,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 @@ -39835,12 +39835,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 @@ -50155,9 +50155,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 @@ -50168,9 +50168,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 @@ -50189,9 +50189,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 @@ -50921,8 +50921,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 @@ -55289,8 +55289,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

0 comments on commit 75016ed

Please sign in to comment.