Code Merge [Tizen3.0]: Applied tizen.org patches
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-opp-client.c
old mode 100644 (file)
new mode 100755 (executable)
index f1b3300..6b91b22
@@ -1,13 +1,17 @@
 /*
- * bluetooth-frwk
+ * Bluetooth-frwk
  *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
+ *              Girishashok Joshi <girish.joshi@samsung.com>
+ *              Chanyeol Park <chanyeol.park@samsung.com>
  *
  * 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
+ *             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,
@@ -26,7 +30,6 @@
 #include "bt-request-sender.h"
 #include "bt-event-handler.h"
 
-
 static void __bt_get_file_size(char **files, unsigned long *file_size, int *count)
 {
        int file_count = 0;
@@ -46,7 +49,7 @@ BT_EXPORT_API int bluetooth_opc_init(void)
        bt_user_info_t *user_info;
 
        user_info = _bt_get_user_data(BT_COMMON);
-       retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
+       retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        return _bt_register_event(BT_OPP_CLIENT_EVENT, user_info->cb, user_info->user_data);
 }
@@ -66,22 +69,34 @@ BT_EXPORT_API int bluetooth_opc_push_files(bluetooth_device_address_t *remote_ad
        bt_user_info_t *user_info;
        char filename[BT_FILE_PATH_MAX];
 
-       BT_CHECK_PARAMETER(remote_address);
-       BT_CHECK_PARAMETER(file_name_array);
-       BT_CHECK_ENABLED();
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_PARAMETER(file_name_array, return);
+       BT_CHECK_ENABLED(return);
+
+       if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_OPP_PUSH_FILES)
+            == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+               BT_ERR("Don't have a privilege to use this API");
+               return BLUETOOTH_ERROR_PERMISSION_DEINED;
+       }
 
        __bt_get_file_size(file_name_array, &size, &file_count);
        retv_if(file_count == 0, BLUETOOTH_ERROR_INVALID_PARAM);
 
+       user_info = _bt_get_user_data(BT_COMMON);
+       retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
+
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
-       user_info = _bt_get_user_data(BT_COMMON);
-       retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
-
        g_array_append_vals(in_param1, remote_address, sizeof(bluetooth_device_address_t));
 
        for (i = 0; i < file_count; i++) {
+               if (strlen(file_name_array[i]) >= sizeof(filename)) {
+                       BT_ERR("[%s] has too long path.", file_name_array[i]);
+                       BT_FREE_PARAMS(in_param1, in_param2, in_param3,
+                                      in_param4, out_param);
+                       return BLUETOOTH_ERROR_INVALID_PARAM;
+               }
                g_strlcpy(filename, file_name_array[i], sizeof(filename));
                g_array_append_vals(in_param2, filename, BT_FILE_PATH_MAX);
        }
@@ -101,7 +116,7 @@ BT_EXPORT_API int bluetooth_opc_cancel_push(void)
 {
        int result;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -119,7 +134,7 @@ BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
        int result;
        gboolean exist = FALSE;
 
-       BT_CHECK_ENABLED();
+       BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -129,6 +144,32 @@ BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
 
        if (result == BLUETOOTH_ERROR_NONE) {
                exist = g_array_index(out_param, gboolean, 0);
+               BT_DBG("Exist %d", exist);
+       } else {
+               BT_ERR("Fail to send request");
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_opc_is_sending(gboolean *is_sending)
+{
+       int result;
+
+       *is_sending = FALSE;
+
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               *is_sending = g_array_index(out_param, gboolean, 0);
        } else {
                BT_ERR("Fail to send request");
        }