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

Check for opts params in osp_get_performance_ext() #268

Merged
merged 5 commits into from
Sep 26, 2019
Merged
Changes from 2 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
76 changes: 65 additions & 11 deletions osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,36 @@ osp_delete_scan (osp_connection_t *connection, const char *scan_id)
* @param[out] graph Graphic base64 encoded.
* @param[out] error Pointer to error, if any.
*
* @return 0 if success, 1 if error.
* @return 0 if success, -1 if error.
*/
int
osp_get_performance_ext (osp_connection_t *connection,
osp_get_performance_opts_t opts,
char **graph, char **error)
osp_get_performance_opts_t opts, char **graph,
char **error)
{
entity_t entity;
int rc;
time_t now;

if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send get_performance command "
"to scanner. Not valid connection");
return -1;
}

time (&now);

if (!opts.titles || !strcmp (opts.titles, "") || opts.start < 0
|| opts.start > now || opts.end < 0 || opts.end > now)
{
if (error)
*error = g_strdup ("Couldn't send get_performance command "
"to scanner. Bad or missing parameters.");
return -1;
}

assert (connection);
rc = osp_send_command (connection, &entity,
"<get_performance start='%d' "
"end='%d' titles='%s'/>",
Expand All @@ -478,11 +497,11 @@ osp_get_performance_ext (osp_connection_t *connection,
{
if (error)
*error = g_strdup ("Couldn't send get_performance command to scanner");
return 1;
return -1;
}

if (graph && entity_text (entity) && strcmp (entity_text (entity), "\0"))
*graph = g_strdup (entity_text (entity));
*graph = g_strdup (entity_text (entity));
else
{
const char *text = entity_attribute (entity, "status_text");
Expand All @@ -491,7 +510,7 @@ osp_get_performance_ext (osp_connection_t *connection,
if (error)
*error = g_strdup (text);
free_entity (entity);
return 1;
return -1;
}

free_entity (entity);
Expand All @@ -515,7 +534,15 @@ osp_get_scan_status_ext (osp_connection_t *connection,
int rc;
osp_scan_status_t status = OSP_SCAN_STATUS_ERROR;

assert (connection);

mattmundell marked this conversation as resolved.
Show resolved Hide resolved
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send get_scans command "
"to scanner. Not valid connection");
return status;
}

assert (opts.scan_id);
rc = osp_send_command (connection, &entity,
"<get_scans scan_id='%s'"
Expand Down Expand Up @@ -576,7 +603,13 @@ osp_get_scan_pop (osp_connection_t *connection, const char *scan_id,
int progress;
int rc;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send get_scan command "
"to scanner. Not valid connection");
return -1;
}
assert (scan_id);
rc = osp_send_command (connection, &entity,
"<get_scans scan_id='%s'"
Expand Down Expand Up @@ -649,7 +682,13 @@ osp_stop_scan (osp_connection_t *connection, const char *scan_id, char **error)
entity_t entity;
int rc;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send stop_scan command "
"to scanner. Not valid connection");
return -1;
}
assert (scan_id);
rc = osp_send_command (connection, &entity, "<stop_scan scan_id='%s'/>",
scan_id);
Expand Down Expand Up @@ -726,7 +765,14 @@ osp_start_scan (osp_connection_t *connection, const char *target,
int status;
int rc;

assert (connection);
if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send start_scan command "
"to scanner. Not valid connection");
return -1;
}

assert (target);
/* Construct options string. */
if (options)
Expand Down Expand Up @@ -904,6 +950,14 @@ osp_start_scan_ext (osp_connection_t *connection,
char filename[] = "/tmp/osp-cmd-XXXXXX";
int fd;

if (!connection)
{
if (error)
*error = g_strdup ("Couldn't send start_scan command "
"to scanner. Not valid connection");
return -1;
}

fd = mkstemp (filename);
FILE *file = fdopen (fd, "w");

Expand Down