Skip to content

Commit

Permalink
Add vtref_*(), and nvti_ref*() functions.
Browse files Browse the repository at this point in the history
This add vref_type(), vtref_id(), nvt_ref() and
nvt_ref_len() to the API.
These functions allow to work with the actual reference
object rather than with the serialized strings.
The names are choosen to be consistent with the prefs
handling.
  • Loading branch information
janowagner committed May 7, 2019
1 parent 4b96b46 commit 33da42f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
58 changes: 57 additions & 1 deletion base/nvti.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,34 @@ vtref_free (vtref_t *ref)
g_free (ref);
}

/**
* @brief Get the type of a reference.
*
* @param r The VT Reference structure of which the type should
* be returned.
*
* @return The type string. Don't free this.
*/
gchar *
vtref_type (const vtref_t *r)
{
return (r ? r->type : NULL);
}

/**
* @brief Get the id of a reference.
*
* @param r The VT Reference structure of which the id should
* be returned.
*
* @return The id string. Don't free this.
*/
gchar *
vtref_id (const vtref_t *r)
{
return (r ? r->ref_id : NULL);
}

/**
* @brief Add a reference to the VT Info.
*
Expand Down Expand Up @@ -298,6 +326,34 @@ nvti_name (const nvti_t *n)
return (n ? n->name : NULL);
}

/**
* @brief Get the number of references of the NVT.
*
* @param n The NVT Info structure.
*
* @return The number of references.
*/
guint
nvti_ref_len (const nvti_t *n)
{
return (n ? g_slist_length (n->refs) : 0);
}

/**
* @brief Get the n'th reference of the NVT.
*
* @param n The NVT Info structure.
*
* @param p The position of the reference to return.
*
* @return The reference. NULL on error.
*/
vtref_t *
nvti_ref (const nvti_t *n, guint p)
{
return (n ? g_slist_nth_data (n->refs, p) : NULL);
}

/**
* @brief Get references as string.
*
Expand Down Expand Up @@ -521,7 +577,7 @@ nvti_pref_len (const nvti_t *n)
*
* @param p The position of the preference to return.
*
* @return The number of preferences. NULL if
* @return The preference. NULL on error.
*/
const nvtpref_t *
nvti_pref (const nvti_t *n, guint p)
Expand Down
9 changes: 9 additions & 0 deletions base/nvti.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,17 @@ vtref_t *
vtref_new (const gchar *, const gchar *, const gchar *);
void
vtref_free (vtref_t *);
gchar *
vtref_type (const vtref_t *);
gchar *
vtref_id (const vtref_t *);

int
nvti_add_ref (nvti_t *, vtref_t *);
guint
nvti_ref_len (const nvti_t *);
vtref_t *
nvti_ref (const nvti_t *, guint);

nvti_t *
nvti_new (void);
Expand Down

0 comments on commit 33da42f

Please sign in to comment.