Apply the base implement for tizen 3.0 new BT share UX 42/97642/1 accepted/tizen/common/20161115.200520 submit/tizen/20161115.034359
authorDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 11 Nov 2016 08:32:08 +0000 (17:32 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 15 Nov 2016 02:11:10 +0000 (11:11 +0900)
- Fix the "failed" count of the sended file

Change-Id: I86c57dfd80fa110ef78fdb004249a8b73a85f0e5
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
Signed-off-by: Hyuk Lee <hyuk0512.lee@samsung.com>
22 files changed:
bt-share/CMakeLists.txt
bt-share/include/applog.h
bt-share/include/bt-share-common.h
bt-share/include/bt-share-ipc.h
bt-share/include/bt-share-main.h
bt-share/include/bt-share-noti-handler.h
bt-share/include/bt-share-notification.h
bt-share/include/bt-share-resource.h
bt-share/include/bt-share-syspopup.h
bt-share/include/obex-event-handler.h
bt-share/src/bt-share-common.c
bt-share/src/bt-share-ipc.c
bt-share/src/bt-share-main.c
bt-share/src/bt-share-noti-handler.c
bt-share/src/bt-share-notification.c
bt-share/src/bt-share-syspopup.c
bt-share/src/obex-event-handler.c
lib/applog.h
lib/bluetooth-share-api.h
lib/bluetooth-share-api.pc.in
lib/bt-share-db.c
packaging/init_db.sh

index a62e97e..083dfff 100644 (file)
@@ -25,9 +25,9 @@ pkg_check_modules(pkgs REQUIRED glib-2.0 bluetooth-api
                                capi-content-media-content
                                libtzplatform-config eventsystem
                                cynara-creds-dbus cynara-client cynara-session
-                               storage)
+                               storage db-util)
 pkg_check_modules(CALENDAR_SERVICE2 calendar-service2)
