From: Jiwan Kim Date: Thu, 26 Jan 2017 06:52:01 +0000 (+0900) Subject: Fix handling GVariant byte array X-Git-Tag: submit/tizen/20170512.045637~43 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fzigbee-manager.git;a=commitdiff_plain;h=b5e80cc6e74dce8530f14650f1de01402dfbd687 Fix handling GVariant byte array - GDbus XML codegen replaces 'ay' variant (written XML introspection file) into '^ay' variant. - If there is '0x0' inside of byte array, array would be broken. (it acts as a null terminator) Change-Id: Iedbbd014ce87d4286a5f3221a0156e8cbf696025 Signed-off-by: Jiwan Kim --- diff --git a/common/include/zigbee_service_type.h b/common/include/zigbee_service_type.h index 4de51df..c1c33ce 100644 --- a/common/include/zigbee_service_type.h +++ b/common/include/zigbee_service_type.h @@ -111,6 +111,15 @@ typedef struct { char node_type; /**< Node Type */ } ZigbeeServiceServiceNodeType_t; +/** + * @brief Definition for service get mac structure. + * @since_tizen 3.0 + */ +typedef struct { + int result; /**< Result */ + char eui64[ZIGBEE_EUI64_SIZE]; /**< EUI64 (an IEEE address) */ +} ZigbeeServiceGetMac_t; + /* -------------------------------------------------------------------------------------- * For Notifications * -------------------------------------------------------------------------------------*/ diff --git a/zigbee-daemon/zigbee-interface/introspection/service.xml b/zigbee-daemon/zigbee-interface/introspection/service.xml index 148bebf..7b1e3d2 100644 --- a/zigbee-daemon/zigbee-interface/introspection/service.xml +++ b/zigbee-daemon/zigbee-interface/introspection/service.xml @@ -48,7 +48,7 @@ - + diff --git a/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_service.c b/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_service.c index 988e961..46fa03e 100644 --- a/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_service.c +++ b/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_service.c @@ -63,10 +63,10 @@ static void on_service_enable_resp(ZigBeeServiceInterface *service_interface, } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_enable(service_object, invocation, payload->result, payload->enabled); @@ -138,10 +138,10 @@ static void on_service_disable_resp(ZigBeeServiceInterface *service_interface, } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_disable(service_object, invocation, payload->result); @@ -210,10 +210,10 @@ static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interfac } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_zb_hw_reset(service_object, invocation, payload->result); @@ -282,10 +282,10 @@ static void on_service_form_network_resp(ZigBeeServiceInterface *service_interfa } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_form_network(service_object, invocation, payload->result); @@ -354,10 +354,10 @@ static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_coex_start(service_object, invocation, payload->result); @@ -433,10 +433,10 @@ static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface, } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_coex_stop(service_object, invocation, payload->result); @@ -505,10 +505,10 @@ static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interf } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_leave_network(service_object, invocation, payload->result); @@ -570,7 +570,7 @@ static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_int ZigbeeServiceGetNetworkInfo_t *payload = (ZigbeeServiceGetNetworkInfo_t*)resp_data; - GVariant *v_eui64; + GVariant *v_eui64 = NULL; NOT_USED(service_interface); NOT_USED(request_id); @@ -581,10 +581,10 @@ static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_int } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"), payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL); @@ -658,10 +658,10 @@ static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interfac } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_permit_join(service_object, invocation, payload->result); @@ -739,10 +739,10 @@ static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interf } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_leave_request(service_object, invocation, payload->result); @@ -830,10 +830,10 @@ static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_inte } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); /* To-To : zigbee_service_complete_get_device_list */ //zigbee_service_complete_get_device_list(service_object, invocation, resp_data); @@ -892,8 +892,11 @@ static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface, ZigbeeService *service_object; GDBusMethodInvocation *invocation; + ZigbeeServiceGetMac_t *payload = + (ZigbeeServiceGetMac_t*)resp_data; + + GVariant *v_eui64 = NULL; - NOT_USED(cb_data); NOT_USED(service_interface); NOT_USED(request_id); @@ -904,16 +907,18 @@ static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface, } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); + + v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"), + payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL); - /* Todo : plugin must load resp_data as char pointer */ - //zigbee_service_complete_get_mac(service_object, invocation, resp_data); + zigbee_service_complete_get_mac(service_object, invocation, payload->result, + v_eui64); g_free(cb_data); - } static gboolean on_service_get_mac(ZigbeeService *service_object, @@ -968,7 +973,6 @@ static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_inte ZigbeeService *service_object; GDBusMethodInvocation *invocation; - NOT_USED(cb_data); NOT_USED(service_interface); NOT_USED(request_id); @@ -979,10 +983,10 @@ static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_inte } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); /* To-Do : zigbee_service_complete_get_device_list */ //zigbee_service_complete_get_device_info(service_object, invocation, resp_data); @@ -1042,7 +1046,6 @@ static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_in ZigbeeService *service_object; GDBusMethodInvocation *invocation; - NOT_USED(cb_data); NOT_USED(service_interface); NOT_USED(request_id); @@ -1053,10 +1056,10 @@ static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_in } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); /* To fix : end-points must be changed gchar* -> GVariant ay */ //zigbee_service_complete_get_endpoint_list(service_object, invocation, resp_data); @@ -1131,7 +1134,6 @@ static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_int ZigbeeService *service_object; GDBusMethodInvocation *invocation; - NOT_USED(cb_data); NOT_USED(service_interface); NOT_USED(request_id); @@ -1142,10 +1144,10 @@ static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_int } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); /* To-Do : zigbee_service_complete_get_cluster_list */ //zigbee_service_complete_get_cluster_list(service_object, invocation, resp_data); @@ -1221,10 +1223,9 @@ static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interf ZigbeeService *service_object; GDBusMethodInvocation *invocation; - ZigbeeServiceServiceNodeType_t *payload = + ZigbeeServiceServiceNodeType_t *payload = (ZigbeeServiceServiceNodeType_t *)resp_data; - NOT_USED(cb_data); NOT_USED(service_interface); NOT_USED(request_id); @@ -1235,10 +1236,10 @@ static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interf } service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); - zblib_check_null_ret("service_object", service_object); + zblib_check_null_free_and_ret("service_object", service_object, cb_data); invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); - zblib_check_null_ret("invocation", invocation); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); zigbee_service_complete_get_node_type(service_object, invocation, payload->result, payload->node_type); @@ -1323,11 +1324,11 @@ void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface * switch(noti_id) { case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: { - ZigbeeServiceServiceFormNetworkDone_t *panid_t = + ZigbeeServiceServiceFormNetworkDone_t *panid_t = (ZigbeeServiceServiceFormNetworkDone_t*)noti_data; Z_LOGD("form_network_done : [0x%X]", panid_t->pan_id); - + zigbee_service_emit_form_network_done(service_object, panid_t->pan_id); } break; diff --git a/zigbee-daemon/zigbee-interface/src/zigbee_service_interface_common.c b/zigbee-daemon/zigbee-interface/src/zigbee_service_interface_common.c index 1c0a2bf..e967880 100644 --- a/zigbee-daemon/zigbee-interface/src/zigbee_service_interface_common.c +++ b/zigbee-daemon/zigbee-interface/src/zigbee_service_interface_common.c @@ -72,19 +72,15 @@ void zigbee_service_dbus_interface_destroy_resp_cb_data(ZigbeeServiceInterfaceRe void *zigbee_service_dbus_interface_ref_interface_object(ZigbeeServiceInterfaceRespCbData_t *resp_cb_data) { - if (resp_cb_data) - return resp_cb_data->interface_object; - - return NULL; + zblib_check_null_ret_error("resp_cb_data", resp_cb_data, NULL); + return resp_cb_data->interface_object; } GDBusMethodInvocation * zigbee_service_dbus_interface_ref_invocation(ZigbeeServiceInterfaceRespCbData_t *resp_cb_data) { - if (resp_cb_data) - return resp_cb_data->invocation; - - return NULL; + zblib_check_null_ret_error("resp_cb_data", resp_cb_data, NULL); + return resp_cb_data->invocation; } gboolean zigbee_service_dbus_interface_dispatch_request(ZigBeeServiceInterface *service_interface, diff --git a/zigbee-daemon/zigbee-lib/include/zblib_common.h b/zigbee-daemon/zigbee-lib/include/zblib_common.h index 2e08098..0f46d98 100644 --- a/zigbee-daemon/zigbee-lib/include/zblib_common.h +++ b/zigbee-daemon/zigbee-lib/include/zblib_common.h @@ -35,4 +35,12 @@ } \ } while (FALSE) +#define zblib_check_null_free_and_ret(name, value, data) do { \ + if (G_UNLIKELY(NULL == (value))) { \ + Z_LOGE("%s is NULL", name); \ + g_free(data); \ + return; \ + } \ +} while (FALSE) + #endif /* __ZIGBEE_LIB_COMMON_H__ */