From 5e91bfd5b8ae377896c5fc5527540d98a7301d8d Mon Sep 17 00:00:00 2001 From: wanghaemq Date: Wed, 3 Jan 2024 01:12:19 -0500 Subject: [PATCH 1/2] * FIX [hook] Fix that some msgs from external are forwarded to webhook handler. Signed-off-by: wanghaemq --- nanomq/webhook_inproc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nanomq/webhook_inproc.c b/nanomq/webhook_inproc.c index 514ddef1c..a810cc2bf 100644 --- a/nanomq/webhook_inproc.c +++ b/nanomq/webhook_inproc.c @@ -314,9 +314,13 @@ hook_work_cb(void *arg) body = (char *) nng_msg_body(msg); root = NULL; - if (exconf->count > 0) { - // Only parse msg when exchange is enabled - root = cJSON_Parse(body); + // TODO Not efficent + // Only parse msg when exchange is enabled + root = cJSON_Parse(body); + cJSON *idjo = cJSON_GetObjectItem(root, "ID"); + if (!idjo) { + cJSON_Delete(root); + root = NULL; } if (root) { cJSON *idjo = cJSON_GetObjectItem(root, "ID"); From 107ae338a18d831434a2ab17ed430a1cb2c7b847 Mon Sep 17 00:00:00 2001 From: wanghaemq Date: Wed, 3 Jan 2024 01:13:28 -0500 Subject: [PATCH 2/2] * FIX [hook] Fix the error that access a null pointer. Signed-off-by: wanghaemq --- nanomq/webhook_inproc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nanomq/webhook_inproc.c b/nanomq/webhook_inproc.c index a810cc2bf..4aebe55ec 100644 --- a/nanomq/webhook_inproc.c +++ b/nanomq/webhook_inproc.c @@ -323,7 +323,6 @@ hook_work_cb(void *arg) root = NULL; } if (root) { - cJSON *idjo = cJSON_GetObjectItem(root, "ID"); char *idstr = NULL; if (idjo) idstr = idjo->valuestring; @@ -361,14 +360,15 @@ hook_work_cb(void *arg) msg = work->msg; work->msg = NULL; - // TODO match exchange with IPC msg (by MQ name) - nng_socket *ex_sock = exconf->nodes[0]->sock; if (exconf->count == 0) { log_error("Exchange is not enabled"); nng_msg_free(msg); goto skip; } + // TODO match exchange with IPC msg (by MQ name) + nng_socket *ex_sock = exconf->nodes[0]->sock; + body = (char *) nng_msg_body(msg); root = cJSON_Parse(body);