/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
+ * 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.
#include <dlog.h>
#include <string.h>
#include <dirent.h>
-#ifdef TIZEN_MDM_ENABLE
-#include <bt-service-mdm.h>
+#ifdef TIZEN_DPM_ENABLE
+#include "bt-service-dpm.h"
#endif
+
#include <vconf.h>
#include <gio/gio.h>
#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;
char *device_name;
int transfer_id;
gint64 file_size;
+ gint64 progress;
char *address;
} bt_transfer_info_t;
char *device_name;
char *transfer_path;
char *address;
+ unsigned char contact_auth_info[5];
} bt_auth_info_t;
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;
-int _bt_obex_get_native_pid(void)
+static bt_session_info_t *__bt_find_session_by_path(char *transfer_path)
{
- return agent_info.native_server->app_pid;
+ 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)
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("(isssstii)", result,
+ 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);
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);
BT_INFO("Device_path %s", device_path);
device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
return NULL;
}
g_variant_get(result, "(@a{sv})", &value);
- g_variant_unref(result);
+ 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;
+}
+
+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);
+ g_variant_get(temp_value, "s", &name);
if (temp_value)
g_variant_unref(temp_value);
- BT_INFO("Alias Name: %s", name);
+
+ 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;
+ }
+
+ if (is_alias_set == FALSE)
+ __bt_get_auth_info(value, (char *)auth_info);
}
+ g_variant_unref(result);
+ g_object_unref(device_proxy);
- return name;
+ *device_name = g_strdup(name);
+ g_free(name);
+ return;
}
static int __bt_get_transfer_id(const char *path)
GDBusProxy *proxy;
GError *err = NULL;
- conn = _bt_get_session_gconn();
+ conn = _bt_gdbus_get_session_gconn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
GDBusConnection *conn;
GDBusProxy *proxy;
GError *err = NULL;
- conn = _bt_get_session_gconn();
+ conn = _bt_gdbus_get_session_gconn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL,BT_OBEX_SERVICE_NAME,
+ NULL, BT_OBEX_SERVICE_NAME,
transfer_path,
BT_PROPERTIES_INTERFACE,
NULL, &err);
const char *transfer_path)
{
GDBusProxy *transfer_proxy;
- char *bdaddress = NULL;
GVariant *result = NULL;
GError *err = NULL;
GVariantIter *iter = NULL;
}
}
g_variant_iter_free(iter);
- if (transfer_info->type == NULL)
- goto fail;
+
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(bdaddress);
+ transfer_info->device_name = g_strdup(transfer_info->address);
+
+ if (transfer_info->type == NULL)
+ goto fail;
+
transfer_info->path = g_strdup(transfer_path);
- transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
}
g_object_unref(transfer_proxy);
gpointer user_data)
{
char *device_name = NULL;
+ unsigned char auth_info[5] = {0, };
int result = BLUETOOTH_ERROR_NONE;
GDBusProxy *transfer_properties_proxy;
char * bdaddress = NULL;
GVariantIter *iter;
GVariant *param = NULL;
GError *err = NULL;
+ bt_session_info_t *session_info = NULL;
BT_DBG(" path [%s] \n", path);
return FALSE;
}
-#ifdef TIZEN_MDM_ENABLE
- mdm_bt_allow_t mode = MDM_BT_ALLOWED;
-#endif
-
__bt_free_auth_info(agent_info.auth_info);
agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t));
agent_info.auth_info->transfer_path = g_strdup(path);
+#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) {
+ 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) {
+ 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_object_unref(transfer_properties_proxy);
+ g_free(bdaddress);
if (agent_info.server_type == BT_CUSTOM_SERVER) {
/* No need to send the event */
_bt_obex_server_accept_authorize(agent_info.auth_info->filename, FALSE);
return TRUE;
}
- param = g_variant_new("(ist)", result,
- agent_info.auth_info->filename,
- agent_info.auth_info->file_size);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
- param);
+
+ 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;
}
request_info_t *req_info;
GVariant *out_param1 = NULL;
GVariant *param = NULL;
+ GVariantBuilder *builder = NULL;
int result = BLUETOOTH_ERROR_NONE;
+ int i = 0;
BT_DBG("%s", 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;
}
done:
transfers = g_slist_append(transfers, transfer_info);
- BT_DBG("Transfer id %d\n", transfer_info->transfer_id);
- param = g_variant_new("(isstii)", result,
+ 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);
+ 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,
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);
- param = g_variant_new("(isstiii)", result,
+ 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,
- progress,
+ current_progress,
agent_info.server_type);
_bt_send_event(BT_OPP_SERVER_EVENT,
BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
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
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("(isstii)", result,
+ 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);
+ agent_info.server_type,
+ builder);
_bt_send_event(BT_OPP_SERVER_EVENT,
BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
param);
+ g_variant_builder_unref(builder);
}
- param = g_variant_new("(isssstii)", result,
+ 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_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("(i)", result);
+ 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,
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);
- param = g_variant_new("(i)", result);
+ 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,
param);
+ session_list = g_slist_remove(session_list, session);
+ g_free(session->address);
+ g_free(session->path);
+ g_free(session);
BT_DBG("-");
}
{
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);
_bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
BT_OBEX_MANAGER,
NULL, &g_error);
- if (manager_proxy == NULL) {
+ if (manager_proxy == NULL)
return BLUETOOTH_ERROR_INTERNAL;
- }
- g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent",
+ 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,
return BLUETOOTH_ERROR_INTERNAL;
}
+ if (result)
+ g_variant_unref(result);
+
agent_info.proxy = manager_proxy;
return BLUETOOTH_ERROR_NONE;
int _bt_unregister_obex_server(void)
{
+ GVariant *result = NULL;
GError *g_error = NULL;
retv_if(agent_info.proxy == NULL,
BLUETOOTH_ERROR_INTERNAL);
- g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent",
+ 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,
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;
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)
{
BT_DBG("+");
- if (__bt_check_folder_path(dest_path) == FALSE)
+
+ 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;
}
snprintf(file_path, sizeof(file_path), "%s", filename);
g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context,
- g_variant_new("(s)",&file_path));
+ 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;
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;
}
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;
GVariant *folder = NULL;
char *string = "Root";
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);
- dp = opendir(root);
+ if (!agent_info.proxy) {
+ BT_ERR("obex agent_info proxy error");
+ g_free(dst_root);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ 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);
- folder = g_variant_new_string(root);
- g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty",
+ 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,
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;
}
{
bt_transfer_info_t *transfer = NULL;
GDBusProxy *proxy;
+ GVariant *result = NULL;
GError *err = NULL;
BT_DBG("+");
transfer = __bt_find_transfer_by_id(transfer_id);
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- g_dbus_proxy_call_sync(proxy, "Cancel", NULL,
+ 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;
}
{
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;
}
{
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;
}
{
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;
}
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;
+}