Modify the process uid / pid and file download path 55/72655/1 accepted/tizen/common/20160602.140333 accepted/tizen/ivi/20160602.231104 accepted/tizen/mobile/20160602.231125 accepted/tizen/tv/20160602.231052 accepted/tizen/wearable/20160602.231059 submit/tizen/20160602.083934
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 2 Jun 2016 04:20:11 +0000 (13:20 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 2 Jun 2016 04:20:11 +0000 (13:20 +0900)
This patchset is for resolving bugs related with file sharing.
"Cannot share Text by BT" and "Unable to recieve file via bluetooth"

Change-Id: If8d2d9f66f2ff8c8e4f3d58a61166e0313ae7806
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-share/CMakeLists.txt
bt-share/include/bt-share-common.h
bt-share/include/bt-share-noti-handler.h
bt-share/src/bt-share-common.c
bt-share/src/bt-share-main.c
bt-share/src/bt-share-noti-handler.c
bt-share/src/obex-event-handler.c
packaging/bluetooth-share.spec
packaging/init_db.sh

index 2122ac3..590d1fb 100644 (file)
@@ -24,7 +24,8 @@ pkg_check_modules(pkgs REQUIRED glib-2.0 bluetooth-api
                                appsvc appcore-efl storage
                                capi-content-media-content
                                libtzplatform-config eventsystem
-                               cynara-creds-dbus cynara-client cynara-session)
+                               cynara-creds-dbus cynara-client cynara-session
+                               storage)
 pkg_check_modules(CALENDAR_SERVICE2 calendar-service2)
 pkg_check_modules(CONTACTS_SERVICE2 contacts-service2)
 
