--- /dev/null
+Jinmin Jung <jinmin@samsung.com>
+DoHyun Pyun <dh79.pyun@samsung.com>
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+ADD_SUBDIRECTORY(lib)
+
+ADD_SUBDIRECTORY(bt-share)
--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
--- /dev/null
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
--- /dev/null
+<manifest>
+ <define>
+ <domain name="bt_share"/>
+ <provide>
+ <label name="bt_share::db"/>
+ </provide>
+ <request>
+ <smack request="dbus" type="w"/>
+ <smack request="system::vconf" type="arwxt"/>
+ <smack request="bt_share::db" type="rw"/>
+ </request>
+ </define>
+ <assign>
+ <filesystem path="/usr/share/dbus-1/services/org.bluetooth.share.service" label="_"/>
+ </assign>
+ <request>
+ <domain name="bt_share"/>
+ </request>
+</manifest>
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(bluetooth-share C)
+
+SET(SRCS src/bt-share-main.c
+src/bt-share-notification.c
+src/bt-share-common.c
+src/obex-event-handler.c
+src/bt-share-syspopup.c
+src/bt-share-ipc.c
+src/bt-share-noti-handler.c
+)
+
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED glib-2.0 bluetooth-api
+ aul dbus-glib-1 appcore-common
+ dlog vconf syspopup-caller pmapi sysman
+ notification calendar-service2 contacts-service2
+ appsvc appcore-efl libprivilege-control
+ capi-content-media-content)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(BINDIR "/usr/bin")
+SET(EXEC_PREFIX "\${prefix}")
+#SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "/usr/include")
+SET(VERSION 1.0)
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"")
+ADD_DEFINITIONS("-DTARGET")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../lib -lbluetooth-share-api)
+
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/org.bluetooth.share.service DESTINATION share/dbus-1/services)
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __APPLOG_H__
+#define __APPLOG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * SYSLOG_INFO(), SYSLOG_ERR(), SYSLOG_DBG() are syslog() wrappers.
+ * PRT_INFO(), PRT_ERR(), PRT_DBG() are fprintf() wrappers.
+ *
+ * If SLP_DEBUG is not defined, SYSLOG_DBG() and PRT_DBG() is ignored.
+ *
+ * IF SLP_SYSLOG_OUT or SLP_DAEMON is defined,
+ * INFO(), ERR(), DBG() are SYSLOG_XXX()
+ * Otherwise,
+ * They are PRT_XXX()
+ *
+ *
+ * warn_if(exrp, fmt, ...)
+ * If expr is true, The fmt string is printed using ERR().
+ *
+ * ret_if(), retv_if(), retm_if(), retvm_if()
+ * If expr is true, current function return.
+ * Postfix 'v' means that it has a return value and
+ * 'm' means that it has output message.
+ *
+ */
+
+#include <stdio.h>
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "BLUETOOTH_SHARE"
+
+#define INFO(fmt, arg...) \
+ SLOGI(fmt, ##arg)
+
+#define ERR(fmt, arg...) \
+ SLOGE(fmt, ##arg)
+
+#define DBG(fmt, arg...) \
+ SLOGD(fmt, ##arg)
+
+#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); \
+ return (val); \
+ } \
+ } while (0)
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __APPLOG_H__ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_COMMON_H_
+#define __DEF_BLUETOOTH_SHARE_COMMON_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+
+/* Define Error type */
+#define BT_SHARE_FAIL -1
+#define BT_SHARE_ERROR_NONE 0
+
+typedef enum {
+ BT_STATUS_OFF = 0x0000,
+ BT_STATUS_ON = 0x0001,
+ BT_STATUS_BT_VISIBLE = 0x0002,
+ BT_STATUS_TRANSFER = 0x0004,
+} bt_status_t;
+
+
+int _bt_share_block_sleep(gboolean is_block);
+int _bt_set_transfer_indicator(gboolean state);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_COMMON_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_IPC_H_
+#define __DEF_BLUETOOTH_SHARE_IPC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.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_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
+#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_FRWK_INTERFACE "User.Bluetooth.FRWK"
+#define BT_SHARE_FRWK_SIGNAL_DEINIT "deinit"
+
+#define BT_IPC_STRING_SIZE 256
+#define BT_ADDR_STR_LEN_MAX 18
+
+#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_ONGOING = -1,
+ BT_TR_SUCCESS,
+ BT_TR_FAIL
+} bt_app_tr_status_t;
+
+typedef struct {
+ int file_cnt;
+ char addr[BLUETOOTH_ADDRESS_LENGTH];
+ char name[BLUETOOTH_DEVICE_NAME_LENGTH_MAX];
+ char *mode;
+ char **file_path;
+} 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 _remove_transfer_info(opc_transfer_info_t *node);
+int _request_file_send(opc_transfer_info_t *node);
+void _bt_send_message_to_ui(int transfer_id,
+ char *name,
+ int percentage,
+ gboolean completed,
+ int error_type);
+void _bt_create_warning_popup(int error_type);
+void _bt_update_transfer_list_view(const char *table);
+
+gboolean _bt_update_sent_data_status(int uid, bt_app_tr_status_t status);
+
+void _bt_rm_all_send_data(void);
+void _bt_rm_all_recv_data(void);
+gboolean _bt_add_recv_transfer_status_data(char *device_name,
+ char *filepath,
+ int status);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_IPC_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_H_
+#define __DEF_BLUETOOTH_SHARE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <notification.h>
+
+#ifndef PACKAGE_NAME
+#define PACKAGE_NAME "bluetooth-share"
+#endif
+
+#define UI_PACKAGE "org.tizen.bluetooth-share-ui"
+#define UI_PKG_PATH "/opt/apps/org.tizen.bluetooth-share-ui/bin/bluetooth-share-ui"
+
+#define BT_VCONF_OPP_SERVER_INIT "memory/private/bluetooth-share/opp_server_init"
+
+typedef void (*bt_app_cb) (void *, void *, void *);
+
+typedef struct {
+ bt_app_cb popup_cb;
+ void *popup_cb_data;
+ gboolean syspopup_request;
+} bt_app_popups_t;
+
+typedef struct {
+ int tr_success;
+ int tr_fail;
+} bt_transfer_status_info_t;
+
+struct bt_appdata {
+ bt_app_popups_t popups;
+ bt_transfer_status_info_t send_data;
+ bt_transfer_status_info_t recv_data;
+ GSList *tr_send_list;
+ GSList *tr_next_data;
+ int current_tr_uid;
+ notification_h send_noti;
+ notification_h receive_noti;
+ notification_h opc_noti;
+ int opc_noti_id;
+ DBusGConnection *conn;
+ GObject *object;
+ gboolean obex_server_init;
+};
+
+
+void _bt_terminate_app(void);
+
+int _bt_init_obex_server(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_NOTI_HANDLER_H_
+#define __DEF_BLUETOOTH_SHARE_NOTI_HANDLER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STORAGE_PATH_LEN_MAX 30
+
+
+#define BT_DOWNLOAD_PHONE_FOLDER "/opt/usr/media/Downloads"
+#define BT_DOWNLOAD_MMC_FOLDER "/opt/storage/sdcard"
+#define BT_DOWNLOAD_MEDIA_FOLDER "/opt/usr/media"
+#define BT_FTP_FOLDER "/opt/share/bt-ftp"
+
+void _bt_init_vconf_notification(void);
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_NOTI_HANDLER_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_NOTI_H_
+#define __DEF_BLUETOOTH_SHARE_NOTI_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+#include <notification.h>
+
+#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"
+
+/* 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 {
+ CREATE_PROGRESS,
+ CREATE_TR_LIST
+} bt_qp_launch_type_t;
+
+
+notification_h _bt_create_notification(bt_qp_type_t type);
+
+int _bt_insert_notification(notification_h noti,
+ char *title,
+ char *content,
+ char *icon_path);
+
+int _bt_update_notification(notification_h noti,
+ char *title,
+ char *content,
+ char *icon_path);
+
+int _bt_update_notification_progress(void *handle,
+ int id,
+ int val);
+
+
+gboolean _bt_get_notification_text(int priv_id, char *str);
+
+int _bt_delete_notification(notification_h noti);
+
+int _bt_set_notification_app_launch(notification_h noti,
+ bt_qp_launch_type_t type,
+ const char *transfer_type,
+ const char *filename,
+ const char *progress_cnt);
+int _bt_set_notification_property(notification_h noti, int flag);
+
+void _bt_register_notification_cb(struct bt_appdata *ad);
+
+void _bt_unregister_notification_cb(struct bt_appdata *ad);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_NOTI_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_RES_H_
+#define __DEF_BLUETOOTH_SHARE_RES_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <libintl.h>
+
+/*============== String ================= */
+#define BT_COMMON_PKG "ug-setting-bluetooth-efl"
+#define BT_COMMON_RES "/usr/ug/res/locale"
+
+#define BT_STR_FILE_EXSIST_MSG \
+ dgettext(BT_COMMON_PKG, "IDS_BT_POP_PS_ALREADY_EXISTS_OVERWRITE_Q")
+#define BT_STR_FILE_DELETE_AUTHORIZE_MSG \
+ dgettext(BT_COMMON_PKG, "Delete %s by %s ?")
+#define BT_STR_RECEIVING dgettext(BT_COMMON_PKG, "IDS_BT_POP_RECEIVING_ING")
+#define BT_STR_SENDING \
+ dgettext(BT_COMMON_PKG, "IDS_BT_POP_SHARING_ING")
+#define BT_STR_MEMORY_FULL \
+ dgettext(BT_COMMON_PKG, "IDS_BT_POP_MEMORYFULL")
+#define BT_STR_RECEIVCED \
+ dgettext(BT_COMMON_PKG, "IDS_BT_BODY_RECEIVED")
+#define BT_STR_PD_FILES_RECEIVED \
+ dgettext(BT_COMMON_PKG, "IDS_BT_POP_PD_FILES_RECEIVED")
+#define BT_STR_UNABLE_TO_SEND \
+ dgettext(BT_COMMON_PKG, "IDS_BT_POP_SENDINGFAIL")
+
+#define BT_STR_SEND_NOTI "Bluetooth share: Sent"
+#define BT_STR_RECEIVED_NOTI "Bluetooth share: Received"
+#define BT_TR_STATUS "%d successful, %d failed"
+
+/*============== Image ================= */
+#define ICONDIR "/opt/apps/org.tizen.bluetooth-share-ui/res/images"
+#define BT_ICON_PATH_MAX 256
+
+#define BT_ICON_QP_SEND ICONDIR"/Q02_icon_BT_transmit.png"
+#define BT_ICON_QP_RECEIVE ICONDIR"/Q02_icon_BT_receive.png"
+#define BT_ICON_QP_BT_ON ICONDIR"/Q02_QuickPanel_icon_bluetooth_noti.png"
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_RES_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_SYSPOPUP_H_
+#define __DEF_BLUETOOTH_SHARE_SYSPOPUP_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BT_GLOBALIZATION_STR_LENGTH 256
+#define BT_FILE_NAME_LEN_MAX 255
+#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;
+
+typedef enum {
+ POPUP_RESPONSE_OK,
+ POPUP_RESPONSE_CANCEL,
+ POPUP_RESPONSE_TIMEOUT
+} bt_popup_response;
+
+
+typedef struct {
+ char *title;
+ char *type;
+ char *file;
+ char *device_name;
+} bt_app_sys_popup_params_t;
+
+
+
+int _bt_launch_system_popup(bt_app_event_type_t event_type,
+ bt_app_sys_popup_params_t *popup_params,
+ void *cb,
+ void *data);
+
+gboolean _bt_app_popup_memoryfull(gpointer user_data);
+
+//void _bt_app_obex_download_dup_file_cb(void *data, void *obj,
+// void *event_info);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_SYSPOPUP_H_ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __BT_EVENT_HANDLER_H__
+#define __BT_EVENT_HANDLER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "bluetooth-api.h"
+
+#define BT_FILE_PATH_LEN_MAX (4096 + 10)
+#define BT_TEMP_FILE_PATH_LEN_MAX 262
+#define BT_TEXT_LEN_MAX 255
+
+typedef enum {
+ BT_FILE_IMAGE, /**<IMAGE */
+ BT_FILE_VCARD, /**<VCARD */
+ BT_FILE_VCAL, /**<VCAL */
+ BT_FILE_VBOOKMARK, /**<VBOOKMARK */
+ BT_FILE_VMEMO,
+ BT_FILE_DOC, /**<DOC, */
+ BT_FILE_OTHER /**<OTHER*/
+} bt_file_type_t;
+
+int _bt_get_transfer_id_by_noti_id(int noti_id);
+
+void _bt_clear_receive_noti_list(void);
+
+void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
+ void *user_data);
+
+void _bt_obex_server_event_handler(int event,
+ bluetooth_event_param_t *param,
+ void *user_data);
+
+void _bt_app_obex_download_dup_file_cb(void *data, void *obj,
+ void *event_info);
+
+void _bt_get_default_storage(char *storage);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __BT_EVENT_HANDLER_H__ */
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <pmapi.h>
+#include <glib.h>
+#include "vconf-keys.h"
+#include "applog.h"
+#include "bt-share-common.h"
+#include <vconf.h>
+
+int _bt_share_block_sleep(gboolean is_block)
+{
+ static int block_sleep_count = 0;
+ int result = -1;
+
+ DBG("is_block [%d], block_sleep_count[%d]\n", is_block,
+ block_sleep_count);
+
+ if (is_block) {
+ if (block_sleep_count < 0) {
+ DBG("block_sleep_count[%d] is invalid. It is set to 0.\n",
+ block_sleep_count);
+ block_sleep_count = 0;
+ } else if (block_sleep_count == 0) {
+ result = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+ if (result != 0) {
+ DBG("LCD Lock is failed with result code [%d]\n", result);
+ }
+ } else {
+ result = 0;
+ }
+
+ if (result == 0) {
+ block_sleep_count++;
+ }
+ } else {
+ if (block_sleep_count <= 0) {
+ DBG("block_sleep_count[%d] is invalid. It is set to 0.\n",
+ block_sleep_count);
+ block_sleep_count = 0;
+ } else if (block_sleep_count == 1) {
+ result = pm_unlock_state(LCD_OFF, PM_RESET_TIMER);
+ if (result != 0) {
+ DBG("LCD Unlock is failed with result code [%d]\n",
+ result);
+ }
+ } else {
+ result = 0;
+ }
+
+ if (result == 0) {
+ block_sleep_count--;
+ }
+ }
+
+ DBG("result [%d]\n", result);
+ return result;
+}
+
+
+
+int _bt_set_transfer_indicator(gboolean state)
+{
+ int bt_device_state;
+ static int block_cnt = 0;
+ int ret;
+
+ ret = vconf_get_int(VCONFKEY_BT_STATUS, (void *)&bt_device_state);
+ if (ret != 0) {
+ DBG("Get vconf failed\n");
+ return -1;
+ }
+
+ if(state == TRUE) {
+ block_cnt++;
+ if(bt_device_state & BT_STATUS_TRANSFER)
+ return 0;
+ bt_device_state |= BT_STATUS_TRANSFER;
+ } else {
+ if(block_cnt > 0)
+ block_cnt--;
+ if(block_cnt != 0)
+ return 0;
+ bt_device_state ^= BT_STATUS_TRANSFER;
+ }
+
+ ret = vconf_set_int(VCONFKEY_BT_STATUS, bt_device_state);
+ if (ret != 0) {
+ DBG("Set vconf failed\n");
+ return -1;
+ }
+ return 0;
+}
+
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <notification.h>
+#include <sysman.h>
+#include <aul.h>
+#include <vconf.h>
+
+#include "applog.h"
+#include "bluetooth-api.h"
+#include "bt-share-main.h"
+#include "bt-share-ipc.h"
+#include "bt-share-syspopup.h"
+#include "bt-share-notification.h"
+#include "bt-share-resource.h"
+#include "obex-event-handler.h"
+#include "bluetooth-share-api.h"
+
+GSList *bt_transfer_list = NULL;
+DBusConnection *dbus_connection = NULL;
+
+extern struct bt_appdata *app_state;
+
+static void __bt_create_send_data(opc_transfer_info_t *node);
+static void __bt_share_update_tr_info(int tr_uid, int tr_type);
+
+static void __bt_tr_data_free(bt_tr_data_t *data)
+{
+ retm_if(data == NULL, "Invalid param");
+
+ g_free(data->file_path);
+ g_free(data->dev_name);
+ g_free(data->addr);
+ g_free(data);
+}
+
+static void __popup_res_cb(int res)
+{
+ DBG("+\n");
+ struct bt_appdata *ad = app_state;
+ if (ad->popups.syspopup_request == FALSE) {
+ DBG("This event is not mine\n");
+ return;
+ }
+ DBG(" res : %d\n", res);
+ /* Inorder to support calling popup from callback, we have to make
+ * syspopup_request false here and also should not assign
+ * ad->popups.popup_cb = NULL */
+
+ ad->popups.syspopup_request = FALSE;
+
+ if (NULL != ad->popups.popup_cb) {
+ if (res == 0)
+ ad->popups.popup_cb(ad->popups.popup_cb_data,
+ NULL,
+ (void *)POPUP_RESPONSE_OK);
+ else if (res == 1)
+ ad->popups.popup_cb(ad->popups.popup_cb_data,
+ NULL,
+ (void *)POPUP_RESPONSE_CANCEL);
+ else if (res == 2)
+ ad->popups.popup_cb(ad->popups.popup_cb_data,
+ NULL,
+ (void *)POPUP_RESPONSE_TIMEOUT);
+ }
+ DBG("-\n");
+}
+
+
+static opc_transfer_info_t *__add_transfer_info(DBusMessage *msg)
+{
+ int reserved = 0;
+ int cnt = 0;
+ char *addr = NULL;
+ int len;
+ char *filepath = NULL;
+ char *mode = NULL;
+ char *name = NULL;
+ opc_transfer_info_t *data;
+ int i = 0;
+ char *token = NULL;
+ char *tmp = NULL;
+ char *ptr = NULL;
+
+ retv_if(msg == NULL, NULL);
+ dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_INT32, &reserved,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+ &addr, &len,
+ DBUS_TYPE_INT32, &cnt,
+ DBUS_TYPE_STRING, &filepath,
+ DBUS_TYPE_STRING, &mode,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID);
+
+ retv_if(cnt <= 0, NULL);
+ retv_if(addr == NULL, NULL);
+ retv_if(filepath == NULL, NULL);
+ retv_if(name == NULL, NULL);
+
+ DBG("reserved ( %d )\n", reserved);
+ DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", addr[0],
+ addr[1], addr[2], addr[3], addr[4], addr[5]);
+ DBG(" cnt( %d )\n", cnt);
+ DBG(" filepath( %s )\n", filepath);
+ DBG(" mode ( %s )\n", mode);
+ DBG(" name ( %s )\n", name);
+
+ data = g_new0(opc_transfer_info_t, 1);
+
+ data->file_path = g_new0(char *, cnt + 1);
+ data->file_cnt = cnt;
+ memcpy(data->addr, addr, BLUETOOTH_ADDRESS_LENGTH);
+ memcpy(data->name, name, BLUETOOTH_DEVICE_NAME_LENGTH_MAX);
+
+ token = strtok_r(filepath, FILE_PATH_DELIM, &ptr);
+ while ((token != NULL) && (i < cnt)) {
+ len = strlen(token);
+
+ tmp = g_malloc0(len + 1);
+
+ g_strlcpy(tmp, token, len + 1);
+ data->file_path[i] = tmp;
+ DBG("File [%d] [%s]\n", i, data->file_path[i]);
+ i++;
+
+ token = strtok_r(NULL, FILE_PATH_DELIM, &ptr);
+ }
+
+ bt_transfer_list = g_slist_append(bt_transfer_list, data);
+
+ return data;
+}
+
+
+void _free_transfer_info(opc_transfer_info_t *node)
+{
+ int i;
+
+ DBG("+\n");
+ ret_if(node == NULL);
+
+ for (i = 0; i < node->file_cnt; i++) {
+ g_free(node->file_path[i]);
+ }
+ g_free(node->file_path);
+ g_free(node);
+
+ DBG("-\n");
+}
+
+void _remove_transfer_info(opc_transfer_info_t *node)
+{
+ DBG("+\n");
+ ret_if(node == NULL);
+
+ bt_transfer_list = g_slist_remove(bt_transfer_list, node);
+ _free_transfer_info(node);
+
+ DBG("-\n");
+}
+
+int _request_file_send(opc_transfer_info_t *node)
+{
+ struct bt_appdata *ad = app_state;
+ int ret;
+ DBG("+\n");
+ retv_if(ad == 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) {
+ DBG("bluetooth_opc_push_files failed : %d", ret);
+ return ret;
+ }
+
+ __bt_create_send_data(node);
+
+ DBG("-\n");
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static DBusHandlerResult __event_filter(DBusConnection *sys_conn,
+ DBusMessage *msg, void *data)
+{
+ int ret;
+ char *member;
+ const char *path = dbus_message_get_path(msg);
+
+ 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);
+ DBG("member (%s)\n", 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;
+ 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) {
+ DBG("Aleady OPC progressing. Once completed previous job, will be started\n");
+ } else if ( ret != BLUETOOTH_ERROR_NONE) {
+ _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL);
+ 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 transfer_id = 0;
+ int noti_id = 0;
+ if (!dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_STRING, &transfer_type,
+ DBUS_TYPE_INT32, ¬i_id,
+ DBUS_TYPE_INVALID)) {
+ ERR("OPP abort handling failed");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ DBG("transfer_type = %s\n", transfer_type);
+ if (!g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT)) {
+ bluetooth_opc_cancel_push();
+ } else {
+ transfer_id = _bt_get_transfer_id_by_noti_id(noti_id);
+ bluetooth_obex_server_cancel_transfer(transfer_id);
+ }
+ } else if (dbus_message_is_signal(msg, BT_SHARE_UI_INTERFACE,
+ BT_SHARE_UI_SIGNAL_SEND_FILE)) {
+ opc_transfer_info_t *node;
+ 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) {
+ DBG("Aleady OPC progressing. Once completed previous job, will be started\n");
+ } else if ( ret != BLUETOOTH_ERROR_NONE) {
+ _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL);
+ 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);
+
+ DBG("tr_uid = %d, tr_type = %d \n", 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) {
+ if (vconf_set_bool(BT_VCONF_OPP_SERVER_INIT, FALSE)< 0)
+ ERR("Fail to set the vconf");
+ }
+ } else {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+gboolean _bt_init_dbus_signal(void)
+{
+ DBG("+\n");
+ DBusGConnection *conn;
+ GError *err = NULL;
+ DBusError dbus_error;
+
+ conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
+ if (!conn) {
+ DBG(" DBUS get failed\n");
+ g_error_free(err);
+ return FALSE;
+ }
+ dbus_connection = dbus_g_connection_get_connection(conn);
+
+ /* Add the filter for network client functions */
+ dbus_error_init(&dbus_error);
+ dbus_connection_add_filter(dbus_connection, __event_filter, NULL, NULL);
+ 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\n");
+ dbus_error_free(&dbus_error);
+ }
+
+ DBG("-\n");
+ return TRUE;
+}
+
+void _bt_send_message_to_ui(int transfer_id, char *name, int percentage, gboolean completed, int error_type)
+{
+ DBusMessage *msg = NULL;
+ DBG("+\n");
+ ret_if(dbus_connection == NULL);
+ ret_if(name == NULL);
+
+ msg = dbus_message_new_signal(BT_SHARE_ENG_OBJECT,
+ BT_SHARE_ENG_INTERFACE,
+ BT_SHARE_ENG_SIGNAL_PROGRESS);
+ if (!msg) {
+ ERR("Unable to allocate memory\n");
+ return;
+ }
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &transfer_id,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INT32, &percentage,
+ DBUS_TYPE_BOOLEAN, &completed,
+ DBUS_TYPE_INT32, &error_type,
+ DBUS_TYPE_INVALID)) {
+ ERR("Event sending failed\n");
+ dbus_message_unref(msg);
+ return;
+ }
+ DBG("Dbus send message append request is done.\n");
+
+ dbus_message_set_destination(msg, BT_SHARE_UI_INTERFACE);
+ dbus_connection_send(dbus_connection, msg, NULL);
+ dbus_message_unref(msg);
+ DBG("-\n");
+ return;
+}
+
+
+void _bt_create_warning_popup(int error_type)
+{
+ /* If bluetooth-share-ui process is existed, send dbus signal. */
+ /* Otherwise create the process and terminate it after popup shown */
+ if (sysman_get_pid(UI_PKG_PATH) == -1) {
+ char str[BT_TEXT_LEN_MAX] = {0,};
+ bundle *b = NULL;
+ b = bundle_create();
+ ret_if(b == NULL);
+
+ switch(error_type) {
+ case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
+ case BLUETOOTH_ERROR_NOT_CONNECTED:
+ case BLUETOOTH_ERROR_ACCESS_DENIED:
+ case BLUETOOTH_ERROR_OUT_OF_MEMORY:
+ case BLUETOOTH_ERROR_INTERNAL:
+ snprintf(str, BT_TEXT_LEN_MAX, "%s", BT_STR_UNABLE_TO_SEND);
+ break;
+ default:
+ bundle_free(b);
+ return;
+ }
+
+ bundle_add(b, "launch-type", "warning_popup");
+ bundle_add(b, "message", str);
+
+ aul_launch_app(UI_PACKAGE, b);
+
+ bundle_free(b);
+ }else {
+ DBusMessage *msg = NULL;
+ ret_if(dbus_connection == NULL);
+
+ msg = dbus_message_new_signal(BT_SHARE_ENG_OBJECT,
+ BT_SHARE_ENG_INTERFACE,
+ BT_SHARE_ENG_SIGNAL_ERROR);
+ if (!msg) {
+ ERR("Unable to allocate memory\n");
+ return;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &error_type,
+ DBUS_TYPE_INVALID)) {
+ DBG("Event sending failed\n");
+ dbus_message_unref(msg);
+ return;
+ }
+
+ dbus_message_set_destination(msg, BT_SHARE_UI_INTERFACE);
+ dbus_connection_send(dbus_connection, msg, NULL);
+ dbus_message_unref(msg);
+ }
+
+ return;
+}
+
+void _bt_update_transfer_list_view(const char *table)
+{
+ DBusMessage *msg = NULL;
+ ret_if(dbus_connection == NULL);
+
+ msg = 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\n");
+ return;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &table,
+ DBUS_TYPE_INVALID)) {
+ DBG("Event sending failed\n");
+ dbus_message_unref(msg);
+ return;
+ }
+
+ dbus_message_set_destination(msg, BT_SHARE_UI_INTERFACE);
+ dbus_connection_send(dbus_connection, msg, NULL);
+ dbus_message_unref(msg);
+}
+
+static time_t __bt_get_current_timedata(void)
+{
+ time_t t;
+ time(&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);
+
+ snprintf(address, BT_ADDR_STR_LEN_MAX,
+ "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+ addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
+
+ return g_strdup(address);
+}
+
+static void __bt_create_send_data(opc_transfer_info_t *node)
+{
+ DBG("__bt_create_send_data \n");
+ ret_if(node == NULL);
+ struct bt_appdata *ad = app_state;
+
+ int count = 0;
+ int session_id;
+
+ sqlite3 *db = NULL;
+
+ DBG("Name [%s]\n", node->name);
+
+ db = bt_share_open_db();
+ if (!db)
+ return;
+
+ session_id = bt_share_get_last_session_id(db, BT_DB_OUTBOUND);
+ DBG("Last session id = %d\n", 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) {
+ bt_share_close_db(db);
+ return;
+ }
+
+ tmp->tr_status = BT_TR_ONGOING;
+ tmp->sid = session_id + 1;
+ tmp->file_path = g_strdup(node->file_path[count]);
+ tmp->dev_name = g_strdup(node->name);
+ tmp->timestamp = __bt_get_current_timedata();
+ tmp->addr = __bt_conv_addr_type_to_addr_string(node->addr);
+ 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);
+
+ if (ad->tr_send_list == NULL)
+ return;
+
+ ad->tr_next_data = ad->tr_send_list;
+
+ return;
+}
+
+gboolean _bt_update_sent_data_status(int uid, bt_app_tr_status_t status)
+{
+ DBG("_bt_update_sent_data_status \n");
+
+ DBG("uid = %d \n", uid);
+ sqlite3 *db = NULL;
+ bt_tr_data_t *tmp;
+ tmp = g_malloc0(sizeof(bt_tr_data_t));
+ if (!tmp)
+ return FALSE;
+
+ db = bt_share_open_db();
+ if (!db) {
+ g_free(tmp);
+ return FALSE;
+ }
+
+ tmp->tr_status = status;
+ tmp->timestamp = __bt_get_current_timedata();
+ 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_add_recv_transfer_status_data(char *device_name,
+ char *filepath, int status)
+{
+ if (device_name == NULL || filepath == NULL)
+ return FALSE;
+
+ sqlite3 *db = NULL;
+ bt_tr_data_t *tmp;
+
+ DBG("Name [%s]\n", device_name);
+ tmp = g_malloc0(sizeof(bt_tr_data_t));
+ if (!tmp)
+ return FALSE;
+
+ db = bt_share_open_db();
+ if (!db) {
+ g_free(tmp);
+ return FALSE;
+ }
+
+ tmp->tr_status = status;
+ tmp->file_path = g_strdup(filepath);
+ tmp->dev_name = g_strdup(device_name);
+ tmp->timestamp = __bt_get_current_timedata();
+ bt_share_add_tr_data(db, BT_DB_INBOUND, tmp);
+ bt_share_close_db(db);
+ __bt_tr_data_free(tmp);
+
+ return TRUE;
+}
+
+static void __bt_share_update_tr_info(int tr_uid, int tr_type)
+{
+ DBG("__bt_share_update_tr_info tr_uid = %d \n", tr_uid);
+ int status = -1;
+ struct bt_appdata *ad = app_state;
+ char str[NOTIFICATION_TEXT_LEN_MAX] = { 0 };
+ bt_tr_data_t *info = NULL;
+ sqlite3 *db = NULL;
+
+ db = bt_share_open_db();
+ if (!db)
+ return;
+
+ if (tr_type == BT_TR_OUTBOUND) {
+ if (tr_uid == -1) {
+ /* Click the "clear list" button in bluetooth-share-ui */
+ /* 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;
+ bt_share_remove_tr_data_by_notification(db, BT_DB_OUTBOUND);
+ bt_share_close_db(db);
+ } else {
+ /* Delete selected outbound db / notification info */
+
+ info = bt_share_get_tr_data(db, BT_DB_OUTBOUND, tr_uid);
+ if (info != NULL) {
+ status = info->tr_status;
+ g_free(info);
+ }
+
+ 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)
+ ad->send_data.tr_success--;
+ else if (status == BT_TR_FAIL && ad->send_data.tr_fail > 0)
+ ad->send_data.tr_fail--;
+ else
+ return;
+
+ if ((ad->send_data.tr_success + ad->send_data.tr_fail) != 0) {
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->send_data.tr_success, ad->send_data.tr_fail);
+
+ _bt_update_notification(ad->send_noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ } else {
+ _bt_delete_notification(ad->send_noti);
+ }
+ }
+ } else if (tr_type == BT_TR_INBOUND) {
+ if (tr_uid == -1) {
+ /* Click the "clear list" button in bluetooth-share-ui */
+ /* Delete all inbound db / notification info */
+
+ _bt_delete_notification(ad->receive_noti);
+ ad->receive_noti = NULL;
+ ad->recv_data.tr_success = 0;
+ ad->recv_data.tr_fail = 0;
+ bt_share_remove_all_tr_data(db, BT_DB_INBOUND);
+ bt_share_close_db(db);
+ } else {
+ /* Delete selected outbound db / notification info */
+
+ info = bt_share_get_tr_data(db, BT_DB_INBOUND, tr_uid);
+ if (info != NULL) {
+ status = info->tr_status;
+ g_free(info);
+ }
+
+ bt_share_remove_tr_data_by_id(db, BT_DB_INBOUND, tr_uid);
+ bt_share_close_db(db);
+
+ if (status == BT_TR_SUCCESS && ad->recv_data.tr_success > 0)
+ ad->recv_data.tr_success--;
+ else if (status == BT_TR_FAIL && ad->recv_data.tr_fail > 0)
+ ad->recv_data.tr_fail--;
+ else
+ return;
+
+ if ((ad->recv_data.tr_success + ad->recv_data.tr_fail) != 0) {
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->recv_data.tr_success, ad->recv_data.tr_fail);
+
+ _bt_update_notification(ad->receive_noti,
+ BT_STR_RECEIVED_NOTI, str,
+ BT_ICON_QP_RECEIVE);
+ } else {
+ _bt_delete_notification(ad->receive_noti);
+ }
+ }
+ } else {
+ ERR("Invalid transfer type \n");
+ }
+ return;
+}
+
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+#include <string.h>
+#include <appcore-efl.h>
+#include <privilege-control.h>
+#include <vconf.h>
+#include "applog.h"
+#include "bt-share-main.h"
+#include "bluetooth-api.h"
+#include "obex-event-handler.h"
+#include "bt-share-ipc.h"
+#include "bt-share-noti-handler.h"
+#include "bt-share-resource.h"
+#include "bt-share-notification.h"
+#include "bt-share-common.h"
+
+#include "bluetooth-share-api.h"
+
+#define BLUETOOTH_SHARE_BUS "org.projectx.bluetooth.share"
+
+static gboolean terminated;
+
+GMainLoop *main_loop = NULL;
+struct bt_appdata *app_state = NULL;
+
+static void __bt_release_service(struct bt_appdata *ad)
+{
+ if (ad == NULL)
+ return;
+
+ _bt_delete_notification(ad->send_noti);
+ _bt_delete_notification(ad->receive_noti);
+ _bt_delete_notification(ad->opc_noti);
+ _bt_clear_receive_noti_list();
+ ad->send_noti = NULL;
+ ad->receive_noti = NULL;
+ ad->opc_noti = NULL;
+
+ bluetooth_opc_deinit();
+ bluetooth_obex_server_deinit();
+ _bt_unregister_notification_cb(ad);
+
+ if (vconf_set_bool(BT_VCONF_OPP_SERVER_INIT, FALSE) < 0)
+ ERR("Fail to set the vconf");
+}
+
+static void __bt_sigterm_handler(int signo)
+{
+ DBG("+");
+
+ if (main_loop) {
+ g_main_loop_quit(main_loop);
+ } else {
+ terminated = TRUE;
+ }
+
+ DBG("-");
+}
+
+static void __bt_update_notification_status_values()
+{
+ struct bt_appdata *ad = app_state;
+ GSList *tr_data_list = NULL;
+ GSList *list_iter = NULL;
+ bt_tr_data_t *info = NULL;;
+ char str[NOTIFICATION_TEXT_LEN_MAX] = { 0 };
+ notification_h noti = NULL;
+ sqlite3 *db = NULL;
+
+ db = bt_share_open_db();
+ if (!db)
+ return;
+
+ tr_data_list = bt_share_get_all_tr_data_list(db, BT_DB_OUTBOUND);
+ if (NULL != tr_data_list) {
+ list_iter = tr_data_list;
+
+ while (NULL != list_iter) {
+ info = list_iter->data;
+ if (NULL == info)
+ break;
+
+ if (info->tr_status == BT_TR_SUCCESS) {
+ ad->send_data.tr_success++;
+ } else if (info->tr_status == BT_TR_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 */
+ ad->send_data.tr_fail++;
+ info->tr_status = BT_TR_FAIL;
+ bt_share_update_tr_data(db, BT_DB_OUTBOUND, info->id, info);
+ } else {
+ ERR("Invalid status\n");
+ }
+
+ list_iter = g_slist_next(list_iter);
+ }
+
+ if ((ad->send_data.tr_success + ad->send_data.tr_fail) != 0) {
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->send_data.tr_success, ad->send_data.tr_fail);
+
+ noti = _bt_create_notification(BT_NOTI_T);
+ _bt_set_notification_app_launch(noti,
+ CREATE_TR_LIST,
+ NOTI_TR_TYPE_OUT, NULL, NULL);
+ _bt_set_notification_property(noti, QP_NO_DELETE | QP_NO_TICKER);
+ _bt_insert_notification(noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ ad->send_noti = noti;
+ }
+
+ bt_share_release_tr_data_list(tr_data_list);
+ tr_data_list = NULL;
+ list_iter = NULL;
+ }
+
+ tr_data_list = bt_share_get_all_tr_data_list(db, BT_DB_INBOUND);
+ if (NULL != tr_data_list) {
+ list_iter = tr_data_list;
+
+ while (NULL != list_iter) {
+ info = list_iter->data;
+ if (NULL == info)
+ break;
+
+ if (info->tr_status == BT_TR_SUCCESS)
+ ad->recv_data.tr_success++;
+ else
+ ad->recv_data.tr_fail++;
+
+ list_iter = g_slist_next(list_iter);
+ }
+
+ if ((ad->recv_data.tr_success + ad->recv_data.tr_fail) != 0) {
+
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->recv_data.tr_success, ad->recv_data.tr_fail);
+ DBG("str = [%s] \n", str);
+
+ noti = _bt_create_notification(BT_NOTI_T);
+ _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
+ NOTI_TR_TYPE_IN, NULL, NULL);
+ _bt_set_notification_property(noti, QP_NO_DELETE | QP_NO_TICKER);
+ _bt_insert_notification(noti,
+ BT_STR_RECEIVED_NOTI, str,
+ BT_ICON_QP_RECEIVE);
+ ad->receive_noti = noti;
+ }
+
+ bt_share_release_tr_data_list(tr_data_list);
+ tr_data_list = NULL;
+ list_iter = NULL;
+ }
+
+ bt_share_close_db(db);
+
+ return;
+}
+
+static gboolean __bt_dbus_request_name(void)
+{
+ int ret_code = 0;
+ DBusConnection *conn;
+ DBusError err;
+
+ dbus_error_init(&err);
+
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+
+ if (dbus_error_is_set(&err))
+ goto failed;
+
+ 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;
+
+ if(DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER == ret_code) {
+ dbus_connection_unref(conn);
+ return TRUE;
+ }
+
+failed:
+ if (dbus_error_is_set(&err)) {
+ ERR("D-Bus Error: %s\n", err.message);
+ dbus_error_free(&err);
+ }
+
+ if (!conn)
+ dbus_connection_unref(conn);
+
+
+ return FALSE;
+}
+
+int _bt_init_obex_server(void)
+{
+ char storage[STORAGE_PATH_LEN_MAX];
+
+ _bt_get_default_storage(storage);
+ if (bluetooth_obex_server_init(storage) !=
+ BLUETOOTH_ERROR_NONE) {
+ DBG("Fail to init obex server");
+ return BT_SHARE_FAIL;
+ }
+
+ bluetooth_obex_server_set_root(BT_FTP_FOLDER);
+
+ return BT_SHARE_ERROR_NONE;
+}
+
+void _bt_terminate_app(void)
+{
+ if (main_loop) {
+ g_main_loop_quit(main_loop);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ DBG("+");
+ int ret;
+ struct bt_appdata ad;
+ memset(&ad, 0, sizeof(struct bt_appdata));
+ app_state = &ad;
+
+ signal(SIGTERM, __bt_sigterm_handler);
+
+ g_type_init();
+
+ if (__bt_dbus_request_name() == FALSE) {
+ DBG("Aleady dbus instance existed\n");
+ exit(0);
+ }
+
+ /* init internationalization */
+ if (appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0)
+ return -1;
+
+ /* Set the uid / gid to 5000 */
+ if (set_app_privilege("com.samsung.bluetooth-share", NULL, NULL) !=
+ PC_OPERATION_SUCCESS)
+ ERR("Failed to set app privilege.\n");
+
+ bluetooth_register_callback(_bt_share_event_handler, NULL);
+ ret = bluetooth_opc_init();
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ ERR("bluetooth_opc_init failed!!\n");
+ return -1;
+ }
+
+ _bt_init_dbus_signal();
+ _bt_init_vconf_notification();
+ __bt_update_notification_status_values();
+ _bt_register_notification_cb(&ad);
+
+ if (_bt_init_obex_server() == BT_SHARE_ERROR_NONE)
+ ad.obex_server_init = TRUE;
+
+ if (terminated == TRUE) {
+ __bt_release_service(&ad);
+ return -1;
+ }
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(main_loop);
+
+ __bt_release_service(&ad);
+
+ DBG("-");
+ return 0;
+}
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <vconf.h>
+#include "applog.h"
+#include "bluetooth-api.h"
+#include "bt-share-noti-handler.h"
+
+
+static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
+{
+ 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));
+
+ if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
+ /* Phone memory is 0, MMC is 1 */
+ default_memory = vconf_keynode_get_int(node);
+ root_path = default_memory ? BT_DOWNLOAD_MMC_FOLDER : BT_DOWNLOAD_MEDIA_FOLDER;
+ download_path = default_memory ? BT_DOWNLOAD_MMC_FOLDER : BT_DOWNLOAD_PHONE_FOLDER;
+
+ bluetooth_obex_server_set_root(root_path);
+ bluetooth_obex_server_set_destination_path(download_path);
+ }
+}
+
+void _bt_init_vconf_notification(void)
+{
+ int ret;
+ ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
+ __bt_default_memory_changed_cb, NULL);
+ if (ret < 0) {
+ DBG("vconf_notify_key_changed failed\n");
+ }
+}
+
+void _bt_deinit_vconf_notification(void)
+{
+ vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
+ (vconf_callback_fn) __bt_default_memory_changed_cb);
+ return;
+}
+
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <applog.h>
+#include <notification.h>
+#include <appsvc.h>
+#include <vconf.h>
+
+#include "bt-share-common.h"
+#include "bt-share-notification.h"
+#include "bt-share-main.h"
+#include "obex-event-handler.h"
+#include "bluetooth-share-api.h"
+
+#define BT_PERCENT_STR_LEN 5
+#define BT_PRIV_ID_STR_LEN 8
+
+notification_h _bt_create_notification(bt_qp_type_t type)
+{
+ DBG("+\n");
+ DBG("+Create type : %d\n", type);
+ notification_h noti = NULL;
+ noti = notification_create(type);
+ if (!noti) {
+ ERR("Fail to notification_new\n");
+ return NULL;
+ }
+ DBG("noti : %d \n", noti);
+ DBG("-\n");
+ return noti;
+}
+
+int _bt_insert_notification(notification_h noti,
+ char *title,
+ char *content,
+ char *icon_path)
+{
+ DBG("+\n");
+ int noti_id = 0;
+
+ if (!noti)
+ return BT_SHARE_FAIL;
+
+ DBG("Insert noti : %d \n", noti);
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
+ ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_image\n");
+ }
+
+ if (title) {
+ ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+ title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_text\n");
+ }
+ }
+
+ if (content) {
+ ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+ content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_text\n");
+ }
+ }
+
+ ret = notification_insert(noti, ¬i_id);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_insert\n");
+ }
+
+ DBG("-\n");
+ return noti_id;
+}
+
+int _bt_update_notification(notification_h noti,
+ char *title,
+ char *content,
+ char *icon_path)
+{
+ DBG("+\n");
+ if (!noti)
+ return BT_SHARE_FAIL;
+
+ DBG("Insert noti : %d \n", noti);
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
+ ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_image\n");
+ }
+
+ if (title) {
+ ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+ title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_text\n");
+ }
+ }
+
+ if (content) {
+ ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+ content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_text\n");
+ }
+ }
+
+ ret = notification_update(noti);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_update\n");
+ }
+
+ DBG("-\n");
+ return ret;
+}
+
+int _bt_update_notification_progress(void *handle,
+ int id,
+ int val)
+{
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+ ret = notification_update_progress(handle, id, (double)val / 100);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_update_progress\n");
+ }
+ return ret;
+}
+
+
+gboolean _bt_get_notification_text(int priv_id, char *str)
+{
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+ notification_list_h list = NULL;
+ notification_h noti = NULL;
+
+ /* Get notification information from notification detail list */
+ ret = notification_get_detail_list(BT_SHARE_BIN_PATH,
+ -1,
+ priv_id,
+ -1,
+ &list);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_get_text\n");
+ return FALSE;
+ }
+
+ if (list) {
+ noti = notification_list_get_data(list);
+ char *text = NULL;
+ notification_get_text(noti,
+ NOTIFICATION_TEXT_TYPE_TITLE,
+ &text);
+ g_strlcpy(str, text, NOTIFICATION_TEXT_LEN_MAX);
+ } else {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+int _bt_delete_notification(notification_h noti)
+{
+ DBG("+\n");
+
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
+ if (!noti)
+ return BT_SHARE_FAIL;
+
+ /* In case daemon, give full path */
+ ret = notification_delete(noti);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_delete_by_priv_id\n");
+ }
+ DBG("-\n");
+ return ret;
+}
+
+int _bt_set_notification_app_launch(notification_h noti,
+ bt_qp_launch_type_t type,
+ const char *transfer_type,
+ const char *filename,
+ const char *progress_cnt)
+{
+ DBG("+\n");
+ if (!noti)
+ return -1;
+
+ if (!transfer_type)
+ return -1;
+
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+ bundle *b = NULL;
+ b = bundle_create();
+ if (!b)
+ return -1;
+
+ if (type == CREATE_PROGRESS) {
+ int group_id = 0;
+ int priv_id = 0;
+ double percentage = 0;
+ char progress[BT_PERCENT_STR_LEN] = { 0 };
+ char priv_id_str[BT_PRIV_ID_STR_LEN] = { 0 };
+
+ if (!filename) {
+ bundle_free(b);
+ return -1;
+ }
+
+ ret = notification_get_progress(noti, &percentage);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ ERR("Fail to notification_update_progress\n");
+ else
+ snprintf(progress, BT_PERCENT_STR_LEN, "%d", (int)percentage);
+
+ ret = notification_get_id(noti, &group_id, &priv_id);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ ERR("Fail to notification_update_progress\n");
+ else
+ snprintf(priv_id_str, BT_PRIV_ID_STR_LEN, "%d", priv_id);
+
+ 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, "transfer_id", priv_id_str);
+ if (g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT) == 0) {
+ if (!progress_cnt) {
+ bundle_free(b);
+ return -1;
+ }
+ appsvc_add_data(b, "progress_cnt", progress_cnt);
+ }
+ } else if (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;
+ }
+
+ 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\n");
+ }
+
+ bundle_free(b);
+ DBG("-\n");
+ return ret;
+}
+
+
+int _bt_set_notification_property(notification_h noti, int flag)
+{
+ DBG("+\n");
+ if (!noti)
+ return -1;
+
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
+ ret = notification_set_property(noti, flag);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_property\n");
+ }
+
+ ret = notification_set_display_applist(noti,
+ NOTIFICATION_DISPLAY_APP_ALL ^
+ NOTIFICATION_DISPLAY_APP_TICKER);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("Fail to notification_set_display_applist\n");
+ }
+
+ DBG("-\n");
+ return ret;
+}
+
+
+static void __bt_noti_changed_cb(void *data, notification_type_e type)
+{
+ DBG("+\n");
+
+ struct bt_appdata *ad = (struct bt_appdata *)data;
+ if (NULL == ad)
+ return;
+
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+ int count = 0;
+ sqlite3 *db = NULL;
+
+ noti_err = notification_get_count(NOTIFICATION_TYPE_NOTI, BT_SHARE_BIN_PATH,
+ NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE, &count);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ return;
+ }
+
+ /* This callback used only for clear button of notification bar. */
+ /* So need to check the clear button of in/outbound list view */
+ if (count >= 1)
+ return;
+
+ ad->send_data.tr_fail = 0;
+ ad->send_data.tr_success = 0;
+ ad->recv_data.tr_fail = 0;
+ ad->recv_data.tr_success = 0;
+
+ db = bt_share_open_db();
+ if (!db)
+ return;
+
+ bt_share_remove_tr_data_by_notification(db, BT_DB_INBOUND);
+ bt_share_remove_tr_data_by_notification(db, BT_DB_OUTBOUND);
+ DBG("DB record of notification was removed\n");
+
+ ad->send_noti = NULL;
+ ad->receive_noti = NULL;
+
+ bt_share_close_db(db);
+
+ DBG("-\n");
+}
+
+void _bt_register_notification_cb(struct bt_appdata *ad)
+{
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ noti_err = notification_resister_changed_cb(__bt_noti_changed_cb, ad);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_resister_changed_cb failed %d \n", noti_err);
+ }
+}
+
+void _bt_unregister_notification_cb(struct bt_appdata *ad)
+{
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ noti_err = notification_unresister_changed_cb(__bt_noti_changed_cb);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_unresister_changed_cb failed %d \n", noti_err);
+ }
+}
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syspopup_caller.h>
+#include "applog.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;
+#define BT_POPUP_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
+#define BT_SYSPOPUP_EVENT_LEN_MAX 50
+
+
+
+
+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;
+ }
+ ret = syspopup_launch("bt-syspopup", b);
+
+ if (0 > ret) {
+ ERR("launching sys-popup failed\n");
+ return TRUE;
+ } else {
+ DBG("Hurray Popup launched \n");
+ bundle_free(b);
+ return FALSE;
+ }
+}
+
+int _bt_launch_system_popup(bt_app_event_type_t event_type,
+ bt_app_sys_popup_params_t *popup_params,
+ void *cb,
+ void *data)
+{
+ int ret = 0;
+ bundle *b = NULL;
+ char event_str[BT_SYSPOPUP_EVENT_LEN_MAX] = { 0 };
+ struct bt_appdata *ad = app_state;
+
+ DBG("+\n");
+ if(cb == NULL)
+ return -1;
+
+ b = bundle_create();
+ if(b == NULL)
+ return -1;
+
+ bundle_add(b, "title", popup_params->title);
+ bundle_add(b, "type", popup_params->type);
+ bundle_add(b, "file", popup_params->file);
+ bundle_add(b, "device_name", popup_params->device_name);
+
+ switch (event_type) {
+ case BT_APP_EVENT_CONFIRM_MODE_REQUEST:
+ strncpy(event_str, "app-confirm-request", sizeof(event_str));
+ break;
+ case BT_APP_EVENT_FILE_RECEIVED:
+ strncpy(event_str, "file-received", sizeof(event_str));
+ break;
+ case BT_APP_EVENT_INFORMATION:
+ strncpy(event_str, "bt-information", sizeof(event_str));
+ break;
+ case BT_APP_EVENT_OVERWRITE_REQUEST:
+ strncpy(event_str, "confirm-overwrite-request", sizeof(event_str));
+ break;
+ default:
+ break;
+ }
+
+ bundle_add(b, "event-type", event_str);
+
+ /*The system popup launch function is not able to launch second popup
+ * if first popup is being processed still, this due to the check
+ * in AUL module to restrict multiple launching of syspopup,
+ * to solve this problem after discussion it is decided that if
+ * the popup launch fails then it will be retried
+ * after small timeout. */
+ ret = syspopup_launch("bt-syspopup", b);
+ if (0 > ret) {
+ ERR("Popup launch failed...retry = %d\n", ret);
+ g_timeout_add(BT_POPUP_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS,
+ (GSourceFunc) __bt_system_popup_timer_cb, b);
+ } else {
+ bundle_free(b);
+ }
+
+ ad->popups.popup_cb = (bt_app_cb) cb;
+ ad->popups.popup_cb_data = data;
+ ad->popups.syspopup_request = TRUE;
+
+ DBG("-\n");
+ return 0;
+}
+
+
+gboolean _bt_app_popup_memoryfull(gpointer user_data)
+{
+ bt_app_sys_popup_params_t popup_params = { NULL };
+
+ popup_params.title = BT_STR_MEMORY_FULL;
+ popup_params.type = "none";
+ _bt_launch_system_popup(BT_APP_EVENT_INFORMATION,
+ &popup_params,
+ NULL,
+ NULL);
+ return FALSE;
+}
+
+
--- /dev/null
+/*
+ * bluetooth-share
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sys/vfs.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <vconf-keys.h>
+#include <calendar2.h>
+#include <contacts.h>
+#include <vconf.h>
+#include <Ecore_File.h>
+#include <bluetooth-share-api.h>
+#include <notification.h>
+#include <media_content.h>
+
+#include "applog.h"
+#include "bluetooth-api.h"
+#include "obex-event-handler.h"
+#include "bt-share-main.h"
+#include "bt-share-syspopup.h"
+#include "bt-share-resource.h"
+#include "bt-share-ipc.h"
+#include "bt-share-notification.h"
+#include "bt-share-common.h"
+#include "bt-share-noti-handler.h"
+
+
+extern struct bt_appdata *app_state;
+
+typedef struct {
+ void *noti_handle;
+ int transfer_id;
+ int noti_id;
+} bt_noti_data_t;
+
+bt_obex_server_authorize_into_t server_auth_info;
+extern GSList *bt_transfer_list;
+GSList *bt_receive_noti_list;
+
+gboolean _bt_obex_writeclose(bt_obex_server_transfer_info_t *transfer_complete_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)
+{
+ GSList *l;
+ bt_noti_data_t *data;
+
+ for (l = bt_receive_noti_list; l != NULL; l = l->next) {
+ data = l->data;
+
+ if (data == NULL)
+ continue;
+
+ if (data->transfer_id == transfer_id)
+ return data;
+ }
+
+ return NULL;
+}
+
+static char *__get_file_name(int cnt, char **path)
+{
+ char *pfilename;
+ if (path == NULL) {
+ DBG("Path is invalid");
+ return NULL;
+ }
+ pfilename = strrchr(path[cnt], '/') + 1;
+ DBG("File name[%d] : %s \n", cnt, pfilename);
+ return pfilename;
+}
+
+static void __delete_notification(gpointer data, gpointer user_data)
+{
+ bt_noti_data_t *noti_data = data;
+
+ if (noti_data == NULL)
+ return;
+
+ _bt_delete_notification(noti_data->noti_handle);
+ g_free(noti_data);
+}
+
+int _bt_get_transfer_id_by_noti_id(int noti_id)
+{
+ GSList *l;
+ bt_noti_data_t *data;
+
+ 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;
+ }
+
+ return -1;
+}
+
+void _bt_clear_receive_noti_list(void)
+{
+ if (bt_receive_noti_list) {
+ g_slist_foreach(bt_receive_noti_list,
+ (GFunc)__delete_notification,
+ NULL);
+ g_slist_free(bt_receive_noti_list);
+ bt_receive_noti_list = NULL;
+ }
+}
+
+void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
+ void *user_data)
+{
+ int noti_id;
+ static int send_index = 0;
+ char *name = NULL;
+ char str[NOTIFICATION_TEXT_LEN_MAX] = { 0 };
+ char opc_cnt[NOTIFICATION_TEXT_LEN_MAX] = { 0 };
+ int percentage = 0;
+ notification_h noti = NULL;
+ bt_obex_server_authorize_into_t *auth_info;
+ bt_obex_server_transfer_info_t *transfer_info;
+ opc_transfer_info_t *node = NULL;
+ struct bt_appdata *ad = app_state;
+ bt_tr_data_t *info = NULL;
+ bt_opc_transfer_info_t *client_info = NULL;
+ bt_noti_data_t *data;
+ int s_id = 0;
+
+ if (bt_transfer_list)
+ node = bt_transfer_list->data;
+ DBG("OPC event : [0x%x] \n", event);
+
+ switch (event) {
+ 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_DISABLED:
+ g_free(server_auth_info.filename);
+ server_auth_info.filename = NULL;
+ _bt_terminate_app();
+ break;
+
+ case BLUETOOTH_EVENT_OPC_CONNECTED:
+ DBG("BLUETOOTH_EVENT_OPC_CONNECTED, result [%d] \n", param->result);
+ if (param->result != BLUETOOTH_ERROR_NONE) {
+ _bt_create_warning_popup(param->result);
+
+ if (NULL != node && node->file_cnt > send_index) {
+ info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+ s_id = info->sid;
+ DBG("info->sid = %d info->id = %d\n", info->sid, info->id);
+ while (NULL != ad->tr_next_data) {
+ info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+ if (info == NULL)
+ break;
+ DBG("info->sid = %d info->id = %d\n", info->sid, info->id);
+ if (info->sid != s_id) {
+ DBG("SID did not match so break done.\n");
+ break;
+ }
+
+ _bt_update_sent_data_status(info->id, BT_TR_FAIL);
+ ad->send_data.tr_fail++;
+ ad->tr_next_data = g_slist_next(ad->tr_next_data);
+ }
+
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->send_data.tr_success,
+ ad->send_data.tr_fail);
+
+ DBG("str = [%s] \n", str);
+
+ if (ad->send_noti == NULL) {
+ noti = _bt_create_notification(BT_NOTI_T);
+ _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
+ NOTI_TR_TYPE_OUT, NULL, NULL);
+ _bt_set_notification_property(noti, QP_NO_DELETE);
+ _bt_insert_notification(noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ ad->send_noti = noti;
+ } else {
+ _bt_update_notification(ad->send_noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ }
+ }
+
+ send_index = 0;
+ _remove_transfer_info(node);
+
+ if (!ad->tr_next_data) {
+ bt_share_release_tr_data_list(ad->tr_send_list);
+ ad->tr_send_list = NULL;
+ }
+
+ _bt_update_transfer_list_view(BT_OUTBOUND_TABLE);
+ } else {
+ _bt_share_block_sleep(TRUE);
+ _bt_set_transfer_indicator(TRUE);
+ }
+ break;
+
+ case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
+ DBG("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED \n");
+
+ ret_if(node == NULL);
+ name = __get_file_name(send_index++, node->file_path);
+ snprintf(opc_cnt, sizeof(opc_cnt), "%d/%d",
+ send_index, node->file_cnt);
+
+ if (ad->opc_noti) {
+ _bt_delete_notification(ad->opc_noti);
+ ad->opc_noti = NULL;
+ ad->opc_noti_id = 0;
+ }
+
+ noti = _bt_create_notification(BT_ONGOING_T);
+ _bt_set_notification_property(noti, QP_NO_TICKER);
+ ad->opc_noti_id = _bt_insert_notification(noti,
+ name, opc_cnt,
+ BT_ICON_QP_SEND);
+ _bt_set_notification_app_launch(noti, CREATE_PROGRESS,
+ NOTI_TR_TYPE_OUT, name, opc_cnt);
+ _bt_update_notification(noti, NULL, NULL, NULL);
+
+ ad->opc_noti = noti;
+
+ if (ad->tr_next_data == NULL) {
+ ERR("ad->tr_next_data is NULL \n");
+ break;
+ }
+
+ info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+ if (info == NULL)
+ break;
+
+ ad->current_tr_uid = info->id;
+ DBG("ad->current_tr_uid = [%d] \n", ad->current_tr_uid);
+ break;
+
+ case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
+ client_info = (bt_opc_transfer_info_t *)param->param_data;
+ ret_if(client_info == NULL);
+
+ name = strrchr(client_info->filename, '/');
+ if (name)
+ name++;
+ else
+ name = client_info->filename;
+
+ percentage = client_info->percentage;
+ _bt_update_notification_progress(NULL,
+ ad->opc_noti_id, percentage);
+ _bt_send_message_to_ui(ad->opc_noti_id, name, percentage,
+ FALSE, BLUETOOTH_ERROR_NONE);
+ break;
+
+ case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
+ DBG("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE \n");
+ client_info = (bt_opc_transfer_info_t *)param->param_data;
+ ret_if(client_info == NULL);
+
+ DBG("client_info->filename = [%s] \n", client_info->filename);
+ DBG("ad->current_tr_uid = [%d] \n", ad->current_tr_uid);
+
+ name = strrchr(client_info->filename, '/');
+ if (name)
+ name++;
+ else
+ name = client_info->filename;
+
+ DBG("name address = [%x] \n", name);
+
+ _bt_send_message_to_ui(ad->opc_noti_id, name, 100, TRUE, param->result);
+
+ _bt_delete_notification(ad->opc_noti);
+ ad->opc_noti = NULL;
+ ad->opc_noti_id = 0;
+
+ DBG("ad->send_data.tr_fail = %d, ad->send_data.tr_success= %d \n",
+ ad->send_data.tr_fail, ad->send_data.tr_success);
+
+ if (param->result != BLUETOOTH_ERROR_NONE)
+ ad->send_data.tr_fail++;
+ else
+ ad->send_data.tr_success++;
+
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->send_data.tr_success,
+ ad->send_data.tr_fail);
+
+ DBG("str = [%s] \n", str);
+
+ if (ad->send_noti == NULL) {
+ noti = _bt_create_notification(BT_NOTI_T);
+ _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
+ NOTI_TR_TYPE_OUT, NULL, NULL);
+ _bt_set_notification_property(noti, QP_NO_DELETE);
+ _bt_insert_notification(noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ ad->send_noti = noti;
+ } else {
+ _bt_update_notification(ad->send_noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ }
+
+ if (param->result != BLUETOOTH_ERROR_NONE) {
+ _bt_update_sent_data_status(ad->current_tr_uid,
+ BT_TR_FAIL);
+ _bt_create_warning_popup(param->result);
+ } else {
+ _bt_update_sent_data_status(ad->current_tr_uid,
+ BT_TR_SUCCESS);
+ }
+ _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:
+ DBG("BLUETOOTH_EVENT_OPC_DISCONNECTED \n");
+
+ ret_if(node == NULL);
+
+ if (node->file_cnt > send_index) {
+ info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+ if (info == NULL)
+ break;
+ s_id = info->sid;
+ DBG("info->sid = %d info->id = %d\n", info->sid, info->id);
+
+ while (NULL != ad->tr_next_data) {
+ info = (bt_tr_data_t *)(ad->tr_next_data)->data;
+ if (info == NULL)
+ break;
+ DBG("info->sid = %d info->id = %d\n", info->sid, info->id);
+
+ if (s_id != info->sid) {
+ DBG("SID did not match so break done.\n");
+ break;
+ }
+
+ _bt_update_sent_data_status(info->id, BT_TR_FAIL);
+ ad->send_data.tr_fail++;
+ ad->tr_next_data = g_slist_next(ad->tr_next_data);
+ }
+
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->send_data.tr_success,
+ ad->send_data.tr_fail);
+
+ DBG("str = [%s] \n", str);
+
+ if (ad->send_noti == NULL) {
+ noti = _bt_create_notification(BT_NOTI_T);
+ _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
+ NOTI_TR_TYPE_OUT, NULL, NULL);
+ _bt_set_notification_property(noti, QP_NO_DELETE);
+ _bt_insert_notification(noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ ad->send_noti = noti;
+ } else {
+ _bt_update_notification(ad->send_noti,
+ BT_STR_SEND_NOTI, str,
+ BT_ICON_QP_SEND);
+ }
+ }
+
+ send_index = 0;
+ _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;
+ }
+ break;
+
+ case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
+ DBG("BT_EVENT_OBEX_TRANSFER_AUTHORIZE \n");
+ if (param->result == BLUETOOTH_ERROR_NONE) {
+ g_free(server_auth_info.filename);
+ server_auth_info.filename = NULL;
+
+ auth_info = param->param_data;
+ server_auth_info.filename = g_strdup(auth_info->filename);
+ server_auth_info.length = auth_info->length;
+ if (server_auth_info.filename)
+ __bt_obex_file_push_auth(&server_auth_info);
+ }
+ break;
+
+ case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
+ DBG("BT_EVENT_OBEX_TRANSFER_STARTED \n");
+ transfer_info = param->param_data;
+
+ DBG(" %s \n", transfer_info->type);
+ noti = _bt_create_notification(BT_ONGOING_T);
+ _bt_set_notification_property(noti, QP_NO_TICKER);
+ if (0 == g_strcmp0(transfer_info->type, TRANSFER_GET)) {
+ noti_id = _bt_insert_notification(noti,
+ transfer_info->filename, NULL,
+ BT_ICON_QP_SEND);
+ _bt_set_notification_app_launch(noti, CREATE_PROGRESS,
+ NOTI_TR_TYPE_IN, transfer_info->filename, NULL);
+ _bt_update_notification_progress(NULL,
+ noti_id, 0);
+ _bt_update_notification(noti, NULL, NULL, NULL);
+ } else {
+ noti_id = _bt_insert_notification(noti,
+ transfer_info->filename, NULL,
+ BT_ICON_QP_RECEIVE);
+ _bt_set_notification_app_launch(noti, CREATE_PROGRESS,
+ NOTI_TR_TYPE_IN, transfer_info->filename, NULL);
+ _bt_update_notification(noti, NULL, NULL, NULL);
+ }
+
+ data = g_new0(bt_noti_data_t, 1);
+ data->noti_handle = noti;
+ data->noti_id = noti_id;
+ data->transfer_id = transfer_info->transfer_id;
+
+ bt_receive_noti_list = g_slist_append(bt_receive_noti_list, data);
+
+ _bt_set_transfer_indicator(TRUE);
+ _bt_share_block_sleep(TRUE);
+ break;
+
+ case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
+ DBG("BT_EVENT_OBEX_TRANSFER_PROGRESS \n");
+ if (param->result == BLUETOOTH_ERROR_NONE) {
+ transfer_info = param->param_data;
+
+ data = __bt_get_noti_data_by_transfer_id(transfer_info->transfer_id);
+
+ _bt_update_notification_progress(NULL,
+ data->noti_id,
+ transfer_info->percentage);
+
+ _bt_send_message_to_ui(data->noti_id,
+ transfer_info->filename,
+ transfer_info->percentage,
+ FALSE, BLUETOOTH_ERROR_NONE);
+ }
+ break;
+
+ case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
+ DBG("BT_EVENT_OBEX_TRANSFER_COMPLETED \n");
+ transfer_info = param->param_data;
+ _bt_share_block_sleep(FALSE);
+ _bt_set_transfer_indicator(FALSE);
+
+ data = __bt_get_noti_data_by_transfer_id(transfer_info->transfer_id);
+
+ if (data) {
+ _bt_send_message_to_ui(data->noti_id,
+ transfer_info->filename,
+ transfer_info->percentage, TRUE, param->result);
+
+ if (param->result == BLUETOOTH_ERROR_NONE) {
+ _bt_obex_writeclose(param->param_data);
+ _bt_update_notification_progress(NULL,
+ data->noti_id, 100);
+ } else {
+ DBG("param->result = %d \n", param->result);
+ _bt_create_warning_popup(param->result);
+ }
+
+
+ _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 (param->result != BLUETOOTH_ERROR_NONE) {
+ ad->recv_data.tr_fail++;
+ _bt_add_recv_transfer_status_data(
+ transfer_info->device_name,
+ transfer_info->filename,
+ BT_TR_FAIL);
+ } else {
+ ad->recv_data.tr_success++;
+ _bt_add_recv_transfer_status_data(
+ transfer_info->device_name,
+ transfer_info->filename,
+ BT_TR_SUCCESS);
+ }
+
+ snprintf(str, sizeof(str), BT_TR_STATUS,
+ ad->recv_data.tr_success, ad->recv_data.tr_fail);
+ DBG("str = [%s] \n", str);
+
+ if (ad->receive_noti == NULL) {
+ noti = _bt_create_notification(BT_NOTI_T);
+ _bt_set_notification_app_launch(noti, CREATE_TR_LIST,
+ NOTI_TR_TYPE_IN, NULL, NULL);
+ _bt_set_notification_property(noti, QP_NO_DELETE);
+ _bt_insert_notification(noti,
+ BT_STR_RECEIVED_NOTI, str,
+ BT_ICON_QP_RECEIVE);
+ ad->receive_noti = noti;
+ } else {
+ _bt_update_notification(ad->receive_noti,
+ BT_STR_RECEIVED_NOTI, str,
+ BT_ICON_QP_RECEIVE);
+ }
+ }
+
+ _bt_update_transfer_list_view(BT_INBOUND_TABLE);
+ break;
+
+ default:
+ DBG("Unhandled event %x", event);
+ break;
+ }
+
+}
+
+void _bt_get_default_storage(char *storage)
+{
+ int val = -1;
+ if (-1 == vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, (void *)&val)) {
+ DBG("vconf error\n");
+ val = 0;
+ }
+ if (val == 0) /* Phone memory is 0, MMC is 1 */
+ g_strlcpy(storage, BT_DOWNLOAD_PHONE_FOLDER, STORAGE_PATH_LEN_MAX);
+ else
+ g_strlcpy(storage, BT_DOWNLOAD_MMC_FOLDER, STORAGE_PATH_LEN_MAX);
+ DBG("Default storage : %s\n", 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;
+
+ DBG("response : %d\n", (int)event_info);
+
+ if ((int)event_info == POPUP_RESPONSE_OK) {
+ DBG("OK button pressed \n");
+ bluetooth_obex_server_accept_authorize(server_auth_info->filename);
+ } else if ((int)event_info == POPUP_RESPONSE_CANCEL) {
+ bluetooth_obex_server_reject_authorize();
+ }
+ return;
+}
+
+static gboolean __bt_get_available_memory(long *available_mem_size)
+{
+ struct statfs fs = {0, };
+ int val = -1;
+ char *default_memory = NULL;
+
+ if (-1 == vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
+ (void *)&val)) {
+ ERR("vconf error\n");
+ return FALSE;
+ }
+ if (val == 0) /* Phone memory is 0, MMC is 1 */
+ default_memory = BT_DOWNLOAD_MEDIA_FOLDER;
+ else
+ default_memory = BT_DOWNLOAD_MMC_FOLDER;
+ if (statfs(default_memory, &fs) != 0) {
+ *available_mem_size = 0;
+ return FALSE;
+ }
+ *available_mem_size = fs.f_bavail * (fs.f_bsize/1024);
+ return TRUE;
+}
+
+gboolean _bt_app_obex_openwrite_requested(bt_obex_server_authorize_into_t
+ *server_auth_info)
+{
+ char temp_filename[BT_FILE_PATH_LEN_MAX] = { 0, };
+ bt_app_sys_popup_params_t popup_params = { NULL };
+ char storage[STORAGE_PATH_LEN_MAX] = { 0, };
+
+ /* Check if file is already present */
+ _bt_get_default_storage(storage);
+
+ snprintf(temp_filename, BT_FILE_PATH_LEN_MAX, "%s/%s",
+ storage, server_auth_info->filename);
+
+ if (access(temp_filename, F_OK) == 0) {
+ DBG("opp_info->file_info.file_name = %s is already exsist\n",
+ server_auth_info->filename);
+
+ /*File exsists: Ask the user if he wants to download the file */
+ popup_params.file = server_auth_info->filename;
+ popup_params.type = "twobtn";
+ _bt_launch_system_popup(BT_APP_EVENT_OVERWRITE_REQUEST,
+ &popup_params,
+ _bt_app_obex_download_dup_file_cb,
+ server_auth_info);
+ } else {
+ bluetooth_obex_server_accept_authorize(server_auth_info->filename);
+ }
+ return FALSE;
+}
+
+static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t *server_auth_info)
+{
+ long available_mem_size = 0;
+
+ DBG("+\n");
+
+ if (__bt_get_available_memory(&available_mem_size) == FALSE) {
+ ERR("Unable to get available memory size\n");
+ goto reject;
+ }
+ if (available_mem_size < server_auth_info->length / 1024) {
+ g_timeout_add(BT_APP_POPUP_LAUNCH_TIMEOUT,
+ (GSourceFunc)_bt_app_popup_memoryfull,
+ NULL);
+ goto reject;
+ }
+
+ DBG("Check for overwrite. \n");
+ /* Two popups back to back. So add a timeout */
+ g_timeout_add(BT_APP_POPUP_LAUNCH_TIMEOUT,
+ (GSourceFunc)_bt_app_obex_openwrite_requested,
+ server_auth_info);
+
+ return;
+
+reject:
+ bluetooth_obex_server_reject_authorize();
+
+ DBG("-\n");
+ return;
+}
+
+static bt_file_type_t __get_file_type(char *extn)
+{
+ DBG("exten : %s \n", extn);
+
+ 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;
+ }
+ return BT_FILE_OTHER;
+}
+
+static bool __bt_vcard_handler(contacts_record_h record, void *user_data)
+{
+ int ret;
+
+ ret = contacts_db_insert_record(record, NULL);
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("contacts_svc_insert_vcard error : %d\n", ret);
+ }
+
+ return true;
+}
+
+static bool __bt_vcalendar_handler(calendar_record_h record, void *user_data)
+{
+ int ret;
+
+ ret = calendar_db_insert_record(record, NULL);
+ if (ret != CALENDAR_ERROR_NONE) {
+ ERR("calendar_db_insert_record error : %d\n", ret);
+ }
+
+ return true;
+}
+
+static gboolean __bt_save_v_object(char *file_path,
+ bt_file_type_t file_type)
+{
+ retv_if(NULL == file_path, FALSE);
+ int ret;
+
+ DBG("file_path = %s, file_type = %d\n", file_path, file_type);
+
+ switch (file_type) {
+ case BT_FILE_VCARD:
+ ret = contacts_connect2();
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("contacts_connect2 error = %d \n", ret);
+ return FALSE;
+ }
+
+ ret = contacts_vcard_parse_to_contact_foreach(file_path,
+ __bt_vcard_handler, NULL);
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("[error] = %d \n", ret);
+ ret = contacts_disconnect2();
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("contacts_disconnect2 error = %d \n", ret);
+ }
+ return FALSE;
+ }
+
+ ret = contacts_disconnect2();
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("contacts_disconnect2 error = %d \n", ret);
+ return FALSE;
+ }
+ break;
+
+ case BT_FILE_VCAL:
+ ret = calendar_connect();
+ if (ret != CALENDAR_ERROR_NONE) {
+ ERR("calendar_connect error = %d \n", ret);
+ return FALSE;
+ }
+
+ ret = calendar_vcalendar_parse_to_calendar_foreach(file_path,
+ __bt_vcalendar_handler, NULL);
+ if (ret != CALENDAR_ERROR_NONE) {
+ ERR("[error] = %d \n", ret);
+ ret = calendar_disconnect();
+ if ( ret != CALENDAR_ERROR_NONE) {
+ ERR("calendar_disconnect error = %d \n", ret);
+ }
+ return FALSE;
+ }
+ ret = calendar_disconnect();
+ if (ret != CALENDAR_ERROR_NONE) {
+ ERR("calendar_disconnect error = %d \n", ret);
+ return FALSE;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ 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;
+}
+
+gboolean _bt_obex_writeclose(bt_obex_server_transfer_info_t *transfer_complete_info)
+{
+ char file_path[BT_TEMP_FILE_PATH_LEN_MAX] = { 0, };
+ bt_file_type_t file_type = 0;
+ char *extn = NULL;
+ char storage[STORAGE_PATH_LEN_MAX] ={0, };
+
+ retv_if(transfer_complete_info->filename == NULL, FALSE);
+
+
+ DBG("File name[%s], File name length = [%d]\n",
+ transfer_complete_info->filename,
+ strlen(transfer_complete_info->filename));
+
+ extn = strrchr(transfer_complete_info->filename, '.');
+ if (NULL != extn)
+ extn++;
+ DBG("====== : %s\n", extn);
+ file_type = __get_file_type(extn);
+ DBG("file type : %d\n", file_type);
+
+ _bt_get_default_storage(storage);
+ snprintf(file_path, sizeof(file_path), "%s/%s", storage,
+ transfer_complete_info->filename);
+
+ DBG("BT_OPP_FILE_SAVE : file_path = %s\n", file_path);
+
+ switch (file_type) {
+ case BT_FILE_VCARD:
+ case BT_FILE_VCAL:
+ case BT_FILE_VBOOKMARK:
+ if (__bt_save_v_object(file_path, file_type) == FALSE) {
+ ecore_file_remove(file_path);
+ } else {
+ __bt_scan_media_file(file_path);
+ }
+ break;
+ default:
+ __bt_scan_media_file(file_path);
+ break;
+ }
+ return TRUE;
+}
+
--- /dev/null
+[D-BUS Service]
+Name=org.bluetooth.share
+Exec=/usr/bin/bluetooth-share
--- /dev/null
+/usr/include/bluetooth-share/*
+/usr/lib/pkgconfig/*
--- /dev/null
+@PREFIX@/bin/*
+/opt/share/bt-ftp
+/usr/share/dbus-1/services/*.service
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+if [ ! -f /opt/dbspace/.bluetooth_trasnfer.db ]
+then
+ sqlite3 /opt/dbspace/.bluetooth_trasnfer.db 'PRAGMA journal_mode = PERSIST;
+ create table if not exists inbound (
+ id INTEGER PRIMARY KEY autoincrement,
+ tr_status INTEGER,
+ file_path TEXT,
+ dev_name TEXT,
+ timestamp INTEGER default 0,
+ addr TEXT
+ );
+ create table if not exists outbound (
+ id INTEGER PRIMARY KEY autoincrement,
+ tr_status INTEGER,
+ file_path TEXT,
+ dev_name TEXT,
+ timestamp INTEGER default 0,
+ addr TEXT
+ );
+ '
+fi
+
+# root case
+if [ ${USER} == "root" ]
+then
+ # Set vconf values with -g/-u options
+
+ # 5000 is inhouse user id
+ # do not use relative path
+
+ # For the FTP server folder
+
+ if [ ! -e /opt/share/bt-ftp/Media ]
+ then
+ ln -s /opt/media /opt/share/bt-ftp/Media
+ fi
+
+ if [ ! -e /opt/share/bt-ftp/SD_External ]
+ then
+ ln -s /opt/storage/sdcard /opt/share/bt-ftp/SD_External
+ fi
+
+ vconftool set -t bool memory/private/bluetooth-share/quickpanel_clear_btn_status FALSE -g 6520 -i
+ vconftool set -t bool memory/private/bluetooth-share/opp_server_init FALSE -g 6520 -i
+
+ chown :5000 /opt/dbspace/.bluetooth_trasnfer.db
+ chown :5000 /opt/dbspace/.bluetooth_trasnfer.db-journal
+fi
+
+chmod 660 /opt/dbspace/.bluetooth_trasnfer.db
+chmod 660 /opt/dbspace/.bluetooth_trasnfer.db-journal
--- /dev/null
+bluetooth-share (0.0.46) unstable; urgency=low
+
+ * Tagging and Uploading package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.46
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Wed, 12 Dec 2012 10:06:29 +0900
+
+bluetooth-share (0.0.45) unstable; urgency=low
+
+ * Tagging and Uploading package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.45
+
+ -- Sunil Kumar Behera <sunil.behera@samsung.com> Wed, 28 Nov 2012 19:11:47 +0530
+
+bluetooth-share (0.0.44) unstable; urgency=low
+
+ * Change the media update method
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.44
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Mon, 26 Nov 2012 13:02:41 +0900
+
+bluetooth-share (0.0.43) unstable; urgency=low
+
+ * Modify the manifast
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.43
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Thu, 22 Nov 2012 11:28:29 +0900
+
+bluetooth-share (0.0.42) unstable; urgency=low
+
+ * Modify the manifast
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.42
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Wed, 21 Nov 2012 13:02:00 +0900
+
+bluetooth-share (0.0.41) unstable; urgency=low
+
+ * Fix the bug about notification
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.41
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Fri, 16 Nov 2012 10:51:28 +0900
+
+bluetooth-share (0.0.40) unstable; urgency=low
+
+ * Modify the notification API
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.40
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Thu, 15 Nov 2012 18:09:24 +0900
+
+bluetooth-share (0.0.39) unstable; urgency=low
+
+ * Change the contact API
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.39
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 13 Nov 2012 10:46:00 +0900
+
+bluetooth-share (0.0.38) unstable; urgency=low
+
+ * Fix the build break
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.38
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Thu, 08 Nov 2012 14:44:16 +0900
+
+bluetooth-share (0.0.37) unstable; urgency=low
+
+ * Fix the JIRA issue
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.37
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 06 Nov 2012 15:55:39 +0900
+
+bluetooth-share (0.0.36) unstable; urgency=low
+
+ * Add -pie compile option
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.36
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Wed, 31 Oct 2012 15:27:26 +0900
+
+bluetooth-share (0.0.35) unstable; urgency=low
+
+ * Fix for retry file send crash issue
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.35
+
+ -- Chethan T N <chethan.tn@samsung.com> Fri, 26 Oct 2012 17:26:55 +0530
+
+bluetooth-share (0.0.34) unstable; urgency=low
+
+ * Change directory path
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.34
+
+ -- InJun Yang <injun.yang@samsung.com> Thu, 25 Oct 2012 13:56:00 +0900
+
+bluetooth-share (0.0.33) unstable; urgency=low
+
+ * Fix the bug abt abnormal termination
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.33
+
+ -- InJun Yang <injun.yang@samsung.com> Fri, 19 Oct 2012 17:38:30 +0900
+
+bluetooth-share (0.0.32) unstable; urgency=low
+
+ * Fix the bug about OPP server
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.32
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Thu, 18 Oct 2012 09:40:09 +0900
+
+bluetooth-share (0.0.31) unstable; urgency=low
+
+ * Fix the bug about OPP server
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.31
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Fri, 12 Oct 2012 15:06:22 +0900
+
+bluetooth-share (0.0.30) unstable; urgency=low
+
+ * Change SMACK domain name
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.30
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Mon, 26 Nov 2012 14:42:28 +0900
+
+bluetooth-share (0.0.28) unstable; urgency=low
+
+ * Change SMACK domain name
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.28
+
+ -- Sangki Park <sangki79.park@samsung.com> Tue, 25 Sep 2012 10:27:55 +0900
+
+bluetooth-share (0.0.27) unstable; urgency=low
+
+ * Apply smack manifest file
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.27
+
+ -- Sangki Park <sangki79.park@samsung.com> Fri, 21 Sep 2012 10:03:02 +0900
+
+bluetooth-share (0.0.26) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.26
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 11 Sep 2012 11:05:27 +0900
+
+bluetooth-share (0.0.25) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.25
+
+ -- InJun Yang <injun.yang@samsung.com> Tue, 07 Aug 2012 12:38:33 +0900
+
+bluetooth-share (0.0.24) unstable; urgency=low
+
+ * Fix the PLM issue abt clear button of notification bar
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.24
+
+ -- InJun Yang <injun.yang@samsung.com> Fri, 20 Jul 2012 18:44:33 +0900
+
+bluetooth-share (0.0.23) unstable; urgency=low
+
+ * Tagging and upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.23
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Fri, 20 Jul 2012 13:36:44 +0900
+
+bluetooth-share (0.0.22) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.22
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 17 Jul 2012 10:27:35 +0900
+
+bluetooth-share (0.0.21) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.21
+
+ -- InJun Yang <injun.yang@samsung.com> Tue, 10 Jul 2012 19:26:52 +0900
+
+bluetooth-share (0.0.20) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.20
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 10 Jul 2012 17:55:02 +0900
+
+bluetooth-share (0.0.19) unstable; urgency=low
+
+ * Ordered by timestamp
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.19
+
+ -- InJun Yang <injun.yang@samsung.com> Tue, 10 Jul 2012 08:57:19 +0900
+
+bluetooth-share (0.0.18) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.18
+
+ -- InJun Yang <injun.yang@samsung.com> Fri, 06 Jul 2012 20:09:04 +0900
+
+bluetooth-share (0.0.17) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.17
+
+ -- InJun Yang <injun.yang@samsung.com> Wed, 20 Jun 2012 20:45:27 +0900
+
+bluetooth-share (0.0.16) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.16
+
+ -- InJun Yang <injun.yang@samsung.com> Fri, 15 Jun 2012 18:45:52 +0900
+
+bluetooth-share (0.0.15) unstable; urgency=low
+
+ * Modify the sending flow as UX guideline
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.15
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Mon, 04 Jun 2012 08:59:20 +0900
+
+bluetooth-share (0.0.14) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.14
+
+ -- InJun Yang <injun.yang@samsung.com> Tue, 29 May 2012 17:47:33 +0900
+
+bluetooth-share (0.0.13) unstable; urgency=low
+
+ * Add db script to postinst file
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.13
+
+ -- InJun Yang <injun.yang@samsung.com> Thu, 24 May 2012 13:05:43 +0900
+
+bluetooth-share (0.0.12) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.12
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Wed, 23 May 2012 12:16:47 +0900
+
+bluetooth-share (0.0.11) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.11
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 22 May 2012 09:45:06 +0900
+
+bluetooth-share (0.0.10) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.10
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Mon, 21 May 2012 11:06:30 +0900
+
+bluetooth-share (0.0.9) unstable; urgency=low
+
+ * Fix the auto activating issue
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.9
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Wed, 16 May 2012 11:36:34 +0900
+
+bluetooth-share (0.0.8) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.8
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Tue, 08 May 2012 08:56:03 +0900
+
+bluetooth-share (0.0.7) unstable; urgency=low
+
+ * Upload the package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.7
+
+ -- InJun Yang <injun.yang@samsung.com> Thu, 22 Mar 2012 16:48:32 +0900
+
+bluetooth-share (0.0.6) unstable; urgency=low
+
+ * Increase the version number to upload.
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.6
+
+ -- Sunil Kumar Behera <sunil.behera@samsung.com> Tue, 21 Feb 2012 14:09:43 +0530
+
+bluetooth-share (0.0.5) unstable; urgency=low
+
+ * FIx the spelling of API name (sessioin -> session)
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.5
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Thu, 05 Jan 2012 17:55:10 +0900
+
+bluetooth-share (0.0.4) unstable; urgency=low
+
+ * Upload package
+ * Git: slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.4
+
+ -- DoHyun Pyun <dh79.pyun@samsung.com> Fri, 30 Dec 2011 08:01:56 +0900
+
+bluetooth-share (0.0.3) unstable; urgency=low
+
+ * Upload package
+ * Git: 165.213.180.234:slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.3
+
+ -- InJun Yang <injun.yang@samsung.com> Wed, 30 Nov 2011 10:24:29 +0900
+
+bluetooth-share (0.0.2) unstable; urgency=low
+
+ * Upload package
+ * Git: 165.213.180.234:slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.2
+
+ -- InJun Yang <injun.yang@samsung.com> Wed, 09 Nov 2011 08:50:32 +0900
+
+bluetooth-share (0.0.1) unstable; urgency=low
+
+ * initial release
+ * Git: 165.213.180.234:slp/pkgs/b/bluetooth-share
+ * Tag: bluetooth-share_0.0.1
+
+ -- Injun Yang <injun.yang@samsung.com> Fri, 23 Sep 2011 16:17:49 +0900
--- /dev/null
+Source: bluetooth-share
+Section: net
+Priority: extra
+Maintainer: Hocheol Seo <hocheol.seo@samsung.com>, DoHyun Pyun <dh79.pyun@samsung.com>, ChanYeol Park <chanyeol.park@samsung.com>, InJun Yang <injun.yang@samsung.com>, Seungyoun Ju <sy39.ju@samsung.com>
+Uploaders: Sunil Behera <sunil.behera@samsung.com>, Syam Sidhardhan <s.syam@samsung.com>
+Build-Depends: debhelper (>= 5), libbluetooth-frwk-dev, libglib2.0-dev, libdbus-1-dev, libdbus-glib-1-dev, libappcore-common-dev, libaul-1-dev, dlog-dev, syspopup-caller-dev, libappsvc-dev, libbundle-dev, libnotification-dev, libslp-calendar-dev, libcontacts-service-dev, libslp-pm-dev, libslp-sysman-dev, libx11-dev, libappcore-efl-dev, libslp-db-util-dev, libprivilege-control-dev
+Standards-Version: 3.7.2
+
+Package: bluetooth-share
+Section: application
+Provides:bluetooth-app-headers
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends},libbluetooth-frwk-0, libaul-1, libdlog-0
+Description: Bluetooth File Share Agent
+
+Package: bluetooth-share-dbg
+Section: debug
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, bluetooth-share (= ${Source-Version})
+Description: Bluetooth file share Agent (unstripped)
+
+Package: libbluetooth-share
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Bluetooth Share library
+
+Package: libbluetooth-share-dev
+Section: devel
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends},dlog-dev, libdbus-glib-1-dev, libglib2.0-dev, libbluetooth-share (= ${Source-Version})
+XB-Generate-Docs: yes
+Description: Bluetooth Share
--- /dev/null
+/usr/include/*
+/usr/lib/pkgconfig/*
--- /dev/null
+/usr/lib/lib*
--- /dev/null
+#!/usr/bin/make -f
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+PREFIX ?= /usr
+#RESDIR ?= /usr/bin/bluetooth-share/res
+#DATADIR ?= /usr/bin/bluetooth-share/data
+CFLAGS ?= -Wall -g
+LDFLAGS ?=
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+
+CFLAGS += -fpie
+LDFLAGS += -pie -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -Wl,--unresolved-symbols=ignore-in-shared-libs
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ # Add here commands to configure the package.
+ CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
+ cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX)
+ touch configure-stamp
+
+
+build: build-stamp
+
+build-stamp: configure-stamp
+ dh_testdir
+
+ # Add here commands to compile the package.
+ $(MAKE)
+ #docbook-to-man debian/bluetooth.sgml > bluetooth.1
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ cat $$f > $${f%.in}; \
+ sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+ done
+
+ touch $@
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+
+ # Add here commands to clean up after the build process.
+ -$(MAKE) clean
+
+ for f in `find $(CURDIR)/ -name "CMakeCache.txt"`; do \
+ rm -f $${f}; \
+ done
+ for f in `find $(CURDIR)/ -name "CMakeFiles"`; do \
+ rm -rf $${f}; \
+ done
+ for f in `find $(CURDIR)/ -name "cmake_install.cmake"`; do \
+ rm -f $${f}; \
+ done
+ for f in `find $(CURDIR)/ -name "Makefile"`; do \
+ rm -f $${f}; \
+ done
+ for f in `find $(CURDIR)/ -name "install_manifest.txt"`; do \
+ rm -f $${f}; \
+ done
+ for f in `find $(CURDIR)/ -name "*.edj"`; do \
+ rm -f $${f}; \
+ done
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ rm -f $${f%.in}; \
+ done
+
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/tmp.
+ $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+ mkdir -p $(CURDIR)/debian/tmp/opt/share/bt-ftp
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+# dh_installchangelogs
+# dh_installdocs
+# dh_installexamples
+ dh_install --sourcedir=debian/tmp
+# dh_installman
+ dh_link
+ dh_strip --dbg-package=bluetooth-share-dbg
+ dh_compress
+ dh_fixperms
+# dh_perl
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(bluetooth-share-api C)
+
+SET(SRCS bt-share-db.c
+)
+SET(HEADERS bluetooth-share-api.h)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(apipkgs REQUIRED glib-2.0 db-util dlog)
+
+FOREACH(flag ${apipkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "/usr/include")
+SET(VERSION 1.0)
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION 0.1.0)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${apipkgs_LDFLAGS})
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)
+
+FOREACH(hfile ${HEADERS})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/bluetooth-share-api)
+ENDFOREACH(hfile)
+
--- /dev/null
+/*
+ * bluetooth-share-api
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __APPLOG_H__
+#define __APPLOG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * SYSLOG_INFO(), SYSLOG_ERR(), SYSLOG_DBG() are syslog() wrappers.
+ * PRT_INFO(), PRT_ERR(), PRT_DBG() are fprintf() wrappers.
+ *
+ * If SLP_DEBUG is not defined, SYSLOG_DBG() and PRT_DBG() is ignored.
+ *
+ * IF SLP_SYSLOG_OUT or SLP_DAEMON is defined,
+ * INFO(), ERR(), DBG() are SYSLOG_XXX()
+ * Otherwise,
+ * They are PRT_XXX()
+ *
+ *
+ * warn_if(exrp, fmt, ...)
+ * If expr is true, The fmt string is printed using ERR().
+ *
+ * ret_if(), retv_if(), retm_if(), retvm_if()
+ * If expr is true, current function return.
+ * Postfix 'v' means that it has a return value and
+ * 'm' means that it has output message.
+ *
+ */
+
+#if defined(SLP_SYSLOG_OUT) || defined(SLP_DAEMON)
+#include <syslog.h>
+#endif
+#include <stdio.h>
+#include <dlog.h>
+
+#if defined(SLP_SYSLOG_OUT) || defined(SLP_DAEMON)
+#define __LOG(prio, fmt, arg...) \
+ do { syslog(prio, fmt, ##arg); } while (0)
+
+#define __LOGD(prio, fmt, arg...) \
+ do {
+ syslog(prio, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg);
+ } while (0)
+#else
+#define __LOG(prio, fmt, arg...) do { } while (0)
+#define __LOGD(prio, fmt, arg...) do { } while (0)
+#endif
+
+#define __PRT(prio, fmt, arg...) \
+ do { \
+ fprintf((LOG_PRI(prio) == LOG_ERR ? stderr : stdout), \
+ fmt"\n", ##arg); \
+ } while (0)
+
+#define __PRTD(prio, fmt, arg...) \
+ do { \
+ fprintf((LOG_PRI(prio) == LOG_ERR ? stderr : stdout), \
+ "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \
+ } while (0)
+#define _NOUT (prio, fmt, arg...) do { } while (0)
+
+#ifdef SLP_DEBUG
+#define _LOGD __LOGD
+#define _LOG __LOGD
+#define _PRTD __PRTD
+#define _PRT __PRTD
+#else
+#define _LOGD _NOUT
+#define _LOG __LOG
+#define _PRTD _NOUT
+#define _PRT __PRT
+#endif
+
+#define SYSLOG_INFO(fmt, arg...) _LOG(LOG_INFO, fmt, ##arg)
+#define SYSLOG_ERR(fmt, arg...) _LOG(LOG_ERR, fmt, ##arg)
+#define SYSLOG_DBG(fmt, arg...) _LOGD(LOG_DEBUG, fmt, ##arg)
+
+#define PRT_INFO(fmt, arg...) \
+ LOG(LOG_DEBUG, BT_SHARE, "%s:%d "fmt, __func__, __LINE__, ##arg)
+
+#define PRT_ERR(fmt, arg...) \
+ LOG(LOG_DEBUG, BT_SHARE, "%s:%d "fmt, __func__, __LINE__, ##arg)
+
+#define PRT_DBG(fmt, arg...) \
+ LOG(LOG_DEBUG, BT_SHARE, "%s:%d "fmt, __func__, __LINE__, ##arg)
+
+#define BT_SHARE "BT_SHARE"
+
+
+#if defined(SLP_SYSLOG_OUT) || defined(SLP_DAEMON)
+#define INFO SYSLOG_INFO
+#define ERR SYSLOG_ERR
+#define DBG SYSLOG_DBG
+#else
+#define INFO(fmt, arg...) \
+ SLOG(LOG_DEBUG, BT_SHARE, "%s:%d "fmt, __func__, __LINE__, ##arg)
+
+#define ERR(fmt, arg...) \
+ SLOG(LOG_DEBUG, BT_SHARE, "%s:%d "fmt, __func__, __LINE__, ##arg)
+
+#define DBG(fmt, arg...) \
+ SLOG(LOG_DEBUG, BT_SHARE, "%s:%d "fmt, __func__, __LINE__, ##arg)
+#endif
+
+#ifdef SLP_DEBUG
+#define warn_if(expr, fmt, arg...) do { \
+ if (expr) { \
+ ERR("(%s) -> "fmt, #expr, ##arg); \
+ } \
+ } while (0)
+#define ret_if(expr) do { \
+ if (expr) { \
+ ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return; \
+ } \
+ } while (0)
+#define retv_if(expr, val) do { \
+ if (expr) { \
+ ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return (val); \
+ } \
+ } while (0)
+#define retm_if(expr, fmt, arg...) do { \
+ if (expr) { \
+ ERR(fmt, ##arg); \
+ ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return; \
+ } \
+ } while (0)
+#define retvm_if(expr, val, fmt, arg...) do { \
+ if (expr) { \
+ ERR(fmt, ##arg); \
+ ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return (val); \
+ } \
+ } while (0)
+
+#else
+#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); \
+ return (val); \
+ } \
+ } while (0)
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __APPLOG_H__ */
--- /dev/null
+/*
+ * bluetooth-share-api
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __DEF_BLUETOOTH_SHARE_API_H_
+#define __DEF_BLUETOOTH_SHARE_API_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <db-util.h>
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+enum {
+ BT_SHARE_ERR_NONE = 0,
+ BT_SHARE_ERR_INTERNAL = -1,
+ BT_SHARE_ERR_INVALID_PARAM = -2,
+ BT_SHARE_ERR_UNKNOWN = -3
+}bt_share_err_e;
+
+
+typedef struct {
+ unsigned int id;
+ unsigned int sid;
+ unsigned int tr_status;
+ int timestamp;
+ char *file_path;
+ char *dev_name;
+ char *addr;
+}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_update_tr_data(sqlite3 *db, int db_table, int id, 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 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_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_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);
+
+EXPORT_API int bt_share_remove_all_tr_data(sqlite3 *db, int db_table);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BLUETOOTH_SHARE_API_H_ */
--- /dev/null
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: bluetooth-share-api
+Description: SAMSUNG Linux platform Bluetooth share API
+Version: @VERSION@
+Requires: dlog dbus-glib-1 vconf
+Libs: -L${libdir} -lbluetooth-share-api
+Cflags: -I${includedir} -I${includedir}/bluetooth-share-api
--- /dev/null
+/*
+ * bluetooth-share-api
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sqlite3.h>
+#include <db-util.h>
+
+#include "applog.h"
+#include "bt-share-db.h"
+#include "bluetooth-share-api.h"
+
+
+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");
+
+ 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;
+ }
+
+ return BT_SHARE_ERR_NONE;
+}
+
+
+sqlite3 *__bt_db_open(void)
+{
+ int ret;
+ sqlite3 *db = NULL;
+
+ ret = db_util_open(BT_TRANSFER_DB, &db, DB_UTIL_REGISTER_HOOK_METHOD);
+ if (ret) {
+ ERR("Can't open database: %s", sqlite3_errmsg(db));
+ db_util_close(db);
+ return NULL;
+ }
+
+ 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");
+}
+
+static int __bt_db_end_transaction(sqlite3 *db)
+{
+ 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;
+
+ 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) VALUES(?, '%d', '%d', '%s', '%s', '%d', '%s');",
+ TABLE(db_table), data->sid, data->tr_status, data->file_path,
+ data->dev_name, data->timestamp, data->addr);
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK)
+ goto error;
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_DONE)
+ goto error;
+
+ sqlite3_finalize(stmt);
+
+ DBG("-\n");
+ return BT_SHARE_ERR_NONE;
+
+error:
+ ERR("[ERROR] szQuery : %s", query);
+ ERR("[ERROR] SQL error msg : %s", (char *)sqlite3_errmsg(db));
+ if (stmt) {
+ sqlite3_finalize(stmt);
+ }
+
+ 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, };
+
+ 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);
+
+ __bt_db_begin_transaction(db);
+ ret = __bt_exec_query(db, query);
+ if (ret != BT_SHARE_ERR_NONE) {
+ return BT_SHARE_ERR_INTERNAL;
+ }
+ __bt_db_end_transaction(db);
+
+ return BT_SHARE_ERR_NONE;
+}
+
+static bt_tr_data_t *__bt_db_get_record_by_id(sqlite3 *db, int db_table, int id)
+{
+ DBG("+\n");
+ int ret = 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);
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK)
+ 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++));
+ } else {
+ goto error;
+ }
+
+ DBG("%d, %d, %s, %s, %d, %s\n", data->sid, data->tr_status, data->file_path,
+ data->dev_name, data->timestamp, data->addr);
+
+ sqlite3_finalize(stmt);
+
+ DBG("-\n");
+ return data;
+
+error:
+ ERR("[ERROR] szQuery : %s", query);
+ ERR("[ERROR] SQL error msg : %s", (char *)sqlite3_errmsg(db));
+ if (stmt) {
+ sqlite3_finalize(stmt);
+ }
+ return NULL;
+}
+
+
+static GSList *__bt_db_get_record_list(sqlite3 *db, const char*query)
+{
+ int ret;
+ sqlite3_stmt *stmt = NULL;
+ int idx = 0;
+ 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");
+ sqlite3_finalize(stmt);
+ return NULL;
+ }
+
+ ret = sqlite3_step(stmt);
+ while (ret == SQLITE_ROW) {
+ idx = 0;
+ bt_tr_data_t *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++));
+
+ 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;
+ unsigned int sid = 0;
+ char query[BT_DB_QUERY_LEN] = {0, };
+ sqlite3_stmt *stmt = NULL;
+
+ retvm_if(db == NULL, NULL, "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));
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK)
+ goto error;
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW)
+ sid = INT(stmt, 1); /* to get the session id */
+ else
+ goto error;
+
+ sqlite3_finalize(stmt);
+
+ DBG("-\n");
+ return sid;
+error:
+ ERR("[ERROR] szQuery : %s", query);
+ ERR("[ERROR] SQL error msg : %s", (char *)sqlite3_errmsg(db));
+ if (stmt) {
+ sqlite3_finalize(stmt);
+ }
+
+ return 0;
+}
+
+
+static void __bt_release_memory(bt_tr_data_t *data)
+{
+ retm_if(data == NULL, "Invalid param");
+
+ g_free(data->file_path);
+ g_free(data->dev_name);
+ g_free(data->addr);
+ g_free(data);
+}
+
+
+static int __bt_db_release_record_list(GSList *list)
+{
+ retvm_if(list == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+
+ g_slist_foreach(list, (GFunc)__bt_release_memory, NULL);
+ g_slist_free(list);
+
+ return BT_SHARE_ERR_NONE;
+}
+
+static int __bt_db_get_record_count(sqlite3 *db, int db_table)
+{
+ char query[BT_DB_QUERY_LEN] = {0, };
+ sqlite3_stmt *stmt;
+ int idx;
+ int count = 0;
+ int ret = 0;
+
+ snprintf(query, sizeof(query), "SELECT COUNT(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 BT_SHARE_ERR_INTERNAL;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ idx = 0;
+ count = INT(stmt, idx++);
+ } else {
+ sqlite3_finalize(stmt);
+ return BT_SHARE_ERR_INTERNAL;
+ }
+
+ 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;
+ sqlite3_stmt *stmt = NULL;
+
+ retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handler is null");
+
+ 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;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_DONE) {
+ ERR("sqlite3_step() Failed(%d)", ret);
+ sqlite3_finalize(stmt);
+ return BT_SHARE_ERR_INTERNAL;
+ }
+
+ sqlite3_finalize(stmt);
+
+ return BT_SHARE_ERR_NONE;
+}
+
+EXPORT_API sqlite3 *bt_share_open_db(void)
+{
+ sqlite3 *db = NULL;
+
+ db = __bt_db_open();
+ if (!db)
+ return NULL;
+
+ return db;
+}
+
+EXPORT_API int bt_share_close_db(sqlite3 *db)
+{
+ retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
+
+ return __bt_db_close(db);
+}
+
+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");
+
+ 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)
+{
+ retvm_if(data == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+ retvm_if(db == NULL, BT_SHARE_ERR_INTERNAL, "DB handle is NULL");
+
+ 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)
+{
+ retvm_if(db == NULL, NULL, "DB handle is NULL");
+
+ return __bt_db_get_record_by_id(db, db_table, id);
+}
+
+EXPORT_API GSList *bt_share_get_all_tr_data_list(sqlite3 *db, int db_table)
+{
+ retvm_if(db == NULL, NULL, "DB handle is NULL");
+
+ char query[BT_DB_QUERY_LEN] = {0, };
+ snprintf(query, sizeof(query),
+ "SELECT * FROM %s ORDER BY TIMESTAMP DESC;",
+ TABLE(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)
+{
+ retvm_if(db == NULL, NULL, "DB handle 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));
+
+ 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");
+
+ char query[BT_DB_QUERY_LEN] = {0, };
+ snprintf(query, sizeof(query),
+ "SELECT * FROM %s WHERE tr_status = %d;",
+ TABLE(db_table), status);
+
+ return __bt_db_get_record_list(db, query);
+}
+
+EXPORT_API unsigned int bt_share_get_last_session_id(sqlite3 *db, int db_table)
+{
+ retvm_if(db == NULL, NULL, "DB handle is NULL");
+
+ return __bt_db_get_last_session_id(db, db_table);
+}
+
+EXPORT_API int bt_share_release_tr_data_list(GSList *list)
+{
+ retvm_if(list == NULL, BT_SHARE_ERR_INVALID_PARAM, "Invalid param");
+
+ return __bt_db_release_record_list(list);
+}
+
+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);
+}
+
+EXPORT_API int bt_share_remove_tr_data_by_id(sqlite3 *db, int db_table, int 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 id=%d;",
+ TABLE(db_table), 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)
+{
+ 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=%d;",
+ TABLE(db_table), status);
+
+ return __bt_db_delete_record(db, query);
+}
+
+EXPORT_API int bt_share_remove_tr_data_by_notification(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));
+
+ return __bt_db_delete_record(db, query);
+}
+
+EXPORT_API int bt_share_remove_all_tr_data(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;", TABLE(db_table));
+
+ return __bt_db_delete_record(db, query);
+}
+
--- /dev/null
+/*
+ * bluetooth-share-api
+ *
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ #ifndef __DEF_BT_SHARE_DB_H_
+#define __DEF_BT_SHARE_DB_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BT_TRANSFER_DB "/opt/dbspace/.bluetooth_trasnfer.db"
+#define BT_INBOUND_TABLE "inbound"
+#define BT_OUTBOUND_TABLE "outbound"
+#define BT_DB_QUERY_LEN 512
+
+#define TABLE(type) ((type == BT_DB_INBOUND) ? BT_INBOUND_TABLE : BT_OUTBOUND_TABLE)
+#define TEXT(s, n) (char *)sqlite3_column_text(s, n)
+#define INT(s, n) sqlite3_column_int(s, n)
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __DEF_BT_SHARE_DB_H_ */
+
--- /dev/null
+%define _optdir /opt
+
+Name: bluetooth-share
+Summary: Bluetooth file share Agent
+Version: 0.0.47
+Release: 2
+Group: TO_BE/FILLED_IN
+License: Apache License, Version 2.0
+Source0: %{name}-%{version}.tar.gz
+Requires(post): vconf
+Requires(post): coreutils
+Requires(post): sqlite
+Requires(post): smack-utils
+BuildRequires: cmake
+BuildRequires: gettext-tools
+BuildRequires: pkgconfig(appcore-efl)
+BuildRequires: pkgconfig(bluetooth-api)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(calendar-service2)
+BuildRequires: pkgconfig(contacts-service2)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(syspopup-caller)
+BuildRequires: pkgconfig(pmapi)
+BuildRequires: pkgconfig(sysman)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(appsvc)
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(libprivilege-control)
+BuildRequires: pkgconfig(capi-content-media-content)
+
+%description
+Bluetooth File Share Agent
+
+%package -n libbluetooth-share
+Summary: Bluetooth share library
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description -n libbluetooth-share
+Bluetooth share library
+
+%package -n libbluetooth-share-devel
+Summary: Development package for libbluetooth-share
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description -n libbluetooth-share-devel
+Development package for libbluetooth-share
+
+%prep
+%setup -q
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+make
+
+%install
+rm -rf %{buildroot}
+%make_install
+mkdir -p %{buildroot}%{_optdir}/share/bt-ftp
+
+%post
+# For the FTP server folder
+if [ ! -e /opt/share/bt-ftp ]
+then
+ mkdir -p /opt/share/bt-ftp
+fi
+
+if [ ! -e /opt/share/bt-ftp/Media ]
+then
+ ln -s /opt/usr/media /opt/share/bt-ftp/Media
+fi
+
+if [ ! -e /opt/share/bt-ftp/SD_External ]
+then
+ ln -s /opt/storage/sdcard /opt/share/bt-ftp/SD_External
+fi
+
+vconftool set -tf bool memory/private/bluetooth-share/quickpanel_clear_btn_status FALSE -g 6520 -i
+vconftool set -tf bool memory/private/bluetooth-share/opp_server_init FALSE -g 6520 -i
+
+if [ ! -f /opt/dbspace/.bluetooth_trasnfer.db ]
+then
+ sqlite3 /opt/dbspace/.bluetooth_trasnfer.db 'PRAGMA journal_mode = PERSIST;
+ create table if not exists inbound (
+ id INTEGER PRIMARY KEY autoincrement,
+ sid INTEGER,
+ tr_status INTEGER,
+ file_path TEXT,
+ dev_name TEXT,
+ timestamp INTEGER default 0,
+ addr TEXT
+ );
+ create table if not exists outbound (
+ id INTEGER PRIMARY KEY autoincrement,
+ sid INTEGER,
+ tr_status INTEGER,
+ file_path TEXT,
+ dev_name TEXT,
+ timestamp INTEGER default 0,
+ addr TEXT
+ );
+ '
+fi
+
+chown :5000 /opt/dbspace/.bluetooth_trasnfer.db
+chown :5000 /opt/dbspace/.bluetooth_trasnfer.db-journal
+chmod 660 /opt/dbspace/.bluetooth_trasnfer.db
+chmod 660 /opt/dbspace/.bluetooth_trasnfer.db-journal
+
+if [ -f /usr/lib/rpm-plugins/msm.so ]
+then
+chsmack -a 'bt_share::db' /opt/dbspace/.bluetooth_trasnfer.db
+chsmack -a 'bt_share::db' /opt/dbspace/.bluetooth_trasnfer.db-journal
+fi
+
+%files
+%manifest bluetooth-share.manifest
+%defattr(-,root,root,-)
+%{_bindir}/bluetooth-share
+%{_datadir}/dbus-1/services/org.bluetooth.share.service
+%{_optdir}/share/bt-ftp
+
+%files -n libbluetooth-share
+%defattr(-, root, root)
+%{_libdir}/libbluetooth-share-api.so.0.*
+
+%files -n libbluetooth-share-devel
+%defattr(-, root, root)
+/usr/include/bluetooth-share-api/bluetooth-share-api.h
+%{_libdir}/libbluetooth-share-api.so
+%{_libdir}/pkgconfig/bluetooth-share-api.pc