X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-obex-server.c;h=4363a7e8813c2a96a93310af7d97dd562865f9eb;hb=3dc948154117f63053dc0ee386749b8d00e21097;hp=296d1c6801d41ce063d1eb3151fea262fb11445f;hpb=f8cd843634b70ab96c83bd552606c197fcf5decc;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-obex-server.c b/bt-service/bt-service-obex-server.c old mode 100755 new mode 100644 index 296d1c6..4363a7e --- a/bt-service/bt-service-obex-server.c +++ b/bt-service/bt-service-obex-server.c @@ -1,11 +1,5 @@ /* - * Bluetooth-frwk - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hocheol Seo - * Girishashok Joshi - * Chanyeol Park + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +15,19 @@ * */ -#include -#include #include #include #include #include #include +#ifdef TIZEN_DPM_ENABLE +#include "bt-service-dpm.h" +#endif + #include +#include + #include "bluetooth-api.h" #include "bt-internal-types.h" @@ -40,12 +38,17 @@ #include "bt-service-obex-server.h" #include "bt-service-agent.h" +#define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */ #define BT_OBEX_SERVER_AGENT_PATH "/org/obex/server_agent" #define BT_OBEX_SERVICE "org.bluez.obex" #define BT_OBEX_MANAGER "org.bluez.obex.AgentManager1" #define BT_OBEX_PATH "/org/bluez/obex" +#define BT_OBEX_PATH_PREFIX "/opt/usr/media" +#define BT_OBEX_DEFAULT_PATH "/opt/usr/home/owner/media" +#define BT_OBEX_PATH_MAX_LENGTH 255 + typedef struct { char *filename; @@ -55,17 +58,19 @@ typedef struct { char *device_name; int transfer_id; gint64 file_size; + gint64 progress; char *address; } bt_transfer_info_t; typedef struct { - DBusGMethodInvocation *reply_context; - gint64 file_size; + GDBusMethodInvocation *reply_context; + guint64 file_size; char *filename; char *file_path; char *device_name; char *transfer_path; char *address; + unsigned char contact_auth_info[5]; } bt_auth_info_t; typedef struct { @@ -75,8 +80,7 @@ typedef struct { } bt_server_info_t; typedef struct { - BtObexAgent *obex_agent; - DBusGProxy *proxy; + GDBusProxy *proxy; int server_type; int accept_id; bt_auth_info_t *auth_info; @@ -84,8 +88,35 @@ typedef struct { bt_server_info_t *custom_server; } bt_obex_agent_info_t; +typedef struct { + char *path; + char *address; + gboolean authorized; +} bt_session_info_t; + static GSList *transfers; static bt_obex_agent_info_t agent_info; +static GSList *session_list = NULL; + +static bt_session_info_t *__bt_find_session_by_path(char *transfer_path) +{ + GSList *l; + bt_session_info_t *session; + + retv_if(transfer_path == NULL, NULL); + + for (l = session_list; l != NULL; l = l->next) { + session = l->data; + + if (session == NULL) + continue; + + if (g_strcmp0(session->path, transfer_path) == 0) + return session; + } + + return NULL; +} static GQuark __bt_obex_error_quark(void) { @@ -191,21 +222,22 @@ static void __bt_free_transfer_info(bt_transfer_info_t *transfer_info) void _bt_obex_check_pending_transfer(const char *address) { BT_DBG("+"); + GVariant *param = NULL; bt_transfer_info_t *transfer_info = __bt_find_transfer_by_address(address); if (transfer_info != NULL) { int result = BLUETOOTH_ERROR_CANCEL; + param = g_variant_new("(issssstii)", result, + transfer_info->filename, + transfer_info->type, + transfer_info->device_name, + transfer_info->file_path, + transfer_info->address, + transfer_info->file_size, + transfer_info->transfer_id, + agent_info.server_type); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &transfer_info->filename, - DBUS_TYPE_STRING, &transfer_info->type, - DBUS_TYPE_STRING, &transfer_info->device_name, - DBUS_TYPE_STRING, &transfer_info->file_path, - DBUS_TYPE_UINT64, &transfer_info->file_size, - DBUS_TYPE_INT32, &transfer_info->transfer_id, - DBUS_TYPE_INT32, &agent_info.server_type, - DBUS_TYPE_INVALID); - + param); transfers = g_slist_remove(transfers, transfer_info); __bt_free_transfer_info(transfer_info); } @@ -216,44 +248,145 @@ static char *__bt_get_remote_device_name(const char *bdaddress) { char *device_path = NULL; char *name = NULL; - GHashTable *hash = NULL; - GValue *value; - DBusGProxy *device_proxy; - DBusGProxy *adapter_proxy; - DBusGConnection *conn; + GVariant *value; + GVariant *result = NULL; + GError *err = NULL; + GDBusProxy *device_proxy; + GDBusConnection *conn; retv_if(bdaddress == NULL, NULL); - adapter_proxy = _bt_get_adapter_proxy(); - retv_if(adapter_proxy == NULL, NULL); - device_path = _bt_get_device_object_path((char *)bdaddress); retv_if(device_path == NULL, NULL); - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); retv_if(conn == NULL, NULL); - - device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME, - device_path, BT_PROPERTIES_INTERFACE); + BT_INFO("Device_path %s", device_path); + device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_BLUEZ_NAME, + device_path, + BT_PROPERTIES_INTERFACE, + NULL, &err); g_free(device_path); retv_if(device_proxy == NULL, NULL); - dbus_g_proxy_call(device_proxy, "GetAll", NULL, - G_TYPE_STRING, BT_DEVICE_INTERFACE, - G_TYPE_INVALID, - dbus_g_type_get_map("GHashTable", G_TYPE_STRING, - G_TYPE_VALUE), &hash, G_TYPE_INVALID); - + result = g_dbus_proxy_call_sync(device_proxy, "GetAll", + g_variant_new("(s)", BT_DEVICE_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &err); + if (err) { + BT_ERR("DBus Error : %s", err->message); + g_clear_error(&err); + return NULL; + } + if (result == NULL) { + BT_ERR("g_dbus_proxy_call_sync function return NULL"); + return NULL; + } + g_variant_get(result, "(@a{sv})", &value); + + if (value) { + GVariant *temp_value = g_variant_lookup_value(value, "Alias", + G_VARIANT_TYPE_STRING); + g_variant_get(temp_value, "s", &name); + if (temp_value) + g_variant_unref(temp_value); + + if (name != NULL) + DBG_SECURE("Alias Name [%s]", name); + else { + temp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING); + g_variant_get(temp_value, "s", &name); + if (temp_value) + g_variant_unref(temp_value); + DBG_SECURE("Name = %s", name); + } + } + g_variant_unref(result); g_object_unref(device_proxy); + return name; +} - if (hash != NULL) { - value = g_hash_table_lookup(hash, "Alias"); - name = value ? g_value_dup_string(value) : NULL; - g_hash_table_destroy(hash); +static void __bt_get_remote_device_name_authinfo(const char *bdaddress, + char **device_name, unsigned char *auth_info) +{ + char *device_path = NULL; + char *name = NULL; + gboolean is_alias_set; + GVariant *value; + GVariant *result = NULL; + GError *err = NULL; + GDBusProxy *device_proxy; + GDBusConnection *conn; + + ret_if(bdaddress == NULL); + + device_path = _bt_get_device_object_path((char *)bdaddress); + ret_if(device_path == NULL); + + conn = _bt_gdbus_get_system_gconn(); + ret_if(conn == NULL); + BT_INFO("Device_path %s", device_path); + device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_BLUEZ_NAME, + device_path, + BT_PROPERTIES_INTERFACE, + NULL, &err); + + g_free(device_path); + ret_if(device_proxy == NULL); + + result = g_dbus_proxy_call_sync(device_proxy, "GetAll", + g_variant_new("(s)", BT_DEVICE_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &err); + if (err) { + BT_ERR("DBus Error : %s", err->message); + g_clear_error(&err); + return; } + if (result == NULL) { + BT_ERR("g_dbus_proxy_call_sync function return NULL"); + return; + } + g_variant_get(result, "(@a{sv})", &value); + + if (value) { + GVariant *temp_value = g_variant_lookup_value(value, "Alias", + G_VARIANT_TYPE_STRING); + g_variant_get(temp_value, "s", &name); + if (temp_value) + g_variant_unref(temp_value); + + if (name != NULL) + DBG_SECURE("Alias Name [%s]", name); + else { + temp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING); + g_variant_get(temp_value, "s", &name); + if (temp_value) + g_variant_unref(temp_value); + DBG_SECURE("Name = %s", name); + } + temp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN); + if (temp_value) { + is_alias_set = g_variant_get_boolean(temp_value); + g_variant_unref(temp_value); + } else { + is_alias_set = FALSE; + } - return name; + if (is_alias_set == FALSE) + __bt_get_auth_info(value, (char *)auth_info); + } + g_variant_unref(result); + g_object_unref(device_proxy); + + *device_name = g_strdup(name); + g_free(name); + return; } static int __bt_get_transfer_id(const char *path) @@ -268,46 +401,58 @@ static int __bt_get_transfer_id(const char *path) return atoi(tmp); } -static DBusGProxy *__bt_get_transfer_proxy(const char *transfer_path) +static GDBusProxy *__bt_get_transfer_proxy(const char *transfer_path) { - DBusGConnection *conn; - DBusGProxy *proxy; + GDBusConnection *conn; + GDBusProxy *proxy; + GError *err = NULL; - conn = _bt_get_session_gconn(); + conn = _bt_gdbus_get_session_gconn(); retv_if(conn == NULL, NULL); - proxy = dbus_g_proxy_new_for_name(conn, - BT_OBEX_SERVICE_NAME, + proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_OBEX_SERVICE_NAME, transfer_path, - BT_OBEX_TRANSFER_INTERFACE); + BT_OBEX_TRANSFER_INTERFACE, + NULL, &err); + + if (err) { + BT_ERR("Error : %s", err->message); + g_clear_error(&err); + return NULL; + } return proxy; } -static DBusGProxy *__bt_get_transfer_properties_proxy(const char *transfer_path) +static GDBusProxy *__bt_get_transfer_properties_proxy(const char *transfer_path) { - DBusGConnection *conn; - DBusGProxy *proxy; - - conn = _bt_get_session_gconn(); + GDBusConnection *conn; + GDBusProxy *proxy; + GError *err = NULL; + conn = _bt_gdbus_get_session_gconn(); retv_if(conn == NULL, NULL); - proxy = dbus_g_proxy_new_for_name(conn, - BT_OBEX_SERVICE_NAME, + proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_OBEX_SERVICE_NAME, transfer_path, - BT_PROPERTIES_INTERFACE); - + BT_PROPERTIES_INTERFACE, + NULL, &err); + if (err) { + BT_ERR("Error : %s", err->message); + g_clear_error(&err); + return NULL; + } return proxy; } static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info, const char *transfer_path) { - GHashTable *hash = NULL; - GValue *value; - DBusGProxy *transfer_proxy; - char *bdaddress; - + GDBusProxy *transfer_proxy; + GVariant *result = NULL; + GError *err = NULL; + GVariantIter *iter = NULL; BT_CHECK_PARAMETER(transfer_info, return); BT_CHECK_PARAMETER(transfer_path, return); @@ -315,69 +460,81 @@ static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info, retv_if(transfer_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - dbus_g_proxy_call(transfer_proxy, "GetAll", NULL, - G_TYPE_STRING, BT_OBEX_TRANSFER_INTERFACE, - G_TYPE_INVALID, - dbus_g_type_get_map("GHashTable", G_TYPE_STRING, - G_TYPE_VALUE), &hash, G_TYPE_INVALID); - - if (hash == NULL) { - g_object_unref(transfer_proxy); - return BLUETOOTH_ERROR_INTERNAL; - } + result = g_dbus_proxy_call_sync(transfer_proxy, "GetAll", + g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &err); - value = g_hash_table_lookup(hash, "Operation"); - transfer_info->type = value ? g_strdup(g_value_get_string(value)) : NULL; - if (!transfer_info->type) + if (err) { + BT_ERR("DBus Error : %s", err->message); + g_clear_error(&err); goto fail; - - value = g_hash_table_lookup(hash, "Name"); - - transfer_info->filename = value ? g_strdup(g_value_get_string(value)) : NULL; - if (!transfer_info->filename) + } + if (result == NULL) { + BT_ERR("g_dbus_proxy_call_sync function return NULL"); goto fail; + } - value = g_hash_table_lookup(hash, "Size"); - transfer_info->file_size = value ? g_value_get_uint64(value) : 0; - - transfer_info->path = g_strdup(transfer_path); - transfer_info->transfer_id = __bt_get_transfer_id(transfer_path); + g_variant_get(result, "(a{sv})", &iter); + g_variant_unref(result); + if (iter) { + const gchar *key; + GVariant *val; + gsize len = 0; + while (g_variant_iter_loop(iter, "{sv}", &key, &val)) { + if (g_strcmp0(key, "Operation") == 0) { + transfer_info->type = g_variant_dup_string(val, &len); + } else if (g_strcmp0(key, "Name") == 0) { + transfer_info->filename = g_variant_dup_string(val, &len); + } else if (g_strcmp0(key, "Size") == 0) { + transfer_info->file_size = g_variant_get_uint64(val); + } else if (g_strcmp0(key, "Address") == 0) { + transfer_info->address = g_variant_dup_string(val, &len); + BT_INFO("addressss %s", transfer_info->address); + } else if (g_strcmp0(key, "Filename") == 0) { + transfer_info->file_path = g_variant_dup_string(val, &len); + if (!transfer_info->file_path) + transfer_info->file_path = g_strdup(transfer_info->filename); + } + } + g_variant_iter_free(iter); - value = g_hash_table_lookup(hash, "Address"); - bdaddress = value ? (char *)g_value_get_string(value) : NULL; - if (!bdaddress) - goto fail; - transfer_info->address = g_strdup(bdaddress); + if (transfer_info->address == NULL) + goto fail; + transfer_info->device_name = __bt_get_remote_device_name(transfer_info->address); + transfer_info->transfer_id = __bt_get_transfer_id(transfer_path); + if (!transfer_info->device_name) + transfer_info->device_name = g_strdup(transfer_info->address); - value = g_hash_table_lookup(hash, "Filename"); - transfer_info->file_path = value ? g_strdup(g_value_get_string(value)) : NULL; - if (!transfer_info->file_path) - transfer_info->file_path = g_strdup(transfer_info->filename); + if (transfer_info->type == NULL) + goto fail; - transfer_info->device_name = __bt_get_remote_device_name(bdaddress); - if (!transfer_info->device_name) - transfer_info->device_name = g_strdup(bdaddress); + transfer_info->path = g_strdup(transfer_path); + } - g_hash_table_destroy(hash); g_object_unref(transfer_proxy); return BLUETOOTH_ERROR_NONE; fail: - g_hash_table_destroy(hash); g_object_unref(transfer_proxy); return BLUETOOTH_ERROR_INTERNAL; } -static gboolean __bt_authorize_cb(DBusGMethodInvocation *context, +static gboolean __bt_authorize_cb(GDBusMethodInvocation *context, const char *path, gpointer user_data) { char *device_name = NULL; + unsigned char auth_info[5] = {0, }; int result = BLUETOOTH_ERROR_NONE; - DBusGProxy *transfer_properties_proxy; - GHashTable *hash = NULL; - GValue *value; + GDBusProxy *transfer_properties_proxy; char * bdaddress = NULL; + GVariant *ret; + GVariantIter *iter; + GVariant *param = NULL; + GError *err = NULL; + bt_session_info_t *session_info = NULL; BT_DBG(" path [%s] \n", path); @@ -385,13 +542,23 @@ static gboolean __bt_authorize_cb(DBusGMethodInvocation *context, retv_if(transfer_properties_proxy == NULL, FALSE); - dbus_g_proxy_call(transfer_properties_proxy, "GetAll", NULL, - G_TYPE_STRING, BT_OBEX_TRANSFER_INTERFACE, - G_TYPE_INVALID, - dbus_g_type_get_map("GHashTable", G_TYPE_STRING, - G_TYPE_VALUE), &hash, G_TYPE_INVALID); - - if (hash == NULL) { + ret = g_dbus_proxy_call_sync(transfer_properties_proxy, "GetAll", + g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &err); + if (err) { + BT_ERR("DBus Error : %s", err->message); + g_clear_error(&err); + return FALSE; + } + if (ret == NULL) { + BT_ERR("g_dbus_proxy_call_sync function return NULL"); + return FALSE; + } + g_variant_get(ret, "(a{sv})", &iter); + g_variant_unref(ret); + if (iter == NULL) { g_object_unref(transfer_properties_proxy); return FALSE; } @@ -400,29 +567,54 @@ static gboolean __bt_authorize_cb(DBusGMethodInvocation *context, agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t)); + memset(agent_info.auth_info, 0, sizeof(bt_auth_info_t)); + agent_info.auth_info->reply_context = context; agent_info.auth_info->transfer_path = g_strdup(path); - value = g_hash_table_lookup(hash, "Name"); - agent_info.auth_info->filename = value ? g_strdup(g_value_get_string(value)) : NULL; - - value = g_hash_table_lookup(hash, "Size"); - agent_info.auth_info->file_size = value ? g_value_get_uint64(value) : 0; - - value = g_hash_table_lookup(hash, "Address"); - bdaddress = value ? (char *)g_value_get_string(value) : NULL; - agent_info.auth_info->address = g_strdup(bdaddress); +#ifdef TIZEN_DPM_ENABLE + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_HANDSFREE_ONLY) { + /* Free auth info in next function */ + _bt_obex_server_reject_authorize(); + return FALSE; + } +#endif + if (iter) { + const gchar *key; + GVariant *val; + gsize len = 0; + while (g_variant_iter_loop(iter, "{sv}", &key, &val)) { + if (g_strcmp0(key, "Name") == 0) + agent_info.auth_info->filename = g_variant_dup_string(val, &len); + else if (g_strcmp0(key, "Address") == 0) + bdaddress = g_variant_dup_string(val, &len); + else if (g_strcmp0(key, "Size") == 0) + agent_info.auth_info->file_size = g_variant_get_uint64(val); + } + g_variant_iter_free(iter); + } - device_name = __bt_get_remote_device_name(bdaddress); + __bt_get_remote_device_name_authinfo(bdaddress, &device_name, auth_info); if (!device_name) device_name = g_strdup(bdaddress); + agent_info.auth_info->address = g_strdup(bdaddress); agent_info.auth_info->device_name = device_name; + memcpy(agent_info.auth_info->contact_auth_info, auth_info, 5); + + session_info = __bt_find_session_by_path((char *)path); + if (NULL == session_info) { + session_info = g_malloc0(sizeof(bt_session_info_t)); + session_info->path = g_strdup(path); + session_info->address = g_strdup(bdaddress); + session_info->authorized = FALSE; + session_list = g_slist_append(session_list, session_info); + } - g_hash_table_destroy(hash); g_object_unref(transfer_properties_proxy); + g_free(bdaddress); if (agent_info.server_type == BT_CUSTOM_SERVER) { /* No need to send the event */ @@ -430,12 +622,18 @@ static gboolean __bt_authorize_cb(DBusGMethodInvocation *context, return TRUE; } - _bt_send_event(BT_OPP_SERVER_EVENT, - BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &agent_info.auth_info->filename, - DBUS_TYPE_UINT64, &agent_info.auth_info->file_size, - DBUS_TYPE_INVALID); + if (session_info->authorized == FALSE) { + _bt_launch_system_popup(BT_AGENT_EVENT_EXCHANGE_REQUEST, device_name, + auth_info, NULL, NULL, BT_OBEX_SERVER_AGENT_PATH); + } else { + param = g_variant_new("(istss)", result, + agent_info.auth_info->filename, + agent_info.auth_info->file_size, + agent_info.auth_info->address, + agent_info.auth_info->device_name); + _bt_send_event(BT_OPP_SERVER_EVENT, + BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, param); + } return TRUE; } @@ -444,9 +642,11 @@ void _bt_obex_transfer_started(const char *transfer_path) { bt_transfer_info_t *transfer_info; request_info_t *req_info; - GArray *out_param1 = NULL; - GArray *out_param2 = NULL; + GVariant *out_param1 = NULL; + GVariant *param = NULL; + GVariantBuilder *builder = NULL; int result = BLUETOOTH_ERROR_NONE; + int i = 0; BT_DBG("%s", transfer_path); @@ -462,23 +662,21 @@ void _bt_obex_transfer_started(const char *transfer_path) transfer_info->transfer_id = __bt_get_transfer_id(transfer_path); transfer_info->file_path = agent_info.auth_info->file_path; transfer_info->address = g_strdup(agent_info.auth_info->address); + } else { if (__bt_get_transfer_properties(transfer_info, transfer_path) < 0) { BT_ERR("Get Properties failed"); - __bt_free_auth_info(agent_info.auth_info); __bt_free_transfer_info(transfer_info); - agent_info.auth_info = NULL; return; } agent_info.server_type = BT_FTP_SERVER; } - __bt_free_auth_info(agent_info.auth_info); - agent_info.auth_info = NULL; - if (agent_info.server_type == BT_CUSTOM_SERVER) { if (agent_info.custom_server == NULL) { __bt_free_transfer_info(transfer_info); + __bt_free_auth_info(agent_info.auth_info); + agent_info.auth_info = NULL; return; } @@ -490,68 +688,97 @@ void _bt_obex_transfer_started(const char *transfer_path) agent_info.accept_id = 0; result = BLUETOOTH_ERROR_NONE; + GArray *g_out_param1 = NULL; + g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); + if (out_param1 == NULL) { + out_param1 = g_variant_new_from_data((const GVariantType *)"ay", + g_out_param1->data, g_out_param1->len, + TRUE, NULL, NULL); + } - out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); - out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar)); - - g_array_append_vals(out_param2, &result, sizeof(int)); - - dbus_g_method_return(req_info->context, out_param1, out_param2); - - g_array_free(out_param1, TRUE); - g_array_free(out_param2, TRUE); - + g_dbus_method_invocation_return_value(req_info->context, + g_variant_new("(iv)", result, out_param1)); + g_array_free(g_out_param1, TRUE); _bt_delete_request_list(req_info->req_id); } done: transfers = g_slist_append(transfers, transfer_info); - BT_DBG("Transfer id %d\n", transfer_info->transfer_id); + BT_DBG("Transfer id %d", transfer_info->transfer_id); + + builder = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for (i = 0; i < 5; i++) { + if (agent_info.auth_info) + g_variant_builder_add(builder, "y", agent_info.auth_info->contact_auth_info[i]); + } + + param = g_variant_new("(isssstii(ay))", result, + transfer_info->device_name, + transfer_info->filename, + transfer_info->type, + transfer_info->address, + transfer_info->file_size, + transfer_info->transfer_id, + agent_info.server_type, + builder); + + __bt_free_auth_info(agent_info.auth_info); + agent_info.auth_info = NULL; + + g_variant_builder_unref(builder); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &transfer_info->filename, - DBUS_TYPE_STRING, &transfer_info->type, - DBUS_TYPE_UINT64, &transfer_info->file_size, - DBUS_TYPE_INT32, &transfer_info->transfer_id, - DBUS_TYPE_INT32, &agent_info.server_type, - DBUS_TYPE_INVALID); + param); } void _bt_obex_transfer_progress(const char *transfer_path, - int transferred) + guint64 transferred) { BT_DBG("+"); bt_transfer_info_t *transfer_info; - int progress = 0; + int current_progress = 0; + int previous_progress; + GVariant *param = NULL; int result = BLUETOOTH_ERROR_NONE; transfer_info = __bt_find_transfer_by_path(transfer_path); ret_if(transfer_info == NULL); - progress = (int)(((gdouble)transferred / + current_progress = (int)(((gdouble)transferred / (gdouble)transfer_info->file_size) * 100); + previous_progress = (int)(((gdouble)transfer_info->progress / + (gdouble)transfer_info->file_size) * 100); + + if (current_progress == previous_progress) { + BT_DBG("Same Percentage Value: Do not emit Signal"); + return; + } + + transfer_info->progress = transferred; + param = g_variant_new("(isssstiii)", result, + transfer_info->filename, + transfer_info->type, + transfer_info->device_name, + transfer_info->address, + transfer_info->file_size, + transfer_info->transfer_id, + current_progress, + agent_info.server_type); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &transfer_info->filename, - DBUS_TYPE_STRING, &transfer_info->type, - DBUS_TYPE_UINT64, &transfer_info->file_size, - DBUS_TYPE_INT32, &transfer_info->transfer_id, - DBUS_TYPE_INT32, &progress, - DBUS_TYPE_INT32, &agent_info.server_type, - DBUS_TYPE_INVALID); - + param); BT_DBG("-"); } void _bt_obex_transfer_completed(const char *transfer_path, gboolean success) { bt_transfer_info_t *transfer_info; - + GVariantBuilder *builder = NULL; + GVariant *param = NULL; int result; + int i = 0; BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success); result = (success == TRUE) ? BLUETOOTH_ERROR_NONE @@ -577,104 +804,136 @@ void _bt_obex_transfer_completed(const char *transfer_path, gboolean success) transfer_info->device_name = g_strdup(agent_info.auth_info->device_name); transfer_info->transfer_id = __bt_get_transfer_id(transfer_path); transfer_info->file_path = agent_info.auth_info->file_path; + transfer_info->address = g_strdup(agent_info.auth_info->address); + builder = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for (i = 0; i < 5; i++) + g_variant_builder_add(builder, "y", agent_info.auth_info->contact_auth_info[i]); + + param = g_variant_new("(isssstii(ay))", result, + transfer_info->filename, + transfer_info->type, + transfer_info->device_name, + transfer_info->address, + transfer_info->file_size, + transfer_info->transfer_id, + agent_info.server_type, + builder); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &transfer_info->filename, - DBUS_TYPE_STRING, &transfer_info->type, - DBUS_TYPE_UINT64, &transfer_info->file_size, - DBUS_TYPE_INT32, &transfer_info->transfer_id, - DBUS_TYPE_INT32, &agent_info.server_type, - DBUS_TYPE_INVALID); + param); + g_variant_builder_unref(builder); } - + param = g_variant_new("(issssstii)", result, + transfer_info->filename, + transfer_info->type, + transfer_info->device_name, + transfer_info->file_path, + transfer_info->address, + transfer_info->file_size, + transfer_info->transfer_id, + agent_info.server_type); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &transfer_info->filename, - DBUS_TYPE_STRING, &transfer_info->type, - DBUS_TYPE_STRING, &transfer_info->device_name, - DBUS_TYPE_STRING, &transfer_info->file_path, - DBUS_TYPE_UINT64, &transfer_info->file_size, - DBUS_TYPE_INT32, &transfer_info->transfer_id, - DBUS_TYPE_INT32, &agent_info.server_type, - DBUS_TYPE_INVALID); - + param); transfers = g_slist_remove(transfers, transfer_info); __bt_free_transfer_info(transfer_info); } -void _bt_obex_transfer_connected() +void _bt_obex_transfer_connected(const char *obj_path) { BT_DBG("+"); int result = BLUETOOTH_ERROR_NONE; + GVariant *param = NULL; + bt_transfer_info_t *transfer_info = NULL; + + transfer_info = g_new0(bt_transfer_info_t, 1); + __bt_get_transfer_properties(transfer_info, obj_path); + INFO_SECURE("Address[%s] Name[%s] TransferID[%d] ", transfer_info->address, + transfer_info->device_name, transfer_info->transfer_id); + + param = g_variant_new("(issi)", result, transfer_info->address, + transfer_info->device_name, transfer_info->transfer_id); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); + param); + __bt_free_transfer_info(transfer_info); BT_DBG("-"); } -void _bt_obex_transfer_disconnected() +void _bt_obex_transfer_disconnected(char * obj_path) { BT_DBG("+"); int result = BLUETOOTH_ERROR_NONE; + GVariant *param = NULL; + bt_session_info_t *session = NULL; + int transfer_id = -1; + session = __bt_find_session_by_path(obj_path); + ret_if(session == NULL); + + transfer_id = __bt_get_transfer_id(obj_path); + DBG_SECURE("transfer_id: [%d]", transfer_id); + + DBG_SECURE("%s", session->address); + param = g_variant_new("(isi)", result, session->address, transfer_id); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - + param); + session_list = g_slist_remove(session_list, session); + g_free(session->address); + g_free(session->path); + g_free(session); BT_DBG("-"); } int _bt_register_obex_server(void) { - DBusGConnection *g_conn; - DBusGProxy *manager_proxy; + GDBusConnection *g_conn; + GDBusProxy *manager_proxy; + GVariant *result = NULL; GError *g_error = NULL; /* Get the session bus. */ - g_conn = _bt_get_session_gconn(); + g_conn = _bt_gdbus_get_session_gconn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); - if (!agent_info.obex_agent) { - agent_info.obex_agent = _bt_obex_agent_new(); + _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH); - retv_if(agent_info.obex_agent == NULL, BLUETOOTH_ERROR_INTERNAL); + _bt_obex_setup(BT_OBEX_SERVER_AGENT_PATH); - _bt_obex_setup(agent_info.obex_agent, BT_OBEX_SERVER_AGENT_PATH); - - _bt_obex_set_authorize_cb(agent_info.obex_agent, + _bt_obex_set_authorize_cb(BT_OBEX_SERVER_AGENT_PATH, __bt_authorize_cb, NULL); - } - manager_proxy = dbus_g_proxy_new_for_name(g_conn, BT_OBEX_SERVICE, - BT_OBEX_PATH, BT_OBEX_MANAGER); + manager_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_OBEX_SERVICE, + BT_OBEX_PATH, + BT_OBEX_MANAGER, + NULL, &g_error); - if (manager_proxy == NULL) { - g_object_unref(agent_info.obex_agent); - agent_info.obex_agent = NULL; + if (manager_proxy == NULL) return BLUETOOTH_ERROR_INTERNAL; - } - dbus_g_proxy_call(manager_proxy, "RegisterAgent", &g_error, - DBUS_TYPE_G_OBJECT_PATH, BT_OBEX_SERVER_AGENT_PATH, - G_TYPE_INVALID, G_TYPE_INVALID); + result = g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent", + g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &g_error); + if (g_error != NULL) { BT_ERR("Agent registration failed: %s\n", g_error->message); - g_object_unref(agent_info.obex_agent); - agent_info.obex_agent = NULL; g_object_unref(manager_proxy); g_error_free(g_error); return BLUETOOTH_ERROR_INTERNAL; } + if (result) + g_variant_unref(result); + agent_info.proxy = manager_proxy; return BLUETOOTH_ERROR_NONE; @@ -682,28 +941,29 @@ int _bt_register_obex_server(void) int _bt_unregister_obex_server(void) { + GVariant *result = NULL; GError *g_error = NULL; - retv_if(agent_info.obex_agent == NULL, - BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST); - retv_if(agent_info.proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - dbus_g_proxy_call(agent_info.proxy, "UnregisterAgent", &g_error, - DBUS_TYPE_G_OBJECT_PATH, BT_OBEX_SERVER_AGENT_PATH, - G_TYPE_INVALID, G_TYPE_INVALID); + result = g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent", + g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &g_error); if (g_error != NULL) { BT_ERR("Agent unregistration failed: %s", g_error->message); g_error_free(g_error); } + if (result) + g_variant_unref(result); + + _bt_obex_agent_destroy(BT_OBEX_SERVER_AGENT_PATH); g_object_unref(agent_info.proxy); agent_info.proxy = NULL; - g_object_unref(agent_info.obex_agent); - agent_info.obex_agent = NULL; - return BLUETOOTH_ERROR_NONE; } @@ -725,35 +985,62 @@ gboolean __bt_check_folder_path(const char *dest_path) return TRUE; } +char *__bt_transfer_folder_path(char *dest_path) +{ + char *dst_path = (char *)g_malloc0(BT_OBEX_PATH_MAX_LENGTH); + if (g_str_has_prefix(dest_path, BT_OBEX_PATH_PREFIX)) + snprintf(dst_path, BT_OBEX_PATH_MAX_LENGTH, BT_OBEX_DEFAULT_PATH"%s", dest_path + strlen(BT_OBEX_PATH_PREFIX)); + else + snprintf(dst_path, BT_OBEX_PATH_MAX_LENGTH, "%s", dest_path); + + BT_INFO("obex transfed path : %s", dst_path); + return dst_path; +} + int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native) { - if (__bt_check_folder_path(dest_path) == FALSE) + BT_DBG("+"); + + char *dst_path; + dst_path = __bt_transfer_folder_path((char *)dest_path); + + if (__bt_check_folder_path(dst_path) == FALSE) { + g_free(dst_path); return BLUETOOTH_ERROR_INVALID_PARAM; + } if (is_native == TRUE) { - retv_if(agent_info.native_server, - BLUETOOTH_ERROR_DEVICE_BUSY); + if (agent_info.native_server) { + BT_ERR("obex native server busy"); + g_free(dst_path); + return BLUETOOTH_ERROR_DEVICE_BUSY; + } /* Force to change the control to native */ agent_info.native_server = g_malloc0(sizeof(bt_server_info_t)); - agent_info.native_server->dest_path = g_strdup(dest_path); + agent_info.native_server->dest_path = g_strdup(dst_path); agent_info.native_server->sender = g_strdup(sender); agent_info.native_server->app_pid = app_pid; agent_info.server_type = BT_NATIVE_SERVER; _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL); } else { - retv_if(agent_info.custom_server, - BLUETOOTH_ERROR_DEVICE_BUSY); + if (agent_info.custom_server) { + BT_ERR("obex custom server busy"); + g_free(dst_path); + return BLUETOOTH_ERROR_DEVICE_BUSY; + } /* Force to change the control to custom */ agent_info.custom_server = g_malloc0(sizeof(bt_server_info_t)); - agent_info.custom_server->dest_path = g_strdup(dest_path); + agent_info.custom_server->dest_path = g_strdup(dst_path); agent_info.custom_server->sender = g_strdup(sender); agent_info.custom_server->app_pid = app_pid; agent_info.server_type = BT_CUSTOM_SERVER; _bt_register_osp_server_in_agent(BT_OBEX_SERVER, NULL, NULL, -1); } + g_free(dst_path); + BT_DBG("-"); return BLUETOOTH_ERROR_NONE; } @@ -820,15 +1107,37 @@ int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native) else snprintf(file_path, sizeof(file_path), "%s", filename); - dbus_g_method_return(agent_info.auth_info->reply_context, - file_path); - + g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context, + g_variant_new("(s)", &file_path)); agent_info.auth_info->reply_context = NULL; agent_info.auth_info->file_path = g_strdup(file_path); + g_free(agent_info.auth_info->filename); + agent_info.auth_info->filename = g_strdup(filename); return BLUETOOTH_ERROR_NONE; } +void _bt_obex_server_reply_accept(void) +{ + GVariant *param = NULL; + bt_session_info_t *session_info = NULL; + int result = BLUETOOTH_ERROR_NONE; + param = g_variant_new("(istss)", result, + agent_info.auth_info->filename, + agent_info.auth_info->file_size, + agent_info.auth_info->address, + agent_info.auth_info->device_name); + BT_INFO("Send Obex Authorize"); + _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, param); + + session_info = __bt_find_session_by_path(agent_info.auth_info->transfer_path); + + if (NULL == session_info) + BT_ERR("Couldn't get the session info from the list"); + else + session_info->authorized = TRUE; +} + int _bt_obex_server_reject_authorize(void) { GError *g_error; @@ -840,8 +1149,8 @@ int _bt_obex_server_reject_authorize(void) BT_OBEX_AGENT_ERROR_CANCEL, "CancelledByUser"); - dbus_g_method_return_error(agent_info.auth_info->reply_context, - g_error); + g_dbus_method_invocation_return_gerror(agent_info.auth_info->reply_context, + g_error); g_error_free(g_error); __bt_free_auth_info(agent_info.auth_info); @@ -854,15 +1163,18 @@ int _bt_obex_server_set_destination_path(const char *dest_path, gboolean is_native) { bt_server_info_t *server_info; - BT_CHECK_PARAMETER(dest_path, return); + char *dst_path; + dst_path = __bt_transfer_folder_path((char *)dest_path); + DIR *dp = NULL; - dp = opendir(dest_path); + dp = opendir(dst_path); if (dp == NULL) { BT_ERR("The directory does not exist"); + g_free(dst_path); return BLUETOOTH_ERROR_INVALID_PARAM; } @@ -873,69 +1185,96 @@ int _bt_obex_server_set_destination_path(const char *dest_path, else server_info = agent_info.custom_server; - retv_if(server_info == NULL, - BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST); + if (!server_info) { + BT_ERR("obex server info is NULL"); + g_free(dst_path); + return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST; + } g_free(server_info->dest_path); - server_info->dest_path = g_strdup(dest_path); + server_info->dest_path = g_strdup(dst_path); + g_free(dst_path); return BLUETOOTH_ERROR_NONE; } int _bt_obex_server_set_root(const char *root) { + GVariant *result = NULL; GError *g_error = NULL; - GValue folder = { 0 }; + GVariant *folder = NULL; + char *string = "Root"; DIR *dp = NULL; BT_CHECK_PARAMETER(root, return); - retv_if(agent_info.proxy == NULL, - BLUETOOTH_ERROR_INTERNAL); + char *dst_root; + dst_root = __bt_transfer_folder_path((char *)root); + + if (!agent_info.proxy) { + BT_ERR("obex agent_info proxy error"); + g_free(dst_root); + return BLUETOOTH_ERROR_INTERNAL; + } - dp = opendir(root); + dp = opendir(dst_root); if (dp == NULL) { BT_ERR("The directory does not exist"); + g_free(dst_root); return BLUETOOTH_ERROR_INVALID_PARAM; } closedir(dp); - g_value_init(&folder, G_TYPE_STRING); - g_value_set_string(&folder, root); - - dbus_g_proxy_call(agent_info.proxy, "SetProperty", - &g_error, G_TYPE_STRING, "Root", - G_TYPE_VALUE, &folder, G_TYPE_INVALID, G_TYPE_INVALID); - - g_value_unset(&folder); + folder = g_variant_new_string(dst_root); + result = g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty", + g_variant_new("(sv)", string, folder), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &g_error); if (g_error) { BT_ERR("SetProperty Fail: %s", g_error->message); g_error_free(g_error); + g_free(dst_root); return BLUETOOTH_ERROR_INTERNAL; } + if (result) + g_variant_unref(result); + + g_free(dst_root); return BLUETOOTH_ERROR_NONE; } int _bt_obex_server_cancel_transfer(int transfer_id) { bt_transfer_info_t *transfer = NULL; - DBusGProxy *proxy; - + GDBusProxy *proxy; + GVariant *result = NULL; + GError *err = NULL; + BT_DBG("+"); transfer = __bt_find_transfer_by_id(transfer_id); - retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND); + retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND); proxy = __bt_get_transfer_proxy(transfer->path); retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - dbus_g_proxy_call_no_reply(proxy, "Cancel", G_TYPE_INVALID, G_TYPE_INVALID); + result = g_dbus_proxy_call_sync(proxy, "Cancel", NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, &err); + if (err) { + BT_ERR("Dbus Err: %s", err->message); + g_clear_error(&err); + } g_object_unref(proxy); + if (result) + g_variant_unref(result); + return BLUETOOTH_ERROR_NONE; } @@ -960,11 +1299,10 @@ int _bt_obex_server_is_activated(gboolean *activated) { BT_CHECK_PARAMETER(activated, return); - if (agent_info.custom_server) { + if (agent_info.custom_server) *activated = TRUE; - } else { + else *activated = FALSE; - } return BLUETOOTH_ERROR_NONE; } @@ -973,11 +1311,10 @@ int _bt_obex_server_check_allocation(gboolean *allocation) { BT_CHECK_PARAMETER(allocation, return); - if (agent_info.native_server || agent_info.custom_server) { + if (agent_info.native_server || agent_info.custom_server) *allocation = TRUE; - } else { + else *allocation = FALSE; - } return BLUETOOTH_ERROR_NONE; } @@ -1007,11 +1344,10 @@ int _bt_obex_server_is_receiving(gboolean *receiving) { BT_CHECK_PARAMETER(receiving, return); - if (transfers == NULL || g_slist_length(transfers) == 0) { + if (transfers == NULL || g_slist_length(transfers) == 0) *receiving = FALSE; - } else { + else *receiving = TRUE; - } return BLUETOOTH_ERROR_NONE; } @@ -1019,8 +1355,7 @@ int _bt_obex_server_is_receiving(gboolean *receiving) gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data) { request_info_t *req_info; - GArray *out_param1; - GArray *out_param2; + GVariant *out_param1 = NULL; int result = BLUETOOTH_ERROR_TIMEOUT; /* Already reply in _bt_obex_transfer_started */ @@ -1033,17 +1368,17 @@ gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data) } agent_info.accept_id = 0; + GArray *g_out_param1 = NULL; + g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); + if (out_param1 == NULL) { + out_param1 = g_variant_new_from_data((const GVariantType *)"ay", + g_out_param1->data, g_out_param1->len, + TRUE, NULL, NULL); + } - out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); - out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar)); - - g_array_append_vals(out_param2, &result, sizeof(int)); - - dbus_g_method_return(req_info->context, out_param1, out_param2); - - g_array_free(out_param1, TRUE); - g_array_free(out_param2, TRUE); - + g_dbus_method_invocation_return_value(req_info->context, + g_variant_new("(iv)", result, out_param1)); + g_array_free(g_out_param1, TRUE); _bt_delete_request_list(req_info->req_id); return FALSE; @@ -1073,3 +1408,18 @@ int _bt_obex_server_reject_connection(void) return BLUETOOTH_ERROR_NONE; } +int _bt_opp_get_server_progress(int transfer_id, guint8 *progress) +{ + bt_transfer_info_t *requested_transfer = NULL; + requested_transfer = __bt_find_transfer_by_id(transfer_id); + if (requested_transfer == NULL) { + BT_ERR("No Matching Inbound transfer"); + return BLUETOOTH_ERROR_NOT_FOUND; + } + + *progress = (int)(((double)requested_transfer->progress / + requested_transfer->file_size) * 100); + + BT_DBG("Percentage: %d", *progress); + return BLUETOOTH_ERROR_NONE; +}