3 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #define _DEFAULT_SOURCE
24 #if !GLIB_CHECK_VERSION (2, 31, 0)
25 #include <glib/gmacros.h>
27 #include <cynara-client.h>
28 #include <cynara-session.h>
29 #include <cynara-creds-gdbus.h>
34 #include "account-server-db.h"
35 #include "account_ipc_marshal.h"
36 #include "account-mgr-stub.h"
37 #include "account-private.h"
38 #include "account-error.h"
40 #define _PRIVILEGE_ACCOUNT_READ "http://tizen.org/privilege/account.read"
41 #define _PRIVILEGE_ACCOUNT_WRITE "http://tizen.org/privilege/account.write"
43 #define ACCOUNT_MGR_DBUS_PATH "/org/tizen/account/manager"
44 static guint owner_id = 0;
45 GDBusObjectManagerServer *account_mgr_server_mgr = NULL;
46 static AccountManager* account_mgr_server_obj = NULL;
48 static cynara *p_cynara;
50 //static gboolean has_owner = FALSE;
52 // pid-mode, TODO: make it sessionId-mode, were session id is mix of pid and some rand no, so that
53 // one client can have multiple connections having different modes
54 //static GHashTable* mode_table = NULL;
56 GDBusErrorEntry _account_svc_errors[] =
58 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
59 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
60 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
61 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
62 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
63 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
64 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
65 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
66 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
67 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
68 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
69 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
70 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
71 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
72 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
73 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
74 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
75 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
79 _get_client_pid(GDBusMethodInvocation* invoc)
81 const char *name = NULL;
82 name = g_dbus_method_invocation_get_sender(invoc);
85 _ERR("g_dbus_method_invocation_get_sender failed");
88 _INFO("sender=[%s]", name);
95 _INFO("calling GetConnectionUnixProcessID");
97 GDBusConnection* conn = g_dbus_method_invocation_get_connection(invoc);
98 _ret = g_dbus_connection_call_sync(conn,
99 "org.freedesktop.DBus",
100 "/org/freedesktop/DBus",
101 "org.freedesktop.DBus",
102 "GetConnectionUnixProcessID",
103 g_variant_new("(s)", name),
105 G_DBUS_CALL_FLAGS_NONE,
112 g_variant_get(_ret, "(u)", &pid);
113 g_variant_unref(_ret);
116 _INFO("process Id = [%u]", pid);
121 _account_error_quark (void)
123 static volatile gsize quark_volatile = 0;
125 g_dbus_error_register_error_domain (_ACCOUNT_SVC_ERROR_DOMAIN,
128 G_N_ELEMENTS (_account_svc_errors));
130 return (GQuark) quark_volatile;
133 static int __check_privilege_by_cynara(const char *client, const char *session, const char *user, const char *privilege)
136 char err_buf[128] = {0,};
138 ret = cynara_check(p_cynara, client, session, user, privilege);
140 case CYNARA_API_ACCESS_ALLOWED:
141 _DBG("cynara_check success");
142 return ACCOUNT_ERROR_NONE;
143 case CYNARA_API_ACCESS_DENIED:
144 _ERR("cynara_check permission deined, privilege=%s, error = CYNARA_API_ACCESS_DENIED", privilege);
145 return ACCOUNT_ERROR_PERMISSION_DENIED;
147 cynara_strerror(ret, err_buf, sizeof(err_buf));
148 _ERR("cynara_check error : %s, privilege=%s, ret = %d", err_buf, privilege, ret);
149 return ACCOUNT_ERROR_PERMISSION_DENIED;
153 int __get_information_for_cynara_check(GDBusMethodInvocation *invocation, char **client, char **user, char **session)
155 GDBusConnection *gdbus_conn = NULL;
159 //get GDBusConnection
160 gdbus_conn = g_dbus_method_invocation_get_connection(invocation);
161 if(gdbus_conn == NULL)
163 _ERR("g_dbus_method_invocation_get_connection failed");
167 //get sender(unique_name)
168 sender = (char*) g_dbus_method_invocation_get_sender(invocation);
171 _ERR("g_dbus_method_invocation_get_sender failed");
175 ret = cynara_creds_gdbus_get_user(gdbus_conn, sender, USER_METHOD_DEFAULT, user);
176 if (ret != CYNARA_API_SUCCESS)
178 _ERR("cynara_creds_gdbus_get_user failed, ret = %d", ret);
182 ret = cynara_creds_gdbus_get_client(gdbus_conn, sender, CLIENT_METHOD_DEFAULT, client);
183 if (ret != CYNARA_API_SUCCESS)
185 _ERR("cynara_creds_gdbus_get_client failed, ret = %d", ret);
189 guint pid = _get_client_pid(invocation);
190 _INFO("client Id = [%u]", pid);
192 *session = cynara_session_from_pid(pid);
193 if (*session == NULL)
195 _ERR("cynara_session_from_pid failed");
198 return ACCOUNT_ERROR_NONE;
201 int _check_privilege(GDBusMethodInvocation *invocation, const char* privilege)
205 char *session = NULL;
208 ret = __get_information_for_cynara_check(invocation, &client, &user, &session);
209 if ( ret != ACCOUNT_ERROR_NONE )
211 _ERR("__get_information_for_cynara_check failed");
214 _ACCOUNT_FREE(session);
215 return ACCOUNT_ERROR_PERMISSION_DENIED;
218 ret = __check_privilege_by_cynara(client, session, user, privilege);
219 if ( ret != ACCOUNT_ERROR_NONE )
221 _ERR("__check_privilege_by_cynara failed, ret = %d", ret);
224 _ACCOUNT_FREE(session);
225 return ACCOUNT_ERROR_PERMISSION_DENIED;
229 _ACCOUNT_FREE(session);
230 return ACCOUNT_ERROR_NONE;
233 int _check_priviliege_account_read(GDBusMethodInvocation *invocation)
235 return _check_privilege(invocation, _PRIVILEGE_ACCOUNT_READ);
238 int _check_priviliege_account_write(GDBusMethodInvocation *invocation)
240 return _check_privilege(invocation, _PRIVILEGE_ACCOUNT_WRITE);
243 gboolean account_manager_account_add(AccountManager *obj, GDBusMethodInvocation *invocation, gchar* account_db_path, GVariant* account_data, gpointer user_data)
245 _INFO("account_manager_account_add start");
248 guint pid = _get_client_pid(invocation);
249 _INFO("client Id = [%u]", pid);
251 int return_code = _check_priviliege_account_read(invocation);
252 if (return_code != ACCOUNT_ERROR_NONE)
254 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
258 return_code = _check_priviliege_account_write(invocation);
259 if (return_code != ACCOUNT_ERROR_NONE)
261 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
265 return_code = _account_db_open(1, (const char*)account_db_path);
266 if (return_code != ACCOUNT_ERROR_NONE)
268 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
273 account_s* account = umarshal_account(account_data);
276 _ERR("account unmarshalling failed");
277 return_code = ACCOUNT_ERROR_DB_FAILED;
282 return_code = _account_insert_to_db(account, pid, &db_id);
284 if (return_code != ACCOUNT_ERROR_NONE)
286 _ERR("_account_insert_to_db() error");
293 if (return_code != ACCOUNT_ERROR_NONE)
295 _ERR("Account SVC is returning error [%d]", return_code);
296 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
297 g_dbus_method_invocation_return_gerror (invocation, error);
301 account_manager_complete_account_add(obj, invocation, db_id);
303 _INFO("account_manager_account_add end");
305 return_code = _account_db_close();
306 if (return_code != ACCOUNT_ERROR_NONE)
308 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
309 return_code = ACCOUNT_ERROR_NONE;
315 gboolean account_manager_account_query_all(AccountManager *obj, GDBusMethodInvocation *invocation, gchar *account_db_path)
317 _INFO("account_manager_account_query_all start");
319 GVariant* account_list_variant = NULL;
321 guint pid = _get_client_pid(invocation);
322 _INFO("client Id = [%u]", pid);
324 int return_code = _check_priviliege_account_read(invocation);
325 if (return_code != ACCOUNT_ERROR_NONE)
327 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
331 return_code = _account_db_open(0, (const char*)account_db_path);
332 if (return_code != ACCOUNT_ERROR_NONE)
334 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
339 //Mode checking not required, since default mode is read.
341 GSList* account_list = NULL;
342 account_list = _account_db_query_all(pid);
344 if (account_list == NULL)
346 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
347 _ERR("No account found.");
351 _INFO("account_list length= [%d]", g_slist_length(account_list));
354 _INFO("before calling marshal_account_list");
355 account_list_variant = marshal_account_list(account_list);
356 _INFO("after calling marshal_account_list");
360 if (account_list_variant == NULL)
362 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
363 g_dbus_method_invocation_return_gerror (invocation, error);
367 account_manager_complete_account_query_all(obj, invocation, account_list_variant);
369 _INFO("account_manager_account_query_all end");
371 return_code = _account_db_close();
372 if (return_code != ACCOUNT_ERROR_NONE)
374 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
375 return_code = ACCOUNT_ERROR_NONE;
381 gboolean account_manager_account_type_query_all(AccountManager *obj, GDBusMethodInvocation *invocation, gchar *account_db_path)
383 _INFO("account_manager_account_query_all start");
385 GVariant* account_type_list_variant = NULL;
386 guint pid = _get_client_pid(invocation);
387 _INFO("client Id = [%u]", pid);
389 int return_code = _check_priviliege_account_read(invocation);
390 if (return_code != ACCOUNT_ERROR_NONE)
392 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
396 return_code = _account_db_open(0, (const char*)account_db_path);
397 if (return_code != ACCOUNT_ERROR_NONE)
399 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
404 //Mode checking not required, since default mode is read.
406 GSList* account_type_list = NULL;
407 account_type_list = _account_type_query_all();
409 if (account_type_list == NULL)
411 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
412 _ERR("No account type found.");
416 _INFO("account_type_list length= [%d]", g_slist_length(account_type_list));
419 _INFO("before calling marshal_account_type_list");
420 account_type_list_variant = marshal_account_type_list(account_type_list);
421 _INFO("after calling marshal_account_type_list");
425 if (account_type_list_variant == NULL)
427 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
428 g_dbus_method_invocation_return_gerror (invocation, error);
432 account_manager_complete_account_type_query_all(obj, invocation, account_type_list_variant);
434 _INFO("account_manager_account_query_all end");
436 return_code = _account_db_close();
437 if (return_code != ACCOUNT_ERROR_NONE)
439 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
440 return_code = ACCOUNT_ERROR_NONE;
446 gboolean account_manager_account_type_add(AccountManager *obj, GDBusMethodInvocation *invocation, gchar *account_db_path, GVariant *account_type_data, gpointer user_data)
450 _INFO("account_manager_account_type_add start");
452 guint pid = _get_client_pid(invocation);
453 _INFO("client Id = [%u]", pid);
455 int return_code = _check_priviliege_account_read(invocation);
456 if (return_code != ACCOUNT_ERROR_NONE)
458 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
461 return_code = _check_priviliege_account_write(invocation);
462 if (return_code != ACCOUNT_ERROR_NONE)
464 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
468 return_code = _account_db_open(1, (const char*)account_db_path);
469 if (return_code != ACCOUNT_ERROR_NONE)
471 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
476 account_type_s* account_type = umarshal_account_type(account_type_data);
477 if (account_type == NULL)
479 _ERR("account_type unmarshalling failed");
480 return_code = ACCOUNT_ERROR_DB_FAILED;
484 _INFO("before _account_type_insert_to_db");
485 return_code = _account_type_insert_to_db(account_type, &db_id);
486 _INFO("after _account_type_insert_to_db");
487 if (return_code != ACCOUNT_ERROR_NONE)
489 _ERR("_account_type_insert_to_db error");
495 if (return_code != ACCOUNT_ERROR_NONE)
497 _ERR("Account SVC is returning error [%d]", return_code);
498 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
499 g_dbus_method_invocation_return_gerror (invocation, error);
503 account_manager_complete_account_type_add(obj, invocation, db_id);
505 _INFO("account_manager_account_type_add end");
507 return_code = _account_db_close();
508 if (return_code != ACCOUNT_ERROR_NONE)
510 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
511 return_code = ACCOUNT_ERROR_NONE;
517 gboolean account_manager_account_delete_from_db_by_id(AccountManager *object,
518 GDBusMethodInvocation *invocation,
519 gchar *account_db_path,
522 _INFO("account_manager_account_delete_from_db_by_id start");
524 guint pid = _get_client_pid(invocation);
525 _INFO("client Id = [%u]", pid);
527 int return_code = _check_priviliege_account_read(invocation);
528 if (return_code != ACCOUNT_ERROR_NONE)
530 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
533 return_code = _check_priviliege_account_write(invocation);
534 if (return_code != ACCOUNT_ERROR_NONE)
536 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
540 return_code = _account_db_open(1, (const char*)account_db_path);
541 if (return_code != ACCOUNT_ERROR_NONE)
543 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
548 _INFO("before _account_delete");
549 return_code = _account_delete(pid, account_db_id);
550 _INFO("after _account_delete=[%d]", return_code);
552 if (return_code != ACCOUNT_ERROR_NONE)
554 _ERR("_account_delete error");
560 if (return_code != ACCOUNT_ERROR_NONE)
562 _ERR("Account SVC is returning error [%d]", return_code);
563 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
564 g_dbus_method_invocation_return_gerror (invocation, error);
568 account_manager_complete_account_delete_from_db_by_id(object, invocation);
570 _INFO("account_manager_account_delete_from_db_by_id end");
572 return_code = _account_db_close();
573 if (return_code != ACCOUNT_ERROR_NONE)
575 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
576 return_code = ACCOUNT_ERROR_NONE;
582 gboolean account_manager_account_delete_from_db_by_user_name(AccountManager *object,
583 GDBusMethodInvocation *invocation,
584 gchar *account_db_path,
585 const gchar *user_name,
586 const gchar *package_name)
588 _INFO("account_manager_account_delete_from_db_by_user_name start");
590 guint pid = _get_client_pid(invocation);
591 _INFO("client Id = [%u]", pid);
593 int return_code = _check_priviliege_account_read(invocation);
594 if (return_code != ACCOUNT_ERROR_NONE)
596 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
599 return_code = _check_priviliege_account_write(invocation);
600 if (return_code != ACCOUNT_ERROR_NONE)
602 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
606 return_code = _account_db_open(1, (const char*)account_db_path);
607 if (return_code != ACCOUNT_ERROR_NONE)
609 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
614 _INFO("before _account_delete_from_db_by_user_name");
615 return_code = _account_delete_from_db_by_user_name(pid, user_name, package_name);
616 _INFO("after _account_delete_from_db_by_user_name=[%d]", return_code);
618 if (return_code != ACCOUNT_ERROR_NONE)
620 _ERR("_account_delete_from_db_by_user_name error");
626 if (return_code != ACCOUNT_ERROR_NONE)
628 _ERR("Account SVC is returning error [%d]", return_code);
629 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
630 g_dbus_method_invocation_return_gerror (invocation, error);
634 account_manager_complete_account_delete_from_db_by_id(object, invocation);
636 _INFO("account_manager_account_delete_from_db_by_user_name end");
638 return_code = _account_db_close();
639 if (return_code != ACCOUNT_ERROR_NONE)
641 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
642 return_code = ACCOUNT_ERROR_NONE;
648 gboolean account_manager_account_delete_from_db_by_package_name(AccountManager *object,
649 GDBusMethodInvocation *invocation,
650 gchar *account_db_path,
651 const gchar *package_name, gboolean permission)
653 _INFO("account_manager_account_delete_from_db_by_package_name start");
655 guint pid = _get_client_pid(invocation);
656 _INFO("client Id = [%u]", pid);
658 int return_code = _check_priviliege_account_read(invocation);
659 if (return_code != ACCOUNT_ERROR_NONE)
661 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
664 return_code = _check_priviliege_account_write(invocation);
665 if (return_code != ACCOUNT_ERROR_NONE)
667 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
671 return_code = _account_db_open(1, (const char*)account_db_path);
672 if (return_code != ACCOUNT_ERROR_NONE)
674 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
679 _INFO("before account_delete_from_db_by_package_name");
680 return_code = _account_delete_from_db_by_package_name(pid, package_name, permission);
681 _INFO("after account_delete_from_db_by_package_name=[%d]", return_code);
683 if (return_code != ACCOUNT_ERROR_NONE)
685 _ERR("_account_delete_from_db_by_package_name error");
691 if (return_code != ACCOUNT_ERROR_NONE)
693 _ERR("Account SVC is returning error [%d]", return_code);
694 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
695 g_dbus_method_invocation_return_gerror (invocation, error);
699 account_manager_complete_account_delete_from_db_by_package_name(object, invocation);
701 _INFO("account_manager_account_delete_from_db_by_package_name end");
703 return_code = _account_db_close();
704 if (return_code != ACCOUNT_ERROR_NONE)
706 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
707 return_code = ACCOUNT_ERROR_NONE;
713 gboolean account_manager_account_update_to_db_by_id(AccountManager *object,
714 GDBusMethodInvocation *invocation,
715 gchar *account_db_path,
716 GVariant *account_data,
719 _INFO("account_manager_account_update_to_db_by_id start");
721 guint pid = _get_client_pid(invocation);
722 _INFO("client Id = [%u]", pid);
724 int return_code = _check_priviliege_account_read(invocation);
725 if (return_code != ACCOUNT_ERROR_NONE)
727 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
730 return_code = _check_priviliege_account_write(invocation);
731 if (return_code != ACCOUNT_ERROR_NONE)
733 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
737 return_code = _account_db_open(1, (const char*)account_db_path);
738 if (return_code != ACCOUNT_ERROR_NONE)
740 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
745 account_s* account = umarshal_account(account_data);
748 _ERR("Unmarshal failed");
749 return_code = ACCOUNT_ERROR_DB_FAILED;
753 _INFO("before account_update_to_db_by_id");
754 return_code = _account_update_to_db_by_id(pid, account, account_id);
755 _INFO("after account_update_to_db_by_id=[%d]", return_code);
757 if (return_code != ACCOUNT_ERROR_NONE)
759 _ERR("_account_type_update_to_db_by_id error");
765 if (return_code != ACCOUNT_ERROR_NONE)
767 _ERR("Account SVC is returning error [%d]", return_code);
768 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
769 g_dbus_method_invocation_return_gerror (invocation, error);
773 account_manager_complete_account_update_to_db_by_id(object, invocation);
775 _INFO("account_manager_account_update_to_db_by_id end");
777 return_code = _account_db_close();
778 if (return_code != ACCOUNT_ERROR_NONE)
780 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
781 return_code = ACCOUNT_ERROR_NONE;
787 gboolean account_manager_handle_account_update_to_db_by_user_name(AccountManager *object,
788 GDBusMethodInvocation *invocation,
789 gchar *account_db_path,
790 GVariant *account_data,
791 const gchar *user_name,
792 const gchar *package_name)
794 _INFO("account_manager_handle_account_update_to_db_by_user_name start");
796 guint pid = _get_client_pid(invocation);
797 _INFO("client Id = [%u]", pid);
799 int return_code = _check_priviliege_account_read(invocation);
800 if (return_code != ACCOUNT_ERROR_NONE)
802 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
805 return_code = _check_priviliege_account_write(invocation);
806 if (return_code != ACCOUNT_ERROR_NONE)
808 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
812 return_code = _account_db_open(1, (const char*)account_db_path);
813 if (return_code != ACCOUNT_ERROR_NONE)
815 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
820 account_s* account = umarshal_account(account_data);
823 _ERR("Unmarshal failed");
824 return_code = ACCOUNT_ERROR_DB_FAILED;
828 _INFO("before account_update_to_db_by_id");
829 return_code = _account_update_to_db_by_user_name(pid, account, user_name, package_name);
830 _INFO("after account_update_to_db_by_id=[%d]", return_code);
832 if (return_code != ACCOUNT_ERROR_NONE)
834 _ERR("_account_update_to_db_by_id error");
840 if (return_code != ACCOUNT_ERROR_NONE)
842 _ERR("Account SVC is returning error [%d]", return_code);
843 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
844 g_dbus_method_invocation_return_gerror (invocation, error);
848 account_manager_complete_account_update_to_db_by_id(object, invocation);
850 _INFO("account_manager_handle_account_update_to_db_by_user_name end");
852 return_code = _account_db_close();
853 if (return_code != ACCOUNT_ERROR_NONE)
855 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
856 return_code = ACCOUNT_ERROR_NONE;
863 account_manager_handle_account_type_query_label_by_locale(AccountManager *object,
864 GDBusMethodInvocation *invocation,
865 gchar *account_db_path,
869 _INFO("account_manager_handle_account_type_query_label_by_locale start");
870 guint pid = _get_client_pid(invocation);
872 _INFO("client Id = [%u]", pid);
874 int return_code = _check_priviliege_account_read(invocation);
875 if (return_code != ACCOUNT_ERROR_NONE)
877 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
881 return_code = _account_db_open(0, (const char*)account_db_path);
882 if (return_code != ACCOUNT_ERROR_NONE)
884 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
889 _INFO("before _account_type_query_label_by_locale");
890 char *label_name = NULL;
891 return_code = _account_type_query_label_by_locale(app_id, locale, &label_name);
892 _INFO("after _account_type_query_label_by_locale=[%d]", return_code);
894 if (return_code != ACCOUNT_ERROR_NONE)
896 _ERR("_account_type_query_label_by_locale error");
901 if (return_code != ACCOUNT_ERROR_NONE)
903 _ERR("Account SVC is returning error [%d]", return_code);
904 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
905 g_dbus_method_invocation_return_gerror (invocation, error);
909 account_manager_complete_account_type_query_label_by_locale(object, invocation, label_name);
911 _INFO("account_manager_handle_account_type_query_label_by_locale end");
913 return_code = _account_db_close();
914 if (return_code != ACCOUNT_ERROR_NONE)
916 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
917 return_code = ACCOUNT_ERROR_NONE;
924 account_manager_handle_account_type_query_by_provider_feature(AccountManager *obj,
925 GDBusMethodInvocation *invocation,
926 gchar *account_db_path, const gchar *key)
928 _INFO("account_manager_handle_account_type_query_by_provider_feature start");
929 GVariant* account_type_list_variant = NULL;
931 guint pid = _get_client_pid(invocation);
933 _INFO("client Id = [%u]", pid);
935 int return_code = _check_priviliege_account_read(invocation);
936 if (return_code != ACCOUNT_ERROR_NONE)
938 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
942 return_code = _account_db_open(0, (const char*)account_db_path);
943 if (return_code != ACCOUNT_ERROR_NONE)
945 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
950 //Mode checking not required, since default mode is read.
952 GSList* account_type_list = NULL;
953 account_type_list = _account_type_query_by_provider_feature(key, &return_code);
954 if (return_code != 0)
956 _ERR("_account_type_query_by_provider_feature=[%d]", return_code);
960 if (account_type_list == NULL)
962 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
963 _ERR("No account type found.");
967 if (return_code != ACCOUNT_ERROR_NONE)
969 _ERR("_account_type_query_by_provider_feature error");
973 _INFO("account_type_list length= [%d]", g_slist_length(account_type_list));
975 _INFO("before calling marshal_account_type_list");
976 account_type_list_variant = marshal_account_type_list(account_type_list);
977 _INFO("after calling marshal_account_type_list");
981 if (account_type_list_variant == NULL)
983 GError* error = g_error_new (_account_error_quark(), ACCOUNT_ERROR_RECORD_NOT_FOUND, "RecordNotFound");
984 g_dbus_method_invocation_return_gerror (invocation, error);
988 account_manager_complete_account_type_query_by_provider_feature(obj, invocation, account_type_list_variant);
990 _INFO("account_manager_handle_account_type_query_by_provider_feature end");
992 return_code = _account_db_close();
993 if (return_code != ACCOUNT_ERROR_NONE)
995 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
996 return_code = ACCOUNT_ERROR_NONE;
1002 gboolean account_manager_account_get_total_count_from_db(AccountManager *object, GDBusMethodInvocation *invocation, gchar *account_db_path, gboolean include_hidden)
1004 _INFO("account_manager_account_get_total_count_from_db start");
1005 guint pid = _get_client_pid(invocation);
1007 _INFO("client Id = [%u]", pid);
1009 int return_code = _check_priviliege_account_read(invocation);
1010 if (return_code != ACCOUNT_ERROR_NONE)
1012 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1016 return_code = _account_db_open(0, (const char*)account_db_path);
1017 if (return_code != ACCOUNT_ERROR_NONE)
1019 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1025 _INFO("before account_get_total_count_from_db");
1027 return_code = _account_get_total_count_from_db(include_hidden, &count);
1028 _INFO("before account_get_total_count_from_db=[%d], return_code");
1030 if (return_code != ACCOUNT_ERROR_NONE)
1032 _ERR("_account_get_total_count_from_db error");
1037 if (return_code != ACCOUNT_ERROR_NONE)
1039 _ERR("Account SVC is returning error [%d]", return_code);
1040 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1041 g_dbus_method_invocation_return_gerror (invocation, error);
1045 account_manager_complete_account_get_total_count_from_db(object, invocation, count);
1047 _INFO("account_manager_account_get_total_count_from_db end");
1049 return_code = _account_db_close();
1050 if (return_code != ACCOUNT_ERROR_NONE)
1052 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1053 return_code = ACCOUNT_ERROR_NONE;
1059 gboolean account_manager_handle_account_query_account_by_account_id(AccountManager *object, GDBusMethodInvocation *invocation,
1060 gchar *account_db_path, gint account_db_id)
1062 _INFO("account_manager_handle_account_query_account_by_account_id start");
1063 GVariant* account_variant = NULL;
1065 guint pid = _get_client_pid(invocation);
1067 _INFO("client Id = [%u]", pid);
1069 int return_code = _check_priviliege_account_read(invocation);
1070 if (return_code != ACCOUNT_ERROR_NONE)
1072 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1076 return_code = _account_db_open(0, (const char*)account_db_path);
1077 if (return_code != ACCOUNT_ERROR_NONE)
1079 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1084 account_s* account_data = create_empty_account_instance();
1085 if (account_data == NULL)
1087 _ERR("out of memory");
1088 return_code = ACCOUNT_ERROR_DB_FAILED;
1091 _INFO("before _account_query_account_by_account_id");
1092 return_code = _account_query_account_by_account_id(pid, account_db_id, account_data);
1093 _INFO("after _account_query_account_by_return_code=[%d]", return_code);
1094 _INFO("user_name = %s, user_data_txt[0] = %s, user_data_int[1] = %d", account_data->user_name, account_data->user_data_txt[0], account_data->user_data_int[1]);
1096 if (return_code == ACCOUNT_ERROR_NONE)
1098 account_variant = marshal_account(account_data);
1101 if (return_code != ACCOUNT_ERROR_NONE)
1103 _ERR("_account_type_query_label_by_locale error");
1108 if (account_variant == NULL || return_code != ACCOUNT_ERROR_NONE)
1110 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1111 g_dbus_method_invocation_return_gerror (invocation, error);
1115 account_manager_complete_account_query_account_by_account_id(object, invocation, account_variant);
1117 _INFO("account_manager_handle_account_query_account_by_account_id end");
1119 return_code = _account_db_close();
1120 if (return_code != ACCOUNT_ERROR_NONE)
1122 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1123 return_code = ACCOUNT_ERROR_NONE;
1130 account_manager_handle_account_query_account_by_user_name(AccountManager *obj,
1131 GDBusMethodInvocation *invocation,
1132 gchar *account_db_path, const gchar *user_name)
1134 _INFO("account_manager_handle_account_query_account_by_user_name start");
1136 GVariant* account_list_variant = NULL;
1137 guint pid = _get_client_pid(invocation);
1139 _INFO("client Id = [%u]", pid);
1141 int return_code = _check_priviliege_account_read(invocation);
1142 if (return_code != ACCOUNT_ERROR_NONE)
1144 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1148 return_code = _account_db_open(0, (const char*)account_db_path);
1149 if (return_code != ACCOUNT_ERROR_NONE)
1151 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1156 //Mode checking not required, since default mode is read.
1158 GList* account_list = NULL;
1160 account_list = _account_query_account_by_user_name(pid, user_name, &return_code);
1162 if (account_list == NULL)
1164 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1165 _ERR("No account found.");
1169 _INFO("account_list length= [%d]", g_list_length(account_list));
1171 _INFO("before calling marshal_account_list_double");
1172 account_list_variant = marshal_account_list_double(account_list);
1173 _INFO("after calling marshal_account_list_double");
1175 if (return_code != ACCOUNT_ERROR_NONE)
1177 _ERR("_account_query_account_by_user_name error");
1182 if (account_list_variant == NULL)
1184 GError* error = g_error_new (_account_error_quark(), ACCOUNT_ERROR_RECORD_NOT_FOUND, "RecordNotFound");
1185 g_dbus_method_invocation_return_gerror (invocation, error);
1189 account_manager_complete_account_query_account_by_user_name(obj, invocation, account_list_variant);
1191 _INFO("account_manager_handle_account_query_account_by_user_name end");
1193 return_code = _account_db_close();
1194 if (return_code != ACCOUNT_ERROR_NONE)
1196 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1197 return_code = ACCOUNT_ERROR_NONE;
1204 account_manager_handle_account_query_account_by_package_name(AccountManager *obj,
1205 GDBusMethodInvocation *invocation,
1206 gchar *account_db_path, const gchar *package_name)
1208 _INFO("account_manager_handle_account_query_account_by_package_name start");
1210 GVariant* account_list_variant = NULL;
1211 guint pid = _get_client_pid(invocation);
1213 _INFO("client Id = [%u]", pid);
1215 int return_code = _check_priviliege_account_read(invocation);
1216 if (return_code != ACCOUNT_ERROR_NONE)
1218 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1222 return_code = _account_db_open(0, (const char*)account_db_path);
1223 if (return_code != ACCOUNT_ERROR_NONE)
1225 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1230 //Mode checking not required, since default mode is read.
1232 GList* account_list = NULL;
1234 account_list = _account_query_account_by_package_name(pid, package_name, &return_code);
1236 if (account_list == NULL)
1238 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1239 _ERR("No account found.");
1243 _INFO("account_list length= [%d]", g_list_length(account_list));
1245 account_list_variant = marshal_account_list_double(account_list);
1247 if (return_code != ACCOUNT_ERROR_NONE)
1249 _ERR("_account_query_account_by_package_name error");
1255 if (account_list_variant == NULL)
1257 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1258 _INFO("sending error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
1259 g_dbus_method_invocation_return_gerror (invocation, error);
1263 account_manager_complete_account_query_account_by_package_name(obj, invocation, account_list_variant);
1265 _INFO("account_manager_handle_account_query_account_by_package_name start");
1267 return_code = _account_db_close();
1268 if (return_code != ACCOUNT_ERROR_NONE)
1270 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1271 return_code = ACCOUNT_ERROR_NONE;
1278 account_manager_handle_account_query_account_by_capability(AccountManager *obj,
1279 GDBusMethodInvocation *invocation,
1280 gchar *account_db_path,
1281 const gchar *capability_type,
1282 gint capability_value)
1284 _INFO("account_manager_handle_account_query_account_by_capability start");
1286 GVariant* account_list_variant = NULL;
1288 guint pid = _get_client_pid(invocation);
1290 _INFO("client Id = [%u]", pid);
1292 int return_code = _check_priviliege_account_read(invocation);
1293 if (return_code != ACCOUNT_ERROR_NONE)
1295 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1299 return_code = _account_db_open(0, (const char*)account_db_path);
1300 if (return_code != ACCOUNT_ERROR_NONE)
1302 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1307 //Mode checking not required, since default mode is read.
1309 GList* account_list = NULL;
1311 _INFO("before _account_query_account_by_capability");
1312 account_list = _account_query_account_by_capability(pid, capability_type, capability_value, &return_code);
1313 _INFO("after _account_query_account_by_capability");
1315 if (account_list == NULL)
1317 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1318 _ERR("No account found.");
1322 _INFO("account_list length= [%d]", g_list_length(account_list));
1324 account_list_variant = marshal_account_list_double(account_list);
1326 if (return_code != ACCOUNT_ERROR_NONE)
1328 _ERR("_account_query_account_by_capability error");
1334 if (account_list_variant == NULL)
1336 GError* error = g_error_new (_account_error_quark(), ACCOUNT_ERROR_RECORD_NOT_FOUND, "RecordNotFound");
1337 g_dbus_method_invocation_return_gerror (invocation, error);
1341 account_manager_complete_account_query_account_by_capability(obj, invocation, account_list_variant);
1343 _INFO("account_manager_handle_account_query_account_by_capability end");
1345 return_code = _account_db_close();
1346 if (return_code != ACCOUNT_ERROR_NONE)
1348 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1349 return_code = ACCOUNT_ERROR_NONE;
1356 account_manager_handle_account_query_account_by_capability_type(AccountManager *obj,
1357 GDBusMethodInvocation *invocation,
1358 gchar *account_db_path,
1359 const gchar *capability_type)
1361 _INFO("account_manager_handle_account_query_account_by_capability_type start");
1363 GVariant* account_list_variant = NULL;
1365 guint pid = _get_client_pid(invocation);
1367 _INFO("client Id = [%u]", pid);
1369 int return_code = _check_priviliege_account_read(invocation);
1370 if (return_code != ACCOUNT_ERROR_NONE)
1372 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1376 return_code = _account_db_open(0, (const char*)account_db_path);
1377 if (return_code != ACCOUNT_ERROR_NONE)
1379 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1384 //Mode checking not required, since default mode is read.
1386 GList* account_list = NULL;
1388 account_list = _account_query_account_by_capability_type(pid, capability_type, &return_code);
1390 if (account_list == NULL)
1392 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1393 _ERR("No account found.");
1397 _INFO("account_list length= [%d]", g_list_length(account_list));
1399 _INFO("before calling marshal_account_list_double");
1400 account_list_variant = marshal_account_list_double(account_list);
1401 _INFO("after calling marshal_account_list_double");
1403 if (return_code != ACCOUNT_ERROR_NONE)
1405 _ERR("_account_query_account_by_capability_type error");
1411 if (account_list_variant == NULL)
1413 GError* error = g_error_new (_account_error_quark(), ACCOUNT_ERROR_RECORD_NOT_FOUND, "RecordNotFound");
1414 g_dbus_method_invocation_return_gerror (invocation, error);
1418 account_manager_complete_account_query_account_by_capability(obj, invocation, account_list_variant);
1420 _INFO("account_manager_handle_account_query_account_by_capability_type end");
1422 return_code = _account_db_close();
1423 if (return_code != ACCOUNT_ERROR_NONE)
1425 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1426 return_code = ACCOUNT_ERROR_NONE;
1433 account_manager_handle_account_query_capability_by_account_id(AccountManager *obj,
1434 GDBusMethodInvocation *invocation,
1435 gchar *account_db_path,
1436 const int account_id)
1438 _INFO("account_manager_handle_account_query_capability_by_account_id start");
1440 GVariant* capability_list_variant = NULL;
1442 guint pid = _get_client_pid(invocation);
1444 _INFO("client Id = [%u]", pid);
1446 int return_code = _check_priviliege_account_read(invocation);
1447 if (return_code != ACCOUNT_ERROR_NONE)
1449 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1454 return_code = _account_db_open(0, (const char*)account_db_path);
1455 if (return_code != ACCOUNT_ERROR_NONE)
1457 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1462 //Mode checking not required, since default mode is read.
1464 GSList* capability_list = NULL;
1466 capability_list = _account_get_capability_list_by_account_id(account_id, &return_code);
1468 if (capability_list == NULL)
1470 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1471 _ERR("No capability found.");
1475 _INFO("capability_list length= [%d]", g_slist_length(capability_list));
1477 _INFO("before calling marshal_capability_list");
1478 capability_list_variant = marshal_capability_list(capability_list);
1479 _INFO("after calling marshal_capability_list");
1481 if (return_code != ACCOUNT_ERROR_NONE)
1483 _ERR("_account_get_capability_list_by_account_id error");
1489 if (capability_list_variant == NULL)
1491 GError* error = g_error_new (_account_error_quark(), ACCOUNT_ERROR_RECORD_NOT_FOUND, "RecordNotFound");
1492 g_dbus_method_invocation_return_gerror (invocation, error);
1496 account_manager_complete_account_query_capability_by_account_id(obj, invocation, capability_list_variant);
1498 _INFO("account_manager_handle_account_query_capability_by_account_id end");
1500 return_code = _account_db_close();
1501 if (return_code != ACCOUNT_ERROR_NONE)
1503 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1504 return_code = ACCOUNT_ERROR_NONE;
1510 gboolean account_manager_handle_account_update_sync_status_by_id(AccountManager *object,
1511 GDBusMethodInvocation *invocation,
1512 gchar *account_db_path,
1513 const int account_db_id,
1514 const int sync_status)
1516 _INFO("account_manager_handle_account_update_sync_status_by_id start");
1517 guint pid = _get_client_pid(invocation);
1519 _INFO("client Id = [%u]", pid);
1521 int return_code = _check_priviliege_account_read(invocation);
1522 if (return_code != ACCOUNT_ERROR_NONE)
1524 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1527 return_code = _check_priviliege_account_write(invocation);
1528 if (return_code != ACCOUNT_ERROR_NONE)
1530 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
1534 return_code = _account_db_open(1, (const char*)account_db_path);
1535 if (return_code != ACCOUNT_ERROR_NONE)
1537 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1542 _INFO("before _account_update_sync_status_by_id");
1543 return_code = _account_update_sync_status_by_id(account_db_id, sync_status);
1544 _INFO("after _account_update_sync_status_by_id=[%d]", return_code);
1546 if (return_code != ACCOUNT_ERROR_NONE)
1548 _ERR("_account_update_sync_status_by_id error");
1554 if (return_code != ACCOUNT_ERROR_NONE)
1556 _ERR("Account SVC is returning error [%d]", return_code);
1557 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1558 g_dbus_method_invocation_return_gerror (invocation, error);
1562 account_manager_complete_account_update_sync_status_by_id(object, invocation);
1564 _INFO("account_manager_handle_account_update_sync_status_by_id end");
1566 return_code = _account_db_close();
1567 if (return_code != ACCOUNT_ERROR_NONE)
1569 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1570 return_code = ACCOUNT_ERROR_NONE;
1576 gboolean account_manager_handle_account_type_query_provider_feature_by_app_id(AccountManager *obj,
1577 GDBusMethodInvocation *invocation,
1578 gchar *account_db_path,
1579 const gchar* app_id)
1581 GSList* feature_record_list = NULL;
1582 GVariant* feature_record_list_variant = NULL;
1584 _INFO("account_manager_handle_account_type_query_provider_feature_by_app_id start");
1586 guint pid = _get_client_pid(invocation);
1588 _INFO("client Id = [%u]", pid);
1590 int return_code = _check_priviliege_account_read(invocation);
1591 if (return_code != ACCOUNT_ERROR_NONE)
1593 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1597 return_code = _account_db_open(0, (const char*)account_db_path);
1598 if (return_code != ACCOUNT_ERROR_NONE)
1600 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1605 _INFO("before _account_type_query_provider_feature_by_app_id");
1606 feature_record_list = _account_type_query_provider_feature_by_app_id(app_id, &return_code);
1607 _INFO("after account_type_query_provider_feature_by_app_id=[%d]", return_code);
1609 if (feature_record_list == NULL)
1611 _ERR("account feature_record_list is NULL");
1612 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1616 feature_record_list_variant = provider_feature_list_to_variant(feature_record_list);
1617 _INFO("%s", g_variant_print(feature_record_list_variant, true));
1619 if (return_code != ACCOUNT_ERROR_NONE)
1621 _ERR("_account_type_query_provider_feature_by_app_id error");
1626 if (return_code != ACCOUNT_ERROR_NONE)
1628 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1629 g_dbus_method_invocation_return_gerror (invocation, error);
1633 _INFO("Calling account_manager_complete_account_type_query_provider_feature_by_app_id");
1634 account_manager_complete_account_type_query_provider_feature_by_app_id(obj, invocation, feature_record_list_variant);
1636 _INFO("account_manager_handle_account_type_query_provider_feature_by_app_id end");
1638 return_code = _account_db_close();
1639 if (return_code != ACCOUNT_ERROR_NONE)
1641 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1642 return_code = ACCOUNT_ERROR_NONE;
1648 gboolean account_manager_handle_account_type_query_supported_feature(AccountManager *obj,
1649 GDBusMethodInvocation *invocation,
1650 gchar *account_db_path,
1651 const gchar* app_id,
1652 const gchar* capability)
1654 int is_supported = 0;
1656 _INFO("account_manager_handle_account_type_query_supported_feature start");
1657 guint pid = _get_client_pid(invocation);
1659 _INFO("client Id = [%u]", pid);
1661 int return_code = _check_priviliege_account_read(invocation);
1662 if (return_code != ACCOUNT_ERROR_NONE)
1664 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1668 return_code = _account_db_open(0, (const char*)account_db_path);
1669 if (return_code != ACCOUNT_ERROR_NONE)
1671 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1676 _INFO("before _account_type_query_supported_feature");
1677 is_supported = _account_type_query_supported_feature(app_id, capability, &return_code);
1678 _INFO("after _account_type_query_supported_feature=[%d]", return_code);
1680 if (return_code != ACCOUNT_ERROR_NONE)
1682 _ERR("_account_type_query_supported_feature error");
1687 if (return_code != ACCOUNT_ERROR_NONE)
1689 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1690 g_dbus_method_invocation_return_gerror (invocation, error);
1694 _INFO("Calling account_manager_complete_account_type_query_provider_feature_by_app_id");
1695 account_manager_complete_account_type_query_supported_feature(obj, invocation, is_supported);
1697 _INFO("account_manager_handle_account_type_query_supported_feature end");
1699 return_code = _account_db_close();
1700 if (return_code != ACCOUNT_ERROR_NONE)
1702 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1703 return_code = ACCOUNT_ERROR_NONE;
1709 gboolean account_manager_handle_account_type_update_to_db_by_app_id (AccountManager *obj,
1710 GDBusMethodInvocation *invocation,
1711 gchar *account_db_path,
1712 GVariant *account_type_variant,
1713 const gchar *app_id)
1715 _INFO("account_manager_handle_account_type_update_to_db_by_app_id start");
1717 guint pid = _get_client_pid(invocation);
1719 _INFO("client Id = [%u]", pid);
1721 int return_code = _check_priviliege_account_read(invocation);
1722 if (return_code != ACCOUNT_ERROR_NONE)
1724 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1727 return_code = _check_priviliege_account_write(invocation);
1728 if (return_code != ACCOUNT_ERROR_NONE)
1730 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
1734 return_code = _account_db_open(1, (const char*)account_db_path);
1735 if (return_code != ACCOUNT_ERROR_NONE)
1737 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1742 account_type_s* account_type = umarshal_account_type(account_type_variant);
1744 _INFO("before _account_type_update_to_db_by_app_id");
1745 return_code = _account_type_update_to_db_by_app_id(account_type, app_id);
1746 _INFO("after _account_type_update_to_db_by_app_id=[%d]", return_code);
1748 if (return_code != ACCOUNT_ERROR_NONE)
1750 _ERR("_account_type_update_to_db_by_app_id error");
1755 if (return_code != ACCOUNT_ERROR_NONE)
1757 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1758 g_dbus_method_invocation_return_gerror (invocation, error);
1762 _INFO("Calling account_manager_complete_account_type_update_to_db_by_app_id");
1763 account_manager_complete_account_type_update_to_db_by_app_id(obj, invocation);
1765 _INFO("account_manager_handle_account_type_update_to_db_by_app_id end");
1767 return_code = _account_db_close();
1768 if (return_code != ACCOUNT_ERROR_NONE)
1770 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1771 return_code = ACCOUNT_ERROR_NONE;
1777 gboolean account_manager_handle_account_type_delete_by_app_id (AccountManager *obj,
1778 GDBusMethodInvocation *invocation,
1779 gchar *account_db_path,
1780 const gchar *app_id)
1782 _INFO("account_manager_handle_account_type_delete_by_app_id start");
1784 guint pid = _get_client_pid(invocation);
1786 _INFO("client Id = [%u]", pid);
1788 int return_code = _check_priviliege_account_read(invocation);
1789 if (return_code != ACCOUNT_ERROR_NONE)
1791 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1794 return_code = _check_priviliege_account_write(invocation);
1795 if (return_code != ACCOUNT_ERROR_NONE)
1797 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
1801 return_code = _account_db_open(1, (const char*)account_db_path);
1802 if (return_code != ACCOUNT_ERROR_NONE)
1804 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1809 _INFO("before _account_type_delete_by_app_id");
1810 return_code = _account_type_delete_by_app_id (app_id);
1811 _INFO("after _account_type_delete_by_app_id=[%d]", return_code);
1813 if (return_code != ACCOUNT_ERROR_NONE)
1815 _ERR("_account_type_delete_by_app_id error");
1820 if (return_code != ACCOUNT_ERROR_NONE)
1822 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1823 g_dbus_method_invocation_return_gerror (invocation, error);
1827 _ERR("Calling account_manager_complete_account_type_update_to_db_by_app_id");
1828 account_manager_complete_account_type_delete_by_app_id (obj, invocation);
1830 _INFO("account_manager_handle_account_type_delete_by_app_id end");
1832 return_code = _account_db_close();
1833 if (return_code != ACCOUNT_ERROR_NONE)
1835 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1836 return_code = ACCOUNT_ERROR_NONE;
1842 gboolean account_manager_handle_account_type_query_label_by_app_id (AccountManager *obj,
1843 GDBusMethodInvocation *invocation,
1844 gchar *account_db_path,
1845 const gchar *app_id)
1847 _INFO("account_manager_handle_account_type_query_label_by_app_id start");
1848 GSList* label_list = NULL;
1849 GVariant* label_list_variant = NULL;
1851 guint pid = _get_client_pid(invocation);
1853 _INFO("client Id = [%u]", pid);
1855 int return_code = _check_priviliege_account_read(invocation);
1856 if (return_code != ACCOUNT_ERROR_NONE)
1858 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1862 return_code = _account_db_open(0, (const char*)account_db_path);
1863 if (return_code != ACCOUNT_ERROR_NONE)
1865 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1870 _INFO("before _account_type_get_label_list_by_app_id");
1871 label_list = _account_type_get_label_list_by_app_id (app_id, &return_code);
1872 _INFO("after _account_type_get_label_list_by_app_id=[%d]", return_code);
1874 if (return_code != ACCOUNT_ERROR_NONE)
1876 _ERR("_account_type_get_label_list_by_app_id = [%d]", return_code);
1880 label_list_variant = label_list_to_variant (label_list);
1883 if (return_code != ACCOUNT_ERROR_NONE)
1885 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1886 g_dbus_method_invocation_return_gerror (invocation, error);
1890 _ERR("Calling account_manager_complete_account_type_query_label_by_app_id");
1891 account_manager_complete_account_type_query_label_by_app_id (obj, invocation, label_list_variant);
1893 _INFO("account_manager_handle_account_type_query_label_by_app_id end");
1895 return_code = _account_db_close();
1896 if (return_code != ACCOUNT_ERROR_NONE)
1898 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1899 return_code = ACCOUNT_ERROR_NONE;
1905 gboolean account_manager_handle_account_type_query_by_app_id (AccountManager *obj,
1906 GDBusMethodInvocation *invocation,
1907 gchar *account_db_path,
1908 const gchar *app_id)
1910 _INFO("account_manager_handle_account_type_query_by_app_id start");
1911 GVariant* account_type_variant = NULL;
1913 guint pid = _get_client_pid(invocation);
1915 _INFO("client Id = [%u]", pid);
1917 int return_code = _check_priviliege_account_read(invocation);
1918 if (return_code != ACCOUNT_ERROR_NONE)
1920 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1924 return_code = _account_db_open(0, (const char*)account_db_path);
1925 if (return_code != ACCOUNT_ERROR_NONE)
1927 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1932 _INFO("before _account_type_query_by_app_id");
1933 account_type_s* account_type = NULL;
1934 return_code = _account_type_query_by_app_id (app_id, &account_type);
1935 _INFO("after _account_type_query_by_app_id=[%d]", return_code);
1937 if (return_code != ACCOUNT_ERROR_NONE)
1939 _ERR("_account_type_query_by_app_id = [%d]", return_code);
1942 if (account_type == NULL)
1944 _ERR("account_type read is NULL");
1945 return_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
1949 account_type_variant = marshal_account_type( account_type);
1952 if (return_code != ACCOUNT_ERROR_NONE)
1954 _ERR("Account SVC is returning error [%d]", return_code);
1955 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
1956 g_dbus_method_invocation_return_gerror (invocation, error);
1960 _INFO("Calling account_manager_complete_account_type_query_by_app_id");
1961 account_manager_complete_account_type_query_by_app_id (obj, invocation, account_type_variant);
1963 _INFO("account_manager_handle_account_type_query_by_app_id end");
1965 return_code = _account_db_close();
1966 if (return_code != ACCOUNT_ERROR_NONE)
1968 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1969 return_code = ACCOUNT_ERROR_NONE;
1975 gboolean account_manager_handle_account_type_query_app_id_exist (AccountManager *obj,
1976 GDBusMethodInvocation *invocation,
1977 gchar *account_db_path, const gchar *app_id)
1979 _INFO("account_manager_handle_account_type_query_app_id_exist start");
1980 guint pid = _get_client_pid(invocation);
1982 _INFO("client Id = [%u]", pid);
1984 int return_code = _check_priviliege_account_read(invocation);
1985 if (return_code != ACCOUNT_ERROR_NONE)
1987 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
1991 return_code = _account_db_open(0, (const char*)account_db_path);
1992 if (return_code != ACCOUNT_ERROR_NONE)
1994 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
1999 _INFO("before _account_type_query_app_id_exist");
2000 return_code = _account_type_query_app_id_exist (app_id);
2001 _INFO("after _account_type_query_app_id_exist=[%d]", return_code);
2003 if (return_code != ACCOUNT_ERROR_NONE)
2005 _ERR("_account_type_query_app_id_exist = [%d]", return_code);
2010 if (return_code != ACCOUNT_ERROR_NONE)
2012 _ERR("Account SVC is returning error [%d]", return_code);
2013 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
2014 g_dbus_method_invocation_return_gerror (invocation, error);
2018 _INFO("Calling account_manager_complete_account_type_query_by_app_id");
2019 account_manager_complete_account_type_query_app_id_exist (obj, invocation);
2021 _INFO("account_manager_handle_account_type_query_app_id_exist end");
2023 return_code = _account_db_close();
2024 if (return_code != ACCOUNT_ERROR_NONE)
2026 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
2027 return_code = ACCOUNT_ERROR_NONE;
2033 gboolean account_manager_handle_account_update_to_db_by_id_ex (AccountManager *obj,
2034 GDBusMethodInvocation *invocation,
2035 gchar *account_db_path,
2036 GVariant *account_data,
2039 _INFO("account_manager_handle_account_update_to_db_by_id_ex start");
2040 guint pid = _get_client_pid(invocation);
2042 _INFO("client Id = [%u]", pid);
2044 int return_code = _check_priviliege_account_read(invocation);
2045 if (return_code != ACCOUNT_ERROR_NONE)
2047 _ERR("_check_priviliege_account_read failed, ret = %d", return_code);
2050 return_code = _check_priviliege_account_write(invocation);
2051 if (return_code != ACCOUNT_ERROR_NONE)
2053 _ERR("_check_priviliege_account_write failed, ret = %d", return_code);
2057 return_code = _account_db_open(1, (const char*)account_db_path);
2058 if (return_code != ACCOUNT_ERROR_NONE)
2060 _ERR("_account_db_open() error, db_path = %s, ret = %d", (char*)account_db_path, return_code);
2065 account_s* account = umarshal_account(account_data);
2066 if (account == NULL)
2068 _ERR("Unmarshal failed");
2069 return_code = ACCOUNT_ERROR_INVALID_PARAMETER;
2073 _INFO("before _account_update_to_db_by_id_ex");
2074 return_code = _account_update_to_db_by_id_ex (account, account_id);
2075 _INFO("after _account_update_to_db_by_id_ex()=[%d]", return_code);
2077 if (return_code != ACCOUNT_ERROR_NONE)
2079 _ERR("_account_update_to_db_by_id_ex error");
2084 if (return_code != ACCOUNT_ERROR_NONE)
2086 _ERR("Account SVC is returning error [%d]", return_code);
2087 GError* error = g_error_new (_account_error_quark(), return_code, "RecordNotFound");
2088 g_dbus_method_invocation_return_gerror (invocation, error);
2092 _INFO("Calling account_manager_complete_account_update_to_db_by_id_ex");
2093 account_manager_complete_account_update_to_db_by_id_ex (obj, invocation);
2095 _INFO("in account_manager_handle_account_update_to_db_by_id_ex_p end");
2097 return_code = _account_db_close();
2098 if (return_code != ACCOUNT_ERROR_NONE)
2100 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
2101 return_code = ACCOUNT_ERROR_NONE;
2108 on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
2110 _INFO("on_bus_acquired [%s]", name);
2112 GDBusInterfaceSkeleton* interface = NULL;
2113 account_mgr_server_obj = account_manager_skeleton_new();
2114 if (account_mgr_server_obj == NULL)
2116 _ERR("account_mgr_server_obj NULL!!");
2120 interface = G_DBUS_INTERFACE_SKELETON(account_mgr_server_obj);
2121 if (!g_dbus_interface_skeleton_export(interface, connection, ACCOUNT_MGR_DBUS_PATH, NULL))
2123 _ERR("export failed!!");
2127 _INFO("connecting account signals start");
2129 g_signal_connect(account_mgr_server_obj, "handle_account_add",
2130 G_CALLBACK(account_manager_account_add), NULL);
2132 g_signal_connect(account_mgr_server_obj, "handle_account_query_all",
2133 G_CALLBACK(account_manager_account_query_all), NULL);
2135 g_signal_connect(account_mgr_server_obj, "handle_account_type_add",
2136 G_CALLBACK(account_manager_account_type_add), NULL);
2138 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_all",
2139 G_CALLBACK(account_manager_account_type_query_all), NULL);
2141 g_signal_connect(account_mgr_server_obj, "handle_account_delete_from_db_by_id",
2142 G_CALLBACK(account_manager_account_delete_from_db_by_id), NULL);
2144 g_signal_connect(account_mgr_server_obj, "handle_account_delete_from_db_by_user_name",
2145 G_CALLBACK(account_manager_account_delete_from_db_by_user_name), NULL);
2147 g_signal_connect(account_mgr_server_obj, "handle_account_delete_from_db_by_package_name",
2148 G_CALLBACK(account_manager_account_delete_from_db_by_package_name), NULL);
2150 g_signal_connect(account_mgr_server_obj, "handle_account_update_to_db_by_id",
2151 G_CALLBACK(account_manager_account_update_to_db_by_id), NULL);
2153 g_signal_connect(account_mgr_server_obj, "handle_account_get_total_count_from_db",
2154 G_CALLBACK(account_manager_account_get_total_count_from_db), NULL);
2156 g_signal_connect(account_mgr_server_obj, "handle_account_query_account_by_account_id",
2157 G_CALLBACK(account_manager_handle_account_query_account_by_account_id), NULL);
2159 g_signal_connect(account_mgr_server_obj, "handle_account_update_to_db_by_user_name",
2160 G_CALLBACK(account_manager_handle_account_update_to_db_by_user_name), NULL);
2162 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_label_by_locale",
2163 G_CALLBACK(account_manager_handle_account_type_query_label_by_locale), NULL);
2165 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_by_provider_feature",
2166 G_CALLBACK(account_manager_handle_account_type_query_by_provider_feature), NULL);
2168 g_signal_connect(account_mgr_server_obj, "handle_account_query_account_by_user_name",
2169 G_CALLBACK(account_manager_handle_account_query_account_by_user_name), NULL);
2171 g_signal_connect(account_mgr_server_obj, "handle_account_query_account_by_package_name",
2172 G_CALLBACK(account_manager_handle_account_query_account_by_package_name), NULL);
2174 g_signal_connect(account_mgr_server_obj, "handle_account_query_account_by_capability",
2175 G_CALLBACK(account_manager_handle_account_query_account_by_capability), NULL);
2177 g_signal_connect(account_mgr_server_obj, "handle_account_query_account_by_capability_type",
2178 G_CALLBACK(account_manager_handle_account_query_account_by_capability_type), NULL);
2180 g_signal_connect(account_mgr_server_obj, "handle_account_query_capability_by_account_id",
2181 G_CALLBACK(account_manager_handle_account_query_capability_by_account_id), NULL);
2183 g_signal_connect(account_mgr_server_obj, "handle_account_update_sync_status_by_id",
2184 G_CALLBACK(account_manager_handle_account_update_sync_status_by_id), NULL);
2186 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_provider_feature_by_app_id",
2187 G_CALLBACK(account_manager_handle_account_type_query_provider_feature_by_app_id), NULL);
2190 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_supported_feature",
2191 G_CALLBACK(account_manager_handle_account_type_query_supported_feature), NULL);
2193 g_signal_connect(account_mgr_server_obj, "handle_account_type_update_to_db_by_app_id",
2194 G_CALLBACK(account_manager_handle_account_type_update_to_db_by_app_id), NULL);
2196 g_signal_connect(account_mgr_server_obj, "handle_account_type_delete_by_app_id",
2197 G_CALLBACK(account_manager_handle_account_type_delete_by_app_id), NULL);
2199 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_label_by_app_id",
2200 G_CALLBACK(account_manager_handle_account_type_query_label_by_app_id), NULL);
2202 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_by_app_id",
2203 G_CALLBACK(account_manager_handle_account_type_query_by_app_id), NULL);
2206 g_signal_connect(account_mgr_server_obj, "handle_account_type_query_app_id_exist",
2207 G_CALLBACK(account_manager_handle_account_type_query_app_id_exist), NULL);
2209 g_signal_connect(account_mgr_server_obj, "handle_account_update_to_db_by_id_ex",
2210 G_CALLBACK(account_manager_handle_account_update_to_db_by_id_ex), NULL);
2212 _INFO("connecting account signals end");
2214 g_dbus_object_manager_server_set_connection(account_mgr_server_mgr, connection);
2218 on_name_acquired (GDBusConnection *connection,
2222 _INFO("on_name_acquired");
2227 on_name_lost (GDBusConnection *connection,
2231 _INFO("on_name_lost");
2235 static bool _initialize_dbus()
2237 _INFO("__initialize_dbus Enter");
2239 owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
2240 "org.tizen.account.manager",
2241 G_BUS_NAME_OWNER_FLAGS_NONE,
2248 _INFO("owner_id=[%d]", owner_id);
2252 _INFO("gdbus own failed!!");
2256 _INFO("g_bus_own_name SUCCESS");
2262 static void _initialize()
2264 #if !GLIB_CHECK_VERSION(2,35,0)
2269 if (_initialize_dbus() == false)
2270 { /* because dbus's initialize
2271 failed, we cannot continue any more. */
2272 _ERR("DBUS Initialization Failed");
2276 ret = cynara_initialize(&p_cynara, NULL);
2277 if(ret != CYNARA_API_SUCCESS) {
2278 _ERR("CYNARA Initialization fail");
2285 GMainLoop *mainloop = NULL;
2287 _INFO("Starting Accounts SVC");
2289 mainloop = g_main_loop_new(NULL, FALSE);
2293 g_main_loop_run(mainloop);
2295 cynara_finish(p_cynara);
2297 _INFO("Ending Accounts SVC");