2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #ifdef TIZEN_MDM_ENABLE
24 #include <bt-service-mdm.h>
30 #include "bluetooth-api.h"
31 #include "bt-internal-types.h"
33 #include "bt-service-common.h"
34 #include "bt-service-event.h"
35 #include "bt-service-util.h"
36 #include "bt-service-obex-agent.h"
37 #include "bt-service-obex-server.h"
38 #include "bt-service-agent.h"
40 #define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
41 #define BT_OBEX_SERVER_AGENT_PATH "/org/obex/server_agent"
43 #define BT_OBEX_SERVICE "org.bluez.obex"
44 #define BT_OBEX_MANAGER "org.bluez.obex.AgentManager1"
45 #define BT_OBEX_PATH "/org/bluez/obex"
60 GDBusMethodInvocation *reply_context;
79 bt_auth_info_t *auth_info;
80 bt_server_info_t *native_server;
81 bt_server_info_t *custom_server;
82 } bt_obex_agent_info_t;
84 static GSList *transfers;
85 static bt_obex_agent_info_t agent_info;
87 int _bt_obex_get_native_pid(void)
89 return agent_info.native_server->app_pid;
92 static GQuark __bt_obex_error_quark(void)
94 static GQuark quark = 0;
96 quark = g_quark_from_static_string("agent");
101 static bt_transfer_info_t *__bt_find_transfer_by_id(int transfer_id)
104 bt_transfer_info_t *transfer;
106 for (l = transfers; l != NULL; l = l->next) {
109 if (transfer == NULL)
112 if (transfer->transfer_id == transfer_id)
119 bt_transfer_info_t *__bt_find_transfer_by_address(const char *address)
123 bt_transfer_info_t *transfer;
125 retv_if(address == NULL, NULL);
127 for (l = transfers; l != NULL; l = l->next) {
130 if (transfer == NULL)
133 if (g_strcmp0(transfer->address, address) == 0)
140 static bt_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
143 bt_transfer_info_t *transfer;
145 retv_if(transfer_path == NULL, NULL);
147 for (l = transfers; l != NULL; l = l->next) {
150 if (transfer == NULL)
153 if (g_strcmp0(transfer->path, transfer_path) == 0)
160 static void __bt_free_server_info(bt_server_info_t *server_info)
162 ret_if(server_info == NULL);
164 g_free(server_info->sender);
165 g_free(server_info->dest_path);
169 static void __bt_free_auth_info(bt_auth_info_t *auto_info)
171 ret_if(auto_info == NULL);
173 g_free(auto_info->filename);
174 g_free(auto_info->transfer_path);
175 g_free(auto_info->device_name);
176 g_free(auto_info->address);
180 static void __bt_free_transfer_info(bt_transfer_info_t *transfer_info)
182 ret_if(transfer_info == NULL);
184 g_free(transfer_info->path);
185 g_free(transfer_info->filename);
186 g_free(transfer_info->file_path);
187 g_free(transfer_info->type);
188 g_free(transfer_info->device_name);
189 g_free(transfer_info->address);
190 g_free(transfer_info);
193 void _bt_obex_check_pending_transfer(const char *address)
196 GVariant *param = NULL;
197 bt_transfer_info_t *transfer_info = __bt_find_transfer_by_address(address);
198 if (transfer_info != NULL) {
199 int result = BLUETOOTH_ERROR_CANCEL;
200 param = g_variant_new("(isssstii)", result,
201 transfer_info->filename,
203 transfer_info->device_name,
204 transfer_info->file_path,
205 transfer_info->file_size,
206 transfer_info->transfer_id,
207 agent_info.server_type);
208 _bt_send_event(BT_OPP_SERVER_EVENT,
209 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
211 transfers = g_slist_remove(transfers, transfer_info);
212 __bt_free_transfer_info(transfer_info);
217 static char *__bt_get_remote_device_name(const char *bdaddress)
219 char *device_path = NULL;
222 GVariant *result = NULL;
224 GDBusProxy *device_proxy;
225 GDBusConnection *conn;
227 retv_if(bdaddress == NULL, NULL);
229 device_path = _bt_get_device_object_path((char *)bdaddress);
230 retv_if(device_path == NULL, NULL);
232 conn = _bt_get_system_gconn();
233 retv_if(conn == NULL, NULL);
234 BT_INFO("Device_path %s", device_path);
235 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
238 BT_PROPERTIES_INTERFACE,
242 retv_if(device_proxy == NULL, NULL);
244 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
245 g_variant_new("(s)", BT_DEVICE_INTERFACE),
246 G_DBUS_CALL_FLAGS_NONE,
250 BT_ERR("DBus Error : %s", err->message);
254 if (result == NULL) {
255 BT_ERR("g_dbus_proxy_call_sync function return NULL");
258 g_variant_get(result, "(@a{sv})", &value);
259 g_variant_unref(result);
261 g_object_unref(device_proxy);
263 GVariant *temp_value = g_variant_lookup_value(value, "Alias",
264 G_VARIANT_TYPE_STRING);
265 g_variant_get(temp_value, "(s)", &name);
267 g_variant_unref(temp_value);
268 BT_INFO("Alias Name: %s", name);
274 static int __bt_get_transfer_id(const char *path)
280 tmp = strrchr(path, 'r') + 1;
281 retv_if(tmp == NULL, -1);
286 static GDBusProxy *__bt_get_transfer_proxy(const char *transfer_path)
288 GDBusConnection *conn;
292 conn = _bt_get_session_gconn();
293 retv_if(conn == NULL, NULL);
295 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
296 NULL, BT_OBEX_SERVICE_NAME,
298 BT_OBEX_TRANSFER_INTERFACE,
302 BT_ERR("Error : %s", err->message);
310 static GDBusProxy *__bt_get_transfer_properties_proxy(const char *transfer_path)
312 GDBusConnection *conn;
315 conn = _bt_get_session_gconn();
316 retv_if(conn == NULL, NULL);
318 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
319 NULL,BT_OBEX_SERVICE_NAME,
321 BT_PROPERTIES_INTERFACE,
324 BT_ERR("Error : %s", err->message);
331 static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
332 const char *transfer_path)
334 GDBusProxy *transfer_proxy;
335 char *bdaddress = NULL;
336 GVariant *result = NULL;
338 GVariantIter *iter = NULL;
339 BT_CHECK_PARAMETER(transfer_info, return);
340 BT_CHECK_PARAMETER(transfer_path, return);
342 transfer_proxy = __bt_get_transfer_properties_proxy(transfer_path);
344 retv_if(transfer_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
346 result = g_dbus_proxy_call_sync(transfer_proxy, "GetAll",
347 g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
348 G_DBUS_CALL_FLAGS_NONE,
353 BT_ERR("DBus Error : %s", err->message);
357 if (result == NULL) {
358 BT_ERR("g_dbus_proxy_call_sync function return NULL");
362 g_variant_get(result, "(a{sv})", &iter);
363 g_variant_unref(result);
368 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
369 if (g_strcmp0(key, "Operation") == 0) {
370 transfer_info->type = g_variant_dup_string(val, &len);
371 } else if (g_strcmp0(key, "Name") == 0) {
372 transfer_info->filename = g_variant_dup_string(val, &len);
373 } else if (g_strcmp0(key, "Size") == 0) {
374 transfer_info->file_size = g_variant_get_uint64(val);
375 } else if (g_strcmp0(key, "Address") == 0) {
376 transfer_info->address = g_variant_dup_string(val, &len);
377 BT_INFO("addressss %s", transfer_info->address);
378 } else if (g_strcmp0(key, "Filename") == 0) {
379 transfer_info->file_path = g_variant_dup_string(val, &len);
380 if (!transfer_info->file_path)
381 transfer_info->file_path = g_strdup(transfer_info->filename);
384 g_variant_iter_free(iter);
385 if (transfer_info->type == NULL)
387 if (transfer_info->address == NULL)
390 transfer_info->device_name = __bt_get_remote_device_name(transfer_info->address);
392 if (!transfer_info->device_name)
393 transfer_info->device_name = g_strdup(bdaddress);
394 transfer_info->path = g_strdup(transfer_path);
395 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
398 g_object_unref(transfer_proxy);
399 return BLUETOOTH_ERROR_NONE;
402 g_object_unref(transfer_proxy);
403 return BLUETOOTH_ERROR_INTERNAL;
406 static gboolean __bt_authorize_cb(GDBusMethodInvocation *context,
410 char *device_name = NULL;
411 int result = BLUETOOTH_ERROR_NONE;
412 GDBusProxy *transfer_properties_proxy;
413 char * bdaddress = NULL;
416 GVariant *param = NULL;
419 BT_DBG(" path [%s] \n", path);
421 transfer_properties_proxy = __bt_get_transfer_properties_proxy(path);
423 retv_if(transfer_properties_proxy == NULL, FALSE);
425 ret = g_dbus_proxy_call_sync(transfer_properties_proxy, "GetAll",
426 g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
427 G_DBUS_CALL_FLAGS_NONE,
431 BT_ERR("DBus Error : %s", err->message);
436 BT_ERR("g_dbus_proxy_call_sync function return NULL");
439 g_variant_get(ret, "(a{sv})", &iter);
440 g_variant_unref(ret);
442 g_object_unref(transfer_properties_proxy);
446 #ifdef TIZEN_MDM_ENABLE
447 mdm_bt_allow_t mode = MDM_BT_ALLOWED;
450 __bt_free_auth_info(agent_info.auth_info);
452 agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t));
454 memset(agent_info.auth_info, 0, sizeof(bt_auth_info_t));
456 agent_info.auth_info->reply_context = context;
458 agent_info.auth_info->transfer_path = g_strdup(path);
464 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
465 if (g_strcmp0(key, "Name") == 0) {
466 agent_info.auth_info->filename = g_variant_dup_string(val,&len);
467 } else if (g_strcmp0(key, "Address") == 0) {
468 bdaddress = g_variant_dup_string(val, &len);
469 } else if (g_strcmp0(key, "Size") == 0) {
470 agent_info.auth_info->file_size = g_variant_get_uint64(val);
473 g_variant_iter_free(iter);
476 device_name = __bt_get_remote_device_name(bdaddress);
479 device_name = g_strdup(bdaddress);
481 agent_info.auth_info->device_name = device_name;
483 g_object_unref(transfer_properties_proxy);
485 if (agent_info.server_type == BT_CUSTOM_SERVER) {
486 /* No need to send the event */
487 _bt_obex_server_accept_authorize(agent_info.auth_info->filename, FALSE);
490 param = g_variant_new("(ist)", result,
491 agent_info.auth_info->filename,
492 agent_info.auth_info->file_size);
493 _bt_send_event(BT_OPP_SERVER_EVENT,
494 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
500 void _bt_obex_transfer_started(const char *transfer_path)
502 bt_transfer_info_t *transfer_info;
503 request_info_t *req_info;
504 GVariant *out_param1 = NULL;
505 GVariant *param = NULL;
506 int result = BLUETOOTH_ERROR_NONE;
508 BT_DBG("%s", transfer_path);
510 transfer_info = g_malloc0(sizeof(bt_transfer_info_t));
512 if (agent_info.auth_info != NULL
513 && g_strcmp0(transfer_path, agent_info.auth_info->transfer_path) == 0) {
514 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
515 transfer_info->file_size = agent_info.auth_info->file_size;
516 transfer_info->type = g_strdup(TRANSFER_PUT);
517 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
518 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
519 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
520 transfer_info->file_path = agent_info.auth_info->file_path;
521 transfer_info->address = g_strdup(agent_info.auth_info->address);
523 if (__bt_get_transfer_properties(transfer_info, transfer_path) < 0) {
524 BT_ERR("Get Properties failed");
525 __bt_free_auth_info(agent_info.auth_info);
526 __bt_free_transfer_info(transfer_info);
527 agent_info.auth_info = NULL;
530 agent_info.server_type = BT_FTP_SERVER;
533 __bt_free_auth_info(agent_info.auth_info);
534 agent_info.auth_info = NULL;
536 if (agent_info.server_type == BT_CUSTOM_SERVER) {
537 if (agent_info.custom_server == NULL) {
538 __bt_free_transfer_info(transfer_info);
542 req_info = _bt_get_request_info(agent_info.accept_id);
543 if (req_info == NULL || req_info->context == NULL) {
544 BT_ERR("info is NULL");
548 agent_info.accept_id = 0;
549 result = BLUETOOTH_ERROR_NONE;
550 GArray *g_out_param1 = NULL;
551 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
552 if (out_param1 == NULL) {
553 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
554 g_out_param1->data, g_out_param1->len,
558 g_dbus_method_invocation_return_value(req_info->context,
559 g_variant_new("(iv)", result, out_param1));
560 g_array_free(g_out_param1, TRUE);
561 _bt_delete_request_list(req_info->req_id);
564 transfers = g_slist_append(transfers, transfer_info);
566 BT_DBG("Transfer id %d\n", transfer_info->transfer_id);
567 param = g_variant_new("(isstii)", result,
568 transfer_info->filename,
570 transfer_info->file_size,
571 transfer_info->transfer_id,
572 agent_info.server_type);
573 _bt_send_event(BT_OPP_SERVER_EVENT,
574 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
578 void _bt_obex_transfer_progress(const char *transfer_path,
582 bt_transfer_info_t *transfer_info;
584 GVariant *param = NULL;
585 int result = BLUETOOTH_ERROR_NONE;
587 transfer_info = __bt_find_transfer_by_path(transfer_path);
588 ret_if(transfer_info == NULL);
590 progress = (int)(((gdouble)transferred /
591 (gdouble)transfer_info->file_size) * 100);
593 param = g_variant_new("(isstiii)", result,
594 transfer_info->filename,
596 transfer_info->file_size,
597 transfer_info->transfer_id,
599 agent_info.server_type);
600 _bt_send_event(BT_OPP_SERVER_EVENT,
601 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
606 void _bt_obex_transfer_completed(const char *transfer_path, gboolean success)
608 bt_transfer_info_t *transfer_info;
609 GVariant *param = NULL;
611 BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
613 result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
614 : BLUETOOTH_ERROR_CANCEL;
616 transfer_info = __bt_find_transfer_by_path(transfer_path);
618 if (transfer_info == NULL) {
619 BT_DBG("Very small files receiving case, did not get Active status from obexd");
620 if (agent_info.auth_info == NULL ||
621 g_strcmp0(transfer_path,
622 agent_info.auth_info->transfer_path) != 0) {
623 BT_ERR("auth_info is NULL, returning");
627 transfer_info = g_new0(bt_transfer_info_t, 1);
629 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
630 transfer_info->file_size = agent_info.auth_info->file_size;
631 transfer_info->type = g_strdup(TRANSFER_PUT);
632 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
633 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
634 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
635 transfer_info->file_path = agent_info.auth_info->file_path;
637 param = g_variant_new("(isstii)", result,
638 transfer_info->filename,
640 transfer_info->file_size,
641 transfer_info->transfer_id,
642 agent_info.server_type);
643 _bt_send_event(BT_OPP_SERVER_EVENT,
644 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
647 param = g_variant_new("(isssstii)", result,
648 transfer_info->filename,
650 transfer_info->device_name,
651 transfer_info->file_path,
652 transfer_info->file_size,
653 transfer_info->transfer_id,
654 agent_info.server_type);
655 _bt_send_event(BT_OPP_SERVER_EVENT,
656 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
658 transfers = g_slist_remove(transfers, transfer_info);
659 __bt_free_transfer_info(transfer_info);
662 void _bt_obex_transfer_connected()
666 int result = BLUETOOTH_ERROR_NONE;
667 GVariant *param = NULL;
669 param = g_variant_new("(i)", result);
671 _bt_send_event(BT_OPP_SERVER_EVENT,
672 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED,
677 void _bt_obex_transfer_disconnected()
681 int result = BLUETOOTH_ERROR_NONE;
682 GVariant *param = NULL;
684 param = g_variant_new("(i)", result);
685 _bt_send_event(BT_OPP_SERVER_EVENT,
686 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED,
691 int _bt_register_obex_server(void)
693 GDBusConnection *g_conn;
694 GDBusProxy *manager_proxy;
695 GError *g_error = NULL;
697 /* Get the session bus. */
698 g_conn = _bt_get_session_gconn();
699 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
701 _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
703 _bt_obex_setup(BT_OBEX_SERVER_AGENT_PATH);
705 _bt_obex_set_authorize_cb(BT_OBEX_SERVER_AGENT_PATH,
706 __bt_authorize_cb, NULL);
708 manager_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
709 NULL, BT_OBEX_SERVICE,
714 if (manager_proxy == NULL) {
715 return BLUETOOTH_ERROR_INTERNAL;
718 g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent",
719 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
720 G_DBUS_CALL_FLAGS_NONE,
724 if (g_error != NULL) {
725 BT_ERR("Agent registration failed: %s\n", g_error->message);
726 g_object_unref(manager_proxy);
727 g_error_free(g_error);
728 return BLUETOOTH_ERROR_INTERNAL;
731 agent_info.proxy = manager_proxy;
733 return BLUETOOTH_ERROR_NONE;
736 int _bt_unregister_obex_server(void)
738 GError *g_error = NULL;
740 retv_if(agent_info.proxy == NULL,
741 BLUETOOTH_ERROR_INTERNAL);
743 g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent",
744 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
745 G_DBUS_CALL_FLAGS_NONE,
748 if (g_error != NULL) {
749 BT_ERR("Agent unregistration failed: %s", g_error->message);
750 g_error_free(g_error);
752 _bt_obex_agent_destroy(BT_OBEX_SERVER_AGENT_PATH);
753 g_object_unref(agent_info.proxy);
754 agent_info.proxy = NULL;
756 return BLUETOOTH_ERROR_NONE;
759 gboolean __bt_check_folder_path(const char *dest_path)
763 retv_if(dest_path == NULL, FALSE);
765 dp = opendir(dest_path);
768 BT_ERR("The directory does not exist");
777 int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native)
780 if (__bt_check_folder_path(dest_path) == FALSE)
781 return BLUETOOTH_ERROR_INVALID_PARAM;
783 if (is_native == TRUE) {
784 retv_if(agent_info.native_server,
785 BLUETOOTH_ERROR_DEVICE_BUSY);
787 /* Force to change the control to native */
788 agent_info.native_server = g_malloc0(sizeof(bt_server_info_t));
789 agent_info.native_server->dest_path = g_strdup(dest_path);
790 agent_info.native_server->sender = g_strdup(sender);
791 agent_info.native_server->app_pid = app_pid;
792 agent_info.server_type = BT_NATIVE_SERVER;
793 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
795 retv_if(agent_info.custom_server,
796 BLUETOOTH_ERROR_DEVICE_BUSY);
798 /* Force to change the control to custom */
799 agent_info.custom_server = g_malloc0(sizeof(bt_server_info_t));
800 agent_info.custom_server->dest_path = g_strdup(dest_path);
801 agent_info.custom_server->sender = g_strdup(sender);
802 agent_info.custom_server->app_pid = app_pid;
803 agent_info.server_type = BT_CUSTOM_SERVER;
804 _bt_register_osp_server_in_agent(BT_OBEX_SERVER, NULL, NULL, -1);
807 return BLUETOOTH_ERROR_NONE;
810 int _bt_obex_server_deallocate(int app_pid, gboolean is_native)
812 if (is_native == TRUE) {
813 retv_if(agent_info.native_server == NULL,
814 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
816 retv_if(agent_info.native_server->app_pid != app_pid,
817 BLUETOOTH_ERROR_ACCESS_DENIED);
819 __bt_free_server_info(agent_info.native_server);
820 agent_info.native_server = NULL;
822 /* Change the control to custom */
823 if (agent_info.custom_server) {
824 agent_info.server_type = BT_CUSTOM_SERVER;
825 _bt_register_osp_server_in_agent(BT_OBEX_SERVER,
829 retv_if(agent_info.custom_server == NULL,
830 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
832 retv_if(agent_info.custom_server->app_pid != app_pid,
833 BLUETOOTH_ERROR_ACCESS_DENIED);
835 __bt_free_server_info(agent_info.custom_server);
836 agent_info.custom_server = NULL;
838 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
840 /* Change the control to native */
841 if (agent_info.native_server)
842 agent_info.server_type = BT_NATIVE_SERVER;
845 return BLUETOOTH_ERROR_NONE;
848 int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native)
850 char file_path[BT_FILE_PATH_MAX] = { 0 };
851 bt_server_info_t *server_info;
853 BT_CHECK_PARAMETER(filename, return);
855 retv_if(agent_info.auth_info == NULL, BLUETOOTH_ERROR_INTERNAL);
857 retv_if(agent_info.auth_info->reply_context == NULL,
858 BLUETOOTH_ERROR_INTERNAL);
860 if (is_native == TRUE)
861 server_info = agent_info.native_server;
863 server_info = agent_info.custom_server;
865 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
867 if (server_info->dest_path != NULL)
868 snprintf(file_path, sizeof(file_path), "%s/%s",
869 server_info->dest_path, filename);
871 snprintf(file_path, sizeof(file_path), "%s", filename);
873 g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context,
874 g_variant_new("(s)",&file_path));
875 agent_info.auth_info->reply_context = NULL;
876 agent_info.auth_info->file_path = g_strdup(file_path);
878 return BLUETOOTH_ERROR_NONE;
881 int _bt_obex_server_reject_authorize(void)
885 retv_if(agent_info.auth_info->reply_context == NULL,
886 BLUETOOTH_ERROR_INTERNAL);
888 g_error = g_error_new(__bt_obex_error_quark(),
889 BT_OBEX_AGENT_ERROR_CANCEL,
892 g_dbus_method_invocation_return_gerror(agent_info.auth_info->reply_context,
894 g_error_free(g_error);
896 __bt_free_auth_info(agent_info.auth_info);
897 agent_info.auth_info = NULL;
899 return BLUETOOTH_ERROR_NONE;
902 int _bt_obex_server_set_destination_path(const char *dest_path,
905 bt_server_info_t *server_info;
907 BT_CHECK_PARAMETER(dest_path, return);
911 dp = opendir(dest_path);
914 BT_ERR("The directory does not exist");
915 return BLUETOOTH_ERROR_INVALID_PARAM;
920 if (is_native == TRUE)
921 server_info = agent_info.native_server;
923 server_info = agent_info.custom_server;
925 retv_if(server_info == NULL,
926 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
928 g_free(server_info->dest_path);
929 server_info->dest_path = g_strdup(dest_path);
931 return BLUETOOTH_ERROR_NONE;
934 int _bt_obex_server_set_root(const char *root)
936 GError *g_error = NULL;
937 GVariant *folder = NULL;
938 char *string = "Root";
941 BT_CHECK_PARAMETER(root, return);
943 retv_if(agent_info.proxy == NULL,
944 BLUETOOTH_ERROR_INTERNAL);
949 BT_ERR("The directory does not exist");
950 return BLUETOOTH_ERROR_INVALID_PARAM;
955 folder = g_variant_new_string(root);
956 g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty",
957 g_variant_new("(sv)", string, folder),
958 G_DBUS_CALL_FLAGS_NONE,
963 BT_ERR("SetProperty Fail: %s", g_error->message);
964 g_error_free(g_error);
965 return BLUETOOTH_ERROR_INTERNAL;
968 return BLUETOOTH_ERROR_NONE;
971 int _bt_obex_server_cancel_transfer(int transfer_id)
973 bt_transfer_info_t *transfer = NULL;
977 transfer = __bt_find_transfer_by_id(transfer_id);
979 retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND);
980 proxy = __bt_get_transfer_proxy(transfer->path);
982 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
984 g_dbus_proxy_call_sync(proxy, "Cancel", NULL,
985 G_DBUS_CALL_FLAGS_NONE,
986 DBUS_TIMEOUT, NULL, &err);
988 BT_ERR("Dbus Err: %s", err->message);
991 g_object_unref(proxy);
993 return BLUETOOTH_ERROR_NONE;
996 int _bt_obex_server_cancel_all_transfers(void)
999 bt_transfer_info_t *transfer;
1001 for (l = transfers; l != NULL; l = l->next) {
1004 if (transfer == NULL)
1007 _bt_obex_server_cancel_transfer(transfer->transfer_id);
1010 return BLUETOOTH_ERROR_NONE;
1013 int _bt_obex_server_is_activated(gboolean *activated)
1015 BT_CHECK_PARAMETER(activated, return);
1017 if (agent_info.custom_server) {
1023 return BLUETOOTH_ERROR_NONE;
1026 int _bt_obex_server_check_allocation(gboolean *allocation)
1028 BT_CHECK_PARAMETER(allocation, return);
1030 if (agent_info.native_server || agent_info.custom_server) {
1033 *allocation = FALSE;
1036 return BLUETOOTH_ERROR_NONE;
1039 int _bt_obex_server_check_termination(char *sender)
1041 BT_CHECK_PARAMETER(sender, return);
1043 if (agent_info.native_server) {
1044 if (g_strcmp0(sender, agent_info.native_server->sender) == 0) {
1045 _bt_obex_server_deallocate(agent_info.native_server->app_pid,
1050 if (agent_info.custom_server) {
1051 if (g_strcmp0(sender, agent_info.custom_server->sender) == 0) {
1052 _bt_obex_server_deallocate(agent_info.custom_server->app_pid,
1057 return BLUETOOTH_ERROR_NONE;
1060 int _bt_obex_server_is_receiving(gboolean *receiving)
1062 BT_CHECK_PARAMETER(receiving, return);
1064 if (transfers == NULL || g_slist_length(transfers) == 0) {
1070 return BLUETOOTH_ERROR_NONE;
1073 gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data)
1075 request_info_t *req_info;
1076 GVariant *out_param1 = NULL;
1077 int result = BLUETOOTH_ERROR_TIMEOUT;
1079 /* Already reply in _bt_obex_transfer_started */
1080 retv_if(agent_info.accept_id == 0, FALSE);
1082 req_info = _bt_get_request_info(agent_info.accept_id);
1083 if (req_info == NULL || req_info->context == NULL) {
1084 BT_ERR("info is NULL");
1088 agent_info.accept_id = 0;
1089 GArray *g_out_param1 = NULL;
1090 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
1091 if (out_param1 == NULL) {
1092 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1093 g_out_param1->data, g_out_param1->len,
1097 g_dbus_method_invocation_return_value(req_info->context,
1098 g_variant_new("(iv)", result, out_param1));
1099 g_array_free(g_out_param1, TRUE);
1100 _bt_delete_request_list(req_info->req_id);
1105 /* To support the BOT */
1106 int _bt_obex_server_accept_connection(int request_id)
1108 if (!_bt_agent_reply_authorize(TRUE))
1109 return BLUETOOTH_ERROR_INTERNAL;
1111 agent_info.accept_id = request_id;
1113 g_timeout_add(BT_SERVER_ACCEPT_TIMEOUT,
1114 (GSourceFunc)__bt_obex_server_accept_timeout_cb,
1117 return BLUETOOTH_ERROR_NONE;
1120 /* To support the BOT */
1121 int _bt_obex_server_reject_connection(void)
1123 if (!_bt_agent_reply_authorize(FALSE))
1124 return BLUETOOTH_ERROR_INTERNAL;
1126 return BLUETOOTH_ERROR_NONE;