guard against empty mqtt subscription topic

This commit is contained in:
hxy7yx
2024-08-14 14:23:30 +08:00
parent 53fd732ed5
commit b13257e453
2 changed files with 6 additions and 4 deletions
+5 -3
View File
@@ -697,9 +697,11 @@ int neu_manager_subscribe(neu_manager_t *manager, const char *app,
// guard against empty mqtt topic parameter
// this is not an elegant solution due to the current architecture
if (params && 0 == strcmp(adapter->module->module_name, "MQTT")) {
neu_json_elem_t elem = { .name = "topic", .t = NEU_JSON_STR };
neu_parse_param(params, NULL, 1, &elem);
if (elem.v.val_str && 0 == strlen(elem.v.val_str)) {
neu_json_elem_t elem = { .name = "topic",
.t = NEU_JSON_STR,
.v.val_str = NULL };
int ret = neu_parse_param(params, NULL, 1, &elem);
if (ret != 0 || (elem.v.val_str && 0 == strlen(elem.v.val_str))) {
free(elem.v.val_str);
return NEU_ERR_MQTT_SUBSCRIBE_FAILURE;
}
+1 -1
View File
@@ -307,7 +307,7 @@ def get_template_tags(tmpl, group, name):
@gen_check
def subscribe_group(app, driver, group, params={}):
def subscribe_group(app, driver, group, params={"topic": "/neuron/mqtt/test"}):
return requests.post(url=config.BASE_URL + "/api/v2/subscribe", headers={"Authorization": config.default_jwt}, json={"app": app, "driver": driver, "group": group, "params": params})