mirror of https://git.48k.eu/ogserver
#942 Use client's IP as filter in GET /hardware
This patch uses client's IP instead of scope ID as a filter for the request. Request: GET /hardware { "client": ["192.168.56.11"] } Response: 200 OK { "hardware": [ { "description": "BIOS", "type": "Tipo de proceso de arranque" }, { "description": "QEMU Standard PC (i440FX + PIIX, 1996) v.pc-i440fx-5.1", "type": "Marca y modelo del equipo" }, { "description": "Intel Corp. Intel Core Processor (Haswell, no TSX, IBRS) 2GHz v.pc-i440fx-5.1", "type": "Microprocesadores" }, { "description": "QEMU 2049MiB (DIMM 0)", "type": "Memorias" }, { "description": "Red Hat, Inc. Virtio network device v.00", "type": "Tarjetas de Red" } ] }master
parent
25c1c16e99
commit
2958d23db2
23
src/rest.c
23
src/rest.c
|
@ -1452,8 +1452,6 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
|
|||
{
|
||||
const char *key, *msglog, *hw_item, *hw_type;
|
||||
json_t *value, *root, *array, *item;
|
||||
struct og_scope scope = {};
|
||||
uint64_t flags = 0;
|
||||
struct og_dbi *dbi;
|
||||
dbi_result result;
|
||||
int err = 0;
|
||||
|
@ -1463,27 +1461,18 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
|
|||
};
|
||||
|
||||
json_object_foreach(element, key, value) {
|
||||
if (!strcmp(key, "scope")) {
|
||||
err = og_json_parse_scope(value, &scope,
|
||||
OG_PARAM_SCOPE_ID |
|
||||
OG_PARAM_SCOPE_TYPE);
|
||||
flags |= OG_REST_PARAM_SCOPE;
|
||||
} else {
|
||||
if (!strcmp(key, "client"))
|
||||
err = og_json_parse_clients(value, params);
|
||||
else
|
||||
err = -1;
|
||||
}
|
||||
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!og_flags_validate(flags, OG_REST_PARAM_SCOPE))
|
||||
if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR))
|
||||
return -1;
|
||||
|
||||
if (strcmp(scope.type, "computer")) {
|
||||
syslog(LOG_ERR, "incorrect scope type\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
|
@ -1501,8 +1490,8 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
|
|||
" ON perfileshard_hardwares.idperfilhard = ordenadores.idperfilhard "
|
||||
"INNER JOIN tipohardwares "
|
||||
" ON hardwares.idtipohardware = tipohardwares.idtipohardware "
|
||||
"WHERE ordenadores.idordenador = %u",
|
||||
scope.id);
|
||||
"WHERE ordenadores.ip = '%s'",
|
||||
params->ips_array[0]);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||
|
|
Loading…
Reference in New Issue