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

Improve handling of http parameters and arguments for gmp #1355

Merged
merged 16 commits into from
Jun 6, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleanup and improve get_assets
* Update get_assets to use gmp_arguments
* Require asset_type param
bjoernricks committed Jun 5, 2019
commit 252f1d133c50dfc7ddf0bf04defa04e8ad361f2f
45 changes: 11 additions & 34 deletions gsad/src/gsad_gmp.c
Original file line number Diff line number Diff line change
@@ -17510,48 +17510,25 @@ get_assets (gvm_connection_t *connection, credentials_t *credentials,
params_t *params, const char *extra_xml,
cmd_response_data_t *response_data)
{
char *ret;
GString *extra_attribs, *extra_response;
gmp_arguments_t *arguments;
const char *asset_type;

asset_type = params_value (params, "asset_type");
if (asset_type == NULL)
{
param_t *param;
param = params_add (params, "asset_type", "host");
param->valid = 1;
param->valid_utf8 = g_utf8_validate (param->value, -1, NULL);
asset_type = params_value (params, "asset_type");
}

if (strcmp (asset_type, "host") && strcmp (asset_type, "os"))
{
cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
return gsad_message (credentials, "Internal error", __FUNCTION__,
__LINE__,
"An internal error occurred while getting Assets. "
"Diagnostics: Invalid asset_type parameter value",
response_data);
}
CHECK_VARIABLE_INVALID (asset_type, "Get Assets");

extra_response = g_string_new (extra_xml ? extra_xml : "");
arguments = gmp_arguments_new ();

extra_attribs = g_string_new ("");
g_string_append_printf (extra_attribs, "type=\"%s\" ignore_pagination=\"%s\"",
params_value (params, "asset_type"),
params_value (params, "ignore_pagination")
? params_value (params, "ignore_pagination")
: "0");
if (params_value (params, "details"))
g_string_append_printf (extra_attribs, " details=\"%s\"",
params_value (params, "details"));
ret = get_many (connection, "asset", credentials, params, extra_response->str,
extra_attribs->str, response_data);
gmp_arguments_add (arguments, "type", asset_type);

g_string_free (extra_response, TRUE);
g_string_free (extra_attribs, TRUE);
if (params_value (params, "ignore_pagination"))
{
gmp_arguments_add (arguments, "ignore_pagination",
params_value (params, "ignore_pagination"));
}

return ret;
return get_many (connection, "asset", credentials, params, extra_xml,
arguments, response_data);
}

/**