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.
22 #include <glib/gprintf.h>
24 #include <gio/gunixfdlist.h>
29 #include <pkgmgr_installer_info.h>
30 #include <system_info.h>
33 #include <account-private.h>
34 #include <account_free.h>
35 #include <account_ipc_marshal.h>
36 #include <account-mgr-stub.h>
40 #include "account-error.h"
41 #include "account-types.h"
42 #include "account_internal.h"
43 #include "account_private_client.h"
45 #define ACCOUNT_FEATURE "http://tizen.org/feature/account"
47 #define CHECK_ACCOUNT_SUPPORTED(feature_name) \
49 bool is_supported = false; \
50 if (!system_info_get_platform_bool(feature_name, &is_supported)) { \
51 if (is_supported == false) { \
52 LOGE("[%s] feature is disabled", feature_name); \
53 return ACCOUNT_ERROR_NOT_SUPPORTED; \
56 LOGE("Error - Feature getting from System Info"); \
60 #define ACCOUNT_DB_OPEN_READONLY 0
61 #define ACCOUNT_DB_OPEN_READWRITE 1
65 static GDBusConnection *_connection = NULL;
66 static AccountManager *_acc_mgr = NULL;
67 static int _instance_count = 0;
68 static pthread_mutex_t _account_proxy_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
70 static void _account_manager_increase_count()
75 static void _account_manager_decrease_count()
80 static void _account_manager_destroy_instance()
82 g_object_unref(_connection);
84 g_object_unref(_acc_mgr);
88 static void _account_manager_release_instance()
90 pthread_mutex_lock(&_account_proxy_instance_mutex);
91 _account_manager_decrease_count();
93 if (_instance_count <= 0)
94 _account_manager_destroy_instance();
95 pthread_mutex_unlock(&_account_proxy_instance_mutex);
98 static char *_account_get_text(const char *text_data)
100 char *text_value = NULL;
102 if (text_data != NULL)
103 text_value = strdup(text_data);
108 static AccountManager *
109 _account_manager_get_instance()
111 _INFO("_account_manager_get_instance");
112 pthread_mutex_lock(&_account_proxy_instance_mutex);
113 if (_acc_mgr != NULL) {
114 _INFO("instance already created.");
115 _account_manager_increase_count();
116 pthread_mutex_unlock(&_account_proxy_instance_mutex);
120 #if !GLIB_CHECK_VERSION(2, 35, 0)
124 GError *error = NULL;
126 _connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
128 _INFO("after g_bus_get_sync");
132 _ERR("Unable to connect to gdbus: %s", error->message);
133 g_clear_error(&error);
135 pthread_mutex_unlock(&_account_proxy_instance_mutex);
139 g_clear_error(&error);
141 /* Create the object */
143 account_manager_proxy_new_sync(_connection,
144 G_DBUS_PROXY_FLAGS_NONE,
145 "org.tizen.account.manager",
146 "/org/tizen/account/manager",
152 _ERR("Unable account_manager_proxy_new_sync: %s", error->message);
153 g_clear_error(&error);
156 g_object_unref(_connection);
159 pthread_mutex_unlock(&_account_proxy_instance_mutex);
163 g_clear_error(&error);
165 _account_manager_increase_count();
166 _INFO("_account_manager_get_instance end");
167 pthread_mutex_unlock(&_account_proxy_instance_mutex);
171 GDBusErrorEntry _account_svc_errors[] = {
172 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
173 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
174 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
175 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
176 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
177 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
178 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
179 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
180 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
181 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
182 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
183 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
184 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
185 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
186 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
187 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
188 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
189 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
192 static int _account_get_error_code(bool is_success, GError *error)
195 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
197 if (g_dbus_error_is_remote_error(error)) {
198 gchar *remote_error = g_dbus_error_get_remote_error(error);
200 _INFO("Remote error[%s]", remote_error);
202 /* FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
203 However error->message matches, so doing reverse lookup */
204 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
206 for (i = 0; i < error_enum_count; i++) {
207 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0) {
208 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
209 g_free(remote_error);
210 return _account_svc_errors[i].error_code;
213 g_free(remote_error);
216 /* All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED */
217 return ACCOUNT_ERROR_PERMISSION_DENIED;
219 return ACCOUNT_ERROR_NONE;
222 ACCOUNT_API int account_connect(void)
224 _INFO("DEPRECATION WARNING: account_connect() is deprecated and will be removed from next release.");
225 return ACCOUNT_ERROR_NONE;
228 ACCOUNT_API int account_connect_readonly(void)
230 _INFO("DEPRECATION WARNING: account_connect_readonly() is deprecated and will be removed from next release.");
231 return ACCOUNT_ERROR_NONE;
234 ACCOUNT_API int account_disconnect(void)
236 _INFO("DEPRECATION WARNING: account_disconnect() is deprecated and will be removed from next release.");
237 return ACCOUNT_ERROR_NONE;
241 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
243 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
245 _INFO("1. account_insert_to_db start");
247 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
248 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
250 account_s *account_data = (account_s *)account;
251 int error_code = ACCOUNT_ERROR_NONE;
252 GError *error = NULL;
254 _INFO("2. Before _account_manager_get_instance()");
255 AccountManager *acc_mgr = _account_manager_get_instance();
256 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
259 GVariant *account_serialized = marshal_account(account_data);
261 _INFO("3. Before account_manager_call_account_add_sync");
262 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_serialized, (int)getuid(), &db_id, NULL, &error);
263 _account_manager_release_instance();
265 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
266 g_clear_error(&error);
268 *account_db_id = db_id;
269 account_data->id = db_id;
271 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
273 return ACCOUNT_ERROR_NONE;
276 g_clear_error(&error);
277 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
281 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
283 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
285 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
286 int error_code = ACCOUNT_ERROR_NONE;
288 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
290 GError *error = NULL;
292 AccountManager *acc_mgr = _account_manager_get_instance();
293 if (acc_mgr == NULL) {
294 _ERR("g_bus_get_sync failed");
295 return ACCOUNT_ERROR_PERMISSION_DENIED;
298 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
299 GVariant *account_serialized_old = NULL;
300 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)getuid(), false, &account_serialized_old, NULL, &error);
303 error_code = _account_get_error_code(is_success, error);
304 g_clear_error(&error);
305 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
306 _account_manager_release_instance();
309 g_clear_error(&error);
311 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
312 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_id, (int)getuid(), NULL, &error);
313 _account_manager_release_instance();
316 error_code = _account_get_error_code(is_success, error);
317 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error_code);
318 g_clear_error(&error);
321 g_clear_error(&error);
323 _INFO("4. Before account_delete_from_db_by_id end");
324 return ACCOUNT_ERROR_NONE;
327 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
329 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
331 int error_code = ACCOUNT_ERROR_NONE;
332 _INFO("account_delete_from_db_by_user_name start");
334 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
335 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
338 GError *error = NULL;
340 AccountManager *acc_mgr = _account_manager_get_instance();
341 if (acc_mgr == NULL) {
342 _ERR("g_bus_get_sync failed");
343 return ACCOUNT_ERROR_PERMISSION_DENIED;
346 GVariant *account_list_variant = NULL;
347 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
349 error_code = _account_get_error_code(is_success, error);
350 g_clear_error(&error);
351 if (error_code != ACCOUNT_ERROR_NONE) {
352 _account_manager_release_instance();
353 _ERR("account_query_account_by_user_name error=[%d]", error_code);
357 GSList *account_list = unmarshal_account_list(account_list_variant);
358 g_variant_unref(account_list_variant);
360 if (account_list == NULL) {
361 _account_manager_release_instance();
362 return ACCOUNT_ERROR_NO_DATA;
365 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, user_name, package_name, (int)getuid(), NULL, &error);
366 _account_manager_release_instance();
369 error_code = _account_get_error_code(is_success, error);
370 g_clear_error(&error);
371 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
372 _account_gslist_account_free(account_list);
375 g_clear_error(&error);
377 _account_gslist_account_free(account_list);
378 return ACCOUNT_ERROR_NONE;
381 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
383 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
385 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
386 int error_code = ACCOUNT_ERROR_NONE;
388 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
390 GError *error = NULL;
392 AccountManager *acc_mgr = _account_manager_get_instance();
393 if (acc_mgr == NULL) {
394 _ERR("g_bus_get_sync failed");
395 return ACCOUNT_ERROR_PERMISSION_DENIED;
398 //First get account list of user_name, used for gSSO DB deletion
399 GVariant* account_list_variant = NULL;
400 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, (int)getuid(), &account_list_variant, NULL, &error);
402 error_code = _account_get_error_code(is_success, error);
403 if (error_code != ACCOUNT_ERROR_NONE)
405 _account_manager_release_instance();
409 _INFO("before unmarshal_account_list");
410 GSList* account_list = unmarshal_account_list(account_list_variant);
411 _INFO("after unmarshal_account_list");
412 if (account_list == NULL)
414 _account_manager_release_instance();
415 return ACCOUNT_ERROR_NO_DATA;
418 bool is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, package_name, permission, (int)getuid(), NULL, &error);
419 _account_manager_release_instance();
422 error_code = _account_get_error_code(is_success, error);
423 g_clear_error(&error);
424 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error_code);
427 g_clear_error(&error);
429 return ACCOUNT_ERROR_NONE;
432 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
434 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
436 _INFO("account_delete_from_db_by_package_name starting with permission");
437 return _account_delete_from_db_by_package_name(package_name, true);
440 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
442 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
444 _INFO("1. account_update_to_db_by_id start");
445 int error_code = ACCOUNT_ERROR_NONE;
447 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
448 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
450 GError *error = NULL;
452 AccountManager *acc_mgr = _account_manager_get_instance();
453 if (acc_mgr == NULL) {
454 _ERR("g_bus_get_sync failed");
455 return ACCOUNT_ERROR_PERMISSION_DENIED;
458 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
459 GVariant *account_serialized_old = NULL;
460 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), false, &account_serialized_old, NULL, &error);
463 error_code = _account_get_error_code(is_success, error);
464 g_clear_error(&error);
465 _account_manager_release_instance();
466 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
469 g_clear_error(&error);
471 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
472 GVariant *account_serialized = marshal_account((account_s *)account);
473 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
474 _account_manager_release_instance();
477 error_code = _account_get_error_code(is_success, error);
478 g_clear_error(&error);
479 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error_code);
482 g_clear_error(&error);
484 _INFO("4. account_update_to_db_by_id end");
485 return ACCOUNT_ERROR_NONE;
488 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
490 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
493 ret = account_update_to_db_by_id(account, account_id);
498 ACCOUNT_INTERNAL_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
500 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
502 _INFO("account_update_to_db_by_id_without_permission start");
503 int error_code = ACCOUNT_ERROR_NONE;
505 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
506 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
508 GError *error = NULL;
510 AccountManager *acc_mgr = _account_manager_get_instance();
511 if (acc_mgr == NULL) {
512 _ERR("g_bus_get_sync failed");
513 return ACCOUNT_ERROR_PERMISSION_DENIED;
516 GVariant *account_serialized_old = NULL;
517 _INFO("before query() account_id[%d]", account_id);
520 if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
521 _ERR("pkgmgr_installer_info_get_target_uid() fail");
522 return ACCOUNT_ERROR_DB_NOT_OPENED;
524 /* Workaround for internal UTC */
528 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)uid, false, &account_serialized_old, NULL, &error);
531 error_code = _account_get_error_code(is_success, error);
532 g_clear_error(&error);
533 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
534 _account_manager_release_instance();
537 g_clear_error(&error);
539 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s *)account)->user_name);
540 GVariant *account_serialized = marshal_account((account_s *)account);
541 _INFO("after marshal() : account_id[%d]", account_id);
542 if (account_serialized == NULL) {
543 _ERR("Invalid input");
544 _account_manager_release_instance();
545 return ACCOUNT_ERROR_INVALID_PARAMETER;
548 _INFO("before call update() : account_id[%d]", account_id);
549 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
551 _INFO("after call update() : is_success=%d", is_success);
552 _account_manager_release_instance();
555 error_code = _account_get_error_code(is_success, error);
556 g_clear_error(&error);
557 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error_code);
560 g_clear_error(&error);
562 return ACCOUNT_ERROR_NONE;
565 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
567 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
569 _INFO("account_update_to_db_by_user_name starting");
570 int error_code = ACCOUNT_ERROR_NONE;
572 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
573 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
574 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
576 GError *error = NULL;
578 AccountManager *acc_mgr = _account_manager_get_instance();
579 if (acc_mgr == NULL) {
580 _ERR("g_bus_get_sync failed");
581 return ACCOUNT_ERROR_PERMISSION_DENIED;
584 GVariant *account_serialized_old = NULL;
585 account_s *account_data = (account_s *)account;
586 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_data->id, (int)getuid(), false, &account_serialized_old, NULL, &error);
589 error_code = _account_get_error_code(is_success, error);
590 g_clear_error(&error);
591 _account_manager_release_instance();
592 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
595 g_clear_error(&error);
597 GVariant *account_serialized = marshal_account(account_data);
598 is_success = account_manager_call_account_update_to_db_by_user_name_sync(acc_mgr, account_serialized, user_name, package_name, (int)getuid(), NULL, &error);
599 _account_manager_release_instance();
602 error_code = _account_get_error_code(is_success, error);
603 g_clear_error(&error);
604 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error_code);
607 g_clear_error(&error);
609 return ACCOUNT_ERROR_NONE;
612 ACCOUNT_API int account_create(account_h *account)
614 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
616 _INFO("account_create start");
618 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
619 return ACCOUNT_ERROR_INVALID_PARAMETER;
622 account_s *data = (account_s *)malloc(sizeof(account_s));
624 ACCOUNT_ERROR("Memory Allocation Failed");
625 return ACCOUNT_ERROR_OUT_OF_MEMORY;
628 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
630 /* Setting account as visible by default */
631 data->secret = ACCOUNT_SECRECY_VISIBLE;
633 /* Setting account as not supporting sync by default */
634 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
636 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
638 data->capablity_list = NULL;
639 data->custom_list = NULL;
641 *account = (account_h)data;
643 _INFO("account_create end");
644 return ACCOUNT_ERROR_NONE;
647 ACCOUNT_API int account_destroy(account_h account)
649 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
651 _INFO("account_destroy start");
652 account_s *data = (account_s *)account;
654 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
656 _account_free_account_with_items(data);
658 _INFO("account_destroy end");
659 return ACCOUNT_ERROR_NONE;
662 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
664 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
667 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
668 return ACCOUNT_ERROR_INVALID_PARAMETER;
671 if (!user_name || strlen(user_name) <= 0) {
672 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL or Empty.\n", __FUNCTION__, __LINE__);
673 return ACCOUNT_ERROR_INVALID_PARAMETER;
676 account_s *data = (account_s *)account;
678 _ACCOUNT_FREE(data->user_name);
679 data->user_name = _account_get_text(user_name);
680 if (data->user_name == NULL) {
681 ACCOUNT_ERROR("OUT OF MEMORY\n");
682 return ACCOUNT_ERROR_OUT_OF_MEMORY;
685 return ACCOUNT_ERROR_NONE;
688 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
690 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
693 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
694 return ACCOUNT_ERROR_INVALID_PARAMETER;
697 if (!display_name || strlen(display_name) <= 0) {
698 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL or Empty.\n", __FUNCTION__, __LINE__);
699 return ACCOUNT_ERROR_INVALID_PARAMETER;
702 account_s *data = (account_s *)account;
704 _ACCOUNT_FREE(data->display_name);
705 data->display_name = _account_get_text(display_name);
706 if (data->display_name == NULL) {
707 ACCOUNT_ERROR("OUT OF MEMORY\n");
708 return ACCOUNT_ERROR_OUT_OF_MEMORY;
711 return ACCOUNT_ERROR_NONE;
714 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
716 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
719 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
720 return ACCOUNT_ERROR_INVALID_PARAMETER;
723 if (!email_address || strlen(email_address) <= 0) {
724 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL or Empty.\n", __FUNCTION__, __LINE__);
725 return ACCOUNT_ERROR_INVALID_PARAMETER;
728 account_s *data = (account_s *)account;
730 _ACCOUNT_FREE(data->email_address);
731 data->email_address = _account_get_text(email_address);
732 if (data->email_address == NULL) {
733 ACCOUNT_ERROR("OUT OF MEMORY\n");
734 return ACCOUNT_ERROR_OUT_OF_MEMORY;
737 return ACCOUNT_ERROR_NONE;
740 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
742 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
745 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
746 return ACCOUNT_ERROR_INVALID_PARAMETER;
749 if (!icon_path || strlen(icon_path) <= 0) {
750 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL or Empty.\n", __FUNCTION__, __LINE__);
751 return ACCOUNT_ERROR_INVALID_PARAMETER;
754 account_s *data = (account_s *)account;
756 _ACCOUNT_FREE(data->icon_path);
757 data->icon_path = _account_get_text(icon_path);
758 if (data->icon_path == NULL) {
759 ACCOUNT_ERROR("OUT OF MEMORY\n");
760 return ACCOUNT_ERROR_OUT_OF_MEMORY;
763 return ACCOUNT_ERROR_NONE;
766 ACCOUNT_API int account_set_source(account_h account, const char *source)
768 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
771 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
772 return ACCOUNT_ERROR_INVALID_PARAMETER;
775 if (!source || strlen(source) <= 0) {
776 ACCOUNT_SLOGE("(%s)-(%d) source is NULL or Empty.\n", __FUNCTION__, __LINE__);
777 return ACCOUNT_ERROR_INVALID_PARAMETER;
779 account_s *data = (account_s *)account;
781 _ACCOUNT_FREE(data->source);
782 data->source = _account_get_text(source);
783 if (data->source == NULL) {
784 ACCOUNT_ERROR("OUT OF MEMORY\n");
785 return ACCOUNT_ERROR_OUT_OF_MEMORY;
788 return ACCOUNT_ERROR_NONE;
791 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
793 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
796 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
797 return ACCOUNT_ERROR_INVALID_PARAMETER;
800 if (!package_name || strlen(package_name) <= 0) {
801 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL or Empty.\n", __FUNCTION__, __LINE__);
802 return ACCOUNT_ERROR_INVALID_PARAMETER;
805 account_s *data = (account_s *)account;
807 _ACCOUNT_FREE(data->package_name);
808 data->package_name = _account_get_text(package_name);
809 if (data->package_name == NULL) {
810 ACCOUNT_ERROR("OUT OF MEMORY\n");
811 return ACCOUNT_ERROR_OUT_OF_MEMORY;
814 return ACCOUNT_ERROR_NONE;
817 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
819 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
822 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
823 return ACCOUNT_ERROR_INVALID_PARAMETER;
826 if (!domain_name || strlen(domain_name) <= 0) {
827 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL or Empty.\n", __FUNCTION__, __LINE__);
828 return ACCOUNT_ERROR_INVALID_PARAMETER;
830 account_s *data = (account_s *)account;
832 _ACCOUNT_FREE(data->domain_name);
833 data->domain_name = _account_get_text(domain_name);
834 if (data->domain_name == NULL) {
835 ACCOUNT_ERROR("OUT OF MEMORY\n");
836 return ACCOUNT_ERROR_OUT_OF_MEMORY;
839 return ACCOUNT_ERROR_NONE;
842 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
844 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
847 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
848 return ACCOUNT_ERROR_INVALID_PARAMETER;
851 if (!access_token || strlen(access_token) <= 0) {
852 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL or Empty.\n", __FUNCTION__, __LINE__);
853 return ACCOUNT_ERROR_INVALID_PARAMETER;
856 account_s *data = (account_s *)account;
858 _ACCOUNT_FREE(data->access_token);
859 data->access_token = _account_get_text(access_token);
860 if (data->access_token == NULL) {
861 ACCOUNT_ERROR("OUT OF MEMORY\n");
862 return ACCOUNT_ERROR_OUT_OF_MEMORY;
865 return ACCOUNT_ERROR_NONE;
868 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
870 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
873 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
874 return ACCOUNT_ERROR_INVALID_PARAMETER;
877 if (!user_txt || strlen(user_txt) <= 0) {
878 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL or Empty.\n", __FUNCTION__, __LINE__);
879 return ACCOUNT_ERROR_INVALID_PARAMETER;
881 if (idx >= USER_TXT_CNT || idx < 0) {
882 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
883 return ACCOUNT_ERROR_INVALID_PARAMETER;
886 account_s *data = (account_s *)account;
888 _ACCOUNT_FREE(data->user_data_txt[idx]);
889 data->user_data_txt[idx] = _account_get_text(user_txt);
890 if (data->user_data_txt[idx] == NULL) {
891 ACCOUNT_ERROR("OUT OF MEMORY\n");
892 return ACCOUNT_ERROR_OUT_OF_MEMORY;
895 return ACCOUNT_ERROR_NONE;
898 ACCOUNT_API int account_set_custom(account_h account, const char *key, const char *value)
900 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
903 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
904 return ACCOUNT_ERROR_INVALID_PARAMETER;
907 if (!key || strlen(key) <= 0) {
908 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
909 return ACCOUNT_ERROR_INVALID_PARAMETER;
912 if (!value || strlen(value) <= 0) {
913 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
914 return ACCOUNT_ERROR_INVALID_PARAMETER;
917 account_s *data = (account_s *)account;
920 bool b_is_new = TRUE;
922 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
924 account_custom_s *custom_data = NULL;
925 custom_data = (account_custom_s *)iter->data;
926 ACCOUNT_SLOGD("account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
928 if (!strcmp(custom_data->key, key)) {
929 char *new_value = NULL;
930 new_value = _account_get_text(value);
931 if (new_value == NULL) {
932 ACCOUNT_ERROR("OUT OF MEMORY\n");
933 return ACCOUNT_ERROR_OUT_OF_MEMORY;
936 _ACCOUNT_FREE(custom_data->value);
937 custom_data->value = new_value;
944 account_custom_s* custom_data = (account_custom_s *)malloc(sizeof(account_custom_s));
945 if (custom_data == NULL) {
946 ACCOUNT_ERROR("Memory Allocation Failed");
947 return ACCOUNT_ERROR_OUT_OF_MEMORY;
950 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
951 custom_data->account_id = data->id;
953 custom_data->key = _account_get_text(key);
954 if (custom_data->key == NULL) {
955 ACCOUNT_ERROR("OUT OF MEMORY\n");
956 _ACCOUNT_FREE(custom_data);
957 return ACCOUNT_ERROR_OUT_OF_MEMORY;
960 custom_data->value = _account_get_text(value);
961 if (custom_data->value == NULL) {
962 ACCOUNT_ERROR("OUT OF MEMORY\n");
963 _ACCOUNT_FREE(custom_data->key);
964 _ACCOUNT_FREE(custom_data);
965 return ACCOUNT_ERROR_OUT_OF_MEMORY;
968 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
971 return ACCOUNT_ERROR_NONE;
974 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
976 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
978 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
980 if (((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN))
981 return ACCOUNT_ERROR_INVALID_PARAMETER;
983 account_s *data = (account_s *)account;
985 data->auth_type = (int)auth_type;
987 return ACCOUNT_ERROR_NONE;
990 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
992 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
994 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
996 if (((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE))
997 return ACCOUNT_ERROR_INVALID_PARAMETER;
999 account_s *data = (account_s *)account;
1001 data->secret = (int)secret;
1003 return ACCOUNT_ERROR_NONE;
1006 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
1008 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1010 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1012 if (((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC))
1013 return ACCOUNT_ERROR_INVALID_PARAMETER;
1015 account_s *data = (account_s *)account;
1017 data->sync_support = (int)sync_support;
1019 return ACCOUNT_ERROR_NONE;
1022 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
1024 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1027 return ACCOUNT_ERROR_INVALID_PARAMETER;
1029 if (idx >= USER_INT_CNT || idx < 0)
1030 return ACCOUNT_ERROR_INVALID_PARAMETER;
1032 account_s *data = (account_s *)account;
1034 data->user_data_int[idx] = user_int;
1036 return ACCOUNT_ERROR_NONE;
1039 ACCOUNT_API int account_set_capability(account_h account, const char *capability_type, account_capability_state_e capability_value)
1041 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1043 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
1044 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
1045 ACCOUNT_RETURN_VAL((strlen(capability_type) > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is Empty"));
1047 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED))
1048 return ACCOUNT_ERROR_INVALID_PARAMETER;
1050 account_s *data = (account_s *)account;
1052 GSList *iter = NULL;
1053 bool b_is_new = TRUE;
1055 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1056 account_capability_s *cap_data = NULL;
1057 cap_data = (account_capability_s *)iter->data;
1059 if (!strcmp(cap_data->type, capability_type)) {
1060 cap_data->value = capability_value;
1067 account_capability_s *cap_data = (account_capability_s *)malloc(sizeof(account_capability_s));
1068 if (cap_data == NULL) {
1069 ACCOUNT_ERROR("Memory Allocation Failed");
1070 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1073 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
1075 cap_data->type = _account_get_text(capability_type);
1076 if (cap_data->type == NULL) {
1077 ACCOUNT_ERROR("OUT OF MEMORY\n");
1078 _ACCOUNT_FREE(cap_data->type);
1079 _ACCOUNT_FREE(cap_data);
1080 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1083 cap_data->value = capability_value;
1084 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
1087 return ACCOUNT_ERROR_NONE;
1090 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
1092 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1095 return ACCOUNT_ERROR_INVALID_PARAMETER;
1098 return ACCOUNT_ERROR_INVALID_PARAMETER;
1100 account_s *data = (account_s *)account;
1102 (*user_name) = NULL;
1103 *user_name = _account_get_text(data->user_name);
1104 if (data->user_name != NULL && *user_name == NULL) {
1105 ACCOUNT_ERROR("OUT OF MEMORY\n");
1106 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1109 return ACCOUNT_ERROR_NONE;
1112 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
1114 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1117 return ACCOUNT_ERROR_INVALID_PARAMETER;
1120 return ACCOUNT_ERROR_INVALID_PARAMETER;
1122 account_s *data = (account_s *)account;
1124 (*display_name) = NULL;
1126 *display_name = _account_get_text(data->display_name);
1127 if (data->display_name != NULL && *display_name == NULL) {
1128 ACCOUNT_ERROR("OUT OF MEMORY\n");
1129 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1133 return ACCOUNT_ERROR_NONE;
1136 ACCOUNT_API int account_get_email_address(account_h account, char **email_address)
1138 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1141 return ACCOUNT_ERROR_INVALID_PARAMETER;
1144 return ACCOUNT_ERROR_INVALID_PARAMETER;
1146 account_s *data = (account_s *)account;
1148 (*email_address) = NULL;
1150 *email_address = _account_get_text(data->email_address);
1151 if (data->email_address != NULL && *email_address == NULL) {
1152 ACCOUNT_ERROR("OUT OF MEMORY\n");
1153 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1156 return ACCOUNT_ERROR_NONE;
1159 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
1161 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1164 return ACCOUNT_ERROR_INVALID_PARAMETER;
1167 return ACCOUNT_ERROR_INVALID_PARAMETER;
1169 account_s *data = (account_s *)account;
1171 (*icon_path) = NULL;
1173 *icon_path = _account_get_text(data->icon_path);
1174 if (data->icon_path != NULL && *icon_path == NULL) {
1175 ACCOUNT_ERROR("OUT OF MEMORY\n");
1176 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1179 return ACCOUNT_ERROR_NONE;
1182 ACCOUNT_API int account_get_source(account_h account, char **source)
1184 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1187 return ACCOUNT_ERROR_INVALID_PARAMETER;
1190 return ACCOUNT_ERROR_INVALID_PARAMETER;
1192 account_s *data = (account_s *)account;
1196 *source = _account_get_text(data->source);
1197 if (data->source != NULL && *source == NULL) {
1198 ACCOUNT_ERROR("OUT OF MEMORY\n");
1199 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1202 return ACCOUNT_ERROR_NONE;
1205 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1207 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1210 return ACCOUNT_ERROR_INVALID_PARAMETER;
1213 return ACCOUNT_ERROR_INVALID_PARAMETER;
1215 account_s *data = (account_s *)account;
1217 (*package_name) = NULL;
1219 *package_name = _account_get_text(data->package_name);
1220 if (data->package_name != NULL && *package_name == NULL) {
1221 ACCOUNT_ERROR("OUT OF MEMORY\n");
1222 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1226 return ACCOUNT_ERROR_NONE;
1229 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1231 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1234 return ACCOUNT_ERROR_INVALID_PARAMETER;
1237 return ACCOUNT_ERROR_INVALID_PARAMETER;
1239 account_s *data = (account_s *)account;
1241 (*domain_name) = NULL;
1243 *domain_name = _account_get_text(data->domain_name);
1244 if (data->domain_name != NULL && *domain_name == NULL) {
1245 ACCOUNT_ERROR("OUT OF MEMORY\n");
1246 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1249 return ACCOUNT_ERROR_NONE;
1252 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1254 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1257 return ACCOUNT_ERROR_INVALID_PARAMETER;
1260 return ACCOUNT_ERROR_INVALID_PARAMETER;
1262 account_s *data = (account_s *)account;
1264 (*access_token) = NULL;
1266 *access_token = _account_get_text(data->access_token);
1267 if (data->access_token != NULL && *access_token == NULL) {
1268 ACCOUNT_ERROR("OUT OF MEMORY\n");
1269 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1272 return ACCOUNT_ERROR_NONE;
1275 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1277 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1280 return ACCOUNT_ERROR_INVALID_PARAMETER;
1283 return ACCOUNT_ERROR_INVALID_PARAMETER;
1285 ACCOUNT_RETURN_VAL((user_text_index >= 0 && user_text_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1287 account_s *data = (account_s *)account;
1291 *text = _account_get_text(data->user_data_txt[user_text_index]);
1292 if (data->user_data_txt[user_text_index] != NULL && *text == NULL) {
1293 ACCOUNT_ERROR("OUT OF MEMORY\n");
1294 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1297 return ACCOUNT_ERROR_NONE;
1300 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1302 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1305 return ACCOUNT_ERROR_INVALID_PARAMETER;
1308 return ACCOUNT_ERROR_INVALID_PARAMETER;
1310 account_s *data = (account_s *)account;
1312 *auth_type = data->auth_type;
1314 return ACCOUNT_ERROR_NONE;
1317 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1319 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1322 return ACCOUNT_ERROR_INVALID_PARAMETER;
1325 return ACCOUNT_ERROR_INVALID_PARAMETER;
1327 account_s *data = (account_s *)account;
1329 *secret = data->secret;
1331 return ACCOUNT_ERROR_NONE;
1334 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1336 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1339 return ACCOUNT_ERROR_INVALID_PARAMETER;
1342 return ACCOUNT_ERROR_INVALID_PARAMETER;
1344 account_s *data = (account_s *)account;
1346 *sync_support = data->sync_support;
1348 return ACCOUNT_ERROR_NONE;
1351 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1353 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1356 return ACCOUNT_ERROR_INVALID_PARAMETER;
1359 return ACCOUNT_ERROR_INVALID_PARAMETER;
1361 account_s *data = (account_s *)account;
1363 *account_id = data->id;
1365 return ACCOUNT_ERROR_NONE;
1368 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1370 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1373 return ACCOUNT_ERROR_INVALID_PARAMETER;
1375 ACCOUNT_RETURN_VAL((user_int_index >= 0 && user_int_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1378 return ACCOUNT_ERROR_INVALID_PARAMETER;
1380 account_s *data = (account_s *)account;
1382 *integer = data->user_data_int[user_int_index];
1384 return ACCOUNT_ERROR_NONE;
1387 ACCOUNT_API int account_get_capability(account_h account, const char *capability_type, account_capability_state_e *capability_value)
1389 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1391 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1392 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1393 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1396 account_s *data = (account_s *)account;
1398 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1399 account_capability_s *cap_data = NULL;
1401 cap_data = (account_capability_s *)iter->data;
1403 if (!strcmp(capability_type, cap_data->type)) {
1404 *capability_value = cap_data->value;
1405 return ACCOUNT_ERROR_NONE;
1409 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1412 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1414 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1416 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1417 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1420 account_s *data = (account_s *)account;
1422 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1423 account_capability_s *cap_data = NULL;
1425 cap_data = (account_capability_s *)iter->data;
1427 if (callback(cap_data->type, cap_data->value, user_data) != TRUE)
1428 return ACCOUNT_ERROR_NONE;
1431 return ACCOUNT_ERROR_NONE;
1434 ACCOUNT_API int account_get_custom(account_h account, const char *key, char **value)
1436 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1438 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1439 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1440 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1443 account_s *data = (account_s *)account;
1445 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1446 account_custom_s *custom_data = NULL;
1448 custom_data = (account_custom_s *)iter->data;
1450 if (!strcmp(key, custom_data->key)) {
1452 *value = _account_get_text(custom_data->value);
1453 if (custom_data->value != NULL && *value == NULL) {
1454 ACCOUNT_ERROR("OUT OF MEMORY\n");
1455 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1458 return ACCOUNT_ERROR_NONE;
1462 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1465 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void *user_data)
1467 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1469 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1470 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1473 account_s *data = (account_s *)account;
1475 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1476 bool cb_ret = FALSE;
1477 account_custom_s *custom_data = NULL;
1479 custom_data = (account_custom_s *)iter->data;
1481 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1486 return ACCOUNT_ERROR_NONE;
1489 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1491 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1493 _INFO("account_foreach_account_from_db start");
1495 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1497 GError *error = NULL;
1499 AccountManager *acc_mgr = _account_manager_get_instance();
1500 if (acc_mgr == NULL) {
1501 _ERR("g_bus_get_sync failed");
1502 return ACCOUNT_ERROR_PERMISSION_DENIED;
1505 GVariant *account_list_variant = NULL;
1506 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, (int)getuid(), &account_list_variant, NULL, &error);
1507 _account_manager_release_instance();
1509 int error_code = _account_get_error_code(is_success, error);
1510 g_clear_error(&error);
1512 if (error_code != ACCOUNT_ERROR_NONE)
1515 GSList *account_list = unmarshal_account_list(account_list_variant);
1516 g_variant_unref(account_list_variant);
1520 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1521 _INFO("iterating received account_list");
1522 account_s *account = NULL;
1523 account = (account_s *)iter->data;
1524 _INFO("Before _account_query_identity_info_by_id");
1526 _INFO("account->id=%d", account->id);
1527 if (callback((account_h)account, user_data) == false) {
1528 _INFO("application callback requested to discontinue.");
1531 _INFO("After one iteration callback");
1533 _account_gslist_account_free(account_list);
1535 _INFO("account_foreach_account_from_db end");
1536 return ACCOUNT_ERROR_NONE;
1539 int _account_query_account_for_account_id(int account_db_id, account_h *account, bool query_del_acc)
1541 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1543 _INFO("_account_query_account_for_account_id start db_id [%d] del_acc [%d]", account_db_id, query_del_acc);
1545 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1546 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT POINTER IS NULL"));
1547 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1549 GError *error = NULL;
1551 AccountManager *acc_mgr = _account_manager_get_instance();
1552 if (acc_mgr == NULL) {
1553 _ERR("g_bus_get_sync failed");
1554 return ACCOUNT_ERROR_PERMISSION_DENIED;
1557 uid_t uid = (int)getuid();
1561 GVariant *account_variant = NULL;
1562 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)uid, query_del_acc, &account_variant, NULL, &error);
1563 _account_manager_release_instance();
1565 int error_code = _account_get_error_code(is_success, error);
1566 g_clear_error(&error);
1567 if (error_code != ACCOUNT_ERROR_NONE)
1570 _INFO("before unmarshal_account");
1571 account_s *account_data = umarshal_account(account_variant);
1572 g_variant_unref(account_variant);
1573 _INFO("after unmarshal_account");
1575 if (account_data == NULL) {
1576 _ERR("Failed to unmarshal");
1577 return ACCOUNT_ERROR_DB_FAILED;
1580 account_s **input = (account_s **)account;
1582 _account_free_account_with_items(*input);
1584 *input = account_data;
1586 _INFO("_account_query_account_for_account_id end");
1588 return ACCOUNT_ERROR_NONE;
1591 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1593 _INFO("account_query_account_by_account_id - account_db_id[%d]", account_db_id);
1595 return _account_query_account_for_account_id(account_db_id, account, false);
1598 ACCOUNT_API int account_query_deleted_account_info_by_account_id(int account_db_id, account_h *account)
1600 _INFO("account_query_deleted_account_info_by_account_id - account_db_id[%d]", account_db_id);
1602 return _account_query_account_for_account_id(account_db_id, account, true);
1605 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char *user_name, void *user_data)
1607 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1609 _INFO("account_query_account_by_user_name starting");
1611 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1612 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1614 GError *error = NULL;
1616 AccountManager *acc_mgr = _account_manager_get_instance();
1617 if (acc_mgr == NULL) {
1618 _ERR("g_bus_get_sync failed");
1619 return ACCOUNT_ERROR_PERMISSION_DENIED;
1622 uid_t uid = (int)getuid();
1626 GVariant *account_list_variant = NULL;
1627 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)uid, &account_list_variant, NULL, &error);
1628 _account_manager_release_instance();
1630 int error_code = _account_get_error_code(is_success, error);
1631 g_clear_error(&error);
1632 if (error_code != ACCOUNT_ERROR_NONE)
1635 GSList *account_list = unmarshal_account_list(account_list_variant);
1636 g_variant_unref(account_list_variant);
1638 if (account_list == NULL)
1639 return ACCOUNT_ERROR_NO_DATA;
1643 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1644 _INFO("iterating received account_list");
1645 account_s *account = NULL;
1646 account = (account_s *)iter->data;
1647 if (callback((account_h)account, user_data) == false) {
1648 _INFO("application callback requested to discontinue.");
1652 _INFO("account_query_account_by_user_name end");
1654 _account_gslist_account_free(account_list);
1655 return ACCOUNT_ERROR_NONE;
1658 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1660 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1662 _INFO("account_query_account_by_package_name starting");
1664 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1665 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1667 GError *error = NULL;
1669 AccountManager *acc_mgr = _account_manager_get_instance();
1670 if (acc_mgr == NULL) {
1671 _ERR("g_bus_get_sync failed");
1672 return ACCOUNT_ERROR_PERMISSION_DENIED;
1675 GVariant *account_list_variant = NULL;
1678 if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
1679 _ERR("pkgmgr_installer_info_get_target_uid() fail");
1680 return ACCOUNT_ERROR_DB_NOT_OPENED;
1683 uid = (int)getuid();
1687 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, package_name, (int)uid, &account_list_variant, NULL, &error);
1688 _account_manager_release_instance();
1690 int error_code = _account_get_error_code(is_success, error);
1691 g_clear_error(&error);
1692 if (error_code != ACCOUNT_ERROR_NONE)
1695 GSList *account_list = unmarshal_account_list(account_list_variant);
1696 g_variant_unref(account_list_variant);
1698 if (account_list == NULL)
1699 return ACCOUNT_ERROR_NO_DATA;
1703 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1704 _INFO("iterating received account_list");
1705 account_s *account = NULL;
1706 account = (account_s *)iter->data;
1708 if (callback((account_h)account, user_data) == false) {
1709 _INFO("application callback requested to discontinue.");
1713 _account_gslist_account_free(account_list);
1714 _INFO("account_query_account_by_package_name end");
1715 return ACCOUNT_ERROR_NONE;
1718 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char *capability_type, account_capability_state_e capability_value, void *user_data)
1720 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1722 _INFO("account_query_account_by_capability starting");
1724 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1726 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1727 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1728 return ACCOUNT_ERROR_INVALID_PARAMETER;
1731 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1733 GError *error = NULL;
1735 AccountManager *acc_mgr = _account_manager_get_instance();
1736 if (acc_mgr == NULL) {
1737 _ERR("g_bus_get_sync failed");
1738 return ACCOUNT_ERROR_PERMISSION_DENIED;
1741 uid_t uid = (int)getuid();
1745 GVariant *account_list_variant = NULL;
1746 bool is_success = account_manager_call_account_query_account_by_capability_sync(acc_mgr, capability_type, capability_value, (int)uid, &account_list_variant, NULL, &error);
1747 _account_manager_release_instance();
1749 int error_code = _account_get_error_code(is_success, error);
1750 g_clear_error(&error);
1751 if (error_code != ACCOUNT_ERROR_NONE)
1754 GSList *account_list = unmarshal_account_list(account_list_variant);
1755 g_variant_unref(account_list_variant);
1756 if (account_list == NULL)
1757 return ACCOUNT_ERROR_NO_DATA;
1761 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1762 _INFO("iterating received account_list");
1763 account_s *account = NULL;
1764 account = (account_s *)iter->data;
1766 if (callback((account_h)account, user_data) == false) {
1767 _INFO("application callback requested to discontinue.");
1771 _account_gslist_account_free(account_list);
1772 _INFO("account_query_account_by_capability end");
1773 return ACCOUNT_ERROR_NONE;
1776 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char *capability_type, void *user_data)
1778 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1780 _INFO("account_query_account_by_capability_type starting");
1782 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1783 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1785 GError *error = NULL;
1787 AccountManager *acc_mgr = _account_manager_get_instance();
1788 if (acc_mgr == NULL) {
1789 _ERR("g_bus_get_sync failed");
1790 return ACCOUNT_ERROR_PERMISSION_DENIED;
1793 uid_t uid = (int)getuid();
1797 GVariant *account_list_variant = NULL;
1798 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, capability_type, (int)uid, &account_list_variant, NULL, &error);
1799 _account_manager_release_instance();
1801 int error_code = _account_get_error_code(is_success, error);
1802 g_clear_error(&error);
1803 if (error_code != ACCOUNT_ERROR_NONE)
1806 GSList *account_list = unmarshal_account_list(account_list_variant);
1807 g_variant_unref(account_list_variant);
1809 if (account_list == NULL)
1810 return ACCOUNT_ERROR_NO_DATA;
1814 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1815 _INFO("iterating received account_list");
1816 account_s *account = NULL;
1817 account = (account_s *)iter->data;
1819 if (callback((account_h)account, user_data) == false) {
1820 _INFO("application callback requested to discontinue.");
1824 _account_gslist_account_free(account_list);
1825 _INFO("account_query_account_by_capability end");
1826 return ACCOUNT_ERROR_NONE;
1829 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1831 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1833 _INFO("account_query_capability_by_account_id starting");
1835 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1836 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1838 GError *error = NULL;
1839 AccountManager *acc_mgr = _account_manager_get_instance();
1840 if (acc_mgr == NULL) {
1841 _ERR("g_bus_get_sync failed");
1842 return ACCOUNT_ERROR_PERMISSION_DENIED;
1845 uid_t uid = (int)getuid();
1849 GVariant *capability_list_variant = NULL;
1850 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_id, (int)uid, &capability_list_variant, NULL, &error);
1851 _account_manager_release_instance();
1853 int error_code = _account_get_error_code(is_success, error);
1854 g_clear_error(&error);
1855 if (error_code != ACCOUNT_ERROR_NONE)
1858 GSList *capability_list = unmarshal_capability_list(capability_list_variant);
1859 g_variant_unref(capability_list_variant);
1861 if (capability_list == NULL)
1862 return ACCOUNT_ERROR_NO_DATA;
1866 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter)) {
1867 _INFO("iterating received account_list");
1868 account_capability_s *capability = NULL;
1869 capability = (account_capability_s *)iter->data;
1870 if (callback(capability->type, capability->value, user_data) == false) {
1871 _INFO("application callback requested to discontinue.");
1876 _account_gslist_capability_free(capability_list);
1877 _INFO("account_query_capability_by_account_id end");
1878 return ACCOUNT_ERROR_NONE;
1881 static int _account_get_total_count(int *count, bool include_hidden)
1883 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1885 _INFO("account_get_total_count_from_db starting");
1888 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1889 return ACCOUNT_ERROR_INVALID_PARAMETER;
1892 GError *error = NULL;
1894 AccountManager *acc_mgr = _account_manager_get_instance();
1895 if (acc_mgr == NULL) {
1896 _ERR("g_bus_get_sync failed");
1897 return ACCOUNT_ERROR_PERMISSION_DENIED;
1900 int temp_count = -1;
1901 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, include_hidden, (int)getuid(), &temp_count, NULL, &error);
1902 _account_manager_release_instance();
1904 int error_code = _account_get_error_code(is_success, error);
1905 g_clear_error(&error);
1906 if (error_code != ACCOUNT_ERROR_NONE)
1909 *count = temp_count;
1910 _INFO("account_get_total_count_from_db end");
1911 return ACCOUNT_ERROR_NONE;
1914 ACCOUNT_API int account_get_total_count_from_db(int *count)
1916 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1918 _INFO("account_get_total_count_from_db starting");
1920 return _account_get_total_count(count, true);
1923 ACCOUNT_INTERNAL_API int account_get_total_count_from_db_ex(int *count)
1925 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1927 _INFO("account_get_total_count_from_db_ex starting");
1929 return _account_get_total_count(count, false);
1932 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1934 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1936 _INFO("account_update_sync_status_by_id starting");
1937 int error_code = ACCOUNT_ERROR_NONE;
1939 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1940 if (((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1941 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1942 return ACCOUNT_ERROR_INVALID_PARAMETER;
1945 GError *error = NULL;
1947 AccountManager *acc_mgr = _account_manager_get_instance();
1948 if (acc_mgr == NULL) {
1949 _ERR("g_bus_get_sync failed");
1950 return ACCOUNT_ERROR_PERMISSION_DENIED;
1953 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_id, sync_status, (int)getuid(), NULL, &error);
1954 _account_manager_release_instance();
1956 error_code = _account_get_error_code(is_success, error);
1957 g_clear_error(&error);
1963 ACCOUNT_API int account_type_create(account_type_h *account_type)
1965 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1967 if (!account_type) {
1968 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1969 return ACCOUNT_ERROR_INVALID_PARAMETER;
1972 account_type_s *data = (account_type_s *)malloc(sizeof(account_type_s));
1974 ACCOUNT_ERROR("Memory Allocation Failed");
1975 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1978 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1981 data->app_id = NULL;
1982 data->service_provider_id = NULL;
1983 data->icon_path = NULL;
1984 data->small_icon_path = NULL;
1985 data->multiple_account_support = false;
1986 data->label_list = NULL;
1987 data->provider_feature_list = NULL;
1989 *account_type = (account_type_h)data;
1991 return ACCOUNT_ERROR_NONE;
1994 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1996 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
1998 _INFO("account_type_destroy");
2000 account_type_s *data = (account_type_s *)account_type;
2003 _ERR("Account type handle is null!");
2004 return ACCOUNT_ERROR_INVALID_PARAMETER;
2007 _account_type_free_account_type_with_items(data);
2009 return ACCOUNT_ERROR_NONE;
2012 ACCOUNT_INTERNAL_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
2014 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2016 if (!account_type) {
2017 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
2018 return ACCOUNT_ERROR_INVALID_PARAMETER;
2021 if (!app_id || strlen(app_id) <= 0) {
2022 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL or Empty.\n", __FUNCTION__, __LINE__);
2023 return ACCOUNT_ERROR_INVALID_PARAMETER;
2026 account_type_s *data = (account_type_s *)account_type;
2028 _ACCOUNT_FREE(data->app_id);
2029 data->app_id = _account_get_text(app_id);
2030 if (data->app_id == NULL) {
2031 ACCOUNT_ERROR("OUT OF MEMORY\n");
2032 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2035 return ACCOUNT_ERROR_NONE;
2038 ACCOUNT_INTERNAL_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
2040 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2043 return ACCOUNT_ERROR_INVALID_PARAMETER;
2045 if (!service_provider_id || strlen(service_provider_id) <= 0)
2046 return ACCOUNT_ERROR_INVALID_PARAMETER;
2048 account_type_s *data = (account_type_s *)account_type;
2050 _ACCOUNT_FREE(data->service_provider_id);
2051 data->service_provider_id = _account_get_text(service_provider_id);
2052 if (data->service_provider_id == NULL) {
2053 ACCOUNT_ERROR("OUT OF MEMORY\n");
2054 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2057 return ACCOUNT_ERROR_NONE;
2060 ACCOUNT_INTERNAL_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
2062 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2065 return ACCOUNT_ERROR_INVALID_PARAMETER;
2067 if (!icon_path || strlen(icon_path) <= 0)
2068 return ACCOUNT_ERROR_INVALID_PARAMETER;
2070 account_type_s *data = (account_type_s *)account_type;
2072 _ACCOUNT_FREE(data->icon_path);
2073 data->icon_path = _account_get_text(icon_path);
2074 if (data->icon_path == NULL) {
2075 ACCOUNT_ERROR("OUT OF MEMORY\n");
2076 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2079 return ACCOUNT_ERROR_NONE;
2082 ACCOUNT_INTERNAL_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
2084 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2087 return ACCOUNT_ERROR_INVALID_PARAMETER;
2089 if (!small_icon_path || strlen(small_icon_path) <= 0)
2090 return ACCOUNT_ERROR_INVALID_PARAMETER;
2092 account_type_s *data = (account_type_s *)account_type;
2094 _ACCOUNT_FREE(data->small_icon_path);
2095 data->small_icon_path = _account_get_text(small_icon_path);
2096 if (data->small_icon_path == NULL) {
2097 ACCOUNT_ERROR("OUT OF MEMORY\n");
2098 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2101 return ACCOUNT_ERROR_NONE;
2104 ACCOUNT_INTERNAL_API int account_type_set_multiple_account_support(account_type_h account_type, bool multiple_account_support)
2106 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2108 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
2110 account_type_s *data = (account_type_s *)account_type;
2112 data->multiple_account_support = multiple_account_support;
2114 return ACCOUNT_ERROR_NONE;
2117 ACCOUNT_INTERNAL_API int account_type_set_label(account_type_h account_type, const char *label, const char *locale)
2119 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2121 if (!account_type) {
2122 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
2123 return ACCOUNT_ERROR_INVALID_PARAMETER;
2126 if (!label || !locale || strlen(label) <= 0 || strlen(locale) <= 0)
2127 return ACCOUNT_ERROR_INVALID_PARAMETER;
2129 account_type_s *data = (account_type_s *)account_type;
2130 label_s *label_data = (label_s *)malloc(sizeof(label_s));
2131 if (label_data == NULL) {
2132 ACCOUNT_ERROR("Memory Allocation Failed");
2133 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2136 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
2138 label_data->label = _account_get_text(label);
2139 if (label_data->label == NULL) {
2140 ACCOUNT_ERROR("OUT OF MEMORY\n");
2141 _ACCOUNT_FREE(label_data);
2142 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2145 label_data->locale = _account_get_text(locale);
2146 if (label_data->locale == NULL) {
2147 ACCOUNT_ERROR("OUT OF MEMORY\n");
2148 _ACCOUNT_FREE(label_data->label);
2149 _ACCOUNT_FREE(label_data);
2150 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2153 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
2155 return ACCOUNT_ERROR_NONE;
2158 ACCOUNT_INTERNAL_API int account_type_set_provider_feature(account_type_h account_type, const char *provider_feature)
2160 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2162 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
2163 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
2164 ACCOUNT_RETURN_VAL((strlen(provider_feature) > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is Empty"));
2166 account_type_s *data = (account_type_s *)account_type;
2168 GSList *iter = NULL;
2169 bool b_is_new = TRUE;
2171 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2172 provider_feature_s *feature_data = NULL;
2173 feature_data = (provider_feature_s *)iter->data;
2175 if (!strcmp(feature_data->key, provider_feature)) {
2182 provider_feature_s* feature_data = (provider_feature_s *)malloc(sizeof(provider_feature_s));
2183 if (feature_data == NULL) {
2184 ACCOUNT_ERROR("Memory Allocation Failed");
2185 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2188 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
2190 feature_data->key = _account_get_text(provider_feature);
2191 if (feature_data->key == NULL) {
2192 ACCOUNT_ERROR("OUT OF MEMORY\n");
2193 _ACCOUNT_FREE(feature_data);
2194 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2197 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
2200 return ACCOUNT_ERROR_NONE;
2203 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char *app_id, void *user_data)
2205 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2207 _INFO("account_type_query_provider_feature_by_app_id start");
2209 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2210 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2212 GError *error = NULL;
2213 gint error_code = ACCOUNT_ERROR_NONE;
2215 AccountManager *acc_mgr = _account_manager_get_instance();
2216 if (acc_mgr == NULL) {
2217 _ERR("g_bus_get_sync failed");
2218 return ACCOUNT_ERROR_PERMISSION_DENIED;
2221 GVariant *feature_list_variant = NULL;
2222 bool is_success = account_manager_call_account_type_query_provider_feature_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &feature_list_variant, NULL, &error);
2223 _account_manager_release_instance();
2225 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
2228 error_code = _account_get_error_code(is_success, error);
2229 g_clear_error(&error);
2230 _ERR("Account IPC call returned error[%d]", error_code);
2233 g_clear_error(&error);
2235 GSList *provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
2236 if (provider_feature_list == NULL) {
2237 error_code = ACCOUNT_ERROR_NO_DATA;
2238 _ERR("[%d]", error_code);
2243 for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2244 provider_feature_s *feature_data = NULL;
2246 feature_data = (provider_feature_s *)iter->data;
2248 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
2249 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2250 return ACCOUNT_ERROR_NONE;
2254 _account_type_gslist_feature_free(provider_feature_list);
2255 _INFO("account_type_query_provider_feature_by_app_id end");
2259 ACCOUNT_API bool account_type_query_supported_feature(const char *app_id, const char *capability)
2261 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2263 _INFO("account_type_query_supported_feature start");
2265 if (app_id == NULL || capability == NULL) {
2266 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2270 int is_supported = 0;
2271 GError *error = NULL;
2272 gint ret = ACCOUNT_ERROR_NONE;
2274 AccountManager *acc_mgr = _account_manager_get_instance();
2275 if (acc_mgr == NULL) {
2276 _ERR("g_bus_get_sync failed");
2277 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2281 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, app_id, capability, (int)getuid(), &is_supported, NULL, &error);
2282 _account_manager_release_instance();
2284 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2287 ret = _account_get_error_code(is_success, error);
2288 g_clear_error(&error);
2289 _ERR("Account IPC call returned error[%d]", ret);
2290 set_last_result(ret);
2293 g_clear_error(&error);
2295 set_last_result(ACCOUNT_ERROR_NONE);
2296 _INFO("account_type_query_supported_feature end");
2297 return is_supported;
2300 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2302 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2305 return ACCOUNT_ERROR_INVALID_PARAMETER;
2308 return ACCOUNT_ERROR_INVALID_PARAMETER;
2310 account_type_s *data = (account_type_s *)account_type;
2313 *app_id = _account_get_text(data->app_id);
2314 if (*app_id == NULL) {
2315 ACCOUNT_ERROR("OUT OF MEMORY\n");
2316 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2319 return ACCOUNT_ERROR_NONE;
2322 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2324 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2327 return ACCOUNT_ERROR_INVALID_PARAMETER;
2329 if (!service_provider_id)
2330 return ACCOUNT_ERROR_INVALID_PARAMETER;
2332 account_type_s *data = (account_type_s *)account_type;
2334 (*service_provider_id) = NULL;
2335 *service_provider_id = _account_get_text(data->service_provider_id);
2336 if (*service_provider_id == NULL) {
2337 ACCOUNT_ERROR("OUT OF MEMORY\n");
2338 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2341 return ACCOUNT_ERROR_NONE;
2344 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2346 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2349 return ACCOUNT_ERROR_INVALID_PARAMETER;
2352 return ACCOUNT_ERROR_INVALID_PARAMETER;
2354 account_type_s *data = (account_type_s *)account_type;
2356 (*icon_path) = NULL;
2357 *icon_path = _account_get_text(data->icon_path);
2358 if (*icon_path == NULL) {
2359 ACCOUNT_ERROR("OUT OF MEMORY\n");
2360 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2363 return ACCOUNT_ERROR_NONE;
2366 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2368 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2371 return ACCOUNT_ERROR_INVALID_PARAMETER;
2373 if (!small_icon_path)
2374 return ACCOUNT_ERROR_INVALID_PARAMETER;
2376 account_type_s *data = (account_type_s *)account_type;
2378 (*small_icon_path) = NULL;
2379 *small_icon_path = _account_get_text(data->small_icon_path);
2380 if (*small_icon_path == NULL) {
2381 ACCOUNT_ERROR("OUT OF MEMORY\n");
2382 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2386 return ACCOUNT_ERROR_NONE;
2389 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2391 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2394 return ACCOUNT_ERROR_INVALID_PARAMETER;
2396 if (!multiple_account_support)
2397 return ACCOUNT_ERROR_INVALID_PARAMETER;
2399 account_type_s *data = (account_type_s *)account_type;
2401 *multiple_account_support = data->multiple_account_support;
2403 return ACCOUNT_ERROR_NONE;
2406 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void *user_data)
2408 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2410 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2411 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2414 account_type_s *data = (account_type_s *)account_type;
2416 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2417 provider_feature_s *feature_data = NULL;
2419 feature_data = (provider_feature_s *)iter->data;
2421 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
2422 ACCOUNT_DEBUG("Callback func returns FALSE, its iteration is stopped!!!!\n");
2423 return ACCOUNT_ERROR_NONE;
2427 return ACCOUNT_ERROR_NONE;
2430 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char *locale, char **label)
2432 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2434 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2435 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2438 account_type_s *data = (account_type_s *)account_type;
2440 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2441 label_s *label_data = NULL;
2443 label_data = (label_s *)iter->data;
2447 if (!strcmp(locale, label_data->locale)) {
2448 *label = _account_get_text(label_data->label);
2449 if (*label == NULL) {
2450 ACCOUNT_ERROR("OUT OF MEMORY\n");
2451 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2454 return ACCOUNT_ERROR_NONE;
2456 gchar **tokens = g_strsplit(locale, "-", 2);
2458 if (tokens != NULL) {
2459 if ((char *)(tokens[1]) != NULL) {
2460 char *upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2461 if (upper_token == NULL) {
2462 ACCOUNT_ERROR("Memory Allocation Failed");
2464 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2467 if (upper_token != NULL) {
2468 char *converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2469 if (converted_locale == NULL) {
2470 ACCOUNT_ERROR("Memory Allocation Failed");
2471 _ACCOUNT_FREE(upper_token);
2473 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2476 if (!strcmp(converted_locale, label_data->locale)) {
2477 _ACCOUNT_FREE(converted_locale);
2478 _ACCOUNT_FREE(upper_token);
2480 *label = _account_get_text(label_data->label);
2481 if (*label == NULL) {
2482 ACCOUNT_ERROR("OUT OF MEMORY\n");
2483 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2486 return ACCOUNT_ERROR_NONE;
2488 _ACCOUNT_FREE(converted_locale);
2490 _ACCOUNT_FREE(upper_token);
2496 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2499 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2501 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2503 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2504 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2507 account_type_s *data = (account_type_s *)account_type;
2509 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2510 label_s *label_data = NULL;
2512 label_data = (label_s *)iter->data;
2514 if (callback(label_data->app_id, label_data->label, label_data->locale, user_data) != TRUE) {
2515 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2516 return ACCOUNT_ERROR_NONE;
2520 return ACCOUNT_ERROR_NONE;
2523 ACCOUNT_INTERNAL_API int account_type_insert_to_db(account_type_h account_type, int *account_type_id)
2525 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2527 _INFO("account_type_insert_to_db starting");
2529 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2530 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2532 GError *error = NULL;
2534 AccountManager *acc_mgr = _account_manager_get_instance();
2535 if (acc_mgr == NULL) {
2536 _ERR("g_bus_get_sync failed");
2537 return ACCOUNT_ERROR_PERMISSION_DENIED;
2541 GVariant *account_type_serialized = marshal_account_type((account_type_s *)account_type);
2544 if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
2545 _ERR("pkgmgr_installer_info_get_target_uid() fail");
2546 return ACCOUNT_ERROR_DB_NOT_OPENED;
2549 /* Workaround for internal UTC */
2553 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_type_serialized, (int)uid, &db_id, NULL, &error);
2554 _account_manager_release_instance();
2556 int ret = _account_get_error_code(is_success, error);
2557 g_clear_error(&error);
2559 if (ret != ACCOUNT_ERROR_NONE)
2562 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2564 *account_type_id = db_id;
2566 account_type_s *account_type_data = (account_type_s *)account_type;
2567 account_type_data->id = db_id;
2569 return ACCOUNT_ERROR_NONE;
2572 ACCOUNT_INTERNAL_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char *app_id)
2574 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2576 _INFO("account_type_update_to_db_by_app_id starting");
2577 int error_code = ACCOUNT_ERROR_NONE;
2579 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2580 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2582 GError *error = NULL;
2584 AccountManager *acc_mgr = _account_manager_get_instance();
2585 if (acc_mgr == NULL) {
2586 _ERR("g_bus_get_sync failed");
2587 return ACCOUNT_ERROR_PERMISSION_DENIED;
2590 GVariant *account_type_variant = marshal_account_type((account_type_s *)account_type);
2591 if (account_type_variant == NULL) {
2592 _ERR("Failed to serialize");
2593 _account_manager_release_instance();
2594 return ACCOUNT_ERROR_INVALID_PARAMETER;
2597 bool is_success = account_manager_call_account_type_update_to_db_by_app_id_sync(acc_mgr, account_type_variant, app_id, (int)getuid(), NULL, &error);
2598 _account_manager_release_instance();
2600 error_code = _account_get_error_code(is_success, error);
2601 g_clear_error(&error);
2606 ACCOUNT_INTERNAL_API int account_type_delete_by_app_id(const char *app_id)
2608 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2610 _INFO("account_type_delete_by_app_id starting");
2611 int error_code = ACCOUNT_ERROR_NONE;
2613 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2615 GError *error = NULL;
2617 AccountManager *acc_mgr = _account_manager_get_instance();
2618 if (acc_mgr == NULL) {
2619 _ERR("g_bus_get_sync failed");
2620 return ACCOUNT_ERROR_PERMISSION_DENIED;
2624 if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
2625 _ERR("pkgmgr_installer_info_get_target_uid() fail");
2626 return ACCOUNT_ERROR_DB_NOT_OPENED;
2629 /* Workaround for internal UTC */
2633 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, app_id, (int)uid, NULL, &error);
2634 _account_manager_release_instance();
2636 error_code = _account_get_error_code(is_success, error);
2637 g_clear_error(&error);
2642 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char *app_id, void *user_data)
2644 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2646 _INFO("account_type_query_label_by_app_id starting");
2648 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2649 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2651 GError *error = NULL;
2653 AccountManager *acc_mgr = _account_manager_get_instance();
2654 if (acc_mgr == NULL) {
2655 _ERR("g_bus_get_sync failed");
2656 return ACCOUNT_ERROR_PERMISSION_DENIED;
2659 GVariant *label_list_variant = NULL;
2660 bool is_success = account_manager_call_account_type_query_label_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &label_list_variant, NULL, &error);
2661 _account_manager_release_instance();
2663 int ret = _account_get_error_code(is_success, error);
2664 g_clear_error(&error);
2666 if (ret != ACCOUNT_ERROR_NONE)
2669 GSList *label_list = variant_to_label_list(label_list_variant);
2670 if (label_list == NULL)
2671 return ACCOUNT_ERROR_NO_DATA;
2675 for (iter = label_list; iter != NULL; iter = g_slist_next(iter)) {
2676 _INFO("iterating received account_list");
2677 label_s *label_record = NULL;
2678 label_record = (label_s *)iter->data;
2679 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false) {
2680 _INFO("application callback requested to discontinue.");
2685 _account_type_gslist_label_free(label_list);
2686 _INFO("account_type_query_label_by_app_id end");
2687 return ACCOUNT_ERROR_NONE;
2690 ACCOUNT_API int account_type_query_by_app_id(const char *app_id, account_type_h *account_type)
2692 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2694 _INFO("account_type_query_by_app_id starting");
2696 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2697 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2698 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2700 GError *error = NULL;
2702 AccountManager *acc_mgr = _account_manager_get_instance();
2703 if (acc_mgr == NULL) {
2704 _ERR("g_bus_get_sync failed");
2705 return ACCOUNT_ERROR_PERMISSION_DENIED;
2708 GVariant *account_type_variant = NULL;
2709 account_type_s *in_data = (account_type_s *)*account_type;
2711 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &account_type_variant, NULL, &error);
2712 _account_manager_release_instance();
2714 int ret = _account_get_error_code(is_success, error);
2715 g_clear_error(&error);
2717 if (ret != ACCOUNT_ERROR_NONE)
2720 account_type_s *received_account_type = umarshal_account_type(account_type_variant);
2721 g_variant_unref(account_type_variant);
2722 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2724 in_data->id = received_account_type->id;
2725 in_data->app_id = received_account_type->app_id;
2726 in_data->service_provider_id = received_account_type->service_provider_id;
2727 in_data->icon_path = received_account_type->icon_path;
2728 in_data->small_icon_path = received_account_type->small_icon_path;
2729 in_data->multiple_account_support = received_account_type->multiple_account_support;
2730 in_data->label_list = received_account_type->label_list;
2731 in_data->provider_feature_list = received_account_type->provider_feature_list;
2733 _ACCOUNT_FREE(received_account_type);
2734 _INFO("account_type_query_by_app_id end");
2735 return ACCOUNT_ERROR_NONE;
2738 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2740 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2742 _INFO("account_type_foreach_account_type_from_db starting");
2744 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2746 GError *error = NULL;
2748 AccountManager *acc_mgr = _account_manager_get_instance();
2749 if (acc_mgr == NULL) {
2750 _ERR("g_bus_get_sync failed");
2751 return ACCOUNT_ERROR_PERMISSION_DENIED;
2754 GVariant *account_type_list_variant = NULL;
2755 _INFO("before account_type_query_all_sync()");
2756 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, (int)getuid(), &account_type_list_variant, NULL, &error);
2757 _account_manager_release_instance();
2759 _INFO("after account_type_query_all_sync()");
2760 int ret = _account_get_error_code(is_success, error);
2761 g_clear_error(&error);
2763 if (ret != ACCOUNT_ERROR_NONE)
2766 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2767 g_variant_unref(account_type_list_variant);
2769 if (account_type_list == NULL)
2770 return ACCOUNT_ERROR_NO_DATA;
2774 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2775 _INFO("iterating received account_list");
2776 account_type_s *account_type = NULL;
2777 account_type = (account_type_s *)iter->data;
2779 if (callback((account_type_h)account_type, user_data) == false) {
2780 _INFO("application callback requested to discontinue.");
2785 _account_type_gslist_account_type_free(account_type_list);
2786 _INFO("account_type_foreach_account_type_from_db end");
2787 return ACCOUNT_ERROR_NONE;
2790 ACCOUNT_API int account_type_query_label_by_locale(const char *app_id, const char *locale, char **label)
2792 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2794 _INFO("account_type_query_label_by_locale starting");
2796 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2797 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2798 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2800 GError *error = NULL;
2802 AccountManager *acc_mgr = _account_manager_get_instance();
2803 if (acc_mgr == NULL) {
2804 _ERR("g_bus_get_sync failed");
2805 return ACCOUNT_ERROR_PERMISSION_DENIED;
2808 char *label_temp = NULL;
2809 _INFO("before account_type_query_label_by_locale_sync()");
2810 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, app_id, locale, (int)getuid(), &label_temp, NULL, &error);
2811 _account_manager_release_instance();
2813 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2814 int ret = _account_get_error_code(is_success, error);
2815 g_clear_error(&error);
2817 if (ret != ACCOUNT_ERROR_NONE)
2820 if (label_temp == NULL)
2821 return ACCOUNT_ERROR_NO_DATA;
2824 *label = _account_get_text(label_temp);
2825 if (*label == NULL) {
2826 ACCOUNT_ERROR("OUT OF MEMORY\n");
2827 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2830 _INFO("account_type_query_label_by_locale end");
2831 return ACCOUNT_ERROR_NONE;
2835 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char *key, void *user_data)
2837 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2839 _INFO("account_type_query_by_provider_feature starting");
2841 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2842 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2844 GError *error = NULL;
2846 AccountManager *acc_mgr = _account_manager_get_instance();
2847 if (acc_mgr == NULL) {
2848 _ERR("g_bus_get_sync failed");
2849 return ACCOUNT_ERROR_PERMISSION_DENIED;
2852 GVariant *account_type_list_variant = NULL;
2853 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, key, (int)getuid(), &account_type_list_variant, NULL, &error);
2854 _account_manager_release_instance();
2856 int ret = _account_get_error_code(is_success, error);
2857 g_clear_error(&error);
2859 if (ret != ACCOUNT_ERROR_NONE)
2862 _INFO("before unmarshal_account_type_list");
2863 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2864 g_variant_unref(account_type_list_variant);
2866 if (account_type_list == NULL)
2867 return ACCOUNT_ERROR_NO_DATA;
2871 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2872 _INFO("iterating received account_type_list");
2873 account_type_s *account_type = NULL;
2874 account_type = (account_type_s *)iter->data;
2876 if (callback((account_type_h)account_type, user_data) == false) {
2877 _INFO("Application callback requested not to continue");
2883 _account_type_gslist_account_type_free(account_type_list);
2884 _INFO("account_type_query_by_provider_feature end");
2885 return ACCOUNT_ERROR_NONE;
2888 ACCOUNT_API int account_type_query_app_id_exist(const char *app_id)
2890 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2892 _INFO("account_type_query_app_id_exist starting");
2893 int error_code = ACCOUNT_ERROR_NONE;
2895 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2897 GError *error = NULL;
2899 AccountManager *acc_mgr = _account_manager_get_instance();
2900 if (acc_mgr == NULL) {
2901 _ERR("g_bus_get_sync failed");
2902 return ACCOUNT_ERROR_PERMISSION_DENIED;
2905 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2906 _account_manager_release_instance();
2908 error_code = _account_get_error_code(is_success, error);
2909 g_clear_error(&error);
2915 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2917 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2918 char *msg = NULL, *vconf_key = NULL;
2919 const char *key_name = NULL;
2920 char event_msg[256] = {0, };
2921 int account_id = -1;
2924 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2929 ACCOUNT_ERROR("user data required\n");
2933 key_name = vconf_keynode_get_name(key);
2935 if (key_name == NULL) {
2936 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2940 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2941 vconf_key = vconf_keynode_get_str(key);
2943 if (vconf_key == NULL) {
2944 ACCOUNT_ERROR("vconf key is NULL.\n");
2948 msg = strdup(vconf_key);
2950 ACCOUNT_ERROR("Memory Allocation Failed");
2954 char *event_type = NULL;
2958 event_type = strtok_r(msg, ":", &ptr);
2959 if (event_type == NULL) {
2960 ACCOUNT_ERROR("strtok_r() failed");
2964 id = strtok_r(NULL, ":", &ptr);
2966 ACCOUNT_ERROR("strtok_r() failed");
2970 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2972 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2974 account_id = atoi(id);
2976 if (tmp->account_subscription_callback)
2977 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2984 ACCOUNT_API int account_subscribe_create(account_subscribe_h *account_subscribe)
2986 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
2988 if (!account_subscribe) {
2989 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2990 return ACCOUNT_ERROR_INVALID_PARAMETER;
2993 account_subscribe_s *data = (account_subscribe_s *)calloc(1, sizeof(account_subscribe_s));
2995 ACCOUNT_ERROR("OUT OF MEMORY\n");
2996 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2999 *account_subscribe = (account_subscribe_h)data;
3001 return ACCOUNT_ERROR_NONE;
3004 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
3006 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
3008 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
3010 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
3012 tmp->account_subscription_callback = callback;
3013 tmp->user_data = user_data;
3016 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
3017 (vconf_callback_fn)_account_subscribe_vconf_callback,
3020 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
3022 if (ret != VCONF_OK) {
3023 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
3024 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
3027 return ACCOUNT_ERROR_NONE;
3030 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
3032 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
3034 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
3036 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
3040 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
3041 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
3042 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
3043 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
3046 return ACCOUNT_ERROR_NONE;
3049 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
3051 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
3052 char *msg = NULL, *vconf_key = NULL;
3053 char event_msg[256] = {0, };
3054 int account_id = -1;
3055 const char *key_name = NULL;
3058 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
3063 ACCOUNT_ERROR("user data required\n");
3067 key_name = vconf_keynode_get_name(key);
3069 if (key_name == NULL) {
3070 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
3074 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
3075 vconf_key = vconf_keynode_get_str(key);
3077 if (vconf_key == NULL) {
3078 ACCOUNT_ERROR("vconf key is NULL.\n");
3081 msg = strdup(vconf_key);
3083 ACCOUNT_ERROR("Memory Allocation Failed");
3087 char *event_type = NULL;
3091 event_type = strtok_r(msg, ":", &ptr);
3092 if (event_type == NULL) {
3093 ACCOUNT_ERROR("event_type is NULL");
3097 id = strtok_r(NULL, ":", &ptr);
3099 ACCOUNT_ERROR("account-id is NULL");
3103 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
3105 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
3107 account_id = atoi(id);
3109 if (tmp->account_subscription_callback)
3110 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
3118 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
3120 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
3122 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
3124 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
3128 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
3129 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
3130 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
3131 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
3134 return ACCOUNT_ERROR_NONE;
3137 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
3139 CHECK_ACCOUNT_SUPPORTED(ACCOUNT_FEATURE);
3141 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
3143 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
3145 tmp->account_subscription_callback = callback;
3146 tmp->user_data = user_data;
3149 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
3150 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
3153 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
3155 if (ret != VCONF_OK) {
3156 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
3157 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
3160 return ACCOUNT_ERROR_NONE;