mirror of
https://github.com/emqx/neuron.git
synced 2026-10-31 00:19:15 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a277e72ae | ||
|
|
6f41467c49 | ||
|
|
0e168159c2 | ||
|
|
11df6a72ef | ||
|
|
e128820073 | ||
|
|
2d6ea94223 | ||
|
|
52e07f194e | ||
|
|
0ab2ffaae6 | ||
|
|
e468084a86 | ||
|
|
ff54153504 | ||
|
|
a6162b296b | ||
|
|
610283c9e4 | ||
|
|
efe07e6692 | ||
|
|
f017a84154 | ||
|
|
835b7b7fa3 | ||
|
|
beb779601a | ||
|
|
30f8b174ab | ||
|
|
d6aefea13a | ||
|
|
4be55c7fec | ||
|
|
a1e4d2c89b | ||
|
|
e3e00a5ee4 | ||
|
|
635aa06dc6 | ||
|
|
b949f43b4a | ||
|
|
9aa7b8fe04 | ||
|
|
8a54a818ae | ||
|
|
394f500748 | ||
|
|
e75cbf854c | ||
|
|
06334b4820 | ||
|
|
46989e0dee | ||
|
|
327490bfb2 | ||
|
|
3626877155 | ||
|
|
54c58567a2 | ||
|
|
b1ed9a9155 | ||
|
|
c05b409aee | ||
|
|
fc7e4bc7d8 | ||
|
|
096bcd3e36 | ||
|
|
4d7de9bdbc | ||
|
|
c1ef351f85 | ||
|
|
e629b9ce35 | ||
|
|
d05da31690 | ||
|
|
a9768b0b5c | ||
|
|
857c95fd11 | ||
|
|
cbe7179569 | ||
|
|
d238c1efb3 | ||
|
|
cac3ee592e | ||
|
|
7287e4e2bf | ||
|
|
41aef8d30a | ||
|
|
ffbd9b336a | ||
|
|
21656149d8 | ||
|
|
eb647d9692 | ||
|
|
71ead18756 | ||
|
|
a127a69d10 | ||
|
|
40e637303c | ||
|
|
1060eb6508 | ||
|
|
9e5702b15b | ||
|
|
5891dc034c | ||
|
|
071e87ac4f | ||
|
|
0a2c6efd1b | ||
|
|
40c7115405 | ||
|
|
9a10abfe3a | ||
|
|
58529e31f8 | ||
|
|
99f02d2e09 | ||
|
|
6cf84fc4a6 | ||
|
|
a668154424 | ||
|
|
4ddd7e9d01 | ||
|
|
79ef5127f6 | ||
|
|
1bb74163f9 | ||
|
|
cb53a6bd33 | ||
|
|
fe48ac8178 | ||
|
|
f564fbf4b2 | ||
|
|
705f618af5 | ||
|
|
4eb1587b8e |
@@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
# checkout
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
@@ -40,6 +40,18 @@ 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-v2.12
|
||||
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
- published
|
||||
|
||||
env:
|
||||
VERSION: 2.12.2
|
||||
VERSION: 2.12.5
|
||||
UI_VERSION: 2.6.1
|
||||
BRANCH: v2.12
|
||||
|
||||
|
||||
@@ -40,8 +40,13 @@ if(USE_GCOV)
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
|
||||
endif(USE_GCOV)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -g")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=format-truncation")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O0")
|
||||
add_compile_options(-fstack-protector-strong)
|
||||
add_link_options(-fstack-protector-strong)
|
||||
add_link_options(-pie -Wl,-z,relro,-z,now)
|
||||
|
||||
if(NOT DISABLE_ASAN)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||
|
||||
@@ -10,6 +10,5 @@ syslog = "<P>%d(%Y-%m-%dT%T%z) %H neuron[%p]: level=%v msg="[%c] %m" file="%f:%L
|
||||
|
||||
[rules]
|
||||
|
||||
*.* "./logs/%c.log", 25MB * 1 ~ "./logs/%c.#2r.log"; file_format
|
||||
*.* "./logs/%c.log", 50MB * 2 ~ "./logs/%c.#2r.log"; file_format
|
||||
*.* >stdout; stdout_format
|
||||
*.* $remote_syslog,"%V"; syslog
|
||||
|
||||
@@ -86,6 +86,9 @@ typedef struct adapter_callbacks {
|
||||
void (*update_im)(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta);
|
||||
void (*update_im_f_m)(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta);
|
||||
void (*scan_tags_response)(neu_adapter_t *adapter, void *r,
|
||||
neu_resp_scan_tags_t *resp_scan);
|
||||
void (*test_read_tag_response)(neu_adapter_t *adapter, void *r,
|
||||
|
||||
@@ -303,6 +303,7 @@ int neu_conn_tcp_server_wait_msg(neu_conn_t *conn, int fd, void *context,
|
||||
int is_ipv4(const char *ip);
|
||||
int is_ipv6(const char *ip);
|
||||
|
||||
bool neu_conn_is_connected(neu_conn_t *conn);
|
||||
bool neu_conn_is_connected(neu_conn_t *conn);
|
||||
uint16_t neu_conn_udp_act_port(neu_conn_t *conn);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#define NEU_VERSION_MAJOR 2
|
||||
#define NEU_VERSION_MINOR 12
|
||||
#define NEU_VERSION_FIX 2
|
||||
#define NEU_VERSION_FIX 5
|
||||
|
||||
#define NEU_GET_VERSION_MAJOR(V) ((0xffff0000 & V) >> 16)
|
||||
#define NEU_GET_VERSION_MINOR(V) ((0x0000ff00 & V) >> 8)
|
||||
@@ -67,7 +67,7 @@
|
||||
#define NEU_LOG_LEVEL_FATAL "fatal"
|
||||
|
||||
#define NEU_CID_LNCLASS_LEN 12
|
||||
#define NEU_CID_LNTYPE_LEN 32
|
||||
#define NEU_CID_LNTYPE_LEN 40
|
||||
#define NEU_CID_LNPREFIX_LEN 10
|
||||
#define NEU_CID_LNINST_LEN 4
|
||||
#define NEU_CID_LDEVICE_LEN 32
|
||||
@@ -85,7 +85,7 @@
|
||||
#define NEU_CID_DATASET_NAME_LEN 32
|
||||
#define NEU_CID_REPORT_NAME_LEN 32
|
||||
#define NEU_CID_REPORT_ID_LEN 64
|
||||
#define NEU_CID_ID_LEN 32
|
||||
#define NEU_CID_ID_LEN 40
|
||||
#define NEU_CID_REF_TYPE_LEN 32
|
||||
#define NEU_CID_IED_NAME_LEN 32
|
||||
#define NEU_CID_ACCESS_POINT_NAME_LEN 16
|
||||
@@ -93,7 +93,7 @@
|
||||
#define NEU_CID_LEN4 4
|
||||
#define NEU_CID_LEN8 8
|
||||
#define NEU_CID_LEN16 16
|
||||
#define NEU_CID_LEN32 32
|
||||
#define NEU_CID_LEN32 72
|
||||
#define NEU_CID_LEN64 64
|
||||
|
||||
#define CHECK_NODE_NAME_LENGTH_ERR \
|
||||
|
||||
+15
-15
@@ -61,58 +61,58 @@ typedef enum neu_json_type {
|
||||
} neu_json_type_e;
|
||||
|
||||
typedef struct {
|
||||
int8_t *i8s;
|
||||
uint8_t length;
|
||||
int8_t * i8s;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_int8_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t *u8s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_uint8_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t *i16s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_int16_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t *u16s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_uint16_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t *i32s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_int32_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t *u32s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_uint32_t;
|
||||
|
||||
typedef struct {
|
||||
int64_t *i64s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_int64_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t *u64s;
|
||||
uint8_t length;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_uint64_t;
|
||||
|
||||
typedef struct {
|
||||
float * f32s;
|
||||
uint8_t length;
|
||||
float * f32s;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_float_t;
|
||||
|
||||
typedef struct {
|
||||
double *f64s;
|
||||
uint8_t length;
|
||||
double * f64s;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_double_t;
|
||||
|
||||
typedef struct {
|
||||
bool * bools;
|
||||
uint8_t length;
|
||||
bool * bools;
|
||||
uint16_t length;
|
||||
} neu_json_value_array_bool_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -343,6 +343,11 @@ typedef struct {
|
||||
uint8_t precision;
|
||||
} neu_dvalue_t;
|
||||
|
||||
static inline bool neu_dvalue_is_array(const neu_dvalue_t *dvalue)
|
||||
{
|
||||
return dvalue->type >= NEU_TYPE_ARRAY_CHAR;
|
||||
}
|
||||
|
||||
static inline void neu_free_dvalue(neu_dvalue_t *dvalue)
|
||||
{
|
||||
if (dvalue->type > NEU_TYPE_ARRAY_CHAR &&
|
||||
|
||||
@@ -200,6 +200,10 @@ typedef struct {
|
||||
|
||||
cid_basictype_e btypes[NEU_TAG_FORMAT_LENGTH]; // for do-[da]
|
||||
int n_btypes;
|
||||
cid_basictype_e btype;
|
||||
|
||||
bool is_array;
|
||||
uint8_t array_size;
|
||||
} cid_fcda_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -298,6 +302,9 @@ typedef struct {
|
||||
|
||||
cid_basictype_e btype;
|
||||
cid_fc_e fc;
|
||||
|
||||
bool is_array;
|
||||
uint8_t array_size;
|
||||
} cid_tm_do_da_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2023 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
--- fix primary key ---
|
||||
BEGIN;
|
||||
|
||||
DROP TABLE IF EXISTS old_node_cache;
|
||||
ALTER TABLE node_cache RENAME TO old_node_cache;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS node_cache (
|
||||
node_name TEXT PRIMARY KEY,
|
||||
CACHE TEXT NOT NULL,
|
||||
FOREIGN KEY (node_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
INSERT OR REPLACE INTO node_cache SELECT * FROM old_node_cache;
|
||||
|
||||
DROP TABLE old_node_cache;
|
||||
|
||||
COMMIT;
|
||||
@@ -204,7 +204,8 @@ void recv_data_callback(void *arg)
|
||||
body_str = nng_msg_body(msg);
|
||||
body_len = nng_msg_len(msg);
|
||||
|
||||
if (*(uint8_t *) body_str == 0x0A && *(uint8_t *) (body_str + 1) == 0xCE) {
|
||||
if (body_len >= 26 && *(uint8_t *) body_str == 0x0A &&
|
||||
*(uint8_t *) (body_str + 1) == 0xCE) {
|
||||
// trace
|
||||
trace_id = (uint8_t *) (body_str + 2);
|
||||
span_id = (uint8_t *) (body_str + 18);
|
||||
@@ -234,9 +235,22 @@ void recv_data_callback(void *arg)
|
||||
if (req->singular) {
|
||||
rv = send_write_tag_req(plugin, &req->single, json_str, trace_flag,
|
||||
trace_id, span_id);
|
||||
if (rv == 0) {
|
||||
plog_notice(plugin, "write tag %s.%s on node %s", req->single.group,
|
||||
req->single.tag, req->single.node);
|
||||
}
|
||||
} else {
|
||||
rv = send_write_tags_req(plugin, &req->plural, json_str, trace_flag,
|
||||
trace_id, span_id);
|
||||
if (rv == 0) {
|
||||
if (req->plural.n_tag == 0) {
|
||||
plog_warn(plugin, "no tags to write on node %s",
|
||||
req->plural.node);
|
||||
} else {
|
||||
plog_notice(plugin, "write %d tags on node %s",
|
||||
req->plural.n_tag, req->plural.node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 != rv) {
|
||||
@@ -260,7 +274,8 @@ static int json_value_to_tag_value(union neu_json_value *req,
|
||||
break;
|
||||
case NEU_JSON_STR:
|
||||
value->type = NEU_TYPE_STRING;
|
||||
strncpy(value->value.str, req->val_str, sizeof(value->value.str));
|
||||
strncpy(value->value.str, req->val_str, sizeof(value->value.str) - 1);
|
||||
value->value.str[sizeof(value->value.str) - 1] = '\0';
|
||||
break;
|
||||
case NEU_JSON_DOUBLE:
|
||||
value->type = NEU_TYPE_DOUBLE;
|
||||
@@ -314,7 +329,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 = {
|
||||
@@ -361,7 +376,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 };
|
||||
@@ -374,7 +389,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)) {
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
"name_zh": "CA 证书",
|
||||
"description": "CA certificate which signs the server certificate",
|
||||
"description_zh": "签发服务器证书的 CA 证书",
|
||||
"attribute": "optional",
|
||||
"attribute": "required",
|
||||
"type": "file",
|
||||
"condition": {
|
||||
"field": "ssl",
|
||||
|
||||
@@ -84,11 +84,11 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ca, optional
|
||||
// ca, required when ssl enabled
|
||||
ret = neu_parse_param(setting, NULL, 1, ca);
|
||||
if (0 != ret) {
|
||||
plog_notice(plugin, "setting no ca");
|
||||
return 0;
|
||||
plog_error(plugin, "setting no ca, required when ssl enabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != decode_b64_param(plugin, ca)) {
|
||||
@@ -106,7 +106,7 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// key, required if cert enable
|
||||
// key, required if cert is set
|
||||
ret = parse_b64_param(plugin, setting, key);
|
||||
if (0 != ret) {
|
||||
return -1;
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
"name_zh": "根 CA 证书",
|
||||
"description": "AWS IoT data endpoint root CA certificate",
|
||||
"description_zh": "AWS IoT 设备数据终端节点根 CA 证书",
|
||||
"attribute": "optional",
|
||||
"attribute": "required",
|
||||
"type": "file",
|
||||
"condition": {
|
||||
"field": "ssl",
|
||||
|
||||
@@ -106,10 +106,6 @@
|
||||
"description_zh": "签发服务器证书的 CA 证书",
|
||||
"attribute": "required",
|
||||
"type": "file",
|
||||
"condition": {
|
||||
"field": "auth",
|
||||
"value": 1
|
||||
},
|
||||
"valid": {
|
||||
"length": 81960
|
||||
}
|
||||
|
||||
@@ -29,22 +29,10 @@
|
||||
#define AUTH_CERT 1
|
||||
|
||||
static int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
neu_json_elem_t *ca, neu_json_elem_t *cert,
|
||||
neu_json_elem_t *key)
|
||||
neu_json_elem_t *cert, neu_json_elem_t *key)
|
||||
{
|
||||
// ca, required
|
||||
int ret = neu_parse_param(setting, NULL, 1, ca);
|
||||
if (0 != ret) {
|
||||
plog_notice(plugin, "setting no ca");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != decode_b64_param(plugin, ca)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// cert, required
|
||||
ret = neu_parse_param(setting, NULL, 1, cert);
|
||||
int ret = neu_parse_param(setting, NULL, 1, cert);
|
||||
if (0 != ret) {
|
||||
plog_notice(plugin, "setting no cert");
|
||||
return -1;
|
||||
@@ -137,8 +125,18 @@ static int azure_parse_config(neu_plugin_t *plugin, const char *setting,
|
||||
password.v.val_str = strdup("");
|
||||
}
|
||||
|
||||
// ca, required for TLS (SSL is always enabled)
|
||||
ret = neu_parse_param(setting, NULL, 1, &ca);
|
||||
if (0 != ret) {
|
||||
plog_error(plugin, "setting no ca");
|
||||
goto error;
|
||||
}
|
||||
if (0 != decode_b64_param(plugin, &ca)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (AUTH_CERT == auth.v.val_int) {
|
||||
ret = parse_ssl_params(plugin, setting, &ca, &cert, &key);
|
||||
ret = parse_ssl_params(plugin, setting, &cert, &key);
|
||||
if (0 != ret) {
|
||||
plog_error(plugin, "setting certificates fail");
|
||||
goto error;
|
||||
|
||||
@@ -306,7 +306,7 @@
|
||||
"name_zh": "CA 证书",
|
||||
"description": "CA certificate which signs the server certificate",
|
||||
"description_zh": "签发服务器证书的 CA 证书",
|
||||
"attribute": "optional",
|
||||
"attribute": "required",
|
||||
"type": "file",
|
||||
"condition": {
|
||||
"field": "ssl",
|
||||
|
||||
@@ -81,11 +81,11 @@ static int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ca, optional
|
||||
// ca, required when ssl enabled
|
||||
ret = neu_parse_param(setting, NULL, 1, ca);
|
||||
if (0 != ret) {
|
||||
plog_notice(plugin, "setting no ca");
|
||||
return 0;
|
||||
plog_error(plugin, "setting no ca, required when ssl enabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != decode_b64_param(plugin, ca)) {
|
||||
@@ -103,7 +103,7 @@ static int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// key, required if cert enable
|
||||
// key, required if cert is set
|
||||
ret = parse_b64_param(plugin, setting, key);
|
||||
if (0 != ret) {
|
||||
return -1;
|
||||
|
||||
+60
-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,36 @@ 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 (wr->tags[i]->name == NULL || wr->tags[i]->value == NULL) {
|
||||
plog_error(plugin, "write request tag missing name/value");
|
||||
model__write_request__free_unpacked(wr, NULL);
|
||||
return;
|
||||
}
|
||||
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 +623,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 +640,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 +937,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 +960,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 +1798,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 +1822,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 +1987,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 +2009,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 +2114,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 +2138,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 +2248,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 +2272,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 +2376,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 +2403,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));
|
||||
|
||||
@@ -167,6 +167,7 @@ int mqtt_plugin_uninit(neu_plugin_t *plugin)
|
||||
|
||||
mqtt_config_fini(&plugin->config);
|
||||
if (plugin->client) {
|
||||
neu_mqtt_client_remove_cache_db(plugin->client);
|
||||
neu_mqtt_client_close(plugin->client);
|
||||
neu_mqtt_client_free(plugin->client);
|
||||
plugin->client = NULL;
|
||||
@@ -395,6 +396,7 @@ int mqtt_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
}
|
||||
|
||||
if (plugin->client != NULL) {
|
||||
neu_mqtt_client_remove_cache_db(plugin->client);
|
||||
neu_mqtt_client_close(plugin->client);
|
||||
neu_mqtt_client_free(plugin->client);
|
||||
}
|
||||
|
||||
@@ -158,6 +158,9 @@ static struct neu_http_handler cors_handler[] = {
|
||||
{
|
||||
.url = "/api/v2/datalayers/tag",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/export/db",
|
||||
},
|
||||
};
|
||||
|
||||
static struct neu_http_handler rest_handlers[] = {
|
||||
@@ -528,6 +531,12 @@ static struct neu_http_handler rest_handlers[] = {
|
||||
.url = "/api/v2/datalayers/tag",
|
||||
.value.handler = handle_datalayers_get_tag,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_GET,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/export/db",
|
||||
.value.handler = handle_export_db,
|
||||
},
|
||||
};
|
||||
|
||||
void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -35,6 +36,7 @@
|
||||
|
||||
#include "argparse.h"
|
||||
#include "parser/neu_json_login.h"
|
||||
#include "persist/persist_impl.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
|
||||
#include "handle.h"
|
||||
@@ -630,3 +632,297 @@ void handle_status(nng_aio *aio)
|
||||
neu_http_response(aio, 0, result);
|
||||
free(result);
|
||||
}
|
||||
|
||||
int nodes_write_to_csv(const char *filename, UT_array *nodes)
|
||||
{
|
||||
FILE *f = fopen(filename, "a");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
utarray_foreach(nodes, neu_persist_node_info_t *, node)
|
||||
{
|
||||
fprintf(f, "%s,%d,%d,%s\n", node->name, node->type, node->state,
|
||||
node->plugin_name);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int settings_write_to_csv(const char *filename, const char *node_name,
|
||||
const char *settings)
|
||||
{
|
||||
FILE *f = fopen(filename, "a");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(f, "%s,%s\n", node_name, settings);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int groups_write_to_csv(const char *filename, const char *driver_name,
|
||||
UT_array *groups)
|
||||
{
|
||||
FILE *f = fopen(filename, "a");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
utarray_foreach(groups, neu_persist_group_info_t *, group)
|
||||
{
|
||||
fprintf(f, "%s,%s,%d, NULL\n", driver_name, group->name,
|
||||
group->interval);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int subscribes_write_to_csv(const char *filename, const char *app_name,
|
||||
UT_array *subscribers)
|
||||
{
|
||||
FILE *f = fopen(filename, "a");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
utarray_foreach(subscribers, neu_persist_subscription_info_t *, sub)
|
||||
{
|
||||
fprintf(f, "%s,%s,%s,%s,%s\n", app_name, sub->driver_name,
|
||||
sub->group_name, sub->params, sub->static_tags);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tags_write_to_csv(const char *filename, const char *node_name,
|
||||
const char *group_name, UT_array *tags)
|
||||
{
|
||||
FILE *f = fopen(filename, "a");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
utarray_foreach(tags, neu_datatag_t *, tag)
|
||||
{
|
||||
fprintf(f, "%s,%s,%s,%s,%d,%d,%f,%f,%d,%s,%s,NULL\n", node_name,
|
||||
group_name, tag->name, tag->address, tag->attribute,
|
||||
tag->precision, tag->decimal, tag->bias, tag->type,
|
||||
tag->description, tag->format);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_csv_header()
|
||||
{
|
||||
FILE *f = fopen("nodes.csv", "w");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", "nodes.csv");
|
||||
return -1;
|
||||
}
|
||||
fprintf(f, "name,type,state,plugin_name\n");
|
||||
fclose(f);
|
||||
|
||||
f = fopen("settings.csv", "w");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", "settings.csv");
|
||||
return -1;
|
||||
}
|
||||
fprintf(f, "node_name,setting\n");
|
||||
fclose(f);
|
||||
|
||||
f = fopen("groups.csv", "w");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", "groups.csv");
|
||||
return -1;
|
||||
}
|
||||
fprintf(f, "driver_name,name,interval,context\n");
|
||||
fclose(f);
|
||||
|
||||
f = fopen("tags.csv", "w");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", "tags.csv");
|
||||
return -1;
|
||||
}
|
||||
fprintf(f,
|
||||
"driver_name,group_name,name,address,attribute,precision,"
|
||||
"decimal,bias,type,description,format,value\n");
|
||||
fclose(f);
|
||||
|
||||
f = fopen("subscribes.csv", "w");
|
||||
if (NULL == f) {
|
||||
nlog_error("failed to open file:%s", "subscribes.csv");
|
||||
return -1;
|
||||
}
|
||||
fprintf(f, "app_name,driver_name,group_name,params,static_tags\n");
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_file(const char *file_name, void **datap, size_t *lenp)
|
||||
{
|
||||
int rv = 0;
|
||||
FILE * f;
|
||||
struct stat st;
|
||||
size_t len;
|
||||
void * data;
|
||||
|
||||
if (stat(file_name, &st) != 0) {
|
||||
return NEU_ERR_FILE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if ((f = fopen(file_name, "rb")) == NULL) {
|
||||
nlog_error("open fail: %s", file_name);
|
||||
return NEU_ERR_FILE_OPEN_FAILURE;
|
||||
}
|
||||
|
||||
len = st.st_size;
|
||||
if (len > 0) {
|
||||
if ((data = malloc(len)) == NULL) {
|
||||
rv = NEU_ERR_EINTERNAL;
|
||||
goto done;
|
||||
}
|
||||
if (fread(data, 1, len, f) != len) {
|
||||
nlog_error("file read failued, errno = %d", errno);
|
||||
rv = NEU_ERR_FILE_READ_FAILURE;
|
||||
free(data);
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
*datap = data;
|
||||
*lenp = len;
|
||||
done:
|
||||
fclose(f);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
void handle_export_db(nng_aio *aio)
|
||||
{
|
||||
write_csv_header();
|
||||
|
||||
UT_array *nodes = NULL;
|
||||
int rv = neu_persister_load_nodes(&nodes);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_WRITE_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
rv = nodes_write_to_csv("nodes.csv", nodes);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_WRITE_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
utarray_free(nodes);
|
||||
return;
|
||||
}
|
||||
|
||||
utarray_foreach(nodes, neu_persist_node_info_t *, node)
|
||||
{
|
||||
char *settings = NULL;
|
||||
rv = neu_persister_load_node_setting(node->name,
|
||||
(const char **) &settings);
|
||||
if (rv != 0) {
|
||||
continue;
|
||||
}
|
||||
rv = settings_write_to_csv("settings.csv", node->name, settings);
|
||||
free(settings);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_WRITE_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
utarray_free(nodes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
utarray_foreach(nodes, neu_persist_node_info_t *, node)
|
||||
{
|
||||
if (node->type == 2) {
|
||||
UT_array *subscribers = NULL;
|
||||
rv = neu_persister_load_subscriptions(node->name, &subscribers);
|
||||
if (rv != 0) {
|
||||
continue;
|
||||
}
|
||||
rv = subscribes_write_to_csv("subscribes.csv", node->name,
|
||||
subscribers);
|
||||
utarray_free(subscribers);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_WRITE_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
utarray_free(nodes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utarray_foreach(nodes, neu_persist_node_info_t *, node)
|
||||
{
|
||||
UT_array *groups = NULL;
|
||||
rv = neu_persister_load_groups(node->name, &groups);
|
||||
if (rv != 0) {
|
||||
continue;
|
||||
}
|
||||
rv = groups_write_to_csv("groups.csv", node->name, groups);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_WRITE_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
utarray_free(nodes);
|
||||
return;
|
||||
}
|
||||
|
||||
utarray_foreach(groups, neu_persist_group_info_t *, group)
|
||||
{
|
||||
UT_array *tags = NULL;
|
||||
rv = neu_persister_load_tags(node->name, group->name, &tags);
|
||||
if (rv != 0) {
|
||||
continue;
|
||||
}
|
||||
rv = tags_write_to_csv("tags.csv", node->name, group->name, tags);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_WRITE_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
utarray_free(nodes);
|
||||
utarray_free(groups);
|
||||
return;
|
||||
}
|
||||
utarray_free(tags);
|
||||
}
|
||||
utarray_free(groups);
|
||||
}
|
||||
|
||||
utarray_free(nodes);
|
||||
|
||||
system("rm -rf /tmp/neuron.zip");
|
||||
system("zip /tmp/neuron.zip nodes.csv settings.csv groups.csv tags.csv "
|
||||
"subscribes.csv");
|
||||
|
||||
void * data = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
rv = read_file("/tmp/neuron.zip", &data, &len);
|
||||
if (rv != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_READ_FAILURE, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
neu_http_response_file(aio, data, len,
|
||||
"attachment; filename=\"neuron.zip\"");
|
||||
free(data);
|
||||
}
|
||||
|
||||
@@ -36,4 +36,6 @@ void handle_add_user(nng_aio *aio);
|
||||
void handle_update_user(nng_aio *aio);
|
||||
void handle_delete_user(nng_aio *aio);
|
||||
|
||||
void handle_export_db(nng_aio *aio);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@ void handle_add_plugin(nng_aio *aio)
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_ADD_PLUGIN;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
strncpy(cmd.library, req->library, NEU_PLUGIN_LIBRARY_LEN);
|
||||
strncpy(cmd.library, req->library, NEU_PLUGIN_LIBRARY_LEN - 1);
|
||||
cmd.schema_file = req->schema_file;
|
||||
cmd.so_file = req->so_file;
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -66,7 +66,7 @@ void handle_update_plugin(nng_aio *aio)
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_UPDATE_PLUGIN;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
strncpy(cmd.library, req->library, NEU_PLUGIN_LIBRARY_LEN);
|
||||
strncpy(cmd.library, req->library, NEU_PLUGIN_LIBRARY_LEN - 1);
|
||||
cmd.schema_file = req->schema_file;
|
||||
cmd.so_file = req->so_file;
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
|
||||
+110
-15
@@ -71,8 +71,8 @@ inline static tkey_t to_key(const char *group, const char *tag)
|
||||
{
|
||||
tkey_t key = { 0 };
|
||||
|
||||
strcpy(key.group, group);
|
||||
strcpy(key.tag, tag);
|
||||
strncpy(key.group, group, sizeof(key.group) - 1);
|
||||
strncpy(key.tag, tag, sizeof(key.tag) - 1);
|
||||
|
||||
return key;
|
||||
}
|
||||
@@ -160,8 +160,8 @@ void neu_driver_cache_add(neu_driver_cache_t *cache, const char *group,
|
||||
if (elem == NULL) {
|
||||
elem = calloc(1, sizeof(struct elem));
|
||||
|
||||
strcpy(elem->key.group, group);
|
||||
strcpy(elem->key.tag, tag);
|
||||
snprintf(elem->key.group, sizeof(elem->key.group), "%s", group);
|
||||
snprintf(elem->key.tag, sizeof(elem->key.tag), "%s", tag);
|
||||
|
||||
HASH_ADD(hh, cache->table, key, sizeof(tkey_t), elem);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ void neu_driver_cache_update_trace(neu_driver_cache_t *cache, const char *group,
|
||||
group_trace_t *elem = NULL;
|
||||
char key[NEU_GROUP_NAME_LEN] = { 0 };
|
||||
|
||||
strcpy(key, group);
|
||||
snprintf(key, sizeof(key), "%s", group);
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
HASH_FIND(hh, cache->trace_table, &key, sizeof(key), elem);
|
||||
@@ -187,7 +187,7 @@ void neu_driver_cache_update_trace(neu_driver_cache_t *cache, const char *group,
|
||||
if (elem == NULL) {
|
||||
elem = calloc(1, sizeof(group_trace_t));
|
||||
|
||||
strcpy(elem->key, group);
|
||||
snprintf(elem->key, sizeof(elem->key), "%s", group);
|
||||
elem->trace_ctx = trace_ctx;
|
||||
|
||||
HASH_ADD(hh, cache->trace_table, key, sizeof(key), elem);
|
||||
@@ -205,7 +205,7 @@ void *neu_driver_cache_get_trace(neu_driver_cache_t *cache, const char *group)
|
||||
|
||||
void *trace = NULL;
|
||||
|
||||
strcpy(key, group);
|
||||
snprintf(key, sizeof(key), "%s", group);
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
HASH_FIND(hh, cache->trace_table, &key, sizeof(key), elem);
|
||||
@@ -219,14 +219,15 @@ void *neu_driver_cache_get_trace(neu_driver_cache_t *cache, const char *group)
|
||||
return trace;
|
||||
}
|
||||
|
||||
void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
bool neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
const char *group, const char *tag,
|
||||
int64_t timestamp, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta,
|
||||
bool change)
|
||||
{
|
||||
struct elem *elem = NULL;
|
||||
tkey_t key = to_key(group, tag);
|
||||
struct elem *elem = NULL;
|
||||
tkey_t key = to_key(group, tag);
|
||||
bool tag_changed = false;
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
HASH_FIND(hh, cache->table, &key, sizeof(tkey_t), elem);
|
||||
@@ -241,6 +242,7 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
(sub_filter_err && elem->value.type != value.type &&
|
||||
elem->value.type != NEU_TYPE_ERROR)) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else if (sub_filter_err && elem->value.type != value.type &&
|
||||
elem->value.type == NEU_TYPE_ERROR) {
|
||||
switch (value.type) {
|
||||
@@ -264,17 +266,20 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (memcmp(&elem->value_old.value, &value.value,
|
||||
sizeof(value.value)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_BYTES:
|
||||
if (elem->value_old.value.bytes.length !=
|
||||
value.value.bytes.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcpy(elem->value_old.value.bytes.bytes,
|
||||
if (memcmp(elem->value_old.value.bytes.bytes,
|
||||
value.value.bytes.bytes,
|
||||
value.value.bytes.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -282,11 +287,13 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.bools.length !=
|
||||
value.value.bools.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.bools.bools,
|
||||
value.value.bools.bools,
|
||||
value.value.bools.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -294,11 +301,13 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.i8s.length !=
|
||||
value.value.i8s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.i8s.i8s,
|
||||
value.value.i8s.i8s,
|
||||
value.value.i8s.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -306,11 +315,13 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.u8s.length !=
|
||||
value.value.u8s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.u8s.u8s,
|
||||
value.value.u8s.u8s,
|
||||
value.value.u8s.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -318,12 +329,14 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.i16s.length !=
|
||||
value.value.i16s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.i16s.i16s,
|
||||
value.value.i16s.i16s,
|
||||
value.value.i16s.length * sizeof(int16_t)) !=
|
||||
0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -331,12 +344,14 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.u16s.length !=
|
||||
value.value.u16s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.u16s.u16s,
|
||||
value.value.u16s.u16s,
|
||||
value.value.u16s.length * sizeof(uint16_t)) !=
|
||||
0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -344,12 +359,14 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.i32s.length !=
|
||||
value.value.i32s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.i32s.i32s,
|
||||
value.value.i32s.i32s,
|
||||
value.value.i32s.length * sizeof(int32_t)) !=
|
||||
0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -357,12 +374,14 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.u32s.length !=
|
||||
value.value.u32s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.u32s.u32s,
|
||||
value.value.u32s.u32s,
|
||||
value.value.u32s.length * sizeof(uint32_t)) !=
|
||||
0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -370,12 +389,14 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.i64s.length !=
|
||||
value.value.i64s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.i64s.i64s,
|
||||
value.value.i64s.i64s,
|
||||
value.value.i64s.length * sizeof(int64_t)) !=
|
||||
0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -383,12 +404,14 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.u64s.length !=
|
||||
value.value.u64s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.u64s.u64s,
|
||||
value.value.u64s.u64s,
|
||||
value.value.u64s.length * sizeof(uint64_t)) !=
|
||||
0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -396,11 +419,13 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.f32s.length !=
|
||||
value.value.f32s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.f32s.f32s,
|
||||
value.value.f32s.f32s,
|
||||
value.value.f32s.length * sizeof(float)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -408,11 +433,13 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.f64s.length !=
|
||||
value.value.f64s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.f64s.f64s,
|
||||
value.value.f64s.f64s,
|
||||
value.value.f64s.length * sizeof(double)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -420,18 +447,21 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.strs.length !=
|
||||
value.value.strs.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.strs.strs,
|
||||
value.value.strs.strs,
|
||||
value.value.strs.length * sizeof(char *)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_CUSTOM: {
|
||||
if (json_equal(elem->value_old.value.json, value.value.json) !=
|
||||
0) {
|
||||
1) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -439,11 +469,13 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.value.ptr.length !=
|
||||
value.value.ptr.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value_old.value.ptr.ptr,
|
||||
value.value.ptr.ptr,
|
||||
value.value.ptr.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,10 +485,12 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.precision == 0) {
|
||||
elem->changed =
|
||||
elem->value_old.value.f32 != value.value.f32;
|
||||
tag_changed = elem->changed;
|
||||
} else {
|
||||
if (fabs(elem->value_old.value.f32 - value.value.f32) >
|
||||
pow(0.1, elem->value_old.precision)) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -464,10 +498,12 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value_old.precision == 0) {
|
||||
elem->changed =
|
||||
elem->value_old.value.d64 != value.value.d64;
|
||||
tag_changed = elem->changed;
|
||||
} else {
|
||||
if (fabs(elem->value_old.value.d64 - value.value.d64) >
|
||||
pow(0.1, elem->value_old.precision)) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,17 +533,20 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (memcmp(&elem->value.value, &value.value,
|
||||
sizeof(value.value)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_BYTES:
|
||||
if (elem->value.value.bytes.length !=
|
||||
value.value.bytes.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcpy(elem->value.value.bytes.bytes,
|
||||
if (memcmp(elem->value.value.bytes.bytes,
|
||||
value.value.bytes.bytes,
|
||||
value.value.bytes.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -515,174 +554,206 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
if (elem->value.value.bools.length !=
|
||||
value.value.bools.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.bools.bools,
|
||||
value.value.bools.bools,
|
||||
value.value.bools.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_INT8:
|
||||
if (elem->value.value.i8s.length != value.value.i8s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.i8s.i8s, value.value.i8s.i8s,
|
||||
value.value.i8s.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_UINT8:
|
||||
if (elem->value.value.u8s.length != value.value.u8s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.u8s.u8s, value.value.u8s.u8s,
|
||||
value.value.u8s.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_INT16:
|
||||
if (elem->value.value.i16s.length != value.value.i16s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(
|
||||
elem->value.value.i16s.i16s, value.value.i16s.i16s,
|
||||
value.value.i16s.length * sizeof(int16_t)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_UINT16:
|
||||
if (elem->value.value.u16s.length != value.value.u16s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(
|
||||
elem->value.value.u16s.u16s, value.value.u16s.u16s,
|
||||
value.value.u16s.length * sizeof(uint16_t)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_INT32:
|
||||
if (elem->value.value.i32s.length != value.value.i32s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(
|
||||
elem->value.value.i32s.i32s, value.value.i32s.i32s,
|
||||
value.value.i32s.length * sizeof(int32_t)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_UINT32:
|
||||
if (elem->value.value.u32s.length != value.value.u32s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(
|
||||
elem->value.value.u32s.u32s, value.value.u32s.u32s,
|
||||
value.value.u32s.length * sizeof(uint32_t)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_INT64:
|
||||
if (elem->value.value.i64s.length != value.value.i64s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(
|
||||
elem->value.value.i64s.i64s, value.value.i64s.i64s,
|
||||
value.value.i64s.length * sizeof(int64_t)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_UINT64:
|
||||
if (elem->value.value.u64s.length != value.value.u64s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(
|
||||
elem->value.value.u64s.u64s, value.value.u64s.u64s,
|
||||
value.value.u64s.length * sizeof(uint64_t)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_FLOAT:
|
||||
if (elem->value.value.f32s.length != value.value.f32s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.f32s.f32s,
|
||||
value.value.f32s.f32s,
|
||||
value.value.f32s.length * sizeof(float)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_DOUBLE:
|
||||
if (elem->value.value.f64s.length != value.value.f64s.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.f64s.f64s,
|
||||
value.value.f64s.f64s,
|
||||
value.value.f64s.length * sizeof(double)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_ARRAY_STRING:
|
||||
if (elem->value.value.strs.length != value.value.strs.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.strs.strs,
|
||||
value.value.strs.strs,
|
||||
value.value.strs.length * sizeof(char *)) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_PTR: {
|
||||
if (elem->value.value.ptr.length != value.value.ptr.length) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
} else {
|
||||
if (memcmp(elem->value.value.ptr.ptr, value.value.ptr.ptr,
|
||||
value.value.ptr.length) != 0) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NEU_TYPE_CUSTOM: {
|
||||
if (json_equal(elem->value.value.json, value.value.json) != 0) {
|
||||
if (json_equal(elem->value.value.json, value.value.json) != 1) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_TYPE_FLOAT:
|
||||
if (elem->value.precision == 0) {
|
||||
elem->changed = elem->value.value.f32 != value.value.f32;
|
||||
tag_changed = elem->changed;
|
||||
} else {
|
||||
if (fabs(elem->value.value.f32 - value.value.f32) >
|
||||
pow(0.1, elem->value.precision)) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NEU_TYPE_DOUBLE:
|
||||
if (elem->value.precision == 0) {
|
||||
elem->changed = elem->value.value.d64 != value.value.d64;
|
||||
tag_changed = elem->changed;
|
||||
} else {
|
||||
if (fabs(elem->value.value.d64 - value.value.d64) >
|
||||
pow(0.1, elem->value.precision)) {
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case NEU_TYPE_ERROR:
|
||||
elem->changed = true;
|
||||
tag_changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -778,7 +849,12 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
}
|
||||
elem->metas = calloc(n_meta, sizeof(neu_tag_meta_t));
|
||||
for (int i = 0; i < n_meta; i++) {
|
||||
memcpy(&elem->metas[i], &metas[i], sizeof(neu_tag_meta_t));
|
||||
if (!neu_dvalue_is_array(&metas[i].value)) {
|
||||
memcpy(&elem->metas[i], &metas[i], sizeof(neu_tag_meta_t));
|
||||
} else {
|
||||
neu_free_dvalue(&metas[i].value);
|
||||
elem->metas[i].value.type = NEU_TYPE_INT8;
|
||||
}
|
||||
}
|
||||
|
||||
elem->n_meta = n_meta;
|
||||
@@ -786,6 +862,7 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
return tag_changed;
|
||||
}
|
||||
|
||||
void neu_driver_cache_update(neu_driver_cache_t *cache, const char *group,
|
||||
@@ -1189,3 +1266,21 @@ void neu_driver_cache_del(neu_driver_cache_t *cache, const char *group,
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
}
|
||||
|
||||
void neu_driver_cache_rename(neu_driver_cache_t *cache, const char *group,
|
||||
const char *old_tag, const char *new_tag)
|
||||
{
|
||||
struct elem *elem = NULL;
|
||||
tkey_t key = to_key(group, old_tag);
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
HASH_FIND(hh, cache->table, &key, sizeof(tkey_t), elem);
|
||||
|
||||
if (elem != NULL) {
|
||||
HASH_DEL(cache->table, elem);
|
||||
elem->key = to_key(group, new_tag);
|
||||
HASH_ADD(hh, cache->table, key, sizeof(tkey_t), elem);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ void neu_driver_cache_update(neu_driver_cache_t *cache, const char *group,
|
||||
const char *tag, int64_t timestamp,
|
||||
neu_dvalue_t value, neu_tag_meta_t *metas,
|
||||
int n_meta);
|
||||
void neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
bool neu_driver_cache_update_change(neu_driver_cache_t *cache,
|
||||
const char *group, const char *tag,
|
||||
int64_t timestamp, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta,
|
||||
|
||||
+267
-11
@@ -113,6 +113,9 @@ static void update(neu_adapter_t *adapter, const char *group, const char *tag,
|
||||
static void update_im(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta);
|
||||
static void update_im_f_m(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta);
|
||||
static void update_with_meta(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta);
|
||||
@@ -175,7 +178,8 @@ static void write_responses(neu_adapter_t *adapter, void *r,
|
||||
neu_driver_write_responses_t *response,
|
||||
int n_response)
|
||||
{
|
||||
neu_reqresp_head_t * req = (neu_reqresp_head_t *) r;
|
||||
neu_reqresp_head_t *req = (neu_reqresp_head_t *) r;
|
||||
const char *iface = (req->sender[0] != '\0') ? req->sender : "unknown";
|
||||
neu_resp_write_tags_t nresp = { 0 };
|
||||
req->type = NEU_RESP_WRITE_TAGS;
|
||||
UT_icd icd = { sizeof(neu_resp_write_tags_ele_t), NULL, NULL, NULL };
|
||||
@@ -190,8 +194,18 @@ static void write_responses(neu_adapter_t *adapter, void *r,
|
||||
strcpy(ele.group, resp->group);
|
||||
strcpy(ele.tag, resp->name);
|
||||
ele.error = resp->error;
|
||||
|
||||
nlog_notice(
|
||||
"driver multi write response detail, driver: %s, interface: "
|
||||
"%s, group: %s, tag: %s, error: %d",
|
||||
adapter->name, iface, resp->group, resp->name, resp->error);
|
||||
|
||||
utarray_push_back(array, &ele);
|
||||
}
|
||||
nlog_notice(
|
||||
"driver multi write response summary, driver: %s, interface: %s, "
|
||||
"result_count: %d",
|
||||
adapter->name, iface, n_response);
|
||||
|
||||
nresp.tags = array;
|
||||
adapter->cb_funs.response(adapter, req, &nresp);
|
||||
@@ -199,8 +213,10 @@ static void write_responses(neu_adapter_t *adapter, void *r,
|
||||
|
||||
static void write_response(neu_adapter_t *adapter, void *r, neu_error error)
|
||||
{
|
||||
neu_reqresp_head_t *req = (neu_reqresp_head_t *) r;
|
||||
neu_resp_error_t nerror = { .error = error };
|
||||
neu_reqresp_head_t *req = (neu_reqresp_head_t *) r;
|
||||
neu_reqresp_type_e req_type = req->type;
|
||||
const char * iface = (req->sender[0] != '\0') ? req->sender : "unknown";
|
||||
neu_resp_error_t nerror = { .error = error };
|
||||
|
||||
neu_otel_trace_ctx trace = NULL;
|
||||
neu_otel_scope_ctx scope = NULL;
|
||||
@@ -221,18 +237,55 @@ static void write_response(neu_adapter_t *adapter, void *r, neu_error error)
|
||||
}
|
||||
}
|
||||
|
||||
if (NEU_REQ_WRITE_TAG == req->type) {
|
||||
neu_req_write_tag_fini((neu_req_write_tag_t *) &req[1]);
|
||||
if (NEU_REQ_WRITE_TAG == req_type) {
|
||||
neu_req_write_tag_t *cmd = (neu_req_write_tag_t *) &req[1];
|
||||
const char * group = cmd->group ? cmd->group : "";
|
||||
const char * tag = cmd->tag ? cmd->tag : "";
|
||||
nlog_notice("driver single write response, driver: %s, interface: %s, "
|
||||
"group: %s, tag: %s, %s, error: %d",
|
||||
adapter->name, iface, group, tag,
|
||||
neu_value_str(cmd->value.type, cmd->value.value), error);
|
||||
neu_req_write_tag_fini(cmd);
|
||||
if (neu_otel_control_is_started() && trace) {
|
||||
neu_otel_scope_set_span_name(scope, "driver write tag response");
|
||||
}
|
||||
} else if (NEU_REQ_WRITE_TAGS == req->type) {
|
||||
neu_req_write_tags_fini((neu_req_write_tags_t *) &req[1]);
|
||||
} else if (NEU_REQ_WRITE_TAGS == req_type) {
|
||||
neu_req_write_tags_t *cmd = (neu_req_write_tags_t *) &req[1];
|
||||
const char * group = cmd->group ? cmd->group : "";
|
||||
nlog_notice("driver multi write response, driver: %s, interface: %s, "
|
||||
"group: %s, tag_count: %d, error: %d",
|
||||
adapter->name, iface, group, cmd->n_tag, error);
|
||||
for (int i = 0; i < cmd->n_tag; i++) {
|
||||
const char *tag_name = cmd->tags[i].tag;
|
||||
nlog_notice("driver multi write response tag detail, driver: %s, "
|
||||
"group: %s, tag: %s, %s",
|
||||
adapter->name, group, tag_name ? tag_name : "",
|
||||
neu_value_str(cmd->tags[i].value.type,
|
||||
cmd->tags[i].value.value));
|
||||
}
|
||||
neu_req_write_tags_fini(cmd);
|
||||
if (neu_otel_control_is_started() && trace) {
|
||||
neu_otel_scope_set_span_name(scope, "driver write tags response");
|
||||
}
|
||||
} else if (NEU_REQ_WRITE_GTAGS == req->type) {
|
||||
neu_req_write_gtags_fini((neu_req_write_gtags_t *) &req[1]);
|
||||
} else if (NEU_REQ_WRITE_GTAGS == req_type) {
|
||||
neu_req_write_gtags_t *cmd = (neu_req_write_gtags_t *) &req[1];
|
||||
nlog_notice("driver multi write response, driver: %s, interface: %s, "
|
||||
"group_count: %d, error: %d",
|
||||
adapter->name, iface, cmd->n_group, error);
|
||||
for (int i = 0; i < cmd->n_group; i++) {
|
||||
const char *group_name =
|
||||
cmd->groups[i].group ? cmd->groups[i].group : "";
|
||||
for (int k = 0; k < cmd->groups[i].n_tag; k++) {
|
||||
const char *tag_name = cmd->groups[i].tags[k].tag;
|
||||
nlog_notice(
|
||||
"driver multi write response tag detail, driver: %s, "
|
||||
"group: %s, tag: %s, %s",
|
||||
adapter->name, group_name, tag_name ? tag_name : "",
|
||||
neu_value_str(cmd->groups[i].tags[k].value.type,
|
||||
cmd->groups[i].tags[k].value.value));
|
||||
}
|
||||
}
|
||||
neu_req_write_gtags_fini(cmd);
|
||||
if (neu_otel_control_is_started() && trace) {
|
||||
neu_otel_scope_set_span_name(scope, "driver write gtags response");
|
||||
}
|
||||
@@ -389,6 +442,107 @@ static void update_with_trace(neu_adapter_t *adapter, const char *group,
|
||||
}
|
||||
}
|
||||
|
||||
static void update_im_f_m(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta)
|
||||
{
|
||||
neu_adapter_driver_t *driver = (neu_adapter_driver_t *) adapter;
|
||||
|
||||
if (tag == NULL) {
|
||||
nlog_warn("update_im_f_m tag is null");
|
||||
return;
|
||||
}
|
||||
|
||||
group_t *find = NULL;
|
||||
|
||||
HASH_FIND_STR(driver->groups, group, find);
|
||||
if (find == NULL) {
|
||||
nlog_error(
|
||||
"update_im_f_m group not found, driver: %s, group: %s, tag: %s",
|
||||
driver->adapter.name, group, tag);
|
||||
return;
|
||||
}
|
||||
|
||||
bool changed = neu_driver_cache_update_change(driver->cache, group, tag,
|
||||
global_timestamp, value,
|
||||
metas, n_meta, false);
|
||||
driver->adapter.cb_funs.update_metric(&driver->adapter,
|
||||
NEU_METRIC_TAG_READS_TOTAL, 1, NULL);
|
||||
if (value.type == NEU_TYPE_ERROR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
return;
|
||||
}
|
||||
|
||||
UT_array *tags = neu_adapter_driver_get_ptag(driver, group, tag);
|
||||
if (tags == NULL) {
|
||||
return;
|
||||
}
|
||||
neu_datatag_t *first = utarray_front(tags);
|
||||
|
||||
if (first == NULL) {
|
||||
utarray_free(tags);
|
||||
nlog_debug("update immediately, driver: %s, "
|
||||
"group: %s, tag: %s, type: %s, "
|
||||
"timestamp: %" PRId64,
|
||||
driver->adapter.name, group, tag,
|
||||
neu_type_string(value.type), global_timestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
nlog_debug("update and report immediately, driver: %s, "
|
||||
"group: %s, tag: %s, type: %s, "
|
||||
"timestamp: %" PRId64,
|
||||
driver->adapter.name, group, tag, neu_type_string(value.type),
|
||||
global_timestamp);
|
||||
|
||||
neu_reqresp_head_t header = {
|
||||
.type = NEU_REQRESP_TRANS_DATA,
|
||||
};
|
||||
neu_reqresp_trans_data_t *data =
|
||||
calloc(1, sizeof(neu_reqresp_trans_data_t));
|
||||
|
||||
data->driver = strdup(driver->adapter.name);
|
||||
data->group = strdup(group);
|
||||
utarray_new(data->tags, neu_resp_tag_value_meta_icd());
|
||||
|
||||
read_report_group(global_timestamp, 0,
|
||||
neu_adapter_get_tag_cache_type(&driver->adapter),
|
||||
driver->cache, group, tags, data->tags);
|
||||
|
||||
if (utarray_len(data->tags) > 0) {
|
||||
|
||||
data->ctx = calloc(1, sizeof(neu_reqresp_trans_data_ctx_t));
|
||||
data->ctx->index = utarray_len(find->apps);
|
||||
pthread_mutex_init(&data->ctx->mtx, NULL);
|
||||
|
||||
if (utarray_len(find->apps) > 0) {
|
||||
pthread_mutex_lock(&find->apps_mtx);
|
||||
|
||||
utarray_foreach(find->apps, sub_app_t *, app)
|
||||
{
|
||||
if (driver->adapter.cb_funs.responseto(
|
||||
&driver->adapter, &header, data, app->addr) != 0) {
|
||||
neu_trans_data_free(data);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&find->apps_mtx);
|
||||
} else {
|
||||
neu_trans_data_free(data);
|
||||
}
|
||||
} else {
|
||||
utarray_free(data->tags);
|
||||
free(data->group);
|
||||
free(data->driver);
|
||||
}
|
||||
|
||||
utarray_free(tags);
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void update_im(neu_adapter_t *adapter, const char *group,
|
||||
const char *tag, neu_dvalue_t value,
|
||||
neu_tag_meta_t *metas, int n_meta)
|
||||
@@ -554,6 +708,7 @@ neu_adapter_driver_t *neu_adapter_driver_create()
|
||||
driver->adapter.cb_funs.driver.fdown_open_response = fdown_open_response;
|
||||
driver->adapter.cb_funs.driver.fup_data_response = fup_data_response;
|
||||
driver->adapter.cb_funs.driver.update_im = update_im;
|
||||
driver->adapter.cb_funs.driver.update_im_f_m = update_im_f_m;
|
||||
driver->adapter.cb_funs.driver.update_with_trace = update_with_trace;
|
||||
driver->adapter.cb_funs.driver.update_with_meta = update_with_meta;
|
||||
driver->adapter.cb_funs.driver.scan_tags_response = scan_tags_response;
|
||||
@@ -1371,6 +1526,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver,
|
||||
group_t *g = find_group(driver, cmd->group);
|
||||
|
||||
if (g == NULL) {
|
||||
nlog_warn("driver write tags group not exist, driver: %s, group: %s",
|
||||
driver->adapter.name, cmd->group);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
NEU_ERR_GROUP_NOT_EXIST);
|
||||
return NEU_ERR_GROUP_NOT_EXIST;
|
||||
@@ -1391,6 +1548,9 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver,
|
||||
cmd->tags[i].value.value.d64,
|
||||
cmd->tags[i].value.type, tag->decimal);
|
||||
} else {
|
||||
nlog_warn("driver write tags not exist, driver: %s, group: %s, "
|
||||
"tag: %s",
|
||||
driver->adapter.name, cmd->group, cmd->tags[i].tag);
|
||||
value_check = NEU_ERR_TAG_NOT_EXIST;
|
||||
}
|
||||
|
||||
@@ -1424,6 +1584,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver,
|
||||
}
|
||||
|
||||
if (value_err != NEU_ERR_SUCCESS) {
|
||||
nlog_warn("driver write tags value error(%d), driver: %s, group: %s",
|
||||
value_err, driver->adapter.name, cmd->group);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
value_err);
|
||||
utarray_foreach(tags, neu_plugin_tag_value_t *, tv)
|
||||
@@ -1437,6 +1599,9 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver,
|
||||
}
|
||||
|
||||
if (utarray_len(tags) != (unsigned int) cmd->n_tag) {
|
||||
nlog_warn("driver write tags some tag not exist, driver: %s, group: "
|
||||
"%s",
|
||||
driver->adapter.name, cmd->group);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
NEU_ERR_TAG_NOT_EXIST);
|
||||
utarray_foreach(tags, neu_plugin_tag_value_t *, tv)
|
||||
@@ -1449,6 +1614,23 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver,
|
||||
return NEU_ERR_TAG_NOT_EXIST;
|
||||
}
|
||||
|
||||
const neu_reqresp_head_t *head = (const neu_reqresp_head_t *) req;
|
||||
const char * iface =
|
||||
(head && head->sender[0] != '\0') ? head->sender : "unknown";
|
||||
|
||||
nlog_notice("driver multi write request received, driver: %s, group: %s, "
|
||||
"interface: %s, tag_count: %d",
|
||||
driver->adapter.name, cmd->group, iface, cmd->n_tag);
|
||||
|
||||
for (int i = 0; i < cmd->n_tag; i++) {
|
||||
const char *tag_name = cmd->tags[i].tag;
|
||||
nlog_notice(
|
||||
"driver multi write request tag detail, driver: %s, group: %s, "
|
||||
"tag: %s, %s",
|
||||
driver->adapter.name, cmd->group, tag_name ? tag_name : "",
|
||||
neu_value_str(cmd->tags[i].value.type, cmd->tags[i].value.value));
|
||||
}
|
||||
|
||||
to_be_write_tag_t wtag = { 0 };
|
||||
wtag.single = false;
|
||||
wtag.req = (void *) req;
|
||||
@@ -1573,6 +1755,29 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver,
|
||||
return NEU_ERR_TAG_NOT_EXIST;
|
||||
}
|
||||
|
||||
const neu_reqresp_head_t *head = (const neu_reqresp_head_t *) req;
|
||||
const char * iface =
|
||||
(head && head->sender[0] != '\0') ? head->sender : "unknown";
|
||||
|
||||
nlog_notice(
|
||||
"driver multi write request received, driver: %s, interface: %s, "
|
||||
"group_count: %d, tag_count: %u",
|
||||
driver->adapter.name, iface, cmd->n_group, n_tag);
|
||||
|
||||
for (int i = 0; i < cmd->n_group; i++) {
|
||||
const char *group_name =
|
||||
cmd->groups[i].group ? cmd->groups[i].group : "";
|
||||
for (int k = 0; k < cmd->groups[i].n_tag; k++) {
|
||||
const char *tag_name = cmd->groups[i].tags[k].tag;
|
||||
nlog_notice("driver multi write request tag detail, driver: %s, "
|
||||
"group: %s, tag: %s, %s",
|
||||
driver->adapter.name, group_name,
|
||||
tag_name ? tag_name : "",
|
||||
neu_value_str(cmd->groups[i].tags[k].value.type,
|
||||
cmd->groups[i].tags[k].value.value));
|
||||
}
|
||||
}
|
||||
|
||||
to_be_write_tag_t wtag = { 0 };
|
||||
wtag.single = false;
|
||||
wtag.req = (void *) req;
|
||||
@@ -1596,6 +1801,8 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
|
||||
group_t * g = find_group(driver, cmd->group);
|
||||
|
||||
if (g == NULL) {
|
||||
nlog_warn("driver write tag group not exist, driver: %s, group: %s",
|
||||
driver->adapter.name, cmd->group);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
NEU_ERR_GROUP_NOT_EXIST);
|
||||
return NEU_ERR_GROUP_NOT_EXIST;
|
||||
@@ -1603,11 +1810,16 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
|
||||
neu_datatag_t *tag = neu_group_find_tag(g->group, cmd->tag);
|
||||
|
||||
if (tag == NULL) {
|
||||
nlog_warn("driver write tag not exist, driver: %s, group: %s, tag: %s",
|
||||
driver->adapter.name, cmd->group, cmd->tag);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
NEU_ERR_TAG_NOT_EXIST);
|
||||
return NEU_ERR_TAG_NOT_EXIST;
|
||||
} else {
|
||||
if ((tag->attribute & NEU_ATTRIBUTE_WRITE) != NEU_ATTRIBUTE_WRITE) {
|
||||
nlog_warn("driver write tag not allow write, driver: %s, group: "
|
||||
"%s, tag: %s",
|
||||
driver->adapter.name, cmd->group, cmd->tag);
|
||||
driver->adapter.cb_funs.driver.write_response(
|
||||
&driver->adapter, req, NEU_ERR_PLUGIN_TAG_NOT_ALLOW_WRITE);
|
||||
neu_tag_free(tag);
|
||||
@@ -1619,6 +1831,9 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
|
||||
cmd->value.type, tag->decimal);
|
||||
|
||||
if (value_check != NEU_ERR_SUCCESS) {
|
||||
nlog_warn("driver write tag value error(%d), driver: %s, group: "
|
||||
"%s, tag: %s",
|
||||
value_check, driver->adapter.name, cmd->group, cmd->tag);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
value_check);
|
||||
neu_tag_free(tag);
|
||||
@@ -1638,6 +1853,17 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
|
||||
|
||||
fix_value(tag, cmd->value.type, &cmd->value);
|
||||
|
||||
const neu_reqresp_head_t *head = (const neu_reqresp_head_t *) req;
|
||||
const char * iface =
|
||||
(head && head->sender[0] != '\0') ? head->sender : "unknown";
|
||||
const char *group_name = cmd->group ? cmd->group : "";
|
||||
const char *tag_name = cmd->tag ? cmd->tag : "";
|
||||
|
||||
nlog_notice("driver single write request received, driver: %s, group: "
|
||||
"%s, tag: %s, interface: %s, %s",
|
||||
driver->adapter.name, group_name, tag_name, iface,
|
||||
neu_value_str(cmd->value.type, cmd->value.value));
|
||||
|
||||
to_be_write_tag_t wtag = { 0 };
|
||||
wtag.single = true;
|
||||
wtag.req = (void *) req;
|
||||
@@ -1745,6 +1971,10 @@ int neu_adapter_driver_update_group(neu_adapter_driver_t *driver,
|
||||
if (NULL != new_name && 0 != strcmp(name, new_name)) {
|
||||
char *new_name_cp1 = strdup(new_name);
|
||||
char *new_name_cp2 = strdup(new_name);
|
||||
if (find->grp.group_free != NULL) {
|
||||
find->grp.group_free(&find->grp);
|
||||
find->grp.group_free = NULL;
|
||||
}
|
||||
if (new_name_cp1 && new_name_cp2 &&
|
||||
0 == neu_group_set_name(find->group, new_name)) {
|
||||
HASH_DEL(driver->groups, find);
|
||||
@@ -2494,9 +2724,35 @@ static int write_callback(void *usr_data)
|
||||
e_time = neu_time_ns();
|
||||
neu_tag_free(wtag->tag);
|
||||
} else {
|
||||
group->driver->adapter.module->intf_funs->driver.write_tags(
|
||||
group->driver->adapter.plugin, (void *) wtag->req, wtag->tvs);
|
||||
const neu_reqresp_head_t *head =
|
||||
(const neu_reqresp_head_t *) wtag->req;
|
||||
const char *iface =
|
||||
(head && head->sender[0] != '\0') ? head->sender : "unknown";
|
||||
|
||||
size_t tag_count = utarray_len(wtag->tvs);
|
||||
nlog_info("driver multi write request start, driver: %s, group: "
|
||||
"%s, interface: %s, tag_count: %zu",
|
||||
group->driver->adapter.name, group->name, iface,
|
||||
tag_count);
|
||||
utarray_foreach(wtag->tvs, neu_plugin_tag_value_t *, tv)
|
||||
{
|
||||
const char *tag_name =
|
||||
(tv && tv->tag && tv->tag->name) ? tv->tag->name : "";
|
||||
nlog_info("driver multi write tag detail, driver: %s, group: "
|
||||
"%s, tag: %s, %s",
|
||||
group->driver->adapter.name, group->name, tag_name,
|
||||
neu_value_str(tv->type, tv->value));
|
||||
}
|
||||
|
||||
int ret =
|
||||
group->driver->adapter.module->intf_funs->driver.write_tags(
|
||||
group->driver->adapter.plugin, (void *) wtag->req,
|
||||
wtag->tvs);
|
||||
e_time = neu_time_ms();
|
||||
|
||||
nlog_info("driver multi write request done, driver: %s, group: %s, "
|
||||
"interface: %s, ret: %d",
|
||||
group->driver->adapter.name, group->name, iface, ret);
|
||||
utarray_foreach(wtag->tvs, neu_plugin_tag_value_t *, tv)
|
||||
{
|
||||
neu_tag_free(tv->tag);
|
||||
|
||||
@@ -372,8 +372,10 @@ void neu_group_change_test(neu_group_t *group, int64_t timestamp, void *arg,
|
||||
neu_group_change_fn fn)
|
||||
{
|
||||
if (group->timestamp != timestamp) {
|
||||
pthread_mutex_lock(&group->mtx);
|
||||
UT_array *tags = to_array(group->tags);
|
||||
fn(arg, group->timestamp, tags, group->interval);
|
||||
pthread_mutex_unlock(&group->mtx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ struct neu_conn {
|
||||
uint8_t *buf;
|
||||
uint16_t buf_size;
|
||||
uint16_t offset;
|
||||
|
||||
uint16_t udp_act_port;
|
||||
};
|
||||
|
||||
static void conn_tcp_server_add_client(neu_conn_t *conn, int fd,
|
||||
@@ -503,7 +505,8 @@ ssize_t neu_conn_recv(neu_conn_t *conn, uint8_t *buf, ssize_t len)
|
||||
conn->param.log,
|
||||
"tcp conn fd: %d, recv buf len %zd, ret: %zd, errno: %s(%d)",
|
||||
conn->fd, len, ret, strerror(errno), errno);
|
||||
if (ret == 0 || (conn->connection_ok && ret == -1 && errno != EAGAIN)) {
|
||||
if (ret == 0 ||
|
||||
(conn->connection_ok && ret == -1 && errno != EAGAIN)) {
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
}
|
||||
@@ -868,6 +871,7 @@ static void conn_connect(neu_conn_t *conn)
|
||||
} else {
|
||||
zlog_error(conn->param.log, "invalid ip: %s",
|
||||
conn->param.params.tcp_server.ip);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -938,6 +942,7 @@ static void conn_connect(neu_conn_t *conn)
|
||||
} else {
|
||||
zlog_error(conn->param.log, "invalid ip: %s",
|
||||
conn->param.params.tcp_server.ip);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -950,6 +955,13 @@ static void conn_connect(neu_conn_t *conn)
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in local_addr = { 0 };
|
||||
socklen_t local_addr_len = sizeof(local_addr);
|
||||
if (getsockname(fd, (struct sockaddr *) &local_addr, &local_addr_len) ==
|
||||
0) {
|
||||
conn->udp_act_port = ntohs(local_addr.sin_port);
|
||||
}
|
||||
|
||||
if (is_ipv4(conn->param.params.udp.dst_ip)) {
|
||||
struct sockaddr_in remote = {
|
||||
.sin_family = AF_INET,
|
||||
@@ -1053,6 +1065,13 @@ static void conn_connect(neu_conn_t *conn)
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in local_addr = { 0 };
|
||||
socklen_t local_addr_len = sizeof(local_addr);
|
||||
if (getsockname(fd, (struct sockaddr *) &local_addr, &local_addr_len) ==
|
||||
0) {
|
||||
conn->udp_act_port = ntohs(local_addr.sin_port);
|
||||
}
|
||||
|
||||
conn->is_connected = true;
|
||||
conn->fd = fd;
|
||||
|
||||
@@ -1464,4 +1483,9 @@ int is_ipv6(const char *ip)
|
||||
bool neu_conn_is_connected(neu_conn_t *conn)
|
||||
{
|
||||
return conn->is_connected;
|
||||
}
|
||||
|
||||
uint16_t neu_conn_udp_act_port(neu_conn_t *conn)
|
||||
{
|
||||
return conn->udp_act_port;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ int neu_conn_eth_check_interface(const char *interface)
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(ifr.ifr_name, interface);
|
||||
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", interface);
|
||||
ret = ioctl(fd, SIOCGIFHWADDR, &ifr);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
@@ -302,7 +302,7 @@ static int get_mac(neu_conn_eth_t *conn, const char *interface)
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||
int ret = -1;
|
||||
|
||||
strcpy(ifr.ifr_name, interface);
|
||||
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", interface);
|
||||
if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
|
||||
memcpy(conn->ic->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
||||
ret = 0;
|
||||
@@ -328,7 +328,7 @@ static int init_socket(const char *interface, uint16_t protocol, uint8_t mac[6])
|
||||
(void) mac;
|
||||
(void) pn_mcast_addr;
|
||||
|
||||
strcpy(ifr.ifr_name, interface);
|
||||
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", interface);
|
||||
if (ioctl(fd, SIOCGIFINDEX, &ifr) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
|
||||
@@ -1258,20 +1258,19 @@ int neu_mqtt_client_set_tls(neu_mqtt_client_t *client, bool enabled,
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (ca && (rv = nng_tls_config_ca_chain(cfg, ca, NULL)) != 0) {
|
||||
if (NULL == ca || '\0' == ca[0]) {
|
||||
log(error, "tls enabled but no ca");
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if ((rv = nng_tls_config_ca_chain(cfg, ca, NULL)) != 0) {
|
||||
log(error, "nng_tls_config_ca_chain fail: %s", nng_strerror(rv));
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cert != NULL && key != NULL) {
|
||||
if ((rv = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) !=
|
||||
0) {
|
||||
log(error, "nng_tls_config_auth_mode fail: %s", nng_strerror(rv));
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (keypass) {
|
||||
pass[0] = write_string_to_random_file(((char **) keypass)[0]);
|
||||
pass[1] = write_string_to_random_file(((char **) keypass)[1]);
|
||||
@@ -1283,12 +1282,12 @@ int neu_mqtt_client_set_tls(neu_mqtt_client_t *client, bool enabled,
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if ((rv = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) != 0) {
|
||||
log(error, "nng_tls_config_auth_mode fail: %s", nng_strerror(rv));
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rv = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) != 0) {
|
||||
log(error, "nng_tls_config_auth_mode fail: %s", nng_strerror(rv));
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
+7
-10
@@ -1395,21 +1395,18 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
UT_array *apps = neu_subscribe_manager_find(
|
||||
manager->subscribe_manager, cmd->driver, cmd->group);
|
||||
|
||||
forward_msg(manager, header, header->receiver);
|
||||
neu_subscribe_manager_remove(manager->subscribe_manager,
|
||||
cmd->driver, cmd->group);
|
||||
|
||||
if (NULL == apps) {
|
||||
break;
|
||||
if (NULL != apps) {
|
||||
utarray_foreach(apps, neu_app_subscribe_t *, app)
|
||||
{
|
||||
forward_msg_copy(manager, header, app->app_name);
|
||||
}
|
||||
utarray_free(apps);
|
||||
}
|
||||
|
||||
// notify app node about group deletion
|
||||
utarray_foreach(apps, neu_app_subscribe_t *, app)
|
||||
{
|
||||
forward_msg_copy(manager, header, app->app_name);
|
||||
}
|
||||
|
||||
utarray_free(apps);
|
||||
forward_msg(manager, header, header->receiver);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -357,7 +357,8 @@ int neu_plugin_manager_find(neu_plugin_manager_t *mgr, const char *plugin_name,
|
||||
info->kind = plugin->kind;
|
||||
|
||||
if (plugin->single_name != NULL) {
|
||||
strcpy(info->single_name, plugin->single_name);
|
||||
snprintf(info->single_name, sizeof(info->single_name), "%s",
|
||||
plugin->single_name);
|
||||
}
|
||||
strncpy(info->name, plugin->name, sizeof(info->name));
|
||||
strncpy(info->library, plugin->lib_name, sizeof(info->library));
|
||||
|
||||
+30
-17
@@ -37,7 +37,7 @@
|
||||
|
||||
#define SPAN_ID_LENGTH 16
|
||||
#define ID_CHARSET "0123456789abcdef"
|
||||
#define TRACE_TIME_OUT (3 * 60 * 1000)
|
||||
#define TRACE_TIME_OUT (60 * 1000)
|
||||
|
||||
bool otel_flag = false;
|
||||
char otel_collector_url[128] = { 0 };
|
||||
@@ -1033,29 +1033,32 @@ void neu_otel_split_traceparent(const char *in, char *trace_id, char *span_id,
|
||||
char * copy = strdup(in);
|
||||
char t_flags[32] = { 0 };
|
||||
|
||||
const size_t trace_id_cap = 64;
|
||||
const size_t span_id_cap = 32;
|
||||
|
||||
token = strtok_r(copy, delimiter, &saveptr);
|
||||
|
||||
token = strtok_r(NULL, delimiter, &saveptr);
|
||||
if (token != NULL) {
|
||||
strcpy(trace_id, token);
|
||||
snprintf(trace_id, trace_id_cap, "%s", token);
|
||||
} else {
|
||||
strcpy(trace_id, "");
|
||||
trace_id[0] = '\0';
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, delimiter, &saveptr);
|
||||
if (token != NULL) {
|
||||
strcpy(span_id, token);
|
||||
snprintf(span_id, span_id_cap, "%s", token);
|
||||
} else {
|
||||
strcpy(span_id, "");
|
||||
span_id[0] = '\0';
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, delimiter, &saveptr);
|
||||
if (token != NULL) {
|
||||
strcpy(t_flags, token);
|
||||
snprintf(t_flags, sizeof(t_flags), "%s", token);
|
||||
sscanf(t_flags, "%x", flags);
|
||||
} else {
|
||||
strcpy(t_flags, "");
|
||||
*flags = 0;
|
||||
t_flags[0] = '\0';
|
||||
*flags = 0;
|
||||
}
|
||||
|
||||
free(copy);
|
||||
@@ -1072,25 +1075,33 @@ static int otel_timer_cb(void *data)
|
||||
|
||||
HASH_ITER(hh, traces_table, el, tmp)
|
||||
{
|
||||
bool should_send = false;
|
||||
bool is_timeout = false;
|
||||
|
||||
if (neu_time_ms() - el->ctx->ts >= TRACE_TIME_OUT) {
|
||||
nlog_debug("trace:%s time out", (char *) el->ctx->trace_id);
|
||||
HASH_DEL(traces_table, el);
|
||||
neu_otel_free_trace(el->ctx);
|
||||
free(el);
|
||||
should_send = true;
|
||||
is_timeout = true;
|
||||
nlog_debug("trace:%s time out, reporting incomplete trace",
|
||||
(char *) el->ctx->trace_id);
|
||||
} else if (el->ctx->final &&
|
||||
el->ctx->span_num ==
|
||||
el->ctx->trace_data.resource_spans[0]
|
||||
->scope_spans[0]
|
||||
->n_spans &&
|
||||
el->ctx->expected_span_num <= 0) {
|
||||
int data_size = neu_otel_trace_pack_size(el->ctx);
|
||||
should_send = true;
|
||||
}
|
||||
|
||||
uint8_t *data_buf = calloc(1, data_size);
|
||||
if (should_send) {
|
||||
int data_size = neu_otel_trace_pack_size(el->ctx);
|
||||
uint8_t *data_buf = calloc(1, data_size);
|
||||
neu_otel_trace_pack(el->ctx, data_buf);
|
||||
int status = neu_http_post_otel_trace(data_buf, data_size);
|
||||
free(data_buf);
|
||||
nlog_debug("send trace:%s status:%d", (char *) el->ctx->trace_id,
|
||||
nlog_debug("send %strace:%s status:%d",
|
||||
is_timeout ? "timeout " : "", (char *) el->ctx->trace_id,
|
||||
status);
|
||||
|
||||
if (status == 200 || status == 400) {
|
||||
HASH_DEL(traces_table, el);
|
||||
neu_otel_free_trace(el->ctx);
|
||||
@@ -1175,10 +1186,12 @@ void neu_otel_set_config(void *config)
|
||||
otel_control_flag = req->control_flag;
|
||||
otel_data_flag = req->data_flag;
|
||||
if (req->collector_url) {
|
||||
strcpy(otel_collector_url, req->collector_url);
|
||||
snprintf(otel_collector_url, sizeof(otel_collector_url), "%s",
|
||||
req->collector_url);
|
||||
}
|
||||
if (req->service_name) {
|
||||
strcpy(otel_service_name, req->service_name);
|
||||
snprintf(otel_service_name, sizeof(otel_service_name), "%s",
|
||||
req->service_name);
|
||||
}
|
||||
otel_data_sample_rate = req->data_sample_rate;
|
||||
|
||||
|
||||
@@ -110,7 +110,6 @@ int neu_parse_param(const char *buf, char **err_param, int n,
|
||||
int ret = 0;
|
||||
|
||||
if (neu_json_decode_value(json, ¶ms_ele) != 0) {
|
||||
neu_json_decode_free(json);
|
||||
if (err_param) {
|
||||
*err_param = strdup("params");
|
||||
}
|
||||
|
||||
@@ -239,7 +239,12 @@ int neu_json_decode_global_config_req_subscriptions(
|
||||
|
||||
json_t *grp_array = json_object_get(sub_obj, "groups");
|
||||
for (size_t j = 0; j < json_array_size(grp_array); ++j) {
|
||||
p->app = strdup(json_string_value(app_obj));
|
||||
const char *app_str = json_string_value(app_obj);
|
||||
if (NULL == app_str) {
|
||||
nlog_error("`app` field is not a string");
|
||||
goto error;
|
||||
}
|
||||
p->app = strdup(app_str);
|
||||
if (NULL == p->app) {
|
||||
nlog_error("strdup fail");
|
||||
goto error;
|
||||
@@ -318,7 +323,12 @@ int neu_json_decode_global_config_req_settings(
|
||||
goto error;
|
||||
}
|
||||
|
||||
p->node = strdup(json_string_value(node_obj));
|
||||
const char *node_str = json_string_value(node_obj);
|
||||
if (NULL == node_str) {
|
||||
nlog_error("`node` field is not a string");
|
||||
goto error;
|
||||
}
|
||||
p->node = strdup(node_str);
|
||||
if (NULL == p->node) {
|
||||
nlog_error("strdup fail");
|
||||
goto error;
|
||||
|
||||
@@ -109,7 +109,7 @@ arrow::Status Client::InsertPrepared(const std::string & table_name,
|
||||
{
|
||||
flight::FlightCallOptions call_options;
|
||||
call_options.headers.push_back(
|
||||
std::make_pair("authorization", "Bearer " + bearer_token_));
|
||||
std::make_pair("authorization", bearer_token_));
|
||||
|
||||
std::string sql = "INSERT INTO " + table_name +
|
||||
" (time, node_name, group_name, tag, value) VALUES (?, ?, ?, ?, ?)";
|
||||
|
||||
+12
-8
@@ -117,19 +117,23 @@ int read_file_string(const char *fn, char **out)
|
||||
}
|
||||
|
||||
// read all file content
|
||||
ssize_t n = 0;
|
||||
while ((n = read(fd, buf + n, fsize))) {
|
||||
if (fsize == n) {
|
||||
break;
|
||||
} else if (n < fsize && EINTR == errno) {
|
||||
continue;
|
||||
} else {
|
||||
ssize_t total = 0;
|
||||
while (total < fsize) {
|
||||
ssize_t n = read(fd, buf + total, fsize - total);
|
||||
if (n < 0) {
|
||||
if (EINTR == errno) {
|
||||
continue;
|
||||
}
|
||||
rv = -1;
|
||||
goto error_read;
|
||||
}
|
||||
if (0 == n) {
|
||||
break; // EOF before the expected size
|
||||
}
|
||||
total += n;
|
||||
}
|
||||
|
||||
buf[fsize] = 0;
|
||||
buf[total] = 0;
|
||||
*out = buf;
|
||||
close(fd);
|
||||
return rv;
|
||||
|
||||
+6
-3
@@ -40,7 +40,7 @@ size_t calcDecodeLength(const char *b64input)
|
||||
{ // Calculates the length of a decoded string
|
||||
size_t len = strlen(b64input), padding = 0;
|
||||
|
||||
if (0 == len) {
|
||||
if (len < 4) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -57,8 +57,11 @@ int Base64Decode(const char *b64message, unsigned char **buffer, int *length)
|
||||
{ // Decodes a base64 encoded string
|
||||
BIO *bio, *b64;
|
||||
|
||||
int decodeLen = calcDecodeLength(b64message);
|
||||
*buffer = (unsigned char *) malloc(decodeLen + 1);
|
||||
int decodeLen = calcDecodeLength(b64message);
|
||||
*buffer = (unsigned char *) malloc(decodeLen + 1);
|
||||
if (NULL == *buffer) {
|
||||
return -1;
|
||||
}
|
||||
(*buffer)[decodeLen] = '\0';
|
||||
|
||||
bio = BIO_new_mem_buf(b64message, -1);
|
||||
|
||||
+126
-51
@@ -274,13 +274,17 @@ typedef struct {
|
||||
} da_basic_type_t;
|
||||
|
||||
static int find_da_basic_type(cid_template_t *template, const char *datype_id,
|
||||
const char *seg_name, da_basic_type_t *da_types)
|
||||
const char *seg_name, da_basic_type_t *da_types,
|
||||
int max)
|
||||
{
|
||||
char name[NEU_CID_LEN64] = { 0 };
|
||||
int index = 0;
|
||||
for (int i = 0; i < template->n_datypes; i++) {
|
||||
if (strcmp(template->datypes[i].id, datype_id) == 0) {
|
||||
for (int j = 0; j < template->datypes[i].n_bdas; j++) {
|
||||
if (index >= max) {
|
||||
break;
|
||||
}
|
||||
if (strlen(seg_name) > 0) {
|
||||
snprintf(name, sizeof(name), "%s.%s", seg_name,
|
||||
template->datypes[i].bdas[j].name);
|
||||
@@ -291,9 +295,10 @@ static int find_da_basic_type(cid_template_t *template, const char *datype_id,
|
||||
if (template->datypes[i].bdas[j].btype == Struct) {
|
||||
index += find_da_basic_type(
|
||||
template, template->datypes[i].bdas[j].ref_type, name,
|
||||
da_types + index);
|
||||
da_types + index, max - index);
|
||||
} else {
|
||||
strcpy(da_types[index].all_name, name);
|
||||
snprintf(da_types[index].all_name,
|
||||
sizeof(da_types[index].all_name), "%s", name);
|
||||
da_types[index].btype = template->datypes[i].bdas[j].btype;
|
||||
index += 1;
|
||||
}
|
||||
@@ -307,7 +312,8 @@ static int find_da_basic_type(cid_template_t *template, const char *datype_id,
|
||||
|
||||
static int find_basic_type(cid_template_t *template, const char *type_id,
|
||||
const char *do_name, const char *da_name,
|
||||
cid_fc_e fc, cid_basictype_e **btypes)
|
||||
cid_fc_e fc, cid_basictype_e **btypes,
|
||||
bool *is_array, uint8_t *array_size)
|
||||
{
|
||||
*btypes = NULL;
|
||||
cid_tm_do_type_t *dotype = NULL;
|
||||
@@ -330,10 +336,13 @@ static int find_basic_type(cid_template_t *template, const char *type_id,
|
||||
(*btypes)[index - 1] = dotype->das[i].btype;
|
||||
continue;
|
||||
}
|
||||
*is_array = dotype->das[i].is_array;
|
||||
*array_size = dotype->das[i].array_size;
|
||||
|
||||
da_basic_type_t da_types[32] = { 0 };
|
||||
int n_da_types = find_da_basic_type(template, dotype->das[i].ref_type,
|
||||
dotype->das[i].name, da_types);
|
||||
int n_da_types = find_da_basic_type(
|
||||
template, dotype->das[i].ref_type, dotype->das[i].name, da_types,
|
||||
(int) (sizeof(da_types) / sizeof(da_types[0])));
|
||||
for (int j = 0; j < n_da_types; j++) {
|
||||
if (strlen(da_name) > 0) {
|
||||
if (strcmp(da_types[j].all_name, da_name) == 0) {
|
||||
@@ -362,15 +371,28 @@ static void update_dataset(cid_dataset_t *dataset, cid_ldevice_t *ldev,
|
||||
find_type_id(ldev, dataset->fcdas[i].prefix,
|
||||
dataset->fcdas[i].lnclass, dataset->fcdas[i].lninst);
|
||||
if (type_id != NULL) {
|
||||
cid_basictype_e *bs = NULL;
|
||||
int ret = find_basic_type(
|
||||
template, type_id, dataset->fcdas[i].do_name,
|
||||
dataset->fcdas[i].da_name, dataset->fcdas[i].fc, &bs);
|
||||
cid_basictype_e *bs = NULL;
|
||||
bool is_array = false;
|
||||
uint8_t array_size = 0;
|
||||
|
||||
int ret =
|
||||
find_basic_type(template, type_id, dataset->fcdas[i].do_name,
|
||||
dataset->fcdas[i].da_name, dataset->fcdas[i].fc,
|
||||
&bs, &is_array, &array_size);
|
||||
if (ret > 0) {
|
||||
if (ret <= 16) {
|
||||
memcpy(dataset->fcdas[i].btypes, bs,
|
||||
ret * sizeof(cid_basictype_e));
|
||||
dataset->fcdas[i].n_btypes = ret;
|
||||
dataset->fcdas[i].btype = bs[0];
|
||||
for (int j = 1; j < ret; j++) {
|
||||
if ((bs[j] & 0x7f) != 15 && (bs[j] & 0x7f) != 16) {
|
||||
dataset->fcdas[i].btype = bs[j];
|
||||
}
|
||||
}
|
||||
|
||||
dataset->fcdas[i].n_btypes = ret;
|
||||
dataset->fcdas[i].is_array = is_array;
|
||||
dataset->fcdas[i].array_size = array_size;
|
||||
} else {
|
||||
nlog_warn(
|
||||
"Too many basic types for %s %s %s %s %s %d %s",
|
||||
@@ -441,13 +463,15 @@ static void update_doi(const char *ref_type, cid_doi_t *dois, int n_dois,
|
||||
|
||||
ctl->btype = da->btype;
|
||||
ctl->fc = da->fc;
|
||||
strcpy(ctl->da_name, da->name);
|
||||
snprintf(ctl->da_name, sizeof(ctl->da_name), "%s",
|
||||
da->name);
|
||||
}
|
||||
}
|
||||
|
||||
da_basic_type_t da_types[32] = { 0 };
|
||||
int n_da_types = find_da_basic_type(
|
||||
template, tm_do->das[k].ref_type, tm_do->das[k].name, da_types);
|
||||
template, tm_do->das[k].ref_type, tm_do->das[k].name, da_types,
|
||||
(int) (sizeof(da_types) / sizeof(da_types[0])));
|
||||
|
||||
if (da->fc == SP || da->fc == SG) {
|
||||
for (int j = 0; j < n_da_types; j++) {
|
||||
@@ -459,7 +483,8 @@ static void update_doi(const char *ref_type, cid_doi_t *dois, int n_dois,
|
||||
|
||||
ctl->btype = da_types[j].btype;
|
||||
ctl->fc = da->fc;
|
||||
strcpy(ctl->da_name, da_types[j].all_name);
|
||||
snprintf(ctl->da_name, sizeof(ctl->da_name), "%s",
|
||||
da_types[j].all_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,9 +497,14 @@ static void update_doi(const char *ref_type, cid_doi_t *dois, int n_dois,
|
||||
|
||||
ctl->btype = da_types[0].btype;
|
||||
ctl->fc = da->fc;
|
||||
strcpy(ctl->da_name, da->name);
|
||||
ctl->n_co_types = n_da_types;
|
||||
for (int j = 0; j < n_da_types; j++) {
|
||||
snprintf(ctl->da_name, sizeof(ctl->da_name), "%s", da->name);
|
||||
int n_co = n_da_types;
|
||||
if (n_co >
|
||||
(int) (sizeof(ctl->co_types) / sizeof(ctl->co_types[0]))) {
|
||||
n_co = sizeof(ctl->co_types) / sizeof(ctl->co_types[0]);
|
||||
}
|
||||
ctl->n_co_types = n_co;
|
||||
for (int j = 0; j < n_co; j++) {
|
||||
ctl->co_types[j] = da_types[j].btype;
|
||||
}
|
||||
}
|
||||
@@ -501,12 +531,16 @@ static int parse_ied(xmlNode *xml_ied, cid_ied_t *ied)
|
||||
{
|
||||
int ret = -1;
|
||||
char *ied_name = (char *) xmlGetProp(xml_ied, (const xmlChar *) "name");
|
||||
if (ied_name == NULL) {
|
||||
nlog_warn("IED has no name attribute");
|
||||
return -1;
|
||||
}
|
||||
if (strlen(ied_name) >= NEU_CID_IED_NAME_LEN) {
|
||||
xmlFree(ied_name);
|
||||
nlog_warn("IED name is too long");
|
||||
return -1;
|
||||
} else {
|
||||
strcpy(ied->name, ied_name);
|
||||
snprintf(ied->name, sizeof(ied->name), "%s", ied_name);
|
||||
xmlFree(ied_name);
|
||||
}
|
||||
xmlNode *access_point = xml_ied->children;
|
||||
@@ -524,7 +558,7 @@ static int parse_ied(xmlNode *xml_ied, cid_ied_t *ied)
|
||||
memset(ap, 0, sizeof(cid_access_point_t));
|
||||
|
||||
if (name != NULL) {
|
||||
strcpy(ap->name, name);
|
||||
snprintf(ap->name, sizeof(ap->name), "%s", name);
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
@@ -565,7 +599,7 @@ static int parse_ldevice(xmlNode *xml_server, cid_access_point_t *ap)
|
||||
memset(ldev, 0, sizeof(cid_ldevice_t));
|
||||
char *inst = (char *) xmlGetProp(ldevice, (const xmlChar *) "inst");
|
||||
if (inst != NULL) {
|
||||
strcpy(ldev->inst, inst);
|
||||
snprintf(ldev->inst, sizeof(ldev->inst), "%s", inst);
|
||||
xmlFree(inst);
|
||||
}
|
||||
int ret = parse_lnode(ldevice, ldev);
|
||||
@@ -887,8 +921,9 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
&template->lnotypes[template->n_lnotypes - 1];
|
||||
memset(tm_lno, 0, sizeof(cid_tm_lno_type_t));
|
||||
|
||||
strcpy(tm_lno->id, id);
|
||||
strcpy(tm_lno->ln_class, ln_class);
|
||||
snprintf(tm_lno->id, sizeof(tm_lno->id), "%s", id);
|
||||
snprintf(tm_lno->ln_class, sizeof(tm_lno->ln_class), "%s",
|
||||
ln_class);
|
||||
|
||||
xmlNode *xdo = child->children;
|
||||
while (xdo != NULL) {
|
||||
@@ -910,8 +945,9 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
&tm_lno->dos[tm_lno->n_dos - 1];
|
||||
memset(tm_do, 0, sizeof(cid_tm_lno_do_t));
|
||||
|
||||
strcpy(tm_do->name, name);
|
||||
strcpy(tm_do->ref_type, ref_type);
|
||||
snprintf(tm_do->name, sizeof(tm_do->name), "%s", name);
|
||||
snprintf(tm_do->ref_type, sizeof(tm_do->ref_type), "%s",
|
||||
ref_type);
|
||||
}
|
||||
|
||||
if (name != NULL) {
|
||||
@@ -944,7 +980,7 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
&template->dotypes[template->n_dotypes - 1];
|
||||
memset(tm_do, 0, sizeof(cid_tm_do_type_t));
|
||||
|
||||
strcpy(tm_do->id, id);
|
||||
snprintf(tm_do->id, sizeof(tm_do->id), "%s", id);
|
||||
xmlNode *da = child->children;
|
||||
while (da != NULL) {
|
||||
if (da->type != XML_ELEMENT_NODE) {
|
||||
@@ -966,8 +1002,10 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
&tm_do->sdos[tm_do->n_sdos - 1];
|
||||
memset(tm_sdo, 0, sizeof(cid_tm_sdo_t));
|
||||
|
||||
strcpy(tm_sdo->name, sdo_name);
|
||||
strcpy(tm_sdo->ref_type, sdo_ref_type);
|
||||
snprintf(tm_sdo->name, sizeof(tm_sdo->name), "%s",
|
||||
sdo_name);
|
||||
snprintf(tm_sdo->ref_type, sizeof(tm_sdo->ref_type),
|
||||
"%s", sdo_ref_type);
|
||||
}
|
||||
|
||||
if (sdo_name != NULL) {
|
||||
@@ -987,6 +1025,8 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
(char *) xmlGetProp(da, (const xmlChar *) "name");
|
||||
char *ref_type =
|
||||
(char *) xmlGetProp(da, (const xmlChar *) "type");
|
||||
char *count =
|
||||
(char *) xmlGetProp(da, (const xmlChar *) "count");
|
||||
|
||||
if (btype != NULL && fc != NULL && name != NULL) {
|
||||
tm_do->n_das += 1;
|
||||
@@ -997,9 +1037,12 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
&tm_do->das[tm_do->n_das - 1];
|
||||
memset(tm_da, 0, sizeof(cid_tm_do_da_t));
|
||||
|
||||
strcpy(tm_da->name, name);
|
||||
snprintf(tm_da->name, sizeof(tm_da->name), "%s",
|
||||
name);
|
||||
if (ref_type != NULL) {
|
||||
strcpy(tm_da->ref_type, ref_type);
|
||||
snprintf(tm_da->ref_type,
|
||||
sizeof(tm_da->ref_type), "%s",
|
||||
ref_type);
|
||||
}
|
||||
tm_da->btype = T_UNKNOWN;
|
||||
tm_da->btype =
|
||||
@@ -1014,6 +1057,14 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
nlog_warn("Unknown fc %s, %d", fc,
|
||||
(int) da->line);
|
||||
}
|
||||
|
||||
if (count != NULL) {
|
||||
tm_da->is_array = true;
|
||||
tm_da->array_size = atoi(count);
|
||||
} else {
|
||||
tm_da->is_array = false;
|
||||
tm_da->array_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (btype != NULL) {
|
||||
@@ -1028,6 +1079,9 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
if (ref_type != NULL) {
|
||||
xmlFree(ref_type);
|
||||
}
|
||||
if (count != NULL) {
|
||||
xmlFree(count);
|
||||
}
|
||||
}
|
||||
|
||||
da = da->next;
|
||||
@@ -1050,7 +1104,7 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
&template->datypes[template->n_datypes - 1];
|
||||
memset(tm_dat, 0, sizeof(cid_tm_da_type_t));
|
||||
|
||||
strcpy(tm_dat->id, id);
|
||||
snprintf(tm_dat->id, sizeof(tm_dat->id), "%s", id);
|
||||
xmlNode *bda = child->children;
|
||||
while (bda != NULL) {
|
||||
if (bda->type != XML_ELEMENT_NODE) {
|
||||
@@ -1072,9 +1126,11 @@ static int parse_template(xmlNode *xml_template, cid_template_t *template)
|
||||
cid_tm_bda_type_t *tm_bda =
|
||||
&tm_dat->bdas[tm_dat->n_bdas - 1];
|
||||
memset(tm_bda, 0, sizeof(cid_tm_bda_type_t));
|
||||
strcpy(tm_bda->name, name);
|
||||
snprintf(tm_bda->name, sizeof(tm_bda->name), "%s",
|
||||
name);
|
||||
if (ref_type != NULL) {
|
||||
strcpy(tm_bda->ref_type, ref_type);
|
||||
snprintf(tm_bda->ref_type, sizeof(tm_bda->ref_type),
|
||||
"%s", ref_type);
|
||||
}
|
||||
tm_bda->btype = T_UNKNOWN;
|
||||
tm_bda->btype = decode_basictype((const char *) btype);
|
||||
@@ -1210,12 +1266,18 @@ cid_dataset_info_t *neu_cid_info_from_string(const char *str)
|
||||
cid_dataset_info_t *info = calloc(1, sizeof(cid_dataset_info_t));
|
||||
info->control = elems[0].v.val_bool;
|
||||
info->buffered = elems[1].v.val_bool;
|
||||
strcpy(info->ied_name, elems[2].v.val_str);
|
||||
strcpy(info->ldevice_inst, elems[3].v.val_str);
|
||||
strcpy(info->ln_class, elems[4].v.val_str);
|
||||
strcpy(info->report_name, elems[5].v.val_str);
|
||||
strcpy(info->report_id, elems[6].v.val_str);
|
||||
strcpy(info->dataset_name, elems[7].v.val_str);
|
||||
snprintf(info->ied_name, sizeof(info->ied_name), "%s",
|
||||
elems[2].v.val_str);
|
||||
snprintf(info->ldevice_inst, sizeof(info->ldevice_inst), "%s",
|
||||
elems[3].v.val_str);
|
||||
snprintf(info->ln_class, sizeof(info->ln_class), "%s",
|
||||
elems[4].v.val_str);
|
||||
snprintf(info->report_name, sizeof(info->report_name), "%s",
|
||||
elems[5].v.val_str);
|
||||
snprintf(info->report_id, sizeof(info->report_id), "%s",
|
||||
elems[6].v.val_str);
|
||||
snprintf(info->dataset_name, sizeof(info->dataset_name), "%s",
|
||||
elems[7].v.val_str);
|
||||
|
||||
free(elems[2].v.val_str);
|
||||
free(elems[3].v.val_str);
|
||||
@@ -1254,8 +1316,9 @@ static void ld_ctrl_do_to_group(const char *ied_name, const char *ap_name,
|
||||
cid_dataset_info_t *g_info = calloc(1, sizeof(cid_dataset_info_t));
|
||||
|
||||
g_info->control = true;
|
||||
strcpy(g_info->ied_name, ied_name);
|
||||
strcpy(g_info->ldevice_inst, ld->inst);
|
||||
snprintf(g_info->ied_name, sizeof(g_info->ied_name), "%s", ied_name);
|
||||
snprintf(g_info->ldevice_inst, sizeof(g_info->ldevice_inst), "%s",
|
||||
ld->inst);
|
||||
|
||||
group->context = g_info;
|
||||
snprintf(group->group, NEU_GROUP_NAME_LEN, "%s/%s$Control", ap_name,
|
||||
@@ -1418,13 +1481,19 @@ static void ln_dataset_to_group(const char *ied_name, const char *ap_name,
|
||||
calloc(1, sizeof(cid_dataset_info_t));
|
||||
|
||||
g_info->control = false;
|
||||
strcpy(g_info->ied_name, ied_name);
|
||||
strcpy(g_info->ldevice_inst, ld_inst);
|
||||
strcpy(g_info->ln_class, ln->lnclass);
|
||||
snprintf(g_info->ied_name, sizeof(g_info->ied_name), "%s",
|
||||
ied_name);
|
||||
snprintf(g_info->ldevice_inst, sizeof(g_info->ldevice_inst),
|
||||
"%s", ld_inst);
|
||||
snprintf(g_info->ln_class, sizeof(g_info->ln_class), "%s",
|
||||
ln->lnclass);
|
||||
g_info->buffered = ln->reports[i].buffered;
|
||||
strcpy(g_info->report_name, ln->reports[i].name);
|
||||
strcpy(g_info->report_id, ln->reports[i].id);
|
||||
strcpy(g_info->dataset_name, ln->datasets[j].name);
|
||||
snprintf(g_info->report_name, sizeof(g_info->report_name), "%s",
|
||||
ln->reports[i].name);
|
||||
snprintf(g_info->report_id, sizeof(g_info->report_id), "%s",
|
||||
ln->reports[i].id);
|
||||
snprintf(g_info->dataset_name, sizeof(g_info->dataset_name),
|
||||
"%s", ln->datasets[j].name);
|
||||
|
||||
group->context = g_info;
|
||||
|
||||
@@ -1475,7 +1544,7 @@ static void ln_dataset_to_group(const char *ied_name, const char *ap_name,
|
||||
fc_to_str(ln->datasets[j].fcdas[k].fc),
|
||||
ln->datasets[j].fcdas[k].do_name);
|
||||
}
|
||||
switch (ln->datasets[j].fcdas[k].btypes[0] & 0x7f) {
|
||||
switch (ln->datasets[j].fcdas[k].btype & 0x7f) {
|
||||
case BOOLEAN:
|
||||
tag->type = NEU_TYPE_BOOL;
|
||||
break;
|
||||
@@ -1506,9 +1575,15 @@ static void ln_dataset_to_group(const char *ied_name, const char *ap_name,
|
||||
case INT32U:
|
||||
tag->type = NEU_TYPE_UINT32;
|
||||
break;
|
||||
case FLOAT32:
|
||||
tag->type = NEU_TYPE_FLOAT;
|
||||
break;
|
||||
case FLOAT32: {
|
||||
if (ln->datasets[j].fcdas[k].is_array) {
|
||||
tag->type = NEU_TYPE_ARRAY_FLOAT;
|
||||
break;
|
||||
} else {
|
||||
tag->type = NEU_TYPE_FLOAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case FLOAT64:
|
||||
tag->type = NEU_TYPE_DOUBLE;
|
||||
break;
|
||||
@@ -1571,7 +1646,7 @@ static void ln_dataset_to_group(const char *ied_name, const char *ap_name,
|
||||
|
||||
void neu_cid_to_msg(char *driver, cid_t *cid, neu_req_add_gtag_t *cmd)
|
||||
{
|
||||
strcpy(cmd->driver, driver);
|
||||
snprintf(cmd->driver, sizeof(cmd->driver), "%s", driver);
|
||||
cmd->n_group = 0;
|
||||
cmd->groups = NULL;
|
||||
|
||||
|
||||
+39
-1
@@ -439,7 +439,8 @@ int neu_http_post_otel_trace(uint8_t *data, int len)
|
||||
|
||||
char url_buf[128] = { 0 };
|
||||
|
||||
sprintf(url_buf, "http://%s/v1/traces", neu_otel_collector_url());
|
||||
snprintf(url_buf, sizeof(url_buf), "http://%s/v1/traces",
|
||||
neu_otel_collector_url());
|
||||
|
||||
if (nng_url_parse(&url, url_buf) != 0) {
|
||||
nng_aio_free(aio);
|
||||
@@ -515,4 +516,41 @@ int neu_http_post_otel_trace(uint8_t *data, int len)
|
||||
nng_http_conn_close(conn);
|
||||
nng_aio_free(aio);
|
||||
return status;
|
||||
}
|
||||
|
||||
int neu_http_response_file(nng_aio *aio, void *data, size_t len,
|
||||
const char *disposition)
|
||||
{
|
||||
nng_http_res *res = NULL;
|
||||
int rv = 0;
|
||||
|
||||
if (((rv = nng_http_res_alloc(&res)) != 0) ||
|
||||
((rv = nng_http_res_set_status(res, NNG_HTTP_STATUS_OK)) != 0) ||
|
||||
((rv = nng_http_res_set_header(res, "Content-Type",
|
||||
"application/octet-stream")) != 0) ||
|
||||
((rv = nng_http_res_set_header(res, "Content-Disposition",
|
||||
disposition)) != 0) ||
|
||||
((rv = nng_http_res_set_header(res, "Access-Control-Allow-Origin",
|
||||
"*")) != 0) ||
|
||||
((rv = nng_http_res_set_header(res, "Access-Control-Allow-Methods",
|
||||
"POST,GET,PUT,DELETE,OPTIONS")) != 0) ||
|
||||
((rv = nng_http_res_set_header(res, "Access-Control-Allow-Headers",
|
||||
"*")) != 0) ||
|
||||
((rv = nng_http_res_set_header(res, "Access-Control-Expose-Headers",
|
||||
"Content-Disposition")) != 0) ||
|
||||
((rv = nng_http_res_copy_data(res, data, len)) != 0)) {
|
||||
nng_http_res_free(res);
|
||||
nng_aio_finish(aio, rv);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
nng_http_req *nng_req = nng_aio_get_input(aio, 0);
|
||||
nlog_notice("%s %s [%d]", nng_http_req_get_method(nng_req),
|
||||
nng_http_req_get_uri(nng_req), NNG_HTTP_STATUS_OK);
|
||||
|
||||
nng_aio_set_output(aio, 0, res);
|
||||
nng_aio_finish(aio, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+106
-115
@@ -586,19 +586,19 @@ static int decode_object(json_t *root, neu_json_elem_t *ele)
|
||||
ele->v.val_bool = json_boolean_value(ob);
|
||||
break;
|
||||
case NEU_JSON_ARRAY_STR: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_str.length = json_array_size(ob);
|
||||
ele->v.val_array_str.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_str.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_str.p_strs =
|
||||
calloc(ele->v.val_array_str.length, sizeof(char *));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_str.p_strs) {
|
||||
ele->v.val_array_str.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_str.length; i++) {
|
||||
json_t * value = json_array_get(ob, i);
|
||||
const char *str_val = json_string_value(value);
|
||||
if (str_val != NULL) {
|
||||
ele->v.val_array_str.p_strs[index] = strdup(str_val);
|
||||
ele->v.val_array_str.p_strs[i] = strdup(str_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -606,235 +606,226 @@ static int decode_object(json_t *root, neu_json_elem_t *ele)
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_BOOL: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_bool.length = json_array_size(ob);
|
||||
ele->v.val_array_bool.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_bool.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_bool.bools =
|
||||
calloc(ele->v.val_array_bool.length, sizeof(bool));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
ele->v.val_array_bool.bools[index] = json_boolean_value(value);
|
||||
if (NULL == ele->v.val_array_bool.bools) {
|
||||
ele->v.val_array_bool.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_bool.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
ele->v.val_array_bool.bools[i] = json_boolean_value(value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_UINT8: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_uint8.length = json_array_size(ob);
|
||||
ele->v.val_array_uint8.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_uint8.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_uint8.u8s =
|
||||
calloc(ele->v.val_array_uint8.length, sizeof(int8_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_uint8.u8s) {
|
||||
ele->v.val_array_uint8.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_uint8.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_uint8.u8s[index] =
|
||||
ele->v.val_array_uint8.u8s[i] =
|
||||
(uint8_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_uint8.u8s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_uint8.u8s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_INT8: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_int8.length = json_array_size(ob);
|
||||
ele->v.val_array_int8.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_int8.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_int8.i8s =
|
||||
calloc(ele->v.val_array_int8.length, sizeof(int8_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_int8.i8s) {
|
||||
ele->v.val_array_int8.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_int8.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_int8.i8s[index] =
|
||||
ele->v.val_array_int8.i8s[i] =
|
||||
(int8_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_int8.i8s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_int8.i8s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_UINT16: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_uint16.length = json_array_size(ob);
|
||||
ele->v.val_array_uint16.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_uint16.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_uint16.u16s =
|
||||
calloc(ele->v.val_array_uint16.length, sizeof(int16_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_uint16.u16s) {
|
||||
ele->v.val_array_uint16.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_uint16.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_uint16.u16s[index] =
|
||||
ele->v.val_array_uint16.u16s[i] =
|
||||
(uint16_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_uint16.u16s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_uint16.u16s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_INT16: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_int16.length = json_array_size(ob);
|
||||
ele->v.val_array_int16.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_int16.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_int16.i16s =
|
||||
calloc(ele->v.val_array_int16.length, sizeof(int16_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_int16.i16s) {
|
||||
ele->v.val_array_int16.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_int16.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_int16.i16s[index] =
|
||||
ele->v.val_array_int16.i16s[i] =
|
||||
(int16_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_int16.i16s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_int16.i16s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_UINT32: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_uint32.length = json_array_size(ob);
|
||||
ele->v.val_array_uint32.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_uint32.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_uint32.u32s =
|
||||
calloc(ele->v.val_array_uint32.length, sizeof(int32_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_uint32.u32s) {
|
||||
ele->v.val_array_uint32.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_uint32.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_uint32.u32s[index] =
|
||||
ele->v.val_array_uint32.u32s[i] =
|
||||
(uint32_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_uint32.u32s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_uint32.u32s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_INT32: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_int32.length = json_array_size(ob);
|
||||
ele->v.val_array_int32.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_int32.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_int32.i32s =
|
||||
calloc(ele->v.val_array_int32.length, sizeof(int32_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_int32.i32s) {
|
||||
ele->v.val_array_int32.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_int32.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_int32.i32s[index] =
|
||||
ele->v.val_array_int32.i32s[i] =
|
||||
(int32_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_int32.i32s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_int32.i32s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_UINT64: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_uint64.length = json_array_size(ob);
|
||||
ele->v.val_array_uint64.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_uint64.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_uint64.u64s =
|
||||
calloc(ele->v.val_array_uint64.length, sizeof(int64_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_uint64.u64s) {
|
||||
ele->v.val_array_uint64.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_uint64.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_uint64.u64s[index] =
|
||||
ele->v.val_array_uint64.u64s[i] =
|
||||
(uint64_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_uint64.u64s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_uint64.u64s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_INT64: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_int64.length = json_array_size(ob);
|
||||
ele->v.val_array_int64.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_int64.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_int64.i64s =
|
||||
calloc(ele->v.val_array_int64.length, sizeof(int64_t));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_int64.i64s) {
|
||||
ele->v.val_array_int64.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_int64.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_real(value)) {
|
||||
ele->v.val_array_int64.i64s[index] =
|
||||
ele->v.val_array_int64.i64s[i] =
|
||||
(int64_t) json_real_value(value);
|
||||
} else {
|
||||
ele->v.val_array_int64.i64s[index] =
|
||||
json_integer_value(value);
|
||||
ele->v.val_array_int64.i64s[i] = json_integer_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_FLOAT: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_float.length = json_array_size(ob);
|
||||
ele->v.val_array_float.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_float.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_float.f32s =
|
||||
calloc(ele->v.val_array_float.length, sizeof(float));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_float.f32s) {
|
||||
ele->v.val_array_float.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_float.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_integer(value)) {
|
||||
ele->v.val_array_float.f32s[index] =
|
||||
ele->v.val_array_float.f32s[i] =
|
||||
(float) json_integer_value(value);
|
||||
} else {
|
||||
ele->v.val_array_float.f32s[index] = json_real_value(value);
|
||||
ele->v.val_array_float.f32s[i] = json_real_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_ARRAY_DOUBLE: {
|
||||
json_t *value = NULL;
|
||||
|
||||
ele->v.val_array_double.length = json_array_size(ob);
|
||||
ele->v.val_array_double.length = (uint16_t) json_array_size(ob);
|
||||
if (ele->v.val_array_double.length > 0) {
|
||||
int index = 0;
|
||||
|
||||
ele->v.val_array_double.f64s =
|
||||
calloc(ele->v.val_array_double.length, sizeof(double));
|
||||
json_array_foreach(ob, index, value)
|
||||
{
|
||||
if (NULL == ele->v.val_array_double.f64s) {
|
||||
ele->v.val_array_double.length = 0;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < ele->v.val_array_double.length; i++) {
|
||||
json_t *value = json_array_get(ob, i);
|
||||
if (json_is_integer(value)) {
|
||||
ele->v.val_array_double.f64s[index] =
|
||||
ele->v.val_array_double.f64s[i] =
|
||||
(double) json_integer_value(value);
|
||||
} else {
|
||||
ele->v.val_array_double.f64s[index] =
|
||||
json_real_value(value);
|
||||
ele->v.val_array_double.f64s[i] = json_real_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@ def conf_base(mocker):
|
||||
"host": HUB,
|
||||
"auth": 0,
|
||||
"sas": SAS,
|
||||
"ca": mocker.ca_base64,
|
||||
}
|
||||
|
||||
|
||||
@@ -174,6 +175,13 @@ def conf_bad_fmt(conf_base):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def conf_no_ca(conf_base):
|
||||
conf = {**conf_base}
|
||||
del conf["ca"]
|
||||
return conf
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def conf_ssl_bad_ca(conf_ssl):
|
||||
return {
|
||||
@@ -230,6 +238,7 @@ class TestAzure:
|
||||
"conf_bad_id",
|
||||
"conf_bad_qos",
|
||||
"conf_bad_fmt",
|
||||
"conf_no_ca",
|
||||
"conf_ssl_bad_ca",
|
||||
"conf_ssl_no_cert",
|
||||
"conf_ssl_bad_cert",
|
||||
|
||||
@@ -71,7 +71,7 @@ UPLOAD_DRV_STATE_TOPIC = f"neuron/{NODE}/state/update"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def mqtt_node():
|
||||
def mqtt_node(class_setup_and_teardown):
|
||||
otel_p = subprocess.Popen(
|
||||
["python3", "otel_server.py", f'{otel_port}'], stderr=subprocess.PIPE, cwd="simulator")
|
||||
api.add_node_check(NODE, "MQTT")
|
||||
@@ -184,6 +184,7 @@ def conf_emqx_ssl(conf_base, mocker):
|
||||
"host": "broker.emqx.io",
|
||||
"port": 8883,
|
||||
"ssl": True,
|
||||
"ca": mocker.ca_base64,
|
||||
}
|
||||
|
||||
|
||||
@@ -262,6 +263,15 @@ def conf_bad_fmt(conf_base):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def conf_ssl_no_ca(conf_base, mocker):
|
||||
return {
|
||||
**conf_base,
|
||||
"port": mocker.ssl_port,
|
||||
"ssl": True,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def conf_ssl_bad_ca(conf_ssl1):
|
||||
return {
|
||||
@@ -374,6 +384,7 @@ class TestMQTT:
|
||||
"conf_bad_id",
|
||||
"conf_bad_qos",
|
||||
"conf_bad_fmt",
|
||||
"conf_ssl_no_ca",
|
||||
"conf_ssl_bad_ca",
|
||||
"conf_ssl_bad_cert",
|
||||
"conf_ssl_no_key",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
|
||||
import neuron.api as api
|
||||
import neuron.config as config
|
||||
import neuron.process as process
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
@@ -10,3 +16,37 @@ def pytest_addoption(parser):
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def get_envx(request):
|
||||
return request.config.getoption("--env")
|
||||
|
||||
|
||||
def _refresh_default_jwt(token):
|
||||
old_jwt = config.default_jwt
|
||||
new_jwt = f"Bearer {token}"
|
||||
|
||||
config.default_jwt = new_jwt
|
||||
|
||||
for _, func in inspect.getmembers(api, inspect.isfunction):
|
||||
defaults = func.__defaults__
|
||||
if defaults:
|
||||
func.__defaults__ = tuple(
|
||||
new_jwt if value == old_jwt else value for value in defaults
|
||||
)
|
||||
|
||||
kwdefaults = func.__kwdefaults__
|
||||
if kwdefaults:
|
||||
func.__kwdefaults__ = {
|
||||
key: new_jwt if value == old_jwt else value
|
||||
for key, value in kwdefaults.items()
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def init_default_jwt():
|
||||
process.remove_persistence()
|
||||
neuron = process.NeuronProcess()
|
||||
neuron.start()
|
||||
|
||||
response = api.login()
|
||||
assert 200 == response.status_code
|
||||
_refresh_default_jwt(response.json()["token"])
|
||||
|
||||
neuron.stop()
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestGroup:
|
||||
|
||||
@description(given="existent node", when="add group with interval < 100 under existent node", then="add failed")
|
||||
def test_add_group_wrong_interval(self):
|
||||
response = api.add_group(node="modbus-tcp", group='group', interval=99)
|
||||
response = api.add_group(node="modbus-tcp", group='group-bad-interval', interval=99)
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_GROUP_PARAMETER_INVALID == response.json()['error']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user