Skip to content

Commit

Permalink
Add method add_nvti_tag().
Browse files Browse the repository at this point in the history
This method adds a single tag to the tags list
except it is a known tag where it is store into
the explicit structure.
  • Loading branch information
janowagner committed Aug 11, 2019
1 parent 5238886 commit 78b9d10
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions base/nvti.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,51 @@ nvti_set_solution_type (nvti_t *n, const gchar *solution_type)
return (0);
}

/**
* @brief Add a tag to the tags of a NVT.
*
* @param n The NVT Info structure.
*
* @param tag The tag to add. A copy will be created from this.
* Some known tags are not added to the tags list
* but rather stored separately.
* The known tags are: solution and solution_type.
*
* @return 0 for success. Anything else indicates an error.
*/
int
nvti_add_tag (nvti_t *n, const gchar *tag_name, const gchar *tag_value)
{
gchar * new_tags;

if (!n)
return (-1);

if (!(tag_name && tag_name[0]))
return (-2);

if (!(tag_value && tag_value[0]))
return (-3);

/* store known tags directly */
if (!strcmp (tag_name, "solution"))
return nvti_set_solution (n, tag_value);
if (!strcmp (tag_name, "solution_type"))
return nvti_set_solution_type (n, tag_value);

/* append unknown tags to the tags list */
if (n->tag)
{
new_tags = g_strconcat (n->tag, "|", tag_name, "=", tag_value, NULL);
g_free (n->tag);
n->tag = new_tags;
}
else
n->tag = g_strconcat (tag_name, "=", tag_value, NULL);

return (0);
}

/**
* @brief Set the tags of a NVT.
*
Expand Down
2 changes: 2 additions & 0 deletions base/nvti.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ nvti_set_solution (nvti_t *, const gchar *);
int
nvti_set_solution_type (nvti_t *, const gchar *);
int
nvti_add_tag (nvti_t *, const gchar *, const gchar *);
int
nvti_set_tag (nvti_t *, const gchar *);
int
nvti_set_cvss_base (nvti_t *, const gchar *);
Expand Down

0 comments on commit 78b9d10

Please sign in to comment.