-pkg_check_modules(CONTACTS_SERVICE2 contacts-service2)
+pkg_check_modules(CONTACTS_SERVICE2 contacts-service2 zlib)
 
 FOREACH(flag ${pkgs_CFLAGS} ${CALENDAR_SERVICE2_CFLAGS} ${CONTACTS_SERVICE2_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 01ddda7..5753b7a 100644 (file)
@@ -61,27 +61,38 @@ extern "C" {
 #define DBG(fmt, arg...) \
        SLOGD(fmt, ##arg)
 
+#define        FN_START DBG("[ENTER FUNC]");
+#define        FN_END DBG("[EXIT FUNC]");
+
+#define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
+#define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
+#define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
+
 #define warn_if(expr, fmt, arg...) do { \
                if (expr) { \
                        ERR(fmt, ##arg); \
                } \
        } while (0)
+
 #define ret_if(expr) do { \
                if (expr) { \
                        return; \
                } \
        } while (0)
+
 #define retv_if(expr, val) do { \
                if (expr) { \
                        return (val); \
                } \
        } while (0)
+
 #define retm_if(expr, fmt, arg...) do { \
                if (expr) { \
                        ERR(fmt, ##arg); \
                        return; \
                } \
        } while (0)
+
 #define retvm_if(expr, val, fmt, arg...) do { \
                if (expr) { \
                        ERR(fmt, ##arg); \
index 694e0ad..68c332c 100644 (file)
@@ -41,19 +41,12 @@ extern "C" {
 #define BT_DOWNLOAD_DEFAULT_PHONE_FOLDER "/opt/usr/home/owner/media/Downloads"
 #define BT_DOWNLOAD_DEFAULT_MMC_FOLDER "/opt/media/SDCardA1"
 #define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER "/opt/usr/home/owner/media/Downloads"
-//#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER tzplatform_getenv(TZ_USER_CONTENT)
-
-/*
-#define BT_FTP_FOLDER tzplatform_mkpath(TZ_SYS_SHARE, "bt-ftp")
-*/
-
 #define BT_DOWNLOAD_PHONE_ROOT "/opt/usr/home/owner/media/"
 #define BT_DOWNLOAD_MMC_ROOT "/opt/media/SDCardA1"
 #define BT_FTP_FOLDER "/opt/share/bt-ftp"
 #define BT_FTP_FOLDER_PHONE "/opt/share/bt-ftp/Media/"
 #define BT_FTP_FOLDER_MMC "/opt/share/bt-ftp/SD_External/"
 
-//#define BT_TMP_DIR "/opt/home/owner/content/Downloads/.bluetooth/"
 #define BT_TMP_DIR "/opt/usr/home/owner/media/Downloads/"
 #define BT_TMP_FILE BT_TMP_DIR"bluetooth_content_share"
 #define TXT_FILE_NAME BT_TMP_DIR"bluetooth_content_share.txt"
@@ -61,28 +54,26 @@ extern "C" {
 #define TXT_FILE_FORMAT BT_TMP_DIR"bluetooth_content_share%s.txt"
 #define HTML_FILE_FORMAT BT_TMP_DIR"bluetooth_content_share%s.html"
 #define HTML_FORMAT "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/></head><body><a href=\"%s\">%s</a></body></html>"
-
-//#define BT_CONTACT_SHARE_TMP_DIR "/opt/home/owner/content/Downloads/.bluetooth/"
 #define BT_CONTACT_SHARE_TMP_DIR "/opt/usr/home/owner/media/Downloads/"
 
 typedef enum {
        BT_HTTP_FILE,
        BT_TXT_FILE,
-} bt_file_t;
+} bt_file_e;
 
 typedef enum {
        BT_STATUS_OFF         = 0x0000,
        BT_STATUS_ON          = 0x0001,
        BT_STATUS_BT_VISIBLE  = 0x0002,
        BT_STATUS_TRANSFER    = 0x0004,
-} bt_status_t;
-
+} bt_status_e;
 
 int _bt_share_block_sleep(gboolean is_block);
 int _bt_set_transfer_indicator(gboolean state);
 char *_bt_share_create_transfer_file(char *text);
 void _bt_remove_tmp_file(char *file_path);
 void _bt_remove_vcf_file(char *file_path);
+char *_bt_get_time_of_the_day(void);
 char *_bt_share_get_storage_path(int storage_type);
 
 #ifdef __cplusplus
index d28934b..853833a 100644 (file)
@@ -25,39 +25,28 @@ extern "C" {
 #endif
 
 #include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
 #include "bluetooth-api.h"
 #include "bt-share-main.h"
 
-#define BT_ADDRESS_LENGTH_MAX 6
-
-#define BT_IPC_SENDER_NAME             "org.projectx.bluetooth"
-#define BT_UG_IPC_RESPONSE_OBJECT "/org/projectx/response_event"
-#define BT_UG_IPC_EVENT_CONNECTED "Connected"
-#define BT_UG_IPC_EVENT_DISCONNECTED   "Disconnected"
-
 #define BT_BLUEZ_INTERFACE "org.freedesktop.DBus"
-#define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
+#define BT_BLUEZ_SIGNAL_NAME_OWNER_CHANGED "NameOwnerChanged"
+
 #define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
 #define BT_SYSPOPUP_METHOD_RESPONSE "Response"
 
-#define BT_UG_IPC_REQUEST_OBJECT "/org/projectx/connect_device"
 #define BT_UG_IPC_INTERFACE "User.Bluetooth.UG"
 #define BT_UG_IPC_METHOD_SEND "Send"
 
 #define BT_SHARE_UI_INTERFACE "User.BluetoothShare.UI"
 #define BT_SHARE_UI_SIGNAL_OPPABORT "opp_abort"
-#define BT_SHARE_UI_SIGNAL_GET_TR_DATA "get_data"
 #define BT_SHARE_UI_SIGNAL_SEND_FILE "send_file"
 #define BT_SHARE_UI_SIGNAL_INFO_UPDATE "info_update"
 
 #define BT_SHARE_ENG_INTERFACE "User.BluetoothShare.Engine"
 #define BT_SHARE_ENG_OBJECT "/org/projectx/transfer_info"
-#define BT_SHARE_ENG_SIGNAL_PROGRESS "transfer_progress"
-#define BT_SHARE_ENG_SIGNAL_ERROR "error_type"
 #define BT_SHARE_ENG_SIGNAL_UPDATE_VIEW "update_view"
-
+#define BT_SHARE_ENG_SIGNAL_OPP_CLIENT_DISCONNECTED "ShareOppClientDisconnected"
+#define BT_SHARE_ENG_SIGNAL_OPP_SERVER_DISCONNECTED "ShareOppServerDisconnected"
 #define BT_SHARE_FRWK_INTERFACE "User.Bluetooth.FRWK"
 #define BT_SHARE_FRWK_SIGNAL_DEINIT "deinit"
 
@@ -69,42 +58,20 @@ extern "C" {
 #define BT_ADDR_STR_LEN_MAX    18
 #define BT_MIME_TYPE_MAX_LEN   20
 
-#define FILE_PATH_DELIM "?"
-
 #define BT_INBOUND_TABLE       "inbound"
 #define BT_OUTBOUND_TABLE      "outbound"
 
-
-typedef struct {
-       int param1;
-       int param2;
-       char param3[BT_IPC_STRING_SIZE];
-} __attribute__ ((packed)) bt_ug_param_t;
-
-
-typedef enum {
-       BT_AG_CONNECT_RESPONSE,
-       BT_AG_DISCONNECT_RESPONSE,
-       BT_AV_CONNECT_RESPONSE,
-       BT_AV_DISCONNECT_RESPONSE,
-       BT_HID_CONNECT_RESPONSE,
-       BT_HID_DISCONNECT_RESPONSE,
-       BT_SENDING_RESPONSE,
-       BT_BROWSING_RESPONSE,
-       BT_PRINTING_RESPONSE,
-       BT_PAIRING_RESPONSE,
-} bt_app_response_t;
-
-typedef enum {
-       BT_APP_SUCCESS,
-       BT_APP_FAIL,
-} bt_app_result_t;
-
 typedef enum {
+       BT_TR_PENDING = -2,
        BT_TR_ONGOING = -1,
        BT_TR_SUCCESS,
        BT_TR_FAIL
-} bt_app_tr_status_t;
+} bt_app_tr_status_e;
+
+typedef enum {
+       BT_TR_OUTBOUND,
+       BT_TR_INBOUND
+} bt_share_tr_type_e;
 
 typedef struct {
        int file_cnt;
@@ -117,47 +84,29 @@ typedef struct {
        unsigned int *size;
 } opc_transfer_info_t;
 
-typedef struct {
-       int uid;
-       int tr_status;
-       char *device_name;
-       char *filepath;
-       int timestamp;
-       char *addr;
-} bt_tr_info_t;
-
-typedef enum {
-       BT_TR_OUTBOUND,
-       BT_TR_INBOUND
-} bt_share_tr_type_t;
-
-
-typedef struct _BtShareMethod BtShareMethod;
-typedef struct _BtShareMethodClass BtShareMethodClass;
-
-struct _BtShareMethod {
-       GObject parent;
-};
-
-struct _BtShareMethodClass {
-       GObjectClass parent_class;
-};
-
 gboolean _bt_init_dbus_signal(void);
-void _free_transfer_info(opc_transfer_info_t *node);
+void _bt_deinit_dbus_signal(void);
+
 void _remove_transfer_info(opc_transfer_info_t *node);
-int _request_file_send(opc_transfer_info_t *node);
+
 void _bt_create_warning_popup(int error_type, char *msg);
+gboolean _bt_update_sent_data_status(int uid,
+                               bt_app_tr_status_e status, char *db_sid);
+
+gboolean _bt_update_recv_data_status(int uid,
+               bt_app_tr_status_e status, char *db_sid,
+               unsigned int filesize, const char *mime_type);
 
-gboolean _bt_update_sent_data_status(int uid, bt_app_tr_status_t status);
+gboolean _bt_update_multiple_sent_data_status(int *uids, int uid_cnt,
+                               bt_app_tr_status_e status, char *db_sid);
 
-void _bt_rm_all_send_data(void);
-void _bt_rm_all_recv_data(void);
 void _bt_update_transfer_list_view(char *db);
+void _bt_send_disconnected_signal(char *signal, int result, char *address,
+               int transfer_id);
 gboolean _bt_add_recv_transfer_status_data(char *device_name,
-                       char *filepath, char *type,
-                       unsigned int size, int status);
-
+                       char *address, char *filepath, char *type,
+                       unsigned int size, int status, char *db_sid);
+int _bt_share_get_unique_id(int db_table, const char *db_sid);
 int _bt_set_eventsystem_transfer_value(gboolean value);
 
 #ifdef __cplusplus
index feeedc8..d8e6048 100644 (file)
@@ -25,16 +25,16 @@ extern "C" {
 #endif
 
 #include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 #include <notification.h>
 #include <tzplatform_config.h>
+#include <db-util.h>
 
 #ifndef PACKAGE_NAME
 #define PACKAGE_NAME "bluetooth-share"
 #endif
 
 #define UI_PACKAGE "org.tizen.bluetooth-share-ui"
-#define UI_PKG_PATH "/usr/apps/org.tizen.bluetooth-share-ui/bin/bluetooth-share-ui"
 
 typedef void (*bt_app_cb) (void *, void *, void *);
 
@@ -49,7 +49,7 @@ typedef struct {
        int tr_fail;
 } bt_transfer_status_info_t;
 
-struct bt_appdata {
+typedef struct {
        bt_app_popups_t popups;
        bt_transfer_status_info_t send_data;
        bt_transfer_status_info_t recv_data;
@@ -62,17 +62,19 @@ struct bt_appdata {
        int send_noti_id;
        int receive_noti_id;
        int opc_noti_id;
-       int syspopup_call;
-       DBusGConnection *conn;
+       GDBusConnection *conn;
        GObject *object;
        gboolean obex_server_init;
        bool opp_transfer_abort;
-};
+       guint idler;
+} bt_appdata_t;
 
 int _bt_init_obex_server(void);
 
 void _bt_terminate_bluetooth_share(void);
 
+void _bt_remove_temporary_files_by_noti_id(sqlite3 *db, int noti_id);
+
 #ifdef __cplusplus
 }
 #endif
index 560e473..c346618 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 
 void _bt_init_vconf_notification(void *data);
 void _bt_deinit_vconf_notification(void);
+
 #ifdef __cplusplus
 }
 #endif
index a8c7132..a4f00d5 100644 (file)
@@ -30,35 +30,18 @@ extern "C" {
 
 #include "bt-share-main.h"
 
-#define BT_SHARE_BIN_PATH "/usr/bin/bluetooth-share"
-
-#define QP_NO_APP_LAUNCH       NOTIFICATION_PROP_DISABLE_APP_LAUNCH
-#define QP_NO_TICKER           NOTIFICATION_PROP_DISABLE_TICKERNOTI
-#define QP_NO_DELETE           (NOTIFICATION_PROP_DISABLE_AUTO_DELETE | NOTIFICATION_PROP_VOLATILE_DISPLAY)
-
-
 #define NOTIFICATION_TEXT_LEN_MAX 100
 #define NOTI_TR_TYPE_IN "inbound"
 #define NOTI_TR_TYPE_OUT "outbound"
 #define NOTI_OPS_APP_ID        "bluetooth-share-opp-server"
 #define NOTI_OPC_APP_ID        "bluetooth-share-opp-client"
 
-/* Priv_id should be unique. */
-enum {
-       SEND_PRIV_ID,                   /* ongoing type for opp client */
-       RECV_NOTI_PRIV_ID = 99999,      /* notification type for obex server */
-       SEND_NOTI_PRIV_ID       /* notification type for obex client */
-};
-
-typedef enum {
-       BT_NOTI_T = NOTIFICATION_TYPE_NOTI,
-       BT_ONGOING_T = NOTIFICATION_TYPE_ONGOING,
-} bt_qp_type_t;
-
 typedef enum {
        BT_SENT_NOTI,
+       BT_SENT_FAILED_NOTI,
        BT_SENDING_NOTI,
        BT_RECEIVED_NOTI,
+       BT_RECEIVED_FAILED_NOTI,
        BT_RECEIVING_NOTI,
 } bt_notification_type_e;
 
@@ -67,37 +50,39 @@ typedef enum {
        CREATE_TR_LIST
 } bt_notification_launch_type_e;
 
+void _bt_insert_instant_notification(bt_notification_type_e type);
 
-notification_h _bt_insert_notification(struct bt_appdata *ad, bt_notification_type_e type, int index, int total);
+notification_h _bt_insert_notification(bt_appdata_t *ad,
+               bt_notification_type_e type, char *dev_name,
+               char *address, char *db_sid);
 
-int _bt_update_notification(struct bt_appdata *ad, notification_h noti,
-                               char *title,
-                               char *content,
-                               char *icon_path);
+int _bt_update_notification(bt_appdata_t *ad, notification_h noti,
+               char *title, char *content, char *icon_path, char *opc_count);
 
 int _bt_update_notification_progress(notification_h noti,
-                               int id,
-                               int val);
+               int id,
+               int val);
 
 int _bt_get_notification_priv_id(notification_h noti);
 
 int _bt_delete_notification(notification_h noti);
 
-int _bt_get_notification_priv_id(notification_h noti);
-
-int _bt_set_notification_app_launch(notification_h noti,
-                                       bt_notification_launch_type_e launch_type,
-                                       const char *transfer_type,
-                                       const char *filename,
-                                       const char *progress_cnt,
-                                       int transfer_id);
-
-gboolean _bt_update_notification_status(struct bt_appdata *ad);
-
-void _bt_register_notification_cb(struct bt_appdata *ad);
+int _bt_set_notification_app_launch(notification_h noti, char *device_name,
+               char *device_addr, char *db_sid,
+               bt_notification_launch_type_e launch_type,
+               const char *transfer_type,
+               const char *filename,
+               unsigned long size,
+               const char *progress_cnt,
+               int transfer_id);
+
+#if 0
+gboolean _bt_update_notification_status(bt_appdata_t *ad);
+#endif
 
-void _bt_unregister_notification_cb(struct bt_appdata *ad);
+void _bt_register_notification_cb(bt_appdata_t *ad);
 
+void _bt_unregister_notification_cb(bt_appdata_t *ad);
 
 #ifdef __cplusplus
 }
index 1713a4a..a9fa13b 100644 (file)
@@ -37,38 +37,23 @@ extern "C" {
        dgettext(BT_COMMON_PKG, "IDS_BT_POP_SENDINGFAIL")
 #define BT_STR_UNABLE_TO_RECEIVE       \
        dgettext(BT_COMMON_PKG, "IDS_BT_BODY_UNABLE_TO_RECEIVE")
-#define BT_TR_STATUS \
-       dgettext(BT_COMMON_PKG, "IDS_BT_BODY_PD_SUCCESSFUL_PD_FAILED")
-#define BT_TR_COPIED_STATUS \
-       dgettext(BT_COMMON_PKG, "IDS_BT_MBODY_P1SD_FILES_COPIED_P2SD_FAILED_ABB")
-#define BT_TR_1FILE_COPIED_STATUS \
-       dgettext(BT_COMMON_PKG, "IDS_BT_MBODY_1_FILE_COPIED_PD_FAILED_ABB")
-#define BT_STR_SENDING \
-       dgettext(BT_COMMON_PKG, "IDS_BT_POP_SENDING_ING")
-#define BT_STR_RECEIVING \
-       dgettext(BT_COMMON_PKG, "IDS_BT_POP_RECEIVING_ING")
-#define BT_STR_RECEIVED \
-       dgettext(BT_COMMON_PKG, "IDS_BT_BODY_RECEIVED")
-#define BT_STR_SENT \
-       dgettext(BT_COMMON_PKG, "IDS_BT_BODY_SENT")
-#define BT_STR_SHARE \
-       dgettext(BT_COMMON_PKG, "IDS_BT_BODY_BLUETOOTH_SHARE")
-#define BT_STR_RECEIVE_VIA_BLUETOOTH \
-       dgettext(BT_COMMON_PKG, "IDS_BT_MBODY_RECEIVE_VIA_BLUETOOTH_ABB")
-#define BT_STR_SEND_VIA_BLUETOOTH \
-       dgettext(BT_COMMON_PKG, "IDS_BT_MBODY_SEND_VIA_BLUETOOTH_ABB")
-#define BT_STR_PREPARING_TO_RECEIVE_FILES \
-       dgettext(BT_COMMON_PKG, "IDS_BT_SBODY_PREPARING_TO_RECEIVE_FILES_ING_ABB")
-#define BT_STR_PREPARING_TO_SEND_FILES \
-       dgettext(BT_COMMON_PKG, "IDS_BT_SBODY_PREPARING_TO_SEND_FILES_ING_ABB")
-#define BT_STR_FILES_RECEIVED_VIA_BLUETOOTH \
-       dgettext(BT_COMMON_PKG, "IDS_BT_MBODY_FILES_RECEIVED_VIA_BLUETOOTH_ABB")
-#define BT_STR_FILES_SENT_VIA_BLUETOOTH \
-       dgettext(BT_COMMON_PKG, "IDS_BT_MBODY_FILES_SENT_VIA_BLUETOOTH_ABB")
-#define BT_STR_BLUETOOTH_ON \
-       dgettext(BT_COMMON_PKG, "IDS_BT_POP_ACTIVATED")
-#define BT_STR_BLUETOOTH_AVAILABLE \
-       dgettext(BT_COMMON_PKG, "IDS_BT_BODY_BLUETOOTH_AVAILABLE")
+#define BT_STR_FILES_SENT\
+       dgettext(BT_COMMON_PKG, "IDS_ST_BODY_FILES_SENT_ABB")
+#define BT_STR_FILES_RECEIVED\
+       dgettext(BT_COMMON_PKG, "IDS_ST_BODY_FILES_RECEIVED_ABB")
+
+#define BT_STR_SENDING_FILES_TO \
+       dgettext(BT_COMMON_PKG, "IDS_WIFI_BODY_SENDING_FILES_TO_PS_ING")
+#define BT_STR_SENDING_FILES \
+       dgettext(BT_COMMON_PKG, "IDS_BT_BODY_SENDING_FILES_ING_ABB")
+#define BT_STR_RECEIVING_FILES_FROM \
+       dgettext(BT_COMMON_PKG, "IDS_WIFI_BODY_RECEIVING_FILES_FROM_PS_ING")
+#define BT_STR_RECEIVING_FILES \
+       dgettext(BT_COMMON_PKG, "IDS_NFC_BODY_RECEIVING_FILES_ING")
+#define BT_STR_SENDING_FILES_FAILED \
+       dgettext(BT_COMMON_PKG, "IDS_WIFI_POP_SENDING_FILES_FAILED")
+#define BT_STR_RECEIVING_FILES_FAILED \
+       dgettext(BT_COMMON_PKG, "IDS_WIFI_POP_RECEIVING_FILES_FAILED")
 
 /*==============  Image ================= */
 #define ICONDIR                "/usr/apps/ug-bluetooth-efl/res/images"
@@ -85,11 +70,11 @@ extern "C" {
 #define BT_ICON_NOTIFICATION_SENDING           "reserved://quickpanel/ani/uploading"
 #define BT_ICON_NOTIFICATION_SENDING_INDICATOR         "reserved://indicator/ani/uploading"
 #define BT_ICON_NOTIFICATION_SENT              QP_PRELOAD_NOTI_ICON_PATH"/noti_upload_complete.png"
-#define BT_ICON_NOTIFICATION_SENT_INDICATOR            ICONDIR"/B03_Processing_upload_complete.png"
+#define BT_ICON_NOTIFICATION_SENT_INDICATOR            ICONDIR"/b03_processing_upload_complete.png"
 #define BT_ICON_NOTIFICATION_RECEIVING         "reserved://quickpanel/ani/downloading"
 #define BT_ICON_NOTIFICATION_RECEIVING_INDICATOR               "reserved://indicator/ani/downloading"
 #define BT_ICON_NOTIFICATION_RECEIVED          QP_PRELOAD_NOTI_ICON_PATH"/noti_download_complete.png"
-#define BT_ICON_NOTIFICATION_RECEIVED_INDICATOR                ICONDIR"/B03_Processing_download_complete.png"
+#define BT_ICON_NOTIFICATION_RECEIVED_INDICATOR                ICONDIR"/b03_processing_download_complete.png"
 
 #ifdef __cplusplus
 }
index 6190e47..ca73b3b 100644 (file)
@@ -29,53 +29,21 @@ extern "C" {
 #define BT_POPUP_TEXT_LEN \
                (BT_GLOBALIZATION_STR_LENGTH + BT_FILE_NAME_LEN_MAX)
 
-
 /* This value are used in the N-prj */
-#define BT_APP_MSGBOX_TIMEOUT 3
-#define BT_APP_AUTHENTICATION_TIMEOUT 35
-#define BT_APP_AUTHORIZATION_TIMEOUT 15
-#define BT_APP_SECURITY_POPUP_TIMEOUT 10
-#define BT_APP_MSGBOX_FTP_TIMEOUT 10
-#define BT_APP_POPUP_SIZE 100
 #define BT_APP_POPUP_LAUNCH_TIMEOUT 100
 
 typedef enum {
-       POPUP_BUTTON_OK = 1,
-       POPUP_BUTTON_OK_AND_CANCEL,
-       POPUP_BUTTON_CANCEL,
-       POPUP_NO_BUTTON
-} bt_button_type_t;
-
-typedef enum {
-       BT_POPUP_NONE = 0,
-       BT_POPUP_TEXT,
-       BT_POPUP_TITLE_TEXT,
-       BT_POPUP_TEXT_BTN,
-       BT_POPUP_TITLE_TEXT_BTN,
-       BT_POPUP_MAX,
-} bt_popup_types_t;
-
-typedef enum {
-       BT_BTN_NONE = 0,
-       BT_BTN_OK,
-       BT_BTN_CANCEL,
-       BT_BTN_OK_CANCEL,
-       BT_BTN_MAX,
-} bt_btn_types_t;
-
-typedef enum {
        BT_APP_EVENT_CONFIRM_MODE_REQUEST = 0x0001,
        BT_APP_EVENT_FILE_RECEIVED = 0x0002,
        BT_APP_EVENT_INFORMATION = 0x0004,
        BT_APP_EVENT_OVERWRITE_REQUEST = 0x0008
-} bt_app_event_type_t;
+} bt_app_event_type_e;
 
 typedef enum {
        POPUP_RESPONSE_OK,
        POPUP_RESPONSE_CANCEL,
        POPUP_RESPONSE_TIMEOUT
-} bt_popup_response;
-
+} bt_popup_response_e;
 
 typedef struct {
        char *title;
@@ -84,9 +52,7 @@ typedef struct {
        char *device_name;
 } bt_app_sys_popup_params_t;
 
-
-
-int _bt_launch_system_popup(bt_app_event_type_t event_type,
+int _bt_launch_system_popup(bt_app_event_type_e event_type,
                            bt_app_sys_popup_params_t *popup_params,
                            void *cb,
                            void *data);
index f7eb514..c493f70 100644 (file)
@@ -25,10 +25,13 @@ extern "C" {
 #endif
 
 #include "bluetooth-api.h"
+#include "bt-share-main.h"
 
 #define BT_FILE_PATH_LEN_MAX   (4096 + 10)
 #define BT_TEMP_FILE_PATH_LEN_MAX 262
 #define BT_TEXT_LEN_MAX 255
+#define BT_ADDRESS_STRING_SIZE 18 /**< This specifies bluetooth device address string length */
+#define BLUETOOTH_DEVICE_NAME_LENGTH_MAX 248 /**< This specifies maximum device name length */
 
 typedef enum {
        BT_FILE_IMAGE,  /**<IMAGE */
@@ -38,15 +41,38 @@ typedef enum {
        BT_FILE_VMEMO,
        BT_FILE_DOC,    /**<DOC, */
        BT_FILE_OTHER   /**<OTHER*/
-} bt_file_type_t;
+} bt_file_type_e;
 
-int _bt_get_transfer_id_by_noti_id(int noti_id);
+typedef struct {
+       int id;
+       char *address;
+       char *device_name;
+       char *db_sid;
+       bt_transfer_status_info_t recv_data;
+} bt_device_rcv_noti_info_t;
+
+typedef struct {
+       char address[BT_ADDRESS_STRING_SIZE];
+       char device_name[BLUETOOTH_DEVICE_NAME_LENGTH_MAX];
+       char *db_sid;
+       notification_h send_noti;
+       bt_transfer_status_info_t send_data;
+} bt_device_snd_noti_info_t;
+
+bt_obex_server_authorize_into_t server_auth_info;
 
 void _bt_clear_receive_noti_list(void);
 
 void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                               void *user_data);
 
+void _bt_get_default_storage(char *storage);
+
+void _bt_obex_cancel_transfer(void *data);
+
+void _bt_convert_addr_type_to_string(char *address,
+                               char *addr);
+
 void _bt_obex_server_event_handler(int event,
                                       bluetooth_event_param_t *param,
                                       void *user_data);
@@ -54,9 +80,6 @@ void _bt_obex_server_event_handler(int event,
 void _bt_app_obex_download_dup_file_cb(void *data, void *obj,
                                       void *event_info);
 
-void _bt_get_default_storage(char *storage);
-void _bt_obex_cancel_transfer(void *data);
-
 void _bt_free_auth_info();
 
 #ifdef __cplusplus
index d7c2186..ca6d9fb 100644 (file)
@@ -58,7 +58,7 @@ static int __bt_eventsystem_set_value(const char *event, const char *key, const
 int _bt_share_block_sleep(gboolean is_block)
 {
        static int block_sleep_count = 0;
-       int result = -1;
+       int result = BT_SHARE_FAIL;
 
        DBG("is_block [%d], block_sleep_count[%d]\n", is_block,
                     block_sleep_count);
@@ -70,16 +70,14 @@ int _bt_share_block_sleep(gboolean is_block)
                        block_sleep_count = 0;
                } else if (block_sleep_count == 0) {
                        result = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
-                       if (result != 0) {
+                       if (result != 0)
                                INFO("LCD Lock is failed with result code [%d]\n", result);
-                       }
                } else {
-                       result = 0;
+                       result = BT_SHARE_ERROR_NONE;
                }
 
-               if (result == 0) {
+               if (result == BT_SHARE_ERROR_NONE)
                        block_sleep_count++;
-               }
        } else {
                if (block_sleep_count <= 0) {
                        INFO("block_sleep_count[%d] is invalid. It is set to 0.\n",
@@ -92,12 +90,11 @@ int _bt_share_block_sleep(gboolean is_block)
                                             result);
                        }
                } else {
-                       result = 0;
+                       result = BT_SHARE_ERROR_NONE;
                }
 
-               if (result == 0) {
+               if (result == BT_SHARE_ERROR_NONE)
                        block_sleep_count--;
-               }
        }
 
        DBG("result [%d]\n", result);
@@ -108,16 +105,13 @@ int _bt_share_block_sleep(gboolean is_block)
 
 int _bt_set_transfer_indicator(gboolean state)
 {
-       int bt_device_state;
        static int block_cnt = 0;
-       int ret;
+       int bt_device_state = 0;
+       int ret = VCONF_OK;
        const char *event_val = NULL;
 
        ret = vconf_get_int(VCONFKEY_BT_STATUS, (void *)&bt_device_state);
-       if (ret != 0) {
-               ERR("Get vconf failed\n");
-               return -1;
-       }
+       retvm_if(ret != VCONF_OK, VCONF_ERROR, "Get vconf failed\n");
 
        if (state == TRUE) {
                block_cnt++;
@@ -129,7 +123,7 @@ int _bt_set_transfer_indicator(gboolean state)
                if (block_cnt > 0)
                        block_cnt--;
                if (block_cnt != 0)
-                       return 0;
+                       return BT_SHARE_ERROR_NONE;
                bt_device_state ^= BT_STATUS_TRANSFER;
                event_val = EVT_VAL_BT_NON_TRANSFERING;
        }
@@ -146,20 +140,17 @@ int _bt_set_transfer_indicator(gboolean state)
 #endif
 
        ret = vconf_set_int(VCONFKEY_BT_STATUS, bt_device_state);
-       if (ret != 0) {
-               ERR("Set vconf failed\n");
-               return -1;
-       }
-       return 0;
+       retvm_if(ret != VCONF_OK, VCONF_ERROR, "Set vconf failed\n");
+       return BT_SHARE_ERROR_NONE;
 }
 
 static char *__bt_share_get_transfer_file_name(int file_type)
 {
        int count = 0;
-       char *appendix;
-       char *file;
-       char *file_format;
-       char *file_name;
+       char *appendix = NULL;
+       char *file = NULL;
+       char *file_format = NULL;
+       char *file_name = NULL;
 
        if (file_type == BT_HTTP_FILE) {
                file_name = HTML_FILE_NAME;
@@ -188,7 +179,7 @@ static char *__bt_share_get_transfer_file_name(int file_type)
 void _bt_remove_tmp_file(char *file_path)
 {
        if (g_str_has_prefix(file_path, BT_TMP_FILE) == TRUE) {
-               DBG("Remove the file: %s", file_path);
+               DBG_SECURE("Remove the file: %s", file_path);
                ecore_file_remove(file_path);
        }
 }
@@ -196,22 +187,22 @@ void _bt_remove_tmp_file(char *file_path)
 void _bt_remove_vcf_file(char *file_path)
 {
        if (g_str_has_prefix(file_path, BT_CONTACT_SHARE_TMP_DIR) == TRUE) {
-               DBG("Remove the file: %s", file_path);
+               DBG_SECURE("Remove the file: %s", file_path);
                ecore_file_remove(file_path);
        }
 }
 
 char *_bt_share_create_transfer_file(char *text)
 {
-       int fd;
-       int file_type;
-       char *file = NULL;
-       char *content;
-       char *url_sheme;
-       ssize_t write_size;
-
        retv_if(text == NULL, NULL);
 
+       int fd = -1;
+       int file_type = -1;
+       char *file = NULL;
+       char *content = NULL;
+       char *url_sheme = NULL;
+       ssize_t write_size = -1;
+
        url_sheme = g_uri_parse_scheme(text);
 
        if (url_sheme) {
@@ -229,17 +220,16 @@ char *_bt_share_create_transfer_file(char *text)
        fd = open(file, O_RDWR | O_CREAT, 0755);
 
        if (fd < 0) {
-               ERR("Fail to open the file");
+               ERR("Fail to open the file : %s", file);
                goto fail;
        }
 
-       if (file_type == BT_HTTP_FILE) {
+       if (file_type == BT_HTTP_FILE)
                content = g_strdup_printf(HTML_FORMAT, text, text);
-       } else {
+       else
                content = g_strdup(text);
-       }
 
-       DBG("content: \n%s", content);
+       DBG_SECURE("content: \n%s", content);
 
        write_size = write(fd, content, strlen(content));
        g_free(content);
@@ -256,6 +246,23 @@ fail:
        return NULL;
 }
 
+char *_bt_get_time_of_the_day(void)
+{
+       char *p = NULL;
+       char buffer[20] = {0, };
+       time_t cur_time = 0;
+       struct tm new_time;
+       struct timeval tv = {0, };
+
+       p = (char *)g_malloc(30);
+       gettimeofday(&tv, NULL);
+       cur_time = tv.tv_sec;
+       localtime_r(&cur_time, &new_time);
+       strftime(buffer, 20, "%m%d%Y%T", &new_time);
+       snprintf(p, 30, "%s%ld", buffer, tv.tv_usec);
+       return p;
+}
+
 static bool __bt_get_storage_id(int sid, storage_type_e type, storage_state_e state,
                const char *path, void *user_data)
 {
index 7d0d924..a871850 100644 (file)
@@ -17,8 +17,6 @@
  *
  */
 
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
 #include <glib.h>
 #include <time.h>
 #include <sys/stat.h>
 #include <aul.h>
 #include <vconf.h>
 #include <bundle_internal.h>
-#include <gio/gio.h>
 
 #include "applog.h"
-#include "bluetooth-api.h"
 #include "bt-share-main.h"
 #include "bt-share-ipc.h"
 #include "bt-share-syspopup.h"
 
 #define FILEPATH_LEN_MAX 4096
 
+#define SIGNAL_COUNT_TO_SUBSCRIBE 7
+
 GSList *bt_transfer_list = NULL;
-DBusConnection *dbus_connection = NULL;
-static GDBusConnection *system_gconn = NULL;
+static GDBusConnection *gdbus_connection = NULL;
 static GDBusProxy *core_proxy = NULL;
 
-extern struct bt_appdata *app_state;
+extern bt_appdata_t *app_state;
 
 static void __bt_create_send_data(opc_transfer_info_t *node);
 static void __bt_create_send_failed_data(char *filepath, char *dev_name,
                                                char *addr, char *type, unsigned int size);
 static void __bt_share_update_tr_info(int tr_uid, int tr_type);
+static void __free_transfer_info(opc_transfer_info_t *node);
+static int __request_file_send(opc_transfer_info_t *node);
+static GDBusConnection *__bt_get_system_gconn(void);
 
 static void __bt_tr_data_free(bt_tr_data_t *data)
 {
@@ -65,17 +65,17 @@ static void __bt_tr_data_free(bt_tr_data_t *data)
        g_free(data->addr);
        g_free(data->type);
        g_free(data->content);
+       g_free(data->db_sid);
        g_free(data);
 }
 
 static void __popup_res_cb(int res)
 {
-       DBG("+");
-       struct bt_appdata *ad = app_state;
-       if (ad->popups.syspopup_request == FALSE) {
-               DBG("This event is not mine\n");
-               return;
-       }
+       FN_START;
+       bt_appdata_t *ad = app_state;
+
+       retm_if(ad->popups.syspopup_request == FALSE, "This event is not mine\n");
+
        DBG(" res : %d", res);
        /* Inorder to support calling popup from callback, we have to make
         * syspopup_request false here and also should not assign
@@ -89,14 +89,12 @@ static void __popup_res_cb(int res)
                                            NULL, (void *)POPUP_RESPONSE_OK);
                else if (res == 1)
                        ad->popups.popup_cb(ad->popups.popup_cb_data,
-                                           NULL,
-                                           (void *)POPUP_RESPONSE_CANCEL);
+                                           NULL, (void *)POPUP_RESPONSE_CANCEL);
                else if (res == 2)
                        ad->popups.popup_cb(ad->popups.popup_cb_data,
-                                           NULL,
-                                           (void *)POPUP_RESPONSE_TIMEOUT);
+                                           NULL, (void *)POPUP_RESPONSE_TIMEOUT);
        }
-       DBG("-");
+       FN_END;
 }
 
 static char *__bt_transfer_folder_path(char *dest_path)
@@ -116,71 +114,46 @@ static char *__bt_transfer_folder_path(char *dest_path)
        return dst_path;
 }
 
-static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
+static opc_transfer_info_t *__add_transfer_info(GVariant *msg)
 {
-       DBG("+");
+       FN_START;
+       retv_if(msg == NULL, NULL);
+
        int i = 0;
        int cnt = 0;
-       char addr[BLUETOOTH_ADDRESS_LENGTH] = { 0, };
+       unsigned int file_size = 0;
        char *name = NULL;
        char *type = NULL;
-       char byte;
+       char byte = 0;
        char *file_path = NULL;
-       char mime_type[BT_MIME_TYPE_MAX_LEN] = { 0 };
-       unsigned int file_size = 0;
-       struct stat file_attr;
-       int len;
-       opc_transfer_info_t *data;
-       struct bt_appdata *ad = app_state;
-       DBusMessageIter iter;
-       DBusMessageIter iter_addr;
-       DBusMessageIter iter_file;
-       DBusMessageIter iter_filepath;
+       opc_transfer_info_t *data = NULL;
+       bt_appdata_t *ad = app_state;
        GSList *list = NULL;
+       char addr[BLUETOOTH_ADDRESS_LENGTH] = {0, };
+       char mime_type[BT_MIME_TYPE_MAX_LEN] = {0, };
+       char bd_addr[BT_ADDRESS_STRING_SIZE] = {0, };
+       char file[FILEPATH_LEN_MAX] = {0, };
+       struct stat file_attr = {0, };
 
-       retv_if(msg == NULL, NULL);
+       GVariantIter *iter_addr;
+       GVariantIter *iter_filepath;
+       GVariantIter *iter_file;
 
-       dbus_message_iter_init(msg, &iter);
-       dbus_message_iter_recurse(&iter, &iter_addr);
+       g_variant_get(msg, "(ayssaay)", &iter_addr, &name, &type, &iter_filepath);
 
-       while (dbus_message_iter_get_arg_type(&iter_addr) == DBUS_TYPE_BYTE) {
-               dbus_message_iter_get_basic(&iter_addr, &byte);
-               addr[i] = byte;
-               i++;
-               dbus_message_iter_next(&iter_addr);
-       }
+       while (g_variant_iter_loop(iter_addr, "y", &byte))
+               addr[i++] = byte;
+       g_variant_iter_free(iter_addr);
 
-       dbus_message_iter_next(&iter);
-       dbus_message_iter_get_basic(&iter, &name);
-       dbus_message_iter_next(&iter);
-       dbus_message_iter_get_basic(&iter, &type);
-
-       dbus_message_iter_next(&iter);
-       dbus_message_iter_recurse(&iter, &iter_file);
-
-       memset(&file_attr, 0, sizeof(struct stat));
-
-       while (dbus_message_iter_get_arg_type(&iter_file) == DBUS_TYPE_ARRAY) {
+       while (g_variant_iter_loop(iter_filepath, "ay", &iter_file)) {
                char *dst_path = NULL;
                i = 0;
-               dbus_message_iter_recurse(&iter_file, &iter_filepath);
-               len = dbus_message_iter_get_array_len(&iter_filepath);
-               if (len <= 0)
-                       continue;
-
-               file_path = g_malloc0(len + 1);
-               if (file_path == NULL) {
-                       ERR("Not enough memory!");
-                       return NULL;
-               }
+               memset(file, 0, FILEPATH_LEN_MAX);
 
-               while (dbus_message_iter_get_arg_type(&iter_filepath) ==
-                      DBUS_TYPE_BYTE) {
-                       dbus_message_iter_get_basic(&iter_filepath, &byte);
-                       file_path[i] = byte;
-                       i++;
-                       dbus_message_iter_next(&iter_filepath);
-               }
+               while (g_variant_iter_loop(iter_file, "y", &byte))
+                       file[i++] = byte;
+
+               file_path = g_strdup(file);
 
                dst_path = __bt_transfer_folder_path(file_path);
                if (dst_path != NULL) {
@@ -191,13 +164,14 @@ static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
                if (aul_get_mime_from_file(file_path, mime_type,
                                BT_MIME_TYPE_MAX_LEN) == AUL_R_OK)
                        INFO("mime type = %s", mime_type);
+
                if (g_utf8_validate(file_path, -1, NULL)) {
                        if (stat(file_path, &file_attr) == 0)
                                file_size = file_attr.st_size;
                        else
                                file_size = 0;
-                       INFO("%d", file_size);
 
+                       INFO("%d", file_size);
                        list = g_slist_append(list, file_path);
                } else {
                        DBG("Invalid filepath");
@@ -205,18 +179,24 @@ static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
                        __bt_create_send_failed_data(file_path, name, addr,
                                                                mime_type, file_size);
 
+                       _bt_convert_addr_type_to_string(bd_addr, addr);
+                       DBG_SECURE("bd_addr = [%s]", bd_addr);
                        if (ad->send_noti == NULL) {
-                               ad->send_noti = _bt_insert_notification(ad, BT_SENT_NOTI, 0, 0);
+                               ad->send_noti = _bt_insert_notification(ad,
+                                                       BT_SENT_NOTI, name,
+                                                       bd_addr, NULL);
                        } else {
-                               _bt_update_notification(ad, ad->send_noti, NULL, NULL, NULL);
+                               _bt_update_notification(ad, ad->send_noti,
+                                               NULL, NULL, NULL, NULL);
                        }
 
                        g_free(file_path);
+                       file_path = NULL;
                }
-
-               dbus_message_iter_next(&iter_file);
        }
 
+       g_variant_iter_free(iter_filepath);
+
        cnt = g_slist_length(list);
        INFO("cnt = %d", cnt);
 
@@ -224,13 +204,16 @@ static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
                /* Show unable to send popup */
                _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL,
                        BT_STR_UNABLE_TO_SEND);
+
+               g_free(name);
+               g_free(type);
                return NULL;
        }
 
        INFO("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", addr[0],
            addr[1], addr[2], addr[3], addr[4], addr[5]);
        INFO(" cnt( %d )", cnt);
-       DBG(" name ( %s )", name);
+       DBG_SECURE(" name ( %s )", name);
 
        data = g_new0(opc_transfer_info_t, 1);
        data->content = g_new0(char *, cnt + 1);
@@ -243,7 +226,7 @@ static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
 
        for (i = 0; i < cnt; i++) {
                char *ptr = g_slist_nth_data(list, i);
-               DBG("%s", ptr);
+               DBG_SECURE("%s", ptr);
                if (g_strcmp0(type, "text") == 0)
                        data->file_path[i] = _bt_share_create_transfer_file(ptr);
                else
@@ -268,139 +251,96 @@ static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
        bt_transfer_list = g_slist_append(bt_transfer_list, data);
 
        g_slist_free_full(list, g_free);
+       g_free(name);
+       g_free(type);
 
        return data;
 }
 
-void _free_transfer_info(opc_transfer_info_t *node)
+static void __free_transfer_info(opc_transfer_info_t *node)
 {
-       int i;
-
-       DBG("+");
+       FN_START;
        ret_if(node == NULL);
 
+       int i = 0;
+
        for (i = 0; i < node->file_cnt; i++) {
-               //_bt_remove_tmp_file(node->file_path[i]);
                g_free(node->file_path[i]);
                g_free(node->content[i]);
                g_free(node->type[i]);
        }
+
        g_free(node->file_path);
        g_free(node->content);
        g_free(node->type);
        g_free(node->size);
        g_free(node);
 
-       DBG("-");
+       FN_END;
 }
 
 void _remove_transfer_info(opc_transfer_info_t *node)
 {
-       DBG("+");
+       FN_START;
        ret_if(node == NULL);
 
        bt_transfer_list = g_slist_remove(bt_transfer_list, node);
-       _free_transfer_info(node);
+       __free_transfer_info(node);
 
-       DBG("-");
+       FN_END;
 }
 
-int _request_file_send(opc_transfer_info_t *node)
+static int __request_file_send(opc_transfer_info_t *node)
 {
-       struct bt_appdata *ad = app_state;
-       int ret;
-       DBG("+");
-       retv_if(ad == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+       FN_START;
+       int ret = 0;
+
+       retv_if(app_state == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
        retv_if(node == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
        ret = bluetooth_opc_push_files((bluetooth_device_address_t *)node->addr,
-                                       node->file_path);
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               ERR("bluetooth_opc_push_files failed : %d", ret);
-               return ret;
-       }
+                                    node->file_path);
+       retvm_if(ret != BLUETOOTH_ERROR_NONE, ret,
+                       "bluetooth_opc_push_files failed : %d", ret);
 
        __bt_create_send_data(node);
 
-       DBG("-");
-       return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_get_owner_info(DBusMessage *msg, char **name,
-                               char **previous, char **current)
-{
-       DBusMessageIter item_iter;
-
-       dbus_message_iter_init(msg, &item_iter);
-
-       if (dbus_message_iter_get_arg_type(&item_iter)
-                                       != DBUS_TYPE_STRING) {
-               ERR("This is bad format dbus\n");
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       dbus_message_iter_get_basic(&item_iter, name);
-
-       retv_if(*name == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       dbus_message_iter_next(&item_iter);
-
-       if (dbus_message_iter_get_arg_type(&item_iter)
-                                       != DBUS_TYPE_STRING) {
-               ERR("This is bad format dbus\n");
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       dbus_message_iter_get_basic(&item_iter, previous);
-
-       retv_if(*previous == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       dbus_message_iter_next(&item_iter);
-
-       if (dbus_message_iter_get_arg_type(&item_iter)
-                                       != DBUS_TYPE_STRING) {
-               ERR("This is bad format dbus\n");
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       dbus_message_iter_get_basic(&item_iter, current);
-
-       retv_if(*current == NULL, BLUETOOTH_ERROR_INTERNAL);
-
+       FN_END;
        return BLUETOOTH_ERROR_NONE;
 }
 
-static DBusHandlerResult __event_filter(DBusConnection *sys_conn,
-                                       DBusMessage *msg, void *data)
+static void __event_filter(GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
 {
-       int ret;
-       char *member;
-       struct bt_appdata *ad = app_state;
-       const char *path = dbus_message_get_path(msg);
-
+       int ret = 0;
+       bt_appdata_t *ad = app_state;
 #ifdef CYNARA_ENABLE
        const char *sender;
        bt_share_cynara_creds sender_creds;
 #endif
 
-       if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-       if (path == NULL || strcmp(path, "/") == 0)
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-       member = (char *)dbus_message_get_member(msg);
-       INFO("member (%s)", member);
-
-       if (dbus_message_is_signal
-           (msg, BT_SYSPOPUP_INTERFACE, BT_SYSPOPUP_METHOD_RESPONSE)) {
-               int res = 0;
-               dbus_message_get_args(msg, NULL,
-                                     DBUS_TYPE_INT32, &res, DBUS_TYPE_INVALID);
-               __popup_res_cb(res);
-       } else if (dbus_message_is_signal
-               (msg, BT_UG_IPC_INTERFACE, BT_UG_IPC_METHOD_SEND)) {
-               opc_transfer_info_t *node;
+/*
+       DBG("Path = %s", object_path);
+*/
+       ret_if(object_path == NULL || strcmp(object_path, "/") == 0);
+       ret_if(interface_name == NULL || signal_name == NULL);
+
+       if (!g_strcmp0(interface_name, BT_SYSPOPUP_INTERFACE)) {
+               DBG("syspopup signal_name = %s", signal_name);
+               if (!g_strcmp0(signal_name, BT_SYSPOPUP_METHOD_RESPONSE)) {
+                       int res = 0;
+                       g_variant_get(parameters, "(i)", &res);
+                       __popup_res_cb(res);
+               }
+       } else if (!g_strcmp0(interface_name, BT_UG_IPC_INTERFACE)) {
+               DBG("ug signal_name = %s", signal_name);
+               if (!g_strcmp0(signal_name, BT_UG_IPC_METHOD_SEND)) {
+                       opc_transfer_info_t *node = NULL;
 
 #ifdef CYNARA_ENABLE
                sender = dbus_message_get_sender(msg);
@@ -409,198 +349,226 @@ static DBusHandlerResult __event_filter(DBusConnection *sys_conn,
                        ERR("acquiring cynara creds failed\n");
                        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
                }
-
                if (_bt_share_cynara_check(&sender_creds, BT_SHARE_PRIVILEGE) != BT_SHARE_FAIL) {
                        ERR("Cynara denied file send\n");
                        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
                }
 #endif
-               node = __add_transfer_info(msg);
-               if (node == NULL)
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-               ret = _request_file_send(node);
-               if (ret == BLUETOOTH_ERROR_IN_PROGRESS) {
-                       INFO("Aleady OPC progressing. Once completed previous job, will be started");
-               } else if (ret != BLUETOOTH_ERROR_NONE) {
-                       _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL, BT_STR_UNABLE_TO_SEND);
-                       g_slist_free_full(bt_transfer_list,
-                                         (GDestroyNotify) _free_transfer_info);
-                       bt_transfer_list = NULL;
-               }
-       } else if (dbus_message_is_signal(msg, BT_SHARE_UI_INTERFACE, BT_SHARE_UI_SIGNAL_OPPABORT)) {
-               const char *transfer_type = NULL;
-               int noti_id = 0;
-
-               if (!dbus_message_get_args(msg, NULL,
-                                          DBUS_TYPE_STRING, &transfer_type,
-                                          DBUS_TYPE_INT32, &noti_id,
-                                          DBUS_TYPE_INVALID)) {
-                       ERR("OPP abort handling failed");
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       node = __add_transfer_info(parameters);
+                       retm_if(node == NULL, "node is NULL");
+
+                       ret = __request_file_send(node);
+                       if (ret == BLUETOOTH_ERROR_IN_PROGRESS) {
+                               INFO("Aleady OPC progressing. Once completed previous job, will be started");
+                       } else if (ret != BLUETOOTH_ERROR_NONE) {
+                               _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL, BT_STR_UNABLE_TO_SEND);
+                               g_slist_free_full(bt_transfer_list, (GDestroyNotify)__free_transfer_info);
+                               bt_transfer_list = NULL;
+                       }
                }
-               ad->opp_transfer_abort = TRUE; /* Transfer aborted by user*/
-               INFO("transfer_type = %s", transfer_type);
-               if (!g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT)) {
-                       bluetooth_opc_cancel_push();
-                       if (ad->opc_noti) {
-                               ret = _bt_delete_notification(ad->opc_noti);
-                               if (ret == NOTIFICATION_ERROR_NONE) {
-                                       ad->opc_noti = NULL;
-                                       ad->opc_noti_id = 0;
+       } else if (!g_strcmp0(interface_name, BT_SHARE_UI_INTERFACE)) {
+               DBG("share ui signal_name = %s", signal_name);
+
+               if (!g_strcmp0(signal_name, BT_SHARE_UI_SIGNAL_OPPABORT)) {
+                       const gchar *transfer_type = NULL;
+                       int noti_id = 0;
+
+                       g_variant_get(parameters, "(&si)", &transfer_type, &noti_id);
+
+                       ad->opp_transfer_abort = TRUE; /* Transfer aborted by user*/
+                       INFO("transfer_type = %s", transfer_type);
+                       if (!g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT)) {
+                               bluetooth_opc_cancel_push();
+                               if (ad->opc_noti) {
+                                       ret = _bt_delete_notification(ad->opc_noti);
+                                       if (ret == NOTIFICATION_ERROR_NONE) {
+                                               ad->opc_noti = NULL;
+                                               ad->opc_noti_id = 0;
+                                       }
                                }
+                       } else {
+                               bluetooth_obex_server_cancel_transfer(noti_id);
                        }
-               } else {
-                       bluetooth_obex_server_cancel_transfer(noti_id);
-               }
-       } else if (dbus_message_is_signal(msg, BT_SHARE_UI_INTERFACE,
-                                         BT_SHARE_UI_SIGNAL_SEND_FILE)) {
-               opc_transfer_info_t *node;
+               } else if (!g_strcmp0(signal_name, BT_SHARE_UI_SIGNAL_SEND_FILE)) {
+                       opc_transfer_info_t *node = NULL;
 
 #ifdef CYNARA_ENABLE
-               sender = dbus_message_get_sender(msg);
-               ret = _bt_share_cynara_get_creds(sys_conn, sender, &sender_creds);
-               if (ret != 0) {
-                       ERR("acquiring cynara creds failed\n");
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-               }
+                       sender = dbus_message_get_sender(msg);
+                       ret = _bt_share_cynara_get_creds(sys_conn, sender, &sender_creds);
+                       if (ret != 0) {
+                               ERR("acquiring cynara creds failed\n");
+                               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       }
 
-               if (_bt_share_cynara_check(&sender_creds, BT_SHARE_PRIVILEGE) != BT_SHARE_FAIL) {
-                       ERR("Cynara denied file send\n");
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-               }
+                       if (_bt_share_cynara_check(&sender_creds, BT_SHARE_PRIVILEGE) != BT_SHARE_FAIL) {
+                               ERR("Cynara denied file send\n");
+                               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       }
 #endif
-               node = __add_transfer_info(msg);
-               if (node == NULL)
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       node = __add_transfer_info(parameters);
+                       retm_if(node == NULL, "node is NULL");
+
+                       ret = __request_file_send(node);
+                       if (ret == BLUETOOTH_ERROR_IN_PROGRESS) {
+                               INFO("Aleady OPC progressing. Once completed previous job, will be started");
+                       } else if (ret != BLUETOOTH_ERROR_NONE) {
+                               _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL, BT_STR_UNABLE_TO_SEND);
+                               g_slist_free_full(bt_transfer_list, (GDestroyNotify)__free_transfer_info);
+                               bt_transfer_list = NULL;
+                       }
+               } else if (!g_strcmp0(signal_name, BT_SHARE_UI_SIGNAL_INFO_UPDATE)) {
+                       int tr_uid = 0;
+                       int tr_type = 0;
 
-               ret = _request_file_send(node);
-               if (ret == BLUETOOTH_ERROR_IN_PROGRESS) {
-                       INFO("Aleady OPC progressing. Once completed previous job, will be started");
-               } else if (ret != BLUETOOTH_ERROR_NONE) {
-                       _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL, BT_STR_UNABLE_TO_SEND);
-                       g_slist_free_full(bt_transfer_list,
-                                         (GDestroyNotify) _free_transfer_info);
-                       bt_transfer_list = NULL;
-               }
-       } else if (dbus_message_is_signal(msg, BT_SHARE_UI_INTERFACE,
-                                         BT_SHARE_UI_SIGNAL_INFO_UPDATE)) {
-               int tr_uid = 0;
-               int tr_type = 0;
-               dbus_message_get_args(msg, NULL,
-                                     DBUS_TYPE_INT32, &tr_uid,
-                                     DBUS_TYPE_INT32, &tr_type,
-                                     DBUS_TYPE_INVALID);
-
-               INFO("tr_uid = %d, tr_type = %d ", tr_uid, tr_type);
-               __bt_share_update_tr_info(tr_uid, tr_type);
-       } else if (dbus_message_is_signal(msg, BT_SHARE_FRWK_INTERFACE,
-                                         BT_SHARE_FRWK_SIGNAL_DEINIT)) {
-               /* Deinitialize the obex server */
-               if (bluetooth_obex_server_deinit() == BLUETOOTH_ERROR_NONE) {
-                       DBG("Obex Server deinit");
+                       g_variant_get(parameters, "(ii)", &tr_uid, &tr_type);
+
+                       __bt_share_update_tr_info(tr_uid, tr_type);
                }
-       } else if (strcasecmp(member, "NameOwnerChanged") == 0) {
-               char *name = NULL;
-               char *previous = NULL;
-               char *current = NULL;
+       } else if (!g_strcmp0(interface_name, BT_SHARE_FRWK_INTERFACE)) {
+               DBG("frwk signal_name = %s", signal_name);
 
-               if (__bt_get_owner_info(msg, &name, &previous, &current)) {
-                       ERR("Fail to get the owner info");
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+               if (!g_strcmp0(signal_name, BT_SHARE_FRWK_SIGNAL_DEINIT)) {
+                       /* Deinitialize the obex server */
+                       if (bluetooth_obex_server_deinit() == BLUETOOTH_ERROR_NONE)
+                               DBG("Obex Server deinit");
                }
+       } else if (!g_strcmp0(interface_name, BT_BLUEZ_INTERFACE)) {
+               if (!g_strcmp0(signal_name, BT_BLUEZ_SIGNAL_NAME_OWNER_CHANGED)) {
+                       char *name = NULL;
+                       char *previous = NULL;
+                       char *current = NULL;
 
-               if (*current != '\0')
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       g_variant_get(parameters, "(&s&s&s)", &name, &previous, &current);
 
-               if (strcasecmp(name, "org.bluez") == 0) {
-                       INFO("Bluetoothd is terminated");
-                       _bt_terminate_bluetooth_share();
+                       if (*current != '\0')
+                               return;
+
+                       if (strcasecmp(name, "org.projectx.bt") == 0) {
+                               INFO("bt-service is terminated");
+                               _bt_terminate_bluetooth_share();
+                       }
                }
        } else {
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+               DBG("Unhandled signal");
        }
-       return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-gboolean _bt_init_dbus_signal(void)
+static int __bt_share_add_filter_subscribe_signal(GDBusConnection *conn,
+               gboolean subscribe)
 {
-       DBG("+");
-       DBusError dbus_error;
+       struct {
+               char *interface;
+               char *member;
+       } match_string[SIGNAL_COUNT_TO_SUBSCRIBE] = {
+                       { BT_SYSPOPUP_INTERFACE, BT_SYSPOPUP_METHOD_RESPONSE },
+                       { BT_UG_IPC_INTERFACE, BT_UG_IPC_METHOD_SEND},
+                       { BT_SHARE_UI_INTERFACE, BT_SHARE_UI_SIGNAL_OPPABORT},
+                       { BT_SHARE_UI_INTERFACE, BT_SHARE_UI_SIGNAL_SEND_FILE},
+                       { BT_SHARE_UI_INTERFACE, BT_SHARE_UI_SIGNAL_INFO_UPDATE},
+                       { BT_SHARE_FRWK_INTERFACE, BT_SHARE_FRWK_SIGNAL_DEINIT},
+                       { BT_BLUEZ_INTERFACE, BT_BLUEZ_SIGNAL_NAME_OWNER_CHANGED}
+       };
+
+       static guint subs_add_filter_id[SIGNAL_COUNT_TO_SUBSCRIBE] = {0, };
+       int i;
 
-       dbus_error_init(&dbus_error);
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
-       if (dbus_connection == NULL) {
-               dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
+       if (subscribe == FALSE) {
+               for (i = 0; i < SIGNAL_COUNT_TO_SUBSCRIBE; ++i) {
+                       if (subs_add_filter_id[i] != 0) {
+                               g_dbus_connection_signal_unsubscribe(conn, subs_add_filter_id[i]);
+                               subs_add_filter_id[i] = 0;
+                       }
+               }
+               return BLUETOOTH_ERROR_NONE;
        }
 
-       if (dbus_connection == NULL) {
-               ERR(" DBUS get failed");
-               if (dbus_error_is_set(&dbus_error)) {
-                       ERR("D-Bus Error: %s\n", dbus_error.message);
-                       dbus_error_free(&dbus_error);
+       for (i = 0; i < SIGNAL_COUNT_TO_SUBSCRIBE; ++i) {
+               if (subs_add_filter_id[i] == 0) {
+                       subs_add_filter_id[i] = g_dbus_connection_signal_subscribe(
+                                       conn, NULL, match_string[i].interface,
+                                       match_string[i].member, NULL, NULL,
+                                       G_DBUS_SIGNAL_FLAGS_NONE, __event_filter, NULL, NULL);
                }
+       }
+       return BLUETOOTH_ERROR_NONE;
+}
+
+gboolean _bt_init_dbus_signal(void)
+{
+       FN_START;
+       GError *error = NULL;
+       GDBusConnection *conn = NULL;
+
+       conn = __bt_get_system_gconn();
+       if (!conn) {
+               ERR("GDBUS get failed");
+               g_error_free(error);
                return FALSE;
        }
 
-       dbus_connection_setup_with_g_main(dbus_connection, NULL);
+       gdbus_connection = conn;
 
        /* Add the filter for network client functions */
-       dbus_connection_add_filter(dbus_connection, __event_filter, NULL, NULL);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_BLUEZ_INTERFACE
-                       ",member=NameOwnerChanged", &dbus_error);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_SYSPOPUP_INTERFACE
-                       ",member=Response", &dbus_error);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_UG_IPC_INTERFACE
-                       ",member=Send", &dbus_error);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_SHARE_UI_INTERFACE
-                       ",member=opp_abort", &dbus_error);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_SHARE_UI_INTERFACE
-                       ",member=send_file", &dbus_error);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_SHARE_UI_INTERFACE
-                       ",member=info_update", &dbus_error);
-       dbus_bus_add_match(dbus_connection,
-                       "type=signal,interface=" BT_SHARE_FRWK_INTERFACE
-                       ",member=deinit", &dbus_error);
-       if (dbus_error_is_set(&dbus_error)) {
-               ERR("Fail to add dbus filter signal");
-               dbus_error_free(&dbus_error);
-       }
+       __bt_share_add_filter_subscribe_signal(conn, TRUE);
 
-       DBG("-");
+       FN_END;
        return TRUE;
 }
 
+void _bt_deinit_dbus_signal(void)
+{
+       FN_START;
+       __bt_share_add_filter_subscribe_signal(gdbus_connection, FALSE);
+       FN_END;
+}
+
+void _bt_send_disconnected_signal(char *signal, int result,
+               char *address, int transfer_id)
+{
+       FN_START;
+       retm_if(gdbus_connection == NULL, "gdbus_connection == NULL");
+
+       GDBusMessage *msg = NULL;
+       GVariant *param = NULL;
+
+       msg = g_dbus_message_new_signal(BT_SHARE_ENG_OBJECT,
+                               BT_SHARE_ENG_INTERFACE,
+                               signal);
+       retm_if(msg == NULL, "Unable to allocate memory");
+
+       param = g_variant_new("(isi)", result, address, transfer_id);
+       g_dbus_message_set_body(msg, param);
+
+       g_dbus_message_set_destination(msg, BT_SHARE_UI_INTERFACE);
+       g_dbus_connection_send_message(gdbus_connection, msg,
+                       G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
+
+       g_object_unref(msg);
+       FN_END;
+}
+
 void _bt_update_transfer_list_view(char *db)
 {
-       DBusMessage *msg = NULL;
-       ret_if(dbus_connection == NULL);
+       ret_if(gdbus_connection == NULL);
+
+       GDBusMessage *msg = NULL;
+       GVariant *param = NULL;
 
-       msg = dbus_message_new_signal(BT_SHARE_ENG_OBJECT,
+       msg = g_dbus_message_new_signal(BT_SHARE_ENG_OBJECT,
                                BT_SHARE_ENG_INTERFACE,
                                BT_SHARE_ENG_SIGNAL_UPDATE_VIEW);
-       if (!msg) {
-               ERR("Unable to allocate memory");
-               return;
-       }
+       retm_if(!msg, "Unable to allocate memory");
 
-       if (!dbus_message_append_args(msg,
-                               DBUS_TYPE_STRING, &db,
-                               DBUS_TYPE_INVALID)) {
-               ERR("Event sending failed");
-               dbus_message_unref(msg);
-               return;
-       }
+       param = g_variant_new("(s)", db);
+       g_dbus_message_set_body(msg, param);
+
+       g_dbus_message_set_destination(msg, BT_SHARE_UI_INTERFACE);
+       g_dbus_connection_send_message(gdbus_connection, msg,
+                       G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
 
-       dbus_message_set_destination(msg, BT_SHARE_UI_INTERFACE);
-       dbus_connection_send(dbus_connection, msg, NULL);
-       dbus_message_unref(msg);
+       g_object_unref(msg);
 }
 
 void _bt_create_warning_popup(int error_type, char *msg)
@@ -610,7 +578,7 @@ void _bt_create_warning_popup(int error_type, char *msg)
        if (aul_app_is_running(UI_PACKAGE) == 0) {
                DBG("Creating new process for Warning Popup");
                char str[BT_TEXT_LEN_MAX] = { 0, };
-               bundle *b;
+               bundle *b = NULL;
 
                DBG("error_type: %d", error_type);
                switch (error_type) {
@@ -642,15 +610,15 @@ void _bt_create_warning_popup(int error_type, char *msg)
 
 static time_t __bt_get_current_timedata(void)
 {
-       time_t t;
+       time_t t = 0;
        time(&t);
-       return ((int) t);
+       return ((int)t);
 }
 
 static char *__bt_conv_addr_type_to_addr_string(char *addr)
 {
-       char address[BT_ADDR_STR_LEN_MAX] = { 0, };
        retv_if(addr == NULL, NULL);
+       char address[BT_ADDR_STR_LEN_MAX] = {0, };
 
        snprintf(address, BT_ADDR_STR_LEN_MAX,
                 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
@@ -662,21 +630,18 @@ static char *__bt_conv_addr_type_to_addr_string(char *addr)
 static void __bt_create_send_failed_data(char *filepath, char *dev_name,
                                         char *addr, char *type, unsigned int size)
 {
-       int session_id;
+       int session_id = -1;
        sqlite3 *db = NULL;
 
        db = bt_share_open_db();
-       if (!db)
-               return;
+       ret_if(!db);
 
        session_id = bt_share_get_last_session_id(db, BT_DB_OUTBOUND);
-
        INFO("Last session id = %d", session_id);
 
-       bt_tr_data_t *tmp;
+       bt_tr_data_t *tmp = NULL;
        tmp = g_malloc0(sizeof(bt_tr_data_t));
-       if (tmp == NULL)
-               return;
+       ret_if(tmp == NULL);
 
        tmp->tr_status = BT_TR_FAIL;
        tmp->sid = session_id + 1;
@@ -691,37 +656,36 @@ static void __bt_create_send_failed_data(char *filepath, char *dev_name,
        __bt_tr_data_free(tmp);
 
        bt_share_close_db(db);
-
-       return;
 }
 
 static void __bt_create_send_data(opc_transfer_info_t *node)
 {
-       DBG("__bt_create_send_data  \n");
+       FN_START;
        ret_if(node == NULL);
-       struct bt_appdata *ad = app_state;
 
        int count = 0;
-       int session_id;
-
+       int session_id = -1;
+       char *snd_db_sid = NULL;
        sqlite3 *db = NULL;
 
-       DBG("Name [%s]", node->name);
+       DBG_SECURE("Name [%s]", node->name);
 
        db = bt_share_open_db();
-       if (!db)
-               return;
+       ret_if(!db);
 
        session_id = bt_share_get_last_session_id(db, BT_DB_OUTBOUND);
-
+       snd_db_sid = _bt_get_time_of_the_day();
        INFO("Last session id = %d", session_id);
+
        for (count = 0; count < node->file_cnt; count++) {
                bt_tr_data_t *tmp;
                tmp = g_malloc0(sizeof(bt_tr_data_t));
-               if (tmp == NULL)
+               if (tmp == NULL) {
+                       g_free(snd_db_sid);
                        return;
+               }
 
-               tmp->tr_status = BT_TR_ONGOING;
+               tmp->tr_status = BT_TR_PENDING;
                tmp->sid = session_id + 1;
                tmp->file_path = g_strdup(node->file_path[count]);
                DBG("tmp->file_path : %s", tmp->file_path);
@@ -732,97 +696,143 @@ static void __bt_create_send_data(opc_transfer_info_t *node)
                tmp->timestamp = __bt_get_current_timedata();
                tmp->addr = __bt_conv_addr_type_to_addr_string(node->addr);
                tmp->size = node->size[count];
+               tmp->db_sid = g_strdup(snd_db_sid);
                bt_share_add_tr_data(db, BT_DB_OUTBOUND, tmp);
                __bt_tr_data_free(tmp);
        }
 
-       if (ad->tr_send_list) {
-               bt_share_release_tr_data_list(ad->tr_send_list);
-               ad->tr_send_list = NULL;
-       }
-
-       ad->tr_send_list = bt_share_get_tr_data_list_by_status(db,
-                                               BT_DB_OUTBOUND, BT_TR_ONGOING);
        bt_share_close_db(db);
+       g_free(snd_db_sid);
 
-       if (ad->tr_send_list == NULL)
-               return;
+       FN_END;
+}
 
-       ad->tr_next_data = ad->tr_send_list;
+gboolean _bt_update_sent_data_status(int uid,
+                               bt_app_tr_status_e status, char *db_sid)
+{
+       INFO("uid = %d", uid);
+       sqlite3 *db = NULL;
+       bt_tr_data_t *tmp = NULL;
 
-       return;
+       db = bt_share_open_db();
+       retv_if(!db, FALSE);
+
+       tmp = g_malloc0(sizeof(bt_tr_data_t));
+       retv_if(!tmp, FALSE);
+
+       tmp->tr_status = status;
+       tmp->timestamp = __bt_get_current_timedata();
+       tmp->db_sid = g_strdup(db_sid);
+       bt_share_update_tr_data(db, BT_DB_OUTBOUND, uid, tmp);
+       bt_share_close_db(db);
+
+       __bt_tr_data_free(tmp);
+       return TRUE;
 }
 
-gboolean _bt_update_sent_data_status(int uid, bt_app_tr_status_t status)
+gboolean _bt_update_recv_data_status(int uid,
+               bt_app_tr_status_e status, char *db_sid,
+               unsigned int filesize, const char *mime_type)
 {
-       DBG("_bt_update_sent_data_status  \n");
-
        INFO("uid = %d", uid);
        sqlite3 *db = NULL;
-       bt_tr_data_t *tmp;
+       bt_tr_data_t *tmp = NULL;
 
        db = bt_share_open_db();
-       if (!db)
-               return FALSE;
+       retv_if(!db, FALSE);
 
        tmp = g_malloc0(sizeof(bt_tr_data_t));
-       if (!tmp)
-               return FALSE;
+       retv_if(!tmp, FALSE);
 
        tmp->tr_status = status;
        tmp->timestamp = __bt_get_current_timedata();
-       bt_share_update_tr_data(db, BT_DB_OUTBOUND, uid, tmp);
+       tmp->db_sid = g_strdup(db_sid);
+       tmp->type = g_strdup(mime_type);
+       tmp->size = filesize;
+       bt_share_update_tr_data(db, BT_DB_INBOUND, uid, tmp);
        bt_share_close_db(db);
+
        __bt_tr_data_free(tmp);
+       return TRUE;
+}
+
+gboolean _bt_update_multiple_sent_data_status(int *uids, int uid_cnt,
+                               bt_app_tr_status_e status, char *db_sid)
+{
+       sqlite3 *db = NULL;
+       bt_tr_data_t *tmp = NULL;
+
+       db = bt_share_open_db();
+       retv_if(!db, FALSE);
+
+       tmp = g_malloc0(sizeof(bt_tr_data_t));
+       tmp->tr_status = status;
+       tmp->timestamp = __bt_get_current_timedata();
+       tmp->db_sid = g_strdup(db_sid);
+       bt_share_update_multiple_tr_data(db, BT_DB_OUTBOUND, uids, uid_cnt, tmp);
+       bt_share_close_db(db);
 
+       __bt_tr_data_free(tmp);
        return TRUE;
 }
 
 gboolean _bt_add_recv_transfer_status_data(char *device_name,
-                       char *filepath, char *type,
-                       unsigned int size, int status)
+                       char *address, char *filepath, char *type,
+                       unsigned int size, int status, char *db_sid)
 {
-       if (device_name == NULL || filepath == NULL)
-               return FALSE;
+       retv_if(device_name == NULL || filepath == NULL, FALSE);
 
        sqlite3 *db = NULL;
-       bt_tr_data_t *tmp;
+       bt_tr_data_t *tmp = NULL;
 
-       DBG("Name [%s]", device_name);
+       DBG_SECURE("Name [%s]", device_name);
 
        db = bt_share_open_db();
-       if (!db)
-               return FALSE;
+       retv_if(!db, FALSE);
 
        tmp = g_malloc0(sizeof(bt_tr_data_t));
-       if (tmp == NULL)
-               return FALSE;
 
        tmp->tr_status = status;
        tmp->file_path = g_strdup(filepath);
        tmp->dev_name = g_strdup(device_name);
+       tmp->addr = g_strdup(address);
+       tmp->db_sid = g_strdup(db_sid);
        tmp->timestamp = __bt_get_current_timedata();
        tmp->type = g_strdup(type);
        tmp->size = size;
        bt_share_add_tr_data(db, BT_DB_INBOUND, tmp);
        bt_share_close_db(db);
-       __bt_tr_data_free(tmp);
 
+       __bt_tr_data_free(tmp);
        return TRUE;
 }
 
+int _bt_share_get_unique_id(int db_table, const char *db_sid)
+{
+       sqlite3 *db = NULL;
+       int index_id = -1;
+
+       DBG("db_table = %d", db_table);
+       db = bt_share_open_db();
+       retv_if(!db, 0);
+
+       index_id = bt_share_get_unique_id(db, db_table, db_sid);
+       bt_share_close_db(db);
+       DBG("index_id = %d", index_id);
+       return index_id;
+}
+
 static void __bt_share_update_tr_info(int tr_uid, int tr_type)
 {
-       DBG("__bt_share_update_tr_info tr_uid = %d", tr_uid);
+       DBG("tr_uid = %d", tr_uid);
 
        int status = -1;
-       struct bt_appdata *ad = app_state;
+       bt_appdata_t *ad = app_state;
        bt_tr_data_t *info = NULL;
        sqlite3 *db = NULL;
 
        db = bt_share_open_db();
-       if (!db)
-               return;
+       ret_if(!db);
 
        if (tr_type == BT_TR_OUTBOUND) {
                if (tr_uid == -1) {
@@ -830,10 +840,11 @@ static void __bt_share_update_tr_info(int tr_uid, int tr_type)
                        /* Delete all outbound db / notification info */
                        _bt_delete_notification(ad->send_noti);
                        ad->send_noti = NULL;
+
                        ad->send_data.tr_success = 0;
                        ad->send_data.tr_fail = 0;
                        DBG("clear all");
-                       bt_share_remove_tr_data_by_notification(db, BT_DB_OUTBOUND);
+                       bt_share_remove_tr_data_non_pending(db, BT_DB_OUTBOUND);
                        bt_share_close_db(db);
                } else {
                        /* Delete selected outbound db / notification info */
@@ -844,7 +855,8 @@ static void __bt_share_update_tr_info(int tr_uid, int tr_type)
                                __bt_tr_data_free(info);
                        }
 
-                       bt_share_remove_tr_data_by_id(db, BT_DB_OUTBOUND, tr_uid);
+                       bt_share_remove_tr_data_by_id(db, BT_DB_OUTBOUND,
+                                                     tr_uid);
                        bt_share_close_db(db);
 
                        if (status == BT_TR_SUCCESS && ad->send_data.tr_success > 0)
@@ -854,9 +866,9 @@ static void __bt_share_update_tr_info(int tr_uid, int tr_type)
                        else
                                return;
 
-                       if ((ad->send_data.tr_success +
-                            ad->send_data.tr_fail) != 0) {
-                               _bt_update_notification(ad, ad->send_noti, NULL, NULL, NULL);
+                       if ((ad->send_data.tr_success + ad->send_data.tr_fail) != 0) {
+                               _bt_update_notification(ad, ad->send_noti,
+                                               NULL, NULL, NULL, NULL);
                        } else {
                                _bt_delete_notification(ad->send_noti);
                        }
@@ -891,9 +903,9 @@ static void __bt_share_update_tr_info(int tr_uid, int tr_type)
                        else
                                return;
 
-                       if ((ad->recv_data.tr_success +
-                            ad->recv_data.tr_fail) != 0) {
-                               _bt_update_notification(ad, ad->receive_noti, NULL, NULL, NULL);
+                       if ((ad->recv_data.tr_success + ad->recv_data.tr_fail) != 0) {
+                               _bt_update_notification(ad, ad->receive_noti,
+                                               NULL, NULL, NULL, NULL);
                        } else {
                                _bt_delete_notification(ad->receive_noti);
                        }
@@ -902,20 +914,19 @@ static void __bt_share_update_tr_info(int tr_uid, int tr_type)
                ERR("Invalid transfer type");
                bt_share_close_db(db);
        }
-       return;
 }
 
-GDBusConnection *__bt_init_system_gconn(void)
+static GDBusConnection *__bt_init_system_gconn(void)
 {
-       if (system_gconn == NULL)
-               system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
+       if (gdbus_connection == NULL)
+               gdbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
 
-       return system_gconn;
+       return gdbus_connection;
 }
 
-GDBusConnection *__bt_get_system_gconn(void)
+static GDBusConnection *__bt_get_system_gconn(void)
 {
-       return (system_gconn) ? system_gconn : __bt_init_system_gconn();
+       return (gdbus_connection) ? gdbus_connection : __bt_init_system_gconn();
 }
 
 GDBusProxy *__bt_init_core_proxy(void)
index 1a43424..868ac3d 100644 (file)
@@ -22,8 +22,8 @@
 #include <string.h>
 #include <appcore-efl.h>
 #include <vconf.h>
-#include <errno.h>
-#include <sys/stat.h>
+#include <Ecore_File.h>
+#include <notification_internal.h>
 
 /* For multi-user support */
 #include <tzplatform_config.h>
 #include "bt-share-notification.h"
 #include "bt-share-common.h"
 #include "bt-share-cynara.h"
-#include "bt-share-db.h"
-
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <grp.h>
 
 #include "bluetooth-share-api.h"
-#include "notification_internal.h"
 
 #define BLUETOOTH_SHARE_BUS            "org.projectx.bluetooth.share"
 
 static gboolean terminated;
+static GMainLoop *main_loop = NULL;
+bt_appdata_t *app_state = NULL;
+static guint owner_id;
 
-GMainLoop *main_loop = NULL;
-struct bt_appdata *app_state = NULL;
+static void __lang_changed_cb(keynode_t *node, void *user_data)
+{
+       FN_START;
+       /* init internationalization */
+       retm_if(appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0,
+                       "appcore_set_i18n failed!");
+       FN_END;
+}
 
 void _bt_terminate_bluetooth_share(void)
 {
-       DBG("+");
+       FN_START;
 
-       if (main_loop) {
+       if (main_loop)
                g_main_loop_quit(main_loop);
-       } else {
+       else
                terminated = TRUE;
-       }
-       DBG("-");
+
+       FN_END;
 }
 
-static void __bt_release_service(struct bt_appdata *ad)
+static void __bt_release_service(bt_appdata_t *ad)
 {
-       if (ad == NULL)
-               return;
+       ret_if(ad == NULL);
 
        _bt_deinit_vconf_notification();
        _bt_delete_notification(ad->opc_noti);
@@ -83,60 +84,70 @@ static void __bt_release_service(struct bt_appdata *ad)
        bluetooth_obex_server_deinit();
        _bt_unregister_notification_cb(ad);
 
-       _bt_free_auth_info();
+       vconf_ignore_key_changed(VCONFKEY_LANGSET, __lang_changed_cb);
+
+       g_free(server_auth_info.filename);
+       g_free(server_auth_info.name);
+       server_auth_info.filename = NULL;
+       server_auth_info.name = NULL;
+
+       if (ad->idler > 0) {
+               DBG("Removing idler!!!");
+               g_source_remove(ad->idler);
+       }
+       if (owner_id != 0)
+               g_bus_unown_name(owner_id);
 
        DBG("Terminating bluetooth-share daemon");
 }
 
 static void __bt_sigterm_handler(int signo)
 {
-       DBG("+");
+       FN_START;
 
-       if (main_loop) {
+       if (main_loop)
                g_main_loop_quit(main_loop);
-       } else {
+       else
                terminated = TRUE;
-       }
 
-       DBG("-");
+       FN_END;
 }
 
 static void __bt_update_transfer_status_values(void)
 {
-       struct bt_appdata *ad = app_state;
+       bt_appdata_t *ad = app_state;
        GSList *tr_data_list = NULL;
        GSList *list_iter = NULL;
        bt_tr_data_t *info = NULL;;
        sqlite3 *db = NULL;
 
+#if 0
        /* Update notification status durning BT off */
-       if (_bt_update_notification_status(ad) == FALSE) {
-               DBG("Notification item is not existed.");
-               return;
-       }
+       retm_if(_bt_update_notification_status(ad) == FALSE,
+                       "Notification item is not existed.");
+#endif
 
        DBG("Initialize transfer information");
 
        db = bt_share_open_db();
-       if (!db)
-               return;
+       ret_if(!db);
 
        tr_data_list = bt_share_get_all_tr_data_list(db, BT_DB_OUTBOUND);
-       if (NULL != tr_data_list) {
+       if (tr_data_list != NULL) {
                list_iter = tr_data_list;
 
-               while (NULL != list_iter) {
+               while (list_iter != NULL) {
                        info = list_iter->data;
-                       if (NULL == info)
+                       if (info == NULL)
                                break;
 
-                       if (info->tr_status == BT_TR_SUCCESS) {
+                       if (info->tr_status == BT_TRANSFER_SUCCESS) {
                                ad->send_data.tr_success++;
-                       } else if (info->tr_status == BT_TR_FAIL) {
+                       } else if (info->tr_status == BT_TRANSFER_FAIL) {
                                ad->send_data.tr_fail++;
-                       } else if (info->tr_status == BT_TR_ONGOING) {
-                       /* In case of ongoing file transfer if bluetooth is switched off
-                       we need to update the status to fail for these transaction */
+                       } else if (info->tr_status == BT_TRANSFER_ONGOING) {
+                               /* In case of ongoing file transfer if bluetooth is switched off
+                               we need to update the status to fail for these transaction */
                                ad->send_data.tr_fail++;
                                info->tr_status = BT_TR_FAIL;
                                bt_share_update_tr_data(db, BT_DB_OUTBOUND, info->id, info);
@@ -153,15 +164,15 @@ static void __bt_update_transfer_status_values(void)
        }
 
        tr_data_list = bt_share_get_all_tr_data_list(db, BT_DB_INBOUND);
-       if (NULL != tr_data_list) {
+       if (tr_data_list != NULL) {
                list_iter = tr_data_list;
 
-               while (NULL != list_iter) {
+               while (list_iter != NULL) {
                        info = list_iter->data;
-                       if (NULL == info)
+                       if (info == NULL)
                                break;
 
-                       if (info->tr_status == BT_TR_SUCCESS)
+                       if (info->tr_status == BT_TRANSFER_SUCCESS)
                                ad->recv_data.tr_success++;
                        else
                                ad->recv_data.tr_fail++;
@@ -175,144 +186,216 @@ static void __bt_update_transfer_status_values(void)
 
        bt_share_close_db(db);
 
-       DBG("[Send] success %d, fail %d", ad->send_data.tr_success, ad->send_data.tr_fail);
-       DBG("[Receive] success %d, fail %d", ad->recv_data.tr_success, ad->recv_data.tr_fail);
+       DBG("[Send] success %d, fail %d", ad->send_data.tr_success,
+                       ad->send_data.tr_fail);
+       DBG("[Receive] success %d, fail %d", ad->recv_data.tr_success,
+                       ad->recv_data.tr_fail);
+}
+
+static GSList *__merge_sorted(GSList *inbound, GSList *outbound)
+{
+       GSList *slist = NULL;
+       int *inbound_noti_id = NULL;
+       int *outbound_noti_id = NULL;
+
+       warn_if(inbound == NULL, "No inbound data!!!");
+       warn_if(outbound == NULL, "No outbound data!!!");
+
+/* **********************Note from glib documentation**************************
+ * g_slist_append() has to traverse the entire list to find the end, which
+ * is inefficient when adding multiple elements. A common idiom to avoid the
+ * inefficiency is to use g_slist_prepend() and reverse the list with
+ * g_slist_reverse() when all elements have been added.
+ * ***************************************************************************/
+
+       while (inbound && outbound) {
+               inbound_noti_id = (int *)inbound->data;
+               outbound_noti_id = (int *)outbound->data;
+
+               if (*inbound_noti_id > *outbound_noti_id) {
+                       slist = g_slist_prepend(slist, outbound_noti_id);
+                       outbound = g_slist_next(outbound);
+               } else {
+                       slist = g_slist_prepend(slist, inbound_noti_id);
+                       inbound = g_slist_next(inbound);
+               }
+       }
+
+       while (inbound) {
+               inbound_noti_id = (int *)inbound->data;
+               slist = g_slist_prepend(slist, inbound_noti_id);
+               inbound = g_slist_next(inbound);
+       }
+
+       while (outbound) {
+               outbound_noti_id = (int *)outbound->data;
+               slist = g_slist_prepend(slist, outbound_noti_id);
+               outbound = g_slist_next(outbound);
+       }
 
-       return;
+       return slist;
 }
 
-static int __bt_lang_changed_cb(void *data, void *user_data)
+void _bt_remove_temporary_files_by_noti_id(sqlite3 *db, int noti_id)
 {
-       if (appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0)
-               return -1;
+       FN_START;
+       GSList *file_list = bt_share_get_all_temporary_files_by_noti_id(db, noti_id, BT_TMP_DIR);
+
+       GSList *current_file = file_list;
+       while (current_file) {
+               DBG("Removing [%s]", (char *)(current_file->data));
+               ecore_file_remove((char *)(current_file->data));
+               current_file = g_slist_next(current_file);
+       }
 
-       return 0;
+       bt_share_release_temporary_file_list(file_list);
+       FN_END;
 }
 
-static gboolean __bt_dbus_request_name(void)
+gboolean __bt_clean_database(gpointer user_data)
 {
-       int ret_code = 0;
-       DBusConnection *conn;
-       DBusError err;
+       bt_appdata_t *ad = app_state;
+       notification_h noti = NULL;
+       notification_list_h noti_list = NULL;
+       notification_list_h current_noti = NULL;
+       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+       sqlite3 *db = NULL;
+       GSList *inbound = NULL;
+       GSList *outbound = NULL;
+       GSList *slist = NULL;
+       GSList *current = NULL;
+       int group_id = 0;
+       int priv_id = 0;
+       int noti_id = 0;
+
+       FN_START;
+
+       if (ad->idler) {
+               DBG("Removing g_idler!!!");
+               g_source_remove(ad->idler);
+               ad->idler = 0;
+       }
 
-       dbus_error_init(&err);
+       noti_err = notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &noti_list);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               ERR("Error in getting notification list. error(%d)", noti_err);
+               return G_SOURCE_REMOVE;
+       }
 
-       conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+       db = bt_share_open_db();
+       inbound = bt_share_get_noti_list(db, BT_DB_INBOUND);
+       outbound = bt_share_get_noti_list(db, BT_DB_OUTBOUND);
+
+       slist = __merge_sorted(inbound, outbound);
+       current = slist;
+       noti_list = notification_list_get_head(noti_list);
+       current_noti = noti_list;
+
+       while (current_noti && current) {
+               noti = notification_list_get_data(current_noti);
+               noti_err  = notification_get_id(noti, &group_id, &priv_id);
+               noti_id = *(int *)(current->data);
+               DBG("priv_id: %d | noti_id: %d", priv_id, noti_id);
+               if (noti_err == NOTIFICATION_ERROR_NONE) {
+                       if (priv_id == noti_id) {
+                               current = g_slist_next(current);
+                               current_noti = notification_list_get_next(current_noti);
+                       } else if (noti_id > priv_id) {
+                               DBG("Removing data by notification id: %d", noti_id);
+
+                               /* Remove all temporary files related to this noti_id */
+                               _bt_remove_temporary_files_by_noti_id(db, noti_id);
+
+                               bt_share_remove_tr_data_by_notification(db, BT_DB_INBOUND, noti_id);
+                               bt_share_remove_tr_data_by_notification(db, BT_DB_OUTBOUND, noti_id);
+                               current = g_slist_next(current);
+                       } else {
+                               current_noti = notification_list_get_next(current_noti);
+                       }
+               } else {
+                       current_noti = notification_list_get_next(current_noti);
+               }
+       }
 
-       if (dbus_error_is_set(&err))
-               goto failed;
+       /* Remove remaining records with remaining noti_id in slist */
+       while (current) {
+               noti_id = *(int *)(current->data);
+               DBG("Removing data by notification id: %d", noti_id);
 
-       ret_code = dbus_bus_request_name(conn,
-                                       BLUETOOTH_SHARE_BUS,
-                                       DBUS_NAME_FLAG_DO_NOT_QUEUE,
-                                       &err);
-       if (dbus_error_is_set(&err))
-               goto failed;
+               /* Remove all temporary files related to this noti_id */
+               _bt_remove_temporary_files_by_noti_id(db, noti_id);
 
-       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER == ret_code) {
-               dbus_connection_unref(conn);
-               return TRUE;
+               bt_share_remove_tr_data_by_notification(db, BT_DB_INBOUND, noti_id);
+               bt_share_remove_tr_data_by_notification(db, BT_DB_OUTBOUND, noti_id);
+               current = g_slist_next(current);
        }
 
-failed:
-       if (dbus_error_is_set(&err)) {
-               ERR("D-Bus Error: %s", err.message);
-               dbus_error_free(&err);
-       }
+       bt_share_close_db(db);
+       notification_free_list(noti_list);
+       bt_share_release_noti_list(inbound);
+       bt_share_release_noti_list(outbound);
+       g_slist_free(slist);
 
-       if (!conn)
-               dbus_connection_unref(conn);
 
+       FN_END
+       return G_SOURCE_REMOVE;
+}
+
+static gboolean __bt_dbus_request_name(void)
+{
+       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, BLUETOOTH_SHARE_BUS,
+                       G_DBUS_CALL_FLAGS_NONE, NULL, NULL, NULL, NULL, NULL);
 
-       return FALSE;
+       return (owner_id != 0) ? TRUE : FALSE;
 }
 
 int _bt_init_obex_server(void)
 {
-       char storage[STORAGE_PATH_LEN_MAX];
+       char storage[STORAGE_PATH_LEN_MAX] = {0, };
 
        _bt_get_default_storage(storage);
-       if (bluetooth_obex_server_init(storage) !=
-                                       BLUETOOTH_ERROR_NONE) {
-               ERR("Fail to init obex server");
-               return BT_SHARE_FAIL;
-       }
+       retvm_if(bluetooth_obex_server_init(storage) != BLUETOOTH_ERROR_NONE,
+                       BT_SHARE_FAIL, "Fail to init obex server");
 
-       bluetooth_obex_server_set_root(storage);
+       bluetooth_obex_server_set_root(BT_FTP_FOLDER);
 
        return BT_SHARE_ERROR_NONE;
 }
 
-#if 0
-void __bt_create_transfer_db(void)
-{
-       struct stat sts;
-       int ret;
-
-       /* Check if the DB exists; if not, create it and initialize it */
-       ret = stat(BT_TRANSFER_DB, &sts);
-       if (ret == -1 && errno == ENOENT) {
-               DBG("DB %s doesn't exist, it needs to be created and initialized", BT_TRANSFER_DB);
-               DBG("script path: %s", SCRIPT_INIT_DB);
-               ret = system(SCRIPT_INIT_DB);
-               if (ret != EXIT_SUCCESS)
-                       ERR("Exit code of epp not clean: %i", ret);
-       }
-}
-#endif
-
 int main(void)
 {
-       int ret;
+       int ret = 0;
        INFO("Starting bluetooth-share daemon");
 
        signal(SIGTERM, __bt_sigterm_handler);
 
-       app_state = calloc(1, sizeof(struct bt_appdata));
+       app_state = calloc(1, sizeof(bt_appdata_t));
        if (!app_state)
                return -1;
 
-#if 0
-       __bt_create_transfer_db();
-#endif
-
        if (__bt_dbus_request_name() == FALSE) {
                INFO("Aleady dbus instance existed");
                exit(0);
        }
 
-       ret = appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, __bt_lang_changed_cb, NULL);
-       if (ret < 0)
-               ERR("Failed to excute the change of language");
-
        /* init internationalization */
-       if (appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0)
-               return -1;
+       retvm_if(appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0,
+                       BT_SHARE_FAIL, "appcore_set_i18n failed!");
 
-#if 0
-       uid_t network_user = 5001; /* uid of owner */
-       gid_t network_group = 100; /* gid of users */
-
-       uid_t network_user = 551; /* uid of network_fw */
-       gid_t network_group = 551; /* gid of network_fw */
-       initgroups("network_fw", network_group);
-       initgroups("users", network_group);
-       ret = setgid(network_group);
-       DBG("setgid return : %d", ret);
-       ret = setuid(network_user);
-       DBG("setuid return : %d", ret);
-#endif
        if (_bt_share_cynara_init()) {
                ERR("Failed to initialize Cynara.\n");
                return -1;
        }
 
-       bluetooth_register_callback(_bt_share_event_handler, NULL);
+       ret = vconf_notify_key_changed(VCONFKEY_LANGSET, __lang_changed_cb, NULL);
+       warn_if(ret != VCONF_OK, "vconf_notify_key_changed failed");
+
+       ret = bluetooth_register_callback(_bt_share_event_handler, NULL);
+       warn_if(ret != BLUETOOTH_ERROR_NONE && ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED,
+                       "bluetooth_register callback failed");
+
        ret = bluetooth_opc_init();
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               ERR("bluetooth_opc_init failed");
-               return -1;
-       }
+       retvm_if(ret != BLUETOOTH_ERROR_NONE, BT_SHARE_FAIL, "bluetooth_opc_init failed");
 
        _bt_init_dbus_signal();
        _bt_init_vconf_notification((void *)app_state);
@@ -324,15 +407,20 @@ int main(void)
 
        if (terminated == TRUE) {
                __bt_release_service(app_state);
+               _bt_deinit_dbus_signal();
                bluetooth_unregister_callback();
-               return -1;
+               return BT_SHARE_FAIL;
        }
 
+       app_state->idler = g_idle_add(__bt_clean_database, NULL);
+       warn_if(!app_state->idler, "Failed to create idler!!!");
+
        main_loop = g_main_loop_new(NULL, FALSE);
        g_main_loop_run(main_loop);
 
        __bt_release_service(app_state);
+       _bt_deinit_dbus_signal();
        bluetooth_unregister_callback();
 
-       return 0;
+       return BT_SHARE_ERROR_NONE;
 }
index 5d3df44..fed23ef 100644 (file)
 
 #include <glib.h>
 #include <vconf.h>
-#include <unistd.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include <storage.h>
-
 /* For multi-user support */
 #include <tzplatform_config.h>
 
 #include "applog.h"
-#include "bluetooth-api.h"
 #include "bt-share-common.h"
+#include "bluetooth-api.h"
 #include "bt-share-noti-handler.h"
 #include "bt-share-main.h"
-#include "obex-event-handler.h"
 #include "bt-share-notification.h"
+#include "obex-event-handler.h"
 
 static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
 {
+       FN_START;
+       ret_if(node == NULL);
+
        int default_memory = 0;
        char *root_path = NULL;
        char *download_path = NULL;
 
-       DBG("__bt_default_memory_changed_cb\n");
-
-       ret_if(node == NULL);
-
-       DBG("key=%s\n", vconf_keynode_get_name(node));
+       DBG_SECURE("key=%s\n", vconf_keynode_get_name(node));
 
        if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
                /* Phone memory is 0, MMC is 1 */
@@ -66,9 +66,8 @@ static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
                }
 
                if (access(download_path, W_OK) != 0) {
-                       if (mkdir(download_path, 0755) < 0) {
-                               ERR("mkdir fail![%s]", download_path);
-                       }
+                       warn_if(mkdir(download_path, 0755) < 0,
+                                       "mkdir fail![%s]", download_path);
                }
 
                bluetooth_obex_server_set_root(root_path);
@@ -77,18 +76,21 @@ static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
                g_free(download_path);
                g_free(root_path);
        }
+
+       FN_END;
 }
 
 static void __bt_mmc_status_changed_cb(keynode_t *node, void *data)
 {
-       DBG("+");
+       FN_START;
+       retm_if(!node || !data, "invalid param!");
 
        int mmc_status = 0;
        int default_memory = 0;
-       int ret = 0;
-       retm_if(!node || !data, "invalid param!");
-       DBG("key=%s", vconf_keynode_get_name(node));
-       struct bt_appdata *ad = (struct bt_appdata *)data;
+       int ret = NOTIFICATION_ERROR_NONE;
+
+       DBG_SECURE("key=%s", vconf_keynode_get_name(node));
+       bt_appdata_t *ad = (bt_appdata_t *)data;
 
        if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
                /* Phone memory is 0, MMC is 1 */
@@ -115,46 +117,39 @@ static void __bt_mmc_status_changed_cb(keynode_t *node, void *data)
                                        retm_if(vconf_set_int(
                                                VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
                                                BT_DEFAULT_MEM_PHONE) != 0, "vconf_set_int failed");
-                                               DBG("Default Memory set to Phone");
+                                       DBG_SECURE("Default Memory set to Phone");
                                }
                        }
                }
        }
-       DBG("-");
+
+       FN_END;
 }
 
 void _bt_init_vconf_notification(void *data)
 {
        retm_if(!data, "invalid param!");
 
-       int ret;
+       int ret = VCONF_OK;
 
        ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
                        __bt_default_memory_changed_cb, NULL);
-       if (ret < 0) {
-               ERR("vconf_notify_key_changed init failed");
-       }
+       warn_if(ret != VCONF_OK, "vconf_notify_key_changed init failed");
 
        ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS,
                        __bt_mmc_status_changed_cb, data);
-       if (ret < 0) {
-               ERR("vconf_notify_key_changed init failed");
-       }
+       warn_if(ret != VCONF_OK, "vconf_notify_key_changed init failed");
 }
 
 void _bt_deinit_vconf_notification(void)
 {
-       int ret;
+       int ret = VCONF_OK;
        ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
                        (vconf_callback_fn) __bt_default_memory_changed_cb);
-       if (ret < 0) {
-               ERR("vconf_notify_key_changed deinit failed");
-       }
+       warn_if(ret != VCONF_OK, "vconf_notify_key_changed deinit failed");
 
        ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS,
                        (vconf_callback_fn) __bt_mmc_status_changed_cb);
-       if (ret < 0) {
-               ERR("vconf_notify_key_changed deinit failed");
-       }
+       warn_if(ret != VCONF_OK, "vconf_notify_key_changed deinit failed");
 }
 
index 92ae1c1..2072184 100644 (file)
@@ -20,6 +20,8 @@
 #include <applog.h>
 #include <notification.h>
 #include <notification_list.h>
+#include <notification_text_domain.h>
+#include <notification_internal.h>
 #include <appsvc.h>
 #include <vconf.h>
 
 #include "obex-event-handler.h"
 #include "bluetooth-share-api.h"
 #include "bt-share-resource.h"
-#include "notification_text_domain.h"
-#include "notification_internal.h"
 
-#define BT_PERCENT_STR_LEN 5
-#define BT_PRIV_ID_STR_LEN 8
-#define BT_NOTI_STR_LEN_MAX 50
+#define BT_PRIV_ID_STR_LEN 12
 
-typedef enum {
-       CSC_DCM,
-       CSC_FTM,
-} bt_csc_type_t;
+extern GSList *bt_rcv_noti_info_list;
+extern GSList *bt_snd_noti_info_list;
 
+void _bt_insert_instant_notification(bt_notification_type_e type)
+{
+       FN_START;
+       notification_h noti = NULL;
+       notification_error_e ret = NOTIFICATION_ERROR_NONE;
+       char *title = NULL;
+       char *icon_path = NULL;
+
+       DBG("Create notification type : %d", type);
+
+       switch (type) {
+       case BT_SENDING_NOTI: {
+               title = BT_STR_SENDING_FILES;
+               icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
+               break;
+       }
+
+       case BT_RECEIVING_NOTI: {
+               title = BT_STR_RECEIVING_FILES;
+               icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
+               break;
+       }
+
+       case BT_SENT_NOTI: {
+               title = BT_STR_FILES_SENT;
+               icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
+               break;
+       }
+
+       case BT_SENT_FAILED_NOTI: {
+               title = BT_STR_SENDING_FILES_FAILED;
+               icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
+               break;
+       }
+
+       case BT_RECEIVED_NOTI: {
+               title = BT_STR_FILES_RECEIVED;
+               icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
+               break;
+       }
+
+       case BT_RECEIVED_FAILED_NOTI: {
+               title = BT_STR_RECEIVING_FILES_FAILED;
+               icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
+               break;
+       }
+
+       default:
+               return;
+       }
+
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
+       retm_if(!noti, "Fail to notification_create");
+
+       if (title) {
+               ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+                                       NULL, title,
+                                       NOTIFICATION_VARIABLE_TYPE_NONE);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                               "Fail to notification_set_text [%d]", ret);
+       }
+
+       if (icon_path) {
+               ret = notification_set_image(noti,
+                               NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, icon_path);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_image [%d]", ret);
+       }
+
+       ret  = notification_set_display_applist(noti,
+                       NOTIFICATION_DISPLAY_APP_TICKER);
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_set_display_applist [%d]", ret);
+
+       ret = notification_post(noti);
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_insert [%d]", ret);
 
-notification_h _bt_insert_notification(struct bt_appdata *ad, bt_notification_type_e type, int index, int total)
+       if (noti)
+               notification_free(noti);
+       FN_END;
+}
+
+notification_h _bt_insert_notification(bt_appdata_t *ad,
+                       bt_notification_type_e type, char *dev_name,
+                       char *address, char *db_sid)
 {
        notification_h noti = NULL;
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
@@ -64,12 +144,18 @@ notification_h _bt_insert_notification(struct bt_appdata *ad, bt_notification_ty
                success = ad->send_data.tr_success;
                fail = ad->send_data.tr_fail;
 
-               if (success == 1)
-                       content = "IDS_BT_MBODY_1_FILE_COPIED_PD_FAILED_ABB";
+               if (success == 0)
+                       title = "IDS_BT_MBODY_SENDING_FAILED";
                else
-                       content = "IDS_BT_MBODY_P1SD_FILES_COPIED_P2SD_FAILED_ABB";
+                       title = "IDS_BT_MBODY_FILE_SENT";
+
+               if (success == 0 && fail > 0)
+                       content = "IDS_BT_SBODY_PD_FAILED_ABB";
+               else if (fail == 0 && success > 0)
+                       content = "IDS_BT_SBODY_PD_SUCCEEDED_ABB";
+               else
+                       content = "IDS_BT_SBODY_P1SD_SUCCEEDED_P2SD_FAILED_ABB2";
 
-               title = "IDS_BT_MBODY_FILES_SENT_VIA_BLUETOOTH_ABB";
                icon_path = BT_ICON_NOTIFICATION_SENT;
                indicator_icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
                flag = NOTIFICATION_PROP_DISABLE_AUTO_DELETE;
@@ -79,27 +165,28 @@ notification_h _bt_insert_notification(struct bt_appdata *ad, bt_notification_ty
                success = ad->recv_data.tr_success;
                fail = ad->recv_data.tr_fail;
 
-               if (success == 1)
-                       content = "IDS_BT_MBODY_1_FILE_COPIED_PD_FAILED_ABB";
-               else
-                       content = "IDS_BT_MBODY_P1SD_FILES_COPIED_P2SD_FAILED_ABB";
-
-               title = "IDS_BT_MBODY_FILES_RECEIVED_VIA_BLUETOOTH_ABB";
+               title = "IDS_BT_MBODY_FILE_RECEIVED";
+               if (success == 0 && fail > 0) {
+                       content = "IDS_BT_SBODY_PD_FAILED_ABB";
+                       title = "IDS_BT_MBODY_RECEIVING_FAILED";
+               } else if (fail == 0 && success > 0) {
+                       content = "IDS_BT_SBODY_PD_SUCCEEDED_ABB";
+               } else {
+                       content = "IDS_BT_SBODY_P1SD_SUCCEEDED_P2SD_FAILED_ABB2";
+               }
                icon_path = BT_ICON_NOTIFICATION_RECEIVED;
                indicator_icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
                flag = NOTIFICATION_PROP_DISABLE_AUTO_DELETE;
                app_id = NOTI_OPS_APP_ID;
                noti_type = NOTIFICATION_TYPE_NOTI;
        } else if (type == BT_SENDING_NOTI) {
-               title = "IDS_BT_MBODY_SEND_VIA_BLUETOOTH_ABB";
-               content = "IDS_BT_SBODY_PREPARING_TO_SEND_FILES_ING_ABB";
+               title = "IDS_BT_SBODY_PREPARING_TO_SEND_FILES_ING_ABB";
                icon_path = BT_ICON_NOTIFICATION_SENDING;
                indicator_icon_path = BT_ICON_NOTIFICATION_SENDING_INDICATOR;
                flag = NOTIFICATION_PROP_DISABLE_TICKERNOTI;
                noti_type = NOTIFICATION_TYPE_ONGOING;
        } else if (type == BT_RECEIVING_NOTI) {
-               title = "IDS_BT_MBODY_RECEIVE_VIA_BLUETOOTH_ABB";
-               content = "IDS_BT_SBODY_PREPARING_TO_RECEIVE_FILES_ING_ABB";
+               title = "IDS_BT_SBODY_PREPARING_TO_RECEIVE_FILES_ING_ABB";
                icon_path = BT_ICON_NOTIFICATION_RECEIVING;
                indicator_icon_path = BT_ICON_NOTIFICATION_RECEIVING_INDICATOR;
                flag = NOTIFICATION_PROP_DISABLE_TICKERNOTI;
@@ -107,192 +194,191 @@ notification_h _bt_insert_notification(struct bt_appdata *ad, bt_notification_ty
        }
 
        noti = notification_create(noti_type);
-       if (!noti) {
-               ERR("Fail to notification_create");
-               return NULL;
-       }
+       retvm_if(!noti, NULL, "Fail to notification_create");
 
        notification_set_text_domain(noti, BT_COMMON_PKG, BT_COMMON_RES);
 
-       if (total > 0) {
-               char *count_str = NULL;
-
-               DBG("total : %d, index: %d", total, index);
-
-               count_str = g_strdup_printf("[%d/%d]", index, total);
-
-               if (count_str) {
-                       ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT,
-                                                       NULL, count_str, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       if (ret != NOTIFICATION_ERROR_NONE)
-                               ERR("Fail to notification_set_text [%d]", ret);
-
-                       g_free(count_str);
-               }
-       }
-
        if (title) {
                ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
-                                       NULL, title,
-                                       NOTIFICATION_VARIABLE_TYPE_NONE);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_text [%d]", ret);
-               }
+                       NULL, title,
+                       NOTIFICATION_VARIABLE_TYPE_NONE);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_text [%d]", ret);
        }
 
        if (content) {
                if (type == BT_SENT_NOTI || type == BT_RECEIVED_NOTI) {
-                       if (success == 1)
-                               ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                                                       NULL, content,
-                                                       NOTIFICATION_VARIABLE_TYPE_INT, fail,
-                                                       NOTIFICATION_VARIABLE_TYPE_NONE);
-                       else
+                       DBG("success : %d, fail : %d", success, fail);
+                       if (success > 0 && fail > 0) {
                                ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
                                                        NULL, content,
                                                        NOTIFICATION_VARIABLE_TYPE_INT, success,
                                                        NOTIFICATION_VARIABLE_TYPE_INT, fail,
                                                        NOTIFICATION_VARIABLE_TYPE_NONE);
+                       } else {
+                               ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+                                                               NULL, content,
+                                                               NOTIFICATION_VARIABLE_TYPE_INT, (success > 0) ? success : fail,
+                                                               NOTIFICATION_VARIABLE_TYPE_NONE);
+                       }
                } else {
                        ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
                                                NULL, content, NOTIFICATION_VARIABLE_TYPE_NONE);
                }
 
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_text [%d]", ret);
-               }
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_text [%d]", ret);
        }
 
        if (icon_path) {
                ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_image [%d]", ret);
-               }
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_image [%d]", ret);
        }
 
        if (indicator_icon_path) {
-               ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, indicator_icon_path);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_image [%d]", ret);
-               }
+               ret = notification_set_image(noti,
+                               NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, indicator_icon_path);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_image [%d]", ret);
        }
 
        if (flag != -1) {
                ret = notification_set_property(noti, flag);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_property [%d]", ret);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_property [%d]", ret);
+
+               if (type == BT_SENDING_NOTI || type == BT_RECEIVING_NOTI) {
+                       ret = notification_set_property(noti,
+                                       NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+                       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                               "Fail to set property for DISABLE_APP_LAUNCH [%d]", ret);
                }
        }
 
        if (app_id) {
                ret = notification_set_pkgname(noti, app_id);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_pkgname [%d]", ret);
-               }
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_pkgname [%d]", ret);
        }
 
        ret = notification_set_display_applist(noti,
-                       NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
-                       NOTIFICATION_DISPLAY_APP_INDICATOR);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_set_display_applist [%d]", ret);
-       }
+                       NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_set_display_applist [%d]", ret);
 
        if (type == BT_SENT_NOTI) {
-               _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
-                               NOTI_TR_TYPE_OUT, NULL, NULL, 0);
+               _bt_set_notification_app_launch(noti, dev_name, address, db_sid,
+                               CREATE_TR_LIST, NOTI_TR_TYPE_OUT, NULL, 0, NULL, 0);
        } else if (type == BT_RECEIVED_NOTI) {
-               _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
-                               NOTI_TR_TYPE_IN, NULL, NULL, 0);
+               _bt_set_notification_app_launch(noti, dev_name, address, db_sid,
+                               CREATE_TR_LIST, NOTI_TR_TYPE_IN, NULL, 0, NULL, 0);
        }
 
        ret = notification_insert(noti, &noti_id);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_insert [%d]", ret);
-       }
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_insert [%d]", ret);
 
        if (type == BT_SENT_NOTI)
                ad->send_noti_id = noti_id;
        else if (type == BT_RECEIVED_NOTI)
                ad->receive_noti_id = noti_id;
 
-       INFO("Insert %s type: %p ", (type == BT_SENT_NOTI || type == BT_RECEIVED_NOTI) ?
-                       "Notification" : "Ongoing", noti);
+       INFO("Insert %s type: %d ", (type == BT_SENT_NOTI ||
+                       type == BT_RECEIVED_NOTI) ? "Notification" : "Ongoing", noti);
 
        return noti;
 }
 
-int _bt_update_notification(struct bt_appdata *ad, notification_h noti,
-                               char *title, char *content, char *icon_path)
+int _bt_update_notification(bt_appdata_t *ad,
+               notification_h noti, char *title, char *content, char *icon_path,
+               char *opc_count)
 {
        retvm_if(!noti, BT_SHARE_FAIL, "noti is NULL");
 
-       INFO("Update noti : %p", noti);
+       INFO("Update noti : %d", noti);
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
        int success = 0;
        int fail = 0;
+       int flags = -1;
 
        if (ad->send_noti == noti) {
                success = ad->send_data.tr_success;
                fail = ad->send_data.tr_fail;
-
-               if (success == 1)
-                       content = "IDS_BT_MBODY_1_FILE_COPIED_PD_FAILED_ABB";
-               else
-                       content = "IDS_BT_MBODY_P1SD_FILES_COPIED_P2SD_FAILED_ABB";
        } else if (ad->receive_noti == noti) {
                success = ad->recv_data.tr_success;
                fail = ad->recv_data.tr_fail;
+       }
 
-               if (success == 1)
-                       content = "IDS_BT_MBODY_1_FILE_COPIED_PD_FAILED_ABB";
+       if (ad->send_noti == noti || ad->receive_noti == noti) {
+               if (success == 0 && fail > 0)
+                       content = "IDS_BT_SBODY_PD_FAILED_ABB";
+               else if (fail == 0 && success > 0)
+                       content = "IDS_BT_SBODY_PD_SUCCEEDED_ABB";
                else
-                       content = "IDS_BT_MBODY_P1SD_FILES_COPIED_P2SD_FAILED_ABB";
+                       content = "IDS_BT_SBODY_P1SD_SUCCEEDED_P2SD_FAILED_ABB2";
        }
 
        if (title) {
                ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
                                        NULL, title,
                                        NOTIFICATION_VARIABLE_TYPE_NONE);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_text [%d]", ret);
-               }
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_text [%d]", ret);
        }
 
        if (content) {
                if (noti == ad->send_noti || noti == ad->receive_noti) {
-                       if (success == 1)
+                       if (success > 0 && fail > 0) {
                                ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                                                       NULL, content,
-                                                       NOTIFICATION_VARIABLE_TYPE_INT, fail,
-                                                       NOTIFICATION_VARIABLE_TYPE_NONE);
-                       else
+                                               NULL, content,
+                                               NOTIFICATION_VARIABLE_TYPE_INT, success,
+                                               NOTIFICATION_VARIABLE_TYPE_INT, fail,
+                                               NOTIFICATION_VARIABLE_TYPE_NONE);
+                       } else {
                                ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                                                       NULL, content,
-                                                       NOTIFICATION_VARIABLE_TYPE_INT, success,
-                                                       NOTIFICATION_VARIABLE_TYPE_INT, fail,
-                                                       NOTIFICATION_VARIABLE_TYPE_NONE);
+                                                               NULL, content,
+                                                               NOTIFICATION_VARIABLE_TYPE_INT, (success > 0) ? success : fail,
+                                                               NOTIFICATION_VARIABLE_TYPE_NONE);
+                       }
                } else {
                        ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
                                                NULL, content, NOTIFICATION_VARIABLE_TYPE_NONE);
                }
 
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_text [%d]", ret);
-               }
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_text [%d]", ret);
+       }
+
+       if (opc_count) {
+               ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT,
+                                       NULL, opc_count, NOTIFICATION_VARIABLE_TYPE_NONE);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_text [%d]", ret);
        }
 
        if (icon_path) {
-               ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
-               if (ret != NOTIFICATION_ERROR_NONE) {
-                       ERR("Fail to notification_set_image [%d]", ret);
+               ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
+                               icon_path);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_set_image [%d]", ret);
+       }
+
+       ret  = notification_get_property(noti, &flags);
+       if (ret == NOTIFICATION_ERROR_NONE) {
+               if (flags & NOTIFICATION_PROP_DISABLE_APP_LAUNCH) {
+                       ret = notification_set_property(noti,
+                                       flags ^ NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+                       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                                       "Failed to set app launch property");
                }
+       } else {
+               ERR("failed to get the property: [%d]", ret);
        }
 
        ret = notification_update(noti);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_update [%d]", ret);
