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>
30 #include <account-private.h>
31 #include <account_free.h>
32 #include <account_ipc_marshal.h>
33 #include <account-mgr-stub.h>
35 #ifdef TIZEN_PROFILE_MOBILE
36 #include "mobile/account.h"
38 #include "wearable/account.h"
41 #include "account-error.h"
42 #include "account-types.h"
43 #include "account_internal.h"
44 #include "account_private_client.h"
46 #define ACCOUNT_DB_OPEN_READONLY 0
47 #define ACCOUNT_DB_OPEN_READWRITE 1
51 static AccountManager *_acc_mgr = NULL;
53 static char *_account_get_text(const char *text_data)
55 char *text_value = NULL;
57 if (text_data != NULL)
58 text_value = strdup(text_data);
64 _account_manager_get_instance()
66 _INFO("_account_manager_get_instance");
67 if (_acc_mgr != NULL) {
68 _INFO("instance already created.");
72 #if !GLIB_CHECK_VERSION(2, 35, 0)
76 GDBusConnection *connection = NULL;
79 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
81 _INFO("after g_bus_get_sync");
85 _ERR("Unable to connect to gdbus: %s", error->message);
86 g_clear_error(&error);
91 g_clear_error(&error);
93 /* Create the object */
95 account_manager_proxy_new_sync(connection,
96 G_DBUS_PROXY_FLAGS_NONE,
97 "org.tizen.account.manager",
98 "/org/tizen/account/manager",
104 _ERR("Unable account_manager_proxy_new_sync: %s", error->message);
105 g_clear_error(&error);
108 g_object_unref(connection);
112 g_clear_error(&error);
113 _INFO("_account_manager_get_instance end");
117 GDBusErrorEntry _account_svc_errors[] = {
118 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
119 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
120 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
121 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
122 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
123 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
124 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
125 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
126 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
127 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
128 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
129 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
130 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
131 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
132 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
133 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
134 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
135 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
138 static int _account_get_error_code(bool is_success, GError *error)
141 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
143 if (g_dbus_error_is_remote_error(error)) {
144 gchar *remote_error = g_dbus_error_get_remote_error(error);
146 _INFO("Remote error[%s]", remote_error);
148 /* FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
149 However error->message matches, so doing reverse lookup */
150 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
152 for (i = 0; i < error_enum_count; i++) {
153 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0) {
154 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
155 g_free(remote_error);
156 return _account_svc_errors[i].error_code;
159 g_free(remote_error);
162 /* All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED */
163 return ACCOUNT_ERROR_PERMISSION_DENIED;
165 return ACCOUNT_ERROR_NONE;
168 #ifdef TIZEN_PROFILE_MOBILE
169 ACCOUNT_API int account_connect(void)
171 return ACCOUNT_ERROR_NONE;
174 ACCOUNT_API int account_connect_readonly(void)
176 return ACCOUNT_ERROR_NONE;
179 ACCOUNT_API int account_disconnect(void)
181 return ACCOUNT_ERROR_NONE;
186 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
188 _INFO("1. account_insert_to_db start");
190 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
191 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
193 account_s *account_data = (account_s *)account;
194 int error_code = ACCOUNT_ERROR_NONE;
195 GError *error = NULL;
197 _INFO("2. Before _account_manager_get_instance()");
198 AccountManager *acc_mgr = _account_manager_get_instance();
199 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
202 GVariant *account_serialized = marshal_account(account_data);
204 _INFO("3. Before account_manager_call_account_add_sync");
205 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_serialized, (int)getuid(), &db_id, NULL, &error);
206 g_variant_unref(account_serialized);
208 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
209 g_clear_error(&error);
211 *account_db_id = db_id;
212 account_data->id = db_id;
214 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
216 return ACCOUNT_ERROR_NONE;
219 g_clear_error(&error);
220 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
225 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
227 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
228 int error_code = ACCOUNT_ERROR_NONE;
230 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
232 GError *error = NULL;
234 AccountManager *acc_mgr = _account_manager_get_instance();
235 if (acc_mgr == NULL) {
236 _ERR("g_bus_get_sync failed");
237 return ACCOUNT_ERROR_PERMISSION_DENIED;
240 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
241 GVariant *account_serialized_old = NULL;
242 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)getuid(), &account_serialized_old, NULL, &error);
245 error_code = _account_get_error_code(is_success, error);
246 g_clear_error(&error);
247 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
250 g_clear_error(&error);
252 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
253 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_id, (int)getuid(), NULL, &error);
256 error_code = _account_get_error_code(is_success, error);
257 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error_code);
258 g_clear_error(&error);
261 g_clear_error(&error);
263 _INFO("4. Before account_delete_from_db_by_id end");
264 return ACCOUNT_ERROR_NONE;
267 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
269 int error_code = ACCOUNT_ERROR_NONE;
270 _INFO("account_delete_from_db_by_user_name start");
272 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
273 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
276 GError *error = NULL;
278 AccountManager *acc_mgr = _account_manager_get_instance();
279 if (acc_mgr == NULL) {
280 _ERR("g_bus_get_sync failed");
281 return ACCOUNT_ERROR_PERMISSION_DENIED;
284 GVariant *account_list_variant = NULL;
285 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
287 error_code = _account_get_error_code(is_success, error);
288 g_clear_error(&error);
289 if (error_code != ACCOUNT_ERROR_NONE) {
290 _ERR("account_query_account_by_user_name error=[%d]", error_code);
294 GSList *account_list = unmarshal_account_list(account_list_variant);
295 g_variant_unref(account_list_variant);
297 if (account_list == NULL)
298 return ACCOUNT_ERROR_NO_DATA;
300 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, user_name, package_name, (int)getuid(), NULL, &error);
303 error_code = _account_get_error_code(is_success, error);
304 g_clear_error(&error);
305 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
306 _account_gslist_account_free(account_list);
309 g_clear_error(&error);
311 _account_gslist_account_free(account_list);
312 return ACCOUNT_ERROR_NONE;
315 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
317 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
318 int error_code = ACCOUNT_ERROR_NONE;
320 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
322 GError *error = NULL;
324 AccountManager *acc_mgr = _account_manager_get_instance();
325 if (acc_mgr == NULL) {
326 _ERR("g_bus_get_sync failed");
327 return ACCOUNT_ERROR_PERMISSION_DENIED;
330 //First get account list of user_name, used for gSSO DB deletion
331 GVariant* account_list_variant = NULL;
332 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);
334 error_code = _account_get_error_code(is_success, error);
335 if (error_code != ACCOUNT_ERROR_NONE)
340 _INFO("before unmarshal_account_list");
341 GSList* account_list = unmarshal_account_list(account_list_variant);
342 _INFO("after unmarshal_account_list");
343 if (account_list == NULL)
345 return ACCOUNT_ERROR_NO_DATA;
348 bool is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, package_name, permission, (int)getuid(), NULL, &error);
351 error_code = _account_get_error_code(is_success, error);
352 g_clear_error(&error);
353 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error_code);
356 g_clear_error(&error);
358 return ACCOUNT_ERROR_NONE;
361 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
363 _INFO("account_delete_from_db_by_package_name starting with permission");
364 return _account_delete_from_db_by_package_name(package_name, true);
367 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
369 _INFO("1. account_update_to_db_by_id start");
370 int error_code = ACCOUNT_ERROR_NONE;
372 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
373 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
375 GError *error = NULL;
377 AccountManager *acc_mgr = _account_manager_get_instance();
378 if (acc_mgr == NULL) {
379 _ERR("g_bus_get_sync failed");
380 return ACCOUNT_ERROR_PERMISSION_DENIED;
383 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
384 GVariant *account_serialized_old = NULL;
385 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &account_serialized_old, NULL, &error);
388 error_code = _account_get_error_code(is_success, error);
389 g_clear_error(&error);
390 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
393 g_clear_error(&error);
395 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
396 GVariant *account_serialized = marshal_account((account_s *)account);
397 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
398 g_variant_unref(account_serialized);
401 error_code = _account_get_error_code(is_success, error);
402 g_clear_error(&error);
403 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error_code);
406 g_clear_error(&error);
408 _INFO("4. account_update_to_db_by_id end");
409 return ACCOUNT_ERROR_NONE;
412 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
415 ret = account_update_to_db_by_id(account, account_id);
420 ACCOUNT_INTERNAL_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
422 _INFO("account_update_to_db_by_id_without_permission start");
423 int error_code = ACCOUNT_ERROR_NONE;
425 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
426 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
428 GError *error = NULL;
430 AccountManager *acc_mgr = _account_manager_get_instance();
431 if (acc_mgr == NULL) {
432 _ERR("g_bus_get_sync failed");
433 return ACCOUNT_ERROR_PERMISSION_DENIED;
436 GVariant *account_serialized_old = NULL;
437 _INFO("before query() account_id[%d]", account_id);
438 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &account_serialized_old, NULL, &error);
441 error_code = _account_get_error_code(is_success, error);
442 g_clear_error(&error);
443 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
446 g_clear_error(&error);
448 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s *)account)->user_name);
449 GVariant *account_serialized = marshal_account((account_s *)account);
450 _INFO("after marshal() : account_id[%d]", account_id);
451 if (account_serialized == NULL) {
452 _ERR("Invalid input");
453 return ACCOUNT_ERROR_INVALID_PARAMETER;
456 _INFO("before call update() : account_id[%d]", account_id);
457 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
458 g_variant_unref(account_serialized);
460 _INFO("after call update() : is_success=%d", is_success);
462 error_code = _account_get_error_code(is_success, error);
463 g_clear_error(&error);
464 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error_code);
467 g_clear_error(&error);
469 return ACCOUNT_ERROR_NONE;
472 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
474 _INFO("account_update_to_db_by_user_name starting");
475 int error_code = ACCOUNT_ERROR_NONE;
477 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
478 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
479 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
481 GError *error = NULL;
483 AccountManager *acc_mgr = _account_manager_get_instance();
484 if (acc_mgr == NULL) {
485 _ERR("g_bus_get_sync failed");
486 return ACCOUNT_ERROR_PERMISSION_DENIED;
489 GVariant *account_serialized_old = NULL;
490 account_s *account_data = (account_s *)account;
491 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_data->id, (int)getuid(), &account_serialized_old, NULL, &error);
494 error_code = _account_get_error_code(is_success, error);
495 g_clear_error(&error);
496 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
499 g_clear_error(&error);
501 GVariant *account_serialized = marshal_account(account_data);
502 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);
503 g_variant_unref(account_serialized);
506 error_code = _account_get_error_code(is_success, error);
507 g_clear_error(&error);
508 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error_code);
511 g_clear_error(&error);
513 return ACCOUNT_ERROR_NONE;
516 ACCOUNT_API int account_create(account_h *account)
518 _INFO("account_create start");
520 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
521 return ACCOUNT_ERROR_INVALID_PARAMETER;
524 account_s *data = (account_s *)malloc(sizeof(account_s));
526 ACCOUNT_FATAL("Memory Allocation Failed");
527 return ACCOUNT_ERROR_OUT_OF_MEMORY;
530 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
532 /* Setting account as visible by default */
533 data->secret = ACCOUNT_SECRECY_VISIBLE;
535 /* Setting account as not supporting sync by default */
536 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
538 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
540 data->capablity_list = NULL;
541 data->custom_list = NULL;
543 *account = (account_h)data;
545 _INFO("account_create end");
546 return ACCOUNT_ERROR_NONE;
549 ACCOUNT_API int account_destroy(account_h account)
551 _INFO("account_destroy start");
552 account_s *data = (account_s *)account;
554 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
556 _account_free_account_with_items(data);
558 _INFO("account_destroy end");
559 return ACCOUNT_ERROR_NONE;
562 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
565 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
566 return ACCOUNT_ERROR_INVALID_PARAMETER;
570 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
571 return ACCOUNT_ERROR_INVALID_PARAMETER;
574 account_s *data = (account_s *)account;
576 _ACCOUNT_FREE(data->user_name);
577 data->user_name = _account_get_text(user_name);
578 if (data->user_name == NULL) {
579 ACCOUNT_FATAL("OUT OF MEMORY\n");
580 return ACCOUNT_ERROR_OUT_OF_MEMORY;
583 return ACCOUNT_ERROR_NONE;
586 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
589 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
590 return ACCOUNT_ERROR_INVALID_PARAMETER;
594 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
595 return ACCOUNT_ERROR_INVALID_PARAMETER;
598 account_s *data = (account_s *)account;
600 _ACCOUNT_FREE(data->display_name);
601 data->display_name = _account_get_text(display_name);
602 if (data->display_name == NULL) {
603 ACCOUNT_FATAL("OUT OF MEMORY\n");
604 return ACCOUNT_ERROR_OUT_OF_MEMORY;
607 return ACCOUNT_ERROR_NONE;
610 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
613 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
614 return ACCOUNT_ERROR_INVALID_PARAMETER;
617 if (!email_address) {
618 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
619 return ACCOUNT_ERROR_INVALID_PARAMETER;
622 account_s *data = (account_s *)account;
624 _ACCOUNT_FREE(data->email_address);
625 data->email_address = _account_get_text(email_address);
626 if (data->email_address == NULL) {
627 ACCOUNT_FATAL("OUT OF MEMORY\n");
628 return ACCOUNT_ERROR_OUT_OF_MEMORY;
631 return ACCOUNT_ERROR_NONE;
634 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
637 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
638 return ACCOUNT_ERROR_INVALID_PARAMETER;
642 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
643 return ACCOUNT_ERROR_INVALID_PARAMETER;
646 account_s *data = (account_s *)account;
648 _ACCOUNT_FREE(data->icon_path);
649 data->icon_path = _account_get_text(icon_path);
650 if (data->icon_path == NULL) {
651 ACCOUNT_FATAL("OUT OF MEMORY\n");
652 return ACCOUNT_ERROR_OUT_OF_MEMORY;
655 return ACCOUNT_ERROR_NONE;
658 ACCOUNT_API int account_set_source(account_h account, const char *source)
661 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
662 return ACCOUNT_ERROR_INVALID_PARAMETER;
666 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
667 return ACCOUNT_ERROR_INVALID_PARAMETER;
669 account_s *data = (account_s *)account;
671 _ACCOUNT_FREE(data->source);
672 data->source = _account_get_text(source);
673 if (data->source == NULL) {
674 ACCOUNT_FATAL("OUT OF MEMORY\n");
675 return ACCOUNT_ERROR_OUT_OF_MEMORY;
678 return ACCOUNT_ERROR_NONE;
681 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
684 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
685 return ACCOUNT_ERROR_INVALID_PARAMETER;
689 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
690 return ACCOUNT_ERROR_INVALID_PARAMETER;
693 account_s *data = (account_s *)account;
695 _ACCOUNT_FREE(data->package_name);
696 data->package_name = _account_get_text(package_name);
697 if (data->package_name == NULL) {
698 ACCOUNT_FATAL("OUT OF MEMORY\n");
699 return ACCOUNT_ERROR_OUT_OF_MEMORY;
702 return ACCOUNT_ERROR_NONE;
705 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
708 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
709 return ACCOUNT_ERROR_INVALID_PARAMETER;
713 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
714 return ACCOUNT_ERROR_INVALID_PARAMETER;
716 account_s *data = (account_s *)account;
718 _ACCOUNT_FREE(data->domain_name);
719 data->domain_name = _account_get_text(domain_name);
720 if (data->domain_name == NULL) {
721 ACCOUNT_FATAL("OUT OF MEMORY\n");
722 return ACCOUNT_ERROR_OUT_OF_MEMORY;
725 return ACCOUNT_ERROR_NONE;
728 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
731 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
732 return ACCOUNT_ERROR_INVALID_PARAMETER;
736 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
737 return ACCOUNT_ERROR_INVALID_PARAMETER;
740 account_s *data = (account_s *)account;
742 _ACCOUNT_FREE(data->access_token);
743 data->access_token = _account_get_text(access_token);
744 if (data->access_token == NULL) {
745 ACCOUNT_FATAL("OUT OF MEMORY\n");
746 return ACCOUNT_ERROR_OUT_OF_MEMORY;
749 return ACCOUNT_ERROR_NONE;
752 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
755 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
756 return ACCOUNT_ERROR_INVALID_PARAMETER;
760 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
761 return ACCOUNT_ERROR_INVALID_PARAMETER;
763 if (idx >= USER_TXT_CNT || idx < 0) {
764 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
765 return ACCOUNT_ERROR_INVALID_PARAMETER;
768 account_s *data = (account_s *)account;
770 _ACCOUNT_FREE(data->user_data_txt[idx]);
771 data->user_data_txt[idx] = _account_get_text(user_txt);
772 if (data->user_data_txt[idx] == NULL) {
773 ACCOUNT_FATAL("OUT OF MEMORY\n");
774 return ACCOUNT_ERROR_OUT_OF_MEMORY;
777 return ACCOUNT_ERROR_NONE;
780 ACCOUNT_API int account_set_custom(account_h account, const char *key, const char *value)
783 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
784 return ACCOUNT_ERROR_INVALID_PARAMETER;
788 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
789 return ACCOUNT_ERROR_INVALID_PARAMETER;
793 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
794 return ACCOUNT_ERROR_INVALID_PARAMETER;
797 account_s *data = (account_s *)account;
800 bool b_is_new = TRUE;
802 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
804 account_custom_s *custom_data = NULL;
805 custom_data = (account_custom_s *)iter->data;
806 ACCOUNT_SLOGD("account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
808 if (!strcmp(custom_data->key, key)) {
809 char *new_value = NULL;
810 new_value = _account_get_text(value);
811 if (new_value == NULL) {
812 ACCOUNT_FATAL("OUT OF MEMORY\n");
813 return ACCOUNT_ERROR_OUT_OF_MEMORY;
816 _ACCOUNT_FREE(custom_data->value);
817 custom_data->value = new_value;
824 int error_code = ACCOUNT_ERROR_NONE;
826 account_custom_s* custom_data = (account_custom_s *)malloc(sizeof(account_custom_s));
827 if (custom_data == NULL) {
828 ACCOUNT_FATAL("Memory Allocation Failed");
829 return ACCOUNT_ERROR_OUT_OF_MEMORY;
832 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
833 custom_data->account_id = data->id;
835 /* custom's app_id field will be automatically filled by account-svc daemon. */
836 /* custom_data->app_id = _account_get_text(data->package_name);
837 if (data->package_name != NULL && custom_data->app_id == NULL) {
838 ACCOUNT_FATAL("OUT OF MEMORY\n");
839 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
842 custom_data->key = _account_get_text(key);
843 if (custom_data->key == NULL) {
844 ACCOUNT_FATAL("OUT OF MEMORY\n");
845 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
848 custom_data->value = _account_get_text(value);
849 if (custom_data->value == NULL) {
850 ACCOUNT_FATAL("OUT OF MEMORY\n");
851 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
854 if (error_code != ACCOUNT_ERROR_NONE) {
855 _ACCOUNT_FREE(custom_data->app_id);
856 _ACCOUNT_FREE(custom_data->key);
857 _ACCOUNT_FREE(custom_data->value);
858 _ACCOUNT_FREE(custom_data);
862 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
865 return ACCOUNT_ERROR_NONE;
868 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
870 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
872 if (((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN))
873 return ACCOUNT_ERROR_INVALID_PARAMETER;
875 account_s *data = (account_s *)account;
877 data->auth_type = (int)auth_type;
879 return ACCOUNT_ERROR_NONE;
882 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
884 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
886 if (((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE))
887 return ACCOUNT_ERROR_INVALID_PARAMETER;
889 account_s *data = (account_s *)account;
891 data->secret = (int)secret;
893 return ACCOUNT_ERROR_NONE;
896 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
898 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
900 if (((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC))
901 return ACCOUNT_ERROR_INVALID_PARAMETER;
903 account_s *data = (account_s *)account;
905 data->sync_support = (int)sync_support;
907 return ACCOUNT_ERROR_NONE;
910 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
913 return ACCOUNT_ERROR_INVALID_PARAMETER;
915 if (idx >= USER_INT_CNT || idx < 0)
916 return ACCOUNT_ERROR_INVALID_PARAMETER;
918 account_s *data = (account_s *)account;
920 data->user_data_int[idx] = user_int;
922 return ACCOUNT_ERROR_NONE;
925 ACCOUNT_API int account_set_capability(account_h account, const char *capability_type, account_capability_state_e capability_value)
927 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
928 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
930 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED))
931 return ACCOUNT_ERROR_INVALID_PARAMETER;
933 account_s *data = (account_s *)account;
936 bool b_is_new = TRUE;
938 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
939 account_capability_s *cap_data = NULL;
940 cap_data = (account_capability_s *)iter->data;
942 if (!strcmp(cap_data->type, capability_type)) {
943 cap_data->value = capability_value;
950 account_capability_s *cap_data = (account_capability_s *)malloc(sizeof(account_capability_s));
951 if (cap_data == NULL) {
952 ACCOUNT_FATAL("Memory Allocation Failed");
953 return ACCOUNT_ERROR_OUT_OF_MEMORY;
956 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
958 cap_data->type = _account_get_text(capability_type);
959 if (cap_data->type == NULL) {
960 ACCOUNT_FATAL("OUT OF MEMORY\n");
961 _ACCOUNT_FREE(cap_data->type);
962 _ACCOUNT_FREE(cap_data);
963 return ACCOUNT_ERROR_OUT_OF_MEMORY;
966 cap_data->value = capability_value;
967 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
970 return ACCOUNT_ERROR_NONE;
973 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
976 return ACCOUNT_ERROR_INVALID_PARAMETER;
979 return ACCOUNT_ERROR_INVALID_PARAMETER;
981 account_s *data = (account_s *)account;
984 *user_name = _account_get_text(data->user_name);
985 if (data->user_name != NULL && *user_name == NULL) {
986 ACCOUNT_FATAL("OUT OF MEMORY\n");
987 return ACCOUNT_ERROR_OUT_OF_MEMORY;
990 return ACCOUNT_ERROR_NONE;
993 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
996 return ACCOUNT_ERROR_INVALID_PARAMETER;
999 return ACCOUNT_ERROR_INVALID_PARAMETER;
1001 account_s *data = (account_s *)account;
1003 (*display_name) = NULL;
1005 *display_name = _account_get_text(data->display_name);
1006 if (data->display_name != NULL && *display_name == NULL) {
1007 ACCOUNT_FATAL("OUT OF MEMORY\n");
1008 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1012 return ACCOUNT_ERROR_NONE;
1015 ACCOUNT_API int account_get_email_address(account_h account, char **email_address)
1018 return ACCOUNT_ERROR_INVALID_PARAMETER;
1021 return ACCOUNT_ERROR_INVALID_PARAMETER;
1023 account_s *data = (account_s *)account;
1025 (*email_address) = NULL;
1027 *email_address = _account_get_text(data->email_address);
1028 if (data->email_address != NULL && *email_address == NULL) {
1029 ACCOUNT_FATAL("OUT OF MEMORY\n");
1030 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1033 return ACCOUNT_ERROR_NONE;
1036 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
1039 return ACCOUNT_ERROR_INVALID_PARAMETER;
1042 return ACCOUNT_ERROR_INVALID_PARAMETER;
1044 account_s *data = (account_s *)account;
1046 (*icon_path) = NULL;
1048 *icon_path = _account_get_text(data->icon_path);
1049 if (data->icon_path != NULL && *icon_path == NULL) {
1050 ACCOUNT_FATAL("OUT OF MEMORY\n");
1051 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1054 return ACCOUNT_ERROR_NONE;
1057 ACCOUNT_API int account_get_source(account_h account, char **source)
1060 return ACCOUNT_ERROR_INVALID_PARAMETER;
1063 return ACCOUNT_ERROR_INVALID_PARAMETER;
1065 account_s *data = (account_s *)account;
1069 *source = _account_get_text(data->source);
1070 if (data->source != NULL && *source == NULL) {
1071 ACCOUNT_FATAL("OUT OF MEMORY\n");
1072 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1075 return ACCOUNT_ERROR_NONE;
1078 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1081 return ACCOUNT_ERROR_INVALID_PARAMETER;
1084 return ACCOUNT_ERROR_INVALID_PARAMETER;
1086 account_s *data = (account_s *)account;
1088 (*package_name) = NULL;
1090 *package_name = _account_get_text(data->package_name);
1091 if (data->package_name != NULL && *package_name == NULL) {
1092 ACCOUNT_FATAL("OUT OF MEMORY\n");
1093 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1097 return ACCOUNT_ERROR_NONE;
1100 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1103 return ACCOUNT_ERROR_INVALID_PARAMETER;
1106 return ACCOUNT_ERROR_INVALID_PARAMETER;
1108 account_s *data = (account_s *)account;
1110 (*domain_name) = NULL;
1112 *domain_name = _account_get_text(data->domain_name);
1113 if (data->domain_name != NULL && *domain_name == NULL) {
1114 ACCOUNT_FATAL("OUT OF MEMORY\n");
1115 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1118 return ACCOUNT_ERROR_NONE;
1121 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1124 return ACCOUNT_ERROR_INVALID_PARAMETER;
1127 return ACCOUNT_ERROR_INVALID_PARAMETER;
1129 account_s *data = (account_s *)account;
1131 (*access_token) = NULL;
1133 *access_token = _account_get_text(data->access_token);
1134 if (data->access_token != NULL && *access_token == NULL) {
1135 ACCOUNT_FATAL("OUT OF MEMORY\n");
1136 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1139 return ACCOUNT_ERROR_NONE;
1142 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1145 return ACCOUNT_ERROR_INVALID_PARAMETER;
1148 return ACCOUNT_ERROR_INVALID_PARAMETER;
1150 ACCOUNT_RETURN_VAL((user_text_index >= 0 && user_text_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1152 account_s *data = (account_s *)account;
1156 *text = _account_get_text(data->user_data_txt[user_text_index]);
1157 if (data->user_data_txt[user_text_index] != NULL && *text == NULL) {
1158 ACCOUNT_FATAL("OUT OF MEMORY\n");
1159 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1162 return ACCOUNT_ERROR_NONE;
1165 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1168 return ACCOUNT_ERROR_INVALID_PARAMETER;
1171 return ACCOUNT_ERROR_INVALID_PARAMETER;
1173 account_s *data = (account_s *)account;
1175 *auth_type = data->auth_type;
1177 return ACCOUNT_ERROR_NONE;
1180 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1183 return ACCOUNT_ERROR_INVALID_PARAMETER;
1186 return ACCOUNT_ERROR_INVALID_PARAMETER;
1188 account_s *data = (account_s *)account;
1190 *secret = data->secret;
1192 return ACCOUNT_ERROR_NONE;
1195 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1198 return ACCOUNT_ERROR_INVALID_PARAMETER;
1201 return ACCOUNT_ERROR_INVALID_PARAMETER;
1203 account_s *data = (account_s *)account;
1205 *sync_support = data->sync_support;
1207 return ACCOUNT_ERROR_NONE;
1210 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1213 return ACCOUNT_ERROR_INVALID_PARAMETER;
1216 return ACCOUNT_ERROR_INVALID_PARAMETER;
1218 account_s *data = (account_s *)account;
1220 *account_id = data->id;
1222 return ACCOUNT_ERROR_NONE;
1225 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1228 return ACCOUNT_ERROR_INVALID_PARAMETER;
1230 ACCOUNT_RETURN_VAL((user_int_index >= 0 && user_int_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1233 return ACCOUNT_ERROR_INVALID_PARAMETER;
1235 account_s *data = (account_s *)account;
1237 *integer = data->user_data_int[user_int_index];
1239 return ACCOUNT_ERROR_NONE;
1242 ACCOUNT_API int account_get_capability(account_h account, const char *capability_type, account_capability_state_e *capability_value)
1244 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1245 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1246 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1249 account_s *data = (account_s *)account;
1251 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1252 account_capability_s *cap_data = NULL;
1254 cap_data = (account_capability_s *)iter->data;
1256 if (!strcmp(capability_type, cap_data->type)) {
1257 *capability_value = cap_data->value;
1258 return ACCOUNT_ERROR_NONE;
1262 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1265 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1267 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1268 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1271 account_s *data = (account_s *)account;
1273 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1274 account_capability_s *cap_data = NULL;
1276 cap_data = (account_capability_s *)iter->data;
1278 if (callback(cap_data->type, cap_data->value, user_data) != TRUE)
1279 return ACCOUNT_ERROR_NONE;
1282 return ACCOUNT_ERROR_NONE;
1285 ACCOUNT_API int account_get_custom(account_h account, const char *key, char **value)
1287 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1288 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1289 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1292 account_s *data = (account_s *)account;
1294 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1295 account_custom_s *custom_data = NULL;
1297 custom_data = (account_custom_s *)iter->data;
1299 if (!strcmp(key, custom_data->key)) {
1301 *value = _account_get_text(custom_data->value);
1302 if (custom_data->value != NULL && *value == NULL) {
1303 ACCOUNT_FATAL("OUT OF MEMORY\n");
1304 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1307 return ACCOUNT_ERROR_NONE;
1311 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1314 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void *user_data)
1316 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1317 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1320 account_s *data = (account_s *)account;
1322 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1323 bool cb_ret = FALSE;
1324 account_custom_s *custom_data = NULL;
1326 custom_data = (account_custom_s *)iter->data;
1328 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1333 return ACCOUNT_ERROR_NONE;
1336 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1338 _INFO("account_foreach_account_from_db start");
1340 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1342 GError *error = NULL;
1344 AccountManager *acc_mgr = _account_manager_get_instance();
1345 if (acc_mgr == NULL) {
1346 _ERR("g_bus_get_sync failed");
1347 return ACCOUNT_ERROR_PERMISSION_DENIED;
1350 GVariant *account_list_variant = NULL;
1351 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, (int)getuid(), &account_list_variant, NULL, &error);
1353 int error_code = _account_get_error_code(is_success, error);
1354 g_clear_error(&error);
1356 if (error_code != ACCOUNT_ERROR_NONE)
1359 GSList *account_list = unmarshal_account_list(account_list_variant);
1360 g_variant_unref(account_list_variant);
1364 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1365 _INFO("iterating received account_list");
1366 account_s *account = NULL;
1367 account = (account_s *)iter->data;
1368 _INFO("Before _account_query_identity_info_by_id");
1370 _INFO("account->id=%d", account->id);
1371 if (callback((account_h)account, user_data) == false) {
1372 _INFO("application callback requested to discontinue.");
1375 _INFO("After one iteration callback");
1377 _account_gslist_account_free(account_list);
1379 _INFO("account_foreach_account_from_db end");
1380 return ACCOUNT_ERROR_NONE;
1383 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1385 _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1387 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1388 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT POINTER IS NULL"));
1389 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1391 GError *error = NULL;
1393 AccountManager *acc_mgr = _account_manager_get_instance();
1394 if (acc_mgr == NULL) {
1395 _ERR("g_bus_get_sync failed");
1396 return ACCOUNT_ERROR_PERMISSION_DENIED;
1399 GVariant *account_variant = NULL;
1400 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)getuid(), &account_variant, NULL, &error);
1402 int error_code = _account_get_error_code(is_success, error);
1403 g_clear_error(&error);
1404 if (error_code != ACCOUNT_ERROR_NONE)
1407 _INFO("before unmarshal_account");
1408 account_s *account_data = umarshal_account(account_variant);
1409 g_variant_unref(account_variant);
1410 _INFO("after unmarshal_account");
1412 if (account_data == NULL) {
1413 _ERR("Failed to unmarshal");
1414 return ACCOUNT_ERROR_DB_FAILED;
1417 account_s **input = (account_s **)account;
1419 _account_free_account_with_items(*input);
1421 *input = account_data;
1423 _INFO("account_query_account_by_account_id end");
1425 return ACCOUNT_ERROR_NONE;
1428 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char *user_name, void *user_data)
1430 _INFO("account_query_account_by_user_name starting");
1432 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1433 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1435 GError *error = NULL;
1437 AccountManager *acc_mgr = _account_manager_get_instance();
1438 if (acc_mgr == NULL) {
1439 _ERR("g_bus_get_sync failed");
1440 return ACCOUNT_ERROR_PERMISSION_DENIED;
1443 GVariant *account_list_variant = NULL;
1444 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
1446 int error_code = _account_get_error_code(is_success, error);
1447 g_clear_error(&error);
1448 if (error_code != ACCOUNT_ERROR_NONE)
1451 GSList *account_list = unmarshal_account_list(account_list_variant);
1452 g_variant_unref(account_list_variant);
1454 if (account_list == NULL)
1455 return ACCOUNT_ERROR_NO_DATA;
1459 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1460 _INFO("iterating received account_list");
1461 account_s *account = NULL;
1462 account = (account_s *)iter->data;
1463 if (callback((account_h)account, user_data) == false) {
1464 _INFO("application callback requested to discontinue.");
1468 _INFO("account_query_account_by_user_name end");
1470 _account_gslist_account_free(account_list);
1471 return ACCOUNT_ERROR_NONE;
1474 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1476 _INFO("account_query_account_by_package_name starting");
1478 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1479 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1481 GError *error = NULL;
1483 AccountManager *acc_mgr = _account_manager_get_instance();
1484 if (acc_mgr == NULL) {
1485 _ERR("g_bus_get_sync failed");
1486 return ACCOUNT_ERROR_PERMISSION_DENIED;
1489 GVariant *account_list_variant = NULL;
1490 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, package_name, (int)getuid(), &account_list_variant, NULL, &error);
1492 int error_code = _account_get_error_code(is_success, error);
1493 g_clear_error(&error);
1494 if (error_code != ACCOUNT_ERROR_NONE)
1497 GSList *account_list = unmarshal_account_list(account_list_variant);
1498 g_variant_unref(account_list_variant);
1500 if (account_list == NULL)
1501 return ACCOUNT_ERROR_NO_DATA;
1505 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1506 _INFO("iterating received account_list");
1507 account_s *account = NULL;
1508 account = (account_s *)iter->data;
1510 if (callback((account_h)account, user_data) == false) {
1511 _INFO("application callback requested to discontinue.");
1515 _account_gslist_account_free(account_list);
1516 _INFO("account_query_account_by_package_name end");
1517 return ACCOUNT_ERROR_NONE;
1520 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char *capability_type, account_capability_state_e capability_value, void *user_data)
1522 _INFO("account_query_account_by_capability starting");
1524 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1526 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1527 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1528 return ACCOUNT_ERROR_INVALID_PARAMETER;
1531 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1533 GError *error = NULL;
1535 AccountManager *acc_mgr = _account_manager_get_instance();
1536 if (acc_mgr == NULL) {
1537 _ERR("g_bus_get_sync failed");
1538 return ACCOUNT_ERROR_PERMISSION_DENIED;
1541 GVariant *account_list_variant = NULL;
1542 bool is_success = account_manager_call_account_query_account_by_capability_sync(acc_mgr, capability_type, capability_value, (int)getuid(), &account_list_variant, NULL, &error);
1544 int error_code = _account_get_error_code(is_success, error);
1545 g_clear_error(&error);
1546 if (error_code != ACCOUNT_ERROR_NONE)
1549 GSList *account_list = unmarshal_account_list(account_list_variant);
1550 g_variant_unref(account_list_variant);
1551 if (account_list == NULL)
1552 return ACCOUNT_ERROR_NO_DATA;
1556 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1557 _INFO("iterating received account_list");
1558 account_s *account = NULL;
1559 account = (account_s *)iter->data;
1561 if (callback((account_h)account, user_data) == false) {
1562 _INFO("application callback requested to discontinue.");
1566 _account_gslist_account_free(account_list);
1567 _INFO("account_query_account_by_capability end");
1568 return ACCOUNT_ERROR_NONE;
1571 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char *capability_type, void *user_data)
1573 _INFO("account_query_account_by_capability_type starting");
1575 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1576 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1578 GError *error = NULL;
1580 AccountManager *acc_mgr = _account_manager_get_instance();
1581 if (acc_mgr == NULL) {
1582 _ERR("g_bus_get_sync failed");
1583 return ACCOUNT_ERROR_PERMISSION_DENIED;
1586 GVariant *account_list_variant = NULL;
1587 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, capability_type, (int)getuid(), &account_list_variant, NULL, &error);
1589 int error_code = _account_get_error_code(is_success, error);
1590 g_clear_error(&error);
1591 if (error_code != ACCOUNT_ERROR_NONE)
1594 GSList *account_list = unmarshal_account_list(account_list_variant);
1595 g_variant_unref(account_list_variant);
1597 if (account_list == NULL)
1598 return ACCOUNT_ERROR_NO_DATA;
1602 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1603 _INFO("iterating received account_list");
1604 account_s *account = NULL;
1605 account = (account_s *)iter->data;
1607 if (callback((account_h)account, user_data) == false) {
1608 _INFO("application callback requested to discontinue.");
1612 _account_gslist_account_free(account_list);
1613 _INFO("account_query_account_by_capability end");
1614 return ACCOUNT_ERROR_NONE;
1617 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1619 _INFO("account_query_capability_by_account_id starting");
1621 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1622 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1624 GError *error = NULL;
1625 AccountManager *acc_mgr = _account_manager_get_instance();
1626 if (acc_mgr == NULL) {
1627 _ERR("g_bus_get_sync failed");
1628 return ACCOUNT_ERROR_PERMISSION_DENIED;
1631 GVariant *capability_list_variant = NULL;
1632 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &capability_list_variant, NULL, &error);
1634 int error_code = _account_get_error_code(is_success, error);
1635 g_clear_error(&error);
1636 if (error_code != ACCOUNT_ERROR_NONE)
1639 GSList *capability_list = unmarshal_capability_list(capability_list_variant);
1640 g_variant_unref(capability_list_variant);
1642 if (capability_list == NULL)
1643 return ACCOUNT_ERROR_NO_DATA;
1647 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter)) {
1648 _INFO("iterating received account_list");
1649 account_capability_s *capability = NULL;
1650 capability = (account_capability_s *)iter->data;
1651 if (callback(capability->type, capability->value, user_data) == false) {
1652 _INFO("application callback requested to discontinue.");
1657 _account_gslist_capability_free(capability_list);
1658 _INFO("account_query_capability_by_account_id end");
1659 return ACCOUNT_ERROR_NONE;
1662 static int _account_get_total_count(int *count, bool include_hidden)
1664 _INFO("account_get_total_count_from_db starting");
1667 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1668 return ACCOUNT_ERROR_INVALID_PARAMETER;
1671 GError *error = NULL;
1673 if (count == NULL) {
1674 _INFO("Invalid input");
1678 AccountManager *acc_mgr = _account_manager_get_instance();
1679 if (acc_mgr == NULL) {
1680 _ERR("g_bus_get_sync failed");
1681 return ACCOUNT_ERROR_PERMISSION_DENIED;
1684 int temp_count = -1;
1685 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, include_hidden, (int)getuid(), &temp_count, NULL, &error);
1686 int error_code = _account_get_error_code(is_success, error);
1687 g_clear_error(&error);
1688 if (error_code != ACCOUNT_ERROR_NONE)
1691 *count = temp_count;
1692 _INFO("account_get_total_count_from_db end");
1693 return ACCOUNT_ERROR_NONE;
1696 ACCOUNT_API int account_get_total_count_from_db(int *count)
1698 _INFO("account_get_total_count_from_db starting");
1700 return _account_get_total_count(count, true);
1703 ACCOUNT_INTERNAL_API int account_get_total_count_from_db_ex(int *count)
1705 _INFO("account_get_total_count_from_db_ex starting");
1707 return _account_get_total_count(count, false);
1710 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1712 _INFO("account_update_sync_status_by_id starting");
1713 int error_code = ACCOUNT_ERROR_NONE;
1715 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1716 if (((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1717 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1718 return ACCOUNT_ERROR_INVALID_PARAMETER;
1721 GError *error = NULL;
1723 AccountManager *acc_mgr = _account_manager_get_instance();
1724 if (acc_mgr == NULL) {
1725 _ERR("g_bus_get_sync failed");
1726 return ACCOUNT_ERROR_PERMISSION_DENIED;
1729 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_id, sync_status, (int)getuid(), NULL, &error);
1731 error_code = _account_get_error_code(is_success, error);
1732 g_clear_error(&error);
1738 ACCOUNT_API int account_type_create(account_type_h *account_type)
1740 if (!account_type) {
1741 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1742 return ACCOUNT_ERROR_INVALID_PARAMETER;
1745 account_type_s *data = (account_type_s *)malloc(sizeof(account_type_s));
1747 ACCOUNT_FATAL("Memory Allocation Failed");
1748 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1751 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1754 data->app_id = NULL;
1755 data->service_provider_id = NULL;
1756 data->icon_path = NULL;
1757 data->small_icon_path = NULL;
1758 data->multiple_account_support = false;
1759 data->label_list = NULL;
1760 data->provider_feature_list = NULL;
1762 *account_type = (account_type_h)data;
1764 return ACCOUNT_ERROR_NONE;
1767 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1769 _INFO("account_type_destroy");
1771 account_type_s *data = (account_type_s *)account_type;
1774 _ERR("Account type handle is null!");
1775 return ACCOUNT_ERROR_INVALID_PARAMETER;
1778 _account_type_free_account_type_with_items(data);
1780 return ACCOUNT_ERROR_NONE;
1783 ACCOUNT_INTERNAL_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1785 if (!account_type) {
1786 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1787 return ACCOUNT_ERROR_INVALID_PARAMETER;
1791 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1792 return ACCOUNT_ERROR_INVALID_PARAMETER;
1795 account_type_s *data = (account_type_s *)account_type;
1797 _ACCOUNT_FREE(data->app_id);
1798 data->app_id = _account_get_text(app_id);
1799 if (data->app_id == NULL) {
1800 ACCOUNT_FATAL("OUT OF MEMORY\n");
1801 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1804 return ACCOUNT_ERROR_NONE;
1807 ACCOUNT_INTERNAL_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1810 return ACCOUNT_ERROR_INVALID_PARAMETER;
1812 if (!service_provider_id)
1813 return ACCOUNT_ERROR_INVALID_PARAMETER;
1815 account_type_s *data = (account_type_s *)account_type;
1817 _ACCOUNT_FREE(data->service_provider_id);
1818 data->service_provider_id = _account_get_text(service_provider_id);
1819 if (data->service_provider_id == NULL) {
1820 ACCOUNT_FATAL("OUT OF MEMORY\n");
1821 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1824 return ACCOUNT_ERROR_NONE;
1827 ACCOUNT_INTERNAL_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1830 return ACCOUNT_ERROR_INVALID_PARAMETER;
1833 return ACCOUNT_ERROR_INVALID_PARAMETER;
1835 account_type_s *data = (account_type_s *)account_type;
1837 _ACCOUNT_FREE(data->icon_path);
1838 data->icon_path = _account_get_text(icon_path);
1839 if (data->icon_path == NULL) {
1840 ACCOUNT_FATAL("OUT OF MEMORY\n");
1841 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1844 return ACCOUNT_ERROR_NONE;
1847 ACCOUNT_INTERNAL_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
1850 return ACCOUNT_ERROR_INVALID_PARAMETER;
1852 if (!small_icon_path)
1853 return ACCOUNT_ERROR_INVALID_PARAMETER;
1855 account_type_s *data = (account_type_s *)account_type;
1857 _ACCOUNT_FREE(data->small_icon_path);
1858 data->small_icon_path = _account_get_text(small_icon_path);
1859 if (data->small_icon_path == NULL) {
1860 ACCOUNT_FATAL("OUT OF MEMORY\n");
1861 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1864 return ACCOUNT_ERROR_NONE;
1867 ACCOUNT_INTERNAL_API int account_type_set_multiple_account_support(account_type_h account_type, bool multiple_account_support)
1869 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1871 account_type_s *data = (account_type_s *)account_type;
1873 data->multiple_account_support = multiple_account_support;
1875 return ACCOUNT_ERROR_NONE;
1878 ACCOUNT_INTERNAL_API int account_type_set_label(account_type_h account_type, const char *label, const char *locale)
1880 if (!account_type) {
1881 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1882 return ACCOUNT_ERROR_INVALID_PARAMETER;
1885 if (!label || !locale)
1886 return ACCOUNT_ERROR_INVALID_PARAMETER;
1888 account_type_s *data = (account_type_s *)account_type;
1889 label_s *label_data = (label_s *)malloc(sizeof(label_s));
1890 if (label_data == NULL) {
1891 ACCOUNT_FATAL("Memory Allocation Failed");
1892 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1895 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
1897 label_data->label = _account_get_text(label);
1898 if (label_data->label == NULL) {
1899 ACCOUNT_FATAL("OUT OF MEMORY\n");
1900 _ACCOUNT_FREE(label_data);
1901 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1904 label_data->locale = _account_get_text(locale);
1905 if (label_data->locale == NULL) {
1906 ACCOUNT_FATAL("OUT OF MEMORY\n");
1907 _ACCOUNT_FREE(label_data->label);
1908 _ACCOUNT_FREE(label_data);
1909 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1912 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
1914 return ACCOUNT_ERROR_NONE;
1917 ACCOUNT_INTERNAL_API int account_type_set_provider_feature(account_type_h account_type, const char *provider_feature)
1919 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
1920 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
1922 account_type_s *data = (account_type_s *)account_type;
1924 GSList *iter = NULL;
1925 bool b_is_new = TRUE;
1927 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
1928 provider_feature_s *feature_data = NULL;
1929 feature_data = (provider_feature_s *)iter->data;
1931 if (!strcmp(feature_data->key, provider_feature)) {
1938 provider_feature_s* feature_data = (provider_feature_s *)malloc(sizeof(provider_feature_s));
1939 if (feature_data == NULL) {
1940 ACCOUNT_FATAL("Memory Allocation Failed");
1941 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1944 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
1946 feature_data->key = _account_get_text(provider_feature);
1947 if (feature_data->key == NULL) {
1948 ACCOUNT_FATAL("OUT OF MEMORY\n");
1949 _ACCOUNT_FREE(feature_data);
1950 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1953 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
1956 return ACCOUNT_ERROR_NONE;
1959 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char *app_id, void *user_data)
1961 _INFO("account_type_query_provider_feature_by_app_id start");
1963 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
1964 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1966 GError *error = NULL;
1967 gint error_code = ACCOUNT_ERROR_NONE;
1969 AccountManager *acc_mgr = _account_manager_get_instance();
1970 if (acc_mgr == NULL) {
1971 _ERR("g_bus_get_sync failed");
1972 return ACCOUNT_ERROR_PERMISSION_DENIED;
1975 GVariant *feature_list_variant = NULL;
1976 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);
1978 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
1981 error_code = _account_get_error_code(is_success, error);
1982 g_clear_error(&error);
1983 _ERR("Account IPC call returned error[%d]", error_code);
1986 g_clear_error(&error);
1988 GSList *provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
1989 if (provider_feature_list == NULL) {
1990 error_code = ACCOUNT_ERROR_NO_DATA;
1991 _ERR("[%d]", error_code);
1996 for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
1997 provider_feature_s *feature_data = NULL;
1999 feature_data = (provider_feature_s *)iter->data;
2001 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
2002 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2003 return ACCOUNT_ERROR_NONE;
2007 _account_type_gslist_feature_free(provider_feature_list);
2008 _INFO("account_type_query_provider_feature_by_app_id end");
2012 ACCOUNT_API bool account_type_query_supported_feature(const char *app_id, const char *capability)
2014 _INFO("account_type_query_supported_feature start");
2016 if (app_id == NULL || capability == NULL) {
2017 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2021 int is_supported = 0;
2022 GError *error = NULL;
2023 gint ret = ACCOUNT_ERROR_NONE;
2025 AccountManager *acc_mgr = _account_manager_get_instance();
2026 if (acc_mgr == NULL) {
2027 _ERR("g_bus_get_sync failed");
2028 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2032 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, app_id, capability, (int)getuid(), &is_supported, NULL, &error);
2034 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2037 ret = _account_get_error_code(is_success, error);
2038 g_clear_error(&error);
2039 _ERR("Account IPC call returned error[%d]", ret);
2040 set_last_result(ret);
2043 g_clear_error(&error);
2045 set_last_result(ACCOUNT_ERROR_NONE);
2046 _INFO("account_type_query_supported_feature end");
2047 return is_supported;
2050 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2053 return ACCOUNT_ERROR_INVALID_PARAMETER;
2056 return ACCOUNT_ERROR_INVALID_PARAMETER;
2058 account_type_s *data = (account_type_s *)account_type;
2061 *app_id = _account_get_text(data->app_id);
2062 if (*app_id == NULL) {
2063 ACCOUNT_FATAL("OUT OF MEMORY\n");
2064 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2067 return ACCOUNT_ERROR_NONE;
2070 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2073 return ACCOUNT_ERROR_INVALID_PARAMETER;
2075 if (!service_provider_id)
2076 return ACCOUNT_ERROR_INVALID_PARAMETER;
2078 account_type_s *data = (account_type_s *)account_type;
2080 (*service_provider_id) = NULL;
2081 *service_provider_id = _account_get_text(data->service_provider_id);
2082 if (*service_provider_id == NULL) {
2083 ACCOUNT_FATAL("OUT OF MEMORY\n");
2084 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2087 return ACCOUNT_ERROR_NONE;
2090 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2093 return ACCOUNT_ERROR_INVALID_PARAMETER;
2096 return ACCOUNT_ERROR_INVALID_PARAMETER;
2098 account_type_s *data = (account_type_s *)account_type;
2100 (*icon_path) = NULL;
2101 *icon_path = _account_get_text(data->icon_path);
2102 if (*icon_path == NULL) {
2103 ACCOUNT_FATAL("OUT OF MEMORY\n");
2104 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2107 return ACCOUNT_ERROR_NONE;
2110 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2113 return ACCOUNT_ERROR_INVALID_PARAMETER;
2115 if (!small_icon_path)
2116 return ACCOUNT_ERROR_INVALID_PARAMETER;
2118 account_type_s *data = (account_type_s *)account_type;
2120 (*small_icon_path) = NULL;
2121 *small_icon_path = _account_get_text(data->small_icon_path);
2122 if (*small_icon_path == NULL) {
2123 ACCOUNT_FATAL("OUT OF MEMORY\n");
2124 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2128 return ACCOUNT_ERROR_NONE;
2131 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2134 return ACCOUNT_ERROR_INVALID_PARAMETER;
2136 if (!multiple_account_support)
2137 return ACCOUNT_ERROR_INVALID_PARAMETER;
2139 account_type_s *data = (account_type_s *)account_type;
2141 *multiple_account_support = data->multiple_account_support;
2143 return ACCOUNT_ERROR_NONE;
2146 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void *user_data)
2148 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2149 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2152 account_type_s *data = (account_type_s *)account_type;
2154 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2155 provider_feature_s *feature_data = NULL;
2157 feature_data = (provider_feature_s *)iter->data;
2159 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
2160 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2161 return ACCOUNT_ERROR_NONE;
2165 return ACCOUNT_ERROR_NONE;
2168 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char *locale, char **label)
2170 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2171 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2174 account_type_s *data = (account_type_s *)account_type;
2176 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2177 label_s *label_data = NULL;
2179 label_data = (label_s *)iter->data;
2183 if (!strcmp(locale, label_data->locale)) {
2184 *label = _account_get_text(label_data->label);
2185 if (*label == NULL) {
2186 ACCOUNT_FATAL("OUT OF MEMORY\n");
2187 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2190 return ACCOUNT_ERROR_NONE;
2192 gchar **tokens = g_strsplit(locale, "-", 2);
2194 if (tokens != NULL) {
2195 if ((char *)(tokens[1]) != NULL) {
2196 char *upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2197 if (upper_token == NULL) {
2198 ACCOUNT_FATAL("Memory Allocation Failed");
2200 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2203 if (upper_token != NULL) {
2204 char *converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2205 if (converted_locale == NULL) {
2206 ACCOUNT_FATAL("Memory Allocation Failed");
2207 _ACCOUNT_FREE(upper_token);
2209 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2212 if (!strcmp(converted_locale, label_data->locale)) {
2213 _ACCOUNT_FREE(converted_locale);
2214 _ACCOUNT_FREE(upper_token);
2216 *label = _account_get_text(label_data->label);
2217 if (*label == NULL) {
2218 ACCOUNT_FATAL("OUT OF MEMORY\n");
2219 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2222 return ACCOUNT_ERROR_NONE;
2224 _ACCOUNT_FREE(converted_locale);
2226 _ACCOUNT_FREE(upper_token);
2232 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2235 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2237 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2238 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2241 account_type_s *data = (account_type_s *)account_type;
2243 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2244 label_s *label_data = NULL;
2246 label_data = (label_s *)iter->data;
2248 if (callback(label_data->app_id, label_data->label, label_data->locale, user_data) != TRUE) {
2249 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2250 return ACCOUNT_ERROR_NONE;
2254 return ACCOUNT_ERROR_NONE;
2257 ACCOUNT_INTERNAL_API int account_type_insert_to_db(account_type_h account_type, int *account_type_id)
2259 _INFO("account_type_insert_to_db starting");
2261 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2262 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2264 GError *error = NULL;
2266 AccountManager *acc_mgr = _account_manager_get_instance();
2267 if (acc_mgr == NULL) {
2268 _ERR("g_bus_get_sync failed");
2269 return ACCOUNT_ERROR_PERMISSION_DENIED;
2273 GVariant *account_type_serialized = marshal_account_type((account_type_s *)account_type);
2274 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_type_serialized, (int)getuid(), &db_id, NULL, &error);
2275 g_variant_unref(account_type_serialized);
2277 int ret = _account_get_error_code(is_success, error);
2278 g_clear_error(&error);
2280 if (ret != ACCOUNT_ERROR_NONE)
2283 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2285 *account_type_id = db_id;
2287 account_type_s *account_type_data = (account_type_s *)account_type;
2288 account_type_data->id = db_id;
2290 return ACCOUNT_ERROR_NONE;
2293 ACCOUNT_INTERNAL_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char *app_id)
2295 _INFO("account_type_update_to_db_by_app_id starting");
2296 int error_code = ACCOUNT_ERROR_NONE;
2298 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2299 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2301 GError *error = NULL;
2303 AccountManager *acc_mgr = _account_manager_get_instance();
2304 if (acc_mgr == NULL) {
2305 _ERR("g_bus_get_sync failed");
2306 return ACCOUNT_ERROR_PERMISSION_DENIED;
2309 GVariant *account_type_variant = marshal_account_type((account_type_s *)account_type);
2310 if (account_type_variant == NULL) {
2311 _ERR("Failed to serialize");
2312 return ACCOUNT_ERROR_INVALID_PARAMETER;
2315 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);
2316 g_variant_unref(account_type_variant);
2318 error_code = _account_get_error_code(is_success, error);
2319 g_clear_error(&error);
2324 ACCOUNT_INTERNAL_API int account_type_delete_by_app_id(const char *app_id)
2326 _INFO("account_type_delete_by_app_id starting");
2327 int error_code = ACCOUNT_ERROR_NONE;
2329 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2331 GError *error = NULL;
2333 AccountManager *acc_mgr = _account_manager_get_instance();
2334 if (acc_mgr == NULL) {
2335 _ERR("g_bus_get_sync failed");
2336 return ACCOUNT_ERROR_PERMISSION_DENIED;
2339 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2341 error_code = _account_get_error_code(is_success, error);
2342 g_clear_error(&error);
2347 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char *app_id, void *user_data)
2349 _INFO("account_type_query_label_by_app_id starting");
2351 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2352 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2354 GError *error = NULL;
2356 AccountManager *acc_mgr = _account_manager_get_instance();
2357 if (acc_mgr == NULL) {
2358 _ERR("g_bus_get_sync failed");
2359 return ACCOUNT_ERROR_PERMISSION_DENIED;
2362 GVariant *label_list_variant = NULL;
2363 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);
2365 int ret = _account_get_error_code(is_success, error);
2366 g_clear_error(&error);
2368 if (ret != ACCOUNT_ERROR_NONE)
2371 GSList *label_list = variant_to_label_list(label_list_variant);
2372 if (label_list == NULL)
2373 return ACCOUNT_ERROR_NO_DATA;
2377 for (iter = label_list; iter != NULL; iter = g_slist_next(iter)) {
2378 _INFO("iterating received account_list");
2379 label_s *label_record = NULL;
2380 label_record = (label_s *)iter->data;
2381 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false) {
2382 _INFO("application callback requested to discontinue.");
2387 _account_type_gslist_label_free(label_list);
2388 _INFO("account_type_query_label_by_app_id end");
2389 return ACCOUNT_ERROR_NONE;
2392 ACCOUNT_API int account_type_query_by_app_id(const char *app_id, account_type_h *account_type)
2394 _INFO("account_type_query_by_app_id starting");
2396 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2397 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2398 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2400 GError *error = NULL;
2402 AccountManager *acc_mgr = _account_manager_get_instance();
2403 if (acc_mgr == NULL) {
2404 _ERR("g_bus_get_sync failed");
2405 return ACCOUNT_ERROR_PERMISSION_DENIED;
2408 GVariant *account_type_variant = NULL;
2409 account_type_s *in_data = (account_type_s *)*account_type;
2411 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &account_type_variant, NULL, &error);
2413 int ret = _account_get_error_code(is_success, error);
2414 g_clear_error(&error);
2416 if (ret != ACCOUNT_ERROR_NONE)
2419 account_type_s *received_account_type = umarshal_account_type(account_type_variant);
2420 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2422 in_data->id = received_account_type->id;
2423 in_data->app_id = received_account_type->app_id;
2424 in_data->service_provider_id = received_account_type->service_provider_id;
2425 in_data->icon_path = received_account_type->icon_path;
2426 in_data->small_icon_path = received_account_type->small_icon_path;
2427 in_data->multiple_account_support = received_account_type->multiple_account_support;
2428 in_data->label_list = received_account_type->label_list;
2429 in_data->provider_feature_list = received_account_type->provider_feature_list;
2431 _ACCOUNT_FREE(received_account_type);
2432 _INFO("account_type_query_by_app_id end");
2433 return ACCOUNT_ERROR_NONE;
2436 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2438 _INFO("account_type_foreach_account_type_from_db starting");
2440 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2442 GError *error = NULL;
2444 AccountManager *acc_mgr = _account_manager_get_instance();
2445 if (acc_mgr == NULL) {
2446 _ERR("g_bus_get_sync failed");
2447 return ACCOUNT_ERROR_PERMISSION_DENIED;
2450 GVariant *account_type_list_variant = NULL;
2451 _INFO("before account_type_query_all_sync()");
2452 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, (int)getuid(), &account_type_list_variant, NULL, &error);
2454 _INFO("after account_type_query_all_sync()");
2455 int ret = _account_get_error_code(is_success, error);
2456 g_clear_error(&error);
2458 if (ret != ACCOUNT_ERROR_NONE)
2461 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2462 g_variant_unref(account_type_list_variant);
2464 if (account_type_list == NULL)
2465 return ACCOUNT_ERROR_NO_DATA;
2469 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2470 _INFO("iterating received account_list");
2471 account_type_s *account_type = NULL;
2472 account_type = (account_type_s *)iter->data;
2474 if (callback((account_type_h)account_type, user_data) == false) {
2475 _INFO("application callback requested to discontinue.");
2480 _account_type_gslist_account_type_free(account_type_list);
2481 _INFO("account_type_foreach_account_type_from_db end");
2482 return ACCOUNT_ERROR_NONE;
2485 ACCOUNT_API int account_type_query_label_by_locale(const char *app_id, const char *locale, char **label)
2487 _INFO("account_type_query_label_by_locale starting");
2489 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2490 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2491 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2493 GError *error = NULL;
2495 AccountManager *acc_mgr = _account_manager_get_instance();
2496 if (acc_mgr == NULL) {
2497 _ERR("g_bus_get_sync failed");
2498 return ACCOUNT_ERROR_PERMISSION_DENIED;
2501 char *label_temp = NULL;
2502 _INFO("before account_type_query_label_by_locale_sync()");
2503 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, app_id, locale, (int)getuid(), &label_temp, NULL, &error);
2505 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2506 int ret = _account_get_error_code(is_success, error);
2507 g_clear_error(&error);
2509 if (ret != ACCOUNT_ERROR_NONE)
2512 if (label_temp == NULL)
2513 return ACCOUNT_ERROR_NO_DATA;
2516 *label = _account_get_text(label_temp);
2517 if (*label == NULL) {
2518 ACCOUNT_FATAL("OUT OF MEMORY\n");
2519 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2522 _INFO("account_type_query_label_by_locale end");
2523 return ACCOUNT_ERROR_NONE;
2527 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char *key, void *user_data)
2529 _INFO("account_type_query_by_provider_feature starting");
2531 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2532 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2534 GError *error = NULL;
2536 AccountManager *acc_mgr = _account_manager_get_instance();
2537 if (acc_mgr == NULL) {
2538 _ERR("g_bus_get_sync failed");
2539 return ACCOUNT_ERROR_PERMISSION_DENIED;
2542 GVariant *account_type_list_variant = NULL;
2543 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, key, (int)getuid(), &account_type_list_variant, NULL, &error);
2545 int ret = _account_get_error_code(is_success, error);
2546 g_clear_error(&error);
2548 if (ret != ACCOUNT_ERROR_NONE)
2551 _INFO("before unmarshal_account_type_list");
2552 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2553 g_variant_unref(account_type_list_variant);
2555 if (account_type_list == NULL)
2556 return ACCOUNT_ERROR_NO_DATA;
2560 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2561 _INFO("iterating received account_type_list");
2562 account_type_s *account_type = NULL;
2563 account_type = (account_type_s *)iter->data;
2565 if (callback((account_type_h)account_type, user_data) == false) {
2566 _INFO("Application callback requested not to continue");
2572 _account_type_gslist_account_type_free(account_type_list);
2573 _INFO("account_type_query_by_provider_feature end");
2574 return ACCOUNT_ERROR_NONE;
2577 ACCOUNT_API int account_type_query_app_id_exist(const char *app_id)
2579 _INFO("account_type_query_app_id_exist starting");
2580 int error_code = ACCOUNT_ERROR_NONE;
2582 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2584 GError *error = NULL;
2586 AccountManager *acc_mgr = _account_manager_get_instance();
2587 if (acc_mgr == NULL) {
2588 _ERR("g_bus_get_sync failed");
2589 return ACCOUNT_ERROR_PERMISSION_DENIED;
2592 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2594 error_code = _account_get_error_code(is_success, error);
2595 g_clear_error(&error);
2601 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2603 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2604 char *msg = NULL, *vconf_key = NULL;
2605 const char *key_name = NULL;
2606 char event_msg[256] = {0, };
2607 int account_id = -1;
2610 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2615 ACCOUNT_ERROR("user data required\n");
2619 key_name = vconf_keynode_get_name(key);
2621 if (key_name == NULL) {
2622 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2626 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2627 vconf_key = vconf_keynode_get_str(key);
2629 if (vconf_key == NULL) {
2630 ACCOUNT_ERROR("vconf key is NULL.\n");
2634 msg = strdup(vconf_key);
2636 ACCOUNT_FATAL("Memory Allocation Failed");
2640 char *event_type = NULL;
2644 event_type = strtok_r(msg, ":", &ptr);
2645 id = strtok_r(NULL, ":", &ptr);
2647 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2649 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2651 account_id = atoi(id);
2653 if (tmp->account_subscription_callback)
2654 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2660 ACCOUNT_API int account_subscribe_create(account_subscribe_h *account_subscribe)
2662 if (!account_subscribe) {
2663 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2664 return ACCOUNT_ERROR_INVALID_PARAMETER;
2667 account_subscribe_s *data = (account_subscribe_s *)calloc(1, sizeof(account_subscribe_s));
2669 ACCOUNT_FATAL("OUT OF MEMORY\n");
2670 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2673 *account_subscribe = (account_subscribe_h)data;
2675 return ACCOUNT_ERROR_NONE;
2678 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
2680 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2682 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2684 tmp->account_subscription_callback = callback;
2685 tmp->user_data = user_data;
2688 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2689 (vconf_callback_fn)_account_subscribe_vconf_callback,
2692 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2694 if (ret != VCONF_OK) {
2695 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2696 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2699 return ACCOUNT_ERROR_NONE;
2702 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2704 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2706 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2710 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2711 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
2712 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2713 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2716 return ACCOUNT_ERROR_NONE;
2719 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2721 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2722 char *msg = NULL, *vconf_key = NULL;
2723 char event_msg[256] = {0, };
2724 int account_id = -1;
2725 const char *key_name = NULL;
2728 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2733 ACCOUNT_ERROR("user data required\n");
2737 key_name = vconf_keynode_get_name(key);
2739 if (key_name == NULL) {
2740 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2744 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2745 vconf_key = vconf_keynode_get_str(key);
2747 if (vconf_key == NULL) {
2748 ACCOUNT_ERROR("vconf key is NULL.\n");
2751 msg = strdup(vconf_key);
2753 ACCOUNT_FATAL("Memory Allocation Failed");
2757 char *event_type = NULL;
2761 event_type = strtok_r(msg, ":", &ptr);
2762 id = strtok_r(NULL, ":", &ptr);
2764 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2766 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2768 account_id = atoi(id);
2770 if (tmp->account_subscription_callback)
2771 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2778 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2780 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2782 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2786 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2787 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
2788 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2789 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2792 return ACCOUNT_ERROR_NONE;
2795 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
2797 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2799 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2801 tmp->account_subscription_callback = callback;
2802 tmp->user_data = user_data;
2805 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2806 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2809 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2811 if (ret != VCONF_OK) {
2812 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2813 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2816 return ACCOUNT_ERROR_NONE;