mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 15:09:11 +08:00
Automatically generated code replace neu_json_plugin
This commit is contained in:
@@ -17,66 +17,69 @@
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#ifndef _NEU_JSON_API_PLUGIN_H_
|
||||
#define _NEU_JSON_API_PLUGIN_H_
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#ifndef _NEU_JSON_API_NEU_PLUGIN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
typedef struct {
|
||||
char * name;
|
||||
int64_t kind;
|
||||
char * lib_name;
|
||||
int64_t node_type;
|
||||
} neu_json_add_plugin_req_t;
|
||||
|
||||
#include "neu_adapter.h"
|
||||
int neu_json_decode_add_plugin_req(char * buf,
|
||||
neu_json_add_plugin_req_t **result);
|
||||
void neu_json_decode_add_plugin_req_free(neu_json_add_plugin_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
plugin_kind_e kind;
|
||||
neu_node_type_e node_type;
|
||||
char * plugin_name;
|
||||
char * plugin_lib_name;
|
||||
} neu_parse_add_plugin_req_t;
|
||||
int64_t id;
|
||||
} neu_json_del_plugin_req_t;
|
||||
|
||||
int neu_parse_decode_add_plugin(char *buf, neu_parse_add_plugin_req_t **result);
|
||||
void neu_parse_decode_add_plugin_free(neu_parse_add_plugin_req_t *req);
|
||||
int neu_json_decode_del_plugin_req(char * buf,
|
||||
neu_json_del_plugin_req_t **result);
|
||||
void neu_json_decode_del_plugin_req_free(neu_json_del_plugin_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
uint32_t plugin_id;
|
||||
} neu_parse_del_plugin_req_t;
|
||||
int64_t id;
|
||||
} neu_json_get_plugin_req_t;
|
||||
|
||||
int neu_parse_decode_del_plugin(char *buf, neu_parse_del_plugin_req_t **result);
|
||||
void neu_parse_decode_del_plugin_free(neu_parse_del_plugin_req_t *req);
|
||||
int neu_json_decode_get_plugin_req(char * buf,
|
||||
neu_json_get_plugin_req_t **result);
|
||||
void neu_json_decode_get_plugin_req_free(neu_json_get_plugin_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
plugin_kind_e kind;
|
||||
neu_node_type_e node_type;
|
||||
char * plugin_name;
|
||||
char * plugin_lib_name;
|
||||
} neu_parse_update_plugin_req_t;
|
||||
|
||||
int neu_parse_decode_update_plugin(char * buf,
|
||||
neu_parse_update_plugin_req_t **result);
|
||||
void neu_parse_decode_update_plugin_free(neu_parse_update_plugin_req_t *req);
|
||||
char * name;
|
||||
int64_t kind;
|
||||
char * lib_name;
|
||||
int64_t id;
|
||||
int64_t node_type;
|
||||
} neu_json_get_plugin_resp_plugin_lib_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t reserved;
|
||||
} neu_parse_get_plugins_req_t;
|
||||
int n_plugin_lib;
|
||||
neu_json_get_plugin_resp_plugin_lib_t *plugin_libs;
|
||||
} neu_json_get_plugin_resp_t;
|
||||
|
||||
int neu_json_encode_get_plugin_resp(void *json_object, void *param);
|
||||
|
||||
typedef struct {
|
||||
uint32_t plugin_id;
|
||||
plugin_kind_e kind;
|
||||
neu_node_type_e node_type;
|
||||
char * plugin_name;
|
||||
char * plugin_lib_name;
|
||||
} neu_parse_get_plugins_res_lib_t;
|
||||
char * name;
|
||||
int64_t kind;
|
||||
char * lib_name;
|
||||
int64_t node_type;
|
||||
} neu_json_update_plugin_req_t;
|
||||
|
||||
typedef struct neu_parse_get_plugins_res {
|
||||
uint16_t n_plugin;
|
||||
neu_parse_get_plugins_res_lib_t *plugin_libs;
|
||||
} neu_parse_get_plugins_res_t;
|
||||
|
||||
int neu_parse_decode_get_plugins(char * buf,
|
||||
neu_parse_get_plugins_req_t **result);
|
||||
void neu_parse_decode_get_plugins_free(neu_parse_get_plugins_req_t *req);
|
||||
int neu_parse_encode_get_plugins(void *json_object, void *param);
|
||||
int neu_json_decode_update_plugin_req(char * buf,
|
||||
neu_json_update_plugin_req_t **result);
|
||||
void neu_json_decode_update_plugin_req_free(neu_json_update_plugin_req_t *req);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"add_plugin_req": {
|
||||
"kind": 1,
|
||||
"node_type": 1,
|
||||
"name": "plugin_name",
|
||||
"lib_name": "plugin_name.so"
|
||||
},
|
||||
"del_plugin_req": {
|
||||
"id": 1
|
||||
},
|
||||
"update_plugin_req": {
|
||||
"kind": 1,
|
||||
"node_type": 1,
|
||||
"name": "plugin_name",
|
||||
"lib_name": "plugin_name.so"
|
||||
},
|
||||
"get_plugin_req": {
|
||||
"id": 1
|
||||
},
|
||||
"get_plugin_resp": {
|
||||
"plugin_libs": [
|
||||
{
|
||||
"id": 1,
|
||||
"kind": 1,
|
||||
"node_type": 1,
|
||||
"name": "plugin_name",
|
||||
"lib_name": "plugin_lib_name"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,9 @@ void handle_add_plugin(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST(
|
||||
aio, neu_parse_add_plugin_req_t, neu_parse_decode_add_plugin, {
|
||||
intptr_t err =
|
||||
neu_system_add_plugin(plugin, req->kind, req->node_type,
|
||||
req->plugin_name, req->plugin_lib_name);
|
||||
aio, neu_json_add_plugin_req_t, neu_json_decode_add_plugin_req, {
|
||||
intptr_t err = neu_system_add_plugin(
|
||||
plugin, req->kind, req->node_type, req->name, req->lib_name);
|
||||
if (err != 0) {
|
||||
http_bad_request(aio, "{\"error\": 1}");
|
||||
} else {
|
||||
@@ -52,9 +51,9 @@ void handle_del_plugin(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST(
|
||||
aio, neu_parse_del_plugin_req_t, neu_parse_decode_del_plugin, {
|
||||
aio, neu_json_del_plugin_req_t, neu_json_decode_del_plugin_req, {
|
||||
plugin_id_t id;
|
||||
id.id_val = req->plugin_id;
|
||||
id.id_val = req->id;
|
||||
intptr_t err = neu_system_del_plugin(plugin, id);
|
||||
if (err != 0) {
|
||||
http_bad_request(aio, "{\"error\": 1}");
|
||||
@@ -68,39 +67,38 @@ void handle_update_plugin(nng_aio *aio)
|
||||
{
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST(aio, neu_parse_update_plugin_req_t,
|
||||
neu_parse_decode_update_plugin, {
|
||||
intptr_t err = neu_system_update_plugin(
|
||||
plugin, req->kind, req->node_type,
|
||||
req->plugin_name, req->plugin_lib_name);
|
||||
if (err != 0) {
|
||||
http_bad_request(aio, "{\"error\": 1}");
|
||||
} else {
|
||||
http_ok(aio, "{\"error\": 0}");
|
||||
}
|
||||
})
|
||||
REST_PROCESS_HTTP_REQUEST(
|
||||
aio, neu_json_update_plugin_req_t, neu_json_decode_update_plugin_req, {
|
||||
intptr_t err = neu_system_update_plugin(
|
||||
plugin, req->kind, req->node_type, req->name, req->lib_name);
|
||||
if (err != 0) {
|
||||
http_bad_request(aio, "{\"error\": 1}");
|
||||
} else {
|
||||
http_ok(aio, "{\"error\": 0}");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
void handle_get_plugin(nng_aio *aio)
|
||||
{
|
||||
neu_plugin_t * plugin = neu_rest_get_plugin();
|
||||
neu_parse_get_plugins_res_t plugin_res = { 0 };
|
||||
char * s_plugin_id = http_get_param(aio, "plugin_id");
|
||||
char * result = NULL;
|
||||
int index = 0;
|
||||
uint32_t plugin_id = 0;
|
||||
vector_t plugin_libs = neu_system_get_plugin(plugin);
|
||||
neu_plugin_t * plugin = neu_rest_get_plugin();
|
||||
neu_json_get_plugin_resp_t plugin_res = { 0 };
|
||||
char * s_plugin_id = http_get_param(aio, "plugin_id");
|
||||
char * result = NULL;
|
||||
int index = 0;
|
||||
uint32_t plugin_id = 0;
|
||||
vector_t plugin_libs = neu_system_get_plugin(plugin);
|
||||
|
||||
if (s_plugin_id != NULL) {
|
||||
plugin_id = atoi(s_plugin_id);
|
||||
}
|
||||
|
||||
plugin_res.n_plugin = plugin_libs.size;
|
||||
plugin_res.n_plugin_lib = plugin_libs.size;
|
||||
if (plugin_id > 0) {
|
||||
plugin_res.n_plugin = 1;
|
||||
plugin_res.n_plugin_lib = 1;
|
||||
}
|
||||
plugin_res.plugin_libs =
|
||||
calloc(plugin_res.n_plugin, sizeof(neu_parse_get_plugins_res_lib_t));
|
||||
plugin_res.plugin_libs = calloc(
|
||||
plugin_res.n_plugin_lib, sizeof(neu_json_get_plugin_resp_plugin_lib_t));
|
||||
|
||||
VECTOR_FOR_EACH(&plugin_libs, iter)
|
||||
{
|
||||
@@ -110,17 +108,17 @@ void handle_get_plugin(nng_aio *aio)
|
||||
continue;
|
||||
}
|
||||
|
||||
plugin_res.plugin_libs[index].node_type = info->node_type;
|
||||
plugin_res.plugin_libs[index].plugin_id = info->plugin_id.id_val;
|
||||
plugin_res.plugin_libs[index].kind = info->plugin_kind;
|
||||
plugin_res.plugin_libs[index].plugin_name = (char *) info->plugin_name;
|
||||
plugin_res.plugin_libs[index].plugin_lib_name =
|
||||
(char *) info->plugin_lib_name;
|
||||
plugin_res.plugin_libs[index].node_type = info->node_type;
|
||||
plugin_res.plugin_libs[index].id = info->plugin_id.id_val;
|
||||
plugin_res.plugin_libs[index].kind = info->plugin_kind;
|
||||
plugin_res.plugin_libs[index].name = (char *) info->plugin_name;
|
||||
plugin_res.plugin_libs[index].lib_name = (char *) info->plugin_lib_name;
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
neu_json_encode_by_fn(&plugin_res, neu_parse_encode_get_plugins, &result);
|
||||
neu_json_encode_by_fn(&plugin_res, neu_json_encode_get_plugin_resp,
|
||||
&result);
|
||||
|
||||
http_ok(aio, result);
|
||||
free(result);
|
||||
|
||||
+164
-111
@@ -17,185 +17,238 @@
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "json/neu_json_plugin.h"
|
||||
|
||||
int neu_parse_decode_add_plugin(char *buf, neu_parse_add_plugin_req_t **result)
|
||||
int neu_json_decode_add_plugin_req(char * buf,
|
||||
neu_json_add_plugin_req_t **result)
|
||||
{
|
||||
neu_parse_add_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_parse_add_plugin_req_t));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = "kind",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "node_type",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "lib_name",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
int ret = 0;
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
neu_json_add_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_json_add_plugin_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "node_type",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "lib_name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "kind",
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->kind = elem[0].v.val_int;
|
||||
req->node_type = elem[1].v.val_int;
|
||||
req->plugin_name = elem[2].v.val_str;
|
||||
req->plugin_lib_name = elem[3].v.val_str;
|
||||
req->node_type = req_elems[0].v.val_int;
|
||||
req->name = req_elems[1].v.val_str;
|
||||
req->lib_name = req_elems[2].v.val_str;
|
||||
req->kind = req_elems[3].v.val_int;
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
decode_fail:
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_add_plugin_free(neu_parse_add_plugin_req_t *req)
|
||||
void neu_json_decode_add_plugin_req_free(neu_json_add_plugin_req_t *req)
|
||||
{
|
||||
free(req->plugin_name);
|
||||
free(req->plugin_lib_name);
|
||||
|
||||
free(req->name);
|
||||
free(req->lib_name);
|
||||
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_decode_del_plugin(char *buf, neu_parse_del_plugin_req_t **result)
|
||||
int neu_json_decode_del_plugin_req(char * buf,
|
||||
neu_json_del_plugin_req_t **result)
|
||||
{
|
||||
neu_parse_del_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_parse_del_plugin_req_t));
|
||||
neu_json_elem_t elem[] = { {
|
||||
int ret = 0;
|
||||
|
||||
neu_json_del_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_json_del_plugin_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->plugin_id = elem[0].v.val_int;
|
||||
req->id = req_elems[0].v.val_int;
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
decode_fail:
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_del_plugin_free(neu_parse_del_plugin_req_t *req)
|
||||
void neu_json_decode_del_plugin_req_free(neu_json_del_plugin_req_t *req)
|
||||
{
|
||||
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_decode_update_plugin(char * buf,
|
||||
neu_parse_update_plugin_req_t **result)
|
||||
int neu_json_decode_get_plugin_req(char * buf,
|
||||
neu_json_get_plugin_req_t **result)
|
||||
{
|
||||
neu_parse_update_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_parse_update_plugin_req_t));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = "kind",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "node_type",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "lib_name",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
int ret = 0;
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
neu_json_get_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_json_get_plugin_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->kind = elem[0].v.val_int;
|
||||
req->node_type = elem[1].v.val_int;
|
||||
req->plugin_name = elem[2].v.val_str;
|
||||
req->plugin_lib_name = elem[3].v.val_str;
|
||||
req->id = req_elems[0].v.val_int;
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
decode_fail:
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_update_plugin_free(neu_parse_update_plugin_req_t *req)
|
||||
void neu_json_decode_get_plugin_req_free(neu_json_get_plugin_req_t *req)
|
||||
{
|
||||
free(req->plugin_name);
|
||||
free(req->plugin_lib_name);
|
||||
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_decode_get_plugins(char * buf,
|
||||
neu_parse_get_plugins_req_t **result)
|
||||
int neu_json_encode_get_plugin_resp(void *json_object, void *param)
|
||||
{
|
||||
(void) buf;
|
||||
neu_parse_get_plugins_req_t *req =
|
||||
calloc(1, sizeof(neu_parse_get_plugins_req_t));
|
||||
int ret = 0;
|
||||
neu_json_get_plugin_resp_t *resp = (neu_json_get_plugin_resp_t *) param;
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void neu_parse_decode_get_plugins_free(neu_parse_get_plugins_req_t *req)
|
||||
{
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_encode_get_plugins(void *json_object, void *param)
|
||||
{
|
||||
neu_parse_get_plugins_res_t *res = (neu_parse_get_plugins_res_t *) param;
|
||||
void * array = NULL;
|
||||
|
||||
for (int i = 0; i < res->n_plugin; i++) {
|
||||
neu_json_elem_t plugin_libs[] = {
|
||||
{
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->plugin_libs[i].plugin_id,
|
||||
},
|
||||
{
|
||||
.name = "kind",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->plugin_libs[i].kind,
|
||||
},
|
||||
void * plugin_lib_array = NULL;
|
||||
neu_json_get_plugin_resp_plugin_lib_t *p_plugin_lib = resp->plugin_libs;
|
||||
for (int i = 0; i < resp->n_plugin_lib; i++) {
|
||||
neu_json_elem_t plugin_lib_elems[] = {
|
||||
{
|
||||
.name = "node_type",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->plugin_libs[i].node_type,
|
||||
.v.val_int = p_plugin_lib->node_type,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->plugin_libs[i].plugin_name,
|
||||
.v.val_str = p_plugin_lib->name,
|
||||
},
|
||||
{
|
||||
.name = "lib_name",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->plugin_libs[i].plugin_lib_name,
|
||||
.v.val_str = p_plugin_lib->lib_name,
|
||||
},
|
||||
{
|
||||
.name = "kind",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = p_plugin_lib->kind,
|
||||
},
|
||||
{
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = p_plugin_lib->id,
|
||||
}
|
||||
};
|
||||
array = neu_json_encode_array(array, plugin_libs, 5);
|
||||
plugin_lib_array =
|
||||
neu_json_encode_array(plugin_lib_array, plugin_lib_elems,
|
||||
NEU_JSON_ELEM_SIZE(plugin_lib_elems));
|
||||
p_plugin_lib++;
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
|
||||
neu_json_elem_t resp_elems[] = { {
|
||||
.name = "plugin_libs",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = array,
|
||||
.v.val_object = plugin_lib_array,
|
||||
} };
|
||||
ret = neu_json_encode_field(json_object, resp_elems,
|
||||
NEU_JSON_ELEM_SIZE(resp_elems));
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int neu_json_decode_update_plugin_req(char * buf,
|
||||
neu_json_update_plugin_req_t **result)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
neu_json_update_plugin_req_t *req =
|
||||
calloc(1, sizeof(neu_json_update_plugin_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "node_type",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "lib_name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "kind",
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->node_type = req_elems[0].v.val_int;
|
||||
req->name = req_elems[1].v.val_str;
|
||||
req->lib_name = req_elems[2].v.val_str;
|
||||
req->kind = req_elems[3].v.val_int;
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
decode_fail:
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_json_decode_update_plugin_req_free(neu_json_update_plugin_req_t *req)
|
||||
{
|
||||
|
||||
free(req->name);
|
||||
free(req->lib_name);
|
||||
|
||||
free(req);
|
||||
}
|
||||
|
||||
+50
-47
@@ -5,34 +5,36 @@
|
||||
#include "json/neu_json_fn.h"
|
||||
#include "json/neu_json_plugin.h"
|
||||
|
||||
#include "neu_adapter.h"
|
||||
|
||||
TEST(JsonPluginTest, AddPluginDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"kind\": 1, "
|
||||
"\"node_type\": 1, "
|
||||
"\"name\": \"plugin1\", "
|
||||
"\"lib_name\": \"lib1\" }";
|
||||
neu_parse_add_plugin_req_t *req = NULL;
|
||||
neu_json_add_plugin_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_add_plugin(buf, &req));
|
||||
EXPECT_EQ(0, neu_json_decode_add_plugin_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(1, req->kind);
|
||||
EXPECT_EQ(1, req->node_type);
|
||||
EXPECT_STREQ("plugin1", req->plugin_name);
|
||||
EXPECT_STREQ("lib1", req->plugin_lib_name);
|
||||
EXPECT_STREQ("plugin1", req->name);
|
||||
EXPECT_STREQ("lib1", req->lib_name);
|
||||
|
||||
neu_parse_decode_add_plugin_free(req);
|
||||
neu_json_decode_add_plugin_req_free(req);
|
||||
}
|
||||
|
||||
TEST(JsonPluginTest, DeletePluginDecode)
|
||||
{
|
||||
char * buf = (char *) "{\"id\": 1 }";
|
||||
neu_parse_del_plugin_req_t *req = NULL;
|
||||
char * buf = (char *) "{\"id\": 1 }";
|
||||
neu_json_del_plugin_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_del_plugin(buf, &req));
|
||||
EXPECT_EQ(0, neu_json_decode_del_plugin_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(1, req->plugin_id);
|
||||
EXPECT_EQ(1, req->id);
|
||||
|
||||
neu_parse_decode_del_plugin_free(req);
|
||||
neu_json_decode_del_plugin_req_free(req);
|
||||
}
|
||||
|
||||
TEST(JsonPluginTest, UpdatePluginDecode)
|
||||
@@ -41,64 +43,65 @@ TEST(JsonPluginTest, UpdatePluginDecode)
|
||||
"\"node_type\": 2, "
|
||||
"\"name\": \"plugin1\", "
|
||||
"\"lib_name\": \"lib1\" }";
|
||||
neu_parse_update_plugin_req_t *req = NULL;
|
||||
neu_json_update_plugin_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_update_plugin(buf, &req));
|
||||
EXPECT_EQ(0, neu_json_decode_update_plugin_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(2, req->kind);
|
||||
EXPECT_EQ(2, req->node_type);
|
||||
EXPECT_STREQ("plugin1", req->plugin_name);
|
||||
EXPECT_STREQ("lib1", req->plugin_lib_name);
|
||||
EXPECT_STREQ("plugin1", req->name);
|
||||
EXPECT_STREQ("lib1", req->lib_name);
|
||||
|
||||
neu_parse_decode_update_plugin_free(req);
|
||||
neu_json_decode_update_plugin_req_free(req);
|
||||
}
|
||||
|
||||
TEST(JsonPluginTest, GetPluginEncode)
|
||||
{
|
||||
char *buf =
|
||||
(char *) "{\"plugin_libs\": [{\"id\": 123, \"kind\": 1, \"node_type\": "
|
||||
"1, \"name\": \"plugin1\", \"lib_name\": \"lib1\"}, {\"id\": "
|
||||
"456, \"kind\": 1, \"node_type\": 1, \"name\": \"plugin2\", "
|
||||
"\"lib_name\": \"lib2\"}, {\"id\": 789, \"kind\": 1, "
|
||||
"\"node_type\": 1, \"name\": \"plugin3\", \"lib_name\": "
|
||||
"\"lib3\"}]}";
|
||||
(char *) "{\"plugin_libs\": [{\"node_type\": 1, \"name\": \"plugin1\", "
|
||||
"\"lib_name\": \"lib1\", \"kind\": 1, \"id\": 123}, "
|
||||
"{\"node_type\": 1, \"name\": \"plugin2\", \"lib_name\": "
|
||||
"\"lib2\", \"kind\": 1, \"id\": 456}, {\"node_type\": 1, "
|
||||
"\"name\": \"plugin3\", \"lib_name\": \"lib3\", \"kind\": 1, "
|
||||
"\"id\": 789}]}";
|
||||
char *result = NULL;
|
||||
|
||||
neu_parse_get_plugins_res_t res = {
|
||||
.n_plugin = 3,
|
||||
neu_json_get_plugin_resp_t res = {
|
||||
.n_plugin_lib = 3,
|
||||
};
|
||||
|
||||
res.plugin_libs = (neu_parse_get_plugins_res_lib_t *) calloc(
|
||||
3, sizeof(neu_parse_get_plugins_res_lib_t));
|
||||
res.plugin_libs = (neu_json_get_plugin_resp_plugin_lib_t *) calloc(
|
||||
3, sizeof(neu_json_get_plugin_resp_plugin_lib_t));
|
||||
|
||||
res.plugin_libs[0].plugin_id = 123;
|
||||
res.plugin_libs[0].kind = PLUGIN_KIND_SYSTEM;
|
||||
res.plugin_libs[0].node_type = NEU_NODE_TYPE_DRIVER;
|
||||
res.plugin_libs[0].plugin_name = strdup((char *) "plugin1");
|
||||
res.plugin_libs[0].plugin_lib_name = strdup((char *) "lib1");
|
||||
res.plugin_libs[0].id = 123;
|
||||
res.plugin_libs[0].kind = PLUGIN_KIND_SYSTEM;
|
||||
res.plugin_libs[0].node_type = NEU_NODE_TYPE_DRIVER;
|
||||
res.plugin_libs[0].name = strdup((char *) "plugin1");
|
||||
res.plugin_libs[0].lib_name = strdup((char *) "lib1");
|
||||
|
||||
res.plugin_libs[1].plugin_id = 456;
|
||||
res.plugin_libs[1].kind = PLUGIN_KIND_SYSTEM;
|
||||
res.plugin_libs[1].node_type = NEU_NODE_TYPE_DRIVER;
|
||||
res.plugin_libs[1].plugin_name = strdup((char *) "plugin2");
|
||||
res.plugin_libs[1].plugin_lib_name = strdup((char *) "lib2");
|
||||
res.plugin_libs[1].id = 456;
|
||||
res.plugin_libs[1].kind = PLUGIN_KIND_SYSTEM;
|
||||
res.plugin_libs[1].node_type = NEU_NODE_TYPE_DRIVER;
|
||||
res.plugin_libs[1].name = strdup((char *) "plugin2");
|
||||
res.plugin_libs[1].lib_name = strdup((char *) "lib2");
|
||||
|
||||
res.plugin_libs[2].plugin_id = 789;
|
||||
res.plugin_libs[2].kind = PLUGIN_KIND_SYSTEM;
|
||||
res.plugin_libs[2].node_type = NEU_NODE_TYPE_DRIVER;
|
||||
res.plugin_libs[2].plugin_name = strdup((char *) "plugin3");
|
||||
res.plugin_libs[2].plugin_lib_name = strdup((char *) "lib3");
|
||||
res.plugin_libs[2].id = 789;
|
||||
res.plugin_libs[2].kind = PLUGIN_KIND_SYSTEM;
|
||||
res.plugin_libs[2].node_type = NEU_NODE_TYPE_DRIVER;
|
||||
res.plugin_libs[2].name = strdup((char *) "plugin3");
|
||||
res.plugin_libs[2].lib_name = strdup((char *) "lib3");
|
||||
|
||||
EXPECT_EQ(
|
||||
0, neu_json_encode_by_fn(&res, neu_parse_encode_get_plugins, &result));
|
||||
0,
|
||||
neu_json_encode_by_fn(&res, neu_json_encode_get_plugin_resp, &result));
|
||||
EXPECT_STREQ(buf, result);
|
||||
|
||||
free(res.plugin_libs[0].plugin_name);
|
||||
free(res.plugin_libs[0].plugin_lib_name);
|
||||
free(res.plugin_libs[1].plugin_name);
|
||||
free(res.plugin_libs[1].plugin_lib_name);
|
||||
free(res.plugin_libs[2].plugin_name);
|
||||
free(res.plugin_libs[2].plugin_lib_name);
|
||||
free(res.plugin_libs[0].name);
|
||||
free(res.plugin_libs[0].lib_name);
|
||||
free(res.plugin_libs[1].name);
|
||||
free(res.plugin_libs[1].lib_name);
|
||||
free(res.plugin_libs[2].name);
|
||||
free(res.plugin_libs[2].lib_name);
|
||||
free(res.plugin_libs);
|
||||
|
||||
free(result);
|
||||
|
||||
Reference in New Issue
Block a user