summaryrefslogtreecommitdiffstats
path: root/ucs2-afb/ucs_binding.c
diff options
context:
space:
mode:
authorTobias Jahnke <tobias.jahnke@microchip.com>2017-12-14 09:03:20 +0100
committerTobias Jahnke <tobias.jahnke@microchip.com>2017-12-14 09:03:20 +0100
commit6eb714dcedb35abf97b939df1965628c068ab6ce (patch)
tree523f8f17831b0f76dc2fe25a0bdaa4f96579f407 /ucs2-afb/ucs_binding.c
parent5b19a1a8e03704ff178c9f605530c3e3f8fa1134 (diff)
ucs_binding.c: Fix compiler warnings
Bug-AGL: SPEC-1177 Fix compiler warnings due to the use of deprecated json-c functions. Change-Id: I8fc783af7f1cbf436d9a979395b6f6cf3c5d511d Signed-off-by: Tobias Jahnke <tobias.jahnke@microchip.com>
Diffstat (limited to 'ucs2-afb/ucs_binding.c')
-rw-r--r--ucs2-afb/ucs_binding.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c
index ca1f756..b72aca9 100644
--- a/ucs2-afb/ucs_binding.c
+++ b/ucs2-afb/ucs_binding.c
@@ -584,28 +584,34 @@ STATIC void ucs2_writei2c_cmd(struct afb_req request, json_object *j_obj) {
uint8_t i2c_data_sz = 0;
uint16_t node_addr = 0;
struct afb_req *async_req_ptr = NULL;
+ json_object *j_tmp;
+ json_bool key_found;
- node_addr = (uint16_t)json_object_get_int(json_object_object_get(j_obj, "node"));
- AFB_NOTICE("node_address: 0x%02X", node_addr);
-
- if (node_addr == 0) {
- afb_req_fail_f(request, "query-params","params wrong or missing");
+ if (json_object_object_get_ex(j_obj, "node", &j_tmp)) {
+ node_addr = (uint16_t)json_object_get_int(j_tmp);
+ AFB_NOTICE("node_address: 0x%02X", node_addr);
+ if (node_addr == 0) {
+ afb_req_fail_f(request, "query-params","param node invalid type");
+ goto OnErrorExit;
+ }
+ }
+ else {
+ afb_req_fail_f(request, "query-params","param node missing");
goto OnErrorExit;
}
- if (json_object_get_type(json_object_object_get(j_obj, "data"))==json_type_array) {
- int size = json_object_array_length(json_object_object_get(j_obj, "data"));
+ key_found = json_object_object_get_ex(j_obj, "data", &j_tmp);
+ if (key_found && (json_object_get_type(j_tmp)==json_type_array)) {
+ int size = json_object_array_length(j_tmp);
if ((size > 0) && (size <= I2C_MAX_DATA_SZ)) {
int32_t i;
int32_t val;
struct json_object *j_elem;
- struct json_object *j_arr = json_object_object_get(j_obj, "data");
for (i = 0; i < size; i++) {
-
- j_elem = json_object_array_get_idx(j_arr, i);
+ j_elem = json_object_array_get_idx(j_tmp, i);
val = json_object_get_int(j_elem);
if ((val < 0) && (val > 0xFF)){
i = 0;
@@ -677,6 +683,10 @@ STATIC void ucs2_sendmessage_cmd(struct afb_req request, json_object *j_obj) {
if (json_object_object_get_ex(j_obj, "node", &j_tmp)) {
node_addr = (uint16_t)json_object_get_int(j_tmp);
AFB_NOTICE("node_address: 0x%02X", node_addr);
+ if (node_addr == 0) {
+ afb_req_fail_f(request, "query-params","param node invalid type");
+ goto OnErrorExit;
+ }
}
else {
afb_req_fail_f(request, "query-params","param node missing");
@@ -684,8 +694,14 @@ STATIC void ucs2_sendmessage_cmd(struct afb_req request, json_object *j_obj) {
}
if (json_object_object_get_ex(j_obj, "msgid", &j_tmp)) {
- msg_id = (uint16_t)json_object_get_int(j_tmp);
- AFB_NOTICE("msgid: 0x%02X", msg_id);
+ if (json_object_get_type(j_tmp) == json_type_int) {
+ msg_id = (uint16_t)json_object_get_int(j_tmp);
+ AFB_NOTICE("msgid: 0x%02X", msg_id);
+ }
+ else {
+ afb_req_fail_f(request, "query-params","param msgid invalid type");
+ goto OnErrorExit;
+ }
}
else {
afb_req_fail_f(request, "query-params","param msgid missing");