mirror of
https://github.com/emqx/neuron.git
synced 2026-10-31 08:29:03 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd3b96a568 | ||
|
|
36fe84ab6e | ||
|
|
ccc9492f82 | ||
|
|
4b97979d38 | ||
|
|
2a4e6a39e9 | ||
|
|
b1bf3830ad | ||
|
|
0e850fe85a | ||
|
|
8ac388f414 | ||
|
|
3400c7546f | ||
|
|
a4b863818f | ||
|
|
62ed730ba6 | ||
|
|
e9c318296b | ||
|
|
848a38e962 | ||
|
|
dd689ca4d2 | ||
|
|
e878a3fd8e | ||
|
|
8b1d72b9dc | ||
|
|
638a2d08f9 | ||
|
|
7000e3f7a6 | ||
|
|
9e9b5be252 | ||
|
|
ed67628e92 |
+22
-10
@@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
# checkout
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
|
||||
cppcheck:
|
||||
runs-on: ubuntu-24.04
|
||||
container: ghcr.io/neugates/build:x86_64-main
|
||||
container: ghcr.io/neugates/build:x86_64-v2.15
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -40,9 +40,21 @@ jobs:
|
||||
cppcheck --enable=all --error-exitcode=2 --inline-suppr --suppress=missingInclude --suppress=unusedFunction --suppress=*:src/otel/trace.pb-c.c --suppress=*:src/otel/common.pb-c.c --suppress=*:src/otel/resource.pb-c.c ./plugins ./src
|
||||
cppcheck --enable=all --error-exitcode=2 --inline-suppr --suppress=missingInclude --suppress=variableScope ./simulator
|
||||
|
||||
flawfinder:
|
||||
name: Flawfinder Scan
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: flawfinder_scan
|
||||
uses: david-a-wheeler/flawfinder@2.0.20
|
||||
with:
|
||||
arguments: '--minlevel=3 .'
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-24.04
|
||||
container: ghcr.io/neugates/build:x86_64-main
|
||||
container: ghcr.io/neugates/build:x86_64-v2.15
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -65,7 +77,7 @@ jobs:
|
||||
|
||||
ut:
|
||||
runs-on: ubuntu-24.04
|
||||
container: ghcr.io/neugates/build:x86_64-main
|
||||
container: ghcr.io/neugates/build:x86_64-v2.15
|
||||
needs: [build]
|
||||
|
||||
steps:
|
||||
@@ -103,7 +115,7 @@ jobs:
|
||||
|
||||
pft:
|
||||
runs-on: ubuntu-24.04
|
||||
container: ghcr.io/neugates/build:x86_64-main
|
||||
container: ghcr.io/neugates/build:x86_64-v2.15
|
||||
needs: [build]
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -169,7 +181,7 @@ jobs:
|
||||
|
||||
pft_kafka:
|
||||
runs-on: ubuntu-24.04
|
||||
container: ghcr.io/neugates/build:x86_64-main
|
||||
container: ghcr.io/neugates/build:x86_64-v2.15
|
||||
needs: [build]
|
||||
services:
|
||||
kafka:
|
||||
@@ -212,13 +224,13 @@ jobs:
|
||||
- name: debug kafka plugin deps
|
||||
run: |
|
||||
echo "=== libs in staging prefix ==="
|
||||
ls -la /home/neuron/main/libs/x86_64-linux-gnu/lib/librdkafka* || echo "no librdkafka"
|
||||
ls -la /home/neuron/main/libs/x86_64-linux-gnu/lib/libzstd* || echo "no libzstd"
|
||||
ls -la /home/neuron/main/libs/x86_64-linux-gnu/lib/libsasl2* || echo "no libsasl2"
|
||||
ls -la /home/neuron/v2.15/libs/x86_64-linux-gnu/lib/librdkafka* || echo "no librdkafka"
|
||||
ls -la /home/neuron/v2.15/libs/x86_64-linux-gnu/lib/libzstd* || echo "no libzstd"
|
||||
ls -la /home/neuron/v2.15/libs/x86_64-linux-gnu/lib/libsasl2* || echo "no libsasl2"
|
||||
echo "=== libs in /usr/local/lib ==="
|
||||
ls -la /usr/local/lib/librdkafka* /usr/local/lib/libzstd* /usr/local/lib/libsasl2* 2>/dev/null || echo "none yet"
|
||||
echo "=== ldd librdkafka from staging ==="
|
||||
ldd /home/neuron/main/libs/x86_64-linux-gnu/lib/librdkafka.so.1 || true
|
||||
ldd /home/neuron/v2.15/libs/x86_64-linux-gnu/lib/librdkafka.so.1 || true
|
||||
echo "=== ldd plugin-kafka from build ==="
|
||||
chmod -R +x ./build/ 2>/dev/null || true
|
||||
ldd ./build/plugins/libplugin-kafka.so || true
|
||||
|
||||
@@ -8,9 +8,9 @@ on:
|
||||
- published
|
||||
|
||||
env:
|
||||
VERSION: 2.14.0
|
||||
VERSION: 2.15.0
|
||||
UI_VERSION: 2.6.1
|
||||
BRANCH: main
|
||||
BRANCH: v2.15
|
||||
|
||||
jobs:
|
||||
cross-build:
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
matrix:
|
||||
arch:
|
||||
- [x86_64-linux-gnu, x86_64, amd64]
|
||||
container: ghcr.io/neugates/build:${{ matrix.arch[1] }}-main
|
||||
container: ghcr.io/neugates/build:${{ matrix.arch[1] }}-v2.15
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -62,7 +62,7 @@ jobs:
|
||||
matrix:
|
||||
arch:
|
||||
- [x86_64-linux-gnu, x86_64, amd64]
|
||||
container: ghcr.io/neugates/build:${{ matrix.arch[1] }}-main
|
||||
container: ghcr.io/neugates/build:${{ matrix.arch[1] }}-v2.15
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX aarch64-linux-gnu)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
set(LIBRARY_DIR /home/neuron/main/libs)
|
||||
set(LIBRARY_DIR /home/neuron/v2.15/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX arm-linux-gnueabi)
|
||||
set(CMAKE_SYSTEM_PROCESSOR armv5tejl)
|
||||
set(LIBRARY_DIR /home/neuron/main/libs)
|
||||
set(LIBRARY_DIR /home/neuron/v2.15/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX arm-linux-gnueabihf)
|
||||
set(CMAKE_SYSTEM_PROCESSOR armv7l)
|
||||
set(LIBRARY_DIR /home/neuron/main/libs)
|
||||
set(LIBRARY_DIR /home/neuron/v2.15/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX x86_64-linux-gnu)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
set(LIBRARY_DIR /home/neuron/main/libs)
|
||||
set(LIBRARY_DIR /home/neuron/v2.15/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#define NEU_VERSION_MAJOR 2
|
||||
#define NEU_VERSION_MINOR 14
|
||||
#define NEU_VERSION_MINOR 15
|
||||
#define NEU_VERSION_FIX 0
|
||||
|
||||
#define NEU_GET_VERSION_MAJOR(V) ((0xffff0000 & V) >> 16)
|
||||
@@ -98,6 +98,9 @@
|
||||
#define NEU_CID_LEN32 32
|
||||
#define NEU_CID_LEN64 64
|
||||
|
||||
#define NEU_TRACE_ID_LEN 64
|
||||
#define NEU_SPAN_ID_LEN 32
|
||||
|
||||
#define CHECK_NODE_NAME_LENGTH_ERR \
|
||||
do { \
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_NODE_NAME_TOO_LONG, { \
|
||||
|
||||
@@ -286,8 +286,8 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
char distro[32];
|
||||
char kernel[32];
|
||||
char machine[32];
|
||||
char kernel[80];
|
||||
char machine[80];
|
||||
char clib[32];
|
||||
char clib_version[32];
|
||||
unsigned cpu_percent;
|
||||
|
||||
@@ -671,8 +671,8 @@ static inline void neu_req_add_tag_fini(neu_req_add_tag_t *req)
|
||||
static inline int neu_req_add_tag_copy(neu_req_add_tag_t *dst,
|
||||
neu_req_add_tag_t *src)
|
||||
{
|
||||
strcpy(dst->driver, src->driver);
|
||||
strcpy(dst->group, src->group);
|
||||
strncpy(dst->driver, src->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(dst->group, src->group, NEU_GROUP_NAME_LEN - 1);
|
||||
dst->tags = (neu_datatag_t *) calloc(src->n_tag, sizeof(src->tags[0]));
|
||||
if (NULL == dst->tags) {
|
||||
return -1;
|
||||
@@ -707,8 +707,8 @@ static inline void neu_req_del_tag_fini(neu_req_del_tag_t *req)
|
||||
static inline int neu_req_del_tag_copy(neu_req_del_tag_t *dst,
|
||||
neu_req_del_tag_t *src)
|
||||
{
|
||||
strcpy(dst->driver, src->driver);
|
||||
strcpy(dst->group, src->group);
|
||||
strncpy(dst->driver, src->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(dst->group, src->group, NEU_GROUP_NAME_LEN - 1);
|
||||
dst->tags = (char **) calloc(src->n_tag, sizeof(src->tags[0]));
|
||||
if (NULL == dst->tags) {
|
||||
return -1;
|
||||
@@ -863,7 +863,7 @@ static inline void neu_req_node_setting_fini(neu_req_node_setting_t *req)
|
||||
static inline int neu_req_node_setting_copy(neu_req_node_setting_t *dst,
|
||||
neu_req_node_setting_t *src)
|
||||
{
|
||||
strcpy(dst->node, src->node);
|
||||
strncpy(dst->node, src->node, NEU_NODE_NAME_LEN - 1);
|
||||
dst->setting = strdup(src->setting);
|
||||
return dst->setting ? 0 : -1;
|
||||
}
|
||||
@@ -1696,13 +1696,13 @@ inline static void neu_msg_exchange(neu_reqresp_head_t *header)
|
||||
{
|
||||
char tmp[NEU_NODE_NAME_LEN] = { 0 };
|
||||
|
||||
strcpy(tmp, header->sender);
|
||||
strncpy(tmp, header->sender, sizeof(tmp) - 1);
|
||||
|
||||
memset(header->sender, 0, sizeof(header->sender));
|
||||
strcpy(header->sender, header->receiver);
|
||||
strncpy(header->sender, header->receiver, sizeof(header->sender) - 1);
|
||||
|
||||
memset(header->receiver, 0, sizeof(header->receiver));
|
||||
strcpy(header->receiver, tmp);
|
||||
strncpy(header->receiver, tmp, sizeof(header->receiver) - 1);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -513,7 +513,7 @@ do {
|
||||
*/
|
||||
#ifdef HASH_DEBUG
|
||||
#include <stdio.h> /* fprintf, stderr */
|
||||
#define HASH_OOPS(...) do { fprintf(stderr, __VA_ARGS__); exit(-1); } while (0)
|
||||
#define HASH_OOPS(...) do { fprintf(stderr, "%s", __VA_ARGS__); exit(-1); } while (0)
|
||||
#define HASH_FSCK(hh,head,where) \
|
||||
do { \
|
||||
struct UT_hash_handle *_thh; \
|
||||
|
||||
+4
-2
@@ -1,9 +1,11 @@
|
||||
{
|
||||
"ip": "0.0.0.0",
|
||||
"ip": "127.0.0.1",
|
||||
"port": 7000,
|
||||
"disable_auth": 0,
|
||||
"syslog_host": "",
|
||||
"syslog_port": 541,
|
||||
"sub_filter_error": 0,
|
||||
"modbus_simulator": { "port":502 }
|
||||
"modbus_simulator": {
|
||||
"port": 502
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ static int send_write_tag_req(neu_plugin_t *plugin, neu_json_write_req_t *req,
|
||||
header.ctx = calloc(1, 48 + strlen(playload) + 1);
|
||||
binary_to_hex(trace_id, 16, header.ctx);
|
||||
binary_to_hex(span_id, 8, header.ctx + 32);
|
||||
strcpy(header.ctx + 48, playload);
|
||||
strncpy(header.ctx + 48, playload, strlen(playload));
|
||||
}
|
||||
|
||||
neu_req_write_tag_t cmd = {
|
||||
@@ -374,7 +374,7 @@ static int send_write_tags_req(neu_plugin_t * plugin,
|
||||
header.ctx = calloc(1, 48 + strlen(playload) + 1);
|
||||
binary_to_hex(trace_id, 16, header.ctx);
|
||||
binary_to_hex(span_id, 8, header.ctx + 32);
|
||||
strcpy(header.ctx + 48, playload);
|
||||
strncpy(header.ctx + 48, playload, strlen(playload));
|
||||
}
|
||||
|
||||
neu_req_write_tags_t cmd = { 0 };
|
||||
@@ -387,7 +387,7 @@ static int send_write_tags_req(neu_plugin_t * plugin,
|
||||
}
|
||||
|
||||
for (int i = 0; i < cmd.n_tag; i++) {
|
||||
strcpy(cmd.tags[i].tag, req->tags[i].tag);
|
||||
strncpy(cmd.tags[i].tag, req->tags[i].tag, NEU_TAG_NAME_LEN - 1);
|
||||
if (0 !=
|
||||
json_value_to_tag_value(&req->tags[i].value, req->tags[i].t,
|
||||
&cmd.tags[i].value)) {
|
||||
|
||||
+55
-30
@@ -39,7 +39,7 @@ static void to_traceparent(uint8_t *trace_id, char *span_id, char *out)
|
||||
size += sprintf(out + size, "%02x", trace_id[i]);
|
||||
}
|
||||
|
||||
sprintf(out + size, "-%s-01", span_id);
|
||||
snprintf(out + size, strlen(span_id) + 5, "-%s-01", span_id);
|
||||
}
|
||||
|
||||
static int tag_values_to_json(UT_array *tags, mqtt_static_vt_t *s_tags,
|
||||
@@ -281,7 +281,7 @@ static inline int send_driver_action(neu_plugin_t * plugin,
|
||||
header.ctx = NULL;
|
||||
|
||||
neu_req_driver_action_t action = { 0 };
|
||||
strncpy(action.driver, req->driver, NEU_NODE_NAME_LEN);
|
||||
strncpy(action.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
action.action = strdup(req->action);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &action)) {
|
||||
@@ -465,7 +465,7 @@ static int send_write_tags_req(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
|
||||
}
|
||||
|
||||
for (int i = 0; i < cmd.n_tag; i++) {
|
||||
strcpy(cmd.tags[i].tag, req->tags[i].tag);
|
||||
strncpy(cmd.tags[i].tag, req->tags[i].tag, NEU_TAG_NAME_LEN - 1);
|
||||
if (0 !=
|
||||
json_value_to_tag_value(&req->tags[i].value, req->tags[i].t,
|
||||
&cmd.tags[i].value)) {
|
||||
@@ -574,6 +574,31 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen(wr->node) >= NEU_NODE_NAME_LEN ||
|
||||
strlen(wr->group) >= NEU_GROUP_NAME_LEN) {
|
||||
plog_error(plugin, "node or group name too long");
|
||||
model__write_request__free_unpacked(wr, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < wr->n_tags; i++) {
|
||||
if (strlen(wr->tags[i]->name) >= NEU_TAG_NAME_LEN) {
|
||||
plog_error(plugin, "tag name too long");
|
||||
model__write_request__free_unpacked(wr, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wr->tags[i]->value->value_case ==
|
||||
MODEL__DATA_ITEM_VALUE__VALUE_STRING_VALUE) {
|
||||
if (strlen(wr->tags[i]->value->string_value) >=
|
||||
NEU_VALUE_SIZE) {
|
||||
plog_error(plugin, "string tag value too long");
|
||||
model__write_request__free_unpacked(wr, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mqtt = calloc(1, sizeof(neu_json_mqtt_t));
|
||||
mqtt->uuid = strdup(wr->uuid);
|
||||
mqtt->payload = NULL;
|
||||
@@ -593,7 +618,7 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
}
|
||||
|
||||
for (int i = 0; i < cmd.n_tag; i++) {
|
||||
strcpy(cmd.tags[i].tag, wr->tags[i]->name);
|
||||
strncpy(cmd.tags[i].tag, wr->tags[i]->name, NEU_TAG_NAME_LEN - 1);
|
||||
switch (wr->tags[i]->value->value_case) {
|
||||
case MODEL__DATA_ITEM_VALUE__VALUE_INT_VALUE:
|
||||
cmd.tags[i].value.type = NEU_TYPE_INT64;
|
||||
@@ -610,8 +635,8 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
break;
|
||||
case MODEL__DATA_ITEM_VALUE__VALUE_STRING_VALUE:
|
||||
cmd.tags[i].value.type = NEU_TYPE_STRING;
|
||||
strcpy(cmd.tags[i].value.value.str,
|
||||
wr->tags[i]->value->string_value);
|
||||
strncpy(cmd.tags[i].value.value.str,
|
||||
wr->tags[i]->value->string_value, NEU_VALUE_SIZE - 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -907,7 +932,7 @@ void handle_driver_action_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
mqtt->tracestate = NULL;
|
||||
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, dar->node);
|
||||
strncpy(cmd.driver, dar->node, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.action = strdup(dar->action);
|
||||
|
||||
model__driver_action_request__free_unpacked(dar, NULL);
|
||||
@@ -930,7 +955,7 @@ void handle_driver_action_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
}
|
||||
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.action = strdup(req->action);
|
||||
neu_json_decode_driver_action_req_free(req);
|
||||
free(json_str);
|
||||
@@ -1768,8 +1793,8 @@ void handle_driver_directory_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
mqtt->tracestate = NULL;
|
||||
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, flr->node);
|
||||
strcpy(cmd.path, flr->path);
|
||||
strncpy(cmd.driver, flr->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.path, flr->path, NEU_PATH_LEN - 1);
|
||||
|
||||
model__file_list_request__free_unpacked(flr, NULL);
|
||||
} else {
|
||||
@@ -1792,8 +1817,8 @@ void handle_driver_directory_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
|
||||
header.ctx = mqtt;
|
||||
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.path, req->path);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.path, req->path, NEU_PATH_LEN - 1);
|
||||
|
||||
neu_json_decode_driver_directory_req_free(req);
|
||||
free(json_str);
|
||||
@@ -1957,8 +1982,8 @@ void handle_driver_fup_open_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
mqtt->tracestate = NULL;
|
||||
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, fur->node);
|
||||
strcpy(cmd.path, fur->path);
|
||||
strncpy(cmd.driver, fur->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.path, fur->path, NEU_PATH_LEN - 1);
|
||||
|
||||
model__file_upload_request__free_unpacked(fur, NULL);
|
||||
} else {
|
||||
@@ -1979,8 +2004,8 @@ void handle_driver_fup_open_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
return;
|
||||
}
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.path, req->path);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.path, req->path, NEU_PATH_LEN - 1);
|
||||
|
||||
neu_json_decode_driver_fup_open_req_free(req);
|
||||
free(json_str);
|
||||
@@ -2084,8 +2109,8 @@ void handle_driver_fup_data_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
|
||||
header.ctx = mqtt;
|
||||
|
||||
strcpy(cmd.driver, fudr->node);
|
||||
strcpy(cmd.path, fudr->path);
|
||||
strncpy(cmd.driver, fudr->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.path, fudr->path, NEU_PATH_LEN - 1);
|
||||
|
||||
model__file_upload_data_request__free_unpacked(fudr, NULL);
|
||||
} else {
|
||||
@@ -2108,8 +2133,8 @@ void handle_driver_fup_data_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
|
||||
header.ctx = mqtt;
|
||||
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.path, req->path);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.path, req->path, NEU_PATH_LEN - 1);
|
||||
|
||||
neu_json_decode_driver_fup_data_req_free(req);
|
||||
free(json_str);
|
||||
@@ -2218,9 +2243,9 @@ void handle_driver_fdown_open_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
mqtt->tracestate = NULL;
|
||||
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, fdr->node);
|
||||
strcpy(cmd.src_path, fdr->src_path);
|
||||
strcpy(cmd.dst_path, fdr->dst_path);
|
||||
strncpy(cmd.driver, fdr->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.src_path, fdr->src_path, NEU_PATH_LEN - 1);
|
||||
strncpy(cmd.dst_path, fdr->dst_path, NEU_PATH_LEN - 1);
|
||||
cmd.size = fdr->size;
|
||||
|
||||
model__file_download_request__free_unpacked(fdr, NULL);
|
||||
@@ -2242,9 +2267,9 @@ void handle_driver_fdown_open_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
return;
|
||||
}
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.src_path, req->src_path);
|
||||
strcpy(cmd.dst_path, req->dst_path);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.src_path, req->src_path, NEU_PATH_LEN - 1);
|
||||
strncpy(cmd.dst_path, req->dst_path, NEU_PATH_LEN - 1);
|
||||
cmd.size = req->size;
|
||||
|
||||
neu_json_decode_driver_fdown_open_req_free(req);
|
||||
@@ -2346,8 +2371,8 @@ void handle_driver_fdown_data_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
mqtt->tracestate = NULL;
|
||||
|
||||
header.ctx = mqtt;
|
||||
strcpy(cmd.driver, fddr->node);
|
||||
strcpy(cmd.src_path, fddr->path);
|
||||
strncpy(cmd.driver, fddr->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.src_path, fddr->path, NEU_PATH_LEN - 1);
|
||||
cmd.more = fddr->more;
|
||||
cmd.len = fddr->data.len;
|
||||
cmd.data = calloc(fddr->data.len, sizeof(uint8_t));
|
||||
@@ -2373,8 +2398,8 @@ void handle_driver_fdown_data_req(neu_mqtt_qos_e qos, const char *topic,
|
||||
}
|
||||
header.ctx = mqtt;
|
||||
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.src_path, req->src_path);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.src_path, req->src_path, NEU_PATH_LEN - 1);
|
||||
cmd.more = req->more;
|
||||
cmd.len = req->len;
|
||||
cmd.data = calloc(req->len, sizeof(uint8_t));
|
||||
|
||||
@@ -24,7 +24,7 @@ static int mqtt_schema_parse(json_t *root, mqtt_schema_vt_t **vts,
|
||||
mqtt_schema_vt_t *vt = &(*vts)[*vts_len - 1];
|
||||
|
||||
memset(vt, 0, sizeof(mqtt_schema_vt_t));
|
||||
strcpy(vt->name, key);
|
||||
strncpy(vt->name, key, sizeof(vt->name) - 1);
|
||||
|
||||
if (strcmp(str_val, "${timestamp}") == 0) {
|
||||
vt->vt = MQTT_SCHEMA_TIMESTAMP;
|
||||
@@ -50,7 +50,7 @@ static int mqtt_schema_parse(json_t *root, mqtt_schema_vt_t **vts,
|
||||
return -1;
|
||||
} else {
|
||||
vt->vt = MQTT_SCHEMA_UD;
|
||||
strcpy(vt->ud, str_val);
|
||||
strncpy(vt->ud, str_val, sizeof(vt->ud) - 1);
|
||||
}
|
||||
}
|
||||
} else if (json_is_object(value)) {
|
||||
@@ -63,7 +63,7 @@ static int mqtt_schema_parse(json_t *root, mqtt_schema_vt_t **vts,
|
||||
mqtt_schema_vt_t *vt = &(*vts)[*vts_len - 1];
|
||||
|
||||
memset(vt, 0, sizeof(mqtt_schema_vt_t));
|
||||
strcpy(vt->name, key);
|
||||
strncpy(vt->name, key, sizeof(vt->name) - 1);
|
||||
|
||||
vt->vt = MQTT_SCHEMA_OBJECT;
|
||||
return mqtt_schema_parse(value, &vt->sub_vts, &vt->n_sub_vts,
|
||||
@@ -338,7 +338,7 @@ int mqtt_static_validate(const char *static_tags, mqtt_static_vt_t **vts,
|
||||
mqtt_static_vt_t *vt = &(*vts)[*vts_len - 1];
|
||||
|
||||
memset(vt, 0, sizeof(mqtt_static_vt_t));
|
||||
strcpy(vt->name, key);
|
||||
strncpy(vt->name, key, sizeof(vt->name) - 1);
|
||||
|
||||
if (json_is_string(value)) {
|
||||
vt->jtype = NEU_JSON_STR;
|
||||
|
||||
@@ -104,8 +104,8 @@ void handle_add_adapter(nng_aio *aio)
|
||||
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_ADD_NODE;
|
||||
strcpy(cmd.node, req->name);
|
||||
strcpy(cmd.plugin, req->plugin);
|
||||
strncpy(cmd.node, req->name, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.plugin, req->plugin, NEU_PLUGIN_NAME_LEN - 1);
|
||||
cmd.setting = req->setting;
|
||||
cmd.tags = req->tags;
|
||||
req->setting = NULL; // moved
|
||||
@@ -146,8 +146,8 @@ static inline int send_node_update_req(nng_aio * aio,
|
||||
}
|
||||
|
||||
neu_req_update_node_t cmd = { 0 };
|
||||
strcpy(cmd.node, req->name);
|
||||
strcpy(cmd.new_name, req->new_name);
|
||||
strncpy(cmd.node, req->name, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.new_name, req->new_name, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
neu_reqresp_head_t header = {
|
||||
.ctx = aio,
|
||||
@@ -190,7 +190,7 @@ void handle_del_adapter(nng_aio *aio)
|
||||
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_DEL_NODE;
|
||||
strcpy(cmd.node, req->name);
|
||||
strncpy(cmd.node, req->name, NEU_NODE_NAME_LEN - 1);
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
@@ -228,16 +228,16 @@ void handle_get_adapter(nng_aio *aio)
|
||||
|
||||
if (neu_http_get_param_str(aio, "plugin", plugin_name,
|
||||
sizeof(plugin_name)) > 0) {
|
||||
strcpy(cmd.plugin, plugin_name);
|
||||
strncpy(cmd.plugin, plugin_name, NEU_PLUGIN_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
if (neu_http_get_param_str(aio, "node", node_name, sizeof(node_name)) > 0) {
|
||||
strcpy(cmd.node, node_name);
|
||||
strncpy(cmd.node, node_name, NEU_NODE_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
if (neu_http_get_param_str(aio, "group", group_name, sizeof(group_name)) >
|
||||
0) {
|
||||
strcpy(cmd.query.q_group_name, group_name);
|
||||
strncpy(cmd.query.q_group_name, group_name, NEU_GROUP_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
uintmax_t query_state = 0;
|
||||
@@ -316,7 +316,7 @@ void handle_set_node_setting(nng_aio *aio)
|
||||
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_NODE_SETTING;
|
||||
strcpy(cmd.node, req->node);
|
||||
strncpy(cmd.node, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.setting = req->setting;
|
||||
req->setting = NULL; // ownership moved
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -350,7 +350,7 @@ void handle_get_node_setting(nng_aio *aio)
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_GET_NODE_SETTING;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
strcpy(cmd.node, node_name);
|
||||
strncpy(cmd.node, node_name, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
@@ -399,7 +399,7 @@ void handle_node_ctl(nng_aio *aio)
|
||||
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_NODE_CTL;
|
||||
strcpy(cmd.node, req->node);
|
||||
strncpy(cmd.node, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.ctl = req->cmd;
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -430,7 +430,7 @@ void handle_get_node_state(nng_aio *aio)
|
||||
header.type = NEU_REQ_GET_NODES_STATE;
|
||||
} else {
|
||||
header.type = NEU_REQ_GET_NODE_STATE;
|
||||
strcpy(cmd.node, node_name);
|
||||
strncpy(cmd.node, node_name, NEU_NODE_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -504,7 +504,8 @@ static int json_to_gdatatags(neu_json_gtag_array_t *gtag_array,
|
||||
}
|
||||
|
||||
for (int i = 0; i < gtag_array->len; i++) {
|
||||
strcpy(gdatatags[i].group, gtag_array->gtags[i].group);
|
||||
strncpy(gdatatags[i].group, gtag_array->gtags[i].group,
|
||||
NEU_GROUP_NAME_LEN - 1);
|
||||
gdatatags[i].n_tag = gtag_array->gtags[i].n_tag;
|
||||
gdatatags[i].interval = gtag_array->gtags[i].interval;
|
||||
gdatatags[i].tags =
|
||||
@@ -704,8 +705,8 @@ void handle_put_node_tag(nng_aio *aio)
|
||||
neu_req_update_node_tag_t cmd = { 0 };
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_UPDATE_NODE_TAG;
|
||||
strcpy(cmd.node, req->name);
|
||||
strcpy(cmd.tags, req->tags);
|
||||
strncpy(cmd.node, req->name, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.tags, req->tags, NEU_NODE_TAGS_LEN - 1);
|
||||
int ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
|
||||
@@ -17,7 +17,7 @@ void handle_cid(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
(void) plugin;
|
||||
|
||||
NEU_PROCESS_HTTP_REQUEST(
|
||||
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_upload_cid_t, neu_json_decode_upload_cid_req, {
|
||||
cid_t cid = { 0 };
|
||||
int parse_re = neu_cid_parse(req->path, &cid);
|
||||
|
||||
@@ -76,8 +76,8 @@ void handle_add_tags(nng_aio *aio)
|
||||
} else {
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_ADD_TAG;
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.n_tag = req->n_tag;
|
||||
cmd.tags = calloc(req->n_tag, sizeof(neu_datatag_t));
|
||||
|
||||
@@ -189,12 +189,13 @@ void handle_add_gtags(nng_aio *aio)
|
||||
if (add_resp.error > 0) {
|
||||
handle_add_tags_resp(aio, &add_resp);
|
||||
} else {
|
||||
strcpy(cmd.driver, req->node);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.n_group = req->n_group;
|
||||
cmd.groups = calloc(req->n_group, sizeof(neu_gdatatag_t));
|
||||
|
||||
for (int i = 0; i < req->n_group; i++) {
|
||||
strcpy(cmd.groups[i].group, req->groups[i].group);
|
||||
strncpy(cmd.groups[i].group, req->groups[i].group,
|
||||
NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.groups[i].n_tag = req->groups[i].n_tag;
|
||||
cmd.groups[i].interval = req->groups[i].interval;
|
||||
cmd.groups[i].tags =
|
||||
@@ -278,7 +279,7 @@ void handle_import_tags(nng_aio *aio)
|
||||
header.type = NEU_REQ_IMPORT_TAGS;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
|
||||
strcpy(cmd.node, req->node);
|
||||
strncpy(cmd.node, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
int ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
@@ -329,8 +330,8 @@ void handle_del_tags(nng_aio *aio)
|
||||
goto error;
|
||||
}
|
||||
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.n_tag = req->n_tags;
|
||||
|
||||
for (int i = 0; i < req->n_tags; i++) {
|
||||
@@ -375,8 +376,8 @@ void handle_update_tags(nng_aio *aio)
|
||||
header.type = NEU_REQ_UPDATE_TAG;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.n_tag = req->n_tag;
|
||||
cmd.tags = calloc(req->n_tag, sizeof(neu_datatag_t));
|
||||
|
||||
@@ -454,10 +455,10 @@ void handle_rename_tag(nng_aio *aio)
|
||||
goto error;
|
||||
}
|
||||
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strcpy(cmd.old_name, req->old_name);
|
||||
strcpy(cmd.new_name, req->new_name);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
strncpy(cmd.old_name, req->old_name, NEU_TAG_NAME_LEN - 1);
|
||||
strncpy(cmd.new_name, req->new_name, NEU_TAG_NAME_LEN - 1);
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
@@ -510,11 +511,11 @@ void handle_get_tags(nng_aio *aio)
|
||||
}
|
||||
|
||||
if (neu_http_get_param_str(aio, "name", tag_name, sizeof(tag_name)) >= 0) {
|
||||
strcpy(cmd.name, tag_name);
|
||||
strncpy(cmd.name, tag_name, NEU_TAG_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
strcpy(cmd.driver, node);
|
||||
strcpy(cmd.group, group);
|
||||
strncpy(cmd.driver, node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, group, NEU_GROUP_NAME_LEN - 1);
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
|
||||
@@ -1093,8 +1093,8 @@ static int get_tags(context_t *ctx, neu_resp_driver_group_info_t *info)
|
||||
};
|
||||
|
||||
neu_req_get_tag_t cmd = { 0 };
|
||||
strcpy(cmd.driver, info->driver);
|
||||
strcpy(cmd.group, info->group);
|
||||
strncpy(cmd.driver, info->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, info->group, NEU_GROUP_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
rv = NEU_ERR_IS_BUSY;
|
||||
@@ -1247,7 +1247,7 @@ static int get_subscriptions(context_t *ctx, neu_resp_node_info_t *info)
|
||||
};
|
||||
|
||||
neu_req_get_subscribe_group_t cmd = { 0 };
|
||||
strcpy(cmd.app, info->node);
|
||||
strncpy(cmd.app, info->node, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
@@ -1331,7 +1331,7 @@ static int get_setting(context_t *ctx, neu_resp_node_info_t *info)
|
||||
};
|
||||
|
||||
neu_req_get_node_setting_t cmd = { 0 };
|
||||
strcpy(cmd.node, info->node);
|
||||
strncpy(cmd.node, info->node, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
@@ -1411,7 +1411,7 @@ static int del_node(context_t *ctx, neu_resp_node_info_t *info)
|
||||
};
|
||||
|
||||
neu_req_del_node_t cmd = { 0 };
|
||||
strcpy(cmd.node, info->node);
|
||||
strncpy(cmd.node, info->node, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
@@ -1431,8 +1431,8 @@ static int add_node(context_t *ctx, neu_json_get_nodes_resp_node_t *req)
|
||||
};
|
||||
|
||||
neu_req_add_node_t cmd = { 0 };
|
||||
strcpy(cmd.node, req->name);
|
||||
strcpy(cmd.plugin, req->plugin);
|
||||
strncpy(cmd.node, req->name, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.plugin, req->plugin, NEU_PLUGIN_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
@@ -1453,8 +1453,8 @@ static int add_group(context_t * ctx,
|
||||
};
|
||||
|
||||
neu_req_add_group_t cmd = { 0 };
|
||||
strcpy(cmd.driver, data->driver);
|
||||
strcpy(cmd.group, data->group);
|
||||
strncpy(cmd.driver, data->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, data->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.interval = data->interval;
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
@@ -1476,8 +1476,8 @@ static int add_tag(context_t *ctx, neu_json_add_tags_req_t *data)
|
||||
};
|
||||
|
||||
neu_req_add_tag_t cmd = { 0 };
|
||||
strcpy(cmd.driver, data->node);
|
||||
strcpy(cmd.group, data->group);
|
||||
strncpy(cmd.driver, data->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, data->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.n_tag = data->n_tag;
|
||||
cmd.tags = calloc(data->n_tag, sizeof(neu_datatag_t));
|
||||
if (NULL == cmd.tags) {
|
||||
@@ -1529,9 +1529,9 @@ static int add_subscription(context_t *ctx, neu_json_subscribe_req_t *data)
|
||||
};
|
||||
|
||||
neu_req_subscribe_t cmd = { 0 };
|
||||
strcpy(cmd.app, data->app);
|
||||
strcpy(cmd.driver, data->driver);
|
||||
strcpy(cmd.group, data->group);
|
||||
strncpy(cmd.app, data->app, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.driver, data->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, data->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.params = data->params; // ownership moved
|
||||
data->params = NULL;
|
||||
|
||||
@@ -1553,7 +1553,7 @@ static int add_setting(context_t *ctx, neu_json_node_setting_req_t *data)
|
||||
};
|
||||
|
||||
neu_req_node_setting_t cmd = { 0 };
|
||||
strcpy(cmd.node, data->node);
|
||||
strncpy(cmd.node, data->node, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.setting = data->setting; // ownership moved
|
||||
data->setting = NULL;
|
||||
|
||||
@@ -1776,7 +1776,7 @@ static int del_app_node(context_t *ctx, neu_json_app_t *app)
|
||||
};
|
||||
|
||||
neu_req_del_node_t cmd = { 0 };
|
||||
strcpy(cmd.node, app->node.name);
|
||||
strncpy(cmd.node, app->node.name, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
@@ -1796,8 +1796,8 @@ static int add_app_node(context_t *ctx, neu_json_app_t *app)
|
||||
};
|
||||
|
||||
neu_req_add_node_t cmd = { 0 };
|
||||
strcpy(cmd.node, app->node.name);
|
||||
strcpy(cmd.plugin, app->node.plugin);
|
||||
strncpy(cmd.node, app->node.name, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.plugin, app->node.plugin, NEU_PLUGIN_NAME_LEN - 1);
|
||||
cmd.setting = app->node.setting;
|
||||
if (app->node.tags != NULL) {
|
||||
cmd.tags = strdup(app->node.tags);
|
||||
@@ -1822,9 +1822,9 @@ static int add_app_tags(context_t *ctx, neu_json_app_t *app)
|
||||
};
|
||||
|
||||
neu_req_update_node_tag_t cmd = { 0 };
|
||||
strcpy(cmd.node, app->node.name);
|
||||
strncpy(cmd.node, app->node.name, NEU_NODE_NAME_LEN - 1);
|
||||
if (app->node.tags != NULL) {
|
||||
strcpy(cmd.tags, app->node.tags);
|
||||
strncpy(cmd.tags, app->node.tags, NEU_TAG_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
@@ -1845,7 +1845,7 @@ static int add_app_setting(context_t *ctx, neu_json_app_t *app)
|
||||
};
|
||||
|
||||
neu_req_node_setting_t cmd = { 0 };
|
||||
strcpy(cmd.node, app->node.name);
|
||||
strncpy(cmd.node, app->node.name, NEU_NODE_NAME_LEN - 1);
|
||||
cmd.setting = app->node.setting;
|
||||
app->node.setting = NULL;
|
||||
|
||||
@@ -1868,9 +1868,9 @@ static int add_app_subscription(context_t *ctx, neu_json_app_t *app,
|
||||
};
|
||||
|
||||
neu_req_subscribe_t cmd = { 0 };
|
||||
strcpy(cmd.app, app->node.name);
|
||||
strcpy(cmd.driver, grp->driver);
|
||||
strcpy(cmd.group, grp->group);
|
||||
strncpy(cmd.app, app->node.name, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.driver, grp->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, grp->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.params = grp->params;
|
||||
cmd.static_tags = grp->static_tags;
|
||||
grp->params = NULL;
|
||||
@@ -1894,7 +1894,7 @@ static int get_default_app_subs(context_t *ctx, neu_json_app_t *app)
|
||||
};
|
||||
|
||||
neu_req_get_subscribe_group_t cmd = { 0 };
|
||||
strcpy(cmd.app, app->node.name);
|
||||
strncpy(cmd.app, app->node.name, NEU_NODE_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
@@ -1923,9 +1923,9 @@ static int get_default_app_subs_resp(context_t * ctx,
|
||||
utarray_foreach(resp->groups, neu_resp_subscribe_info_t *, info)
|
||||
{
|
||||
neu_resp_subscribe_info_t copy = { 0 };
|
||||
strcpy(copy.app, info->app);
|
||||
strcpy(copy.driver, info->driver);
|
||||
strcpy(copy.group, info->group);
|
||||
strncpy(copy.app, info->app, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(copy.driver, info->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(copy.group, info->group, NEU_GROUP_NAME_LEN - 1);
|
||||
utarray_push_back(ctx->default_app_subs, ©);
|
||||
}
|
||||
}
|
||||
@@ -1950,9 +1950,9 @@ static int unsub_app(context_t *ctx, neu_resp_subscribe_info_t *info)
|
||||
};
|
||||
|
||||
neu_req_unsubscribe_t cmd = { 0 };
|
||||
strcpy(cmd.app, info->app);
|
||||
strcpy(cmd.driver, info->driver);
|
||||
strcpy(cmd.group, info->group);
|
||||
strncpy(cmd.app, info->app, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.driver, info->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, info->group, NEU_GROUP_NAME_LEN - 1);
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
return NEU_ERR_IS_BUSY;
|
||||
|
||||
@@ -48,8 +48,8 @@ void handle_add_group_config(nng_aio *aio)
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_ADD_GROUP;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.interval = req->interval;
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
@@ -92,14 +92,14 @@ static inline int send_update_group(nng_aio * aio,
|
||||
} else if (len >= NEU_GROUP_NAME_LEN) {
|
||||
return NEU_ERR_GROUP_NAME_TOO_LONG;
|
||||
}
|
||||
strcpy(cmd.new_name, req->new_name);
|
||||
strncpy(cmd.new_name, req->new_name, NEU_GROUP_NAME_LEN - 1);
|
||||
} else {
|
||||
// if `new_name` is omitted, then keep the node name
|
||||
strcpy(cmd.new_name, req->group);
|
||||
strncpy(cmd.new_name, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.interval = req->set_interval ? req->interval : 0;
|
||||
|
||||
neu_reqresp_head_t header = {
|
||||
@@ -146,8 +146,8 @@ void handle_del_group_config(nng_aio *aio)
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_DEL_GROUP;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
@@ -174,14 +174,14 @@ void handle_get_group_config(nng_aio *aio)
|
||||
NEU_VALIDATE_JWT(aio);
|
||||
|
||||
neu_http_get_param_str(aio, "node", node_name, sizeof(node_name));
|
||||
strcpy(cmd.driver, node_name);
|
||||
strncpy(cmd.driver, node_name, NEU_NODE_NAME_LEN - 1);
|
||||
if (strlen(cmd.driver) == 0) {
|
||||
header.type = NEU_REQ_GET_DRIVER_GROUP;
|
||||
}
|
||||
|
||||
if (neu_http_get_param_str(aio, "group", group_name, sizeof(group_name)) >
|
||||
0) {
|
||||
strcpy(cmd.q_group, group_name);
|
||||
strncpy(cmd.q_group, group_name, NEU_GROUP_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -273,9 +273,9 @@ static inline int send_subscribe(nng_aio *aio, neu_reqresp_type_e type,
|
||||
}
|
||||
|
||||
neu_req_subscribe_t cmd = { 0 };
|
||||
strcpy(cmd.app, req->app);
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.app, req->app, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
cmd.params = req->params; // ownership moved
|
||||
cmd.static_tags = req->static_tags; // ownership moved
|
||||
req->params = NULL;
|
||||
@@ -340,9 +340,9 @@ void handle_grp_unsubscribe(nng_aio *aio)
|
||||
goto error;
|
||||
}
|
||||
|
||||
strcpy(cmd.app, req->app);
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.group, req->group);
|
||||
strncpy(cmd.app, req->app, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
|
||||
@@ -122,12 +122,6 @@ static struct neu_http_handler cors_handler[] = {
|
||||
{
|
||||
.url = "/api/v2/log/level",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/log/list",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/log/file",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/global/config",
|
||||
},
|
||||
@@ -495,18 +489,6 @@ static struct neu_http_handler rest_handlers[] = {
|
||||
.url = "/api/v2/log/global",
|
||||
.value.handler = handle_get_global_log_level,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_GET,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/log/list",
|
||||
.value.handler = handle_log_list,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_GET,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/log/file",
|
||||
.value.handler = handle_log_file,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_GET,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
|
||||
@@ -90,7 +90,8 @@ void handle_log_level(nng_aio *aio)
|
||||
cmd.core = req->core;
|
||||
cmd.log_level = log_level;
|
||||
if (req->node_name != NULL) {
|
||||
strcpy(cmd.node, req->node_name);
|
||||
strncpy(cmd.node, req->node_name,
|
||||
NEU_NODE_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
int ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -194,121 +195,3 @@ void handle_get_global_log_level(nng_aio *aio)
|
||||
|
||||
neu_http_ok(aio, json_response);
|
||||
}
|
||||
|
||||
void handle_log_list(nng_aio *aio)
|
||||
{
|
||||
NEU_VALIDATE_JWT(aio);
|
||||
|
||||
char log_dir[PATH_MAX] = { 0 };
|
||||
getcwd(log_dir, PATH_MAX - 1);
|
||||
strncat(log_dir, "/", sizeof(log_dir) - strlen(log_dir) - 1);
|
||||
strncat(log_dir, LOG_DIR, sizeof(log_dir) - strlen(log_dir) - 1);
|
||||
DIR *dir = opendir(log_dir);
|
||||
if (NULL == dir) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_NOT_EXIST, {
|
||||
neu_http_response(aio, NEU_ERR_FILE_NOT_EXIST, result_error);
|
||||
});
|
||||
}
|
||||
|
||||
UT_icd icd = { sizeof(neu_resp_log_file_t), NULL, NULL, NULL };
|
||||
UT_array *log_files = NULL;
|
||||
utarray_new(log_files, &icd);
|
||||
|
||||
struct dirent *entry = NULL;
|
||||
while (NULL != (entry = readdir(dir))) {
|
||||
if (NULL == strstr(entry->d_name, ".log")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char full_path[PATH_MAX] = { 0 };
|
||||
strncpy(full_path, log_dir, sizeof(full_path) - 1);
|
||||
strncat(full_path, "/", sizeof(full_path) - strlen(full_path) - 1);
|
||||
strncat(full_path, entry->d_name,
|
||||
sizeof(full_path) - strlen(full_path) - 1);
|
||||
struct stat st = { 0 };
|
||||
if (0 != stat(full_path, &st)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
neu_resp_log_file_t log_file = { 0 };
|
||||
strncpy(log_file.file, entry->d_name, sizeof(log_file.file) - 1);
|
||||
log_file.size = st.st_size;
|
||||
utarray_push_back(log_files, &log_file);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
char *result = NULL;
|
||||
neu_json_encode_by_fn(log_files, neu_json_encode_log_list_resp, &result);
|
||||
neu_http_ok(aio, result);
|
||||
free(result);
|
||||
utarray_free(log_files);
|
||||
}
|
||||
|
||||
static int response(nng_aio *aio, char *content, enum nng_http_status status)
|
||||
{
|
||||
nng_http_res *res = NULL;
|
||||
|
||||
nng_http_res_alloc(&res);
|
||||
|
||||
nng_http_res_set_header(res, "Content-Type", "text/plain");
|
||||
nng_http_res_set_header(res, "Access-Control-Allow-Origin", "*");
|
||||
nng_http_res_set_header(res, "Access-Control-Allow-Methods",
|
||||
"POST,GET,PUT,DELETE,OPTIONS");
|
||||
nng_http_res_set_header(res, "Access-Control-Allow-Headers", "*");
|
||||
|
||||
if (content != NULL && strlen(content) > 0) {
|
||||
nng_http_res_copy_data(res, content, strlen(content));
|
||||
}
|
||||
|
||||
nng_http_res_set_status(res, status);
|
||||
|
||||
nng_http_req *nng_req = nng_aio_get_input(aio, 0);
|
||||
nlog_notice("<%p> %s %s [%d]", aio, nng_http_req_get_method(nng_req),
|
||||
nng_http_req_get_uri(nng_req), status);
|
||||
|
||||
nng_aio_set_output(aio, 0, res);
|
||||
nng_aio_finish(aio, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void handle_log_file(nng_aio *aio)
|
||||
{
|
||||
NEU_VALIDATE_JWT(aio);
|
||||
|
||||
char file_name[NEU_NODE_NAME_LEN] = { 0 };
|
||||
if (neu_http_get_param_str(aio, "name", file_name, sizeof(file_name)) <=
|
||||
0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
char path[PATH_MAX] = { 0 };
|
||||
getcwd(path, PATH_MAX - 1);
|
||||
strncat(path, "/", sizeof(path) - strlen(path) - 1);
|
||||
strncat(path, LOG_DIR, sizeof(path) - strlen(path) - 1);
|
||||
|
||||
strncat(path, "/", sizeof(path) - strlen(path) - 1);
|
||||
strncat(path, file_name, sizeof(path) - strlen(path) - 1);
|
||||
|
||||
FILE *file = fopen(path, "r");
|
||||
if (NULL == file) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_NOT_EXIST, {
|
||||
neu_http_response(aio, NEU_ERR_FILE_NOT_EXIST, result_error);
|
||||
});
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long file_size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
char *file_content = (char *) malloc(file_size + 1);
|
||||
fread(file_content, 1, file_size, file);
|
||||
file_content[file_size] = '\0';
|
||||
fclose(file);
|
||||
|
||||
response(aio, file_content, NNG_HTTP_STATUS_OK);
|
||||
free(file_content);
|
||||
}
|
||||
|
||||
@@ -22,11 +22,8 @@
|
||||
|
||||
#include <nng/nng.h>
|
||||
|
||||
// void handle_get_log(nng_aio *aio);
|
||||
void handle_log_level(nng_aio *aio);
|
||||
void handle_global_log_level(nng_aio *aio);
|
||||
void handle_get_global_log_level(nng_aio *aio);
|
||||
void handle_log_list(nng_aio *aio);
|
||||
void handle_log_file(nng_aio *aio);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -114,7 +114,7 @@ void handle_get_user(nng_aio *aio)
|
||||
utarray_foreach(user_infos, neu_persist_user_info_t *, p_info)
|
||||
{
|
||||
neu_json_user_resp_t resp = { 0 };
|
||||
strcpy(resp.name, p_info->name);
|
||||
strncpy(resp.name, p_info->name, NEU_USER_NAME_MAX_LEN);
|
||||
utarray_push_back(user_list, &resp);
|
||||
}
|
||||
utarray_free(user_infos);
|
||||
@@ -547,7 +547,7 @@ void handle_get_plugin_schema(nng_aio *aio)
|
||||
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_CHECK_SCHEMA;
|
||||
strcpy(cmd.schema, schema_name);
|
||||
strncpy(cmd.schema, schema_name, NEU_PLUGIN_NAME_LEN - 1);
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
@@ -809,6 +809,7 @@ done:
|
||||
|
||||
void handle_export_db(nng_aio *aio)
|
||||
{
|
||||
NEU_VALIDATE_JWT(aio);
|
||||
write_csv_header();
|
||||
|
||||
UT_array *nodes = NULL;
|
||||
|
||||
@@ -91,7 +91,7 @@ void handle_del_plugin(nng_aio *aio)
|
||||
header.type = NEU_REQ_DEL_PLUGIN;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
if (strlen(req->plugin) <= sizeof(cmd.plugin)) {
|
||||
strcpy(cmd.plugin, req->plugin);
|
||||
strncpy(cmd.plugin, req->plugin, NEU_PLUGIN_NAME_LEN - 1);
|
||||
int ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
|
||||
+14
-11
@@ -171,10 +171,10 @@ void handle_test_read_tag(nng_aio *aio)
|
||||
goto error;
|
||||
}
|
||||
|
||||
strcpy(cmd.driver, req->driver);
|
||||
strcpy(cmd.group, req->group);
|
||||
strcpy(cmd.tag, req->tag);
|
||||
strcpy(cmd.address, req->address);
|
||||
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN - 1);
|
||||
strncpy(cmd.group, req->group, NEU_GROUP_NAME_LEN - 1);
|
||||
strncpy(cmd.tag, req->tag, NEU_TAG_NAME_LEN - 1);
|
||||
strncpy(cmd.address, req->address, NEU_TAG_ADDRESS_LEN - 1);
|
||||
cmd.attribute = req->attribute;
|
||||
cmd.type = req->type;
|
||||
cmd.precision = req->precision;
|
||||
@@ -316,7 +316,8 @@ void handle_write(nng_aio *aio)
|
||||
break;
|
||||
case NEU_JSON_STR:
|
||||
cmd.value.type = NEU_TYPE_STRING;
|
||||
strcpy(cmd.value.value.str, req->value.val_str);
|
||||
strncpy(cmd.value.value.str, req->value.val_str,
|
||||
NEU_VALUE_SIZE);
|
||||
break;
|
||||
case NEU_JSON_DOUBLE:
|
||||
cmd.value.type = NEU_TYPE_DOUBLE;
|
||||
@@ -522,7 +523,8 @@ void handle_write_tags(nng_aio *aio)
|
||||
req->group = NULL; // ownership moved
|
||||
|
||||
for (int i = 0; i < cmd.n_tag; i++) {
|
||||
strcpy(cmd.tags[i].tag, req->tags[i].tag);
|
||||
strncpy(cmd.tags[i].tag, req->tags[i].tag,
|
||||
NEU_TAG_NAME_LEN - 1);
|
||||
switch (req->tags[i].t) {
|
||||
case NEU_JSON_INT:
|
||||
cmd.tags[i].value.type = NEU_TYPE_INT64;
|
||||
@@ -530,8 +532,8 @@ void handle_write_tags(nng_aio *aio)
|
||||
break;
|
||||
case NEU_JSON_STR:
|
||||
cmd.tags[i].value.type = NEU_TYPE_STRING;
|
||||
strcpy(cmd.tags[i].value.value.str,
|
||||
req->tags[i].value.val_str);
|
||||
strncpy(cmd.tags[i].value.value.str,
|
||||
req->tags[i].value.val_str, NEU_VALUE_SIZE);
|
||||
break;
|
||||
case NEU_JSON_DOUBLE:
|
||||
cmd.tags[i].value.type = NEU_TYPE_DOUBLE;
|
||||
@@ -650,7 +652,8 @@ static void trans(neu_json_write_gtags_req_t *req, neu_req_write_gtags_t *cmd)
|
||||
calloc(cmd->groups[i].n_tag, sizeof(neu_resp_tag_value_t));
|
||||
|
||||
for (int k = 0; k < cmd->groups[i].n_tag; k++) {
|
||||
strcpy(cmd->groups[i].tags[k].tag, req->groups[i].tags[k].tag);
|
||||
strncpy(cmd->groups[i].tags[k].tag, req->groups[i].tags[k].tag,
|
||||
NEU_TAG_NAME_LEN - 1);
|
||||
|
||||
switch (req->groups[i].tags[k].t) {
|
||||
case NEU_JSON_INT:
|
||||
@@ -660,8 +663,8 @@ static void trans(neu_json_write_gtags_req_t *req, neu_req_write_gtags_t *cmd)
|
||||
break;
|
||||
case NEU_JSON_STR:
|
||||
cmd->groups[i].tags[k].value.type = NEU_TYPE_STRING;
|
||||
strcpy(cmd->groups[i].tags[k].value.value.str,
|
||||
req->groups[i].tags[k].value.val_str);
|
||||
strncpy(cmd->groups[i].tags[k].value.value.str,
|
||||
req->groups[i].tags[k].value.val_str, NEU_VALUE_SIZE);
|
||||
break;
|
||||
case NEU_JSON_DOUBLE:
|
||||
cmd->groups[i].tags[k].value.type = NEU_TYPE_DOUBLE;
|
||||
|
||||
@@ -43,15 +43,15 @@ void handle_scan_tags(nng_aio *aio)
|
||||
}
|
||||
|
||||
if (NULL != req->node) {
|
||||
strcpy(cmd.driver, req->node);
|
||||
strncpy(cmd.driver, req->node, NEU_NODE_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
if (NULL != req->id) {
|
||||
strcpy(cmd.id, req->id);
|
||||
strncpy(cmd.id, req->id, NEU_TAG_ADDRESS_LEN - 1);
|
||||
}
|
||||
|
||||
if (NULL != req->ctx) {
|
||||
strcpy(cmd.ctx, req->ctx);
|
||||
strncpy(cmd.ctx, req->ctx, NEU_VALUE_SIZE);
|
||||
}
|
||||
|
||||
cmd.load_index = req->load_index;
|
||||
|
||||
@@ -17,7 +17,7 @@ void handle_tpy(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
(void) plugin;
|
||||
|
||||
NEU_PROCESS_HTTP_REQUEST(
|
||||
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_upload_cid_t, neu_json_decode_upload_cid_req, {
|
||||
tpy_t tpy = { 0 };
|
||||
int parse_re = neu_tpy_parse(req->path, &tpy);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -119,6 +120,9 @@ struct neu_mqtt_client_s {
|
||||
nng_dialer dialer;
|
||||
bool open;
|
||||
bool connected;
|
||||
bool ever_connected;
|
||||
nng_time opened_at_ms;
|
||||
nng_time last_warn_ms;
|
||||
neu_mqtt_client_connection_cb_t connect_cb;
|
||||
void * connect_cb_data;
|
||||
neu_mqtt_client_connection_cb_t disconnect_cb;
|
||||
@@ -619,12 +623,312 @@ static int resub_cb(void *data)
|
||||
log(error, "client_send_sub_msg fail");
|
||||
}
|
||||
}
|
||||
} else if (!client->connected && client->open) {
|
||||
// Watchdog for connection establishment: nng_dialer_start was
|
||||
// called with NNG_FLAG_NONBLOCK, so DNS/TCP/TLS failures are
|
||||
// retried silently. Emit a periodic log so operators can see
|
||||
// that the broker is unreachable instead of guessing.
|
||||
nng_time now = nng_clock();
|
||||
// Grace period before the first warning. Floor at 5s so a
|
||||
// normal remote broker (DNS + TCP + TLS + MQTT handshake) has
|
||||
// enough time to come up without tripping a false alarm; cap
|
||||
// at 30s so a configuration mistake is still surfaced quickly.
|
||||
nng_time grace = (nng_time) client->retry * 3;
|
||||
if (grace < 5000) {
|
||||
grace = 5000;
|
||||
}
|
||||
if (grace > 30000) {
|
||||
grace = 30000;
|
||||
}
|
||||
const nng_time warn_interval = 30000;
|
||||
if (now >= client->opened_at_ms + grace &&
|
||||
(client->last_warn_ms == 0 ||
|
||||
now >= client->last_warn_ms + warn_interval)) {
|
||||
const char *url = client->url ? client->url : "(unset)";
|
||||
if (client->ever_connected) {
|
||||
log(warn, "mqtt client still disconnected from %s, retrying",
|
||||
url);
|
||||
} else {
|
||||
log(error,
|
||||
"mqtt client cannot connect to %s "
|
||||
"(check address/network/credentials/TLS)",
|
||||
url);
|
||||
}
|
||||
client->last_warn_ms = now;
|
||||
}
|
||||
}
|
||||
nng_mtx_unlock(client->mtx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Bridge nng's internal logs (TLS handshake, TCP refused, DNS, ...) into
|
||||
// zlog. nng_log_set_logger is process-global, so we install once and
|
||||
// dispatch each log line back to the right plugin's zlog category by
|
||||
// parsing the "socket<N>" token that nng embeds in its messages. Logs
|
||||
// without a socket id (e.g. generic init/TLS-engine messages) fall back
|
||||
// to a shared "nng" category.
|
||||
#define NEU_MQTT_SOCK_LOG_MAX 64
|
||||
typedef struct {
|
||||
int sock_id;
|
||||
zlog_category_t *cat;
|
||||
} sock_log_entry_t;
|
||||
|
||||
static zlog_category_t *s_nng_log_cat = NULL;
|
||||
static pthread_once_t s_nng_log_once = PTHREAD_ONCE_INIT;
|
||||
static nng_mtx * s_sock_log_mtx = NULL;
|
||||
static sock_log_entry_t s_sock_log_table[NEU_MQTT_SOCK_LOG_MAX];
|
||||
|
||||
static const char *mqtt_reason_code_str(int reason);
|
||||
|
||||
static void sock_log_register(int sock_id, zlog_category_t *cat)
|
||||
{
|
||||
if (sock_id < 0 || NULL == cat || NULL == s_sock_log_mtx) {
|
||||
return;
|
||||
}
|
||||
nng_mtx_lock(s_sock_log_mtx);
|
||||
int free_slot = -1;
|
||||
for (int i = 0; i < NEU_MQTT_SOCK_LOG_MAX; ++i) {
|
||||
if (s_sock_log_table[i].cat != NULL &&
|
||||
s_sock_log_table[i].sock_id == sock_id) {
|
||||
s_sock_log_table[i].cat = cat;
|
||||
nng_mtx_unlock(s_sock_log_mtx);
|
||||
return;
|
||||
}
|
||||
if (free_slot < 0 && s_sock_log_table[i].cat == NULL) {
|
||||
free_slot = i;
|
||||
}
|
||||
}
|
||||
if (free_slot >= 0) {
|
||||
s_sock_log_table[free_slot].sock_id = sock_id;
|
||||
s_sock_log_table[free_slot].cat = cat;
|
||||
}
|
||||
nng_mtx_unlock(s_sock_log_mtx);
|
||||
}
|
||||
|
||||
static void sock_log_unregister(int sock_id)
|
||||
{
|
||||
if (sock_id < 0 || NULL == s_sock_log_mtx) {
|
||||
return;
|
||||
}
|
||||
nng_mtx_lock(s_sock_log_mtx);
|
||||
for (int i = 0; i < NEU_MQTT_SOCK_LOG_MAX; ++i) {
|
||||
if (s_sock_log_table[i].cat != NULL &&
|
||||
s_sock_log_table[i].sock_id == sock_id) {
|
||||
s_sock_log_table[i].cat = NULL;
|
||||
s_sock_log_table[i].sock_id = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
nng_mtx_unlock(s_sock_log_mtx);
|
||||
}
|
||||
|
||||
static zlog_category_t *sock_log_lookup(const char *msg)
|
||||
{
|
||||
if (NULL == msg || NULL == s_sock_log_mtx) {
|
||||
return NULL;
|
||||
}
|
||||
const char *p = strstr(msg, "socket<");
|
||||
if (NULL == p) {
|
||||
return NULL;
|
||||
}
|
||||
p += strlen("socket<");
|
||||
char *end = NULL;
|
||||
long id = strtol(p, &end, 10);
|
||||
if (end == p) {
|
||||
return NULL;
|
||||
}
|
||||
zlog_category_t *cat = NULL;
|
||||
nng_mtx_lock(s_sock_log_mtx);
|
||||
for (int i = 0; i < NEU_MQTT_SOCK_LOG_MAX; ++i) {
|
||||
if (s_sock_log_table[i].cat != NULL &&
|
||||
s_sock_log_table[i].sock_id == (int) id) {
|
||||
cat = s_sock_log_table[i].cat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
nng_mtx_unlock(s_sock_log_mtx);
|
||||
return cat;
|
||||
}
|
||||
|
||||
// NanoSDK's MQTT transport sometimes returns MQTT v5 reason codes (128-162)
|
||||
// directly as nng rv values, which nng_strerror prints as "Unknown error #N".
|
||||
// Rewrite such messages so the actual MQTT meaning is visible in the log.
|
||||
static const char *nng_log_rewrite(const char *msg, char *buf, size_t cap)
|
||||
{
|
||||
if (NULL == msg) {
|
||||
return "";
|
||||
}
|
||||
const char *needle = "Unknown error #";
|
||||
const char *p = strstr(msg, needle);
|
||||
if (NULL == p) {
|
||||
return msg;
|
||||
}
|
||||
const char *num = p + strlen(needle);
|
||||
char * end = NULL;
|
||||
long n = strtol(num, &end, 10);
|
||||
if (end == num) {
|
||||
return msg;
|
||||
}
|
||||
const char *desc = mqtt_reason_code_str((int) n);
|
||||
if (NULL == desc) {
|
||||
return msg;
|
||||
}
|
||||
size_t prefix = (size_t)(p - msg);
|
||||
int rc = snprintf(buf, cap, "%.*s%s (mqtt reason code %ld)%s", (int) prefix,
|
||||
msg, desc, n, end);
|
||||
if (rc < 0 || (size_t) rc >= cap) {
|
||||
return msg;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void nng_log_to_zlog(nng_log_level level, nng_log_facility facility,
|
||||
const char *msgid, const char *msg)
|
||||
{
|
||||
(void) facility;
|
||||
zlog_category_t *cat = sock_log_lookup(msg);
|
||||
if (NULL == cat) {
|
||||
// Generic messages (TLS engine init, etc.) carry no socket id;
|
||||
// park them in the shared "nng" category as a fallback.
|
||||
cat = s_nng_log_cat;
|
||||
}
|
||||
if (NULL == cat) {
|
||||
return;
|
||||
}
|
||||
const char *id = msgid ? msgid : "NNG";
|
||||
char buf[512];
|
||||
const char *m = nng_log_rewrite(msg, buf, sizeof(buf));
|
||||
switch (level) {
|
||||
case NNG_LOG_ERR:
|
||||
zlog_error(cat, "[%s] %s", id, m);
|
||||
break;
|
||||
case NNG_LOG_WARN:
|
||||
zlog_warn(cat, "[%s] %s", id, m);
|
||||
break;
|
||||
case NNG_LOG_NOTICE:
|
||||
zlog_notice(cat, "[%s] %s", id, m);
|
||||
break;
|
||||
case NNG_LOG_INFO:
|
||||
zlog_info(cat, "[%s] %s", id, m);
|
||||
break;
|
||||
case NNG_LOG_DEBUG:
|
||||
zlog_debug(cat, "[%s] %s", id, m);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void nng_log_bridge_init(void)
|
||||
{
|
||||
if (0 != nng_mtx_alloc(&s_sock_log_mtx)) {
|
||||
s_sock_log_mtx = NULL;
|
||||
return;
|
||||
}
|
||||
memset(s_sock_log_table, 0, sizeof(s_sock_log_table));
|
||||
s_nng_log_cat = zlog_get_category("nng");
|
||||
// Surface warnings and errors (TLS/TCP/DNS failures live here); skip
|
||||
// info/debug to keep the log file lean.
|
||||
nng_log_set_level(NNG_LOG_WARN);
|
||||
nng_log_set_logger(nng_log_to_zlog);
|
||||
}
|
||||
|
||||
// Returns a human-readable description for an MQTT v3.1.1 CONNACK return
|
||||
// code or an MQTT v5 reason code. Returns NULL when the value is not a
|
||||
// recognized reason code so callers can fall back to the numeric value.
|
||||
static const char *mqtt_reason_code_str(int reason)
|
||||
{
|
||||
switch (reason) {
|
||||
// MQTT v3.1.1 CONNACK codes (0-5)
|
||||
case 0:
|
||||
return "success";
|
||||
case 1:
|
||||
return "unacceptable protocol version";
|
||||
case 2:
|
||||
return "identifier rejected";
|
||||
case 3:
|
||||
return "server unavailable";
|
||||
case 4:
|
||||
return "bad user name or password";
|
||||
case 5:
|
||||
return "not authorized";
|
||||
// MQTT v5 reason codes (128-162)
|
||||
case 128:
|
||||
return "unspecified error";
|
||||
case 129:
|
||||
return "malformed packet";
|
||||
case 130:
|
||||
return "protocol error";
|
||||
case 131:
|
||||
return "implementation specific error";
|
||||
case 132:
|
||||
return "unsupported protocol version";
|
||||
case 133:
|
||||
return "client identifier not valid";
|
||||
case 134:
|
||||
return "bad user name or password";
|
||||
case 135:
|
||||
return "not authorized";
|
||||
case 136:
|
||||
return "server unavailable";
|
||||
case 137:
|
||||
return "server busy";
|
||||
case 138:
|
||||
return "banned";
|
||||
case 139:
|
||||
return "server shutting down";
|
||||
case 140:
|
||||
return "bad authentication method";
|
||||
case 141:
|
||||
return "keep alive timeout";
|
||||
case 142:
|
||||
return "session taken over";
|
||||
case 143:
|
||||
return "topic filter invalid";
|
||||
case 144:
|
||||
return "topic name invalid";
|
||||
case 145:
|
||||
return "packet identifier in use";
|
||||
case 146:
|
||||
return "packet identifier not found";
|
||||
case 147:
|
||||
return "receive maximum exceeded";
|
||||
case 148:
|
||||
return "topic alias invalid";
|
||||
case 149:
|
||||
return "packet too large";
|
||||
case 150:
|
||||
return "message rate too high";
|
||||
case 151:
|
||||
return "quota exceeded";
|
||||
case 152:
|
||||
return "administrative action";
|
||||
case 153:
|
||||
return "payload format invalid";
|
||||
case 154:
|
||||
return "retain not supported";
|
||||
case 155:
|
||||
return "qos not supported";
|
||||
case 156:
|
||||
return "use another server";
|
||||
case 157:
|
||||
return "server moved";
|
||||
case 158:
|
||||
return "shared subscriptions not supported";
|
||||
case 159:
|
||||
return "connection rate exceeded";
|
||||
case 160:
|
||||
return "maximum connect time";
|
||||
case 161:
|
||||
return "subscription identifiers not supported";
|
||||
case 162:
|
||||
return "wildcard subscriptions not supported";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg)
|
||||
{
|
||||
(void) p;
|
||||
@@ -635,16 +939,26 @@ static void connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg)
|
||||
int reason = 0;
|
||||
|
||||
nng_pipe_get_int(p, NNG_OPT_MQTT_CONNECT_REASON, &reason);
|
||||
log(notice, "mqtt client connected, reason: %d", reason);
|
||||
if (0 == reason) {
|
||||
log(notice, "mqtt client connected to %s",
|
||||
client->url ? client->url : "(unset)");
|
||||
} else {
|
||||
const char *desc = mqtt_reason_code_str(reason);
|
||||
log(error, "mqtt client connect refused by broker %s, reason: %d (%s)",
|
||||
client->url ? client->url : "(unset)", reason,
|
||||
desc ? desc : "unknown");
|
||||
}
|
||||
|
||||
nng_mtx_lock(client->mtx);
|
||||
// start receiving
|
||||
client_start_recv(client);
|
||||
|
||||
// mark as connected
|
||||
client->connected = true;
|
||||
cb = client->connect_cb;
|
||||
data = client->connect_cb_data;
|
||||
client->connected = true;
|
||||
client->ever_connected = true;
|
||||
client->last_warn_ms = 0;
|
||||
cb = client->connect_cb;
|
||||
data = client->connect_cb_data;
|
||||
nng_mtx_unlock(client->mtx);
|
||||
|
||||
if (cb) {
|
||||
@@ -663,7 +977,15 @@ static void disconnect_cb(nng_pipe p, nng_pipe_ev ev, void *arg)
|
||||
int reason = 0;
|
||||
|
||||
nng_pipe_get_int(p, NNG_OPT_MQTT_DISCONNECT_REASON, &reason);
|
||||
log(notice, "mqtt client disconnected, reason: %d", reason);
|
||||
if (0 == reason) {
|
||||
log(notice, "mqtt client disconnected from %s",
|
||||
client->url ? client->url : "(unset)");
|
||||
} else {
|
||||
const char *desc = mqtt_reason_code_str(reason);
|
||||
log(error, "mqtt client disconnected from %s, reason: %d (%s)",
|
||||
client->url ? client->url : "(unset)", reason,
|
||||
desc ? desc : "unknown");
|
||||
}
|
||||
|
||||
nng_mtx_lock(client->mtx);
|
||||
client->connected = false;
|
||||
@@ -1014,6 +1336,8 @@ alloc_sqlite_config(neu_mqtt_client_t *client)
|
||||
|
||||
neu_mqtt_client_t *neu_mqtt_client_new(neu_mqtt_version_e version)
|
||||
{
|
||||
pthread_once(&s_nng_log_once, nng_log_bridge_init);
|
||||
|
||||
neu_mqtt_client_t *client = calloc(1, sizeof(*client));
|
||||
if (NULL == client) {
|
||||
return NULL;
|
||||
@@ -1490,6 +1814,10 @@ int neu_mqtt_client_open(neu_mqtt_client_t *client)
|
||||
}
|
||||
}
|
||||
|
||||
// Route nng's internal logs for this socket back to the plugin's
|
||||
// own zlog category instead of the shared "nng" fallback.
|
||||
sock_log_register(nng_socket_id(client->sock), client->log);
|
||||
|
||||
if (0 != client_make_url(client)) {
|
||||
log(error, "client_make_url fail");
|
||||
goto error;
|
||||
@@ -1544,8 +1872,11 @@ int neu_mqtt_client_open(neu_mqtt_client_t *client)
|
||||
goto error;
|
||||
}
|
||||
|
||||
client->open = true;
|
||||
client->dialer = dialer;
|
||||
client->open = true;
|
||||
client->dialer = dialer;
|
||||
client->ever_connected = false;
|
||||
client->opened_at_ms = nng_clock();
|
||||
client->last_warn_ms = 0;
|
||||
nng_mtx_unlock(client->mtx);
|
||||
|
||||
return 0;
|
||||
@@ -1558,6 +1889,7 @@ error:
|
||||
client->events = NULL;
|
||||
client->timer = NULL;
|
||||
}
|
||||
sock_log_unregister(nng_socket_id(client->sock));
|
||||
nng_close(client->sock);
|
||||
return -1;
|
||||
}
|
||||
@@ -1597,6 +1929,7 @@ int neu_mqtt_client_close(neu_mqtt_client_t *client)
|
||||
// nng_aio_stop(client->recv_aio);
|
||||
|
||||
nng_dialer_close(client->dialer);
|
||||
sock_log_unregister(nng_socket_id(client->sock));
|
||||
rv = nng_close(client->sock);
|
||||
if (0 != rv) {
|
||||
log(error, "nng_close: %s", nng_strerror(rv));
|
||||
|
||||
@@ -126,15 +126,4 @@ class TestLog:
|
||||
response = api.get_nodes_state(node='')
|
||||
assert 200 == response.status_code
|
||||
assert "notice" == response.json()['neuron_core']
|
||||
|
||||
@description(given="neuron started", when="get log list", then="success")
|
||||
def test_get_log_list(self):
|
||||
response = api.get_log_list()
|
||||
assert 200 == response.status_code
|
||||
print(response.json())
|
||||
assert "neuron.log" in [item['file'] for item in response.json()["files"]]
|
||||
|
||||
@description(given="neuron started", when="get log file", then="success")
|
||||
def test_get_log_file(self):
|
||||
response = api.get_log_file(file_name='neuron.log')
|
||||
assert 200 == response.status_code
|
||||
|
||||
@@ -244,7 +244,7 @@ class TestPlugin:
|
||||
assert 200 == response.status_code
|
||||
for plugin in response.json().get("plugins"):
|
||||
if plugin['name'] == 'c1':
|
||||
assert plugin['version'] == '2.14.99'
|
||||
assert plugin['version'] == '2.15.99'
|
||||
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
def test_10_update_plugin_fail3(self):
|
||||
|
||||
@@ -63,7 +63,7 @@ static const neu_plugin_intf_funs_t plugin_intf_funs = {
|
||||
};
|
||||
|
||||
const neu_plugin_module_t neu_plugin_module = {
|
||||
.version = NEU_VERSION(2, 14, 99),
|
||||
.version = NEU_VERSION(2, 15, 99),
|
||||
.schema = "c1",
|
||||
.module_name = "c1",
|
||||
.module_descr = "c1 v2",
|
||||
|
||||
Reference in New Issue
Block a user