-       }
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                       "Fail to notification_update [%d]", ret);
 
        return ret;
 }
@@ -301,10 +387,11 @@ int _bt_update_notification_progress(notification_h not,
                                int id, int val)
 {
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
        ret = notification_update_progress(not, id, (double)val / 100);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_update_progress [%d]\n", ret);
-       }
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_update_progress [%d]\n", ret);
+
        return ret;
 }
 
@@ -315,9 +402,9 @@ int _bt_get_notification_priv_id(notification_h noti)
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
 
        ret = notification_get_id(noti, &group_id, &priv_id);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_get_id [%d]", ret);
-       }
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_get_id [%d]", ret);
+
        return priv_id;
 }
 
@@ -330,103 +417,100 @@ int _bt_delete_notification(notification_h noti)
 
        /* In case daemon, give full path */
        ret = notification_delete(noti);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_delete [%d]", ret);
-       }
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_delete [%d]", ret);
 
        return ret;
 }
 
 int _bt_set_notification_app_launch(notification_h noti,
-                                       bt_notification_launch_type_e launch_type,
-                                       const char *transfer_type,
-                                       const char *filename,
-                                       const char *progress_cnt,
-                                       int transfer_id)
+               char *device_name,
+               char *device_addr,
+               char *db_sid,
+               bt_notification_launch_type_e launch_type,
+               const char *transfer_type,
+               const char *filename,
+               unsigned long size,
+               const char *progress_cnt,
+               int transfer_id)
 {
-       DBG("+\n");
-       if (!noti)
-               return -1;
-
-       if (!transfer_type)
-               return -1;
+       FN_START;
+       retv_if(!noti, BT_SHARE_FAIL);
+       retv_if(!transfer_type, BT_SHARE_FAIL);
+       retv_if(launch_type != CREATE_PROGRESS && launch_type != CREATE_TR_LIST,
+                       BT_SHARE_FAIL);
 
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
        bundle *b = NULL;
        b = bundle_create();
-       if (!b)
-               return -1;
+       retv_if(!b, BT_SHARE_FAIL);
 
-       if (launch_type == CREATE_PROGRESS) {
-               double percentage = 0;
-               char progress[BT_PERCENT_STR_LEN] = { 0 };
-               char priv_id_str[BT_PRIV_ID_STR_LEN] = { 0 };
+       appsvc_set_pkgname(b, UI_PACKAGE);
+       appsvc_add_data(b, "device_name", device_name);
+       appsvc_add_data(b, "device_addr", device_addr);
+       appsvc_add_data(b, "transfer_type", transfer_type);
+       appsvc_add_data(b, "db_sid", db_sid);
 
+       if (launch_type == CREATE_PROGRESS) {
                if (!filename) {
                        bundle_free(b);
-                       return -1;
+                       return BT_SHARE_FAIL;
                }
 
-               ret = notification_get_progress(noti, &percentage);
-               if (ret != NOTIFICATION_ERROR_NONE)
-                       ERR("Fail to notification_get_progress [%d]\n", ret);
-               else
-                       snprintf(progress, BT_PERCENT_STR_LEN, "%d", (int)percentage);
-
+               char priv_id_str[BT_PRIV_ID_STR_LEN] = {0, };
+               char size_str[BT_PRIV_ID_STR_LEN] = {0, };
                snprintf(priv_id_str, BT_PRIV_ID_STR_LEN, "%d", transfer_id);
+               snprintf(size_str, BT_PRIV_ID_STR_LEN, "%lu", size);
 
-               appsvc_set_pkgname(b, UI_PACKAGE);
                appsvc_add_data(b, "launch-type", "ongoing");
-               appsvc_add_data(b, "percentage", progress);
                appsvc_add_data(b, "filename", filename);
-               appsvc_add_data(b, "transfer_type", transfer_type);
+               appsvc_add_data(b, "size", size_str);
                appsvc_add_data(b, "transfer_id", priv_id_str);
-               if (g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT) == 0)  {
+               if (g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT) == 0) {
                        if (!progress_cnt) {
                                bundle_free(b);
-                               return -1;
+                               return BT_SHARE_FAIL;
                        }
                        appsvc_add_data(b, "progress_cnt", progress_cnt);
                }
-       } else if (launch_type == CREATE_TR_LIST) {
-               appsvc_set_pkgname(b, UI_PACKAGE);
-               appsvc_add_data(b, "launch-type", "transfer_list");
-               appsvc_add_data(b, "transfer_type", transfer_type);
        } else {
-               bundle_free(b);
-               return -1;
+               char priv_id_str[BT_PRIV_ID_STR_LEN] = {0, };
+               snprintf(priv_id_str, BT_PRIV_ID_STR_LEN, "%d", transfer_id);
+
+               appsvc_add_data(b, "launch-type", "transfer_list");
+               appsvc_add_data(b, "transfer_id", priv_id_str);
+               appsvc_add_data(b, "filename", filename);
        }
 
        ret = notification_set_execute_option(noti,
                                        NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
                                        NULL, NULL, b);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_set_execute_option [%d]\n", ret);
-       }
+       warn_if(ret != NOTIFICATION_ERROR_NONE,
+               "Fail to notification_set_execute_option [%d]\n", ret);
 
        bundle_free(b);
