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);
63 //FIXME : add true singleton logic
65 _account_manager_get_instance ()
67 _INFO("_account_manager_get_instance");
70 _INFO("instance already created.");
74 #if !GLIB_CHECK_VERSION(2,35,0)
78 GDBusConnection *connection = NULL;
81 connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
83 _INFO("after g_bus_get_sync");
87 _ERR("Unable to connect to gdbus: %s", error->message);
88 g_clear_error(&error);
93 g_clear_error(&error);
95 /* Create the object */
97 account_manager_proxy_new_sync(connection,
98 G_DBUS_PROXY_FLAGS_NONE,
99 "org.tizen.account.manager",
100 "/org/tizen/account/manager",
106 _ERR("Unable account_manager_proxy_new_sync: %s", error->message);
107 g_clear_error(&error);
110 g_object_unref(connection);
114 g_clear_error(&error);
115 _INFO("_account_manager_get_instance end");
119 GDBusErrorEntry _account_svc_errors[] =
121 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
122 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
123 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
124 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
125 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
126 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
127 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
128 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
129 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
130 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
131 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
132 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
133 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
134 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
135 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
136 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
137 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
138 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
141 static int _account_get_error_code(bool is_success, GError *error)
145 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
147 if (g_dbus_error_is_remote_error(error))
149 gchar *remote_error = g_dbus_error_get_remote_error(error);
152 _INFO("Remote error[%s]", remote_error);
154 //FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
155 //However error->message matches, so doing reverse lookup
156 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
158 for (i = 0; i < error_enum_count; i++)
160 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0)
162 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
163 g_free(remote_error);
164 return _account_svc_errors[i].error_code;
167 g_free(remote_error);
170 //All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED
171 return ACCOUNT_ERROR_PERMISSION_DENIED;
173 return ACCOUNT_ERROR_NONE;
176 #ifdef TIZEN_PROFILE_MOBILE
177 ACCOUNT_API int account_connect(void)
179 return ACCOUNT_ERROR_NONE;
182 ACCOUNT_API int account_connect_readonly(void)
184 return ACCOUNT_ERROR_NONE;
187 ACCOUNT_API int account_disconnect(void)
189 return ACCOUNT_ERROR_NONE;
194 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
196 _INFO("1. account_insert_to_db start");
198 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
199 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
201 account_s *account_data = (account_s*) account;
202 int error_code = ACCOUNT_ERROR_NONE;
203 GError *error = NULL;
205 _INFO("2. Before _account_manager_get_instance()");
206 AccountManager* acc_mgr = _account_manager_get_instance();
207 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
210 GVariant* account_serialized = marshal_account(account_data);
212 _INFO("3. Before account_manager_call_account_add_sync");
213 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_serialized, (int)getuid(), &db_id, NULL, &error);
214 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
215 g_clear_error(&error);
217 *account_db_id = db_id;
218 account_data->id = db_id;
220 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
222 return ACCOUNT_ERROR_NONE;
225 g_clear_error(&error);
226 //Failed to get dbus.
227 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
232 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
234 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
235 int error_code = ACCOUNT_ERROR_NONE;
237 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
239 GError *error = NULL;
241 AccountManager* acc_mgr = _account_manager_get_instance();
244 _ERR("g_bus_get_sync failed");
245 return ACCOUNT_ERROR_PERMISSION_DENIED;
248 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
249 GVariant *account_serialized_old = NULL;
250 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, &account_serialized_old, NULL, &error);
254 error_code = _account_get_error_code(is_success, error);
255 g_clear_error(&error);
256 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
259 g_clear_error(&error);
261 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
262 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_id, (int)getuid(), NULL, &error);
266 error_code = _account_get_error_code(is_success, error);
267 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error_code);
268 g_clear_error(&error);
271 g_clear_error(&error);
273 _INFO("4. Before account_delete_from_db_by_id end");
274 return ACCOUNT_ERROR_NONE;
277 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
279 int error_code = ACCOUNT_ERROR_NONE;
280 _INFO("account_delete_from_db_by_user_name start");
282 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
283 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
286 GError *error = NULL;
288 AccountManager* acc_mgr = _account_manager_get_instance();
291 _ERR("g_bus_get_sync failed");
292 return ACCOUNT_ERROR_PERMISSION_DENIED;
295 GVariant* account_list_variant = NULL;
296 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, &account_list_variant, NULL, &error);
298 error_code = _account_get_error_code(is_success, error);
299 g_clear_error(&error);
300 if (error_code != ACCOUNT_ERROR_NONE)
302 _ERR("account_query_account_by_user_name error=[%d]", error_code);
306 GSList* account_list = unmarshal_account_list(account_list_variant);
307 g_variant_unref(account_list_variant);
309 if (account_list == NULL)
311 return ACCOUNT_ERROR_NO_DATA;
314 //TODO free account_list, account_list_variant
316 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, user_name, package_name, (int)getuid(), NULL, &error);
320 error_code = _account_get_error_code(is_success, error);
321 g_clear_error(&error);
322 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
323 _account_gslist_account_free(account_list);
326 g_clear_error(&error);
328 _account_gslist_account_free(account_list);
329 return ACCOUNT_ERROR_NONE;
332 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
334 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
335 int error_code = ACCOUNT_ERROR_NONE;
337 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
339 GError *error = NULL;
341 AccountManager* acc_mgr = _account_manager_get_instance();
344 _ERR("g_bus_get_sync failed");
345 return ACCOUNT_ERROR_PERMISSION_DENIED;
348 //First get account list of user_name, used for gSSO DB deletion
349 GVariant* account_list_variant = NULL;
350 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, &account_list_variant, NULL, &error);
352 error_code = _account_get_error_code(is_success, error);
353 if (error_code != ACCOUNT_ERROR_NONE)
358 _INFO("before unmarshal_account_list");
359 GSList* account_list = unmarshal_account_list(account_list_variant);
360 _INFO("after unmarshal_account_list");
361 if (account_list == NULL)
363 return ACCOUNT_ERROR_NO_DATA;
366 bool is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, package_name, permission, (int)getuid(), NULL, &error);
370 error_code = _account_get_error_code(is_success, error);
371 g_clear_error(&error);
372 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error_code);
375 g_clear_error(&error);
377 return ACCOUNT_ERROR_NONE;
380 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
382 _INFO("account_delete_from_db_by_package_name starting with permission");
383 return _account_delete_from_db_by_package_name(package_name, true);
386 ACCOUNT_INTERNAL_API int account_delete_from_db_by_package_name_without_permission(const char *package_name)
388 _INFO("account_delete_from_db_by_package_name starting without permission");
389 return _account_delete_from_db_by_package_name(package_name, false);
392 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
394 //First we will update account db
395 _INFO("1. account_update_to_db_by_id start");
396 int error_code = ACCOUNT_ERROR_NONE;
398 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
399 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
401 GError *error = NULL;
403 AccountManager* acc_mgr = _account_manager_get_instance();
406 _ERR("g_bus_get_sync failed");
407 return ACCOUNT_ERROR_PERMISSION_DENIED;
410 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
411 GVariant *account_serialized_old = NULL;
412 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, &account_serialized_old, NULL, &error);
416 error_code = _account_get_error_code(is_success, error);
417 g_clear_error(&error);
418 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
421 g_clear_error(&error);
423 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
424 GVariant* account_serialized = marshal_account((account_s*) account);
425 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
429 error_code = _account_get_error_code(is_success, error);
430 g_clear_error(&error);
431 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error_code);
434 g_clear_error(&error);
436 _INFO("4. account_update_to_db_by_id end");
437 return ACCOUNT_ERROR_NONE;
440 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
443 ret = account_update_to_db_by_id(account, account_id);
448 ACCOUNT_INTERNAL_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
450 //First we will update account db
451 //Then we will update gSSO DB, if it fails then we will rollback account db updates
453 _INFO("account_update_to_db_by_id_without_permission start");
454 int error_code = ACCOUNT_ERROR_NONE;
456 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
457 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
459 GError *error = NULL;
461 AccountManager* acc_mgr = _account_manager_get_instance();
464 _ERR("g_bus_get_sync failed");
465 return ACCOUNT_ERROR_PERMISSION_DENIED;
468 GVariant *account_serialized_old = NULL;
469 _INFO("before query() account_id[%d]", account_id);
470 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, &account_serialized_old, NULL, &error);
474 error_code = _account_get_error_code(is_success, error);
475 g_clear_error(&error);
476 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
479 g_clear_error(&error);
481 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s*)account)->user_name);
482 GVariant* account_serialized = marshal_account((account_s*) account);
483 _INFO("after marshal() : account_id[%d]", account_id);
484 if (account_serialized == NULL)
486 _ERR("Invalid input");
487 return ACCOUNT_ERROR_INVALID_PARAMETER;
490 _INFO("before call update() : account_id[%d]", account_id);
491 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_serialized, account_id, NULL, &error);
493 _INFO("after call update() : is_success=%d", is_success);
496 error_code = _account_get_error_code(is_success, error);
497 g_clear_error(&error);
498 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error_code);
501 g_clear_error(&error);
503 return ACCOUNT_ERROR_NONE;
506 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
508 //First we will update account db
509 _INFO("account_update_to_db_by_user_name starting");
510 int error_code = ACCOUNT_ERROR_NONE;
512 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
513 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
514 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
516 GError *error = NULL;
518 AccountManager* acc_mgr = _account_manager_get_instance();
521 _ERR("g_bus_get_sync failed");
522 return ACCOUNT_ERROR_PERMISSION_DENIED;
525 GVariant *account_serialized_old = NULL;
526 account_s *account_data = (account_s*) account;
527 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_data->id, &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);
536 g_clear_error(&error);
538 GVariant* account_serialized = marshal_account(account_data);
539 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);
543 error_code = _account_get_error_code(is_success, error);
544 g_clear_error(&error);
545 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error_code);
548 g_clear_error(&error);
550 return ACCOUNT_ERROR_NONE;
553 ACCOUNT_API int account_create(account_h *account)
555 _INFO("account_create start");
557 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
558 return ACCOUNT_ERROR_INVALID_PARAMETER;
561 account_s *data = (account_s*)malloc(sizeof(account_s));
564 ACCOUNT_FATAL("Memory Allocation Failed");
565 return ACCOUNT_ERROR_OUT_OF_MEMORY;
567 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
569 /*Setting account as visible by default*/
570 data->secret = ACCOUNT_SECRECY_VISIBLE;
572 /*Setting account as not supporting sync by default*/
573 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
575 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
577 // data->account_list = NULL;
578 data->capablity_list = NULL;
579 data->custom_list = NULL;
580 // data->domain_list = NULL;
581 // data->mechanism_list = NULL;
583 *account = (account_h)data;
585 _INFO("account_create end");
586 return ACCOUNT_ERROR_NONE;
589 ACCOUNT_API int account_destroy(account_h account)
591 _INFO("account_destroy start");
592 account_s *data = (account_s*)account;
594 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
596 _account_free_account_with_items(data);
598 _INFO("account_destroy end");
599 return ACCOUNT_ERROR_NONE;
602 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
605 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
606 return ACCOUNT_ERROR_INVALID_PARAMETER;
610 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
611 return ACCOUNT_ERROR_INVALID_PARAMETER;
614 account_s *data = (account_s*)account;
616 _ACCOUNT_FREE(data->user_name);
617 data->user_name = _account_get_text(user_name);
619 return ACCOUNT_ERROR_NONE;
622 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
625 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
626 return ACCOUNT_ERROR_INVALID_PARAMETER;
630 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
631 return ACCOUNT_ERROR_INVALID_PARAMETER;
634 account_s *data = (account_s*)account;
636 _ACCOUNT_FREE(data->display_name);
637 data->display_name = _account_get_text(display_name);
639 return ACCOUNT_ERROR_NONE;
642 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
645 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
646 return ACCOUNT_ERROR_INVALID_PARAMETER;
649 if (!email_address) {
650 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
651 return ACCOUNT_ERROR_INVALID_PARAMETER;
654 account_s *data = (account_s*)account;
656 _ACCOUNT_FREE(data->email_address);
657 data->email_address = _account_get_text(email_address);
659 return ACCOUNT_ERROR_NONE;
662 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
665 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
666 return ACCOUNT_ERROR_INVALID_PARAMETER;
670 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
671 return ACCOUNT_ERROR_INVALID_PARAMETER;
674 account_s *data = (account_s*)account;
676 _ACCOUNT_FREE(data->icon_path);
677 data->icon_path = _account_get_text(icon_path);
679 return ACCOUNT_ERROR_NONE;
682 ACCOUNT_API int account_set_source(account_h account, const char *source)
685 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
686 return ACCOUNT_ERROR_INVALID_PARAMETER;
690 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
691 return ACCOUNT_ERROR_INVALID_PARAMETER;
693 account_s *data = (account_s*)account;
695 _ACCOUNT_FREE(data->source);
696 data->source = _account_get_text(source);
698 return ACCOUNT_ERROR_NONE;
701 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
704 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
705 return ACCOUNT_ERROR_INVALID_PARAMETER;
709 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
710 return ACCOUNT_ERROR_INVALID_PARAMETER;
713 account_s *data = (account_s*)account;
715 _ACCOUNT_FREE(data->package_name);
716 data->package_name = _account_get_text(package_name);
718 return ACCOUNT_ERROR_NONE;
721 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
724 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
725 return ACCOUNT_ERROR_INVALID_PARAMETER;
729 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
730 return ACCOUNT_ERROR_INVALID_PARAMETER;
732 account_s *data = (account_s*)account;
734 _ACCOUNT_FREE(data->domain_name);
735 data->domain_name = _account_get_text(domain_name);
737 return ACCOUNT_ERROR_NONE;
740 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
743 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
744 return ACCOUNT_ERROR_INVALID_PARAMETER;
748 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
749 return ACCOUNT_ERROR_INVALID_PARAMETER;
752 account_s *data = (account_s*)account;
754 _ACCOUNT_FREE(data->access_token);
755 data->access_token = _account_get_text(access_token);
757 return ACCOUNT_ERROR_NONE;
760 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
763 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
764 return ACCOUNT_ERROR_INVALID_PARAMETER;
768 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
769 return ACCOUNT_ERROR_INVALID_PARAMETER;
771 if (idx >= USER_TXT_CNT || idx < 0) {
772 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
773 return ACCOUNT_ERROR_INVALID_PARAMETER;
776 account_s *data = (account_s*)account;
778 _ACCOUNT_FREE(data->user_data_txt[idx]);
779 data->user_data_txt[idx] = _account_get_text(user_txt);
781 return ACCOUNT_ERROR_NONE;
784 ACCOUNT_API int account_set_custom(account_h account, const char* key, const char* value)
787 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
788 return ACCOUNT_ERROR_INVALID_PARAMETER;
792 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
793 return ACCOUNT_ERROR_INVALID_PARAMETER;
797 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
798 return ACCOUNT_ERROR_INVALID_PARAMETER;
801 account_s *data = (account_s*)account;
804 bool b_is_new = TRUE;
806 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
808 account_custom_s* custom_data = NULL;
809 custom_data = (account_custom_s*)iter->data;
810 ACCOUNT_SLOGD( "account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
812 if(!strcmp(custom_data->key, key)) {
813 _ACCOUNT_FREE(custom_data->value);
814 custom_data->value = _account_get_text(value);
820 account_custom_s* custom_data = (account_custom_s*)malloc(sizeof(account_custom_s));
822 if (custom_data == NULL) {
823 return ACCOUNT_ERROR_OUT_OF_MEMORY;
825 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
826 custom_data->account_id = data->id;
827 custom_data->app_id = _account_get_text(data->package_name);
828 custom_data->key = _account_get_text(key);
829 custom_data->value = _account_get_text(value);
830 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
833 return ACCOUNT_ERROR_NONE;
836 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
838 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
840 if ( ((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN)) {
841 return ACCOUNT_ERROR_INVALID_PARAMETER;
844 account_s *data = (account_s*)account;
846 data->auth_type = (int)auth_type;
848 return ACCOUNT_ERROR_NONE;
851 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
853 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
855 if ( ((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE)) {
856 return ACCOUNT_ERROR_INVALID_PARAMETER;
859 account_s *data = (account_s*)account;
861 data->secret = (int)secret;
863 return ACCOUNT_ERROR_NONE;
866 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
868 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
870 if ( ((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC)) {
871 return ACCOUNT_ERROR_INVALID_PARAMETER;
874 account_s *data = (account_s*)account;
876 data->sync_support= (int)sync_support;
878 return ACCOUNT_ERROR_NONE;
881 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
884 return ACCOUNT_ERROR_INVALID_PARAMETER;
887 if (idx >= USER_INT_CNT ||idx < 0) {
888 return ACCOUNT_ERROR_INVALID_PARAMETER;
891 account_s *data = (account_s*)account;
893 data->user_data_int[idx] = user_int;
895 return ACCOUNT_ERROR_NONE;
898 ACCOUNT_API int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_value)
900 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
901 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
903 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED)) {
904 return ACCOUNT_ERROR_INVALID_PARAMETER;
907 account_s *data = (account_s*)account;
910 bool b_is_new = TRUE;
912 for(iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
913 account_capability_s *cap_data = NULL;
914 cap_data = (account_capability_s*)iter->data;
916 if(!strcmp(cap_data->type, capability_type)) {
917 cap_data->value = capability_value;
924 account_capability_s* cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
926 if (cap_data == NULL)
927 return ACCOUNT_ERROR_OUT_OF_MEMORY;
928 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
930 cap_data->type = _account_get_text(capability_type);
931 cap_data->value = capability_value;
932 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
935 return ACCOUNT_ERROR_NONE;
938 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
941 return ACCOUNT_ERROR_INVALID_PARAMETER;
945 return ACCOUNT_ERROR_INVALID_PARAMETER;
948 account_s *data = (account_s*)account;
951 *user_name = _account_get_text(data->user_name);
953 return ACCOUNT_ERROR_NONE;
956 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
959 return ACCOUNT_ERROR_INVALID_PARAMETER;
963 return ACCOUNT_ERROR_INVALID_PARAMETER;
966 account_s *data = (account_s*)account;
968 (*display_name) = NULL;
970 *display_name = _account_get_text(data->display_name);
972 return ACCOUNT_ERROR_NONE;
975 ACCOUNT_API int account_get_email_address(account_h account,char **email_address)
978 return ACCOUNT_ERROR_INVALID_PARAMETER;
981 if (!email_address) {
982 return ACCOUNT_ERROR_INVALID_PARAMETER;
985 account_s *data = (account_s*)account;
987 (*email_address) = NULL;
989 *email_address = _account_get_text(data->email_address);
991 return ACCOUNT_ERROR_NONE;
994 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
997 return ACCOUNT_ERROR_INVALID_PARAMETER;
1001 return ACCOUNT_ERROR_INVALID_PARAMETER;
1004 account_s *data = (account_s*)account;
1006 (*icon_path) = NULL;
1008 *icon_path = _account_get_text(data->icon_path);
1010 return ACCOUNT_ERROR_NONE;
1013 ACCOUNT_API int account_get_source(account_h account, char **source)
1016 return ACCOUNT_ERROR_INVALID_PARAMETER;
1020 return ACCOUNT_ERROR_INVALID_PARAMETER;
1023 account_s *data = (account_s*)account;
1027 *source = _account_get_text(data->source);
1029 return ACCOUNT_ERROR_NONE;
1032 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1035 return ACCOUNT_ERROR_INVALID_PARAMETER;
1038 if (!package_name) {
1039 return ACCOUNT_ERROR_INVALID_PARAMETER;
1042 account_s *data = (account_s*)account;
1044 (*package_name) = NULL;
1046 *package_name = _account_get_text(data->package_name);
1048 return ACCOUNT_ERROR_NONE;
1051 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1054 return ACCOUNT_ERROR_INVALID_PARAMETER;
1058 return ACCOUNT_ERROR_INVALID_PARAMETER;
1061 account_s *data = (account_s*)account;
1063 (*domain_name) = NULL;
1065 *domain_name = _account_get_text(data->domain_name);
1067 return ACCOUNT_ERROR_NONE;
1070 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1073 return ACCOUNT_ERROR_INVALID_PARAMETER;
1076 if (!access_token) {
1077 return ACCOUNT_ERROR_INVALID_PARAMETER;
1080 account_s *data = (account_s*)account;
1082 (*access_token) = NULL;
1084 *access_token = _account_get_text(data->access_token);
1086 return ACCOUNT_ERROR_NONE;
1089 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1092 return ACCOUNT_ERROR_INVALID_PARAMETER;
1096 return ACCOUNT_ERROR_INVALID_PARAMETER;
1098 ACCOUNT_RETURN_VAL((user_text_index >=0 && user_text_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1100 account_s *data = (account_s*)account;
1104 *text = _account_get_text(data->user_data_txt[user_text_index]);
1106 return ACCOUNT_ERROR_NONE;
1109 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1112 return ACCOUNT_ERROR_INVALID_PARAMETER;
1115 return ACCOUNT_ERROR_INVALID_PARAMETER;
1118 account_s* data = (account_s*)account;
1120 *auth_type = data->auth_type;
1122 return ACCOUNT_ERROR_NONE;
1125 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1128 return ACCOUNT_ERROR_INVALID_PARAMETER;
1131 return ACCOUNT_ERROR_INVALID_PARAMETER;
1134 account_s* data = (account_s*)account;
1136 *secret = data->secret;
1138 return ACCOUNT_ERROR_NONE;
1141 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1144 return ACCOUNT_ERROR_INVALID_PARAMETER;
1146 if (!sync_support) {
1147 return ACCOUNT_ERROR_INVALID_PARAMETER;
1150 account_s* data = (account_s*)account;
1152 *sync_support = data->sync_support;
1154 return ACCOUNT_ERROR_NONE;
1157 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1160 return ACCOUNT_ERROR_INVALID_PARAMETER;
1163 return ACCOUNT_ERROR_INVALID_PARAMETER;
1166 account_s *data = (account_s*)account;
1168 *account_id = data->id;
1170 return ACCOUNT_ERROR_NONE;
1173 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1176 return ACCOUNT_ERROR_INVALID_PARAMETER;
1179 ACCOUNT_RETURN_VAL((user_int_index >=0 && user_int_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1182 return ACCOUNT_ERROR_INVALID_PARAMETER;
1185 account_s *data = (account_s*)account;
1187 *integer = data->user_data_int[user_int_index];
1189 return ACCOUNT_ERROR_NONE;
1192 ACCOUNT_API int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value)
1194 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1195 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1196 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1199 account_s *data = (account_s*)account;
1201 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1202 account_capability_s *cap_data = NULL;
1204 cap_data = (account_capability_s*)iter->data;
1206 if(!strcmp(capability_type, cap_data->type)) {
1207 *capability_value = cap_data->value;
1208 return ACCOUNT_ERROR_NONE;
1212 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1215 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1217 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1218 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1221 account_s *data = (account_s*)account;
1223 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1224 account_capability_s *cap_data = NULL;
1226 cap_data = (account_capability_s*)iter->data;
1228 if(callback(cap_data->type, cap_data->value, user_data)!=TRUE){
1229 return ACCOUNT_ERROR_NONE;
1233 return ACCOUNT_ERROR_NONE;
1236 ACCOUNT_API int account_get_custom(account_h account, const char* key, char** value)
1238 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1239 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1240 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1243 account_s *data = (account_s*)account;
1245 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1246 account_custom_s *custom_data = NULL;
1248 custom_data = (account_custom_s*)iter->data;
1250 if(!strcmp(key, custom_data->key)) {
1252 *value = _account_get_text(custom_data->value);
1253 return ACCOUNT_ERROR_NONE;
1257 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1260 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void* user_data)
1262 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1263 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1266 account_s *data = (account_s*)account;
1268 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1269 bool cb_ret = FALSE;
1270 account_custom_s *custom_data = NULL;
1272 custom_data = (account_custom_s*)iter->data;
1274 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1280 return ACCOUNT_ERROR_NONE;
1283 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1285 _INFO("account_foreach_account_from_db start");
1287 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1289 GError *error = NULL;
1291 AccountManager* acc_mgr = _account_manager_get_instance();
1292 if (acc_mgr == NULL)
1294 _ERR("g_bus_get_sync failed");
1295 return ACCOUNT_ERROR_PERMISSION_DENIED;
1298 GVariant* account_list_variant = NULL;
1299 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, &account_list_variant, NULL, &error);
1301 int error_code = _account_get_error_code(is_success, error);
1302 g_clear_error(&error);
1304 if (error_code != ACCOUNT_ERROR_NONE)
1309 GSList* account_list = unmarshal_account_list(account_list_variant);
1310 g_variant_unref(account_list_variant);
1314 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1316 _INFO("iterating received account_list");
1317 account_s *account = NULL;
1318 account = (account_s*)iter->data;
1319 _INFO("Before _account_query_identity_info_by_id");
1321 _INFO("account->id=%d", account->id);
1322 if (callback((account_h)account, user_data) == false)
1324 _INFO("application callback requested to discontinue.");
1327 _INFO("After one iteration callback");
1329 _account_gslist_account_free(account_list);
1331 _INFO("account_foreach_account_from_db end");
1332 return ACCOUNT_ERROR_NONE;
1335 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1337 _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1339 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1340 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT POINTER IS NULL"));
1341 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1343 GError *error = NULL;
1345 AccountManager* acc_mgr = _account_manager_get_instance();
1346 if (acc_mgr == NULL)
1348 _ERR("g_bus_get_sync failed");
1349 return ACCOUNT_ERROR_PERMISSION_DENIED;
1352 GVariant* account_variant = NULL;
1353 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, &account_variant, NULL, &error);
1355 int error_code = _account_get_error_code(is_success, error);
1356 g_clear_error(&error);
1357 if (error_code != ACCOUNT_ERROR_NONE)
1362 _INFO("before unmarshal_account");
1363 account_s* account_data = umarshal_account(account_variant);
1364 _INFO("after unmarshal_account");
1366 if (account_data == NULL)
1368 _ERR("Failed to unmarshal");
1369 return ACCOUNT_ERROR_DB_FAILED;
1372 account_s **input = (account_s **)account;
1374 _account_free_account_with_items(*input);
1376 *input = account_data;
1378 _INFO("account_query_account_by_account_id end");
1380 return ACCOUNT_ERROR_NONE;
1383 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char* user_name, void* user_data)
1385 _INFO("account_query_account_by_user_name starting");
1387 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1388 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1390 GError *error = NULL;
1392 AccountManager* acc_mgr = _account_manager_get_instance();
1393 if (acc_mgr == NULL)
1395 _ERR("g_bus_get_sync failed");
1396 return ACCOUNT_ERROR_PERMISSION_DENIED;
1399 GVariant* account_list_variant = NULL;
1400 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, &account_list_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)
1409 GSList* account_list = unmarshal_account_list(account_list_variant);
1410 g_variant_unref(account_list_variant);
1412 if (account_list == NULL)
1414 return ACCOUNT_ERROR_NO_DATA;
1419 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1421 _INFO("iterating received account_list");
1422 account_s *account = NULL;
1423 account = (account_s*)iter->data;
1424 if (callback((account_h)account, user_data) == false)
1426 _INFO("application callback requested to discontinue.");
1430 _INFO("account_query_account_by_user_name end");
1432 _account_gslist_account_free(account_list);
1433 return ACCOUNT_ERROR_NONE;
1436 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1438 _INFO("account_query_account_by_package_name starting");
1440 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1441 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1443 GError *error = NULL;
1445 AccountManager* acc_mgr = _account_manager_get_instance();
1446 if (acc_mgr == NULL)
1448 _ERR("g_bus_get_sync failed");
1449 return ACCOUNT_ERROR_PERMISSION_DENIED;
1452 GVariant* account_list_variant = NULL;
1453 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, package_name, &account_list_variant, NULL, &error);
1455 int error_code = _account_get_error_code(is_success, error);
1456 g_clear_error(&error);
1457 if (error_code != ACCOUNT_ERROR_NONE)
1462 GSList* account_list = unmarshal_account_list(account_list_variant);
1463 g_variant_unref(account_list_variant);
1465 if (account_list == NULL)
1467 return ACCOUNT_ERROR_NO_DATA;
1472 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1474 _INFO("iterating received account_list");
1475 account_s *account = NULL;
1476 account = (account_s*)iter->data;
1478 if (callback((account_h)account, user_data) == false)
1480 _INFO("application callback requested to discontinue.");
1484 _account_gslist_account_free(account_list);
1485 _INFO("account_query_account_by_package_name end");
1486 return ACCOUNT_ERROR_NONE;
1489 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char* capability_type, account_capability_state_e capability_value, void *user_data)
1491 _INFO("account_query_account_by_capability starting");
1493 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1495 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1496 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1497 return ACCOUNT_ERROR_INVALID_PARAMETER;
1500 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1502 GError *error = NULL;
1504 AccountManager* acc_mgr = _account_manager_get_instance();
1505 if (acc_mgr == NULL)
1507 _ERR("g_bus_get_sync failed");
1508 return ACCOUNT_ERROR_PERMISSION_DENIED;
1511 GVariant* account_list_variant = NULL;
1512 bool is_success = account_manager_call_account_query_account_by_capability_sync(acc_mgr, capability_type, capability_value, &account_list_variant, NULL, &error);
1514 int error_code = _account_get_error_code(is_success, error);
1515 g_clear_error(&error);
1516 if (error_code != ACCOUNT_ERROR_NONE)
1521 GSList* account_list = unmarshal_account_list(account_list_variant);
1522 g_variant_unref(account_list_variant);
1523 if (account_list == NULL)
1525 return ACCOUNT_ERROR_NO_DATA;
1530 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1532 _INFO("iterating received account_list");
1533 account_s *account = NULL;
1534 account = (account_s*)iter->data;
1536 if (callback((account_h)account, user_data) == false)
1538 _INFO("application callback requested to discontinue.");
1542 _account_gslist_account_free(account_list);
1543 _INFO("account_query_account_by_capability end");
1544 return ACCOUNT_ERROR_NONE;
1547 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char* capability_type, void* user_data)
1549 _INFO("account_query_account_by_capability_type starting");
1551 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1552 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1554 GError *error = NULL;
1556 AccountManager* acc_mgr = _account_manager_get_instance();
1557 if (acc_mgr == NULL)
1559 _ERR("g_bus_get_sync failed");
1560 return ACCOUNT_ERROR_PERMISSION_DENIED;
1563 GVariant* account_list_variant = NULL;
1564 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, capability_type, &account_list_variant, NULL, &error);
1566 int error_code = _account_get_error_code(is_success, error);
1567 g_clear_error(&error);
1568 if (error_code != ACCOUNT_ERROR_NONE)
1573 GSList* account_list = unmarshal_account_list(account_list_variant);
1574 g_variant_unref(account_list_variant);
1576 if (account_list == NULL)
1578 return ACCOUNT_ERROR_NO_DATA;
1583 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1585 _INFO("iterating received account_list");
1586 account_s *account = NULL;
1587 account = (account_s*)iter->data;
1589 if (callback((account_h)account, user_data) == false)
1591 _INFO("application callback requested to discontinue.");
1595 _account_gslist_account_free(account_list);
1596 _INFO("account_query_account_by_capability end");
1597 return ACCOUNT_ERROR_NONE;
1600 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1602 _INFO("account_query_capability_by_account_id starting");
1604 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1605 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1607 GError *error = NULL;
1608 AccountManager* acc_mgr = _account_manager_get_instance();
1609 if (acc_mgr == NULL)
1611 _ERR("g_bus_get_sync failed");
1612 return ACCOUNT_ERROR_PERMISSION_DENIED;
1615 GVariant* capability_list_variant = NULL;
1616 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_id, &capability_list_variant, NULL, &error);
1618 int error_code = _account_get_error_code(is_success, error);
1619 g_clear_error(&error);
1620 if (error_code != ACCOUNT_ERROR_NONE)
1625 _INFO("before unmarshal_capability_list");
1626 GSList* capability_list = unmarshal_capability_list(capability_list_variant);
1627 _INFO("after unmarshal_capability_list");
1628 if (capability_list == NULL)
1630 return ACCOUNT_ERROR_NO_DATA;
1635 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter))
1637 _INFO("iterating received account_list");
1638 account_capability_s *capability = NULL;
1639 capability = (account_capability_s*)iter->data;
1641 if (callback(capability->type, capability->value, user_data) == false)
1643 _INFO("application callback requested to discontinue.");
1649 _account_gslist_capability_free(capability_list);
1650 _INFO("account_query_capability_by_account_id end");
1651 return ACCOUNT_ERROR_NONE;
1654 static int _account_get_total_count(int *count, bool include_hidden)
1656 _INFO("account_get_total_count_from_db starting");
1660 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1661 return ACCOUNT_ERROR_INVALID_PARAMETER;
1664 GError *error = NULL;
1668 _INFO("Invalid input");
1672 AccountManager* acc_mgr = _account_manager_get_instance();
1673 if (acc_mgr == NULL)
1675 _ERR("g_bus_get_sync failed");
1676 return ACCOUNT_ERROR_PERMISSION_DENIED;
1679 int temp_count = -1;
1680 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, include_hidden, &temp_count, NULL, &error);
1681 int error_code = _account_get_error_code(is_success, error);
1682 g_clear_error(&error);
1683 if (error_code != ACCOUNT_ERROR_NONE)
1688 *count = temp_count;
1689 _INFO("account_get_total_count_from_db end");
1690 return ACCOUNT_ERROR_NONE;
1693 ACCOUNT_API int account_get_total_count_from_db(int *count)
1695 _INFO("account_get_total_count_from_db starting");
1697 return _account_get_total_count(count, true);
1700 ACCOUNT_INTERNAL_API int account_get_total_count_from_db_ex(int *count)
1702 _INFO("account_get_total_count_from_db_ex starting");
1704 return _account_get_total_count(count, false);
1707 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1709 _INFO("account_update_sync_status_by_id starting");
1710 int error_code = ACCOUNT_ERROR_NONE;
1712 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1713 if ( ((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1714 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1715 return ACCOUNT_ERROR_INVALID_PARAMETER;
1718 GError *error = NULL;
1720 AccountManager* acc_mgr = _account_manager_get_instance();
1721 if (acc_mgr == NULL)
1723 _ERR("g_bus_get_sync failed");
1724 return ACCOUNT_ERROR_PERMISSION_DENIED;
1727 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_id, sync_status, (int)getuid(), NULL, &error);
1729 error_code = _account_get_error_code(is_success, error);
1730 g_clear_error(&error);
1736 static int _account_type_free_label_items(label_s *data)
1739 return ACCOUNT_ERROR_INVALID_PARAMETER;
1742 _ACCOUNT_FREE(data->app_id);
1743 _ACCOUNT_FREE(data->label);
1744 _ACCOUNT_FREE(data->locale);
1746 return ACCOUNT_ERROR_NONE;
1749 static int _account_type_label_gslist_free(GSList* list)
1751 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
1755 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
1756 label_s *label_data = (label_s*)iter->data;
1757 _account_type_free_label_items(label_data);
1758 _ACCOUNT_FREE(label_data);
1764 return ACCOUNT_ERROR_NONE;
1767 static int _account_type_free_provider_feature_items(provider_feature_s *data)
1770 return ACCOUNT_ERROR_INVALID_PARAMETER;
1773 _ACCOUNT_FREE(data->key);
1774 _ACCOUNT_FREE(data->app_id);
1776 return ACCOUNT_ERROR_NONE;
1779 static int _account_type_provider_feature_gslist_free(GSList* list)
1781 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
1785 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
1786 provider_feature_s *feature_data = (provider_feature_s*)iter->data;
1787 _account_type_free_provider_feature_items(feature_data);
1788 _ACCOUNT_FREE(feature_data);
1794 return ACCOUNT_ERROR_NONE;
1797 static int _account_type_free_account_type_items(account_type_s *data)
1800 return ACCOUNT_ERROR_INVALID_PARAMETER;
1803 _ACCOUNT_FREE(data->app_id);
1804 _ACCOUNT_FREE(data->service_provider_id);
1805 _ACCOUNT_FREE(data->icon_path);
1806 _ACCOUNT_FREE(data->small_icon_path);
1808 _account_type_label_gslist_free(data->label_list);
1809 _account_type_provider_feature_gslist_free(data->provider_feature_list);
1810 // _account_type_glist_free(data->account_type_list);
1812 return ACCOUNT_ERROR_NONE;
1815 static int _account_type_gslist_free(GSList* list)
1817 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Glist is NULL"));
1821 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
1822 account_type_s *account_type_record = (account_type_s*)iter->data;
1823 _account_type_free_account_type_items(account_type_record);
1824 _ACCOUNT_FREE(account_type_record);
1830 return ACCOUNT_ERROR_NONE;
1835 static int _account_type_glist_free(GList* list)
1837 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Glist is NULL"));
1841 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
1842 account_type_s *account_type_record = (account_type_s*)iter->data;
1843 _account_type_free_account_type_items(account_type_record);
1844 _ACCOUNT_FREE(account_type_record);
1850 return ACCOUNT_ERROR_NONE;
1854 ACCOUNT_API int account_type_create(account_type_h *account_type)
1856 if (!account_type) {
1857 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1858 return ACCOUNT_ERROR_INVALID_PARAMETER;
1861 account_type_s *data = (account_type_s*)malloc(sizeof(account_type_s));
1865 ACCOUNT_ERROR("Memory Allocation Failed");
1866 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1869 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1872 data->app_id = NULL;
1873 data->service_provider_id = NULL;
1874 data->icon_path = NULL;
1875 data->small_icon_path = NULL;
1876 data->multiple_account_support = false;
1877 data->label_list = NULL;
1878 // data->account_type_list = NULL;
1879 data->provider_feature_list = NULL;
1881 *account_type = (account_type_h)data;
1883 return ACCOUNT_ERROR_NONE;
1886 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1888 _INFO("account_type_destroy");
1890 account_type_s *data = (account_type_s*)account_type;
1894 _ERR("Account type handle is null!");
1895 return ACCOUNT_ERROR_INVALID_PARAMETER;
1898 _account_type_free_account_type_with_items(data);
1900 return ACCOUNT_ERROR_NONE;
1903 ACCOUNT_INTERNAL_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1905 if (!account_type) {
1906 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1907 return ACCOUNT_ERROR_INVALID_PARAMETER;
1911 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1912 return ACCOUNT_ERROR_INVALID_PARAMETER;
1915 account_type_s *data = (account_type_s*)account_type;
1917 _ACCOUNT_FREE(data->app_id);
1918 data->app_id = _account_get_text(app_id);
1920 return ACCOUNT_ERROR_NONE;
1923 ACCOUNT_INTERNAL_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1925 if (!account_type) {
1926 return ACCOUNT_ERROR_INVALID_PARAMETER;
1929 if (!service_provider_id) {
1930 return ACCOUNT_ERROR_INVALID_PARAMETER;
1933 account_type_s *data = (account_type_s*)account_type;
1935 _ACCOUNT_FREE(data->service_provider_id);
1936 data->service_provider_id = _account_get_text(service_provider_id);
1938 return ACCOUNT_ERROR_NONE;
1941 ACCOUNT_INTERNAL_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1943 if (!account_type) {
1944 return ACCOUNT_ERROR_INVALID_PARAMETER;
1948 return ACCOUNT_ERROR_INVALID_PARAMETER;
1951 account_type_s *data = (account_type_s*)account_type;
1953 _ACCOUNT_FREE(data->icon_path);
1954 data->icon_path = _account_get_text(icon_path);
1956 return ACCOUNT_ERROR_NONE;
1959 ACCOUNT_INTERNAL_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
1961 if (!account_type) {
1962 return ACCOUNT_ERROR_INVALID_PARAMETER;
1965 if (!small_icon_path) {
1966 return ACCOUNT_ERROR_INVALID_PARAMETER;
1969 account_type_s *data = (account_type_s*)account_type;
1971 _ACCOUNT_FREE(data->small_icon_path);
1972 data->small_icon_path = _account_get_text(small_icon_path);
1974 return ACCOUNT_ERROR_NONE;
1977 ACCOUNT_INTERNAL_API int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
1979 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1981 account_type_s *data = (account_type_s*)account_type;
1983 data->multiple_account_support = multiple_account_support;
1985 return ACCOUNT_ERROR_NONE;
1988 ACCOUNT_INTERNAL_API int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
1990 if (!account_type) {
1991 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1992 return ACCOUNT_ERROR_INVALID_PARAMETER;
1995 if(!label || !locale) {
1996 return ACCOUNT_ERROR_INVALID_PARAMETER;
1999 account_type_s *data = (account_type_s*)account_type;
2000 label_s *label_data = (label_s*)malloc(sizeof(label_s));
2002 if (label_data == NULL) {
2003 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2005 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
2007 label_data->label = _account_get_text(label);
2008 label_data->locale = _account_get_text(locale);
2010 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
2012 return ACCOUNT_ERROR_NONE;
2015 ACCOUNT_INTERNAL_API int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature)
2017 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
2018 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
2020 account_type_s *data = (account_type_s*)account_type;
2022 GSList *iter = NULL;
2023 bool b_is_new = TRUE;
2025 for(iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2026 provider_feature_s *feature_data = NULL;
2027 feature_data = (provider_feature_s*)iter->data;
2029 if(!strcmp(feature_data->key, provider_feature)) {
2036 provider_feature_s* feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
2038 if (feature_data == NULL)
2039 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2040 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
2042 feature_data->key = _account_get_text(provider_feature);
2043 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
2046 return ACCOUNT_ERROR_NONE;
2049 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
2051 _INFO("account_type_query_provider_feature_by_app_id start");
2053 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2054 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2056 GError *error = NULL;
2057 gint error_code = ACCOUNT_ERROR_NONE;
2059 AccountManager* acc_mgr = _account_manager_get_instance();
2060 if (acc_mgr == NULL)
2062 _ERR("g_bus_get_sync failed");
2063 return ACCOUNT_ERROR_PERMISSION_DENIED;
2066 GVariant* feature_list_variant = NULL;
2067 bool is_success = account_manager_call_account_type_query_provider_feature_by_app_id_sync(acc_mgr, app_id, &feature_list_variant, NULL, &error);
2069 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
2073 error_code = _account_get_error_code(is_success, error);
2074 g_clear_error(&error);
2075 _ERR("Account IPC call returned error[%d]", error_code);
2078 g_clear_error(&error);
2080 GSList* provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
2081 if (provider_feature_list == NULL)
2083 error_code = ACCOUNT_ERROR_NO_DATA;
2084 _ERR("[%d]", error_code);
2089 for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2090 provider_feature_s *feature_data = NULL;
2092 feature_data = (provider_feature_s*)iter->data;
2094 if(callback(feature_data->app_id, feature_data->key, user_data)!=TRUE) {
2095 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2096 return ACCOUNT_ERROR_NONE;
2100 _account_type_gslist_feature_free(provider_feature_list);
2101 _INFO("account_type_query_provider_feature_by_app_id end");
2105 ACCOUNT_API bool account_type_query_supported_feature(const char* app_id, const char* capability)
2107 _INFO("account_type_query_supported_feature start");
2109 if (app_id == NULL || capability == NULL)
2111 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2115 int is_supported = 0;
2116 GError *error = NULL;
2117 gint ret = ACCOUNT_ERROR_NONE;
2119 AccountManager* acc_mgr = _account_manager_get_instance();
2120 if (acc_mgr == NULL)
2122 _ERR("g_bus_get_sync failed");
2123 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2127 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, app_id, capability, &is_supported, NULL, &error);
2129 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2133 ret = _account_get_error_code(is_success, error);
2134 g_clear_error(&error);
2135 _ERR("Account IPC call returned error[%d]", ret);
2136 set_last_result(ret);
2139 g_clear_error(&error);
2141 set_last_result(ACCOUNT_ERROR_NONE);
2142 _INFO("account_type_query_supported_feature end");
2143 return is_supported;
2146 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2148 if (!account_type) {
2149 return ACCOUNT_ERROR_INVALID_PARAMETER;
2153 return ACCOUNT_ERROR_INVALID_PARAMETER;
2156 account_type_s *data = (account_type_s*)account_type;
2159 *app_id = _account_get_text(data->app_id);
2161 return ACCOUNT_ERROR_NONE;
2164 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2166 if (!account_type) {
2167 return ACCOUNT_ERROR_INVALID_PARAMETER;
2170 if (!service_provider_id) {
2171 return ACCOUNT_ERROR_INVALID_PARAMETER;
2174 account_type_s *data = (account_type_s*)account_type;
2176 (*service_provider_id) = NULL;
2177 *service_provider_id = _account_get_text(data->service_provider_id);
2179 return ACCOUNT_ERROR_NONE;
2182 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2184 if (!account_type) {
2185 return ACCOUNT_ERROR_INVALID_PARAMETER;
2189 return ACCOUNT_ERROR_INVALID_PARAMETER;
2192 account_type_s *data = (account_type_s*)account_type;
2194 (*icon_path) = NULL;
2195 *icon_path = _account_get_text(data->icon_path);
2197 return ACCOUNT_ERROR_NONE;
2200 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2202 if (!account_type) {
2203 return ACCOUNT_ERROR_INVALID_PARAMETER;
2206 if (!small_icon_path) {
2207 return ACCOUNT_ERROR_INVALID_PARAMETER;
2210 account_type_s *data = (account_type_s*)account_type;
2212 (*small_icon_path) = NULL;
2213 *small_icon_path = _account_get_text(data->small_icon_path);
2215 return ACCOUNT_ERROR_NONE;
2218 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2220 if (!account_type) {
2221 return ACCOUNT_ERROR_INVALID_PARAMETER;
2223 if (!multiple_account_support) {
2224 return ACCOUNT_ERROR_INVALID_PARAMETER;
2227 account_type_s *data = (account_type_s*)account_type;
2229 *multiple_account_support = data->multiple_account_support;
2231 return ACCOUNT_ERROR_NONE;
2234 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void* user_data)
2236 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2237 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2240 account_type_s *data = (account_type_s*)account_type;
2242 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2243 provider_feature_s *feature_data = NULL;
2245 feature_data = (provider_feature_s*)iter->data;
2247 if(callback(feature_data->app_id, feature_data->key, user_data)!=TRUE) {
2248 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2249 return ACCOUNT_ERROR_NONE;
2253 return ACCOUNT_ERROR_NONE;
2256 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char* locale, char** label)
2258 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2259 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2262 account_type_s *data = (account_type_s*)account_type;
2264 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2265 label_s *label_data = NULL;
2267 label_data = (label_s*)iter->data;
2271 if(!strcmp(locale, label_data->locale)) {
2272 *label = _account_get_text(label_data->label);
2273 return ACCOUNT_ERROR_NONE;
2275 gchar** tokens = g_strsplit(locale, "-", 2);
2276 if(tokens != NULL) {
2277 if((char*)(tokens[1]) != NULL) {
2278 char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2279 if(upper_token != NULL) {
2280 char* converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2281 if(!strcmp(converted_locale, label_data->locale)) {
2282 _ACCOUNT_FREE(converted_locale);
2283 _ACCOUNT_FREE(upper_token);
2285 *label = _account_get_text(label_data->label);
2286 return ACCOUNT_ERROR_NONE;
2288 _ACCOUNT_FREE(converted_locale);
2290 _ACCOUNT_FREE(upper_token);
2296 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2299 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2301 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2302 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2305 account_type_s *data = (account_type_s*)account_type;
2307 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2308 label_s *label_data = NULL;
2310 label_data = (label_s*)iter->data;
2312 if(callback(label_data->app_id, label_data->label, label_data->locale, user_data)!=TRUE) {
2313 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2314 return ACCOUNT_ERROR_NONE;
2318 return ACCOUNT_ERROR_NONE;
2321 ACCOUNT_INTERNAL_API int account_type_insert_to_db(account_type_h account_type, int* account_type_id)
2323 _INFO("account_type_insert_to_db starting");
2325 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2326 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2328 GError *error = NULL;
2330 AccountManager* acc_mgr = _account_manager_get_instance();
2331 if (acc_mgr == NULL)
2333 _ERR("g_bus_get_sync failed");
2334 return ACCOUNT_ERROR_PERMISSION_DENIED;
2338 GVariant* account_type_serialized = marshal_account_type((account_type_s*) account_type);
2339 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_type_serialized, &db_id, NULL, &error);
2341 int ret = _account_get_error_code(is_success, error);
2342 g_clear_error(&error);
2344 if (ret != ACCOUNT_ERROR_NONE)
2349 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2351 *account_type_id = db_id;
2353 account_type_s* account_type_data = (account_type_s*)account_type;
2354 account_type_data->id = db_id;
2356 return ACCOUNT_ERROR_NONE;
2359 ACCOUNT_INTERNAL_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char* app_id)
2361 _INFO("account_type_update_to_db_by_app_id starting");
2362 int error_code = ACCOUNT_ERROR_NONE;
2364 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2365 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2367 GError *error = NULL;
2369 AccountManager* acc_mgr = _account_manager_get_instance();
2370 if (acc_mgr == NULL)
2372 _ERR("g_bus_get_sync failed");
2373 return ACCOUNT_ERROR_PERMISSION_DENIED;
2376 GVariant* account_type_variant = marshal_account_type((account_type_s*) account_type);
2377 if (account_type_variant == NULL)
2379 _ERR("Failed to serialize");
2380 return ACCOUNT_ERROR_INVALID_PARAMETER;
2383 bool is_success = account_manager_call_account_type_update_to_db_by_app_id_sync(acc_mgr, account_type_variant, app_id, NULL, &error);
2385 error_code = _account_get_error_code(is_success, error);
2386 g_clear_error(&error);
2391 ACCOUNT_INTERNAL_API int account_type_delete_by_app_id(const char* app_id)
2393 _INFO("account_type_delete_by_app_id starting");
2394 int error_code = ACCOUNT_ERROR_NONE;
2396 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2398 GError *error = NULL;
2400 AccountManager* acc_mgr = _account_manager_get_instance();
2401 if (acc_mgr == NULL)
2403 _ERR("g_bus_get_sync failed");
2404 return ACCOUNT_ERROR_PERMISSION_DENIED;
2407 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, app_id, NULL, &error);
2409 error_code = _account_get_error_code(is_success, error);
2410 g_clear_error(&error);
2415 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
2417 _INFO("account_type_query_label_by_app_id starting");
2419 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2420 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2422 GError *error = NULL;
2424 AccountManager* acc_mgr = _account_manager_get_instance();
2425 if (acc_mgr == NULL)
2427 _ERR("g_bus_get_sync failed");
2428 return ACCOUNT_ERROR_PERMISSION_DENIED;
2431 GVariant* label_list_variant = NULL;
2432 bool is_success = account_manager_call_account_type_query_label_by_app_id_sync(acc_mgr, app_id, &label_list_variant, NULL, &error);
2434 int ret = _account_get_error_code(is_success, error);
2435 g_clear_error(&error);
2437 if (ret != ACCOUNT_ERROR_NONE)
2442 _INFO("before variant_to_label_list");
2443 GSList* label_list = variant_to_label_list (label_list_variant);
2444 _INFO("after variant_to_label_list");
2445 if (label_list == NULL)
2447 return ACCOUNT_ERROR_NO_DATA;
2452 for (iter = label_list; iter != NULL; iter = g_slist_next(iter))
2454 _INFO("iterating received account_list");
2455 label_s *label_record = NULL;
2456 label_record = (label_s*)iter->data;
2458 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false)
2460 _INFO("application callback requested to discontinue.");
2466 _account_type_gslist_label_free(label_list);
2467 _INFO("account_type_query_label_by_app_id end");
2468 return ACCOUNT_ERROR_NONE;
2471 ACCOUNT_API int account_type_query_by_app_id(const char* app_id, account_type_h *account_type)
2473 _INFO("account_type_query_by_app_id starting");
2475 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2476 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2477 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2479 GError *error = NULL;
2481 AccountManager* acc_mgr = _account_manager_get_instance();
2482 if (acc_mgr == NULL)
2484 _ERR("g_bus_get_sync failed");
2485 return ACCOUNT_ERROR_PERMISSION_DENIED;
2488 GVariant* account_type_variant = NULL;
2489 account_type_s *in_data = (account_type_s*) (*account_type);
2491 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, app_id, &account_type_variant, NULL, &error);
2493 int ret = _account_get_error_code(is_success, error);
2494 g_clear_error(&error);
2496 if (ret != ACCOUNT_ERROR_NONE)
2501 account_type_s* received_account_type = umarshal_account_type (account_type_variant);
2502 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2504 in_data->id = received_account_type->id;
2505 in_data->app_id = received_account_type->app_id;
2506 in_data->service_provider_id = received_account_type->service_provider_id;
2507 in_data->icon_path = received_account_type->icon_path;
2508 in_data->small_icon_path = received_account_type->small_icon_path;
2509 in_data->multiple_account_support = received_account_type->multiple_account_support;
2510 in_data->label_list = received_account_type->label_list;
2511 in_data->provider_feature_list = received_account_type->provider_feature_list;
2513 _ACCOUNT_FREE(received_account_type);
2514 _INFO("account_type_query_by_app_id end");
2515 return ACCOUNT_ERROR_NONE;
2518 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2520 _INFO("account_type_foreach_account_type_from_db starting");
2522 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2524 GError *error = NULL;
2526 AccountManager* acc_mgr = _account_manager_get_instance();
2527 if (acc_mgr == NULL)
2529 _ERR("g_bus_get_sync failed");
2530 return ACCOUNT_ERROR_PERMISSION_DENIED;
2533 GVariant* account_type_list_variant = NULL;
2534 _INFO("before account_type_query_all_sync()");
2535 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, &account_type_list_variant, NULL, &error);
2537 _INFO("after account_type_query_all_sync()");
2538 int ret = _account_get_error_code(is_success, error);
2539 g_clear_error(&error);
2541 if (ret != ACCOUNT_ERROR_NONE)
2546 GSList* account_type_list = unmarshal_account_type_list(account_type_list_variant);
2547 g_variant_unref(account_type_list_variant);
2549 if (account_type_list == NULL)
2551 return ACCOUNT_ERROR_NO_DATA;
2556 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2558 _INFO("iterating received account_list");
2559 account_type_s *account_type = NULL;
2560 account_type = (account_type_s*)iter->data;
2562 if (callback((account_type_h)account_type, user_data) == false)
2564 _INFO("application callback requested to discontinue.");
2569 _account_type_gslist_account_type_free(account_type_list);
2570 _INFO("account_type_foreach_account_type_from_db end");
2571 return ACCOUNT_ERROR_NONE;
2574 ACCOUNT_API int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label)
2576 _INFO("account_type_query_label_by_locale starting");
2578 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2579 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2580 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2582 GError *error = NULL;
2584 AccountManager* acc_mgr = _account_manager_get_instance();
2585 if (acc_mgr == NULL)
2587 _ERR("g_bus_get_sync failed");
2588 return ACCOUNT_ERROR_PERMISSION_DENIED;
2591 char* label_temp = NULL;
2592 _INFO("before account_type_query_label_by_locale_sync()");
2593 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, app_id, locale, &label_temp, NULL, &error);
2595 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2596 int ret = _account_get_error_code(is_success, error);
2597 g_clear_error(&error);
2599 if (ret != ACCOUNT_ERROR_NONE)
2604 if (label_temp == NULL)
2606 return ACCOUNT_ERROR_NO_DATA;
2609 *label = _account_get_text(label_temp);
2610 _INFO("account_type_query_label_by_locale end");
2611 return ACCOUNT_ERROR_NONE;
2615 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char* key, void* user_data)
2617 _INFO("account_type_query_by_provider_feature starting");
2619 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2620 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2622 GError *error = NULL;
2624 AccountManager* acc_mgr = _account_manager_get_instance();
2625 if (acc_mgr == NULL)
2627 _ERR("g_bus_get_sync failed");
2628 return ACCOUNT_ERROR_PERMISSION_DENIED;
2631 GVariant* account_type_list_variant = NULL;
2632 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, key, &account_type_list_variant, NULL, &error);
2634 int ret = _account_get_error_code(is_success, error);
2635 g_clear_error(&error);
2637 if (ret != ACCOUNT_ERROR_NONE)
2642 _INFO("before unmarshal_account_type_list");
2643 GSList* account_type_list = unmarshal_account_type_list(account_type_list_variant);
2644 g_variant_unref(account_type_list_variant);
2646 if (account_type_list == NULL)
2648 return ACCOUNT_ERROR_NO_DATA;
2653 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2655 _INFO("iterating received account_type_list");
2656 account_type_s *account_type = NULL;
2657 account_type = (account_type_s*)iter->data;
2659 if (callback((account_type_h)account_type, user_data) == false)
2661 _INFO("Application callback requested not to continue");
2667 _account_type_gslist_account_type_free(account_type_list);
2668 _INFO("account_type_query_by_provider_feature end");
2669 return ACCOUNT_ERROR_NONE;
2672 ACCOUNT_API int account_type_query_app_id_exist(const char* app_id)
2674 _INFO("account_type_query_app_id_exist starting");
2675 int error_code = ACCOUNT_ERROR_NONE;
2677 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2679 GError *error = NULL;
2681 AccountManager* acc_mgr = _account_manager_get_instance();
2682 if (acc_mgr == NULL)
2684 _ERR("g_bus_get_sync failed");
2685 return ACCOUNT_ERROR_PERMISSION_DENIED;
2688 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, app_id, NULL, &error);
2690 error_code = _account_get_error_code(is_success, error);
2691 g_clear_error(&error);
2697 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2699 account_subscribe_s* tmp = (account_subscribe_s*)user_data;
2700 char *msg = NULL, *vconf_key = NULL;
2701 const char *key_name = NULL;
2702 char event_msg[256] ={0, };
2703 int account_id = -1;
2706 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2711 ACCOUNT_ERROR("user data required\n");
2715 key_name = vconf_keynode_get_name(key);
2717 if ( key_name == NULL ) {
2718 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2722 if(!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2724 vconf_key = vconf_keynode_get_str(key);
2726 if( vconf_key == NULL){
2727 ACCOUNT_ERROR("vconf key is NULL.\n");
2730 msg = strdup(vconf_key);
2732 char* event_type = NULL;
2736 event_type = strtok_r(msg, ":", &ptr);
2737 id = strtok_r(NULL, ":", &ptr);
2739 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2741 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2743 account_id = atoi(id);
2745 if(tmp->account_subscription_callback)
2746 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2753 ACCOUNT_API int account_subscribe_create(account_subscribe_h* account_subscribe)
2755 if (!account_subscribe) {
2756 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2757 return ACCOUNT_ERROR_INVALID_PARAMETER;
2760 account_subscribe_s *data = (account_subscribe_s*)calloc(1,sizeof(account_subscribe_s));
2763 ACCOUNT_FATAL("OUT OF MEMORY\n");
2764 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2767 *account_subscribe = (account_subscribe_h)data;
2769 return ACCOUNT_ERROR_NONE;
2772 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2774 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2776 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2778 tmp->account_subscription_callback = callback;
2779 tmp->user_data = user_data;
2782 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2783 (vconf_callback_fn)_account_subscribe_vconf_callback,
2786 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2788 if(ret != VCONF_OK) {
2789 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2790 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2793 return ACCOUNT_ERROR_NONE;
2796 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2798 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2800 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2804 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2805 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
2806 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2807 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2810 return ACCOUNT_ERROR_NONE;
2813 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2815 account_subscribe_s* tmp = (account_subscribe_s*)user_data;
2816 char *msg = NULL, *vconf_key = NULL;
2817 char event_msg[256] ={0, };
2818 int account_id = -1;
2819 const char *key_name = NULL;
2822 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2827 ACCOUNT_ERROR("user data required\n");
2831 key_name = vconf_keynode_get_name(key);
2833 if ( key_name == NULL ) {
2834 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2838 if(!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2840 vconf_key = vconf_keynode_get_str(key);
2842 if( vconf_key == NULL){
2843 ACCOUNT_ERROR("vconf key is NULL.\n");
2846 msg = strdup(vconf_key);
2848 char* event_type = NULL;
2852 event_type = strtok_r(msg, ":", &ptr);
2853 id = strtok_r(NULL, ":", &ptr);
2855 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2857 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2859 account_id = atoi(id);
2861 if(tmp->account_subscription_callback)
2862 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2869 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2871 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2873 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2877 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2878 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
2879 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2880 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2883 return ACCOUNT_ERROR_NONE;
2886 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2888 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2890 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2892 tmp->account_subscription_callback = callback;
2893 tmp->user_data = user_data;
2896 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2897 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2900 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2902 if(ret != VCONF_OK) {
2903 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2904 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2907 return ACCOUNT_ERROR_NONE;