index ff01ba0..fa90dab 100644 (file)
@@ -30,7 +30,8 @@ extern "C" {
 #define BT_SHARE_FAIL -1
 #define BT_SHARE_ERROR_NONE 0
 
-#define BT_TMP_DIR "/opt/usr/media/Downloads/.bluetooth/"
+//#define BT_TMP_DIR "/opt/home/owner/content/Downloads/.bluetooth/"
+#define BT_TMP_DIR "/opt/home/owner/content/Downloads/"
 #define BT_TMP_FILE BT_TMP_DIR"bluetooth_content_share"
 #define TXT_FILE_NAME BT_TMP_DIR"bluetooth_content_share.txt"
 #define HTML_FILE_NAME BT_TMP_DIR"bluetooth_content_share.html"
@@ -38,7 +39,8 @@ extern "C" {
 #define HTML_FILE_FORMAT BT_TMP_DIR"bluetooth_content_share%s.html"
 #define HTML_FORMAT "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/></head><body><a href=\"%s\">%s</a></body></html>"
 
-#define BT_CONTACT_SHARE_TMP_DIR "/opt/usr/media/Downloads/.bluetooth/"
+//#define BT_CONTACT_SHARE_TMP_DIR "/opt/home/owner/content/Downloads/.bluetooth/"
+#define BT_CONTACT_SHARE_TMP_DIR "/opt/home/owner/content/Downloads/"
 
 typedef enum {
        BT_HTTP_FILE,
index 68a9b74..1d3c0b2 100644 (file)
@@ -28,10 +28,10 @@ extern "C" {
 #define BT_DEFAULT_MEM_PHONE 0
 #define BT_DEFAULT_MEM_MMC 1
 
-#define BT_DOWNLOAD_PHONE_FOLDER "/opt/usr/media/Downloads"
-#define BT_DOWNLOAD_MMC_FOLDER "/opt/storage/sdcard/Downloads"
-#define BT_DOWNLOAD_MEDIA_FOLDER "/opt/home/owner/content/Downloads"
-//#define BT_DOWNLOAD_MEDIA_FOLDER tzplatform_getenv(TZ_USER_CONTENT)
+#define BT_DOWNLOAD_DEFAULT_PHONE_FOLDER "/opt/usr/media/Downloads"
+#define BT_DOWNLOAD_DEFAULT_MMC_FOLDER "/opt/storage/sdcard/Downloads"
+#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER "/opt/home/owner/content/Downloads"
+//#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER tzplatform_getenv(TZ_USER_CONTENT)
 
 /*
 #define BT_FTP_FOLDER tzplatform_mkpath(TZ_SYS_SHARE, "bt-ftp")
index 8360b0c..79c5456 100644 (file)
@@ -25,6 +25,9 @@
 #include <Ecore_File.h>
 #include <bundle.h>
 #include <eventsystem.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+#include <linux/xattr.h>
 
 #include "vconf-keys.h"
 #include "applog.h"
index 9de45d9..7cca364 100644 (file)
@@ -305,7 +305,7 @@ int _bt_init_obex_server(void)
                return BT_SHARE_FAIL;
        }
 
-       bluetooth_obex_server_set_root(BT_FTP_FOLDER);
+       bluetooth_obex_server_set_root(storage);
 
        return BT_SHARE_ERROR_NONE;
 }
@@ -358,10 +358,15 @@ int main(void)
        if (appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0)
                return -1;
 
+       uid_t network_user = 5001; /* uid of owner */
+       gid_t network_group = 100; /* gid of users */
+
+#if 0
        uid_t network_user = 551; /* uid of network_fw */
        gid_t network_group = 551; /* gid of network_fw */
-
        initgroups("network_fw", network_group);
+#endif
+       initgroups("users", network_group);
        ret = setgid(network_group);
        DBG("setgid return : %d", ret);
        ret = setuid(network_user);
index 0721f2e..f930000 100644 (file)
@@ -21,6 +21,7 @@
 #include <vconf.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <storage.h>
 
 /* For multi-user support */
 #include <tzplatform_config.h>
@@ -34,6 +35,7 @@
 
 static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
 {
+       int ret;
        int default_memory = 0;
        char *root_path = NULL;
        char *download_path = NULL;
@@ -47,8 +49,29 @@ static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
        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 ? (char *)BT_DOWNLOAD_MMC_FOLDER : (char *)BT_DOWNLOAD_MEDIA_FOLDER;
-               download_path = default_memory ? (char *)BT_DOWNLOAD_MMC_FOLDER : (char *)BT_DOWNLOAD_PHONE_FOLDER;
+
+               if (default_memory == BT_DEFAULT_MEM_MMC) /* MMC */ {
+                       ret = storage_get_directory(STORAGE_TYPE_EXTERNAL,
+                                               STORAGE_DIRECTORY_DOWNLOADS, &download_path);
+
+                       if (ret != STORAGE_ERROR_NONE)
+                               DBG("Fail to get the download path: %d", ret);
+
+                       ret = storage_get_root_directory(STORAGE_TYPE_EXTERNAL, &root_path);
+
+                       if (ret != STORAGE_ERROR_NONE)
+                               DBG("Fail to get the root path: %d", ret);
+
+                       if (download_path == NULL)
+                               download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MMC_FOLDER);
+
+                       if (root_path == NULL)
+                               root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MMC_FOLDER);
+
+               } else {
+                       download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
+                       root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
+               }
 
                if (access(download_path, W_OK) != 0) {
                        if (mkdir(download_path, 0755) < 0) {
@@ -58,6 +81,9 @@ static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
 
                bluetooth_obex_server_set_root(root_path);
                bluetooth_obex_server_set_destination_path(download_path);
+
+               g_free(download_path);
+               g_free(root_path);
        }
 }
 
index 8d34fe7..2d185db 100644 (file)
@@ -696,9 +696,9 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
 
 void _bt_get_default_storage(char *storage)
 {
-       int val;
-       int err;
-       char *path;
+       int val = BT_DEFAULT_MEM_PHONE;
+       int ret;
+       char *path = NULL;
 
        if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
                                                (void *)&val)) {
@@ -706,25 +706,26 @@ void _bt_get_default_storage(char *storage)
                val = BT_DEFAULT_MEM_PHONE;
        }
 
-       if (val == BT_DEFAULT_MEM_MMC)
-               path = BT_DOWNLOAD_MMC_FOLDER;
-       else
-               path = BT_DOWNLOAD_PHONE_FOLDER;
+       if (val == BT_DEFAULT_MEM_MMC) {
+               ret = storage_get_directory(STORAGE_TYPE_EXTERNAL,
+                                       STORAGE_DIRECTORY_DOWNLOADS, &path);
 
-       if (access(path, W_OK) == 0) {
-               g_strlcpy(storage, path, STORAGE_PATH_LEN_MAX);
-               DBG("Storage path = [%s]\n", storage);
-               return;
-       }
+               if (ret != STORAGE_ERROR_NONE)
+                       DBG("Fail to get the download path: %d", ret);
 
-       if (mkdir(BT_DOWNLOAD_MEDIA_FOLDER, 0755) < 0) {
-               err = -errno;
-               DBG("mkdir: %d", -err);
+               if (path == NULL)
+                       path = g_strdup(BT_DOWNLOAD_DEFAULT_MMC_FOLDER);
+       } else {
+               path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
        }
 
-       g_strlcpy(storage, BT_DOWNLOAD_MEDIA_FOLDER, STORAGE_PATH_LEN_MAX);
+       g_strlcpy(storage, path, STORAGE_PATH_LEN_MAX);
+       g_free(path);
 
        DBG("Default storage : %s\n", storage);
+
+       if (access(storage, W_OK) != 0)
+               DBG("Can't access the storage");
 }
 
 
index 6a4c24f..8f8f296 100644 (file)
@@ -41,6 +41,7 @@ BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
 BuildRequires:  pkgconfig(cynara-creds-dbus)
 BuildRequires:  pkgconfig(eventsystem)
+BuildRequires:  pkgconfig(storage)
 
 %description
 Bluetooth File Share Agent
index ea94c31..75d5f5f 100644 (file)
@@ -30,8 +30,10 @@ then
        '
 fi
 
-chown network_fw:network_fw $TZ_SYS_DB/.bluetooth_transfer.db
-chown network_fw:network_fw $TZ_SYS_DB/.bluetooth_transfer.db-journal
+#chown network_fw:network_fw $TZ_SYS_DB/.bluetooth_transfer.db
+#chown network_fw:network_fw $TZ_SYS_DB/.bluetooth_transfer.db-journal
+chown 5001:100 $TZ_SYS_DB/.bluetooth_transfer.db
+chown 5001:100 $TZ_SYS_DB/.bluetooth_transfer.db-journal
 chmod 664 $TZ_SYS_DB/.bluetooth_transfer.db
 chmod 664 $TZ_SYS_DB/.bluetooth_transfer.db-journal