4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
29 #ifdef TIZEN_MDM_ENABLE
30 #include <bt-service-mdm.h>
36 #include "bluetooth-api.h"
37 #include "bt-internal-types.h"
39 #include "bt-service-common.h"
40 #include "bt-service-event.h"
41 #include "bt-service-util.h"
42 #include "bt-service-obex-agent.h"
43 #include "bt-service-obex-server.h"
44 #include "bt-service-agent.h"
46 #define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
47 #define BT_OBEX_SERVER_AGENT_PATH "/org/obex/server_agent"
49 #define BT_OBEX_SERVICE "org.bluez.obex"
50 #define BT_OBEX_MANAGER "org.bluez.obex.AgentManager1"
51 #define BT_OBEX_PATH "/org/bluez/obex"
66 GDBusMethodInvocation *reply_context;
85 bt_auth_info_t *auth_info;
86 bt_server_info_t *native_server;
87 bt_server_info_t *custom_server;
88 } bt_obex_agent_info_t;
90 static GSList *transfers;
91 static bt_obex_agent_info_t agent_info;
93 static GQuark __bt_obex_error_quark(void)
95 static GQuark quark = 0;
97 quark = g_quark_from_static_string("agent");
102 static bt_transfer_info_t *__bt_find_transfer_by_id(int transfer_id)
105 bt_transfer_info_t *transfer;
107 for (l = transfers; l != NULL; l = l->next) {
110 if (transfer == NULL)
113 if (transfer->transfer_id == transfer_id)
120 bt_transfer_info_t *__bt_find_transfer_by_address(const char *address)
124 bt_transfer_info_t *transfer;
126 retv_if(address == NULL, NULL);
128 for (l = transfers; l != NULL; l = l->next) {
131 if (transfer == NULL)
134 if (g_strcmp0(transfer->address, address) == 0)
141 static bt_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
144 bt_transfer_info_t *transfer;
146 retv_if(transfer_path == NULL, NULL);
148 for (l = transfers; l != NULL; l = l->next) {
151 if (transfer == NULL)
154 if (g_strcmp0(transfer->path, transfer_path) == 0)
161 static void __bt_free_server_info(bt_server_info_t *server_info)
163 ret_if(server_info == NULL);
165 g_free(server_info->sender);
166 g_free(server_info->dest_path);
170 static void __bt_free_auth_info(bt_auth_info_t *auto_info)
172 ret_if(auto_info == NULL);
174 g_free(auto_info->filename);
175 g_free(auto_info->transfer_path);
176 g_free(auto_info->device_name);
177 g_free(auto_info->address);
181 static void __bt_free_transfer_info(bt_transfer_info_t *transfer_info)
183 ret_if(transfer_info == NULL);
185 g_free(transfer_info->path);
186 g_free(transfer_info->filename);
187 g_free(transfer_info->file_path);
188 g_free(transfer_info->type);
189 g_free(transfer_info->device_name);
190 g_free(transfer_info->address);
191 g_free(transfer_info);
194 void _bt_obex_check_pending_transfer(const char *address)
197 GVariant *param = NULL;
198 bt_transfer_info_t *transfer_info = __bt_find_transfer_by_address(address);
199 if (transfer_info != NULL) {
200 int result = BLUETOOTH_ERROR_CANCEL;
201 param = g_variant_new("(isssstii)", result,
202 transfer_info->filename,
204 transfer_info->device_name,
205 transfer_info->file_path,
206 transfer_info->file_size,
207 transfer_info->transfer_id,
208 agent_info.server_type);
209 _bt_send_event(BT_OPP_SERVER_EVENT,
210 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
212 transfers = g_slist_remove(transfers, transfer_info);
213 __bt_free_transfer_info(transfer_info);
218 static char *__bt_get_remote_device_name(const char *bdaddress)
220 char *device_path = NULL;
223 GVariant *result = NULL;
225 GDBusProxy *device_proxy;
226 GDBusConnection *conn;
228 retv_if(bdaddress == NULL, NULL);
230 device_path = _bt_get_device_object_path((char *)bdaddress);
231 retv_if(device_path == NULL, NULL);
233 conn = _bt_get_session_gconn();
234 retv_if(conn == NULL, NULL);
235 BT_INFO("Device_path %s", device_path);
236 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
239 BT_PROPERTIES_INTERFACE,
243 retv_if(device_proxy == NULL, NULL);
245 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
246 g_variant_new("(s)", BT_DEVICE_INTERFACE),
247 G_DBUS_CALL_FLAGS_NONE,
251 BT_ERR("DBus Error : %s", err->message);
255 if (result == NULL) {
256 BT_ERR("g_dbus_proxy_call_sync function return NULL");
259 g_variant_get(result, "(@a{sv})", &value);
260 g_variant_unref(result);
262 g_object_unref(device_proxy);
264 GVariant *temp_value = g_variant_lookup_value(value, "Alias",
265 G_VARIANT_TYPE_STRING);
266 g_variant_get(temp_value, "(s)", &name);
268 g_variant_unref(temp_value);
269 BT_INFO("Alias Name: %s", name);
275 static int __bt_get_transfer_id(const char *path)
281 tmp = strrchr(path, 'r') + 1;
282 retv_if(tmp == NULL, -1);
287 static GDBusProxy *__bt_get_transfer_proxy(const char *transfer_path)
289 GDBusConnection *conn;
293 conn = _bt_get_session_gconn();
294 retv_if(conn == NULL, NULL);
296 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
297 NULL, BT_OBEX_SERVICE_NAME,
299 BT_OBEX_TRANSFER_INTERFACE,
303 BT_ERR("Error : %s", err->message);
311 static GDBusProxy *__bt_get_transfer_properties_proxy(const char *transfer_path)
313 GDBusConnection *conn;
316 conn = _bt_get_session_gconn();
317 retv_if(conn == NULL, NULL);
319 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
320 NULL,BT_OBEX_SERVICE_NAME,
322 BT_PROPERTIES_INTERFACE,
325 BT_ERR("Error : %s", err->message);
332 static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
333 const char *transfer_path)
335 GDBusProxy *transfer_proxy;
336 char *bdaddress = NULL;
337 GVariant *result = NULL;
339 GVariantIter *iter = NULL;
340 BT_CHECK_PARAMETER(transfer_info, return);
341 BT_CHECK_PARAMETER(transfer_path, return);
343 transfer_proxy = __bt_get_transfer_properties_proxy(transfer_path);
345 retv_if(transfer_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
347 result = g_dbus_proxy_call_sync(transfer_proxy, "GetAll",
348 g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
349 G_DBUS_CALL_FLAGS_NONE,
354 BT_ERR("DBus Error : %s", err->message);
358 if (result == NULL) {
359 BT_ERR("g_dbus_proxy_call_sync function return NULL");
363 g_variant_get(result, "(a{sv})", &iter);
364 g_variant_unref(result);
369 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
370 if (g_strcmp0(key, "Operation") == 0) {
371 transfer_info->type = g_variant_dup_string(val, &len);
372 } else if (g_strcmp0(key, "Name") == 0) {
373 transfer_info->filename = g_variant_dup_string(val, &len);
374 } else if (g_strcmp0(key, "Size") == 0) {
375 transfer_info->file_size = g_variant_get_uint64(val);
376 } else if (g_strcmp0(key, "Address") == 0) {
377 transfer_info->address = g_variant_dup_string(val, &len);
378 BT_INFO("addressss %s", transfer_info->address);
379 } else if (g_strcmp0(key, "Filename") == 0) {
380 transfer_info->file_path = g_variant_dup_string(val, &len);
381 if (!transfer_info->file_path)
382 transfer_info->file_path = g_strdup(transfer_info->filename);
385 g_variant_iter_free(iter);
386 if (transfer_info->type == NULL)
388 if (transfer_info->address == NULL)
391 transfer_info->device_name = __bt_get_remote_device_name(transfer_info->address);
393 if (!transfer_info->device_name)
394 transfer_info->device_name = g_strdup(bdaddress);
395 transfer_info->path = g_strdup(transfer_path);
396 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
399 g_object_unref(transfer_proxy);
400 return BLUETOOTH_ERROR_NONE;
403 g_object_unref(transfer_proxy);
404 return BLUETOOTH_ERROR_INTERNAL;
407 static gboolean __bt_authorize_cb(GDBusMethodInvocation *context,
411 char *device_name = NULL;
412 int result = BLUETOOTH_ERROR_NONE;
413 GDBusProxy *transfer_properties_proxy;
414 char * bdaddress = NULL;
417 GVariant *param = NULL;
420 BT_DBG(" path [%s] \n", path);
422 transfer_properties_proxy = __bt_get_transfer_properties_proxy(path);
424 retv_if(transfer_properties_proxy == NULL, FALSE);
426 ret = g_dbus_proxy_call_sync(transfer_properties_proxy, "GetAll",
427 g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
428 G_DBUS_CALL_FLAGS_NONE,
432 BT_ERR("DBus Error : %s", err->message);
437 BT_ERR("g_dbus_proxy_call_sync function return NULL");
440 g_variant_get(ret, "(a{sv})", &iter);
441 g_variant_unref(ret);
443 g_object_unref(transfer_properties_proxy);
447 #ifdef TIZEN_MDM_ENABLE
448 mdm_bt_allow_t mode = MDM_BT_ALLOWED;
451 __bt_free_auth_info(agent_info.auth_info);
453 agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t));
455 memset(agent_info.auth_info, 0, sizeof(bt_auth_info_t));
457 agent_info.auth_info->reply_context = context;
459 agent_info.auth_info->transfer_path = g_strdup(path);
465 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
466 if (g_strcmp0(key, "Name") == 0) {
467 agent_info.auth_info->filename = g_variant_dup_string(val,&len);
468 } else if (g_strcmp0(key, "Address") == 0) {
469 bdaddress = g_variant_dup_string(val, &len);
470 } else if (g_strcmp0(key, "Size") == 0) {
471 agent_info.auth_info->file_size = g_variant_get_uint64(val);
474 g_variant_iter_free(iter);
477 device_name = __bt_get_remote_device_name(bdaddress);
480 device_name = g_strdup(bdaddress);
482 agent_info.auth_info->device_name = device_name;
484 g_object_unref(transfer_properties_proxy);
486 if (agent_info.server_type == BT_CUSTOM_SERVER) {
487 /* No need to send the event */
488 _bt_obex_server_accept_authorize(agent_info.auth_info->filename, FALSE);
491 param = g_variant_new("(ist)", result,
492 agent_info.auth_info->filename,
493 agent_info.auth_info->file_size);
494 _bt_send_event(BT_OPP_SERVER_EVENT,
495 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
501 void _bt_obex_transfer_started(const char *transfer_path)
503 bt_transfer_info_t *transfer_info;
504 request_info_t *req_info;
505 GVariant *out_param1 = NULL;
506 GVariant *param = NULL;
507 int result = BLUETOOTH_ERROR_NONE;
509 BT_DBG("%s", transfer_path);
511 transfer_info = g_malloc0(sizeof(bt_transfer_info_t));
513 if (agent_info.auth_info != NULL
514 && g_strcmp0(transfer_path, agent_info.auth_info->transfer_path) == 0) {
515 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
516 transfer_info->file_size = agent_info.auth_info->file_size;
517 transfer_info->type = g_strdup(TRANSFER_PUT);
518 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
519 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
520 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
521 transfer_info->file_path = agent_info.auth_info->file_path;
522 transfer_info->address = g_strdup(agent_info.auth_info->address);
524 if (__bt_get_transfer_properties(transfer_info, transfer_path) < 0) {
525 BT_ERR("Get Properties failed");
526 __bt_free_auth_info(agent_info.auth_info);
527 __bt_free_transfer_info(transfer_info);
528 agent_info.auth_info = NULL;
531 agent_info.server_type = BT_FTP_SERVER;
534 __bt_free_auth_info(agent_info.auth_info);
535 agent_info.auth_info = NULL;
537 if (agent_info.server_type == BT_CUSTOM_SERVER) {
538 if (agent_info.custom_server == NULL) {
539 __bt_free_transfer_info(transfer_info);
543 req_info = _bt_get_request_info(agent_info.accept_id);
544 if (req_info == NULL || req_info->context == NULL) {
545 BT_ERR("info is NULL");
549 agent_info.accept_id = 0;
550 result = BLUETOOTH_ERROR_NONE;
551 GArray *g_out_param1 = NULL;
552 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
553 if (out_param1 == NULL) {
554 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
555 g_out_param1->data, g_out_param1->len,
559 g_dbus_method_invocation_return_value(req_info->context,
560 g_variant_new("(iv)", result, out_param1));
561 g_array_free(g_out_param1, TRUE);
562 _bt_delete_request_list(req_info->req_id);
565 transfers = g_slist_append(transfers, transfer_info);
567 BT_DBG("Transfer id %d\n", transfer_info->transfer_id);
568 param = g_variant_new("(isstii)", result,
569 transfer_info->filename,
571 transfer_info->file_size,
572 transfer_info->transfer_id,
573 agent_info.server_type);
574 _bt_send_event(BT_OPP_SERVER_EVENT,
575 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
579 void _bt_obex_transfer_progress(const char *transfer_path,
583 bt_transfer_info_t *transfer_info;
585 GVariant *param = NULL;
586 int result = BLUETOOTH_ERROR_NONE;
588 transfer_info = __bt_find_transfer_by_path(transfer_path);
589 ret_if(transfer_info == NULL);
591 progress = (int)(((gdouble)transferred /
592 (gdouble)transfer_info->file_size) * 100);
594 param = g_variant_new("(isstiii)", result,
595 transfer_info->filename,
597 transfer_info->file_size,
598 transfer_info->transfer_id,
600 agent_info.server_type);
601 _bt_send_event(BT_OPP_SERVER_EVENT,
602 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
607 void _bt_obex_transfer_completed(const char *transfer_path, gboolean success)
609 bt_transfer_info_t *transfer_info;
610 GVariant *param = NULL;
612 BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
614 result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
615 : BLUETOOTH_ERROR_CANCEL;
617 transfer_info = __bt_find_transfer_by_path(transfer_path);
619 if (transfer_info == NULL) {
620 BT_DBG("Very small files receiving case, did not get Active status from obexd");
621 if (agent_info.auth_info == NULL ||
622 g_strcmp0(transfer_path,
623 agent_info.auth_info->transfer_path) != 0) {
624 BT_ERR("auth_info is NULL, returning");
628 transfer_info = g_new0(bt_transfer_info_t, 1);
630 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
631 transfer_info->file_size = agent_info.auth_info->file_size;
632 transfer_info->type = g_strdup(TRANSFER_PUT);
633 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
634 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
635 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
636 transfer_info->file_path = agent_info.auth_info->file_path;
638 param = g_variant_new("(isstii)", result,
639 transfer_info->filename,
641 transfer_info->file_size,
642 transfer_info->transfer_id,
643 agent_info.server_type);
644 _bt_send_event(BT_OPP_SERVER_EVENT,
645 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
648 param = g_variant_new("(isssstii)", result,
649 transfer_info->filename,
651 transfer_info->device_name,
652 transfer_info->file_path,
653 transfer_info->file_size,
654 transfer_info->transfer_id,
655 agent_info.server_type);
656 _bt_send_event(BT_OPP_SERVER_EVENT,
657 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
659 transfers = g_slist_remove(transfers, transfer_info);
660 __bt_free_transfer_info(transfer_info);
663 void _bt_obex_transfer_connected()
667 int result = BLUETOOTH_ERROR_NONE;
668 GVariant *param = NULL;
670 param = g_variant_new("(i)", result);
672 _bt_send_event(BT_OPP_SERVER_EVENT,
673 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED,
678 void _bt_obex_transfer_disconnected()
682 int result = BLUETOOTH_ERROR_NONE;
683 GVariant *param = NULL;
685 param = g_variant_new("(i)", result);
686 _bt_send_event(BT_OPP_SERVER_EVENT,
687 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED,
692 int _bt_register_obex_server(void)
694 GDBusConnection *g_conn;
695 GDBusProxy *manager_proxy;
696 GError *g_error = NULL;
698 /* Get the session bus. */
699 g_conn = _bt_get_session_gconn();
700 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
702 _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
704 _bt_obex_setup(BT_OBEX_SERVER_AGENT_PATH);
706 _bt_obex_set_authorize_cb(BT_OBEX_SERVER_AGENT_PATH,
707 __bt_authorize_cb, NULL);
709 manager_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
710 NULL, BT_OBEX_SERVICE,
715 if (manager_proxy == NULL) {
716 return BLUETOOTH_ERROR_INTERNAL;
719 g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent",
720 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
721 G_DBUS_CALL_FLAGS_NONE,
725 if (g_error != NULL) {
726 BT_ERR("Agent registration failed: %s\n", g_error->message);
727 g_object_unref(manager_proxy);
728 g_error_free(g_error);
729 return BLUETOOTH_ERROR_INTERNAL;
732 agent_info.proxy = manager_proxy;
734 return BLUETOOTH_ERROR_NONE;
737 int _bt_unregister_obex_server(void)
739 GError *g_error = NULL;
741 retv_if(agent_info.proxy == NULL,
742 BLUETOOTH_ERROR_INTERNAL);
744 g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent",
745 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
746 G_DBUS_CALL_FLAGS_NONE,
749 if (g_error != NULL) {
750 BT_ERR("Agent unregistration failed: %s", g_error->message);
751 g_error_free(g_error);
753 _bt_obex_agent_destroy(BT_OBEX_SERVER_AGENT_PATH);
754 g_object_unref(agent_info.proxy);
755 agent_info.proxy = NULL;
757 return BLUETOOTH_ERROR_NONE;
760 gboolean __bt_check_folder_path(const char *dest_path)
764 retv_if(dest_path == NULL, FALSE);
766 dp = opendir(dest_path);
769 BT_ERR("The directory does not exist");
778 int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native)
781 if (__bt_check_folder_path(dest_path) == FALSE)
782 return BLUETOOTH_ERROR_INVALID_PARAM;
784 if (is_native == TRUE) {
785 retv_if(agent_info.native_server,
786 BLUETOOTH_ERROR_DEVICE_BUSY);
788 /* Force to change the control to native */
789 agent_info.native_server = g_malloc0(sizeof(bt_server_info_t));
790 agent_info.native_server->dest_path = g_strdup(dest_path);
791 agent_info.native_server->sender = g_strdup(sender);
792 agent_info.native_server->app_pid = app_pid;
793 agent_info.server_type = BT_NATIVE_SERVER;
794 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
796 retv_if(agent_info.custom_server,
797 BLUETOOTH_ERROR_DEVICE_BUSY);
799 /* Force to change the control to custom */
800 agent_info.custom_server = g_malloc0(sizeof(bt_server_info_t));
801 agent_info.custom_server->dest_path = g_strdup(dest_path);
802 agent_info.custom_server->sender = g_strdup(sender);
803 agent_info.custom_server->app_pid = app_pid;
804 agent_info.server_type = BT_CUSTOM_SERVER;
805 _bt_register_osp_server_in_agent(BT_OBEX_SERVER, NULL, NULL, -1);
808 return BLUETOOTH_ERROR_NONE;
811 int _bt_obex_server_deallocate(int app_pid, gboolean is_native)
813 if (is_native == TRUE) {
814 retv_if(agent_info.native_server == NULL,
815 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
817 retv_if(agent_info.native_server->app_pid != app_pid,
818 BLUETOOTH_ERROR_ACCESS_DENIED);
820 __bt_free_server_info(agent_info.native_server);
821 agent_info.native_server = NULL;
823 /* Change the control to custom */
824 if (agent_info.custom_server) {
825 agent_info.server_type = BT_CUSTOM_SERVER;
826 _bt_register_osp_server_in_agent(BT_OBEX_SERVER,
830 retv_if(agent_info.custom_server == NULL,
831 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
833 retv_if(agent_info.custom_server->app_pid != app_pid,
834 BLUETOOTH_ERROR_ACCESS_DENIED);
836 __bt_free_server_info(agent_info.custom_server);
837 agent_info.custom_server = NULL;
839 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
841 /* Change the control to native */
842 if (agent_info.native_server)
843 agent_info.server_type = BT_NATIVE_SERVER;
846 return BLUETOOTH_ERROR_NONE;
849 int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native)
851 char file_path[BT_FILE_PATH_MAX] = { 0 };
852 bt_server_info_t *server_info;
854 BT_CHECK_PARAMETER(filename, return);
856 retv_if(agent_info.auth_info == NULL, BLUETOOTH_ERROR_INTERNAL);
858 retv_if(agent_info.auth_info->reply_context == NULL,
859 BLUETOOTH_ERROR_INTERNAL);
861 if (is_native == TRUE)
862 server_info = agent_info.native_server;
864 server_info = agent_info.custom_server;
866 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
868 if (server_info->dest_path != NULL)
869 snprintf(file_path, sizeof(file_path), "%s/%s",
870 server_info->dest_path, filename);
872 snprintf(file_path, sizeof(file_path), "%s", filename);
874 g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context,
875 g_variant_new("(s)",&file_path));
876 agent_info.auth_info->reply_context = NULL;
877 agent_info.auth_info->file_path = g_strdup(file_path);
879 return BLUETOOTH_ERROR_NONE;
882 int _bt_obex_server_reject_authorize(void)
886 retv_if(agent_info.auth_info->reply_context == NULL,
887 BLUETOOTH_ERROR_INTERNAL);
889 g_error = g_error_new(__bt_obex_error_quark(),
890 BT_OBEX_AGENT_ERROR_CANCEL,
893 g_dbus_method_invocation_return_gerror(agent_info.auth_info->reply_context,
895 g_error_free(g_error);
897 __bt_free_auth_info(agent_info.auth_info);
898 agent_info.auth_info = NULL;
900 return BLUETOOTH_ERROR_NONE;
903 int _bt_obex_server_set_destination_path(const char *dest_path,
906 bt_server_info_t *server_info;
908 BT_CHECK_PARAMETER(dest_path, return);
912 dp = opendir(dest_path);
915 BT_ERR("The directory does not exist");
916 return BLUETOOTH_ERROR_INVALID_PARAM;
921 if (is_native == TRUE)
922 server_info = agent_info.native_server;
924 server_info = agent_info.custom_server;
926 retv_if(server_info == NULL,
927 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
929 g_free(server_info->dest_path);
930 server_info->dest_path = g_strdup(dest_path);
932 return BLUETOOTH_ERROR_NONE;
935 int _bt_obex_server_set_root(const char *root)
937 GError *g_error = NULL;
938 GVariant *folder = NULL;
939 char *string = "Root";
942 BT_CHECK_PARAMETER(root, return);
944 retv_if(agent_info.proxy == NULL,
945 BLUETOOTH_ERROR_INTERNAL);
950 BT_ERR("The directory does not exist");
951 return BLUETOOTH_ERROR_INVALID_PARAM;
956 folder = g_variant_new_string(root);
957 g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty",
958 g_variant_new("(sv)", string, folder),
959 G_DBUS_CALL_FLAGS_NONE,
964 BT_ERR("SetProperty Fail: %s", g_error->message);
965 g_error_free(g_error);
966 return BLUETOOTH_ERROR_INTERNAL;
969 return BLUETOOTH_ERROR_NONE;
972 int _bt_obex_server_cancel_transfer(int transfer_id)
974 bt_transfer_info_t *transfer = NULL;
978 transfer = __bt_find_transfer_by_id(transfer_id);
980 retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND);
981 proxy = __bt_get_transfer_proxy(transfer->path);
983 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
985 g_dbus_proxy_call_sync(proxy, "Cancel", NULL,
986 G_DBUS_CALL_FLAGS_NONE,
987 DBUS_TIMEOUT, NULL, &err);
989 BT_ERR("Dbus Err: %s", err->message);
992 g_object_unref(proxy);
994 return BLUETOOTH_ERROR_NONE;
997 int _bt_obex_server_cancel_all_transfers(void)
1000 bt_transfer_info_t *transfer;
1002 for (l = transfers; l != NULL; l = l->next) {
1005 if (transfer == NULL)
1008 _bt_obex_server_cancel_transfer(transfer->transfer_id);
1011 return BLUETOOTH_ERROR_NONE;
1014 int _bt_obex_server_is_activated(gboolean *activated)
1016 BT_CHECK_PARAMETER(activated, return);
1018 if (agent_info.custom_server) {
1024 return BLUETOOTH_ERROR_NONE;
1027 int _bt_obex_server_check_allocation(gboolean *allocation)
1029 BT_CHECK_PARAMETER(allocation, return);
1031 if (agent_info.native_server || agent_info.custom_server) {
1034 *allocation = FALSE;
1037 return BLUETOOTH_ERROR_NONE;
1040 int _bt_obex_server_check_termination(char *sender)
1042 BT_CHECK_PARAMETER(sender, return);
1044 if (agent_info.native_server) {
1045 if (g_strcmp0(sender, agent_info.native_server->sender) == 0) {
1046 _bt_obex_server_deallocate(agent_info.native_server->app_pid,
1051 if (agent_info.custom_server) {
1052 if (g_strcmp0(sender, agent_info.custom_server->sender) == 0) {
1053 _bt_obex_server_deallocate(agent_info.custom_server->app_pid,
1058 return BLUETOOTH_ERROR_NONE;
1061 int _bt_obex_server_is_receiving(gboolean *receiving)
1063 BT_CHECK_PARAMETER(receiving, return);
1065 if (transfers == NULL || g_slist_length(transfers) == 0) {
1071 return BLUETOOTH_ERROR_NONE;
1074 gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data)
1076 request_info_t *req_info;
1077 GVariant *out_param1 = NULL;
1078 int result = BLUETOOTH_ERROR_TIMEOUT;
1080 /* Already reply in _bt_obex_transfer_started */
1081 retv_if(agent_info.accept_id == 0, FALSE);
1083 req_info = _bt_get_request_info(agent_info.accept_id);
1084 if (req_info == NULL || req_info->context == NULL) {
1085 BT_ERR("info is NULL");
1089 agent_info.accept_id = 0;
1090 GArray *g_out_param1 = NULL;
1091 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
1092 if (out_param1 == NULL) {
1093 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1094 g_out_param1->data, g_out_param1->len,
1098 g_dbus_method_invocation_return_value(req_info->context,
1099 g_variant_new("(iv)", result, out_param1));
1100 g_array_free(g_out_param1, TRUE);
1101 _bt_delete_request_list(req_info->req_id);
1106 /* To support the BOT */
1107 int _bt_obex_server_accept_connection(int request_id)
1109 if (!_bt_agent_reply_authorize(TRUE))
1110 return BLUETOOTH_ERROR_INTERNAL;
1112 agent_info.accept_id = request_id;
1114 g_timeout_add(BT_SERVER_ACCEPT_TIMEOUT,
1115 (GSourceFunc)__bt_obex_server_accept_timeout_cb,
1118 return BLUETOOTH_ERROR_NONE;
1121 /* To support the BOT */
1122 int _bt_obex_server_reject_connection(void)
1124 if (!_bt_agent_reply_authorize(FALSE))
1125 return BLUETOOTH_ERROR_INTERNAL;
1127 return BLUETOOTH_ERROR_NONE;