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

Make solution and solution_type explicit for nvti #255

Merged
merged 3 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 78 additions & 2 deletions base/nvti.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ typedef struct nvti
gchar *oid; /**< @brief Object ID */
gchar *name; /**< @brief The name */

gchar *solution; /**< @brief The solution */
gchar *solution_type; /**< @brief The solution type */

gchar *tag; /**< @brief List of tags attached to this NVT */
gchar *cvss_base; /**< @brief CVSS base score for this NVT. */

Expand Down Expand Up @@ -338,6 +341,8 @@ nvti_free (nvti_t *n)

g_free (n->oid);
g_free (n->name);
g_free (n->solution);
g_free (n->solution_type);
g_free (n->tag);
g_free (n->cvss_base);
g_free (n->dependencies);
Expand Down Expand Up @@ -500,9 +505,37 @@ nvti_refs (const nvti_t *n, const gchar *type, const gchar *exclude_types,
}

/**
* @brief Get the tag.
* @brief Get the solution.
*
* @param n The NVT Info structure of which the name should
* @param n The NVT Info structure of which the solution should
* be returned.
*
* @return The solution string. Don't free this.
*/
gchar *
nvti_solution (const nvti_t *n)
{
return (n ? n->solution : NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: you're the only one using parens with "return". Everywhere else uses "return 0;" style.

}

/**
* @brief Get the solution type.
*
* @param n The NVT Info structure of which the solution type should
* be returned.
*
* @return The solution type string. Don't free this.
*/
gchar *
nvti_solution_type (const nvti_t *n)
{
return (n ? n->solution_type : NULL);
}

/**
* @brief Get the tags.
*
* @param n The NVT Info structure of which the tags should
* be returned.
*
* @return The tags string. Don't free this.
Expand Down Expand Up @@ -736,6 +769,49 @@ nvti_set_name (nvti_t *n, const gchar *name)
return (0);
}

/**
* @brief Set the solution of a NVT.
*
* @param n The NVT Info structure.
*
* @param solution The solution to set. A copy will be created from this.
*
* @return 0 for success. Anything else indicates an error.
*/
int
nvti_set_solution (nvti_t *n, const gchar *solution)
{
if (!n)
return (-1);

if (n->solution)
g_free (n->solution);
n->solution = g_strdup (solution);
return (0);
}

/**
* @brief Set the solution type of a NVT.
*
* @param n The NVT Info structure.
*
* @param solution_type The solution type to set. A copy will be created
* from this.
*
* @return 0 for success. Anything else indicates an error.
*/
int
nvti_set_solution_type (nvti_t *n, const gchar *solution_type)
{
if (!n)
return (-1);

if (n->solution_type)
g_free (n->solution_type);
n->solution_type = g_strdup (solution_type);
return (0);
}

/**
* @brief Set the tags of a NVT.
*
Expand Down
8 changes: 8 additions & 0 deletions base/nvti.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ nvti_name (const nvti_t *);
gchar *
nvti_refs (const nvti_t *, const gchar *, const char *, guint);
gchar *
nvti_solution (const nvti_t *);
gchar *
nvti_solution_type (const nvti_t *);
gchar *
nvti_tag (const nvti_t *);
gchar *
nvti_cvss_base (const nvti_t *);
Expand Down Expand Up @@ -134,6 +138,10 @@ nvti_set_oid (nvti_t *, const gchar *);
int
nvti_set_name (nvti_t *, const gchar *);
int
nvti_set_solution (nvti_t *, const gchar *);
int
nvti_set_solution_type (nvti_t *, const gchar *);
int
nvti_set_tag (nvti_t *, const gchar *);
int
nvti_set_cvss_base (nvti_t *, const gchar *);
Expand Down