mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
fix(restful): update group name check for name confliction
This commit is contained in:
@@ -153,6 +153,17 @@ Update group with too long new name, it should fail.
|
||||
|
||||
[Teardown] Del Node modbus-node
|
||||
|
||||
Update group name to conflicting group name, it should fail.
|
||||
Add Node modbus-node ${PLUGIN-MODBUS-TCP}
|
||||
Add Group modbus-node group 1000
|
||||
Add Group modbus-node grp 1000
|
||||
|
||||
${res} = Update Group modbus-node group new_name=grp
|
||||
Check Response Status ${res} 409
|
||||
Check Error Code ${res} ${NEU_ERR_GROUP_EXIST}
|
||||
|
||||
[Teardown] Del Node modbus-node
|
||||
|
||||
Update group name, it should success.
|
||||
Add Node modbus-node ${PLUGIN-MODBUS-TCP}
|
||||
Add Group modbus-node group 1000
|
||||
|
||||
@@ -724,8 +724,17 @@ int neu_adapter_driver_update_group(neu_adapter_driver_t *driver,
|
||||
return NEU_ERR_GROUP_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (NULL != new_name && 0 == strlen(new_name)) {
|
||||
return NEU_ERR_EINTERNAL;
|
||||
if (NULL != new_name) {
|
||||
if (0 == strlen(new_name)) {
|
||||
return NEU_ERR_EINTERNAL;
|
||||
}
|
||||
if (0 != strcmp(name, new_name)) {
|
||||
group_t *other = NULL;
|
||||
HASH_FIND_STR(driver->groups, new_name, other);
|
||||
if (NULL != other) {
|
||||
return NEU_ERR_GROUP_EXIST;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stop the timer first to avoid race condition
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#include "utils/log.h"
|
||||
#include "json/json.h"
|
||||
|
||||
#include "neu_json_group_config.h"
|
||||
@@ -618,14 +619,14 @@ int neu_json_decode_update_group_config_req(
|
||||
goto error;
|
||||
}
|
||||
|
||||
neu_json_elem_t interval_elem = {
|
||||
.name = "interval",
|
||||
.t = NEU_JSON_INT,
|
||||
};
|
||||
ret = neu_json_decode_by_json(json_obj, 1, &interval_elem);
|
||||
if (0 == ret) {
|
||||
json_t *json_interval = json_object_get(json_obj, "interval");
|
||||
if (NULL != json_interval) {
|
||||
if (!json_is_integer(json_interval)) {
|
||||
nlog_error("decode interval is not integer");
|
||||
goto error;
|
||||
}
|
||||
req->set_interval = true;
|
||||
req->interval = interval_elem.v.val_int;
|
||||
req->interval = json_integer_value(json_interval);
|
||||
} else if (NULL == req->new_name) {
|
||||
// at least one of `new_name` or `interval` should be provided
|
||||
goto error;
|
||||
|
||||
Reference in New Issue
Block a user