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 int _bt_obex_get_native_pid(void)
95 return agent_info.native_server->app_pid;
98 static GQuark __bt_obex_error_quark(void)
100 static GQuark quark = 0;
102 quark = g_quark_from_static_string("agent");
107 static bt_transfer_info_t *__bt_find_transfer_by_id(int transfer_id)
110 bt_transfer_info_t *transfer;
112 for (l = transfers; l != NULL; l = l->next) {
115 if (transfer == NULL)
118 if (transfer->transfer_id == transfer_id)
125 bt_transfer_info_t *__bt_find_transfer_by_address(const char *address)
129 bt_transfer_info_t *transfer;
131 retv_if(address == NULL, NULL);
133 for (l = transfers; l != NULL; l = l->next) {
136 if (transfer == NULL)
139 if (g_strcmp0(transfer->address, address) == 0)
146 static bt_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
149 bt_transfer_info_t *transfer;
151 retv_if(transfer_path == NULL, NULL);
153 for (l = transfers; l != NULL; l = l->next) {
156 if (transfer == NULL)
159 if (g_strcmp0(transfer->path, transfer_path) == 0)
166 static void __bt_free_server_info(bt_server_info_t *server_info)
168 ret_if(server_info == NULL);
170 g_free(server_info->sender);
171 g_free(server_info->dest_path);
175 static void __bt_free_auth_info(bt_auth_info_t *auto_info)
177 ret_if(auto_info == NULL);
179 g_free(auto_info->filename);
180 g_free(auto_info->transfer_path);
181 g_free(auto_info->device_name);
182 g_free(auto_info->address);
186 static void __bt_free_transfer_info(bt_transfer_info_t *transfer_info)
188 ret_if(transfer_info == NULL);
190 g_free(transfer_info->path);
191 g_free(transfer_info->filename);
192 g_free(transfer_info->file_path);
193 g_free(transfer_info->type);
194 g_free(transfer_info->device_name);
195 g_free(transfer_info->address);
196 g_free(transfer_info);
199 void _bt_obex_check_pending_transfer(const char *address)
202 GVariant *param = NULL;
203 bt_transfer_info_t *transfer_info = __bt_find_transfer_by_address(address);
204 if (transfer_info != NULL) {
205 int result = BLUETOOTH_ERROR_CANCEL;
206 param = g_variant_new("(isssstii)", result,
207 transfer_info->filename,
209 transfer_info->device_name,
210 transfer_info->file_path,
211 transfer_info->file_size,
212 transfer_info->transfer_id,
213 agent_info.server_type);
214 _bt_send_event(BT_OPP_SERVER_EVENT,
215 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
217 transfers = g_slist_remove(transfers, transfer_info);
218 __bt_free_transfer_info(transfer_info);
223 static char *__bt_get_remote_device_name(const char *bdaddress)
225 char *device_path = NULL;
228 GVariant *result = NULL;
230 GDBusProxy *device_proxy;
231 GDBusConnection *conn;
233 retv_if(bdaddress == NULL, NULL);
235 device_path = _bt_get_device_object_path((char *)bdaddress);
236 retv_if(device_path == NULL, NULL);
238 conn = _bt_get_system_gconn();
239 retv_if(conn == NULL, NULL);
240 BT_INFO("Device_path %s", device_path);
241 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
244 BT_PROPERTIES_INTERFACE,
248 retv_if(device_proxy == NULL, NULL);
250 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
251 g_variant_new("(s)", BT_DEVICE_INTERFACE),
252 G_DBUS_CALL_FLAGS_NONE,
256 BT_ERR("DBus Error : %s", err->message);
260 if (result == NULL) {
261 BT_ERR("g_dbus_proxy_call_sync function return NULL");
264 g_variant_get(result, "(@a{sv})", &value);
265 g_variant_unref(result);
267 g_object_unref(device_proxy);
269 GVariant *temp_value = g_variant_lookup_value(value, "Alias",
270 G_VARIANT_TYPE_STRING);
271 g_variant_get(temp_value, "(s)", &name);
273 g_variant_unref(temp_value);
274 BT_INFO("Alias Name: %s", name);
280 static int __bt_get_transfer_id(const char *path)
286 tmp = strrchr(path, 'r') + 1;
287 retv_if(tmp == NULL, -1);
292 static GDBusProxy *__bt_get_transfer_proxy(const char *transfer_path)
294 GDBusConnection *conn;
298 conn = _bt_get_session_gconn();
299 retv_if(conn == NULL, NULL);
301 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
302 NULL, BT_OBEX_SERVICE_NAME,
304 BT_OBEX_TRANSFER_INTERFACE,
308 BT_ERR("Error : %s", err->message);
316 static GDBusProxy *__bt_get_transfer_properties_proxy(const char *transfer_path)
318 GDBusConnection *conn;
321 conn = _bt_get_session_gconn();
322 retv_if(conn == NULL, NULL);
324 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
325 NULL,BT_OBEX_SERVICE_NAME,
327 BT_PROPERTIES_INTERFACE,
330 BT_ERR("Error : %s", err->message);
337 static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
338 const char *transfer_path)
340 GDBusProxy *transfer_proxy;
341 char *bdaddress = NULL;
342 GVariant *result = NULL;
344 GVariantIter *iter = NULL;
345 BT_CHECK_PARAMETER(transfer_info, return);
346 BT_CHECK_PARAMETER(transfer_path, return);
348 transfer_proxy = __bt_get_transfer_properties_proxy(transfer_path);
350 retv_if(transfer_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
352 result = g_dbus_proxy_call_sync(transfer_proxy, "GetAll",
353 g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
354 G_DBUS_CALL_FLAGS_NONE,
359 BT_ERR("DBus Error : %s", err->message);
363 if (result == NULL) {
364 BT_ERR("g_dbus_proxy_call_sync function return NULL");
368 g_variant_get(result, "(a{sv})", &iter);
369 g_variant_unref(result);
374 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
375 if (g_strcmp0(key, "Operation") == 0) {
376 transfer_info->type = g_variant_dup_string(val, &len);
377 } else if (g_strcmp0(key, "Name") == 0) {
378 transfer_info->filename = g_variant_dup_string(val, &len);
379 } else if (g_strcmp0(key, "Size") == 0) {
380 transfer_info->file_size = g_variant_get_uint64(val);
381 } else if (g_strcmp0(key, "Address") == 0) {
382 transfer_info->address = g_variant_dup_string(val, &len);
383 BT_INFO("addressss %s", transfer_info->address);
384 } else if (g_strcmp0(key, "Filename") == 0) {
385 transfer_info->file_path = g_variant_dup_string(val, &len);
386 if (!transfer_info->file_path)
387 transfer_info->file_path = g_strdup(transfer_info->filename);
390 g_variant_iter_free(iter);
391 if (transfer_info->type == NULL)
393 if (transfer_info->address == NULL)
396 transfer_info->device_name = __bt_get_remote_device_name(transfer_info->address);
398 if (!transfer_info->device_name)
399 transfer_info->device_name = g_strdup(bdaddress);
400 transfer_info->path = g_strdup(transfer_path);
401 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
404 g_object_unref(transfer_proxy);
405 return BLUETOOTH_ERROR_NONE;
408 g_object_unref(transfer_proxy);
409 return BLUETOOTH_ERROR_INTERNAL;
412 static gboolean __bt_authorize_cb(GDBusMethodInvocation *context,
416 char *device_name = NULL;
417 int result = BLUETOOTH_ERROR_NONE;
418 GDBusProxy *transfer_properties_proxy;
419 char * bdaddress = NULL;
422 GVariant *param = NULL;
425 BT_DBG(" path [%s] \n", path);
427 transfer_properties_proxy = __bt_get_transfer_properties_proxy(path);
429 retv_if(transfer_properties_proxy == NULL, FALSE);
431 ret = g_dbus_proxy_call_sync(transfer_properties_proxy, "GetAll",
432 g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
433 G_DBUS_CALL_FLAGS_NONE,
437 BT_ERR("DBus Error : %s", err->message);
442 BT_ERR("g_dbus_proxy_call_sync function return NULL");
445 g_variant_get(ret, "(a{sv})", &iter);
446 g_variant_unref(ret);
448 g_object_unref(transfer_properties_proxy);
452 #ifdef TIZEN_MDM_ENABLE
453 mdm_bt_allow_t mode = MDM_BT_ALLOWED;
456 __bt_free_auth_info(agent_info.auth_info);
458 agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t));
460 memset(agent_info.auth_info, 0, sizeof(bt_auth_info_t));
462 agent_info.auth_info->reply_context = context;
464 agent_info.auth_info->transfer_path = g_strdup(path);
470 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
471 if (g_strcmp0(key, "Name") == 0) {
472 agent_info.auth_info->filename = g_variant_dup_string(val,&len);
473 } else if (g_strcmp0(key, "Address") == 0) {
474 bdaddress = g_variant_dup_string(val, &len);
475 } else if (g_strcmp0(key, "Size") == 0) {
476 agent_info.auth_info->file_size = g_variant_get_uint64(val);
479 g_variant_iter_free(iter);
482 device_name = __bt_get_remote_device_name(bdaddress);
485 device_name = g_strdup(bdaddress);
487 agent_info.auth_info->device_name = device_name;
489 g_object_unref(transfer_properties_proxy);
491 if (agent_info.server_type == BT_CUSTOM_SERVER) {
492 /* No need to send the event */
493 _bt_obex_server_accept_authorize(agent_info.auth_info->filename, FALSE);
496 param = g_variant_new("(ist)", result,
497 agent_info.auth_info->filename,
498 agent_info.auth_info->file_size);
499 _bt_send_event(BT_OPP_SERVER_EVENT,
500 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
506 void _bt_obex_transfer_started(const char *transfer_path)
508 bt_transfer_info_t *transfer_info;
509 request_info_t *req_info;
510 GVariant *out_param1 = NULL;
511 GVariant *param = NULL;
512 int result = BLUETOOTH_ERROR_NONE;
514 BT_DBG("%s", transfer_path);
516 transfer_info = g_malloc0(sizeof(bt_transfer_info_t));
518 if (agent_info.auth_info != NULL
519 && g_strcmp0(transfer_path, agent_info.auth_info->transfer_path) == 0) {
520 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
521 transfer_info->file_size = agent_info.auth_info->file_size;
522 transfer_info->type = g_strdup(TRANSFER_PUT);
523 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
524 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
525 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
526 transfer_info->file_path = agent_info.auth_info->file_path;
527 transfer_info->address = g_strdup(agent_info.auth_info->address);
529 if (__bt_get_transfer_properties(transfer_info, transfer_path) < 0) {
530 BT_ERR("Get Properties failed");
531 __bt_free_auth_info(agent_info.auth_info);
532 __bt_free_transfer_info(transfer_info);
533 agent_info.auth_info = NULL;
536 agent_info.server_type = BT_FTP_SERVER;
539 __bt_free_auth_info(agent_info.auth_info);
540 agent_info.auth_info = NULL;
542 if (agent_info.server_type == BT_CUSTOM_SERVER) {
543 if (agent_info.custom_server == NULL) {
544 __bt_free_transfer_info(transfer_info);
548 req_info = _bt_get_request_info(agent_info.accept_id);
549 if (req_info == NULL || req_info->context == NULL) {
550 BT_ERR("info is NULL");
554 agent_info.accept_id = 0;
555 result = BLUETOOTH_ERROR_NONE;
556 GArray *g_out_param1 = NULL;
557 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
558 if (out_param1 == NULL) {
559 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
560 g_out_param1->data, g_out_param1->len,
564 g_dbus_method_invocation_return_value(req_info->context,
565 g_variant_new("(iv)", result, out_param1));
566 g_array_free(g_out_param1, TRUE);
567 _bt_delete_request_list(req_info->req_id);
570 transfers = g_slist_append(transfers, transfer_info);
572 BT_DBG("Transfer id %d\n", transfer_info->transfer_id);
573 param = g_variant_new("(isstii)", result,
574 transfer_info->filename,
576 transfer_info->file_size,
577 transfer_info->transfer_id,
578 agent_info.server_type);
579 _bt_send_event(BT_OPP_SERVER_EVENT,
580 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
584 void _bt_obex_transfer_progress(const char *transfer_path,
588 bt_transfer_info_t *transfer_info;
590 GVariant *param = NULL;
591 int result = BLUETOOTH_ERROR_NONE;
593 transfer_info = __bt_find_transfer_by_path(transfer_path);
594 ret_if(transfer_info == NULL);
596 progress = (int)(((gdouble)transferred /
597 (gdouble)transfer_info->file_size) * 100);
599 param = g_variant_new("(isstiii)", result,
600 transfer_info->filename,
602 transfer_info->file_size,
603 transfer_info->transfer_id,
605 agent_info.server_type);
606 _bt_send_event(BT_OPP_SERVER_EVENT,
607 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
612 void _bt_obex_transfer_completed(const char *transfer_path, gboolean success)
614 bt_transfer_info_t *transfer_info;
615 GVariant *param = NULL;
617 BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
619 result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
620 : BLUETOOTH_ERROR_CANCEL;
622 transfer_info = __bt_find_transfer_by_path(transfer_path);
624 if (transfer_info == NULL) {
625 BT_DBG("Very small files receiving case, did not get Active status from obexd");
626 if (agent_info.auth_info == NULL ||
627 g_strcmp0(transfer_path,
628 agent_info.auth_info->transfer_path) != 0) {
629 BT_ERR("auth_info is NULL, returning");
633 transfer_info = g_new0(bt_transfer_info_t, 1);
635 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
636 transfer_info->file_size = agent_info.auth_info->file_size;
637 transfer_info->type = g_strdup(TRANSFER_PUT);
638 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
639 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
640 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
641 transfer_info->file_path = agent_info.auth_info->file_path;
643 param = g_variant_new("(isstii)", result,
644 transfer_info->filename,
646 transfer_info->file_size,
647 transfer_info->transfer_id,
648 agent_info.server_type);
649 _bt_send_event(BT_OPP_SERVER_EVENT,
650 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
653 param = g_variant_new("(isssstii)", result,
654 transfer_info->filename,
656 transfer_info->device_name,
657 transfer_info->file_path,
658 transfer_info->file_size,
659 transfer_info->transfer_id,
660 agent_info.server_type);
661 _bt_send_event(BT_OPP_SERVER_EVENT,
662 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
664 transfers = g_slist_remove(transfers, transfer_info);
665 __bt_free_transfer_info(transfer_info);
668 void _bt_obex_transfer_connected()
672 int result = BLUETOOTH_ERROR_NONE;
673 GVariant *param = NULL;
675 param = g_variant_new("(i)", result);
677 _bt_send_event(BT_OPP_SERVER_EVENT,
678 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED,
683 void _bt_obex_transfer_disconnected()
687 int result = BLUETOOTH_ERROR_NONE;
688 GVariant *param = NULL;
690 param = g_variant_new("(i)", result);
691 _bt_send_event(BT_OPP_SERVER_EVENT,
692 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED,
697 int _bt_register_obex_server(void)
699 GDBusConnection *g_conn;
700 GDBusProxy *manager_proxy;
701 GError *g_error = NULL;
703 /* Get the session bus. */
704 g_conn = _bt_get_session_gconn();
705 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
707 _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
709 _bt_obex_setup(BT_OBEX_SERVER_AGENT_PATH);
711 _bt_obex_set_authorize_cb(BT_OBEX_SERVER_AGENT_PATH,
712 __bt_authorize_cb, NULL);
714 manager_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
715 NULL, BT_OBEX_SERVICE,
720 if (manager_proxy == NULL) {
721 return BLUETOOTH_ERROR_INTERNAL;
724 g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent",
725 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
726 G_DBUS_CALL_FLAGS_NONE,
730 if (g_error != NULL) {
731 BT_ERR("Agent registration failed: %s\n", g_error->message);
732 g_object_unref(manager_proxy);
733 g_error_free(g_error);
734 return BLUETOOTH_ERROR_INTERNAL;
737 agent_info.proxy = manager_proxy;
739 return BLUETOOTH_ERROR_NONE;
742 int _bt_unregister_obex_server(void)
744 GError *g_error = NULL;
746 retv_if(agent_info.proxy == NULL,
747 BLUETOOTH_ERROR_INTERNAL);
749 g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent",
750 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
751 G_DBUS_CALL_FLAGS_NONE,
754 if (g_error != NULL) {
755 BT_ERR("Agent unregistration failed: %s", g_error->message);
756 g_error_free(g_error);
758 _bt_obex_agent_destroy(BT_OBEX_SERVER_AGENT_PATH);
759 g_object_unref(agent_info.proxy);
760 agent_info.proxy = NULL;
762 return BLUETOOTH_ERROR_NONE;
765 gboolean __bt_check_folder_path(const char *dest_path)
769 retv_if(dest_path == NULL, FALSE);
771 dp = opendir(dest_path);
774 BT_ERR("The directory does not exist");
783 int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native)
786 if (__bt_check_folder_path(dest_path) == FALSE)
787 return BLUETOOTH_ERROR_INVALID_PARAM;
789 if (is_native == TRUE) {
790 retv_if(agent_info.native_server,
791 BLUETOOTH_ERROR_DEVICE_BUSY);
793 /* Force to change the control to native */
794 agent_info.native_server = g_malloc0(sizeof(bt_server_info_t));
795 agent_info.native_server->dest_path = g_strdup(dest_path);
796 agent_info.native_server->sender = g_strdup(sender);
797 agent_info.native_server->app_pid = app_pid;
798 agent_info.server_type = BT_NATIVE_SERVER;
799 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
801 retv_if(agent_info.custom_server,
802 BLUETOOTH_ERROR_DEVICE_BUSY);
804 /* Force to change the control to custom */
805 agent_info.custom_server = g_malloc0(sizeof(bt_server_info_t));
806 agent_info.custom_server->dest_path = g_strdup(dest_path);
807 agent_info.custom_server->sender = g_strdup(sender);
808 agent_info.custom_server->app_pid = app_pid;
809 agent_info.server_type = BT_CUSTOM_SERVER;
810 _bt_register_osp_server_in_agent(BT_OBEX_SERVER, NULL, NULL, -1);
813 return BLUETOOTH_ERROR_NONE;
816 int _bt_obex_server_deallocate(int app_pid, gboolean is_native)
818 if (is_native == TRUE) {
819 retv_if(agent_info.native_server == NULL,
820 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
822 retv_if(agent_info.native_server->app_pid != app_pid,
823 BLUETOOTH_ERROR_ACCESS_DENIED);
825 __bt_free_server_info(agent_info.native_server);
826 agent_info.native_server = NULL;
828 /* Change the control to custom */
829 if (agent_info.custom_server) {
830 agent_info.server_type = BT_CUSTOM_SERVER;
831 _bt_register_osp_server_in_agent(BT_OBEX_SERVER,
835 retv_if(agent_info.custom_server == NULL,
836 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
838 retv_if(agent_info.custom_server->app_pid != app_pid,
839 BLUETOOTH_ERROR_ACCESS_DENIED);
841 __bt_free_server_info(agent_info.custom_server);
842 agent_info.custom_server = NULL;
844 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
846 /* Change the control to native */
847 if (agent_info.native_server)
848 agent_info.server_type = BT_NATIVE_SERVER;
851 return BLUETOOTH_ERROR_NONE;
854 int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native)
856 char file_path[BT_FILE_PATH_MAX] = { 0 };
857 bt_server_info_t *server_info;
859 BT_CHECK_PARAMETER(filename, return);
861 retv_if(agent_info.auth_info == NULL, BLUETOOTH_ERROR_INTERNAL);
863 retv_if(agent_info.auth_info->reply_context == NULL,
864 BLUETOOTH_ERROR_INTERNAL);
866 if (is_native == TRUE)
867 server_info = agent_info.native_server;
869 server_info = agent_info.custom_server;
871 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
873 if (server_info->dest_path != NULL)
874 snprintf(file_path, sizeof(file_path), "%s/%s",
875 server_info->dest_path, filename);
877 snprintf(file_path, sizeof(file_path), "%s", filename);
879 g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context,
880 g_variant_new("(s)",&file_path));
881 agent_info.auth_info->reply_context = NULL;
882 agent_info.auth_info->file_path = g_strdup(file_path);
884 return BLUETOOTH_ERROR_NONE;
887 int _bt_obex_server_reject_authorize(void)
891 retv_if(agent_info.auth_info->reply_context == NULL,
892 BLUETOOTH_ERROR_INTERNAL);
894 g_error = g_error_new(__bt_obex_error_quark(),
895 BT_OBEX_AGENT_ERROR_CANCEL,
898 g_dbus_method_invocation_return_gerror(agent_info.auth_info->reply_context,
900 g_error_free(g_error);
902 __bt_free_auth_info(agent_info.auth_info);
903 agent_info.auth_info = NULL;
905 return BLUETOOTH_ERROR_NONE;
908 int _bt_obex_server_set_destination_path(const char *dest_path,
911 bt_server_info_t *server_info;
913 BT_CHECK_PARAMETER(dest_path, return);
917 dp = opendir(dest_path);
920 BT_ERR("The directory does not exist");
921 return BLUETOOTH_ERROR_INVALID_PARAM;
926 if (is_native == TRUE)
927 server_info = agent_info.native_server;
929 server_info = agent_info.custom_server;
931 retv_if(server_info == NULL,
932 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
934 g_free(server_info->dest_path);
935 server_info->dest_path = g_strdup(dest_path);
937 return BLUETOOTH_ERROR_NONE;
940 int _bt_obex_server_set_root(const char *root)
942 GError *g_error = NULL;
943 GVariant *folder = NULL;
944 char *string = "Root";
947 BT_CHECK_PARAMETER(root, return);
949 retv_if(agent_info.proxy == NULL,
950 BLUETOOTH_ERROR_INTERNAL);
955 BT_ERR("The directory does not exist");
956 return BLUETOOTH_ERROR_INVALID_PARAM;
961 folder = g_variant_new_string(root);
962 g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty",
963 g_variant_new("(sv)", string, folder),
964 G_DBUS_CALL_FLAGS_NONE,
969 BT_ERR("SetProperty Fail: %s", g_error->message);
970 g_error_free(g_error);
971 return BLUETOOTH_ERROR_INTERNAL;
974 return BLUETOOTH_ERROR_NONE;
977 int _bt_obex_server_cancel_transfer(int transfer_id)
979 bt_transfer_info_t *transfer = NULL;
983 transfer = __bt_find_transfer_by_id(transfer_id);
985 retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND);
986 proxy = __bt_get_transfer_proxy(transfer->path);
988 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
990 g_dbus_proxy_call_sync(proxy, "Cancel", NULL,
991 G_DBUS_CALL_FLAGS_NONE,
992 DBUS_TIMEOUT, NULL, &err);
994 BT_ERR("Dbus Err: %s", err->message);
997 g_object_unref(proxy);
999 return BLUETOOTH_ERROR_NONE;
1002 int _bt_obex_server_cancel_all_transfers(void)
1005 bt_transfer_info_t *transfer;
1007 for (l = transfers; l != NULL; l = l->next) {
1010 if (transfer == NULL)
1013 _bt_obex_server_cancel_transfer(transfer->transfer_id);
1016 return BLUETOOTH_ERROR_NONE;
1019 int _bt_obex_server_is_activated(gboolean *activated)
1021 BT_CHECK_PARAMETER(activated, return);
1023 if (agent_info.custom_server) {
1029 return BLUETOOTH_ERROR_NONE;
1032 int _bt_obex_server_check_allocation(gboolean *allocation)
1034 BT_CHECK_PARAMETER(allocation, return);
1036 if (agent_info.native_server || agent_info.custom_server) {
1039 *allocation = FALSE;
1042 return BLUETOOTH_ERROR_NONE;
1045 int _bt_obex_server_check_termination(char *sender)
1047 BT_CHECK_PARAMETER(sender, return);
1049 if (agent_info.native_server) {
1050 if (g_strcmp0(sender, agent_info.native_server->sender) == 0) {
1051 _bt_obex_server_deallocate(agent_info.native_server->app_pid,
1056 if (agent_info.custom_server) {
1057 if (g_strcmp0(sender, agent_info.custom_server->sender) == 0) {
1058 _bt_obex_server_deallocate(agent_info.custom_server->app_pid,
1063 return BLUETOOTH_ERROR_NONE;
1066 int _bt_obex_server_is_receiving(gboolean *receiving)
1068 BT_CHECK_PARAMETER(receiving, return);
1070 if (transfers == NULL || g_slist_length(transfers) == 0) {
1076 return BLUETOOTH_ERROR_NONE;
1079 gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data)
1081 request_info_t *req_info;
1082 GVariant *out_param1 = NULL;
1083 int result = BLUETOOTH_ERROR_TIMEOUT;
1085 /* Already reply in _bt_obex_transfer_started */
1086 retv_if(agent_info.accept_id == 0, FALSE);
1088 req_info = _bt_get_request_info(agent_info.accept_id);
1089 if (req_info == NULL || req_info->context == NULL) {
1090 BT_ERR("info is NULL");
1094 agent_info.accept_id = 0;
1095 GArray *g_out_param1 = NULL;
1096 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
1097 if (out_param1 == NULL) {
1098 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1099 g_out_param1->data, g_out_param1->len,
1103 g_dbus_method_invocation_return_value(req_info->context,
1104 g_variant_new("(iv)", result, out_param1));
1105 g_array_free(g_out_param1, TRUE);
1106 _bt_delete_request_list(req_info->req_id);
1111 /* To support the BOT */
1112 int _bt_obex_server_accept_connection(int request_id)
1114 if (!_bt_agent_reply_authorize(TRUE))
1115 return BLUETOOTH_ERROR_INTERNAL;
1117 agent_info.accept_id = request_id;
1119 g_timeout_add(BT_SERVER_ACCEPT_TIMEOUT,
1120 (GSourceFunc)__bt_obex_server_accept_timeout_cb,
1123 return BLUETOOTH_ERROR_NONE;
1126 /* To support the BOT */
1127 int _bt_obex_server_reject_connection(void)
1129 if (!_bt_agent_reply_authorize(FALSE))
1130 return BLUETOOTH_ERROR_INTERNAL;
1132 return BLUETOOTH_ERROR_NONE;