-       DBG("-\n");
+       FN_END;
        return ret;
 }
 
-gboolean _bt_update_notification_status(struct bt_appdata *ad)
+#if 0
+gboolean _bt_update_notification_status(bt_appdata_t *ad)
 {
+       retv_if(ad == NULL, FALSE);
+
        notification_h noti = NULL;
        notification_list_h list_head = NULL;
        notification_list_h list_traverse = NULL;
-       char *app_id = NULL;
        gboolean is_noti_existed = FALSE;
        gboolean send_noti = FALSE;
        gboolean receive_noti = FALSE;
        sqlite3 *db = NULL;
+       char *app_id = NULL;
        int group_id = 0;
        int priv_id = 0;
-       int ret;
-
-       retv_if(ad == NULL, FALSE);
+       int ret = 0;
 
        /* When bt-share is launched, need to update notification status  */
-
        notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &list_head);
        list_traverse = list_head;
 
@@ -436,36 +520,37 @@ gboolean _bt_update_notification_status(struct bt_appdata *ad)
 
                if (g_strcmp0(app_id, NOTI_OPS_APP_ID) == 0) {
                        ret = notification_clone(noti, &ad->receive_noti);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Fail to clone notificatoin");
-                       }
+                       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                                       "Fail to clone notificatoin");
+
                        ret = notification_get_id(noti, &group_id, &priv_id);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Fail to get notification id");
-                       }
+                       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                                       "Fail to get notification id");
+
                        ad->receive_noti_id = priv_id;
                        receive_noti = TRUE;
                } else if (g_strcmp0(app_id, NOTI_OPC_APP_ID) == 0) {
                        ret = notification_clone(noti, &ad->send_noti);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Unable to clone notificatoin");
-                       }
+                       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                                       "Unable to clone notificatoin");
+
                        ret = notification_get_id(noti, &group_id, &priv_id);
