Skip to content

Commit

Permalink
Merge pull request #357 from jjnicola/vts-version
Browse files Browse the repository at this point in the history
Modify osp_get_vts_version()
  • Loading branch information
mattmundell authored Jun 29, 2020
2 parents 4319466 + 2bbad2d commit e5b2715
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
- Improve validation in is_hostname [#353](https://github.com/greenbone/gvm-libs/pull/353)
- Use get_vts instead of get_version to get the feed version is osp_get_vts_version(). [#357](https://github.com/greenbone/gvm-libs/pull/357)

### Fixed
- Fix is_cidr_block(). [#322](https://github.com/greenbone/gvm-libs/pull/322)
Expand Down
40 changes: 30 additions & 10 deletions osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,38 +331,51 @@ osp_get_version (osp_connection_t *connection, char **s_name, char **s_version,
*
* @param[in] connection Connection to an OSP server.
* @param[out] vts_version Parsed scanner version.
* @param[out] error Pointer to error, if any.
*
* @return 0 if success, 1 if error.
*/
int
osp_get_vts_version (osp_connection_t *connection, char **vts_version)
osp_get_vts_version (osp_connection_t *connection, char **vts_version,
char **error)
{
entity_t entity, vts, version;
entity_t entity, vts;
const char *version;
const char *status, *status_text;
osp_get_vts_opts_t get_vts_opts;

if (!connection)
return 1;

if (osp_send_command (connection, &entity, "<get_version/>"))
get_vts_opts.filter = NULL;
get_vts_opts.version_only = 1;
if (osp_get_vts_ext (connection, get_vts_opts, &entity))
return 1;

vts = entity_child (entity, "vts");
if (!vts)
status = entity_attribute (entity, "status");

if (status != NULL && !strcmp (status, "400"))
{
g_warning ("%s: element VTS missing.", __func__);
status_text = entity_attribute (entity, "status_text");
g_debug ("%s: %s - %s.", __func__, status, status_text);
if (error)
*error = g_strdup (status_text);
free_entity (entity);
return 1;
}

version = entity_child (vts, "version");
if (!version)
vts = entity_child (entity, "vts");
if (!vts)
{
g_warning ("%s: element VERSION missing.", __func__);
g_warning ("%s: element VTS missing.", __func__);
free_entity (entity);
return 1;
}

version = entity_attribute (vts, "vts_version");

if (vts_version)
*vts_version = g_strdup (entity_text (version));
*vts_version = g_strdup (version);

free_entity (entity);
return 0;
Expand Down Expand Up @@ -410,6 +423,13 @@ osp_get_vts_ext (osp_connection_t *connection, osp_get_vts_opts_t opts,
if (vts == NULL)
return 1;

if (opts.version_only == 1)
{
if (osp_send_command (connection, vts, "<get_vts version_only='1'/>"))
return 1;
return 0;
}

if (opts.filter)
{
if (osp_send_command (connection, vts, "<get_vts filter='%s'/>",
Expand Down
5 changes: 3 additions & 2 deletions osp/osp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ osp_get_version (osp_connection_t *, char **, char **, char **, char **,
char **, char **);

int
osp_get_vts_version (osp_connection_t *, char **);
osp_get_vts_version (osp_connection_t *, char **, char **error);

int
osp_get_vts (osp_connection_t *, entity_t *);

typedef struct
{
char *filter; ///< the filter to apply for a vt sub-selection.
char *filter; ///< the filter to apply for a vt sub-selection.
int version_only; ///< if get only feed info or the vt collection
} osp_get_vts_opts_t;

int
Expand Down

0 comments on commit e5b2715

Please sign in to comment.