From e4266746d07e83533954e92ad2927574cdca88df Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Wed, 16 Mar 2022 15:49:41 +0800 Subject: [PATCH] Add license json-api parser code --- include/json/neu_json_license.h | 46 +++++++++++++++++++++++ src/parser/neu_json_license.c | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 include/json/neu_json_license.h create mode 100644 src/parser/neu_json_license.c diff --git a/include/json/neu_json_license.h b/include/json/neu_json_license.h new file mode 100644 index 00000000..ceb9980e --- /dev/null +++ b/include/json/neu_json_license.h @@ -0,0 +1,46 @@ +/** + * NEURON IIoT System for Industry 4.0 + * Copyright (C) 2020-2022 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. + **/ + +/* + * DO NOT EDIT THIS FILE MANUALLY! + * It was automatically generated by `json-autotype`. + */ + +#ifndef _NEU_JSON_API_NEU_JSON_LICENSE_H_ +#define _NEU_JSON_API_NEU_JSON_LICENSE_H_ + +#include "json/json.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char *license; +} neu_json_set_license_req_t; + +int neu_json_decode_set_license_req(char * buf, + neu_json_set_license_req_t **result); +void neu_json_decode_set_license_req_free(neu_json_set_license_req_t *req); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/parser/neu_json_license.c b/src/parser/neu_json_license.c new file mode 100644 index 00000000..47a13ac0 --- /dev/null +++ b/src/parser/neu_json_license.c @@ -0,0 +1,66 @@ +/** + * NEURON IIoT System for Industry 4.0 + * Copyright (C) 2020-2022 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. + **/ + +/* + * DO NOT EDIT THIS FILE MANUALLY! + * It was automatically generated by `json-autotype`. + */ + +#include +#include + +#include "json/json.h" + +#include "json/neu_json_license.h" + +int neu_json_decode_set_license_req(char * buf, + neu_json_set_license_req_t **result) +{ + int ret = 0; + neu_json_set_license_req_t *req = + calloc(1, sizeof(neu_json_set_license_req_t)); + + neu_json_elem_t req_elems[] = { { + .name = "license", + .t = NEU_JSON_STR, + } }; + ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems); + if (ret != 0) { + goto decode_fail; + } + + req->license = req_elems[0].v.val_str; + + *result = req; + return ret; + +decode_fail: + if (req != NULL) { + free(req); + } + return -1; +} + +void neu_json_decode_set_license_req_free(neu_json_set_license_req_t *req) +{ + + free(req->license); + + free(req); +}