X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-httpproxy%2Fbt-httpproxy.c;h=2035160ba63b64718d16dd19f730f2986916665a;hb=ada9ae03059e4bd38ced9b3af20dbc5a5ef78757;hp=5efd71ae9b745d247e4e3c568f22aff95004aab6;hpb=27684cccaeba4696b5a05b8bc2dc0d3e6618f706;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-httpproxy/bt-httpproxy.c b/bt-httpproxy/bt-httpproxy.c index 5efd71a..2035160 100644 --- a/bt-httpproxy/bt-httpproxy.c +++ b/bt-httpproxy/bt-httpproxy.c @@ -44,8 +44,8 @@ char *http_status_desc_obj_path = NULL; char *http_security_obj_path = NULL; static GMainLoop *main_loop; -static int property_sub_id = -1; -static int adapter_sub_id = -1; +static guint property_sub_id; +static guint adapter_sub_id; static http_request_state req_state; #ifdef HPS_GATT_DB @@ -69,7 +69,6 @@ static GSList *hps_char_list = NULL; static GDBusConnection *conn; static GDBusConnection *g_conn; static guint g_owner_id = 0; -GDBusNodeInfo *hps_node_info = NULL; char *g_uri = NULL; char *g_header = NULL; @@ -96,18 +95,17 @@ static void _bt_hps_set_char_value(const char *obj_path, const char* value, int static void _hps_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str) { - int i = 0; - unsigned int addr[BLUETOOTH_ADDRESS_LENGTH] = { 0, }; + char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5; if (addr_str == NULL || addr_str[0] == '\0') return; - i = sscanf(addr_str, "%X:%X:%X:%X:%X:%X", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]); - if (i != BLUETOOTH_ADDRESS_LENGTH) - BT_ERR("Invalid format string - [%s]", addr_str); - - for (i = 0; i < BLUETOOTH_ADDRESS_LENGTH; i++) - addr_hex->addr[i] = (unsigned char)addr[i]; + addr_hex->addr[0] = strtol(addr_str, &ptr5, 16); + addr_hex->addr[1] = strtol(ptr5 + 1, &ptr4, 16); + addr_hex->addr[2] = strtol(ptr4 + 1, &ptr3, 16); + addr_hex->addr[3] = strtol(ptr3 + 1, &ptr2, 16); + addr_hex->addr[4] = strtol(ptr2 + 1, &ptr1, 16); + addr_hex->addr[5] = strtol(ptr1 + 1, NULL, 16); } static char *__hps_convert_uuid_to_uuid128(const char *uuid) @@ -118,15 +116,18 @@ static char *__hps_convert_uuid_to_uuid128(const char *uuid) len = strlen(uuid); switch (len) { - case 4: /* UUID 16bits */ + case 4: + /* UUID 16bits */ uuid128 = g_strdup_printf("0000%s-0000-1000-8000-00805F9B34FB", uuid); break; - case 8: /* UUID 32bits */ + case 8: + /* UUID 32bits */ uuid128 = g_strdup_printf("%s-0000-1000-8000-00805F9B34FB", uuid); break; - case 36: /* UUID 128bits */ + case 36: + /* UUID 128bits */ uuid128 = strdup(uuid); break; @@ -200,6 +201,7 @@ static const GDBusInterfaceVTable hps_method_table = { static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { + GDBusNodeInfo *node_info = NULL; guint object_id; GError *error = NULL; @@ -207,14 +209,21 @@ static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *na g_conn = connection; + node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error); + if (!node_info) { + BT_ERR("Failed to install: %s", error->message); + g_clear_error(&error); + return; + } + object_id = g_dbus_connection_register_object(connection, BT_HPS_OBJECT_PATH, - hps_node_info->interfaces[0], + node_info->interfaces[0], &hps_method_table, NULL, NULL, &error); + g_dbus_node_info_unref(node_info); if (object_id == 0) { BT_ERR("Failed to register method table: %s", error->message); g_error_free(error); - g_dbus_node_info_unref(hps_node_info); } return; @@ -235,7 +244,6 @@ static void _bt_hps_on_name_lost(GDBusConnection *connection, BT_DBG(""); g_object_unref(g_conn); g_conn = NULL; - g_dbus_node_info_unref(hps_node_info); g_bus_unown_name(g_owner_id); return; @@ -243,17 +251,10 @@ static void _bt_hps_on_name_lost(GDBusConnection *connection, int _bt_hps_register_interface(void) { - GError *error = NULL; guint owner_id; BT_DBG(""); - hps_node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error); - if (!hps_node_info) { - BT_ERR("Failed to install: %s", error->message); - return BLUETOOTH_ERROR_INTERNAL; - } - owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, BT_HPS_SERVICE_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, @@ -271,7 +272,6 @@ void _bt_hps_unregister_interface(void) g_object_unref(g_conn); g_conn = NULL; - g_dbus_node_info_unref(hps_node_info); g_bus_unown_name(g_owner_id); return; @@ -318,28 +318,24 @@ static void _bt_hps_set_char_value(const char *obj_path, const char* value, int if (tmp->data) { struct hps_char_info *char_info = tmp->data; if (!g_strcmp0(char_info->char_path, obj_path)) { - gchar *str = NULL; - if (offset > 0) { - str = g_strdup(char_info->char_value); - char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length); + gchar *data = NULL; + if (char_info->char_value == NULL) { + char_info->char_value = g_malloc0(offset + value_length); + char_info->value_length = offset + value_length; + } else if (char_info->value_length >= offset + value_length) { + /* Just change from offset */ + memcpy(&char_info->char_value[offset], value, value_length); } else { - char_info->char_value = g_try_realloc(char_info->char_value, value_length); + /* Values crossing pervious allocated limit realloc */ + data = g_memdup(char_info->char_value, char_info->value_length); + char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length); + memcpy(char_info->char_value, data, char_info->value_length); + memcpy(&char_info->char_value[offset], value, value_length); + char_info->value_length = offset + value_length; + g_free(data); } - if (char_info->char_value) { - if (str) { - memcpy(char_info->char_value, str, strlen(str)); - g_free(str); - } - if (offset > 0) { - memcpy(&char_info->char_value[offset], value, value_length); - char_info->value_length = offset + value_length; - } else { - memcpy(char_info->char_value, value, value_length); - char_info->value_length = value_length; - } - hps_char_list = g_slist_insert_sorted(hps_char_list, + hps_char_list = g_slist_insert_sorted(hps_char_list, char_info, char_info_cmp); - } return; } } @@ -633,9 +629,10 @@ void _bt_hps_head_response_cb(SoupSession *session, // Write Data to Status Code Characteristic #ifdef HPS_GATT_DB data_status = (hdr_len > MAX_ENTITY_LENGTH) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED; - if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) { + + if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) _bt_hps_set_notify_read_status(http_hdr_obj_path, 0, data_status, http_status); - } + _bt_hps_send_status_notification(http_status, data_status, &addr_hex); #else status[0] = http_status & 0x0F; @@ -755,9 +752,10 @@ void _bt_hps_get_response_cb(SoupSession *session, // Write Data to Status Code Characteristic #ifdef HPS_GATT_DB data_status = (body->length > MAX_ENTITY_LENGTH) ? DS_BODY_TRUNCATED : DS_BODY_RECEIVED; - if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) { + + if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) _bt_hps_set_notify_read_status(http_entity_obj_path, 0, data_status, http_status); - } + _bt_hps_send_status_notification(http_status, data_status, &addr_hex); #else @@ -806,9 +804,10 @@ void _bt_hps_get_response_cb(SoupSession *session, // Write Data to Status Code Characteristic #ifdef HPS_GATT_DB data_status = (hdr_len > MAX_HEADER_LENGTH) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED; - if (data_status == DS_HEADER_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) { + + if (data_status == DS_HEADER_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) _bt_hps_set_notify_read_status(http_hdr_obj_path, 0, data_status, http_status); - } + _bt_hps_send_status_notification(http_status, data_status, &addr_hex); #else status[0] = http_status & 0x0F; @@ -1149,11 +1148,6 @@ void _bt_hps_gatt_char_property_changed_event(GVariant *msg, while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &var))) { - if (property == NULL) { - BT_ERR("Property NULL"); - return; - } - if (!g_strcmp0(property, "WriteValue")) { int len = 0; BT_INFO("WriteValue"); @@ -1254,7 +1248,7 @@ void _bt_hps_gatt_char_property_changed_event(GVariant *msg, if (property == NULL) { BT_ERR("Property NULL"); - return; + break; } if (strcasecmp(property, "ChangedValue") == 0) { @@ -1270,15 +1264,6 @@ void _bt_hps_gatt_char_property_changed_event(GVariant *msg, g_byte_array_append(gp_byte_array, (const guint8 *)g_variant_get_data(val), len); if (gp_byte_array->len != 0) { - GVariant *byte_array = NULL; - byte_array = g_variant_new_from_data( - G_VARIANT_TYPE_BYTESTRING, - gp_byte_array->data, - gp_byte_array->len, - TRUE, NULL, NULL); - param = g_variant_new("(is@ay)", result, char_handle, - byte_array); - if (strcmp(path, http_uri_obj_path)) { //Retrive URI _bt_hps_uri_write_cb(NULL, len); @@ -1421,9 +1406,22 @@ int _bt_hps_init_event_receiver() void _bt_hps_deinit_event_receiver(void) { BT_DBG(""); - g_dbus_connection_signal_unsubscribe(conn, property_sub_id); - g_dbus_connection_signal_unsubscribe(conn, adapter_sub_id); + + if (conn == NULL) + return; + + if (property_sub_id > 0) { + g_dbus_connection_signal_unsubscribe(conn, property_sub_id); + property_sub_id = 0; + } + + if (adapter_sub_id) { + g_dbus_connection_signal_unsubscribe(conn, adapter_sub_id); + adapter_sub_id = 0; + } + conn = NULL; + return; } @@ -1759,7 +1757,7 @@ int main(void) return -5; } - hps_soup_session = soup_session_async_new(); + hps_soup_session = soup_session_new(); if (hps_soup_session == NULL) { BT_ERR("Failed to soup_session_async_new"); return -6;