-                       if (ret != NOTIFICATION_ERROR_NONE) {
-                               ERR("Fail to get notification id");
-                       }
+                       warn_if(ret != NOTIFICATION_ERROR_NONE,
+                               "Fail to get notification id");
+
                        ad->send_noti_id = priv_id;
                        send_noti = TRUE;
                }
 
                if (receive_noti || send_noti) {
                        time_t ret_time;
-
                        /* Set notication insert_time */
                        notification_get_insert_time(noti, &ret_time);
                        notification_set_time(noti, ret_time);
                        notification_update(noti);
                        is_noti_existed = TRUE;
+                       send_noti = FALSE;
+                       receive_noti = FALSE;
                }
 
                list_traverse = notification_list_get_next(list_traverse);
@@ -478,8 +563,7 @@ gboolean _bt_update_notification_status(struct bt_appdata *ad)
 
        /* If notification item is removed durning BT off, need to remove DB */
        db = bt_share_open_db();
-       if (!db)
-               return is_noti_existed;
+       retv_if(!db, is_noti_existed);
 
        if (!receive_noti)
                bt_share_remove_all_tr_data(db, BT_DB_INBOUND);
@@ -489,97 +573,81 @@ gboolean _bt_update_notification_status(struct bt_appdata *ad)
 
        return is_noti_existed;
 }
+#endif
 
-static void __bt_notification_changed_cb(void *data, notification_type_e type, notification_op *op_list, int num_op)
+static void __bt_notification_changed_cb(void *data, notification_type_e type,
+               notification_op *op_list, int num_op)
 {
-       DBG("__bt_notification_changed_cb");
-
+       FN_START;
        retm_if(data == NULL, "Invalid data");
-       struct bt_appdata *ad = (struct bt_appdata *)data;
-       gboolean is_sent_noti_exist = FALSE;
-       gboolean is_received_noti_exist = FALSE;
-       notification_h noti = NULL;
-       notification_list_h noti_list = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       int group_id;
-       int priv_id;
-       sqlite3 *db = NULL;
-
        retm_if(op_list == NULL, "Invalid op_list");
 
-       if (type != NOTIFICATION_TYPE_NOTI ||
+       bt_appdata_t *ad = (bt_appdata_t *)data;
+       sqlite3 *db = NULL;
+       int i;
+
+       ret_if(type != NOTIFICATION_TYPE_NOTI ||
                (op_list->type != NOTIFICATION_OP_DELETE &&
-               op_list->type != NOTIFICATION_OP_DELETE_ALL))
-               return;
+               op_list->type != NOTIFICATION_OP_DELETE_ALL));
 
