Skip to content

Commit

Permalink
Merge pull request #259 from jjnicola/osp-get-status
Browse files Browse the repository at this point in the history
Add function to get an osp scan status.
  • Loading branch information
mattmundell authored Aug 26, 2019
2 parents ef671eb + d2884d6 commit c275352
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Allow to configure the path to the redis socket via CMake [#256](https://github.com/greenbone/gvm-libs/pull/256)
- A new data model for unified handling of cross references in the NVT meta data as been added. All previous API elements to handle cve, bid, xref werehas been removed. [#225](https://github.com/greenbone/gvm-libs/pull/225) [#232](https://github.com/greenbone/gvm-libs/pull/232).

- A function to get an osp scan status and a enum type for the different status [#259](https://github.com/greenbone/gvm-libs/pull/259)
### Changed
- Change the default path to the redis socket to /run/redis/redis.sock [#256](https://github.com/greenbone/gvm-libs/pull/256)
- Handle EAI_AGAIN in gvm_host_reverse_lookup() IPv6 case and function refactor. [#229](https://github.com/greenbone/gvm-libs/pull/229)
Expand Down
58 changes: 58 additions & 0 deletions osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,64 @@ osp_delete_scan (osp_connection_t *connection, const char *scan_id)
return ret;
}


/**
* @brief Get a scan status from an OSP server
*
* @param[in] connection Connection to an OSP server.
* @param[in] scan_id ID of scan to get.
* @param[out] error Pointer to error, if any.
*
* @return Osp scan status
*/
osp_scan_status_t
osp_get_scan_status_ext (osp_connection_t *connection,
osp_get_scan_status_opts_t opts, char **error)
{
entity_t entity, child;
int rc;
osp_scan_status_t status = OSP_SCAN_STATUS_ERROR;

assert (connection);
assert (opts.scan_id);
rc = osp_send_command (connection, &entity,
"<get_scans scan_id='%s'"
" details='0'"
" pop_results='0'/>",
opts.scan_id);

if (rc)
{
if (error)
*error = g_strdup ("Couldn't send get_scans command to scanner");
return status;
}

child = entity_child (entity, "scan");
if (!child)
{
const char *text = entity_attribute (entity, "status_text");

assert (text);
if (error)
*error = g_strdup (text);
free_entity (entity);
return status;
}

if (!strcmp (entity_attribute (child, "status"), "init"))
status = OSP_SCAN_STATUS_INIT;
else if (!strcmp (entity_attribute (child, "status"), "running"))
status = OSP_SCAN_STATUS_RUNNING;
else if (!strcmp (entity_attribute (child, "status"), "stopped"))
status = OSP_SCAN_STATUS_STOPPED;
else if (!strcmp (entity_attribute (child, "status"), "finished"))
status = OSP_SCAN_STATUS_FINISHED;

free_entity (entity);
return status;
}

/**
* @brief Get a scan from an OSP server, optionally removing the results.
*
Expand Down
21 changes: 21 additions & 0 deletions osp/osp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ typedef enum
OSP_PARAM_TYPE_CRD_UP, /**< Credential user/pass type. */
} osp_param_type_t;

/**
* @brief OSP scan status.
*/
typedef enum
{
OSP_SCAN_STATUS_ERROR = -1, /**< Error status. */
OSP_SCAN_STATUS_INIT, /**< Init status. */
OSP_SCAN_STATUS_RUNNING, /**< Running status. */
OSP_SCAN_STATUS_STOPPED, /**< Stopped status. */
OSP_SCAN_STATUS_FINISHED, /**< Finished status. */
} osp_scan_status_t;

typedef struct osp_param osp_param_t;

/* OSP Connection handling */
Expand Down Expand Up @@ -111,6 +123,15 @@ osp_get_scan_pop (osp_connection_t *,
int,
char **);

typedef struct {
const char *scan_id; ///< UUID of the scan which get the status from.
} osp_get_scan_status_opts_t;

osp_scan_status_t
osp_get_scan_status_ext (osp_connection_t *,
osp_get_scan_status_opts_t,
char **);

int
osp_delete_scan (osp_connection_t *, const char *);

Expand Down

0 comments on commit c275352

Please sign in to comment.