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_DPM_ENABLE
24 #include "bt-service-dpm.h"
31 #include "bluetooth-api.h"
32 #include "bt-internal-types.h"
34 #include "bt-service-common.h"
35 #include "bt-service-event.h"
36 #include "bt-service-util.h"
37 #include "bt-service-obex-agent.h"
38 #include "bt-service-obex-server.h"
39 #include "bt-service-agent.h"
41 #define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
42 #define BT_OBEX_SERVER_AGENT_PATH "/org/obex/server_agent"
44 #define BT_OBEX_SERVICE "org.bluez.obex"
45 #define BT_OBEX_MANAGER "org.bluez.obex.AgentManager1"
46 #define BT_OBEX_PATH "/org/bluez/obex"
61 GDBusMethodInvocation *reply_context;
80 bt_auth_info_t *auth_info;
81 bt_server_info_t *native_server;
82 bt_server_info_t *custom_server;
83 } bt_obex_agent_info_t;
85 static GSList *transfers;
86 static bt_obex_agent_info_t agent_info;
88 int _bt_obex_get_native_pid(void)
90 return agent_info.native_server->app_pid;
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_system_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 __bt_free_auth_info(agent_info.auth_info);
449 agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t));
451 memset(agent_info.auth_info, 0, sizeof(bt_auth_info_t));
453 agent_info.auth_info->reply_context = context;
455 agent_info.auth_info->transfer_path = g_strdup(path);
457 #ifdef TIZEN_DPM_ENABLE
458 if(_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_HANDSFREE_ONLY) {
459 /* Free auth info in next function */
460 _bt_obex_server_reject_authorize();
469 while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
470 if (g_strcmp0(key, "Name") == 0) {
471 agent_info.auth_info->filename = g_variant_dup_string(val,&len);
472 } else if (g_strcmp0(key, "Address") == 0) {
473 bdaddress = g_variant_dup_string(val, &len);
474 } else if (g_strcmp0(key, "Size") == 0) {
475 agent_info.auth_info->file_size = g_variant_get_uint64(val);
478 g_variant_iter_free(iter);
481 device_name = __bt_get_remote_device_name(bdaddress);
484 device_name = g_strdup(bdaddress);
486 agent_info.auth_info->device_name = device_name;
488 g_object_unref(transfer_properties_proxy);
490 if (agent_info.server_type == BT_CUSTOM_SERVER) {
491 /* No need to send the event */
492 _bt_obex_server_accept_authorize(agent_info.auth_info->filename, FALSE);
495 param = g_variant_new("(ist)", result,
496 agent_info.auth_info->filename,
497 agent_info.auth_info->file_size);
498 _bt_send_event(BT_OPP_SERVER_EVENT,
499 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
505 void _bt_obex_transfer_started(const char *transfer_path)
507 bt_transfer_info_t *transfer_info;
508 request_info_t *req_info;
509 GVariant *out_param1 = NULL;
510 GVariant *param = NULL;
511 int result = BLUETOOTH_ERROR_NONE;
513 BT_DBG("%s", transfer_path);
515 transfer_info = g_malloc0(sizeof(bt_transfer_info_t));
517 if (agent_info.auth_info != NULL
518 && g_strcmp0(transfer_path, agent_info.auth_info->transfer_path) == 0) {
519 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
520 transfer_info->file_size = agent_info.auth_info->file_size;
521 transfer_info->type = g_strdup(TRANSFER_PUT);
522 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
523 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
524 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
525 transfer_info->file_path = agent_info.auth_info->file_path;
526 transfer_info->address = g_strdup(agent_info.auth_info->address);
528 if (__bt_get_transfer_properties(transfer_info, transfer_path) < 0) {
529 BT_ERR("Get Properties failed");
530 __bt_free_auth_info(agent_info.auth_info);
531 __bt_free_transfer_info(transfer_info);
532 agent_info.auth_info = NULL;
535 agent_info.server_type = BT_FTP_SERVER;
538 __bt_free_auth_info(agent_info.auth_info);
539 agent_info.auth_info = NULL;
541 if (agent_info.server_type == BT_CUSTOM_SERVER) {
542 if (agent_info.custom_server == NULL) {
543 __bt_free_transfer_info(transfer_info);
547 req_info = _bt_get_request_info(agent_info.accept_id);
548 if (req_info == NULL || req_info->context == NULL) {
549 BT_ERR("info is NULL");
553 agent_info.accept_id = 0;
554 result = BLUETOOTH_ERROR_NONE;
555 GArray *g_out_param1 = NULL;
556 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
557 if (out_param1 == NULL) {
558 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
559 g_out_param1->data, g_out_param1->len,
563 g_dbus_method_invocation_return_value(req_info->context,
564 g_variant_new("(iv)", result, out_param1));
565 g_array_free(g_out_param1, TRUE);
566 _bt_delete_request_list(req_info->req_id);
569 transfers = g_slist_append(transfers, transfer_info);
571 BT_DBG("Transfer id %d\n", transfer_info->transfer_id);
572 param = g_variant_new("(isstii)", result,
573 transfer_info->filename,
575 transfer_info->file_size,
576 transfer_info->transfer_id,
577 agent_info.server_type);
578 _bt_send_event(BT_OPP_SERVER_EVENT,
579 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
583 void _bt_obex_transfer_progress(const char *transfer_path,
587 bt_transfer_info_t *transfer_info;
589 GVariant *param = NULL;
590 int result = BLUETOOTH_ERROR_NONE;
592 transfer_info = __bt_find_transfer_by_path(transfer_path);
593 ret_if(transfer_info == NULL);
595 progress = (int)(((gdouble)transferred /
596 (gdouble)transfer_info->file_size) * 100);
598 param = g_variant_new("(isstiii)", result,
599 transfer_info->filename,
601 transfer_info->file_size,
602 transfer_info->transfer_id,
604 agent_info.server_type);
605 _bt_send_event(BT_OPP_SERVER_EVENT,
606 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
611 void _bt_obex_transfer_completed(const char *transfer_path, gboolean success)
613 bt_transfer_info_t *transfer_info;
614 GVariant *param = NULL;
616 BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
618 result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
619 : BLUETOOTH_ERROR_CANCEL;
621 transfer_info = __bt_find_transfer_by_path(transfer_path);
623 if (transfer_info == NULL) {
624 BT_DBG("Very small files receiving case, did not get Active status from obexd");
625 if (agent_info.auth_info == NULL ||
626 g_strcmp0(transfer_path,
627 agent_info.auth_info->transfer_path) != 0) {
628 BT_ERR("auth_info is NULL, returning");
632 transfer_info = g_new0(bt_transfer_info_t, 1);
634 transfer_info->filename = g_strdup(agent_info.auth_info->filename);
635 transfer_info->file_size = agent_info.auth_info->file_size;
636 transfer_info->type = g_strdup(TRANSFER_PUT);
637 transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
638 transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
639 transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
640 transfer_info->file_path = agent_info.auth_info->file_path;
642 param = g_variant_new("(isstii)", result,
643 transfer_info->filename,
645 transfer_info->file_size,
646 transfer_info->transfer_id,
647 agent_info.server_type);
648 _bt_send_event(BT_OPP_SERVER_EVENT,
649 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
652 param = g_variant_new("(isssstii)", result,
653 transfer_info->filename,
655 transfer_info->device_name,
656 transfer_info->file_path,
657 transfer_info->file_size,
658 transfer_info->transfer_id,
659 agent_info.server_type);
660 _bt_send_event(BT_OPP_SERVER_EVENT,
661 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
663 transfers = g_slist_remove(transfers, transfer_info);
664 __bt_free_transfer_info(transfer_info);
667 void _bt_obex_transfer_connected()
671 int result = BLUETOOTH_ERROR_NONE;
672 GVariant *param = NULL;
674 param = g_variant_new("(i)", result);
676 _bt_send_event(BT_OPP_SERVER_EVENT,
677 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED,
682 void _bt_obex_transfer_disconnected()
686 int result = BLUETOOTH_ERROR_NONE;
687 GVariant *param = NULL;
689 param = g_variant_new("(i)", result);
690 _bt_send_event(BT_OPP_SERVER_EVENT,
691 BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED,
696 int _bt_register_obex_server(void)
698 GDBusConnection *g_conn;
699 GDBusProxy *manager_proxy;
700 GError *g_error = NULL;
702 /* Get the session bus. */
703 g_conn = _bt_get_session_gconn();
704 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
706 _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
708 _bt_obex_setup(BT_OBEX_SERVER_AGENT_PATH);
710 _bt_obex_set_authorize_cb(BT_OBEX_SERVER_AGENT_PATH,
711 __bt_authorize_cb, NULL);
713 manager_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
714 NULL, BT_OBEX_SERVICE,
719 if (manager_proxy == NULL) {
720 return BLUETOOTH_ERROR_INTERNAL;
723 g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent",
724 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
725 G_DBUS_CALL_FLAGS_NONE,
729 if (g_error != NULL) {
730 BT_ERR("Agent registration failed: %s\n", g_error->message);
731 g_object_unref(manager_proxy);
732 g_error_free(g_error);
733 return BLUETOOTH_ERROR_INTERNAL;
736 agent_info.proxy = manager_proxy;
738 return BLUETOOTH_ERROR_NONE;
741 int _bt_unregister_obex_server(void)
743 GError *g_error = NULL;
745 retv_if(agent_info.proxy == NULL,
746 BLUETOOTH_ERROR_INTERNAL);
748 g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent",
749 g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
750 G_DBUS_CALL_FLAGS_NONE,
753 if (g_error != NULL) {
754 BT_ERR("Agent unregistration failed: %s", g_error->message);
755 g_error_free(g_error);
757 _bt_obex_agent_destroy(BT_OBEX_SERVER_AGENT_PATH);
758 g_object_unref(agent_info.proxy);
759 agent_info.proxy = NULL;
761 return BLUETOOTH_ERROR_NONE;
764 gboolean __bt_check_folder_path(const char *dest_path)
768 retv_if(dest_path == NULL, FALSE);
770 dp = opendir(dest_path);
773 BT_ERR("The directory does not exist");
782 int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native)
785 if (__bt_check_folder_path(dest_path) == FALSE)
786 return BLUETOOTH_ERROR_INVALID_PARAM;
788 if (is_native == TRUE) {
789 retv_if(agent_info.native_server,
790 BLUETOOTH_ERROR_DEVICE_BUSY);
792 /* Force to change the control to native */
793 agent_info.native_server = g_malloc0(sizeof(bt_server_info_t));
794 agent_info.native_server->dest_path = g_strdup(dest_path);
795 agent_info.native_server->sender = g_strdup(sender);
796 agent_info.native_server->app_pid = app_pid;
797 agent_info.server_type = BT_NATIVE_SERVER;
798 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
800 retv_if(agent_info.custom_server,
801 BLUETOOTH_ERROR_DEVICE_BUSY);
803 /* Force to change the control to custom */
804 agent_info.custom_server = g_malloc0(sizeof(bt_server_info_t));
805 agent_info.custom_server->dest_path = g_strdup(dest_path);
806 agent_info.custom_server->sender = g_strdup(sender);
807 agent_info.custom_server->app_pid = app_pid;
808 agent_info.server_type = BT_CUSTOM_SERVER;
809 _bt_register_osp_server_in_agent(BT_OBEX_SERVER, NULL, NULL, -1);
812 return BLUETOOTH_ERROR_NONE;
815 int _bt_obex_server_deallocate(int app_pid, gboolean is_native)
817 if (is_native == TRUE) {
818 retv_if(agent_info.native_server == NULL,
819 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
821 retv_if(agent_info.native_server->app_pid != app_pid,
822 BLUETOOTH_ERROR_ACCESS_DENIED);
824 __bt_free_server_info(agent_info.native_server);
825 agent_info.native_server = NULL;
827 /* Change the control to custom */
828 if (agent_info.custom_server) {
829 agent_info.server_type = BT_CUSTOM_SERVER;
830 _bt_register_osp_server_in_agent(BT_OBEX_SERVER,
834 retv_if(agent_info.custom_server == NULL,
835 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
837 retv_if(agent_info.custom_server->app_pid != app_pid,
838 BLUETOOTH_ERROR_ACCESS_DENIED);
840 __bt_free_server_info(agent_info.custom_server);
841 agent_info.custom_server = NULL;
843 _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
845 /* Change the control to native */
846 if (agent_info.native_server)
847 agent_info.server_type = BT_NATIVE_SERVER;
850 return BLUETOOTH_ERROR_NONE;
853 int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native)
855 char file_path[BT_FILE_PATH_MAX] = { 0 };
856 bt_server_info_t *server_info;
858 BT_CHECK_PARAMETER(filename, return);
860 retv_if(agent_info.auth_info == NULL, BLUETOOTH_ERROR_INTERNAL);
862 retv_if(agent_info.auth_info->reply_context == NULL,
863 BLUETOOTH_ERROR_INTERNAL);
865 if (is_native == TRUE)
866 server_info = agent_info.native_server;
868 server_info = agent_info.custom_server;
870 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
872 if (server_info->dest_path != NULL)
873 snprintf(file_path, sizeof(file_path), "%s/%s",
874 server_info->dest_path, filename);
876 snprintf(file_path, sizeof(file_path), "%s", filename);
878 g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context,
879 g_variant_new("(s)",&file_path));
880 agent_info.auth_info->reply_context = NULL;
881 agent_info.auth_info->file_path = g_strdup(file_path);
883 return BLUETOOTH_ERROR_NONE;
886 int _bt_obex_server_reject_authorize(void)
890 retv_if(agent_info.auth_info->reply_context == NULL,
891 BLUETOOTH_ERROR_INTERNAL);
893 g_error = g_error_new(__bt_obex_error_quark(),
894 BT_OBEX_AGENT_ERROR_CANCEL,
897 g_dbus_method_invocation_return_gerror(agent_info.auth_info->reply_context,
899 g_error_free(g_error);
901 __bt_free_auth_info(agent_info.auth_info);
902 agent_info.auth_info = NULL;
904 return BLUETOOTH_ERROR_NONE;
907 int _bt_obex_server_set_destination_path(const char *dest_path,
910 bt_server_info_t *server_info;
912 BT_CHECK_PARAMETER(dest_path, return);
916 dp = opendir(dest_path);
919 BT_ERR("The directory does not exist");
920 return BLUETOOTH_ERROR_INVALID_PARAM;
925 if (is_native == TRUE)
926 server_info = agent_info.native_server;
928 server_info = agent_info.custom_server;
930 retv_if(server_info == NULL,
931 BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
933 g_free(server_info->dest_path);
934 server_info->dest_path = g_strdup(dest_path);
936 return BLUETOOTH_ERROR_NONE;
939 int _bt_obex_server_set_root(const char *root)
941 GError *g_error = NULL;
942 GVariant *folder = NULL;
943 char *string = "Root";
946 BT_CHECK_PARAMETER(root, return);
948 retv_if(agent_info.proxy == NULL,
949 BLUETOOTH_ERROR_INTERNAL);
954 BT_ERR("The directory does not exist");
955 return BLUETOOTH_ERROR_INVALID_PARAM;
960 folder = g_variant_new_string(root);
961 g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty",
962 g_variant_new("(sv)", string, folder),
963 G_DBUS_CALL_FLAGS_NONE,
968 BT_ERR("SetProperty Fail: %s", g_error->message);
969 g_error_free(g_error);
970 return BLUETOOTH_ERROR_INTERNAL;
973 return BLUETOOTH_ERROR_NONE;
976 int _bt_obex_server_cancel_transfer(int transfer_id)
978 bt_transfer_info_t *transfer = NULL;
982 transfer = __bt_find_transfer_by_id(transfer_id);
984 retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND);
985 proxy = __bt_get_transfer_proxy(transfer->path);
987 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
989 g_dbus_proxy_call_sync(proxy, "Cancel", NULL,
990 G_DBUS_CALL_FLAGS_NONE,
991 DBUS_TIMEOUT, NULL, &err);
993 BT_ERR("Dbus Err: %s", err->message);
996 g_object_unref(proxy);
998 return BLUETOOTH_ERROR_NONE;
1001 int _bt_obex_server_cancel_all_transfers(void)
1004 bt_transfer_info_t *transfer;
1006 for (l = transfers; l != NULL; l = l->next) {
1009 if (transfer == NULL)
1012 _bt_obex_server_cancel_transfer(transfer->transfer_id);
1015 return BLUETOOTH_ERROR_NONE;
1018 int _bt_obex_server_is_activated(gboolean *activated)
1020 BT_CHECK_PARAMETER(activated, return);
1022 if (agent_info.custom_server) {
1028 return BLUETOOTH_ERROR_NONE;
1031 int _bt_obex_server_check_allocation(gboolean *allocation)
1033 BT_CHECK_PARAMETER(allocation, return);
1035 if (agent_info.native_server || agent_info.custom_server) {
1038 *allocation = FALSE;
1041 return BLUETOOTH_ERROR_NONE;
1044 int _bt_obex_server_check_termination(char *sender)
1046 BT_CHECK_PARAMETER(sender, return);
1048 if (agent_info.native_server) {
1049 if (g_strcmp0(sender, agent_info.native_server->sender) == 0) {
1050 _bt_obex_server_deallocate(agent_info.native_server->app_pid,
1055 if (agent_info.custom_server) {
1056 if (g_strcmp0(sender, agent_info.custom_server->sender) == 0) {
1057 _bt_obex_server_deallocate(agent_info.custom_server->app_pid,
1062 return BLUETOOTH_ERROR_NONE;
1065 int _bt_obex_server_is_receiving(gboolean *receiving)
1067 BT_CHECK_PARAMETER(receiving, return);
1069 if (transfers == NULL || g_slist_length(transfers) == 0) {
1075 return BLUETOOTH_ERROR_NONE;
1078 gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data)
1080 request_info_t *req_info;
1081 GVariant *out_param1 = NULL;
1082 int result = BLUETOOTH_ERROR_TIMEOUT;
1084 /* Already reply in _bt_obex_transfer_started */
1085 retv_if(agent_info.accept_id == 0, FALSE);
1087 req_info = _bt_get_request_info(agent_info.accept_id);
1088 if (req_info == NULL || req_info->context == NULL) {
1089 BT_ERR("info is NULL");
1093 agent_info.accept_id = 0;
1094 GArray *g_out_param1 = NULL;
1095 g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
1096 if (out_param1 == NULL) {
1097 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1098 g_out_param1->data, g_out_param1->len,
1102 g_dbus_method_invocation_return_value(req_info->context,
1103 g_variant_new("(iv)", result, out_param1));
1104 g_array_free(g_out_param1, TRUE);
1105 _bt_delete_request_list(req_info->req_id);
1110 /* To support the BOT */
1111 int _bt_obex_server_accept_connection(int request_id)
1113 if (!_bt_agent_reply_authorize(TRUE))
1114 return BLUETOOTH_ERROR_INTERNAL;
1116 agent_info.accept_id = request_id;
1118 g_timeout_add(BT_SERVER_ACCEPT_TIMEOUT,
1119 (GSourceFunc)__bt_obex_server_accept_timeout_cb,
1122 return BLUETOOTH_ERROR_NONE;
1125 /* To support the BOT */
1126 int _bt_obex_server_reject_connection(void)
1128 if (!_bt_agent_reply_authorize(FALSE))
1129 return BLUETOOTH_ERROR_INTERNAL;
1131 return BLUETOOTH_ERROR_NONE;