-       if (ad->send_noti == NULL && ad->receive_noti == NULL)
-               return;
+       DBG("Notifications Changed: %d", num_op);
+       DBG("Currently Received NotiID: %d", ad->receive_noti_id);
+       db = bt_share_open_db();
+       for (i = 0; i < num_op; i++, op_list++) {
+               DBG("TYPE:%d PRIV_ID:%d", op_list->type, op_list->priv_id);
 
-       noti_err = notification_get_list(type, -1, &noti_list);
-       ret_if(noti_err != NOTIFICATION_ERROR_NONE);
-
-       noti_list = notification_list_get_head(noti_list);
-       while (noti_list) {
-               noti = notification_list_get_data(noti_list);
-               noti_err  = notification_get_id(noti, &group_id, &priv_id);
-               if (noti_err == NOTIFICATION_ERROR_NONE) {
-                       if (ad->send_noti_id == priv_id)
-                               is_sent_noti_exist = TRUE;
-                       else if (ad->receive_noti_id == priv_id)
-                               is_received_noti_exist = TRUE;
+               if (op_list->priv_id == ad->receive_noti_id) {
+                       ad->receive_noti = NULL;
+                       ad->receive_noti_id = 0;
                }
-               noti_list = notification_list_get_next(noti_list);
-       }
-       notification_free_list(noti_list);
 
-       db = bt_share_open_db();
-       retm_if(!db, "fail to open db!");
-
-       if (is_sent_noti_exist == FALSE) {
-               DBG("Not found sent notification. Delete outbound db");
-               ad->send_noti = NULL;
-               ad->send_noti_id = 0;
-               if (bt_share_remove_tr_data_by_notification(db,
-                       BT_DB_OUTBOUND) == BT_SHARE_ERR_NONE) {
+               if (bt_share_check_noti_id(db, BT_DB_OUTBOUND, op_list->priv_id)
+                                               == BT_SHARE_ERR_NONE) {
+                       DBG("Delete Entries from OUTBOUND for NotiID %d", op_list->priv_id);
+                       ad->send_noti = NULL;
+                       ad->send_noti_id = 0;
                        ad->send_data.tr_fail = 0;
                        ad->send_data.tr_success = 0;
+                       _bt_remove_temporary_files_by_noti_id(db, op_list->priv_id);
+                       bt_share_remove_tr_data_by_notification(db,
+                                       BT_DB_OUTBOUND, op_list->priv_id);
                }
-       }
-       if (is_received_noti_exist == FALSE) {
-               DBG("Not found recv notification. Delete inbound db");
-               ad->receive_noti = NULL;
-               ad->receive_noti_id = 0;
-               if (bt_share_remove_tr_data_by_notification(db,
-                       BT_DB_INBOUND) == BT_SHARE_ERR_NONE) {
+               if (bt_share_check_noti_id(db, BT_DB_INBOUND, op_list->priv_id)
+                                               == BT_SHARE_ERR_NONE) {
+                       DBG("Delete Entries from INBOUND for NotiID %d", op_list->priv_id);
+                       ad->receive_noti = NULL;
+                       ad->receive_noti_id = 0;
                        ad->recv_data.tr_fail = 0;
                        ad->recv_data.tr_success = 0;
+                       bt_share_remove_tr_data_by_notification(db,
+                                       BT_DB_INBOUND, op_list->priv_id);
                }
        }
-
        bt_share_close_db(db);
 
        DBG("SEND: Success[%d] Fail[%d] ||||| RECEIVE: Success[%d] Fail[%d]",
                        ad->send_data.tr_success, ad->send_data.tr_fail,
                        ad->recv_data.tr_success, ad->recv_data.tr_fail);
+       FN_END;
 
 }
 
-void _bt_register_notification_cb(struct bt_appdata *ad)
+void _bt_register_notification_cb(bt_appdata_t *ad)
 {
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
 
-       noti_err = notification_register_detailed_changed_cb(__bt_notification_changed_cb, ad);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               ERR("notification_resister_changed_cb failed [%d]\n", noti_err);
-       }
+       noti_err = notification_register_detailed_changed_cb(
+                       __bt_notification_changed_cb, ad);
+       warn_if(noti_err != NOTIFICATION_ERROR_NONE,
+                       "notification_resister_changed_cb failed [%d]\n", noti_err);
 }
 
-void _bt_unregister_notification_cb(struct bt_appdata *ad)
+void _bt_unregister_notification_cb(bt_appdata_t *ad)
 {
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
 
-       noti_err = notification_unregister_detailed_changed_cb(__bt_notification_changed_cb, NULL);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               ERR("notification_unresister_changed_cb failed [%d]\n", noti_err);
-       }
+       noti_err = notification_unregister_detailed_changed_cb(
+                       __bt_notification_changed_cb, NULL);
+       warn_if(noti_err != NOTIFICATION_ERROR_NONE,
+                       "notification_unresister_changed_cb failed [%d]\n", noti_err);
 }
index 245a4a6..cff757a 100644 (file)
 #include <bundle_internal.h>
 
 #include "applog.h"
+#include "bt-share-common.h"
 #include "bluetooth-api.h"
 #include "bt-share-syspopup.h"
 #include "bt-share-main.h"
 #include "bt-share-resource.h"
 #include "obex-event-handler.h"
 
-extern struct bt_appdata *app_state;
+extern bt_appdata_t *app_state;
 #define BT_POPUP_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
 #define BT_SYSPOPUP_EVENT_LEN_MAX 50
-#define BT_SYSPOPUP_MAX_CALL 10
 
 static gboolean __bt_system_popup_timer_cb(gpointer user_data)
 {
        int ret = 0;
        bundle *b = (bundle *) user_data;
 
-       if (NULL == b) {
-               ERR("There is some problem with the user data..popup can not be created\n");
-               return FALSE;
-       }
+       retvm_if(!b, FALSE,
+               "There is some problem with the user data..popup can not be created\n");
 
        ret = syspopup_launch("bt-syspopup", b);
-       if (0 > ret) {
-               ERR("launching sys-popup failed\n");
-       }
+       warn_if(0 > ret, "launching sys-popup failed\n");
 
        bundle_free(b);
        return FALSE;
 }
 
-int _bt_launch_system_popup(bt_app_event_type_t event_type,
+int _bt_launch_system_popup(bt_app_event_type_e event_type,
                            bt_app_sys_popup_params_t *popup_params,
                            void *cb,
                            void *data)
 {
-       int ret = 0;
+       FN_START;
+       int ret = BT_SHARE_ERROR_NONE;
        bundle *b = NULL;
-       char event_str[BT_SYSPOPUP_EVENT_LEN_MAX] = { 0 };
-       struct bt_appdata *ad = app_state;
-
-       DBG("+\n");
+       bt_appdata_t *ad = app_state;
+       char event_str[BT_SYSPOPUP_EVENT_LEN_MAX] = {0, };
 
        b = bundle_create();
-       if (b == NULL) {
-               ERR("bundle_create failed");
-               return -1;
-       }
+       retvm_if(!b, BT_SHARE_FAIL, "bundle_create failed");
 
        bundle_add(b, "title", popup_params->title);
        bundle_add(b, "type", popup_params->type);
@@ -78,18 +70,26 @@ int _bt_launch_system_popup(bt_app_event_type_t event_type,
        bundle_add(b, "device_name", popup_params->device_name);
 
        switch (event_type) {
-       case BT_APP_EVENT_CONFIRM_MODE_REQUEST:
+       case BT_APP_EVENT_CONFIRM_MODE_REQUEST: {
                strncpy(event_str, "app-confirm-request", sizeof(event_str));
                break;
-       case BT_APP_EVENT_FILE_RECEIVED:
+       }
+
+       case BT_APP_EVENT_FILE_RECEIVED: {
                strncpy(event_str, "file-received", sizeof(event_str));
                break;
-       case BT_APP_EVENT_INFORMATION:
+       }
+
+       case BT_APP_EVENT_INFORMATION: {
                strncpy(event_str, "bt-information", sizeof(event_str));
                break;
-       case BT_APP_EVENT_OVERWRITE_REQUEST:
+       }
+
+       case BT_APP_EVENT_OVERWRITE_REQUEST: {
                strncpy(event_str, "confirm-overwrite-request", sizeof(event_str));
                break;
+       }
+
        default:
                break;
        }
@@ -117,8 +117,8 @@ int _bt_launch_system_popup(bt_app_event_type_t event_type,
        ad->popups.popup_cb_data = data;
        ad->popups.syspopup_request = TRUE;
 
-       DBG("-\n");
-       return 0;
+       FN_END;
+       return BT_SHARE_ERROR_NONE;
 }
 
 
@@ -129,9 +129,7 @@ gboolean _bt_app_popup_memoryfull(gpointer user_data)
        popup_params.title = BT_STR_MEMORY_FULL;
        popup_params.type = "none";
        _bt_launch_system_popup(BT_APP_EVENT_INFORMATION,
-                               &popup_params,
-                               NULL,
-                               NULL);
+                       &popup_params, NULL, NULL);
        return FALSE;
 }
 
index 90e1972..5af4735 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include <ctype.h>
+#include <arpa/inet.h>
 #include <app_control.h>
 #include <vconf-keys.h>
 #ifdef ENABLE_CALENDAR_SERVICE2
-#include <calendar2.h>
+#include <calendar.h>
 #endif
 #ifdef ENABLE_CONTACTS_SERVICE2
 #include <contacts.h>
+#include <contacts_filter.h>
 #endif
 #include <vconf.h>
 #include <Ecore_File.h>
@@ -38,6 +41,7 @@
 #include <sys/stat.h>
 #include <aul.h>
 #include <storage.h>
+#include <zlib.h>
 
 /* For multi-user support */
 #include <tzplatform_config.h>
@@ -61,121 +65,162 @@ typedef struct {
 
 typedef struct {
        char *file_path;
-       bt_file_type_t file_type;
+       bt_file_type_e file_type;
 } bt_file_info_t;
 
-extern struct bt_appdata *app_state;
+extern bt_appdata_t *app_state;
 extern GSList *bt_transfer_list;
 GSList *bt_receive_noti_list;
-
-
-static gboolean isFirstReceivedPacket = FALSE;
+GSList *bt_rcv_noti_info_list = NULL;
+GSList *bt_snd_noti_info_list = NULL;
 
 static gboolean isTransferConnectedReceived = FALSE;
 
-static bt_obex_server_authorize_into_t g_server_auth_info;
-
-gboolean __bt_scan_media_file(char *file_path);
-
-void *_bt_obex_writeclose(bt_file_info_t *info);
+static void *__bt_obex_writeclose(bt_file_info_t *info);
 
 static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t *server_auth_info);
 
-static bt_noti_data_t *__bt_get_noti_data_by_transfer_id(int transfer_id)
+void _bt_convert_addr_type_to_string(char *address,
+                               char *addr)
 {
-       GSList *l;
-       bt_noti_data_t *data;
+       ret_if(address == NULL || addr == NULL);
 
-       for (l = bt_receive_noti_list; l != NULL; l = l->next) {
-               data = l->data;
+       g_snprintf(address, BT_ADDRESS_STRING_SIZE,
+                       "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+                       addr[0], addr[1], addr[2],
+                       addr[3], addr[4], addr[5]);
+}
 
-               if (data == NULL)
-                       continue;
+static void __bt_free_rcv_notification(gpointer data)
+{
+       bt_device_rcv_noti_info_t *noti_data = data;
+       ret_if(!noti_data);
 
-               if (data->transfer_id == transfer_id)
-                       return data;
-       }
+       bt_rcv_noti_info_list = g_slist_remove(bt_rcv_noti_info_list, noti_data);
+       g_free(noti_data->address);
+       g_free(noti_data->device_name);
+       g_free(noti_data->db_sid);
+       g_free(noti_data);
+}
 
-       return NULL;
+static void __bt_free_snd_notification(gpointer data)
+{
+       bt_device_snd_noti_info_t *noti_data = data;
+       ret_if(!noti_data);
+
+       bt_snd_noti_info_list = g_slist_remove(bt_snd_noti_info_list, noti_data);
+       g_free(noti_data->db_sid);
+       g_free(noti_data);
 }
 
-static char *__get_file_name(int cnt, char **path)
+static void _bt_get_pending_list(bt_appdata_t *ad)
 {
-       char *pfilename;
-       if (path == NULL) {
-               DBG("Path is invalid");
-               return NULL;
+       sqlite3 *db = NULL;
+       retm_if(ad == NULL, "Application data ad is NULL");
+
+       db = bt_share_open_db();
+       if (ad->tr_send_list) {
+               bt_share_release_tr_data_list(ad->tr_send_list);
+               ad->tr_send_list = NULL;
+               ad->tr_next_data = NULL;
        }
-       pfilename = strrchr(path[cnt], '/') + 1;
-       DBG("File name[%d] : %s \n", cnt, pfilename);
-       return pfilename;
+
+       ad->tr_send_list = bt_share_get_tr_data_list_by_status(db,
+                               BT_DB_OUTBOUND, BT_TR_PENDING);
+
+       bt_share_close_db(db);
+
+       if (ad->tr_send_list)
+               ad->tr_next_data = ad->tr_send_list;
 }
 
-static bt_file_type_t __get_file_type(char *extn)
+static bt_device_snd_noti_info_t *__bt_get_snd_noti_data_by_device_address(char *address)
 {
-       DBG("exten : %s \n", extn);
+       GSList *l = NULL;
+       bt_device_snd_noti_info_t *data = NULL;
 
-       if (NULL != extn) {
-               if (!strcmp(extn, "vcf"))
-                       return BT_FILE_VCARD;
-               else if (!strcmp(extn, "vcs"))
-                       return BT_FILE_VCAL;
-               else if (!strcmp(extn, "vbm"))
-                       return BT_FILE_VBOOKMARK;
+       for (l = bt_snd_noti_info_list; l != NULL; l = l->next) {
+               data = l->data;
+               if (data == NULL)
+                       continue;
+
+               retv_if(!strcmp(data->address, address), data);
        }
-       return BT_FILE_OTHER;
+
+       return NULL;
 }
 
-static void __delete_notification(gpointer data, gpointer user_data)
+static bt_device_rcv_noti_info_t *__bt_get_rcv_noti_data_by_device_address(char *address)
 {
-       bt_noti_data_t *noti_data = data;
+       GSList *l = NULL;
+       bt_device_rcv_noti_info_t *data = NULL;
 
-       if (noti_data == NULL)
-               return;
+       for (l = bt_rcv_noti_info_list; l != NULL; l = l->next) {
+               data = l->data;
+               if (data == NULL)
+                       continue;
 
-       _bt_delete_notification(noti_data->noti_handle);
-       g_free(noti_data);
+               retv_if(!strcmp(data->address, address), data);
+       }
+
+       return NULL;
 }
 
-int _bt_get_transfer_id_by_noti_id(int noti_id)
+static bt_noti_data_t *__bt_get_noti_data_by_transfer_id(int transfer_id)
 {
-       GSList *l;
-       bt_noti_data_t *data;
+       GSList *l = NULL;
+       bt_noti_data_t *data = NULL;
 
        for (l = bt_receive_noti_list; l != NULL; l = l->next) {
                data = l->data;
-
                if (data == NULL)
                        continue;
 
-               if (data->noti_id == noti_id)
-                       return data->transfer_id;
+               retv_if(data->transfer_id == transfer_id, data);
        }
 
-       return -1;
+       return NULL;
+}
+
+static char *__get_file_name(int cnt, char **path)
+{
+       retvm_if(path == NULL || path[cnt] == NULL, NULL, "Path is invalid");
+       char *pfilename = NULL;
+
+       pfilename = strrchr(path[cnt], '/') + 1;
+       DBG_SECURE("File name[%d] : %s", cnt, pfilename);
+       return pfilename;
+}
+
+static void __delete_notification(gpointer data, gpointer user_data)
+{
+       bt_noti_data_t *noti_data = data;
+       ret_if(!noti_data);
+
+       _bt_delete_notification(noti_data->noti_handle);
+       g_free(noti_data);
 }
 
 void _bt_obex_cancel_transfer(void *data)
 {
-       DBG("+");
+       FN_START;
        retm_if(!data, "invalid param!");
+
        GSList *l = NULL;
        bt_noti_data_t *noti_data = NULL;
        int ret = 0;
 
        for (l = bt_receive_noti_list; l != NULL; l = l->next) {
                noti_data = l->data;
-
                if (noti_data == NULL)
                        continue;
 
                DBG("noti_id : %d", noti_data->noti_id);
                ret = bluetooth_obex_server_cancel_transfer(noti_data->transfer_id);
-               if (ret != BLUETOOTH_ERROR_NONE) {
-                       ERR("bluetooth_obex_server_cancel_transfer[ret:%d]", ret);
-               }
+               warn_if(ret != BLUETOOTH_ERROR_NONE,
+                       "bluetooth_obex_server_cancel_transfer[ret:%d]", ret);
        }
-       DBG("-");
+       FN_END;
 }
 
 void _bt_clear_receive_noti_list(void)
@@ -189,14 +234,14 @@ void _bt_clear_receive_noti_list(void)
        }
 }
 
-char * __get_dest_file_path(const char *path)
+char *__get_dest_file_path(const char *path)
 {
-       char file_path[BT_TEMP_FILE_PATH_LEN_MAX] = { 0, };
+       char file_path[BT_TEMP_FILE_PATH_LEN_MAX] = {0, };
 
        /* Media updation is failing if we give FTP folder path.
-          So we have to map the FTP folder path like below
-          /opt/share/bt-ftp/Media/XX -> /opt/usr/media/XX
-          /opt/share/bt-ftp/SD_External/XX -> /opt/storage/sdcard/XX
+            So we have to map the FTP folder path like below
+            /opt/share/bt-ftp/Media/XX -> /opt/usr/media/XX
+            /opt/share/bt-ftp/SD_External/XX -> /opt/storage/sdcard/XX
         */
        if (g_str_has_prefix(path, BT_FTP_FOLDER_PHONE)) {
                snprintf(file_path, sizeof(file_path), "%s/%s",
@@ -210,8 +255,7 @@ char * __get_dest_file_path(const char *path)
                snprintf(file_path, sizeof(file_path), "%s", path);
        }
 
-       DBG("File path %s", file_path);
-
+       DBG_SECURE("File path %s", file_path);
        return g_strdup(file_path);
 }
 
@@ -221,58 +265,374 @@ static void __free_file_info(bt_file_info_t *info)
        g_free(info);
 }
 
+static bt_file_type_e __get_file_type(char *extn)
+{
+       DBG("extn : %s", extn);
+
+       if (extn != NULL) {
+               if (!strcmp(extn, "vcf"))
+                       return BT_FILE_VCARD;
+               else if (!strcmp(extn, "vcs"))
+                       return BT_FILE_VCAL;
+               else if (!strcmp(extn, "vbm"))
+                       return BT_FILE_VBOOKMARK;
+       }
+       return BT_FILE_OTHER;
+}
+
+static gboolean __bt_scan_media_file(char *file_path)
+{
+       int ret = 0;
+
+       ret = media_content_connect();
+       retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, FALSE,
+               "Fail to connect the media content: %d", ret);
+
+       ret = media_content_scan_file(file_path);
+       warn_if(ret != MEDIA_CONTENT_ERROR_NONE, "Fail to scan file: %d", ret);
+
+       ret = media_content_disconnect();
+       warn_if(ret != MEDIA_CONTENT_ERROR_NONE,
+                       "Fail to disconnect the media content: %d", ret);
+
+       return TRUE;
+}
+
+void __bt_update_db_with_noti_id(bt_tr_db_table_e table, notification_h noti,
+               const char *db_sid)
+{
+       sqlite3 *db = bt_share_open_db();
+       int noti_id = 0;
+
+       noti_id = _bt_get_notification_priv_id(noti);
+       INFO("Update into database noti_id: %d", noti_id);
+       bt_share_update_noti_id(db, table, noti_id, db_sid);
+
+       bt_share_close_db(db);
+}
+
+#ifdef ENABLE_CONTACTS_SERVICE2
+void _bt_util_get_number(char *source, char *dest)
+{
+       int len = 7;
+       int slen = 0;
+       char buf[9];
+
+       slen = strlen(source);
+       slen--;
+       buf[8] = '\0';
+       while (len > -1) {
+               if (slen > -1) {
+                       if (isdigit(source[slen])) {
+                               buf[len] = source[slen];
+                               --len;
+                       }
+                       --slen;
+               } else {
+                       break;
+               }
+       }
+       if (len < 0)
+               len = 0;
+       strcpy(dest, &buf[len]);
+}
+
+void _bt_util_get_contact_name(int lcontact_id, char **contact_name)
+{
+       int ret = 0;
+       int count = 0;
+       contacts_filter_h filter = NULL;
+       contacts_query_h query = NULL;
+       contacts_list_h list = NULL;
+       contacts_record_h record = NULL;
+       char *name = NULL;
+
+       DBG("+");
+       ret = contacts_filter_create(_contacts_contact._uri, &filter);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to create filter for contacts");
+               goto fail;
+       }
+
+       ret = contacts_filter_add_int(filter, _contacts_contact.id,
+                       CONTACTS_MATCH_EXACTLY, lcontact_id);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to add str to filter for contacts");
+               goto fail;
+       }
+
+       ret = contacts_query_create(_contacts_contact._uri, &query);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to create qurey for contacts");
+               goto fail;
+       }
+
+       ret = contacts_query_set_filter(query, filter);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to set filter for contacts");
+               goto fail;
+       }
+
+       ret = contacts_db_get_count_with_query(query, &count);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to get count from db");
+               goto fail;
+       }
+
+       if (count < 1) {
+               DBG("No match");
+               goto fail;
+       }
+       DBG("count = %d", count);
+       ret = contacts_db_get_records_with_query(query, 0, 0, &list);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to get records from db");
+               goto fail;
+       }
+       contacts_list_first(list);
+
+       while (ret == CONTACTS_ERROR_NONE) {
+               contacts_list_get_current_record_p(list, &record);
+               contacts_record_get_str_p(record,
+                               _contacts_contact.display_name,
+                               &name);
+               if (name != NULL) {
+                       *contact_name = g_strdup(name);
+                       break;
+               }
+
+               ret = contacts_list_next(list);
+       }
+
+fail:
+       if (filter)
+               contacts_filter_destroy(filter);
+
+       if (query)
+               contacts_query_destroy(query);
+
+       if (list)
+               contacts_list_destroy(list, true);
+       DBG("-");
+       return;
+}
+
+unsigned int bt_crc32(const void *src, unsigned long src_sz)
+{
+       return (crc32(0, src, src_sz) & 0xFFFF);
+}
+
+void _bt_util_get_contact_info(unsigned char *auth_info, int *contact_id, char **contact_name)
+{
+       unsigned int shash = 0;
+       unsigned int chash = 0;
+       char pnumber[20] = {0,};
+       char str_hash[7] = {0,};
+       int ret = CONTACTS_ERROR_NONE;
+       char *number = NULL;
+       int lcontact_id = 0;
+       int count = 0;
+
+       contacts_filter_h filter = NULL;
+       contacts_query_h query = NULL;
+       contacts_list_h list = NULL;
+       contacts_record_h record = NULL;
+
+       retm_if(!auth_info, "auth_info is NULL");
+       retm_if(!contact_id, "contact_id is NULL");
+       retm_if(!contact_name, "contact_name is NULL");
+       DBG("+");
+       if (contacts_connect() != CONTACTS_ERROR_NONE) {
+               ERR("contacts_connect failed");
+               return;
+       }
+
+       memcpy(&shash, auth_info, 3);
+       shash = ntohl(shash);
+       shash >>= 8;
+
+       memcpy(&chash, &auth_info[3], 2);
+       chash = ntohl(chash);
+       chash >>= 16;
+
+       g_snprintf(str_hash, 7, "%X", shash);
+
+#if 0
+       ret = contacts_filter_create(_contacts_quick_connect_info._uri, &filter);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to create filter for contacts");
+               goto fail;
+       }
+
+       ret = contacts_filter_add_str(filter, _contacts_quick_connect_info.hash,
+                       CONTACTS_MATCH_EXACTLY, str_hash);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to add str to filter for contacts");
+               goto fail;
+       }
+
+       ret = contacts_query_create(_contacts_quick_connect_info._uri, &query);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to create qurey for contacts");
+               goto fail;
+       }
+#endif
+
+       ret = contacts_query_set_filter(query, filter);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to set filter for contacts");
+               goto fail;
+       }
+
+       ret = contacts_db_get_count_with_query(query, &count);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to get count from db");
+               goto fail;
+       }
+
+       if (count < 1) {
+               DBG("No match");
+               goto fail;
+       }
+
+       ret = contacts_db_get_records_with_query(query, 0, 0, &list);
+       if (ret != CONTACTS_ERROR_NONE) {
+               ERR("Fail to get records from db");
+               goto fail;
+       }
+
+       contacts_list_first(list);
+
+       while (ret == CONTACTS_ERROR_NONE) {
+               contacts_list_get_current_record_p(list, &record);
+#if 0
+               contacts_record_get_str_p(record,
+                               _contacts_quick_connect_info.number,
+                               &number);
+#endif
+               DBG_SECURE("number: [%s]", number);
+               if (number != NULL) {
+                       _bt_util_get_number(number, pnumber);
+                       DBG_SECURE("pnumber: [%s]", pnumber);
+
+                       DBG_SECURE("CRC [%X], [%X]", chash, bt_crc32(pnumber, strlen(pnumber)));
+
+                       if (bt_crc32(pnumber , strlen(pnumber)) == chash) {
+#if 0
+                               contacts_record_get_int(record,
+                                               _contacts_quick_connect_info.contact_id,
+                                               &lcontact_id);
+#endif
+                               *contact_id = lcontact_id;
+                               _bt_util_get_contact_name(lcontact_id, contact_name);
+                               DBG_SECURE("contact id : %d", lcontact_id);
+                               break;
+                       }
+               }
+               ret = contacts_list_next(list);
+       }
+
+fail:
+       if (filter)
+               contacts_filter_destroy(filter);
+
+       if (query)
+               contacts_query_destroy(query);
+
+       if (list)
+               contacts_list_destroy(list, true);
+
+       contacts_disconnect();
+
+       DBG("-");
+}
+#endif
+
 void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                               void *user_data)
 {
-       int ret;
        static int send_index = 0;
        static gboolean is_started = FALSE;
+       static char *snd_db_sid = NULL;
+       static char *rcv_db_sid = NULL;
+       static bool is_tr_wait = true;
        int percentage = 0;
        int s_id = 0;
        char *name = NULL;
-       char opc_cnt[NOTIFICATION_TEXT_LEN_MAX] = {0, };
+       char *opc_cnt = NULL;
        notification_h noti = NULL;
        bt_obex_server_authorize_into_t *auth_info = NULL;
        bt_obex_server_transfer_info_t *transfer_info = NULL;
        opc_transfer_info_t *node = NULL;
-       struct bt_appdata *ad = app_state;
+       bt_appdata_t *ad = app_state;
        bt_tr_data_t *info = NULL;
        bt_opc_transfer_info_t *client_info = NULL;
        bt_noti_data_t *data = NULL;
+       bt_device_snd_noti_info_t *snd_noti_info = NULL;
+
        pthread_t thread_id;
+       char bd_addr[BT_ADDRESS_STRING_SIZE] = {0, };
 
        if (bt_transfer_list)
                node = bt_transfer_list->data;
 
        switch (event) {
-       case BLUETOOTH_EVENT_ENABLED:
+       case BLUETOOTH_EVENT_ENABLED: {
                if (ad->obex_server_init == FALSE) {
                        if (_bt_init_obex_server() == BT_SHARE_ERROR_NONE)
                                ad->obex_server_init = TRUE;
                }
                break;
-
-       case BLUETOOTH_EVENT_OPC_CONNECTED:
-               INFO("BLUETOOTH_EVENT_OPC_CONNECTED, result [%d] \n", param->result);
+       }
+       case BLUETOOTH_EVENT_DISABLED: {
+               INFO("BT is disabled");
+               _bt_terminate_bluetooth_share();
+               break;
+       }
+       case BLUETOOTH_EVENT_OPC_CONNECTED: {
+               INFO("BLUETOOTH_EVENT_OPC_CONNECTED, result [%d]", param->result);
                send_index = 0;
                is_started = FALSE;
+               is_tr_wait = true;
+
+               _bt_get_pending_list(ad);
+
+               retm_if(ad->tr_next_data == NULL, "ad->tr_next_data is NULL");
+
+               info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+               retm_if(info == NULL, "info is NULL");
+
+               snd_db_sid = info->db_sid;
+               DBG_SECURE("snd_db_sid = [%s]", snd_db_sid);
+
+               _bt_convert_addr_type_to_string(bd_addr, info->addr);
+               DBG_SECURE("bd_addr = [%s]", bd_addr);
+
+               INFO("New device %s", node->name);
+
+               snd_noti_info = g_new0(bt_device_snd_noti_info_t, 1);
+               memcpy(snd_noti_info->device_name, node->name,
+                                       BLUETOOTH_DEVICE_NAME_LENGTH_MAX);
+               memcpy(snd_noti_info->address,
+                               info->addr, BT_ADDRESS_STRING_SIZE);
+               snd_noti_info->db_sid = g_strdup(snd_db_sid);
+               snd_noti_info->send_noti = NULL;
+               snd_noti_info->send_data.tr_success = 0;
+               snd_noti_info->send_data.tr_fail = 0;
+               bt_snd_noti_info_list = g_slist_append(bt_snd_noti_info_list, snd_noti_info);
+
                if (param->result != BLUETOOTH_ERROR_NONE) {
                        _bt_create_warning_popup(param->result,
                                BT_STR_UNABLE_TO_SEND);
-                       if (NULL != node && node->file_cnt > send_index) {
-                               if (ad->tr_next_data == NULL) {
-                                       ERR("ad->tr_next_data is NULL");
-                                       return;
-                               }
-                               info = (bt_tr_data_t *)(ad->tr_next_data)->data;
-                               if (info == NULL) {
-                                       ERR("info is NULL");
-                                       return;
-                               }
+                       if (node != NULL && node->file_cnt > send_index) {
+                               int *uids;
+                               int uid_cnt = 0;
 
                                s_id = info->sid;
                                INFO("info->sid = %d info->id = %d", info->sid, info->id);
-                               while (NULL != ad->tr_next_data) {
+                               uids = g_malloc0(node->file_cnt * sizeof(int));
+
+                               while (ad->tr_next_data != NULL) {
                                        info = (bt_tr_data_t *)(ad->tr_next_data)->data;
                                        if (info == NULL)
                                                break;
@@ -282,19 +642,34 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                                                break;
                                        }
 
-                                       _bt_update_sent_data_status(info->id, BT_TR_FAIL);
-                                       ad->send_data.tr_fail++;
+                                       uids[uid_cnt++] = info->id;
+                                       snd_noti_info->send_data.tr_fail++;
                                        ad->tr_next_data = g_slist_next(ad->tr_next_data);
                                }
-                               _bt_update_transfer_list_view("outbound");
-
-                               if (ad->send_noti == NULL) {
-                                       ad->send_noti = _bt_insert_notification(ad, BT_SENT_NOTI, 0, 0);
+                               _bt_update_multiple_sent_data_status(uids, uid_cnt, BT_TR_FAIL,
+                                                               snd_noti_info->db_sid);
+                               _bt_update_transfer_list_view(BT_OUTBOUND_TABLE);
+
+                               if (snd_noti_info->send_noti == NULL) {
+                                       ad->send_data.tr_success = snd_noti_info->send_data.tr_success;
+                                       ad->send_data.tr_fail = snd_noti_info->send_data.tr_fail;
+                                       snd_noti_info->send_noti = _bt_insert_notification(
+                                               ad, BT_SENT_NOTI, snd_noti_info->device_name,
+                                               snd_noti_info->address, snd_noti_info->db_sid);
                                } else {
-                                       _bt_update_notification(ad, ad->send_noti, NULL, NULL, NULL);
+                                       ad->send_noti = snd_noti_info->send_noti;
+                                       ad->send_data.tr_success = snd_noti_info->send_data.tr_success;
+                                       ad->send_data.tr_fail = snd_noti_info->send_data.tr_fail;
+                                       _bt_update_notification(ad, ad->send_noti, NULL, NULL,
+                                                                       NULL, NULL);
                                }
+                               /* Update Database with Notification ID*/
+                               __bt_update_db_with_noti_id(BT_DB_OUTBOUND, snd_noti_info->send_noti,
+                                               snd_noti_info->db_sid);
+                               g_free(uids);
                        }
 
+                       __bt_free_snd_notification(snd_noti_info);
                        _remove_transfer_info(node);
 
                        if (!ad->tr_next_data) {
@@ -303,71 +678,110 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                        }
 
                } else {
-                       ret = notification_status_message_post(BT_STR_SENDING);
-                       if (ret != NOTIFICATION_ERROR_NONE)
-                               ERR("notification_status_message_post() is failed : %d", ret);
+                       if (node) {
+                               _bt_insert_instant_notification(BT_SENDING_NOTI);
+
+                               if (ad->opc_noti) {
+                                       _bt_delete_notification(ad->opc_noti);
+                                       ad->opc_noti = NULL;
+                                       ad->opc_noti_id = 0;
+                               }
 
+                               noti = _bt_insert_notification(ad,
+                                                       BT_SENDING_NOTI, node->name,
+                                                       node->addr, info->db_sid);
+                               ad->opc_noti = noti;
+                               ad->opc_noti_id = _bt_get_notification_priv_id(noti);
+                       }
                        _bt_share_block_sleep(TRUE);
                        _bt_set_transfer_indicator(TRUE);
                }
                break;
+       }
 
-       case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
+       case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED: {
                INFO("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
                ret_if(node == NULL);
+               retm_if(!ad, "ad is NULL");
+               retm_if(!ad->tr_next_data, "ad>tr_next_data is NULL");
+
+               info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+               ret_if(info == NULL);
 
                is_started = TRUE;
 
-               if (ad->opc_noti) {
-                       _bt_delete_notification(ad->opc_noti);
-                       ad->opc_noti = NULL;
-                       ad->opc_noti_id = 0;
-               }
+               if (send_index > 0 && is_tr_wait == true)
+                       is_tr_wait = false;
 
                name = __get_file_name(send_index++, node->file_path);
-               snprintf(opc_cnt, sizeof(opc_cnt), "%d/%d",
-                               send_index, node->file_cnt);
-
-               noti = _bt_insert_notification(ad, BT_SENDING_NOTI, send_index, node->file_cnt);
-               ad->opc_noti_id = _bt_get_notification_priv_id(noti);
-               _bt_set_notification_app_launch(noti, CREATE_PROGRESS,
-                                       NOTI_TR_TYPE_OUT, name, opc_cnt, 0);
 
-               ad->opc_noti = noti;
+               if (node->file_cnt > 1)
+                       opc_cnt = g_strdup_printf("[%d/%d]", send_index, node->file_cnt);
 
                INFO("file count %d", node->file_cnt);
-               _bt_update_notification(ad, ad->opc_noti, name, NULL, NULL);
+               _bt_convert_addr_type_to_string(bd_addr, node->addr);
+               DBG_SECURE("bd_addr = [%s]", bd_addr);
+
+               if (node->file_cnt > 1)
+                       _bt_set_notification_app_launch(ad->opc_noti, node->name, bd_addr,
+                                       info->db_sid, CREATE_PROGRESS, NOTI_TR_TYPE_OUT,
+                                       name, *(node->size), opc_cnt, 0);
+               else
+                       _bt_set_notification_app_launch(ad->opc_noti, node->name, bd_addr,
+                                       info->db_sid, CREATE_PROGRESS, NOTI_TR_TYPE_OUT,
+                                       name, *(node->size), "[1/1]", 0);
+
+               _bt_update_sent_data_status(info->id, BT_TR_ONGOING, info->db_sid);
                _bt_update_transfer_list_view("outbound");
 
-               if (ad->tr_next_data == NULL) {
-                       ERR("ad->tr_next_data is NULL");
-                       return;
+               if (ad->opc_noti && is_tr_wait == false) {
+                       char *tmp = BT_STR_SENDING_FILES_TO;
+                       char *sending_files = g_strdup_printf(tmp, node->name);
+                       _bt_update_notification(ad, ad->opc_noti, name, sending_files, NULL, opc_cnt);
+                       _bt_update_notification_progress(NULL, ad->opc_noti_id, 0);
+                       g_free(sending_files);
                }
 
-               info = (bt_tr_data_t *)(ad->tr_next_data)->data;
-               ret_if(info == NULL);
+               g_free(opc_cnt);
+               retm_if(ad->tr_next_data == NULL, "ad->tr_next_data is NULL");
+
                ad->current_tr_uid = info->id;
                INFO("ad->current_tr_uid = [%d]", ad->current_tr_uid);
                break;
+       }
 
-       case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
+       case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS: {
                client_info = (bt_opc_transfer_info_t *)param->param_data;
                ret_if(client_info == NULL);
 
+               percentage = client_info->percentage;
                name =  strrchr(client_info->filename, '/');
                if (name)
                        name++;
                else
                        name = client_info->filename;
 
-               percentage = client_info->percentage;
+               if (ad->opc_noti) {
+                       if (is_tr_wait == true) {
+                               char *tmp = BT_STR_SENDING_FILES_TO;
+                               char *sending_files = g_strdup_printf(tmp, node->name);
 
-               _bt_update_notification_progress(NULL,
-                               ad->opc_noti_id, percentage);
-               break;
+                               if (node->file_cnt > 1)
+                                       opc_cnt = g_strdup_printf("[%d/%d]", send_index, node->file_cnt);
 
+                               _bt_update_notification(ad, ad->opc_noti, name, sending_files,
+                                               NULL, opc_cnt);
 
-       case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
+                               g_free(opc_cnt);
+                               g_free(sending_files);
+                               is_tr_wait = false;
+                       }
+                       _bt_update_notification_progress(NULL, ad->opc_noti_id, percentage);
+               }
+               break;
+       }
+
+       case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE: {
                INFO("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
 
                if (!is_started) {
@@ -384,7 +798,7 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                client_info = (bt_opc_transfer_info_t *)param->param_data;
                ret_if(client_info == NULL);
 
-               DBG("client_info->filename = [%s]", client_info->filename);
+               DBG_SECURE("client_info->filename = [%s]", client_info->filename);
                INFO("ad->current_tr_uid = [%d]", ad->current_tr_uid);
 
                name =  strrchr(client_info->filename, '/');
@@ -393,86 +807,126 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                else
                        name = client_info->filename;
 
-               DBG("name address = [%x]", name);
+               if (ad->opc_noti && is_tr_wait == true) {
+                       char *tmp = BT_STR_SENDING_FILES_TO;
+                       char *sending_files = g_strdup_printf(tmp, node->name);
 
+                       if (node->file_cnt > 1)
+                               opc_cnt = g_strdup_printf("[%d/%d]", send_index, node->file_cnt);
 
+                       _bt_update_notification(ad, ad->opc_noti, name, sending_files, NULL, opc_cnt);
+                       g_free(opc_cnt);
+                       g_free(sending_files);
+                       is_tr_wait = false;
+               }
 
-               if (ad->opc_noti) {
-                       _bt_delete_notification(ad->opc_noti);
-                       ad->opc_noti = NULL;
-                       ad->opc_noti_id = 0;
+               DBG("name address = [%x]", name);
+
+               _bt_convert_addr_type_to_string(bd_addr, node->addr);
+               DBG_SECURE("bd_addr = [%s]", bd_addr);
+
+               snd_noti_info = __bt_get_snd_noti_data_by_device_address(bd_addr);
+               if (snd_noti_info == NULL) {
+                       INFO("New device %s", node->name);
+
+                       snd_noti_info = g_new0(bt_device_snd_noti_info_t, 1);
+                       memcpy(snd_noti_info->device_name, node->name,
+                                               BLUETOOTH_DEVICE_NAME_LENGTH_MAX);
+                       memcpy(snd_noti_info->address, bd_addr,
+                                               BT_ADDRESS_STRING_SIZE);
+                       snd_noti_info->db_sid = g_strdup(snd_db_sid);
+                       snd_noti_info->send_noti = NULL;
+                       snd_noti_info->send_data.tr_success = 0;
+                       snd_noti_info->send_data.tr_fail = 0;
+                       bt_snd_noti_info_list = g_slist_append(bt_snd_noti_info_list, snd_noti_info);
                }
                INFO("ad->send_data.tr_fail = %d, ad->send_data.tr_success= %d",
                        ad->send_data.tr_fail, ad->send_data.tr_success);
 
                if (param->result != BLUETOOTH_ERROR_NONE)
-                       ad->send_data.tr_fail++;
+                       snd_noti_info->send_data.tr_fail++;
                else {
-                       ad->send_data.tr_success++;
+                       snd_noti_info->send_data.tr_success++;
                        _bt_remove_tmp_file(client_info->filename);
                        _bt_remove_vcf_file(client_info->filename);
+                       _bt_update_notification_progress(NULL, ad->opc_noti_id, 100);
                }
 
-               if (ad->send_noti == NULL) {
-                       ad->send_noti = _bt_insert_notification(ad, BT_SENT_NOTI, 0, 0);
-               } else {
-                       _bt_update_notification(ad, ad->send_noti, NULL, NULL, NULL);
-               }
-
-               if (param->result != BLUETOOTH_ERROR_NONE) {
+               if (param->result == BLUETOOTH_ERROR_NOT_FOUND) {
+                       ERR("File Doesn't exist. ");
                        _bt_update_sent_data_status(ad->current_tr_uid,
-                                                       BT_TR_FAIL);
-                       DBG("opp_transfer_abort by user %d ", ad->opp_transfer_abort);
+                                                       BT_TR_FAIL, snd_noti_info->db_sid);
+               } else if (param->result != BLUETOOTH_ERROR_NONE) {
+                       _bt_update_sent_data_status(ad->current_tr_uid,
+                                                       BT_TR_FAIL, snd_noti_info->db_sid);
+                       ERR("opp_transfer_abort by user %d ", ad->opp_transfer_abort);
+
                        if (!ad->opp_transfer_abort)
                                _bt_create_warning_popup(param->result,
                                        BT_STR_UNABLE_TO_SEND);
+
                        ad->opp_transfer_abort = FALSE;
-                       _bt_update_transfer_list_view("outbound");
-                       ad->tr_next_data = g_slist_next(ad->tr_next_data);
-                       break;
                } else {
                        _bt_update_sent_data_status(ad->current_tr_uid,
-                                                       BT_TR_SUCCESS);
+                                                       BT_TR_SUCCESS, snd_noti_info->db_sid);
                }
 
-               _bt_update_transfer_list_view("outbound");
+               _bt_update_transfer_list_view(BT_OUTBOUND_TABLE);
 
                ad->tr_next_data = g_slist_next(ad->tr_next_data);
                break;
+       }
 
-
-       case BLUETOOTH_EVENT_OPC_DISCONNECTED:
+       case BLUETOOTH_EVENT_OPC_DISCONNECTED: {
                INFO("BLUETOOTH_EVENT_OPC_DISCONNECTED");
                ret_if(node == NULL);
 
+               if (ad->opc_noti) {
+                       _bt_delete_notification(ad->opc_noti);
+                       ad->opc_noti = NULL;
+                       ad->opc_noti_id = 0;
+               }
+
+               _bt_convert_addr_type_to_string(bd_addr, node->addr);
+               DBG_SECURE("bd_addr = [%s]", bd_addr);
+
+               snd_noti_info = __bt_get_snd_noti_data_by_device_address(bd_addr);
+
+               if (snd_noti_info == NULL) {
+                       ERR("snd_noti_info == NULL, this shouldn't happen");
+                       goto done;
+               }
+               if (snd_noti_info->send_noti == NULL) {
+                       ad->send_data.tr_success = snd_noti_info->send_data.tr_success;
+                       ad->send_data.tr_fail = snd_noti_info->send_data.tr_fail;
+                       snd_noti_info->send_noti = _bt_insert_notification(ad,
+                               BT_SENT_NOTI, snd_noti_info->device_name,
+                               snd_noti_info->address, snd_noti_info->db_sid);
+               }
+
+               if (snd_noti_info->send_data.tr_success)
+                       _bt_insert_instant_notification(BT_SENT_NOTI);
+               else
+                       _bt_insert_instant_notification(BT_SENT_FAILED_NOTI);
+
                if (node->file_cnt > send_index) {
+                       int *uids;
+                       int uid_cnt = 0;
                        send_index = 0;
                        is_started = FALSE;
+                       retm_if(!ad->tr_next_data, "ad>tr_next_data is NULL");
 
-                       if (!ad) {
-                               ERR("ad is NULL");
-                               break;
-                       }
-                       if (!ad->tr_next_data) {
-                               send_index = 0;
-                               is_started = FALSE;
-                               _bt_share_block_sleep(FALSE);
-                               _bt_set_transfer_indicator(FALSE);
-                               _remove_transfer_info(node);
-                               if (!ad->tr_next_data) {
-                                       bt_share_release_tr_data_list(ad->tr_send_list);
-                                       ad->tr_send_list = NULL;
-                               }
-
-                               ERR("ad>tr_next_data is NULL");
+                       info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+                       if (info == NULL) {
+                               /* Send Disconnect to Share-UI */
+                               _bt_send_disconnected_signal(BT_SHARE_ENG_SIGNAL_OPP_CLIENT_DISCONNECTED,
+                                               BLUETOOTH_ERROR_NONE, bd_addr, 0);
                                break;
                        }
 
-                       info = (bt_tr_data_t *)(ad->tr_next_data)->data;
-                       if (info == NULL)
-                               break;
                        s_id = info->sid;
                        INFO("info->sid = %d info->id = %d", info->sid, info->id);
+                       uids = g_malloc0(node->file_cnt * sizeof(int));
 
                        while (NULL != ad->tr_next_data) {
                                info = (bt_tr_data_t *)(ad->tr_next_data)->data;
@@ -485,22 +939,30 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                                        break;
                                }
 
-                               _bt_update_sent_data_status(info->id, BT_TR_FAIL);
-                               ad->send_data.tr_fail++;
+                               uids[uid_cnt++] = info->id;
+                               snd_noti_info->send_data.tr_fail++;
                                ad->tr_next_data = g_slist_next(ad->tr_next_data);
                        }
-                       _bt_update_transfer_list_view("outbound");
-
-                       if (ad->send_noti == NULL) {
-                               ad->send_noti = _bt_insert_notification(ad, BT_SENT_NOTI, 0, 0);
-                       } else {
-                               _bt_update_notification(ad, ad->send_noti, NULL, NULL, NULL);
-                       }
+                       _bt_update_multiple_sent_data_status(uids, uid_cnt, BT_TR_FAIL,
+                                                               snd_noti_info->db_sid);
+                       ad->send_noti = snd_noti_info->send_noti;
+                       ad->send_data.tr_success = snd_noti_info->send_data.tr_success;
+                       ad->send_data.tr_fail = snd_noti_info->send_data.tr_fail;
+                       _bt_update_notification(ad, ad->send_noti, NULL, NULL, NULL, NULL);
+                       g_free(uids);
                }
 
+               /* Update Database with Notification ID*/
+               __bt_update_db_with_noti_id(BT_DB_OUTBOUND, snd_noti_info->send_noti,
+                               snd_noti_info->db_sid);
+done:
+               /* Send Disconnect to Share-UI */
+               _bt_send_disconnected_signal(BT_SHARE_ENG_SIGNAL_OPP_CLIENT_DISCONNECTED,
+                               BLUETOOTH_ERROR_NONE, bd_addr, 0);
 
                send_index = 0;
                is_started = FALSE;
+               __bt_free_snd_notification(snd_noti_info);
                _bt_share_block_sleep(FALSE);
                _bt_set_transfer_indicator(FALSE);
                _remove_transfer_info(node);
@@ -509,76 +971,174 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                        ad->tr_send_list = NULL;
                }
                break;
+       }
 
-       case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
+       case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE: {
                INFO("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
                break;
-       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
+       }
+
+       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE: {
                INFO("BT_EVENT_OBEX_TRANSFER_AUTHORIZE");
                if (param->result == BLUETOOTH_ERROR_NONE) {
-                       g_free(g_server_auth_info.filename);
-                       g_server_auth_info.filename = NULL;
+                       g_free(server_auth_info.filename);
+                       g_free(server_auth_info.name);
+                       server_auth_info.filename = NULL;
+                       server_auth_info.name = NULL;
 
                        auth_info = param->param_data;
-                       g_server_auth_info.filename = g_strdup(auth_info->filename);
-                       g_server_auth_info.length = auth_info->length;
-                       if (g_server_auth_info.filename)
-                               __bt_obex_file_push_auth(&g_server_auth_info);
+                       server_auth_info.filename = g_strdup(auth_info->filename);
+                       server_auth_info.length = auth_info->length;
+                       server_auth_info.name = g_strdup(auth_info->name);
+
+                       if (server_auth_info.filename)
+                               __bt_obex_file_push_auth(&server_auth_info);
                }
                break;
+       }
 
-       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED:
+       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED: {
                INFO("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED");
+               bt_device_rcv_noti_info_t *rcv_noti_info = NULL;
+
+               rcv_db_sid = _bt_get_time_of_the_day();
+
+               DBG_SECURE("rcv_db_sid = [%s]", rcv_db_sid);
                if (param->result == BLUETOOTH_ERROR_NONE) {
+                       bt_obex_server_connection_info_t *conn_info = param->param_data;
+                       DBG_SECURE("Address[%s] DeviceName[%s] TransferID[%d]",
+                                       conn_info->address, conn_info->device_name,
+                                       conn_info->transfer_id);
+
+                       rcv_noti_info =
+                               __bt_get_rcv_noti_data_by_device_address(conn_info->address);
+                       if (rcv_noti_info == NULL) {
+                               INFO("New device %s", conn_info->device_name);
+
+                               rcv_noti_info = g_new0(bt_device_rcv_noti_info_t, 1);
+                               rcv_noti_info->id = -1;
+                               rcv_noti_info->address = g_strdup(conn_info->address);
+                               rcv_noti_info->device_name = g_strdup(conn_info->device_name);
+                               rcv_noti_info->db_sid = g_strdup(rcv_db_sid);
+                               rcv_noti_info->recv_data.tr_success = -1;
+                               rcv_noti_info->recv_data.tr_fail = -1;
+                               bt_rcv_noti_info_list = g_slist_append(bt_rcv_noti_info_list, rcv_noti_info);
+                       }
+
+                       /* Insert Notification */
+                       /* TODO: Need to distinguish between GET or PUT request and show Receiving or Sending */
+                       noti = _bt_insert_notification(ad,
+                                       BT_RECEIVING_NOTI,
+                                       rcv_noti_info->device_name,
+                                       rcv_noti_info->address,
+                                       rcv_noti_info->db_sid);
+
+                       /* Save notification handle & ID and Transfer ID*/
+                       data = g_new0(bt_noti_data_t, 1);
+                       data->noti_handle = noti;
+                       data->noti_id = _bt_get_notification_priv_id(noti);
+                       data->transfer_id = conn_info->transfer_id;
+                       bt_receive_noti_list = g_slist_append(bt_receive_noti_list, data);
+
 
                        isTransferConnectedReceived = TRUE;
                }
                break;
-       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
+       }
+
+       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED: {
                INFO("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
-               isFirstReceivedPacket = TRUE;
                transfer_info = param->param_data;
-               if (transfer_info->file_size > (100 * 1024)) {
-                       if (0 == g_strcmp0(transfer_info->type, TRANSFER_GET)) {
-                               /*GET request */
-                               noti = _bt_insert_notification(ad, BT_SENDING_NOTI, 0, 0);
+               unsigned int file_size = 0;
+               char *contact_name = NULL;
+               bt_device_rcv_noti_info_t *rcv_noti_info =
+                       __bt_get_rcv_noti_data_by_device_address(transfer_info->address);
+               data = __bt_get_noti_data_by_transfer_id(transfer_info->transfer_id);
+               int current_file;
 
-                               _bt_set_notification_app_launch(noti, CREATE_PROGRESS,
-                                               NOTI_TR_TYPE_OUT, transfer_info->filename, NULL,
-                                               transfer_info->transfer_id);
-                       } else {
-                               /*PUT Request */
-                               noti = _bt_insert_notification(ad, BT_RECEIVING_NOTI, 0, 0);
-                               _bt_set_notification_app_launch(noti, CREATE_PROGRESS,
-                                               NOTI_TR_TYPE_IN, transfer_info->filename, NULL,
-                                               transfer_info->transfer_id);
-                       }
+               retm_if(data == NULL || rcv_noti_info == NULL, "Notification data NULL");
 
-                       data = g_new0(bt_noti_data_t, 1);
-                       data->noti_handle = noti;
-                       data->noti_id = _bt_get_notification_priv_id(noti);
+               if (rcv_noti_info->recv_data.tr_success == -1 &&
+                               rcv_noti_info->recv_data.tr_fail == -1) {
+                       current_file = 1;
+               } else {
+                       current_file = rcv_noti_info->recv_data.tr_success +
+                                       rcv_noti_info->recv_data.tr_fail + 1;
+               }
 
-                       data->transfer_id = transfer_info->transfer_id;
+               opc_cnt = g_strdup_printf("[%d/All]", current_file);
+
+               if (g_strcmp0(transfer_info->type, TRANSFER_GET) == 0) {
+                       /*GET request */
+                       _bt_set_notification_app_launch(noti,
+                                       transfer_info->device_name,
+                                       transfer_info->address,
+                                       rcv_db_sid,
+                                       CREATE_PROGRESS,
+                                       NOTI_TR_TYPE_OUT,
+                                       transfer_info->filename,
+                                       transfer_info->file_size, NULL,
+                                       transfer_info->transfer_id);
+               } else {
+                       /*PUT Request */
+                       _bt_add_recv_transfer_status_data(transfer_info->device_name,
+                                       transfer_info->address, transfer_info->filename, NULL,
+                                       file_size, BT_TR_ONGOING, rcv_noti_info->db_sid);
+                       rcv_noti_info->id = _bt_share_get_unique_id(BT_DB_INBOUND,
+                                       rcv_noti_info->db_sid);
+                       _bt_update_transfer_list_view(BT_INBOUND_TABLE);
+
+                       _bt_set_notification_app_launch(data->noti_handle,
+                                       transfer_info->device_name, transfer_info->address,
+                                       rcv_noti_info->db_sid, CREATE_PROGRESS,
+                                       NOTI_TR_TYPE_IN, transfer_info->filename,
+                                       transfer_info->file_size, NULL,
+                                       transfer_info->transfer_id);
+               }
 
-                       bt_receive_noti_list = g_slist_append(bt_receive_noti_list, data);
+               char *tmp = BT_STR_RECEIVING_FILES_FROM;
+
+#ifdef ENABLE_CONTACTS_SERVICE2
+{
+               int contact_id = -1;
+
+               if (transfer_info->contact_auth_info) {
+                       unsigned char auth_info_null[5];
+                       memset(auth_info_null, 0X0, 5);
+                       if (memcmp(transfer_info->contact_auth_info, auth_info_null, 5)) {
+                               _bt_util_get_contact_info(transfer_info->contact_auth_info, &contact_id, &contact_name);
+                               DBG_SECURE("contact_id: %d | contact_name: [%s]", contact_id, contact_name);
+                       }
                }
+               char *receiving_files = g_strdup_printf(tmp,
+                                       contact_name ? contact_name : transfer_info->device_name);
+}
+#else
+               char *receiving_files = g_strdup_printf(tmp, transfer_info->device_name);
+#endif
+
+               INFO("Notification data: %p", data);
+               if (data) {
+                       _bt_update_notification(ad, data->noti_handle,
+                               transfer_info->filename, receiving_files, NULL, opc_cnt);
+                       _bt_update_notification_progress(data->noti_handle,
+                                       data->noti_id, 0);
+               }
+
                _bt_set_transfer_indicator(TRUE);
                _bt_share_block_sleep(TRUE);
+               g_free(opc_cnt);
+               g_free(contact_name);
                break;
+       }
 
-       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
+       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS: {
                if (param->result == BLUETOOTH_ERROR_NONE) {
                        transfer_info = param->param_data;
-
                        data = __bt_get_noti_data_by_transfer_id(
                                                transfer_info->transfer_id);
-                       if (data == NULL) {
-                               DBG("Data is NULL, returning");
-                               return;
-                       }
+                       retm_if(data == NULL, "Data is NULL, returning");
 
-                       if (isFirstReceivedPacket)
-                               _bt_update_notification(ad, data->noti_handle, transfer_info->filename, "", NULL);
                        if (data && data->noti_id)
                                _bt_update_notification_progress(
                                                data->noti_handle,
@@ -587,38 +1147,39 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                        else
                                DBG("noti_id is not exist!");
                }
-               isFirstReceivedPacket = FALSE;
                break;
+       }
 
-       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
+       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED: {
                INFO("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
-               char mime_type[BT_MIME_TYPE_MAX_LEN] = { 0 };
+               char mime_type[BT_MIME_TYPE_MAX_LEN] = {0, };
                unsigned int file_size = 0;
                struct stat file_attr;
                char *file_path = NULL;
                transfer_info = param->param_data;
                _bt_set_transfer_indicator(FALSE);
                _bt_share_block_sleep(FALSE);
-               isFirstReceivedPacket = FALSE;
 
                data = __bt_get_noti_data_by_transfer_id(transfer_info->transfer_id);
 
-               if (data) {
-                       _bt_delete_notification(data->noti_handle);
-                       bt_receive_noti_list = g_slist_remove(bt_receive_noti_list, data);
-                       g_free(data);
-               }
-
-               if (0 == g_strcmp0(transfer_info->type, TRANSFER_PUT)) {
+               if (g_strcmp0(transfer_info->type, TRANSFER_PUT) == 0) {
                        INFO("TRANSFER_PUT");
 
                        file_path = __get_dest_file_path(transfer_info->file_path);
-                       DBG("Filename : %s", transfer_info->filename);
-                       DBG("File Path : %s", transfer_info->file_path);
+                       DBG_SECURE("Filename[%s] FilePath[%s] Address[%s]",
+                                       transfer_info->filename, file_path,
+                                       transfer_info->address);
+
+                       bt_device_rcv_noti_info_t *rcv_noti_info =
+                               __bt_get_rcv_noti_data_by_device_address(transfer_info->address);
+
+                       if (rcv_noti_info == NULL)
+                               break;
 
                        if (aul_get_mime_from_file(file_path, mime_type,
                                        BT_MIME_TYPE_MAX_LEN) == AUL_R_OK)
-                               DBG("mime type : %s", mime_type);
+                               DBG_SECURE("mime type : %s", mime_type);
+
                        if (g_utf8_validate(file_path, -1, NULL)) {
                                if (stat(file_path, &file_attr) == 0)
                                        file_size = file_attr.st_size;
@@ -626,37 +1187,39 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                                        file_size = 0;
                        }
 
+                       g_free(file_path);
+
+                       if (rcv_noti_info->recv_data.tr_success == -1 &&
+                                       rcv_noti_info->recv_data.tr_fail == -1) {
+                               rcv_noti_info->recv_data.tr_success = 0;
+                               rcv_noti_info->recv_data.tr_fail = 0;
+                       }
+
                        if (param->result != BLUETOOTH_ERROR_NONE) {
-                               ad->recv_data.tr_fail++;
-                               _bt_add_recv_transfer_status_data(
-                                                       transfer_info->device_name,
-                                                       transfer_info->filename,
-                                                       mime_type, file_size,
-                                                       BT_TR_FAIL);
+                               rcv_noti_info->recv_data.tr_fail++;
+                               _bt_update_recv_data_status(rcv_noti_info->id,
+                                                       BT_TR_FAIL, rcv_noti_info->db_sid,
+                                                       file_size, mime_type);
                        } else {
-                               ad->recv_data.tr_success++;
-                               _bt_add_recv_transfer_status_data(
-                                                       transfer_info->device_name,
-                                                       file_path,
-                                                       mime_type, file_size,
-                                                       BT_TR_SUCCESS);
+                               rcv_noti_info->recv_data.tr_success++;
+                               _bt_update_recv_data_status(rcv_noti_info->id,
+                                                       BT_TR_SUCCESS, rcv_noti_info->db_sid,
+                                                       file_size, mime_type);
+                               if (data)
+                                       _bt_update_notification_progress(data->noti_handle,
+                                                       data->noti_id, 100);
                        }
 
-                       _bt_update_transfer_list_view("inbound");
+                       _bt_update_transfer_list_view(BT_INBOUND_TABLE);
 
-                       if (ad->receive_noti == NULL) {
-                               ad->receive_noti = _bt_insert_notification(ad, BT_RECEIVED_NOTI, 0, 0);
-                       } else {
-                               _bt_update_notification(ad, ad->receive_noti, NULL, NULL, NULL);
-                       }
-               } else if (0 == g_strcmp0(transfer_info->type, TRANSFER_GET)) {
+               } else if (g_strcmp0(transfer_info->type, TRANSFER_GET) == 0) {
                        INFO("TRANSFER_GET");
                }
 
                if (param->result == BLUETOOTH_ERROR_NONE) {
-                       bt_file_type_t file_type;
-                       char *extn;
-                       bt_file_info_t *info;
+                       bt_file_type_e file_type;
+                       char *extn = NULL;
+                       bt_file_info_t *info = NULL;
 
                        transfer_info = param->param_data;
                        if (transfer_info->file_path == NULL) {
@@ -672,7 +1235,7 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                        name = __get_dest_file_path(transfer_info->file_path);
 
                        extn = strrchr(name, '.');
-                       if (NULL != extn)
+                       if (extn != NULL)
                                extn++;
                        file_type = __get_file_type(extn);
 
@@ -690,30 +1253,103 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
                        info->file_path = name;
                        info->file_type = file_type;
 
-                       if (pthread_create(&thread_id, NULL, (void *)&_bt_obex_writeclose,
+                       if (pthread_create(&thread_id, NULL, (void *)&__bt_obex_writeclose,
                                                        info) < 0) {
                                ERR("pthread_create() is failed");
                                __free_file_info(info);
                                break;
                        }
-                       if (pthread_detach(thread_id) < 0) {
-                               ERR("pthread_detach() is failed");
-                       }
+                       warn_if(pthread_detach(thread_id) < 0, "pthread_detach() is failed");
+
                } else {
                        DBG("param->result = %d", param->result);
                        DBG("opp_transfer_abort by user %d ", ad->opp_transfer_abort);
+
                        if (!ad->opp_transfer_abort)
                                _bt_create_warning_popup(param->result,
                                        BT_STR_UNABLE_TO_RECEIVE);
+
                        ad->opp_transfer_abort = FALSE;
                }
                break;
+       }
 
-       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED:
+       case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED: {
                INFO("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED");
+               transfer_info = param->param_data;
+
+               char *address = transfer_info->address;
+               int transfer_id = transfer_info->transfer_id;
+               int ret;
+
+               DBG_SECURE("OBEX Disconnected from: %s, transfer_id: %d", address, transfer_id);
+
                if (param->result == BLUETOOTH_ERROR_NONE)
                        isTransferConnectedReceived = FALSE;
+
+               /* P150828-03206 : OPP connection is disconnected without completed event
+               in this case, noti should be removed in the disconnected event */
+               data = __bt_get_noti_data_by_transfer_id(transfer_id);
+
+               if (data) {
+                       DBG("delete noti in the disconnected event!");
+                       _bt_delete_notification(data->noti_handle);
+                       bt_receive_noti_list = g_slist_remove(bt_receive_noti_list, data);
+                       g_free(data);
+               }
+
+               DBG("Sending signal to bt-share-ui");
+
+               /* Send Disconnect to Share-UI */
+               _bt_send_disconnected_signal(BT_SHARE_ENG_SIGNAL_OPP_SERVER_DISCONNECTED,
+                               BLUETOOTH_ERROR_NONE, address, transfer_id);
+
+               bt_device_rcv_noti_info_t *rcv_noti_info =
+                               __bt_get_rcv_noti_data_by_device_address(address);
+               if (rcv_noti_info == NULL) {
+                       INFO("rcv_noti_info does not exist!");
+                       break;
+               }
+
+               ad->recv_data.tr_success = rcv_noti_info->recv_data.tr_success;
+               ad->recv_data.tr_fail = rcv_noti_info->recv_data.tr_fail;
+               DBG("SUCCESS[%d] Failed[%d]", rcv_noti_info->recv_data.tr_success, rcv_noti_info->recv_data.tr_fail);
+
+               if (rcv_noti_info->recv_data.tr_success == -1 &&
+                               rcv_noti_info->recv_data.tr_fail == -1) {
+                       __bt_free_rcv_notification(rcv_noti_info);
+                       break;
+               }
+               notification_h rcv_noti_info_receive_noti = _bt_insert_notification(ad,
+                               BT_RECEIVED_NOTI, rcv_noti_info->device_name,
+                               rcv_noti_info->address, rcv_noti_info->db_sid);
+               ad->receive_noti = rcv_noti_info_receive_noti;
+               DBG("LAUNCH DATA: Filename [%s] TransferID[%d]",
+                               transfer_info->filename, transfer_info->transfer_id);
+
+               _bt_set_notification_app_launch(rcv_noti_info_receive_noti,
+                               rcv_noti_info->device_name, rcv_noti_info->address,
+                               rcv_noti_info->db_sid, CREATE_TR_LIST,
+                               NOTI_TR_TYPE_IN, transfer_info->filename,
+                               0, NULL, transfer_info->transfer_id);
+               ret = notification_update(rcv_noti_info_receive_noti);
+               warn_if(ret != NOTIFICATION_ERROR_NONE,
+                               "Fail to notification_update [%d]", ret);
+
+               if (rcv_noti_info->recv_data.tr_success != -1) {
+                       if (rcv_noti_info->recv_data.tr_success)
+                               _bt_insert_instant_notification(BT_RECEIVED_NOTI);
+                       else
+                               _bt_insert_instant_notification(BT_RECEIVED_FAILED_NOTI);
+
+                       /* Update Database with Notification ID*/
+                       __bt_update_db_with_noti_id(BT_DB_INBOUND, rcv_noti_info_receive_noti,
+                                       rcv_noti_info->db_sid);
+               }
+
+               __bt_free_rcv_notification(rcv_noti_info);
                break;
+       }
 
        default:
                break;
@@ -746,41 +1382,10 @@ void _bt_get_default_storage(char *storage)
                DBG("Can't access the storage");
 }
 
-
-void _bt_app_obex_download_dup_file_cb(void *data, void *obj,
-                                      void *event_info)
-{
-       bt_obex_server_authorize_into_t *server_auth_info = data;
-       char storage[STORAGE_PATH_LEN_MAX] = { 0, };
-       char temp_filename[BT_FILE_PATH_LEN_MAX] = { 0, };
-
-       DBG("response : %d\n", (int)(uintptr_t)event_info);
-
-       if ((int)(uintptr_t)event_info == POPUP_RESPONSE_OK) {
-               DBG("OK button pressed \n");
-
-               _bt_get_default_storage(storage);
-               snprintf(temp_filename, BT_FILE_PATH_LEN_MAX, "%s/%s",
-                                   storage, server_auth_info->filename);
-
-               if (remove(temp_filename) != 0) {
-                       ERR("File remove failed\n");
-                       bluetooth_obex_server_reject_authorize();
-                       return;
-               }
-
-               DBG("temp_filename %s", temp_filename);
-               bluetooth_obex_server_accept_authorize(server_auth_info->filename);
-       } else if ((int)(uintptr_t)event_info == POPUP_RESPONSE_CANCEL) {
-               bluetooth_obex_server_reject_authorize();
-       }
-       return;
-}
-
 static int __bt_get_available_int_memory(double *dAvail)
 {
-       struct statvfs s;
-       int r;
+       struct statvfs s = { 0, };
+       int r = 0;
 
        r = storage_get_internal_memory_size(&s);
        if (r < 0)
@@ -794,21 +1399,24 @@ static int __bt_get_available_int_memory(double *dAvail)
        return r;
 }
 
-static int __bt_get_available_ext_memory(double *dAvail)
+
+static gboolean __bt_get_available_ext_memory(unsigned long long *available_mem_size)
 {
-       struct statvfs s;
+       struct statvfs s = {0, };
        int r;
 
        r = storage_get_internal_memory_size(&s);
-       if (r < 0)
+       if (r < 0) {
                ERR("ret : %d", r);
-       else {
+               *available_mem_size = 0;
+               return FALSE;
+       } else {
                INFO("total : %lf, avail : %lf",
                (double)s.f_frsize*s.f_blocks, (double)s.f_bsize*s.f_bavail);
-               *dAvail = (double)s.f_bsize*s.f_bavail;
+               *available_mem_size = (unsigned long long)s.f_bsize*s.f_bavail;
        }
 
-       return r;
+       return TRUE;
 }
 
 static gchar *__bt_get_unique_file_name(char *storage_path, char *filename)
@@ -816,11 +1424,10 @@ static gchar *__bt_get_unique_file_name(char *storage_path, char *filename)
        char temp_filepath[BT_FILE_PATH_LEN_MAX] = { 0, };
        char temp_filename[BT_TEMP_FILE_PATH_LEN_MAX] = { 0, };
        char *ext = NULL;
-       char *temp;
+       char *temp = NULL;
        unsigned int seq = 1;
 
        temp = strrchr(filename, '.');
-
        if (temp != NULL) {
                ext = temp + 1;
                *temp = '\0';
@@ -844,12 +1451,12 @@ static gchar *__bt_get_unique_file_name(char *storage_path, char *filename)
                        seq++;
                else
                        break;
-
        } while (1);
 
        return g_strdup(temp_filename);
 }
 
+
 static void __bt_app_obex_openwrite_requested(bt_obex_server_authorize_into_t
                                                        *server_auth_info)
 {
@@ -870,6 +1477,7 @@ static void __bt_app_obex_openwrite_requested(bt_obex_server_authorize_into_t
 
        regex = g_regex_new("[*\"<>;?|\\^:/]", 0, 0, NULL);
        name = g_regex_replace(regex, server_auth_info->filename, -1, 0, "_", 0, NULL);
+
        g_regex_unref(regex);
        if (g_strcmp0(name, server_auth_info->filename) != 0) {
                g_free(server_auth_info->filename);
@@ -891,45 +1499,48 @@ static void __bt_app_obex_openwrite_requested(bt_obex_server_authorize_into_t
        }
 
        bluetooth_obex_server_accept_authorize(server_auth_info->filename);
-
-       return;
 }
 
-static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t *server_auth_info)
+static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t
+                                                       *server_auth_info)
 {
-       DBG("+");
+       FN_START;
 
        int val = -1;
-       double available_mem_size = 0;
+       gboolean ret = FALSE;
+       unsigned long long available_ext_mem_size = 0;
+       double available_int_mem_size = 0;
 
        if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
-                               (void *)&val)) {
+                       (void *)&val)) {
                ERR("vconf error");
                goto reject;
        }
 
-       INFO("File Length = %ld", server_auth_info->length);
+       INFO("File Length =%ld", server_auth_info->length);
 
        if (val == BT_DEFAULT_MEM_MMC) {
-               if (__bt_get_available_ext_memory(&available_mem_size) < 0) {
+               ret = __bt_get_available_ext_memory(&available_ext_mem_size);
+               if (ret == FALSE) {
                        ERR("Unable to get available memory size");
                        goto reject;
                }
-               INFO("available_ext_mem_size =%llu", available_mem_size);
-               if (available_mem_size < server_auth_info->length) {
+
+               INFO("available_ext_mem_size =%llu", available_ext_mem_size);
+               if (available_ext_mem_size < server_auth_info->length) {
                        g_timeout_add(BT_APP_POPUP_LAUNCH_TIMEOUT,
                                (GSourceFunc)_bt_app_popup_memoryfull,
                                NULL);
                        goto reject;
                }
        } else {
-               if (__bt_get_available_int_memory(&available_mem_size) < 0) {
+               if (__bt_get_available_int_memory(&available_int_mem_size) < 0) {
                        ERR("Unable to get available memory size");
                        goto reject;
                }
 
-               INFO("available_int_mem_size =%lf", available_mem_size);
-               if (available_mem_size < server_auth_info->length) {
+               INFO("available_int_mem_size =%lf", available_ext_mem_size);
+               if (available_int_mem_size < server_auth_info->length) {
                        g_timeout_add(BT_APP_POPUP_LAUNCH_TIMEOUT,
                                (GSourceFunc)_bt_app_popup_memoryfull,
                                NULL);
@@ -940,33 +1551,29 @@ static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t *server_aut
        DBG("isTransferConnectedReceived is : %d", isTransferConnectedReceived);
 
        if (isTransferConnectedReceived) {
-               if (notification_status_message_post(BT_STR_RECEIVING) != NOTIFICATION_ERROR_NONE)
-                       ERR("notification_status_message_post() is failed");
-                       isTransferConnectedReceived = FALSE;
+               _bt_insert_instant_notification(BT_RECEIVING_NOTI);
+               isTransferConnectedReceived = FALSE;
        }
 
        __bt_app_obex_openwrite_requested(server_auth_info);
 
-       DBG("-");
+       FN_END;
        return;
 
 reject:
        bluetooth_obex_server_reject_authorize();
 
-       DBG("-");
-       return;
+       FN_END;
 }
 
-
 #ifdef ENABLE_CONTACTS_SERVICE2
 static bool __bt_vcard_handler(contacts_record_h record, void *user_data)
 {
-       int ret;
+       int ret = 0;
 
        ret = contacts_db_insert_record(record, NULL);
-       if (ret != CONTACTS_ERROR_NONE) {
-               ERR("contacts_svc_insert_vcard error : %d\n", ret);
-       }
+       warn_if(ret != CONTACTS_ERROR_NONE,
+               "contacts_svc_insert_vcard error : %d", ret);
 
        return true;
 }
@@ -975,28 +1582,28 @@ static bool __bt_vcard_handler(contacts_record_h record, void *user_data)
 #ifdef ENABLE_CALENDAR_SERVICE2
 static bool __bt_vcalendar_handler(calendar_record_h record, void *user_data)
 {
-       int ret;
+       int ret = 0;
 
        ret = calendar_db_insert_record(record, NULL);
-       if (ret != CALENDAR_ERROR_NONE) {
-               ERR("calendar_db_insert_record error : %d\n", ret);
-       }
+       warn_if(ret != CALENDAR_ERROR_NONE,
+               "calendar_db_insert_record error : %d", ret);
 
        return true;
 }
 #endif /* ENABLE_CALENDAR_SERVICE2 */
 
 static gboolean __bt_save_v_object(char *file_path,
-                                           bt_file_type_t file_type)
+                                           bt_file_type_e file_type)
 {
        retv_if(NULL == file_path, FALSE);
 
-       DBG("file_path = %s, file_type = %d\n", file_path, file_type);
+       DBG_SECURE("file_path = %s, file_type = %d", file_path, file_type);
 
        switch (file_type) {
 #ifdef ENABLE_CONTACTS_SERVICE2
-       case BT_FILE_VCARD:
-               ret = contacts_connect2();
+       case BT_FILE_VCARD: {
+               int ret = 0;
+               ret = contacts_connect();
                if (ret != CONTACTS_ERROR_NONE) {
                        ERR("contacts_connect2 error = %d \n", ret);
                        return FALSE;
@@ -1006,45 +1613,43 @@ static gboolean __bt_save_v_object(char *file_path,
                                        __bt_vcard_handler, NULL);
                if (ret != CONTACTS_ERROR_NONE) {
                        ERR("[error] = %d \n", ret);
-                       ret = contacts_disconnect2();
-                       if (ret != CONTACTS_ERROR_NONE) {
+                       ret = contacts_disconnect();
+                       if (ret != CONTACTS_ERROR_NONE)
                                ERR("contacts_disconnect2 error = %d \n", ret);
-                       }
                        return FALSE;
                }
 
-               ret = contacts_disconnect2();
+               ret = contacts_disconnect();
                if (ret != CONTACTS_ERROR_NONE) {
                        ERR("contacts_disconnect2 error = %d \n", ret);
                        return FALSE;
                }
                break;
+       }
 #endif /* ENABLE_CONTACTS_SERVICE2 */
 
 #ifdef ENABLE_CALENDAR_SERVICE2
-       case BT_FILE_VCAL:
+       case BT_FILE_VCAL: {
+               int ret = 0;
+
                ret = calendar_connect();
-               if (ret != CALENDAR_ERROR_NONE) {
-                       ERR("calendar_connect error = %d \n", ret);
-                       return FALSE;
-               }
+               retvm_if(ret != CALENDAR_ERROR_NONE, FALSE,
+                               "calendar_connect error = %d", ret);
 
                ret = calendar_vcalendar_parse_to_calendar_foreach(file_path,
                                        __bt_vcalendar_handler, NULL);
                if (ret != CALENDAR_ERROR_NONE) {
-                       ERR("[error] = %d \n", ret);
+                       ERR("[error] = %d", ret);
                        ret = calendar_disconnect();
-                       if (ret != CALENDAR_ERROR_NONE) {
-                               ERR("calendar_disconnect error = %d \n", ret);
-                       }
+                       warn_if(ret != CALENDAR_ERROR_NONE,
+                               "calendar_disconnect error = %d", ret);
                        return FALSE;
                }
                ret = calendar_disconnect();
-               if (ret != CALENDAR_ERROR_NONE) {
-                       ERR("calendar_disconnect error = %d \n", ret);
-                       return FALSE;
-               }
+               retvm_if(ret != CALENDAR_ERROR_NONE, FALSE,
+                               "calendar_disconnect error = %d", ret);
                break;
+       }
 #endif /* ENABLE_CALENDAR_SERVICE2 */
 
        default:
@@ -1054,28 +1659,7 @@ static gboolean __bt_save_v_object(char *file_path,
        return TRUE;
 }
 
-gboolean __bt_scan_media_file(char *file_path)
-{
-       int ret;
-
-       ret = media_content_connect();
-       if (ret != MEDIA_CONTENT_ERROR_NONE) {
-               DBG("Fail to connect the media content: %d", ret);
-               return FALSE;
-       }
-
-       ret = media_content_scan_file(file_path);
-       if (ret != MEDIA_CONTENT_ERROR_NONE)
-               DBG("Fail to scan file: %d", ret);
-
-       ret = media_content_disconnect();
-       if (ret != MEDIA_CONTENT_ERROR_NONE)
-               DBG("Fail to disconnect the media content: %d", ret);
-
-       return TRUE;
-}
-
-void *_bt_obex_writeclose(bt_file_info_t *info)
+static void *__bt_obex_writeclose(bt_file_info_t *info)
 {
        if (__bt_save_v_object(info->file_path, info->file_type) == FALSE) {
                ERR("Unable to save vObject");
@@ -1088,9 +1672,3 @@ void *_bt_obex_writeclose(bt_file_info_t *info)
        return NULL;
 }
 
-void _bt_free_auth_info(void)
-{
-       g_free(g_server_auth_info.filename);
-       g_server_auth_info.filename = NULL;
-}
-
index ef1557e..731bc23 100644 (file)
@@ -53,13 +53,16 @@ extern "C" {
 #define LOG_TAG "BLUETOOTH_SHARE_DB"
 
 #define INFO(fmt, arg...) \
-               SLOGI(fmt, ##arg)
+       SLOGI(fmt, ##arg)
 
 #define ERR(fmt, arg...) \
-               SLOGE(fmt, ##arg)
+       SLOGE(fmt, ##arg)
 
 #define DBG(fmt, arg...) \
-               SLOGD(fmt, ##arg)
+       SLOGD(fmt, ##arg)
+
+#define        FN_START DBG("[ENTER FUNC]");
+#define        FN_END DBG("[EXIT FUNC]");
 
 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
@@ -70,22 +73,26 @@ extern "C" {
                        ERR(fmt, ##arg); \
                } \
        } while (0)
+
 #define ret_if(expr) do { \
                if (expr) { \
                        return; \
                } \
        } while (0)
+
 #define retv_if(expr, val) do { \
                if (expr) { \
                        return (val); \
                } \
        } while (0)
+
 #define retm_if(expr, fmt, arg...) do { \
                if (expr) { \
                        ERR(fmt, ##arg); \
                        return; \
                } \
        } while (0)
+
 #define retvm_if(expr, val, fmt, arg...) do { \
                if (expr) { \
                        ERR(fmt, ##arg); \
@@ -93,8 +100,8 @@ extern "C" {
                } \
        } while (0)
 
-
 #ifdef __cplusplus
 }
 #endif
 #endif                         /* __APPLOG_H__ */
+
index 3e0201a..f811aa4 100644 (file)
@@ -24,7 +24,7 @@
 extern "C" {
 #endif
 
-#include <sqlite3.h>
+#include <db-util.h>
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
@@ -37,11 +37,22 @@ typedef enum {
        BT_SHARE_ERR_UNKNOWN = -3
 } bt_share_err_e;
 
+typedef enum {
+       BT_TRANSFER_PENDING = -2,
+       BT_TRANSFER_ONGOING = -1,
+       BT_TRANSFER_SUCCESS,
+       BT_TRANSFER_FAIL
+} bt_tr_status_e;
+
+typedef enum {
+       BT_DB_OUTBOUND,
+       BT_DB_INBOUND
+} bt_tr_db_table_e;
 
 typedef struct {
        unsigned int id;
        unsigned int sid;
-       unsigned int tr_status;
+       bt_tr_status_e tr_status;
        int timestamp;
        char *file_path;
        char *dev_name;
@@ -49,45 +60,92 @@ typedef struct {
        char *type;
        char *content;
        unsigned int size;
+       char *db_sid;
 } bt_tr_data_t;
 
-
-typedef enum {
-       BT_DB_OUTBOUND,
-       BT_DB_INBOUND
-} bt_tr_db_table_e;
-
-
 EXPORT_API sqlite3 *bt_share_open_db(void);
 
 EXPORT_API int bt_share_close_db(sqlite3 *db);
 
-EXPORT_API int bt_share_add_tr_data(sqlite3 *db, int db_table, bt_tr_data_t *data);
+EXPORT_API int bt_share_add_tr_data(sqlite3 *db, int db_table,
+               bt_tr_data_t *data);
+
+EXPORT_API int bt_share_update_tr_data(sqlite3 *db, int db_table,
+               int id, bt_tr_data_t *data);
 
-EXPORT_API int bt_share_update_tr_data(sqlite3 *db, int db_table, int id, bt_tr_data_t *data);
+EXPORT_API int bt_share_update_multiple_tr_data(sqlite3 *db, int db_table,
+               int *ids, int ids_cnt, bt_tr_data_t *data);
 
-EXPORT_API bt_tr_data_t *bt_share_get_tr_data(sqlite3 *db, int db_table, int id);
+EXPORT_API bt_tr_data_t *bt_share_get_tr_data(sqlite3 *db, int db_table,
+               int id);
 
 EXPORT_API GSList *bt_share_get_all_tr_data_list(sqlite3 *db, int db_table);
 
-EXPORT_API GSList *bt_share_get_completed_tr_data_list(sqlite3 *db, int db_table);
+EXPORT_API GSList *bt_share_get_completed_tr_data_list(sqlite3 *db,
+               int db_table, const char *db_sid);
 
-EXPORT_API GSList *bt_share_get_tr_data_list_by_status(sqlite3 *db, int db_table, int status);
+EXPORT_API GSList *bt_share_get_completed_tr_data_by_device(sqlite3 *db,
+               int db_table, const char *address);
 
-EXPORT_API unsigned int bt_share_get_last_session_id(sqlite3 *db, int db_table);
+EXPORT_API GSList *bt_share_get_completed_tr_data_by_sid(sqlite3 *db,
+               int db_table, const char *address, const char *sid);
+
+EXPORT_API GSList *bt_share_get_all_tr_data_by_sid(sqlite3 *db, int db_table,
+               const char *address, const char *sid);
+
+EXPORT_API GSList *bt_share_get_failed_tr_data_by_sid(sqlite3 *db,
+               int db_table, const char *address, const char *sid);
+
+EXPORT_API GSList *bt_share_get_pending_tr_data_by_sid(sqlite3 *db,
+               int db_table, const char *address, const char *sid);
+
+EXPORT_API GSList *bt_share_get_tr_data_list_by_status(sqlite3 *db,
+               int db_table, int status);
+
+EXPORT_API unsigned int bt_share_get_last_session_id(sqlite3 *db,
+               int db_table);
 
 EXPORT_API int bt_share_release_tr_data_list(GSList *list);
 
 EXPORT_API int bt_share_get_tr_data_count(sqlite3 *db, int db_table);
 
-EXPORT_API int bt_share_remove_tr_data_by_id(sqlite3 *db, int db_table, int id);
+EXPORT_API int bt_share_get_tr_result_count(sqlite3 *db, int db_table,
+               int *success, int *fail);
+
+EXPORT_API int bt_share_remove_tr_data_by_id(sqlite3 *db, int db_table,
+               int id);
+
+EXPORT_API int bt_share_remove_tr_data_by_status(sqlite3 *db,
+               int db_table, int status);
 
-EXPORT_API int bt_share_remove_tr_data_by_status(sqlite3 *db, int db_table, int status);
+EXPORT_API int bt_share_remove_tr_data_by_notification(sqlite3 *db,
+               int db_table, int noti_id);
 
-EXPORT_API int bt_share_remove_tr_data_by_notification(sqlite3 *db, int db_table);
+EXPORT_API int bt_share_remove_tr_data_non_pending(sqlite3 *db,
+               int db_table);
 
 EXPORT_API int bt_share_remove_all_tr_data(sqlite3 *db, int db_table);
 
+EXPORT_API int bt_share_update_noti_id(sqlite3 *db, int db_table,
+               int noti_id, const char *db_sid);
+
+EXPORT_API int bt_share_get_noti_id(sqlite3 *db, int db_table,
+               const char *db_sid);
+
+EXPORT_API int bt_share_check_noti_id(sqlite3 *db, int db_table,
+               int notification_id);
+
+EXPORT_API int bt_share_get_unique_id(sqlite3 *db, int db_table,
+               const char *db_sid);
+
+EXPORT_API GSList *bt_share_get_noti_list(sqlite3 *db, int db_table);
+
+EXPORT_API int bt_share_release_noti_list(GSList *slist);
+
+EXPORT_API GSList *bt_share_get_all_temporary_files_by_noti_id(sqlite3 *db,
+               int noti_id, char *path);
+
+EXPORT_API int bt_share_release_temporary_file_list(GSList *file_list);
 
 #ifdef __cplusplus
 }
index a24dee2..691db91 100644 (file)
@@ -7,6 +7,6 @@ Name: bluetooth-share-api
 Description: SAMSUNG Linux platform Bluetooth share API
 Version: @VERSION@
 Requires.private: dlog vconf
-Requires: dbus-glib-1 sqlite3
+Requires: gio-2.0 dbus-glib-1 db-util
 Libs: -L${libdir} -lbluetooth-share-api
 Cflags: -I${includedir} -I${includedir}/bluetooth-share-api
index 5753af7..fa6efcf 100644 (file)
 
 static int __bt_exec_query(sqlite3 *db, char *query)
 {
-       int ret;
-       char *errmsg = NULL;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(query == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+
+       int ret = SQLITE_OK;
+       sqlite3_stmt *stmt = NULL;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       retv_if(ret != SQLITE_OK, BT_SHARE_ERR_INTERNAL);
+
+       ret = sqlite3_step(stmt);
+       retv_if(ret != SQLITE_DONE, BT_SHARE_ERR_INTERNAL);
+
+       sqlite3_finalize(stmt);
+       return BT_SHARE_ERR_NONE;
+}
 
+static int __bt_exec_query_multiple(sqlite3 *db, char *query, int *ids, int ids_cnt)
+{
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
        retvm_if(query == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+       retvm_if(ids == NULL, BT_SHARE_ERR_INTERNAL, "Tr ids are NULL");
 
-       ret = sqlite3_exec(db, query, NULL, 0, &errmsg);
-       if (ret != SQLITE_OK) {
-               DBG("Query: [%s]", query);
-               ERR("SQL error: %s\n", errmsg);
-               sqlite3_free(errmsg);
-               return BT_SHARE_ERR_INTERNAL;
+       int ret = SQLITE_OK;
+       int i;
+       sqlite3_stmt *stmt = NULL;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       retv_if(ret != SQLITE_OK, BT_SHARE_ERR_INTERNAL);
+
+       for (i = 0; i < ids_cnt; i++) {
+               ret = sqlite3_bind_int(stmt, 1, ids[i]);
+               if (ret != SQLITE_OK) {
+                       sqlite3_finalize(stmt);
+                       ERR("sqlite3_bind_int failed for id %d",  ids[i]);
+                       return BT_SHARE_ERR_INTERNAL;
+               }
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       sqlite3_finalize(stmt);
+                       ERR("sqlite3_step failed for id %d",  ids[i]);
+                       return BT_SHARE_ERR_INTERNAL;
+               }
+
+               ret = sqlite3_reset(stmt);
+               if (ret != SQLITE_OK) {
+                       sqlite3_finalize(stmt);
+                       ERR("sqlite3_reset failed for id %d",  ids[i]);
+                       return BT_SHARE_ERR_INTERNAL;
+               }
        }
 
+       sqlite3_finalize(stmt);
        return BT_SHARE_ERR_NONE;
 }
 
-sqlite3 *__bt_db_open(void)
+
+static sqlite3 *__bt_db_open(void)
 {
-       int ret;
+       int ret = SQLITE_OK;
        sqlite3 *db = NULL;
 
        ret = db_util_open(BT_TRANSFER_DB, &db, DB_UTIL_REGISTER_HOOK_METHOD);
@@ -69,41 +109,44 @@ sqlite3 *__bt_db_open(void)
        return db;
 }
 
+
 static int __bt_db_close(sqlite3 *db)
 {
        retv_if(db == NULL, BT_SHARE_ERR_INVALID_PARAM);
-
        db_util_close(db);
-       db = NULL;
-
        return BT_SHARE_ERR_NONE;
 }
 
 static int __bt_db_begin_transaction(sqlite3 *db)
 {
-       return __bt_exec_query(db, "BEGIN  TRANSACTION");
+       return __bt_exec_query(db, "BEGIN TRANSACTION");
 }
 
 static int __bt_db_end_transaction(sqlite3 *db)
 {
-       return __bt_exec_query(db, "COMMIT  TRANSACTION");
+       return __bt_exec_query(db, "COMMIT TRANSACTION");
 }
 
 static int __bt_db_insert_record(sqlite3 *db, int db_table, bt_tr_data_t *data)
 {
-       DBG("+\n");
-       int ret = 0;
-       char query[BT_DB_QUERY_LEN] = {0, };
-       sqlite3_stmt *stmt = NULL;
-
+       FN_START;
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
        retvm_if(data == NULL, BT_SHARE_ERR_INTERNAL, "Insert data is null");
 
-       snprintf(query, BT_DB_QUERY_LEN,
-               "INSERT INTO %s (id, sid, tr_status, file_path, dev_name, timestamp, addr, type, content, size) VALUES(?, '%d', '%d', '%s', '%s', '%d', '%s', '%s', '%s', '%d');",
+       int ret = SQLITE_OK;
+       char *query = NULL;
+       sqlite3_stmt *stmt = NULL;
+
+       DBG("File: %s Type: %s, Size: %d", data->file_path, data->type, data->size);
+       query = sqlite3_mprintf("INSERT INTO %s (id, sid, tr_status, file_path, "
+                       "dev_name, timestamp, addr, type, content, size, db_sid) VALUES(?, "
+                       "'%d', '%d', '%q', '%q', '%d', '%q', '%q', '%q', '%d', '%s');",
                TABLE(db_table), data->sid, data->tr_status, data->file_path,
-               data->dev_name, data->timestamp, data->addr, data->type, data->content, data->size);
+               data->dev_name, data->timestamp, data->addr, data->type, data->file_path,
+               data->size, data->db_sid);
+       retv_if(!query, BT_SHARE_ERR_INTERNAL);
 
+       DBG("query : %s", query);
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK)
                goto error;
@@ -113,54 +156,96 @@ static int __bt_db_insert_record(sqlite3 *db, int db_table, bt_tr_data_t *data)
                goto error;
 
        sqlite3_finalize(stmt);
+       sqlite3_free(query);
 
-       DBG("-\n");
+       FN_END;
        return BT_SHARE_ERR_NONE;
 
 error:
        ERR("[ERROR] szQuery : %s", query);
        ERR("[ERROR] SQL error msg : %s", (char *)sqlite3_errmsg(db));
-       if (stmt) {
+       if (stmt)
                sqlite3_finalize(stmt);
-       }
 
+       if (query)
+               sqlite3_free(query);
        return BT_SHARE_ERR_INTERNAL;
 }
 
 static int __bt_db_update_record(sqlite3 *db, int db_table, int id, bt_tr_data_t *data)
 {
-       DBG("+\n");
-       int ret = 0;
-       char query[BT_DB_QUERY_LEN] = {0, };
-
+       FN_START;
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
        retvm_if(data == NULL, BT_SHARE_ERR_INTERNAL, "Insert data is null");
 
-       snprintf(query, BT_DB_QUERY_LEN,
-               "UPDATE %s SET tr_status=%d, timestamp='%d' WHERE id=%d;",
-               TABLE(db_table), data->tr_status, data->timestamp, id);
+       int ret = SQLITE_OK;
+       char query[BT_DB_QUERY_LEN] = {0, };
+
+       if (db_table == BT_DB_INBOUND) {
+               snprintf(query, BT_DB_QUERY_LEN,
+                       "UPDATE %s SET tr_status=%d, timestamp='%d', db_sid='%s', "
+                       "type='%s', size=%d WHERE id=%d;", TABLE(db_table),
+                       data->tr_status, data->timestamp, data->db_sid,
+                       data->type, data->size, id);
+       } else {
+               snprintf(query, BT_DB_QUERY_LEN, "UPDATE %s SET tr_status=%d, "
+                               "timestamp='%d', db_sid='%s' WHERE id=%d;",     TABLE(db_table),
+                               data->tr_status, data->timestamp, data->db_sid, id);
+       }
 
        __bt_db_begin_transaction(db);
        ret = __bt_exec_query(db, query);
-       if (ret != BT_SHARE_ERR_NONE) {
-               return BT_SHARE_ERR_INTERNAL;
+       retv_if(ret != BT_SHARE_ERR_NONE, BT_SHARE_ERR_INTERNAL);
+       __bt_db_end_transaction(db);
+
+       FN_END;
+       return BT_SHARE_ERR_NONE;
+}
+
+static int __bt_db_update_multiple_record(sqlite3 *db, int db_table, int *ids, int ids_cnt,
+                                               bt_tr_data_t *data)
+{
+       FN_START;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(data == NULL, BT_SHARE_ERR_INTERNAL, "Insert data is null");
+       retvm_if(ids == NULL, BT_SHARE_ERR_INTERNAL, "Tr ids are NULL");
+
+       int ret = SQLITE_OK;
+       char query[BT_DB_QUERY_LEN] = {0, };
+
+       if (db_table == BT_DB_INBOUND) {
+               snprintf(query, BT_DB_QUERY_LEN,
+                       "UPDATE %s SET tr_status=%d, timestamp='%d', db_sid='%s', "
+                       "type='%s', size=%d WHERE id=?;", TABLE(db_table),
+                       data->tr_status, data->timestamp, data->db_sid,
+                       data->type, data->size);
+       } else {
+               snprintf(query, BT_DB_QUERY_LEN, "UPDATE %s SET tr_status=%d, "
+                               "timestamp='%d', db_sid='%s' WHERE id=?;", TABLE(db_table),
+                               data->tr_status, data->timestamp, data->db_sid);
        }
+
+       __bt_db_begin_transaction(db);
+       ret = __bt_exec_query_multiple(db, query, ids, ids_cnt);
+       retv_if(ret != BT_SHARE_ERR_NONE, BT_SHARE_ERR_INTERNAL);
        __bt_db_end_transaction(db);
 
+       FN_END;
        return BT_SHARE_ERR_NONE;
 }
 
-static bt_tr_data_t *__bt_db_get_record_by_id(sqlite3 *db, int db_table, int id)
+static bt_tr_data_t *__bt_db_get_record_by_id(sqlite3 *db, int db_table,
+               int id)
 {
-       DBG("+\n");
-       int ret = 0;
+       FN_START;
+       retvm_if(db == NULL, NULL, "DB handler is null");
+
+       int ret = SQLITE_OK;
+       int idx = 0;
        char query[BT_DB_QUERY_LEN] = {0, };
        sqlite3_stmt *stmt = NULL;
-       int idx = 0;
        bt_tr_data_t *data = NULL;
 
-       retvm_if(db == NULL, NULL, "DB handler is null");
-
        snprintf(query, BT_DB_QUERY_LEN,
                "SELECT * FROM %s WHERE id=%d;", TABLE(db_table), id);
 
@@ -169,49 +254,45 @@ static bt_tr_data_t *__bt_db_get_record_by_id(sqlite3 *db, int db_table, int id)
                goto error;
 
        ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW) {
-               data = g_new0(bt_tr_data_t, 1);
-               data->id = INT(stmt, idx++);
-               data->sid = INT(stmt, idx++);
-               data->tr_status = INT(stmt, idx++);
-               data->file_path = g_strdup(TEXT(stmt, idx++));
-               data->dev_name = g_strdup(TEXT(stmt, idx++));
-               data->timestamp = INT(stmt, idx++);
-               data->addr = g_strdup(TEXT(stmt, idx++));
-               data->type = g_strdup(TEXT(stmt, idx++));
-               data->content = g_strdup(TEXT(stmt, idx++));
-               data->size = INT(stmt, idx++);
-       } else {
+       if (ret != SQLITE_ROW)
                goto error;
-       }
 
-       DBG("%d, %d, %s, %s, %d, %s, %d\n", data->sid, data->tr_status, data->file_path,
-                       data->dev_name, data->timestamp, data->addr, data->size);
+       data = g_new0(bt_tr_data_t, 1);
+       data->id = INT(stmt, idx++);
+       data->sid = INT(stmt, idx++);
+       data->tr_status = INT(stmt, idx++);
+       data->file_path = g_strdup(TEXT(stmt, idx++));
+       data->dev_name = g_strdup(TEXT(stmt, idx++));
+       data->timestamp = INT(stmt, idx++);
+       data->addr = g_strdup(TEXT(stmt, idx++));
+       data->type = g_strdup(TEXT(stmt, idx++));
+       data->content = g_strdup(TEXT(stmt, idx++));
+
+       DBG_SECURE("%d, %d, %s, %s, %d, %s, %d\n", data->sid, data->tr_status,
+                       data->file_path, data->dev_name, data->timestamp, data->addr,
+                       data->size);
 
        sqlite3_finalize(stmt);
-
-       DBG("-\n");
+       FN_END;
        return data;
 
 error:
        ERR("[ERROR] szQuery : %s", query);
        ERR("[ERROR] SQL error msg : %s", (char *)sqlite3_errmsg(db));
-       if (stmt) {
+       if (stmt)
                sqlite3_finalize(stmt);
-       }
+
        return NULL;
 }
 
-
-static GSList *__bt_db_get_record_list(sqlite3 *db, const char*query)
+static GSList *__bt_db_get_record_list(sqlite3 *db, const char *query)
 {
-       int ret;
-       sqlite3_stmt *stmt = NULL;
+       retvm_if(db == NULL, NULL, "DB handler is null");
+       int ret = SQLITE_OK;
        int idx = 0;
+       sqlite3_stmt *stmt = NULL;
        GSList *slist = NULL;
 
-       retvm_if(db == NULL, NULL, "DB handler is null");
-
        ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
        if (ret != SQLITE_OK  || stmt == NULL) {
                ERR("SQL error\n");
@@ -233,27 +314,25 @@ static GSList *__bt_db_get_record_list(sqlite3 *db, const char*query)
                data->type = g_strdup(TEXT(stmt, idx++));
                data->content = g_strdup(TEXT(stmt, idx++));
                data->size = INT(stmt, idx++);
-
+               data->db_sid = g_strdup(TEXT(stmt, idx++));
                slist = g_slist_append(slist, data);
-
                ret = sqlite3_step(stmt);
        }
 
        sqlite3_finalize(stmt);
-
        return slist;
 }
 
 static unsigned int __bt_db_get_last_session_id(sqlite3 *db, int db_table)
 {
-       DBG("+\n");
-       int ret = 0;
+       FN_START;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+
+       int ret = SQLITE_OK;
        unsigned int sid = 0;
        char query[BT_DB_QUERY_LEN] = {0, };
        sqlite3_stmt *stmt = NULL;
 
-       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
-
        snprintf(query, BT_DB_QUERY_LEN,
                "SELECT * FROM %s WHERE id=(SELECT MAX(id) FROM %s);",
                TABLE(db_table), TABLE(db_table));
@@ -263,21 +342,21 @@ static unsigned int __bt_db_get_last_session_id(sqlite3 *db, int db_table)
                goto error;
 
        ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW)
-               sid = INT(stmt, 1);  /* to get the session id */
-       else
+       if (ret != SQLITE_ROW)
                goto error;
 
-       sqlite3_finalize(stmt);
+       sid = INT(stmt, 1);  /* to get the session id */
+       DBG("session_id : %u", sid);
 
-       DBG("-\n");
+       sqlite3_finalize(stmt);
+       FN_END;
        return sid;
+
 error:
        ERR("[ERROR] szQuery : %s", query);
        ERR("[ERROR] SQL error msg : %s", (char *)sqlite3_errmsg(db));
-       if (stmt) {
+       if (stmt)
                sqlite3_finalize(stmt);
-       }
 
        return 0;
 }
@@ -295,6 +374,19 @@ static void __bt_release_memory(bt_tr_data_t *data)
        g_free(data);
 }
 
+static void __bt_release_noti_id(void *noti_id)
+{
+       retm_if(noti_id == NULL, "Invalid data");
+       DBG("Releasing memory for %d", *(int *)noti_id);
+       g_free((int *)noti_id);
+}
+
+static void __bt_release_file_list(void *file)
+{
+       retm_if(file == NULL, "Invalid data");
+       DBG("Releasing file: [%s]", (char *)file);
+       g_free((char *)file);
+}
 
 static int __bt_db_release_record_list(GSList *list)
 {
@@ -306,15 +398,16 @@ static int __bt_db_release_record_list(GSList *list)
        return BT_SHARE_ERR_NONE;
 }
 
-static int __bt_db_get_record_count(sqlite3 *db, int db_table)
+static int __bt_db_get_record_count(sqlite3 *db, const char *query)
 {
-       char query[BT_DB_QUERY_LEN] = {0, };
-       sqlite3_stmt *stmt;
-       int idx;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(query == NULL, BT_SHARE_ERR_INTERNAL, "query is null");
+       int ret = SQLITE_OK;
+       int idx = 0;
        int count = 0;
-       int ret = 0;
+       sqlite3_stmt *stmt = NULL;
 
-       snprintf(query, sizeof(query), "SELECT COUNT(id) FROM %s;", TABLE(db_table));
+       DBG("query : %s", query);
 
        ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
        if (ret != SQLITE_OK  || stmt == NULL) {
@@ -333,24 +426,23 @@ static int __bt_db_get_record_count(sqlite3 *db, int db_table)
        }
 
        sqlite3_finalize(stmt);
-
        DBG("Record count : %d\n", count);
-
        return count;
 }
 
 static int __bt_db_delete_record(sqlite3 *db, const char *query)
 {
-       int ret = 0;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(query == NULL, BT_SHARE_ERR_INTERNAL, "query is null");
+
+       int ret = SQLITE_OK;
        sqlite3_stmt *stmt = NULL;
 
-       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       DBG("query : %s", query);
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               ERR("sqlite3_prepare_v2(%s) Failed(%s)", query, sqlite3_errmsg(db));
-               return BT_SHARE_ERR_INTERNAL;
-       }
+       retvm_if(ret != SQLITE_OK, BT_SHARE_ERR_INTERNAL,
+                       "sqlite3_prepare_v2(%s) Failed(%s)", query, sqlite3_errmsg(db));
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_DONE) {
@@ -369,8 +461,7 @@ EXPORT_API sqlite3 *bt_share_open_db(void)
        sqlite3 *db = NULL;
 
        db = __bt_db_open();
-       if (!db)
-               return NULL;
+       retv_if(!db, NULL);
 
        return db;
 }
@@ -382,7 +473,8 @@ EXPORT_API int bt_share_close_db(sqlite3 *db)
        return __bt_db_close(db);
 }
 
-EXPORT_API int bt_share_add_tr_data(sqlite3 *db, int db_table, bt_tr_data_t *data)
+EXPORT_API int bt_share_add_tr_data(sqlite3 *db, int db_table,
+               bt_tr_data_t *data)
 {
        retvm_if(data == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
@@ -390,7 +482,8 @@ EXPORT_API int bt_share_add_tr_data(sqlite3 *db, int db_table, bt_tr_data_t *dat
        return __bt_db_insert_record(db, db_table, data);
 }
 
-EXPORT_API int bt_share_update_tr_data(sqlite3 *db, int db_table, int id, bt_tr_data_t *data)
+EXPORT_API int bt_share_update_tr_data(sqlite3 *db, int db_table,
+               int id, bt_tr_data_t *data)
 {
        retvm_if(data == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
@@ -398,7 +491,18 @@ EXPORT_API int bt_share_update_tr_data(sqlite3 *db, int db_table, int id, bt_tr_
        return __bt_db_update_record(db, db_table, id, data);
 }
 
-EXPORT_API bt_tr_data_t *bt_share_get_tr_data(sqlite3 *db, int db_table, int id)
+EXPORT_API int bt_share_update_multiple_tr_data(sqlite3 *db, int db_table,
+               int *ids, int ids_cnt, bt_tr_data_t *data)
+{
+       retvm_if(data == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
+       retvm_if(ids == NULL, BT_SHARE_ERR_INTERNAL, "Tr ids are NULL");
+
+       return __bt_db_update_multiple_record(db, db_table, ids, ids_cnt, data);
+}
+
+EXPORT_API bt_tr_data_t *bt_share_get_tr_data(sqlite3 *db, int db_table,
+               int id)
 {
        retvm_if(db == NULL, NULL, "DB handle is NULL");
 
@@ -417,19 +521,97 @@ EXPORT_API GSList *bt_share_get_all_tr_data_list(sqlite3 *db, int db_table)
        return __bt_db_get_record_list(db, query);
 }
 
-EXPORT_API GSList *bt_share_get_completed_tr_data_list(sqlite3 *db, int db_table)
+EXPORT_API GSList *bt_share_get_completed_tr_data_list(sqlite3 *db,
+               int db_table, const char *db_sid)
 {
        retvm_if(db == NULL, NULL, "DB handle is NULL");
+       retvm_if(db_sid == NULL, NULL, "DB_SID is NULL");
 
        char query[BT_DB_QUERY_LEN] = {0, };
        snprintf(query, sizeof(query),
-                       "SELECT * FROM %s WHERE tr_status != -1 ORDER BY TIMESTAMP DESC;",
-                       TABLE(db_table));
+                       "SELECT * FROM %s WHERE tr_status > -1 AND db_sid = '%s' "
+                       "ORDER BY TIMESTAMP DESC;",
+                       TABLE(db_table), db_sid);
+
+       return __bt_db_get_record_list(db, query);
+}
+
+EXPORT_API GSList *bt_share_get_completed_tr_data_by_device(sqlite3 *db,
+               int db_table, const char *address)
+{
+       retvm_if(db == NULL, NULL, "DB handle is NULL");
+       retvm_if(address == NULL, NULL, "Invalid Address");
+
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s WHERE tr_status > -1 AND addr = '%s' "
+                       "ORDER BY TIMESTAMP DESC;",
+                       TABLE(db_table), address);
+
+       return __bt_db_get_record_list(db, query);
+}
+
+EXPORT_API GSList *bt_share_get_completed_tr_data_by_sid(sqlite3 *db,
+               int db_table, const char *address, const char *sid)
+{
+       retvm_if(db == NULL, NULL, "DB handle is NULL");
+       retvm_if(address == NULL, NULL, "Invalid Address");
+
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s WHERE tr_status > -1 AND addr = '%s' AND "
+                       "db_sid = '%s' ORDER BY TIMESTAMP DESC;",
+                       TABLE(db_table), address, sid);
+
+       return __bt_db_get_record_list(db, query);
+}
+
+EXPORT_API GSList *bt_share_get_all_tr_data_by_sid(sqlite3 *db, int db_table,
+               const char *address, const char *sid)
+{
+       retvm_if(db == NULL, NULL, "DB handle is NULL");
+       retvm_if(address == NULL, NULL, "Invalid Address");
+
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s WHERE addr = '%s' AND db_sid = '%s';",
+                       TABLE(db_table), address, sid);
+
+       return __bt_db_get_record_list(db, query);
+}
+
+EXPORT_API GSList *bt_share_get_failed_tr_data_by_sid(sqlite3 *db,
+               int db_table, const char *address, const char *sid)
+{
+       retvm_if(db == NULL, NULL, "DB handle is NULL");
+       retvm_if(address == NULL, NULL, "Invalid Address");
+
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s WHERE tr_status > 0 AND "
+                       "addr = '%s' AND db_sid = '%s' ORDER BY TIMESTAMP DESC;",
+                       TABLE(db_table), address, sid);
 
        return __bt_db_get_record_list(db, query);
 }
 
-EXPORT_API GSList *bt_share_get_tr_data_list_by_status(sqlite3 *db, int db_table, int status)
+EXPORT_API GSList *bt_share_get_pending_tr_data_by_sid(sqlite3 *db,
+               int db_table, const char *address, const char *db_sid)
+{
+       retvm_if(db == NULL, NULL, "DB handle is NULL");
+       retvm_if(address == NULL, NULL, "Invalid Address");
+
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s WHERE tr_status == -2 AND addr = '%s' AND "
+                       "db_sid = '%s' ORDER BY TIMESTAMP DESC;",
+                       TABLE(db_table), address, db_sid);
+
+       return __bt_db_get_record_list(db, query);
+}
+
+EXPORT_API GSList *bt_share_get_tr_data_list_by_status(sqlite3 *db,
+               int db_table, int status)
 {
        retvm_if(db == NULL, NULL, "DB handle is NULL");
 
@@ -459,7 +641,31 @@ EXPORT_API int bt_share_get_tr_data_count(sqlite3 *db, int db_table)
 {
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
 
-       return __bt_db_get_record_count(db, db_table);
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query), "SELECT COUNT(id) FROM %s;",
+                       TABLE(db_table));
+
+       return __bt_db_get_record_count(db, query);
+}
+
+EXPORT_API int bt_share_get_tr_result_count(sqlite3 *db, int db_table,
+               int *success, int *fail)
+{
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
+       retvm_if(!success || !fail, BT_SHARE_ERR_INVALID_PARAM,
+                       "Invalid parameter");
+
+        char query[BT_DB_QUERY_LEN] = {0, };
+
+        snprintf(query, sizeof(query), "SELECT COUNT(tr_status) FROM %s WHERE "
+                        "tr_status=%d;", TABLE(db_table), BT_TRANSFER_SUCCESS);
+       *success = __bt_db_get_record_count(db, query);
+
+       snprintf(query, sizeof(query), "SELECT COUNT(tr_status) FROM %s WHERE "
+                       "tr_status=%d;", TABLE(db_table), BT_TRANSFER_FAIL);
+       *fail = __bt_db_get_record_count(db, query);
+
+       return BT_SHARE_ERR_NONE;
 }
 
 EXPORT_API int bt_share_remove_tr_data_by_id(sqlite3 *db, int db_table, int id)
@@ -474,7 +680,8 @@ EXPORT_API int bt_share_remove_tr_data_by_id(sqlite3 *db, int db_table, int id)
        return __bt_db_delete_record(db, query);
 }
 
-EXPORT_API int bt_share_remove_tr_data_by_status(sqlite3 *db, int db_table, int status)
+EXPORT_API int bt_share_remove_tr_data_by_status(sqlite3 *db,
+               int db_table, int status)
 {
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
 
@@ -486,13 +693,26 @@ EXPORT_API int bt_share_remove_tr_data_by_status(sqlite3 *db, int db_table, int
        return __bt_db_delete_record(db, query);
 }
 
-EXPORT_API int bt_share_remove_tr_data_by_notification(sqlite3 *db, int db_table)
+EXPORT_API int bt_share_remove_tr_data_non_pending(sqlite3 *db,
+               int db_table)
 {
        retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
 
        char query[BT_DB_QUERY_LEN] = {0, };
-       snprintf(query, sizeof(query),
-                       "DELETE FROM %s WHERE tr_status > -1;", TABLE(db_table));
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE "
+                       "tr_status > -1;", TABLE(db_table));
+
+       return __bt_db_delete_record(db, query);
+}
+
+EXPORT_API int bt_share_remove_tr_data_by_notification(sqlite3 *db,
+               int db_table, int noti_id)
+{
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
+
+       char query[BT_DB_QUERY_LEN] = {0, };
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE "
+                       "noti_id = %d;", TABLE(db_table), noti_id);
 
        return __bt_db_delete_record(db, query);
 }
@@ -508,3 +728,216 @@ EXPORT_API int bt_share_remove_all_tr_data(sqlite3 *db, int db_table)
        return __bt_db_delete_record(db, query);
 }
 
+EXPORT_API int bt_share_update_noti_id(sqlite3 *db, int db_table,
+               int noti_id, const char *db_sid)
+{
+       FN_START;
+       int ret = SQLITE_OK;
+       char query[BT_DB_QUERY_LEN] = {0, };
+
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(db_sid == NULL, BT_SHARE_ERR_INTERNAL, "Insert data is null");
+
+       snprintf(query, BT_DB_QUERY_LEN,
+               "UPDATE %s SET noti_id=%d WHERE db_sid='%s';",
+               TABLE(db_table), noti_id, db_sid);
+
+       __bt_db_begin_transaction(db);
+       ret = __bt_exec_query(db, query);
+       retv_if(ret != BT_SHARE_ERR_NONE, BT_SHARE_ERR_INTERNAL);
+       __bt_db_end_transaction(db);
+       FN_END;
+       return BT_SHARE_ERR_NONE;
+}
+
+EXPORT_API int bt_share_get_noti_id(sqlite3 *db, int db_table,
+               const char *db_sid)
+{
+       FN_START;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(db_sid == NULL, BT_SHARE_ERR_INTERNAL, "db_sid is null");
+
+       int ret = SQLITE_OK;
+       int noti_id = 0;
+       char query[BT_DB_QUERY_LEN] = {0, };
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, BT_DB_QUERY_LEN,
+               "SELECT DISTINCT noti_id from %s where db_sid='%s';",
+               TABLE(db_table), db_sid);
+
+       ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK  || stmt == NULL) {
+               ERR("SQL error\n");
+               sqlite3_finalize(stmt);
+               return BT_SHARE_ERR_INTERNAL;
+       }
+       ret = sqlite3_step(stmt);
+
+       while (ret == SQLITE_ROW) {
+               noti_id = INT(stmt, 0);
+               break;
+       }
+
+       sqlite3_finalize(stmt);
+       FN_END;
+       return noti_id;
+}
+
+EXPORT_API int bt_share_check_noti_id(sqlite3 *db, int db_table,
+               int notification_id)
+{
+       FN_START;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+
+       int ret = SQLITE_OK;
+       int noti_id = -1;
+       char query[BT_DB_QUERY_LEN] = {0, };
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, BT_DB_QUERY_LEN,
+               "SELECT DISTINCT noti_id from %s where noti_id='%d';",
+               TABLE(db_table), notification_id);
+
+       ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK  || stmt == NULL) {
+               ERR("SQL error\n");
+               sqlite3_finalize(stmt);
+               return BT_SHARE_ERR_INTERNAL;
+       }
+       ret = sqlite3_step(stmt);
+       DBG("Returned ROWS");
+       while (ret == SQLITE_ROW) {
+               noti_id = INT(stmt, 0);
+               break;
+       }
+
+       sqlite3_finalize(stmt);
+       FN_END;
+       if (noti_id == notification_id)
+               return BT_SHARE_ERR_NONE;
+       else
+               return BT_SHARE_ERR_UNKNOWN;
+}
+
+EXPORT_API int bt_share_get_unique_id(sqlite3 *db, int db_table,
+               const char *db_sid)
+{
+       FN_START;
+       retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+       retvm_if(db_sid == NULL, BT_SHARE_ERR_INTERNAL, "db_sid is null");
+
+       int ret = SQLITE_OK;
+       int unique_id = 0;
+       char query[BT_DB_QUERY_LEN] = {0, };
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, BT_DB_QUERY_LEN,
+               "SELECT DISTINCT id from %s where db_sid='%s' AND tr_status=-1;",
+               TABLE(db_table), db_sid);
+
+       ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK  || stmt == NULL) {
+               ERR("SQL error\n");
+               sqlite3_finalize(stmt);
+               return BT_SHARE_ERR_INTERNAL;
+       }
+       ret = sqlite3_step(stmt);
+
+       while (ret == SQLITE_ROW) {
+               unique_id = INT(stmt, 0);
+               break;
+       }
+
+       sqlite3_finalize(stmt);
+       FN_END;
+       return unique_id;
+}
+
+EXPORT_API GSList *bt_share_get_noti_list(sqlite3 *db, int db_table)
+{
+       int ret = SQLITE_OK;
+       char query[BT_DB_QUERY_LEN] = {0, };
+       sqlite3_stmt *stmt = NULL;
+       GSList *slist = NULL;
+
+       FN_START;
+       retvm_if(db == NULL, NULL, "DB handler is null");
+
+       snprintf(query, BT_DB_QUERY_LEN, "SELECT DISTINCT noti_id FROM %s",
+               TABLE(db_table));
+
+       ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK  || stmt == NULL) {
+               ERR("SQL error\n");
+               sqlite3_finalize(stmt);
+               return NULL;
+       }
+
+       ret = sqlite3_step(stmt);
+       while (ret == SQLITE_ROW) {
+               int *noti_id = (int *)g_new0(int , 1);
+               *noti_id = INT(stmt, 0);
+               slist = g_slist_prepend(slist, noti_id);
+               ret = sqlite3_step(stmt);
+       }
+
+       slist = g_slist_reverse(slist);
+       sqlite3_finalize(stmt);
+
+       FN_END;
+       return slist;
+}
+
+EXPORT_API int bt_share_release_noti_list(GSList *slist)
+{
+       FN_START;
+       retvm_if(slist == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+
+       g_slist_free_full(slist, __bt_release_noti_id);
+       FN_END;
+       return BT_SHARE_ERR_NONE;
+}
+
+EXPORT_API GSList *bt_share_get_all_temporary_files_by_noti_id(sqlite3 *db,
+               int noti_id, char *path) {
+       int ret = SQLITE_OK;
+       char query[BT_DB_QUERY_LEN] = {0, };
+       sqlite3_stmt *stmt = NULL;
+       GSList *file_list = NULL;
+
+       FN_START;
+       retvm_if(db == NULL, NULL, "DB handler is null");
+
+       snprintf(query, BT_DB_QUERY_LEN, "SELECT file_path FROM " BT_OUTBOUND_TABLE
+                       " WHERE noti_id = %d AND file_path LIKE '%s%%'", noti_id, path);
+
+       ret = sqlite3_prepare(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK  || stmt == NULL) {
+               ERR("SQL error\n");
+               sqlite3_finalize(stmt);
+               return NULL;
+       }
+
+       ret = sqlite3_step(stmt);
+       while (ret == SQLITE_ROW) {
+               char *file_path = g_strdup(TEXT(stmt, 0));
+               file_list = g_slist_prepend(file_list, file_path);
+               ret = sqlite3_step(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+       FN_END;
+       return file_list;
+}
+
+EXPORT_API int bt_share_release_temporary_file_list(GSList *file_list)
+{
+       FN_START;
+       retvm_if(file_list == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+
+       g_slist_free_full(file_list, __bt_release_file_list);
+       FN_END;
+       return BT_SHARE_ERR_NONE;
+}
+
index ade809a..95e295e 100644 (file)
@@ -6,7 +6,7 @@ eval $(tzplatform-get TZ_SYS_DB)
 if [ ! -f $TZ_SYS_DB/.bluetooth_transfer.db ]
 then
        /usr/bin/sqlite3 $TZ_SYS_DB/.bluetooth_transfer.db 'PRAGMA journal_mode = PERSIST;
-        create table if not exists inbound (
+       create table if not exists inbound (
                id INTEGER PRIMARY KEY autoincrement,
                sid INTEGER,
                tr_status INTEGER,
@@ -16,7 +16,9 @@ then
                addr TEXT,
                type TEXT,
                content TEXT,
-               size INTEGER
+               size INTEGER,
+               db_sid TEXT,
+               noti_id INTEGER
        );
        create table if not exists outbound (
                id INTEGER PRIMARY KEY autoincrement,
@@ -28,9 +30,10 @@ then
                addr TEXT,
                type TEXT,
                content TEXT,
-               size INTEGER
-       );
-       '
+               size INTEGER,
+               db_sid TEXT,
+               noti_id INTEGER
+       );      '
 fi
 
 /usr/bin/chown 5001:100 $TZ_SYS_DB/.bluetooth_transfer.db