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.
23 #include <glib/gprintf.h>
25 #include <gio/gunixfdlist.h>
29 #include <security-server.h>
32 #include "account-error.h"
33 #include "account-private.h"
34 #include "account-types.h"
35 #include "account_ipc_marshal.h"
38 #include "account-mgr-stub.h"
40 #define ACCOUNT_DB_OPEN_READONLY 0
41 #define ACCOUNT_DB_OPEN_READWRITE 1
45 #define _GET_COOKIE int ret_code = 0;\
46 char *e_cookie = NULL;\
47 char cookie[256] = {0,};\
50 size = security_server_get_cookie_size();\
51 ret_code = security_server_request_cookie(cookie, size);\
53 _ERR("security_server_request_cookie() is failed.");\
54 return ACCOUNT_ERROR_PERMISSION_DENIED;\
57 e_cookie = g_base64_encode((const guchar *)cookie, size);\
58 if (e_cookie == NULL) {\
59 _ERR("g_base64_encode() is failed.");\
60 return ACCOUNT_ERROR_PERMISSION_DENIED;\
63 static AccountManager *_acc_mgr = NULL;
65 static char *_account_get_text(const char *text_data);
66 static int _account_gslist_free(GSList* list);
67 static int _account_glist_free(GList* list);
69 static int _account_free_capability_items(account_capability_s *data)
71 _ACCOUNT_FREE(data->type);
72 _ACCOUNT_FREE(data->package_name);
73 _ACCOUNT_FREE(data->user_name);
75 return ACCOUNT_ERROR_NONE;
78 static int _account_custom_item_free(account_custom_s *data)
80 _ACCOUNT_FREE(data->app_id);
81 _ACCOUNT_FREE(data->key);
82 _ACCOUNT_FREE(data->value);
84 return ACCOUNT_ERROR_NONE;
87 static int _account_custom_gslist_free(GSList* list)
90 return ACCOUNT_ERROR_INVALID_PARAMETER;
95 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
96 account_custom_s *custom_data = (account_custom_s*)iter->data;
97 _account_custom_item_free(custom_data);
98 _ACCOUNT_FREE(custom_data);
104 return ACCOUNT_ERROR_NONE;
107 static int _account_list_free(GList* list)
110 return ACCOUNT_ERROR_INVALID_PARAMETER;
113 g_list_free_full(list, g_free);
116 return ACCOUNT_ERROR_NONE;
119 static int _account_free_account_items(account_s *data)
121 _ACCOUNT_FREE(data->user_name);
122 _ACCOUNT_FREE(data->email_address);
123 _ACCOUNT_FREE(data->display_name);
124 _ACCOUNT_FREE(data->icon_path);
125 _ACCOUNT_FREE(data->source);
126 _ACCOUNT_FREE(data->package_name);
127 _ACCOUNT_FREE(data->domain_name);
128 _ACCOUNT_FREE(data->access_token);
131 for(i=0;i<USER_TXT_CNT;i++)
132 _ACCOUNT_FREE(data->user_data_txt[i]);
134 _account_gslist_free(data->capablity_list);
135 _account_glist_free(data->account_list);
136 _account_custom_gslist_free(data->custom_list);
137 _account_list_free(data->domain_list);
138 _account_list_free(data->mechanism_list);
140 return ACCOUNT_ERROR_NONE;
143 static int _account_gslist_free(GSList* list)
146 return ACCOUNT_ERROR_INVALID_PARAMETER;
151 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
152 account_capability_s *cap_data = (account_capability_s*)iter->data;
153 _account_free_capability_items(cap_data);
154 _ACCOUNT_FREE(cap_data);
160 return ACCOUNT_ERROR_NONE;
163 static int _account_glist_free(GList* list)
166 return ACCOUNT_ERROR_INVALID_PARAMETER;
171 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
172 account_s *account_record = (account_s*)iter->data;
173 _account_free_account_items(account_record);
174 _ACCOUNT_FREE(account_record);
180 return ACCOUNT_ERROR_NONE;
183 static char *_account_get_text(const char *text_data)
185 char *text_value = NULL;
187 if (text_data != NULL) {
188 text_value = strdup(text_data);
193 //FIXME : add true singleton logic
195 _account_manager_get_instance ()
197 _INFO("_account_manager_get_instance");
198 if (_acc_mgr != NULL)
200 _INFO("instance already created.");
204 #if !GLIB_CHECK_VERSION(2,35,0)
208 GDBusConnection *connection = NULL;
209 GError *error = NULL;
211 connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
213 _INFO("after g_bus_get_sync");
216 /* Create the object */
218 account_manager_proxy_new_sync(connection,
219 G_DBUS_PROXY_FLAGS_NONE,
220 "org.tizen.account.manager",
221 "/org/tizen/account/manager",
224 _INFO("_account_manager_get_instance end");
228 GDBusErrorEntry _account_svc_errors[] =
230 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
231 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
232 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
233 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
234 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
235 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
236 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
237 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
238 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
239 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
240 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
241 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
242 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
243 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
244 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
245 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
246 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
247 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
250 static int _account_get_error_code(bool is_success, GError *error)
254 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
256 if (g_dbus_error_is_remote_error(error))
258 gchar *remote_error = g_dbus_error_get_remote_error(error);
261 _INFO("Remote error[%s]", remote_error);
263 //FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
264 //However error->message matches, so doing reverse lookup
265 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
267 for (i = 0; i < error_enum_count; i++)
269 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0)
271 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
272 return _account_svc_errors[i].error_code;
277 //All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED
278 return ACCOUNT_ERROR_PERMISSION_DENIED;
280 return ACCOUNT_ERROR_NONE;
283 ACCOUNT_API int account_connect(void)
285 return ACCOUNT_ERROR_NONE;
288 ACCOUNT_API int account_connect_readonly(void)
290 return ACCOUNT_ERROR_NONE;
293 ACCOUNT_API int account_disconnect(void)
295 return ACCOUNT_ERROR_NONE;
299 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
301 _INFO("1. account_insert_to_db start");
302 char* account_db_path = ACCOUNT_DB_NAME;
304 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
305 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
309 account_s *account_data = (account_s*) account;
310 int error_code = ACCOUNT_ERROR_NONE;
311 GError *error = NULL;
313 _INFO("2. Before _account_manager_get_instance()");
314 AccountManager* acc_mgr = _account_manager_get_instance();
315 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
318 GVariant* account_serialized = marshal_account(account_data);
320 _INFO("3. Before account_manager_call_account_add_sync");
321 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_db_path, account_serialized, e_cookie, &db_id, NULL, &error);
322 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
324 *account_db_id = db_id;
325 account_data->id = db_id;
327 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
329 return ACCOUNT_ERROR_NONE;
332 //Failed to get dbus.
333 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
338 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
340 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
341 char* account_db_path = ACCOUNT_DB_NAME;
343 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
347 GError *error = NULL;
349 AccountManager* acc_mgr = _account_manager_get_instance();
352 _ERR("g_bus_get_sync failed");
353 return ACCOUNT_ERROR_PERMISSION_DENIED;
356 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
357 GVariant *account_serialized_old = NULL;
358 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_db_id, e_cookie, &account_serialized_old, NULL, &error);
361 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
362 return _account_get_error_code(is_success, error);
365 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
366 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_path, account_db_id, e_cookie, NULL, &error);
369 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error->code);
370 return _account_get_error_code(is_success, error);
373 _INFO("4. Before account_delete_from_db_by_id end");
374 return ACCOUNT_ERROR_NONE;
377 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
379 _INFO("account_delete_from_db_by_user_name start");
380 char* account_db_path = ACCOUNT_DB_NAME;
382 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
383 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
387 GError *error = NULL;
389 AccountManager* acc_mgr = _account_manager_get_instance();
392 _ERR("g_bus_get_sync failed");
393 return ACCOUNT_ERROR_PERMISSION_DENIED;
396 GVariant* account_list_variant = NULL;
397 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, account_db_path, user_name, e_cookie, &account_list_variant, NULL, &error);
399 int error_code = _account_get_error_code(is_success, error);
400 if (error_code != ACCOUNT_ERROR_NONE)
402 _ERR("account_query_account_by_user_name error=[%d]", error_code);
406 _INFO("before unmarshal_account_list");
407 GSList* account_list = unmarshal_account_list(account_list_variant);
408 _INFO("after unmarshal_account_list");
409 if (account_list == NULL)
411 return ACCOUNT_ERROR_NO_DATA;
414 //TODO free account_list, account_list_variant
416 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, account_db_path, user_name, package_name, e_cookie, NULL, &error);
420 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error->code);
421 return _account_get_error_code(is_success, error);
424 return ACCOUNT_ERROR_NONE;
427 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
429 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
430 char* account_db_path = ACCOUNT_DB_NAME;
432 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
436 GError *error = NULL;
438 AccountManager* acc_mgr = _account_manager_get_instance();
441 _ERR("g_bus_get_sync failed");
442 return ACCOUNT_ERROR_PERMISSION_DENIED;
445 //First get account list of user_name, used for gSSO DB deletion
446 GVariant* account_list_variant = NULL;
447 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, e_cookie, &account_list_variant, NULL, &error);
449 int error_code = _account_get_error_code(is_success, error);
450 if (error_code != ACCOUNT_ERROR_NONE)
455 _INFO("before unmarshal_account_list");
456 GSList* account_list = unmarshal_account_list(account_list_variant);
457 _INFO("after unmarshal_account_list");
458 if (account_list == NULL)
460 return ACCOUNT_ERROR_NO_DATA;
463 is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, account_db_path, package_name, permission, e_cookie, NULL, &error);
467 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error->code);
468 return _account_get_error_code(is_success, error);
471 return ACCOUNT_ERROR_NONE;
474 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
476 _INFO("account_delete_from_db_by_package_name starting with permission");
477 return _account_delete_from_db_by_package_name(package_name, true);
480 ACCOUNT_API int account_delete_from_db_by_package_name_without_permission(const char *package_name)
482 _INFO("account_delete_from_db_by_package_name starting without permission");
483 return _account_delete_from_db_by_package_name(package_name, false);
486 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
488 //First we will update account db
489 _INFO("1. account_update_to_db_by_id start");
490 char* account_db_path = ACCOUNT_DB_NAME;
492 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
493 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
497 GError *error = NULL;
499 AccountManager* acc_mgr = _account_manager_get_instance();
502 _ERR("g_bus_get_sync failed");
503 return ACCOUNT_ERROR_PERMISSION_DENIED;
506 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
507 GVariant *account_serialized_old = NULL;
508 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_id, e_cookie, &account_serialized_old, NULL, &error);
511 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
512 return _account_get_error_code(is_success, error);
515 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
516 GVariant* account_serialized = marshal_account((account_s*) account);
517 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_db_path, account_serialized, account_id, e_cookie, NULL, &error);
521 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error->code);
522 return _account_get_error_code(is_success, error);
525 _INFO("4. account_update_to_db_by_id end");
526 return ACCOUNT_ERROR_NONE;
529 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
532 ret = account_update_to_db_by_id(account, account_id);
537 ACCOUNT_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
539 //First we will update account db
540 //Then we will update gSSO DB, if it fails then we will rollback account db updates
542 _INFO("account_update_to_db_by_id_without_permission start");
543 char* account_db_path = ACCOUNT_DB_NAME;
545 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
546 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
550 GError *error = NULL;
552 AccountManager* acc_mgr = _account_manager_get_instance();
555 _ERR("g_bus_get_sync failed");
556 return ACCOUNT_ERROR_PERMISSION_DENIED;
559 GVariant *account_serialized_old = NULL;
560 _INFO("before query() account_id[%d]", account_id);
561 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_id, e_cookie, &account_serialized_old, NULL, &error);
564 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
565 return _account_get_error_code(is_success, error);
568 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s*)account)->user_name);
569 GVariant* account_serialized = marshal_account((account_s*) account);
570 _INFO("after marshal() : account_id[%d]", account_id);
571 if (account_serialized == NULL)
573 _ERR("Invalid input");
574 return ACCOUNT_ERROR_INVALID_PARAMETER;
577 _INFO("before call update() : account_id[%d]", account_id);
578 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_db_path, account_serialized, account_id, e_cookie, NULL, &error);
579 _INFO("after call update() : is_success=%d", is_success);
582 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error->code);
583 return _account_get_error_code(is_success, error);
586 return ACCOUNT_ERROR_NONE;
589 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
591 //First we will update account db
592 _INFO("account_update_to_db_by_user_name starting");
593 char* account_db_path = ACCOUNT_DB_NAME;
595 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
596 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
597 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
601 GError *error = NULL;
603 AccountManager* acc_mgr = _account_manager_get_instance();
606 _ERR("g_bus_get_sync failed");
607 return ACCOUNT_ERROR_PERMISSION_DENIED;
610 GVariant *account_serialized_old = NULL;
611 account_s *account_data = (account_s*) account;
612 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_data->id, e_cookie, &account_serialized_old, NULL, &error);
615 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
616 return _account_get_error_code(is_success, error);
619 GVariant* account_serialized = marshal_account(account_data);
620 is_success = account_manager_call_account_update_to_db_by_user_name_sync(acc_mgr, account_db_path, account_serialized, user_name, package_name, e_cookie, NULL, &error);
623 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error->code);
624 return _account_get_error_code(is_success, error);
627 return ACCOUNT_ERROR_NONE;
630 ACCOUNT_API int account_create(account_h *account)
633 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
634 return ACCOUNT_ERROR_INVALID_PARAMETER;
637 account_s *data = (account_s*)malloc(sizeof(account_s));
640 ACCOUNT_FATAL("Memory Allocation Failed");
641 return ACCOUNT_ERROR_OUT_OF_MEMORY;
643 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
645 /*Setting account as visible by default*/
646 data->secret = ACCOUNT_SECRECY_VISIBLE;
648 /*Setting account as not supporting sync by default*/
649 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
651 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
653 data->account_list = NULL;
654 data->capablity_list = NULL;
655 data->custom_list = NULL;
656 data->domain_list = NULL;
657 data->mechanism_list = NULL;
659 *account = (account_h)data;
661 return ACCOUNT_ERROR_NONE;
664 ACCOUNT_API int account_destroy(account_h account)
666 account_s *data = (account_s*)account;
668 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
670 _account_free_account_items(data);
673 return ACCOUNT_ERROR_NONE;
676 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
679 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
680 return ACCOUNT_ERROR_INVALID_PARAMETER;
684 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
685 return ACCOUNT_ERROR_INVALID_PARAMETER;
688 account_s *data = (account_s*)account;
690 _ACCOUNT_FREE(data->user_name);
691 data->user_name = _account_get_text(user_name);
693 return ACCOUNT_ERROR_NONE;
696 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
699 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
700 return ACCOUNT_ERROR_INVALID_PARAMETER;
704 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
705 return ACCOUNT_ERROR_INVALID_PARAMETER;
708 account_s *data = (account_s*)account;
710 _ACCOUNT_FREE(data->display_name);
711 data->display_name = _account_get_text(display_name);
713 return ACCOUNT_ERROR_NONE;
716 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
719 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
720 return ACCOUNT_ERROR_INVALID_PARAMETER;
723 if (!email_address) {
724 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
725 return ACCOUNT_ERROR_INVALID_PARAMETER;
728 account_s *data = (account_s*)account;
730 _ACCOUNT_FREE(data->email_address);
731 data->email_address = _account_get_text(email_address);
733 return ACCOUNT_ERROR_NONE;
736 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
739 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
740 return ACCOUNT_ERROR_INVALID_PARAMETER;
744 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
745 return ACCOUNT_ERROR_INVALID_PARAMETER;
748 account_s *data = (account_s*)account;
750 _ACCOUNT_FREE(data->icon_path);
751 data->icon_path = _account_get_text(icon_path);
753 return ACCOUNT_ERROR_NONE;
756 ACCOUNT_API int account_set_source(account_h account, const char *source)
759 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
760 return ACCOUNT_ERROR_INVALID_PARAMETER;
764 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
765 return ACCOUNT_ERROR_INVALID_PARAMETER;
767 account_s *data = (account_s*)account;
769 _ACCOUNT_FREE(data->source);
770 data->source = _account_get_text(source);
772 return ACCOUNT_ERROR_NONE;
775 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
778 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
779 return ACCOUNT_ERROR_INVALID_PARAMETER;
783 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
784 return ACCOUNT_ERROR_INVALID_PARAMETER;
787 account_s *data = (account_s*)account;
789 _ACCOUNT_FREE(data->package_name);
790 data->package_name = _account_get_text(package_name);
792 return ACCOUNT_ERROR_NONE;
795 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
798 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
799 return ACCOUNT_ERROR_INVALID_PARAMETER;
803 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
804 return ACCOUNT_ERROR_INVALID_PARAMETER;
806 account_s *data = (account_s*)account;
808 _ACCOUNT_FREE(data->domain_name);
809 data->domain_name = _account_get_text(domain_name);
811 return ACCOUNT_ERROR_NONE;
814 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
817 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
818 return ACCOUNT_ERROR_INVALID_PARAMETER;
822 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
823 return ACCOUNT_ERROR_INVALID_PARAMETER;
826 account_s *data = (account_s*)account;
828 _ACCOUNT_FREE(data->access_token);
829 data->access_token = _account_get_text(access_token);
831 return ACCOUNT_ERROR_NONE;
834 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
837 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
838 return ACCOUNT_ERROR_INVALID_PARAMETER;
842 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
843 return ACCOUNT_ERROR_INVALID_PARAMETER;
845 if (idx >= USER_TXT_CNT || idx < 0) {
846 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
847 return ACCOUNT_ERROR_INVALID_PARAMETER;
850 account_s *data = (account_s*)account;
852 _ACCOUNT_FREE(data->user_data_txt[idx]);
853 data->user_data_txt[idx] = _account_get_text(user_txt);
855 return ACCOUNT_ERROR_NONE;
858 ACCOUNT_API int account_set_custom(account_h account, const char* key, const char* value)
861 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
862 return ACCOUNT_ERROR_INVALID_PARAMETER;
866 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
867 return ACCOUNT_ERROR_INVALID_PARAMETER;
871 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
872 return ACCOUNT_ERROR_INVALID_PARAMETER;
875 account_s *data = (account_s*)account;
878 bool b_is_new = TRUE;
880 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
882 account_custom_s* custom_data = NULL;
883 custom_data = (account_custom_s*)iter->data;
884 ACCOUNT_SLOGD( "account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
886 if(!strcmp(custom_data->key, key)) {
887 _ACCOUNT_FREE(custom_data->value);
888 custom_data->value = _account_get_text(value);
894 account_custom_s* custom_data = (account_custom_s*)malloc(sizeof(account_custom_s));
896 if (custom_data == NULL) {
897 return ACCOUNT_ERROR_OUT_OF_MEMORY;
899 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
900 custom_data->account_id = data->id;
901 custom_data->app_id = _account_get_text(data->package_name);
902 custom_data->key = _account_get_text(key);
903 custom_data->value = _account_get_text(value);
904 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
907 return ACCOUNT_ERROR_NONE;
910 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
912 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
914 if ( ((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN)) {
915 return ACCOUNT_ERROR_INVALID_PARAMETER;
918 account_s *data = (account_s*)account;
920 data->auth_type = (int)auth_type;
922 return ACCOUNT_ERROR_NONE;
925 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
927 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
929 if ( ((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE)) {
930 return ACCOUNT_ERROR_INVALID_PARAMETER;
933 account_s *data = (account_s*)account;
935 data->secret = (int)secret;
937 return ACCOUNT_ERROR_NONE;
940 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
942 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
944 if ( ((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC)) {
945 return ACCOUNT_ERROR_INVALID_PARAMETER;
948 account_s *data = (account_s*)account;
950 data->sync_support= (int)sync_support;
952 return ACCOUNT_ERROR_NONE;
955 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
958 return ACCOUNT_ERROR_INVALID_PARAMETER;
961 if (idx >= USER_INT_CNT ||idx < 0) {
962 return ACCOUNT_ERROR_INVALID_PARAMETER;
965 account_s *data = (account_s*)account;
967 data->user_data_int[idx] = user_int;
969 return ACCOUNT_ERROR_NONE;
972 ACCOUNT_API int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_value)
974 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
975 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
977 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED)) {
978 return ACCOUNT_ERROR_INVALID_PARAMETER;
981 account_s *data = (account_s*)account;
984 bool b_is_new = TRUE;
986 for(iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
987 account_capability_s *cap_data = NULL;
988 cap_data = (account_capability_s*)iter->data;
990 if(!strcmp(cap_data->type, capability_type)) {
991 cap_data->value = capability_value;
998 account_capability_s* cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
1000 if (cap_data == NULL)
1001 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1002 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
1004 cap_data->type = _account_get_text(capability_type);
1005 cap_data->value = capability_value;
1006 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
1009 return ACCOUNT_ERROR_NONE;
1012 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
1015 return ACCOUNT_ERROR_INVALID_PARAMETER;
1019 return ACCOUNT_ERROR_INVALID_PARAMETER;
1022 account_s *data = (account_s*)account;
1024 (*user_name) = NULL;
1025 *user_name = _account_get_text(data->user_name);
1027 return ACCOUNT_ERROR_NONE;
1030 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
1033 return ACCOUNT_ERROR_INVALID_PARAMETER;
1036 if (!display_name) {
1037 return ACCOUNT_ERROR_INVALID_PARAMETER;
1040 account_s *data = (account_s*)account;
1042 (*display_name) = NULL;
1044 *display_name = _account_get_text(data->display_name);
1046 return ACCOUNT_ERROR_NONE;
1049 ACCOUNT_API int account_get_email_address(account_h account,char **email_address)
1052 return ACCOUNT_ERROR_INVALID_PARAMETER;
1055 if (!email_address) {
1056 return ACCOUNT_ERROR_INVALID_PARAMETER;
1059 account_s *data = (account_s*)account;
1061 (*email_address) = NULL;
1063 *email_address = _account_get_text(data->email_address);
1065 return ACCOUNT_ERROR_NONE;
1068 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
1071 return ACCOUNT_ERROR_INVALID_PARAMETER;
1075 return ACCOUNT_ERROR_INVALID_PARAMETER;
1078 account_s *data = (account_s*)account;
1080 (*icon_path) = NULL;
1082 *icon_path = _account_get_text(data->icon_path);
1084 return ACCOUNT_ERROR_NONE;
1087 ACCOUNT_API int account_get_source(account_h account, char **source)
1090 return ACCOUNT_ERROR_INVALID_PARAMETER;
1094 return ACCOUNT_ERROR_INVALID_PARAMETER;
1097 account_s *data = (account_s*)account;
1101 *source = _account_get_text(data->source);
1103 return ACCOUNT_ERROR_NONE;
1106 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1109 return ACCOUNT_ERROR_INVALID_PARAMETER;
1112 if (!package_name) {
1113 return ACCOUNT_ERROR_INVALID_PARAMETER;
1116 account_s *data = (account_s*)account;
1118 (*package_name) = NULL;
1120 *package_name = _account_get_text(data->package_name);
1122 return ACCOUNT_ERROR_NONE;
1125 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1128 return ACCOUNT_ERROR_INVALID_PARAMETER;
1132 return ACCOUNT_ERROR_INVALID_PARAMETER;
1135 account_s *data = (account_s*)account;
1137 (*domain_name) = NULL;
1139 *domain_name = _account_get_text(data->domain_name);
1141 return ACCOUNT_ERROR_NONE;
1144 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1147 return ACCOUNT_ERROR_INVALID_PARAMETER;
1150 if (!access_token) {
1151 return ACCOUNT_ERROR_INVALID_PARAMETER;
1154 account_s *data = (account_s*)account;
1156 (*access_token) = NULL;
1158 *access_token = _account_get_text(data->access_token);
1160 return ACCOUNT_ERROR_NONE;
1163 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1166 return ACCOUNT_ERROR_INVALID_PARAMETER;
1170 return ACCOUNT_ERROR_INVALID_PARAMETER;
1172 ACCOUNT_RETURN_VAL((user_text_index >=0 && user_text_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1174 account_s *data = (account_s*)account;
1178 *text = _account_get_text(data->user_data_txt[user_text_index]);
1180 return ACCOUNT_ERROR_NONE;
1183 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1186 return ACCOUNT_ERROR_INVALID_PARAMETER;
1189 return ACCOUNT_ERROR_INVALID_PARAMETER;
1192 account_s* data = (account_s*)account;
1194 *auth_type = data->auth_type;
1196 return ACCOUNT_ERROR_NONE;
1199 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1202 return ACCOUNT_ERROR_INVALID_PARAMETER;
1205 return ACCOUNT_ERROR_INVALID_PARAMETER;
1208 account_s* data = (account_s*)account;
1210 *secret = data->secret;
1212 return ACCOUNT_ERROR_NONE;
1215 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1218 return ACCOUNT_ERROR_INVALID_PARAMETER;
1220 if (!sync_support) {
1221 return ACCOUNT_ERROR_INVALID_PARAMETER;
1224 account_s* data = (account_s*)account;
1226 *sync_support = data->sync_support;
1228 return ACCOUNT_ERROR_NONE;
1231 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1234 return ACCOUNT_ERROR_INVALID_PARAMETER;
1237 return ACCOUNT_ERROR_INVALID_PARAMETER;
1240 account_s *data = (account_s*)account;
1242 *account_id = data->id;
1244 return ACCOUNT_ERROR_NONE;
1247 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1250 return ACCOUNT_ERROR_INVALID_PARAMETER;
1253 ACCOUNT_RETURN_VAL((user_int_index >=0 && user_int_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1256 return ACCOUNT_ERROR_INVALID_PARAMETER;
1259 account_s *data = (account_s*)account;
1261 *integer = data->user_data_int[user_int_index];
1263 return ACCOUNT_ERROR_NONE;
1266 ACCOUNT_API int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value)
1268 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1269 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1270 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1273 account_s *data = (account_s*)account;
1275 _ERR("before for()");
1276 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1277 account_capability_s *cap_data = NULL;
1279 cap_data = (account_capability_s*)iter->data;
1281 _ERR("capability_type = %s, data->type = %s", capability_type, cap_data->type);
1282 _ERR("capability_value = %d, data->value= %d", capability_value, cap_data->value);
1283 if(!strcmp(capability_type, cap_data->type)) {
1284 *capability_value = cap_data->value;
1285 return ACCOUNT_ERROR_NONE;
1288 _ERR("after for()");
1290 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1293 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1295 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1296 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1299 account_s *data = (account_s*)account;
1301 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1302 account_capability_s *cap_data = NULL;
1304 cap_data = (account_capability_s*)iter->data;
1306 if(callback(cap_data->type, cap_data->value, user_data)!=TRUE){
1307 return ACCOUNT_ERROR_NONE;
1311 return ACCOUNT_ERROR_NONE;
1314 ACCOUNT_API int account_get_custom(account_h account, const char* key, char** value)
1316 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1317 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1318 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1321 account_s *data = (account_s*)account;
1323 _ERR("before for()");
1324 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1325 account_custom_s *custom_data = NULL;
1327 custom_data = (account_custom_s*)iter->data;
1329 _ERR("key = %s, custom_data->key = %s", key, custom_data->key);
1330 _ERR("value = %s, custom_data->value = %s", value, custom_data->value);
1332 if(!strcmp(key, custom_data->key)) {
1334 *value = _account_get_text(custom_data->value);
1335 return ACCOUNT_ERROR_NONE;
1338 _ERR("after for()");
1340 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1343 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void* user_data)
1345 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1346 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1349 account_s *data = (account_s*)account;
1351 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1352 bool cb_ret = FALSE;
1353 account_custom_s *custom_data = NULL;
1355 custom_data = (account_custom_s*)iter->data;
1357 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1363 return ACCOUNT_ERROR_NONE;
1366 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1368 _INFO("account_type_foreach_account_type_from_db start");
1369 char* account_db_path = ACCOUNT_DB_NAME;
1371 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1375 GError *error = NULL;
1377 AccountManager* acc_mgr = _account_manager_get_instance();
1378 if (acc_mgr == NULL)
1380 _ERR("g_bus_get_sync failed");
1381 return ACCOUNT_ERROR_PERMISSION_DENIED;
1384 GVariant* account_list_variant = NULL;
1385 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, account_db_path, e_cookie, &account_list_variant, NULL, &error);
1387 int error_code = _account_get_error_code(is_success, error);
1388 if (error_code != ACCOUNT_ERROR_NONE)
1393 _INFO("before unmarshal_account_list");
1394 GSList* account_list = unmarshal_account_list(account_list_variant);
1395 _INFO("after unmarshal_account_list");
1398 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1400 _INFO("iterating received account_list");
1401 account_s *account = NULL;
1402 account = (account_s*)iter->data;
1403 _INFO("Before _account_query_identity_info_by_id");
1405 _INFO("account->id=%d", account->id);
1406 if (callback((account_h)account, user_data) == false)
1408 _INFO("application callback requested to discontinue.");
1411 _INFO("After one iteration callback");
1413 _INFO("account_foreach_account_from_db end");
1415 return ACCOUNT_ERROR_NONE;
1418 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1420 _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1421 char* account_db_path = ACCOUNT_DB_NAME;
1423 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1424 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1428 GError *error = NULL;
1430 AccountManager* acc_mgr = _account_manager_get_instance();
1431 if (acc_mgr == NULL)
1433 _ERR("g_bus_get_sync failed");
1434 return ACCOUNT_ERROR_PERMISSION_DENIED;
1437 GVariant* account_variant = NULL;
1438 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_db_id, e_cookie, &account_variant, NULL, &error);
1440 int error_code = _account_get_error_code(is_success, error);
1441 if (error_code != ACCOUNT_ERROR_NONE)
1446 _INFO("before unmarshal_account");
1447 account_s* account_data = umarshal_account(account_variant);
1448 _INFO("after unmarshal_account");
1450 if (account_data == NULL)
1452 _ERR("Failed to unmarshal");
1453 return ACCOUNT_ERROR_DB_FAILED;
1456 *account = (account_h) account_data;
1458 _INFO("account_query_account_by_account_id end");
1460 return ACCOUNT_ERROR_NONE;
1463 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char* user_name, void* user_data)
1465 _INFO("account_query_account_by_user_name starting");
1466 char* account_db_path = ACCOUNT_DB_NAME;
1468 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1469 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1473 GError *error = NULL;
1475 AccountManager* acc_mgr = _account_manager_get_instance();
1476 if (acc_mgr == NULL)
1478 _ERR("g_bus_get_sync failed");
1479 return ACCOUNT_ERROR_PERMISSION_DENIED;
1482 GVariant* account_list_variant = NULL;
1483 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, account_db_path, user_name, e_cookie, &account_list_variant, NULL, &error);
1485 int error_code = _account_get_error_code(is_success, error);
1486 if (error_code != ACCOUNT_ERROR_NONE)
1491 _INFO("before unmarshal_account_list");
1492 GSList* account_list = unmarshal_account_list(account_list_variant);
1493 _INFO("after unmarshal_account_list");
1494 if (account_list == NULL)
1496 return ACCOUNT_ERROR_NO_DATA;
1501 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1503 _INFO("iterating received account_list");
1504 account_s *account = NULL;
1505 account = (account_s*)iter->data;
1506 if (callback((account_h)account, user_data) == false)
1508 _INFO("application callback requested to discontinue.");
1512 _INFO("account_query_account_by_user_name end");
1514 return ACCOUNT_ERROR_NONE;
1517 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1519 _INFO("account_query_account_by_package_name starting");
1520 char* account_db_path = ACCOUNT_DB_NAME;
1522 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1523 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1527 GError *error = NULL;
1529 AccountManager* acc_mgr = _account_manager_get_instance();
1530 if (acc_mgr == NULL)
1532 _ERR("g_bus_get_sync failed");
1533 return ACCOUNT_ERROR_PERMISSION_DENIED;
1536 GVariant* account_list_variant = NULL;
1537 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, e_cookie, &account_list_variant, NULL, &error);
1538 int error_code = _account_get_error_code(is_success, error);
1539 if (error_code != ACCOUNT_ERROR_NONE)
1544 _INFO("before unmarshal_account_list");
1545 GSList* account_list = unmarshal_account_list(account_list_variant);
1546 _INFO("after unmarshal_account_list");
1547 if (account_list == NULL)
1549 return ACCOUNT_ERROR_NO_DATA;
1554 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1556 _INFO("iterating received account_list");
1557 account_s *account = NULL;
1558 account = (account_s*)iter->data;
1560 if (callback((account_h)account, user_data) == false)
1562 _INFO("application callback requested to discontinue.");
1566 _INFO("account_query_account_by_package_name end");
1567 return ACCOUNT_ERROR_NONE;
1570 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char* capability_type, account_capability_state_e capability_value, void *user_data)
1572 _INFO("account_query_account_by_capability starting");
1573 char* account_db_path = ACCOUNT_DB_NAME;
1575 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1577 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1578 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1579 return ACCOUNT_ERROR_INVALID_PARAMETER;
1582 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1586 GError *error = NULL;
1588 AccountManager* acc_mgr = _account_manager_get_instance();
1589 if (acc_mgr == NULL)
1591 _ERR("g_bus_get_sync failed");
1592 return ACCOUNT_ERROR_PERMISSION_DENIED;
1595 GVariant* account_list_variant = NULL;
1596 bool is_success = account_manager_call_account_query_account_by_capability_sync(acc_mgr, account_db_path, capability_type, capability_value, e_cookie, &account_list_variant, NULL, &error);
1598 int error_code = _account_get_error_code(is_success, error);
1599 if (error_code != ACCOUNT_ERROR_NONE)
1604 _INFO("before unmarshal_account_list");
1605 GSList* account_list = unmarshal_account_list(account_list_variant);
1606 _INFO("after unmarshal_account_list");
1607 if (account_list == NULL)
1609 return ACCOUNT_ERROR_NO_DATA;
1614 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1616 _INFO("iterating received account_list");
1617 account_s *account = NULL;
1618 account = (account_s*)iter->data;
1620 if (callback((account_h)account, user_data) == false)
1622 _INFO("application callback requested to discontinue.");
1626 _INFO("account_query_account_by_capability end");
1627 return ACCOUNT_ERROR_NONE;
1630 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char* capability_type, void* user_data)
1632 _INFO("account_query_account_by_capability_type starting");
1633 char* account_db_path = ACCOUNT_DB_NAME;
1635 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1636 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1640 GError *error = NULL;
1642 AccountManager* acc_mgr = _account_manager_get_instance();
1643 if (acc_mgr == NULL)
1645 _ERR("g_bus_get_sync failed");
1646 return ACCOUNT_ERROR_PERMISSION_DENIED;
1649 GVariant* account_list_variant = NULL;
1650 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, account_db_path, capability_type, e_cookie, &account_list_variant, NULL, &error);
1652 int error_code = _account_get_error_code(is_success, error);
1653 if (error_code != ACCOUNT_ERROR_NONE)
1658 _INFO("before unmarshal_account_list");
1659 GSList* account_list = unmarshal_account_list(account_list_variant);
1660 _INFO("after unmarshal_account_list");
1661 if (account_list == NULL)
1663 return ACCOUNT_ERROR_NO_DATA;
1668 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1670 _INFO("iterating received account_list");
1671 account_s *account = NULL;
1672 account = (account_s*)iter->data;
1674 if (callback((account_h)account, user_data) == false)
1676 _INFO("application callback requested to discontinue.");
1680 _INFO("account_query_account_by_capability end");
1681 return ACCOUNT_ERROR_NONE;
1684 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1686 _INFO("account_query_capability_by_account_id starting");
1687 char* account_db_path = ACCOUNT_DB_NAME;
1689 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1690 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1694 GError *error = NULL;
1695 AccountManager* acc_mgr = _account_manager_get_instance();
1696 if (acc_mgr == NULL)
1698 _ERR("g_bus_get_sync failed");
1699 return ACCOUNT_ERROR_PERMISSION_DENIED;
1702 GVariant* capability_list_variant = NULL;
1703 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_db_path, account_id, e_cookie, &capability_list_variant, NULL, &error);
1704 int error_code = _account_get_error_code(is_success, error);
1705 if (error_code != ACCOUNT_ERROR_NONE)
1710 _INFO("before unmarshal_capability_list");
1711 GSList* capability_list = unmarshal_capability_list(capability_list_variant);
1712 _INFO("after unmarshal_capability_list");
1713 if (capability_list == NULL)
1715 return ACCOUNT_ERROR_NO_DATA;
1720 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter))
1722 _INFO("iterating received account_list");
1723 account_capability_s *capability = NULL;
1724 capability = (account_capability_s*)iter->data;
1726 if (callback(capability->type, capability->value, user_data) == false)
1728 _INFO("application callback requested to discontinue.");
1733 _INFO("account_query_capability_by_account_id end");
1734 return ACCOUNT_ERROR_NONE;
1737 static int _account_get_total_count(int *count, bool include_hidden)
1739 _INFO("account_get_total_count_from_db starting");
1740 char* account_db_path = ACCOUNT_DB_NAME;
1744 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1745 return ACCOUNT_ERROR_INVALID_PARAMETER;
1748 GError *error = NULL;
1752 _INFO("Invalid input");
1758 AccountManager* acc_mgr = _account_manager_get_instance();
1759 if (acc_mgr == NULL)
1761 _ERR("g_bus_get_sync failed");
1762 return ACCOUNT_ERROR_PERMISSION_DENIED;
1765 int temp_count = -1;
1766 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, account_db_path, include_hidden, e_cookie, &temp_count, NULL, &error);
1767 int error_code = _account_get_error_code(is_success, error);
1768 if (error_code != ACCOUNT_ERROR_NONE)
1773 *count = temp_count;
1774 _INFO("account_get_total_count_from_db end");
1775 return ACCOUNT_ERROR_NONE;
1778 ACCOUNT_API int account_get_total_count_from_db(int *count)
1780 _INFO("account_get_total_count_from_db starting");
1782 return _account_get_total_count(count, true);
1785 ACCOUNT_API int account_get_total_count_from_db_ex(int *count)
1787 _INFO("account_get_total_count_from_db_ex starting");
1789 return _account_get_total_count(count, false);
1792 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1794 _INFO("account_update_sync_status_by_id starting");
1795 char* account_db_path = ACCOUNT_DB_NAME;
1797 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1798 if ( ((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1799 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1800 return ACCOUNT_ERROR_INVALID_PARAMETER;
1805 GError *error = NULL;
1807 AccountManager* acc_mgr = _account_manager_get_instance();
1808 if (acc_mgr == NULL)
1810 _ERR("g_bus_get_sync failed");
1811 return ACCOUNT_ERROR_PERMISSION_DENIED;
1814 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_path, account_db_id, sync_status, e_cookie, NULL, &error);
1815 return _account_get_error_code(is_success, error);
1818 static int _account_type_free_label_items(label_s *data)
1820 _ACCOUNT_FREE(data->app_id);
1821 _ACCOUNT_FREE(data->label);
1822 _ACCOUNT_FREE(data->locale);
1824 return ACCOUNT_ERROR_NONE;
1827 static int _account_type_gslist_free(GSList* list)
1829 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
1833 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
1834 label_s *label_data = (label_s*)iter->data;
1835 _account_type_free_label_items(label_data);
1836 _ACCOUNT_FREE(label_data);
1842 return ACCOUNT_ERROR_NONE;
1845 static int _account_type_item_free(account_type_s *data)
1847 _ACCOUNT_FREE(data->app_id);
1848 _ACCOUNT_FREE(data->service_provider_id);
1849 _ACCOUNT_FREE(data->icon_path);
1850 _ACCOUNT_FREE(data->small_icon_path);
1852 return ACCOUNT_ERROR_NONE;
1855 static int _account_type_glist_free(GList* list)
1857 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Glist is NULL"));
1861 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
1862 account_type_s *account_type_record = (account_type_s*)iter->data;
1863 _account_type_item_free(account_type_record);
1864 _ACCOUNT_FREE(account_type_record);
1870 return ACCOUNT_ERROR_NONE;
1873 static int _account_type_free_account_type_items(account_type_s *data)
1875 _account_type_item_free(data);
1877 _account_type_gslist_free(data->label_list);
1878 _account_type_glist_free(data->account_type_list);
1880 return ACCOUNT_ERROR_NONE;
1883 ACCOUNT_API int account_type_create(account_type_h *account_type)
1885 if (!account_type) {
1886 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1887 return ACCOUNT_ERROR_INVALID_PARAMETER;
1890 account_type_s *data = (account_type_s*)malloc(sizeof(account_type_s));
1894 ACCOUNT_ERROR("Memory Allocation Failed");
1895 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1898 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1901 data->app_id = NULL;
1902 data->service_provider_id = NULL;
1903 data->icon_path = NULL;
1904 data->small_icon_path = NULL;
1905 data->multiple_account_support = false;
1906 data->label_list = NULL;
1907 data->account_type_list = NULL;
1908 data->provider_feature_list = NULL;
1910 *account_type = (account_type_h)data;
1912 return ACCOUNT_ERROR_NONE;
1915 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1917 _INFO("account_type_destroy");
1919 account_type_s *data = (account_type_s*)account_type;
1923 _ERR("Account type handle is null!");
1924 return ACCOUNT_ERROR_INVALID_PARAMETER;
1927 _account_type_free_account_type_items(data);
1928 _ACCOUNT_FREE(data);
1930 return ACCOUNT_ERROR_NONE;
1933 ACCOUNT_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1935 return ACCOUNT_ERROR_NONE;
1938 ACCOUNT_API int account_type_set_app_id_internal(account_type_h account_type, const char *app_id)
1940 if (!account_type) {
1941 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1942 return ACCOUNT_ERROR_INVALID_PARAMETER;
1946 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1947 return ACCOUNT_ERROR_INVALID_PARAMETER;
1950 account_type_s *data = (account_type_s*)account_type;
1952 _ACCOUNT_FREE(data->app_id);
1953 data->app_id = _account_get_text(app_id);
1955 return ACCOUNT_ERROR_NONE;
1958 ACCOUNT_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1960 return ACCOUNT_ERROR_NONE;
1963 ACCOUNT_API int account_type_set_service_provider_id_internal(account_type_h account_type, const char *service_provider_id)
1965 if (!account_type) {
1966 return ACCOUNT_ERROR_INVALID_PARAMETER;
1969 if (!service_provider_id) {
1970 return ACCOUNT_ERROR_INVALID_PARAMETER;
1973 account_type_s *data = (account_type_s*)account_type;
1975 _ACCOUNT_FREE(data->service_provider_id);
1976 data->service_provider_id = _account_get_text(service_provider_id);
1978 return ACCOUNT_ERROR_NONE;
1981 ACCOUNT_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1983 return ACCOUNT_ERROR_NONE;
1986 ACCOUNT_API int account_type_set_icon_path_internal(account_type_h account_type, const char *icon_path)
1988 if (!account_type) {
1989 return ACCOUNT_ERROR_INVALID_PARAMETER;
1993 return ACCOUNT_ERROR_INVALID_PARAMETER;
1996 account_type_s *data = (account_type_s*)account_type;
1998 _ACCOUNT_FREE(data->icon_path);
1999 data->icon_path = _account_get_text(icon_path);
2001 return ACCOUNT_ERROR_NONE;
2004 ACCOUNT_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
2006 return ACCOUNT_ERROR_NONE;
2009 ACCOUNT_API int account_type_set_small_icon_path_internal(account_type_h account_type, const char *small_icon_path)
2011 if (!account_type) {
2012 return ACCOUNT_ERROR_INVALID_PARAMETER;
2015 if (!small_icon_path) {
2016 return ACCOUNT_ERROR_INVALID_PARAMETER;
2019 account_type_s *data = (account_type_s*)account_type;
2021 _ACCOUNT_FREE(data->small_icon_path);
2022 data->small_icon_path = _account_get_text(small_icon_path);
2024 return ACCOUNT_ERROR_NONE;
2027 ACCOUNT_API int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
2029 return ACCOUNT_ERROR_NONE;
2032 ACCOUNT_API int account_type_set_multiple_account_support_internal(account_type_h account_type, const bool multiple_account_support)
2034 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
2036 account_type_s *data = (account_type_s*)account_type;
2038 data->multiple_account_support = multiple_account_support;
2040 return ACCOUNT_ERROR_NONE;
2043 ACCOUNT_API int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
2045 return ACCOUNT_ERROR_NONE;
2048 ACCOUNT_API int account_type_set_label_internal(account_type_h account_type, const char* label, const char* locale)
2050 if (!account_type) {
2051 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
2052 return ACCOUNT_ERROR_INVALID_PARAMETER;
2055 if(!label || !locale) {
2056 return ACCOUNT_ERROR_INVALID_PARAMETER;
2059 account_type_s *data = (account_type_s*)account_type;
2060 label_s *label_data = (label_s*)malloc(sizeof(label_s));
2062 if (label_data == NULL) {
2063 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2065 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
2067 label_data->label = _account_get_text(label);
2068 label_data->locale = _account_get_text(locale);
2070 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
2072 return ACCOUNT_ERROR_NONE;
2075 ACCOUNT_API int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature)
2077 return ACCOUNT_ERROR_NONE;
2080 ACCOUNT_API int account_type_set_provider_feature_internal(account_type_h account_type, const char* provider_feature)
2082 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
2083 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
2085 account_type_s *data = (account_type_s*)account_type;
2087 GSList *iter = NULL;
2088 bool b_is_new = TRUE;
2090 for(iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2091 provider_feature_s *feature_data = NULL;
2092 feature_data = (provider_feature_s*)iter->data;
2094 if(!strcmp(feature_data->key, provider_feature)) {
2101 provider_feature_s* feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
2103 if (feature_data == NULL)
2104 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2105 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
2107 feature_data->key = _account_get_text(provider_feature);
2108 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
2111 return ACCOUNT_ERROR_NONE;
2114 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
2116 _INFO("account_type_query_provider_feature_by_app_id start");
2117 char* account_db_path = ACCOUNT_DB_NAME;
2119 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2120 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2124 GError *error = NULL;
2125 gint error_code = ACCOUNT_ERROR_NONE;
2127 AccountManager* acc_mgr = _account_manager_get_instance();
2128 if (acc_mgr == NULL)
2130 _ERR("g_bus_get_sync failed");
2131 return ACCOUNT_ERROR_PERMISSION_DENIED;
2134 GVariant* feature_list_variant = NULL;
2135 bool is_success = account_manager_call_account_type_query_provider_feature_by_app_id_sync(acc_mgr, account_db_path, app_id, e_cookie, &feature_list_variant, NULL, &error);
2136 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
2140 error_code = error->code;
2141 _ERR("Account IPC call returned error[%d]", error_code);
2145 GSList* provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
2146 if (provider_feature_list == NULL)
2148 error_code = ACCOUNT_ERROR_NO_DATA;
2149 _ERR("[%d]", error_code);
2154 for (iter = 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 _INFO("account_type_query_provider_feature_by_app_id end");
2169 ACCOUNT_API bool account_type_query_supported_feature(const char* app_id, const char* capability)
2171 _INFO("account_type_query_supported_feature start");
2172 char* account_db_path = ACCOUNT_DB_NAME;
2174 if (app_id == NULL || capability == NULL)
2176 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2182 int is_supported = 0;
2183 GError *error = NULL;
2184 gint ret = ACCOUNT_ERROR_NONE;
2186 AccountManager* acc_mgr = _account_manager_get_instance();
2187 if (acc_mgr == NULL)
2189 _ERR("g_bus_get_sync failed");
2190 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2194 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, account_db_path, app_id, capability, e_cookie, &is_supported, NULL, &error);
2195 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2200 _ERR("Account IPC call returned error[%d]", ret);
2201 set_last_result(ret);
2205 set_last_result(ACCOUNT_ERROR_NONE);
2206 _INFO("account_type_query_supported_feature end");
2207 return is_supported;
2210 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2212 if (!account_type) {
2213 return ACCOUNT_ERROR_INVALID_PARAMETER;
2217 return ACCOUNT_ERROR_INVALID_PARAMETER;
2220 account_type_s *data = (account_type_s*)account_type;
2223 *app_id = _account_get_text(data->app_id);
2225 return ACCOUNT_ERROR_NONE;
2228 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2230 if (!account_type) {
2231 return ACCOUNT_ERROR_INVALID_PARAMETER;
2234 if (!service_provider_id) {
2235 return ACCOUNT_ERROR_INVALID_PARAMETER;
2238 account_type_s *data = (account_type_s*)account_type;
2240 (*service_provider_id) = NULL;
2241 *service_provider_id = _account_get_text(data->service_provider_id);
2243 return ACCOUNT_ERROR_NONE;
2246 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2248 if (!account_type) {
2249 return ACCOUNT_ERROR_INVALID_PARAMETER;
2253 return ACCOUNT_ERROR_INVALID_PARAMETER;
2256 account_type_s *data = (account_type_s*)account_type;
2258 (*icon_path) = NULL;
2259 *icon_path = _account_get_text(data->icon_path);
2261 return ACCOUNT_ERROR_NONE;
2264 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2266 if (!account_type) {
2267 return ACCOUNT_ERROR_INVALID_PARAMETER;
2270 if (!small_icon_path) {
2271 return ACCOUNT_ERROR_INVALID_PARAMETER;
2274 account_type_s *data = (account_type_s*)account_type;
2276 (*small_icon_path) = NULL;
2277 *small_icon_path = _account_get_text(data->small_icon_path);
2279 return ACCOUNT_ERROR_NONE;
2282 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2284 if (!account_type) {
2285 return ACCOUNT_ERROR_INVALID_PARAMETER;
2287 if (!multiple_account_support) {
2288 return ACCOUNT_ERROR_INVALID_PARAMETER;
2291 account_type_s *data = (account_type_s*)account_type;
2293 *multiple_account_support = data->multiple_account_support;
2295 return ACCOUNT_ERROR_NONE;
2298 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void* user_data)
2300 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2301 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2304 account_type_s *data = (account_type_s*)account_type;
2306 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2307 provider_feature_s *feature_data = NULL;
2309 feature_data = (provider_feature_s*)iter->data;
2311 if(callback(feature_data->app_id, feature_data->key, user_data)!=TRUE) {
2312 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2313 return ACCOUNT_ERROR_NONE;
2317 return ACCOUNT_ERROR_NONE;
2320 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char* locale, char** label)
2322 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2323 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2326 account_type_s *data = (account_type_s*)account_type;
2328 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2329 label_s *label_data = NULL;
2331 label_data = (label_s*)iter->data;
2335 if(!strcmp(locale, label_data->locale)) {
2336 *label = _account_get_text(label_data->label);
2337 return ACCOUNT_ERROR_NONE;
2339 gchar** tokens = g_strsplit(locale, "-", 2);
2340 if(tokens != NULL) {
2341 if((char*)(tokens[1]) != NULL) {
2342 char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2343 if(upper_token != NULL) {
2344 char* converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2345 if(!strcmp(converted_locale, label_data->locale)) {
2346 _ACCOUNT_FREE(converted_locale);
2347 _ACCOUNT_FREE(upper_token);
2349 *label = _account_get_text(label_data->label);
2350 return ACCOUNT_ERROR_NONE;
2352 _ACCOUNT_FREE(converted_locale);
2354 _ACCOUNT_FREE(upper_token);
2360 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2363 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2365 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2366 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2369 account_type_s *data = (account_type_s*)account_type;
2371 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2372 label_s *label_data = NULL;
2374 label_data = (label_s*)iter->data;
2376 if(callback(label_data->app_id, label_data->label, label_data->locale, user_data)!=TRUE) {
2377 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2378 return ACCOUNT_ERROR_NONE;
2382 return ACCOUNT_ERROR_NONE;
2385 ACCOUNT_API int account_type_insert_to_db(account_type_h account_type, int* account_type_id)
2387 return ACCOUNT_ERROR_NONE;
2390 ACCOUNT_API int account_type_insert_to_db_internal(account_type_h account_type, int* account_type_id)
2392 _INFO("account_type_insert_to_db starting");
2393 char* account_db_path = ACCOUNT_DB_NAME;
2395 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2396 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2400 GError *error = NULL;
2402 AccountManager* acc_mgr = _account_manager_get_instance();
2403 if (acc_mgr == NULL)
2405 _ERR("g_bus_get_sync failed");
2406 return ACCOUNT_ERROR_PERMISSION_DENIED;
2410 GVariant* account_type_serialized = marshal_account_type((account_type_s*) account_type);
2411 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_db_path, account_type_serialized, e_cookie, &db_id, NULL, &error);
2412 int ret = _account_get_error_code(is_success, error);
2413 if (ret != ACCOUNT_ERROR_NONE)
2418 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2420 *account_type_id = db_id;
2422 account_type_s* account_type_data = (account_type_s*)account_type;
2423 account_type_data->id = db_id;
2425 return ACCOUNT_ERROR_NONE;
2428 ACCOUNT_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char* app_id)
2430 return ACCOUNT_ERROR_NONE;
2433 ACCOUNT_API int account_type_update_to_db_by_app_id_internal(const account_type_h account_type, const char* app_id)
2435 _INFO("account_type_update_to_db_by_app_id starting");
2436 char* account_db_path = ACCOUNT_DB_NAME;
2438 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2439 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2443 GError *error = NULL;
2445 AccountManager* acc_mgr = _account_manager_get_instance();
2446 if (acc_mgr == NULL)
2448 _ERR("g_bus_get_sync failed");
2449 return ACCOUNT_ERROR_PERMISSION_DENIED;
2452 GVariant* account_type_variant = marshal_account_type((account_type_s*) account_type);
2453 if (account_type_variant == NULL)
2455 _ERR("Failed to serialize");
2456 return ACCOUNT_ERROR_INVALID_PARAMETER;
2459 bool is_success = account_manager_call_account_type_update_to_db_by_app_id_sync(acc_mgr, account_db_path, account_type_variant, app_id, e_cookie, NULL, &error);
2460 return _account_get_error_code(is_success, error);
2463 ACCOUNT_API int account_type_delete_by_app_id(const char* app_id)
2465 return ACCOUNT_ERROR_NONE;
2468 ACCOUNT_API int account_type_delete_by_app_id_internal(const char* app_id)
2470 _INFO("account_type_delete_by_app_id starting");
2471 char* account_db_path = ACCOUNT_DB_NAME;
2473 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2477 GError *error = NULL;
2479 AccountManager* acc_mgr = _account_manager_get_instance();
2480 if (acc_mgr == NULL)
2482 _ERR("g_bus_get_sync failed");
2483 return ACCOUNT_ERROR_PERMISSION_DENIED;
2486 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, account_db_path, app_id, e_cookie, NULL, &error);
2487 return _account_get_error_code(is_success, error);
2490 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
2492 _INFO("account_type_query_label_by_app_id starting");
2493 char* account_db_path = ACCOUNT_DB_NAME;
2495 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2496 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2500 GError *error = NULL;
2502 AccountManager* acc_mgr = _account_manager_get_instance();
2503 if (acc_mgr == NULL)
2505 _ERR("g_bus_get_sync failed");
2506 return ACCOUNT_ERROR_PERMISSION_DENIED;
2509 GVariant* label_list_variant = NULL;
2510 bool is_success = account_manager_call_account_type_query_label_by_app_id_sync(acc_mgr, account_db_path, app_id, e_cookie, &label_list_variant, NULL, &error);
2511 int ret = _account_get_error_code(is_success, error);
2512 if (ret != ACCOUNT_ERROR_NONE)
2517 _INFO("before variant_to_label_list");
2518 GSList* label_list = variant_to_label_list (label_list_variant);
2519 _INFO("after variant_to_label_list");
2520 if (label_list == NULL)
2522 return ACCOUNT_ERROR_NO_DATA;
2527 for (iter = label_list; iter != NULL; iter = g_slist_next(iter))
2529 _INFO("iterating received account_list");
2530 label_s *label_record = NULL;
2531 label_record = (label_s*)iter->data;
2533 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false)
2535 _INFO("application callback requested to discontinue.");
2540 _INFO("account_type_query_label_by_app_id end");
2541 return ACCOUNT_ERROR_NONE;
2544 ACCOUNT_API int account_type_query_by_app_id(const char* app_id, account_type_h *account_type)
2546 _INFO("account_type_query_by_app_id starting");
2547 char* account_db_path = ACCOUNT_DB_NAME;
2549 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2550 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2551 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2555 GError *error = NULL;
2557 AccountManager* acc_mgr = _account_manager_get_instance();
2558 if (acc_mgr == NULL)
2560 _ERR("g_bus_get_sync failed");
2561 return ACCOUNT_ERROR_PERMISSION_DENIED;
2564 GVariant* account_type_variant = NULL;
2565 account_type_s *in_data = (account_type_s*) (*account_type);
2567 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, account_db_path, app_id, e_cookie, &account_type_variant, NULL, &error);
2568 int ret = _account_get_error_code(is_success, error);
2569 if (ret != ACCOUNT_ERROR_NONE)
2574 _INFO("before umarshal_account_type");
2575 account_type_s* received_account_type = umarshal_account_type (account_type_variant);
2576 _INFO("after umarshal_account_type");
2577 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2579 in_data->id = received_account_type->id;
2580 in_data->app_id = received_account_type->app_id;
2581 in_data->service_provider_id = received_account_type->service_provider_id;
2582 in_data->icon_path = received_account_type->icon_path;
2583 in_data->small_icon_path = received_account_type->small_icon_path;
2584 in_data->multiple_account_support = received_account_type->multiple_account_support;
2585 in_data->label_list = received_account_type->label_list;
2586 in_data->account_type_list = received_account_type->account_type_list;
2587 in_data->provider_feature_list = received_account_type->provider_feature_list;
2589 _INFO("account_type_query_by_app_id end");
2590 return ACCOUNT_ERROR_NONE;
2593 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2595 _INFO("account_type_foreach_account_type_from_db starting");
2596 char* account_db_path = ACCOUNT_DB_NAME;
2598 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2602 GError *error = NULL;
2604 AccountManager* acc_mgr = _account_manager_get_instance();
2605 if (acc_mgr == NULL)
2607 _ERR("g_bus_get_sync failed");
2608 return ACCOUNT_ERROR_PERMISSION_DENIED;
2611 GVariant* account_type_list_variant = NULL;
2612 _INFO("before account_type_query_all_sync()");
2613 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, account_db_path, e_cookie, &account_type_list_variant, NULL, &error);
2614 _INFO("after account_type_query_all_sync()");
2615 int ret = _account_get_error_code(is_success, error);
2616 if (ret != ACCOUNT_ERROR_NONE)
2621 _INFO("before unmarshal_account_type_list");
2622 GSList* account_type_list = unmarshal_account_type_list(account_type_list_variant);
2623 _INFO("after unmarshal_account_type_list");
2624 if (account_type_list == NULL)
2626 return ACCOUNT_ERROR_NO_DATA;
2631 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2633 _INFO("iterating received account_list");
2634 account_type_s *account_type = NULL;
2635 account_type = (account_type_s*)iter->data;
2637 if (callback((account_type_h)account_type, user_data) == false)
2639 _INFO("application callback requested to discontinue.");
2643 _INFO("account_foreach_account_from_db end");
2644 return ACCOUNT_ERROR_NONE;
2647 ACCOUNT_API int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label)
2649 _INFO("account_type_query_label_by_locale starting");
2650 char* account_db_path = ACCOUNT_DB_NAME;
2652 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2653 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2654 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2658 GError *error = NULL;
2660 AccountManager* acc_mgr = _account_manager_get_instance();
2661 if (acc_mgr == NULL)
2663 _ERR("g_bus_get_sync failed");
2664 return ACCOUNT_ERROR_PERMISSION_DENIED;
2667 char* label_temp = NULL;
2668 _INFO("before account_type_query_label_by_locale_sync()");
2669 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, account_db_path, app_id, locale, e_cookie, &label_temp, NULL, &error);
2670 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2671 int ret = _account_get_error_code(is_success, error);
2672 if (ret != ACCOUNT_ERROR_NONE)
2677 if (label_temp == NULL)
2679 return ACCOUNT_ERROR_NO_DATA;
2682 *label = _account_get_text(label_temp);
2683 _INFO("account_type_query_label_by_locale end");
2684 return ACCOUNT_ERROR_NONE;
2688 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char* key, void* user_data)
2690 _INFO("account_type_query_by_provider_feature starting");
2691 char* account_db_path = ACCOUNT_DB_NAME;
2693 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2694 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2698 GError *error = NULL;
2700 AccountManager* acc_mgr = _account_manager_get_instance();
2701 if (acc_mgr == NULL)
2703 _ERR("g_bus_get_sync failed");
2704 return ACCOUNT_ERROR_PERMISSION_DENIED;
2707 GVariant* account_type_list_variant = NULL;
2708 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, account_db_path, key, e_cookie, &account_type_list_variant, NULL, &error);
2709 int ret = _account_get_error_code(is_success, error);
2710 if (ret != ACCOUNT_ERROR_NONE)
2715 _INFO("before unmarshal_account_type_list");
2716 GSList* account_type_list = unmarshal_account_type_list(account_type_list_variant);
2717 _INFO("after unmarshal_account_type_list");
2718 if (account_type_list == NULL)
2720 return ACCOUNT_ERROR_NO_DATA;
2725 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2727 _INFO("iterating received account_type_list");
2728 account_type_s *account_type = NULL;
2729 account_type = (account_type_s*)iter->data;
2731 if (callback((account_type_h)account_type, user_data) == false)
2733 _INFO("Application callback requested not to continue");
2738 _INFO("account_type_query_by_provider_feature end");
2739 return ACCOUNT_ERROR_NONE;
2742 ACCOUNT_API int account_type_query_app_id_exist(const char* app_id)
2744 _INFO("account_type_query_app_id_exist starting");
2745 char* account_db_path = ACCOUNT_DB_NAME;
2747 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2751 GError *error = NULL;
2753 AccountManager* acc_mgr = _account_manager_get_instance();
2754 if (acc_mgr == NULL)
2756 _ERR("g_bus_get_sync failed");
2757 return ACCOUNT_ERROR_PERMISSION_DENIED;
2760 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, account_db_path, app_id, e_cookie, NULL, &error);
2762 return _account_get_error_code(is_success, error);
2766 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2768 account_subscribe_s* tmp = (account_subscribe_s*)user_data;
2769 char *msg = NULL, *vconf_key = NULL;
2770 char event_msg[256] ={0, };
2771 int account_id = -1;
2774 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2779 ACCOUNT_ERROR("user data required\n");
2783 if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2785 vconf_key = vconf_keynode_get_str(key);
2787 if( vconf_key == NULL){
2788 ACCOUNT_ERROR("vconf key is NULL.\n");
2791 msg = strdup(vconf_key);
2793 char* event_type = NULL;
2797 event_type = strtok_r(msg, ":", &ptr);
2798 id = strtok_r(NULL, ":", &ptr);
2800 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2802 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2804 account_id = atoi(id);
2806 if(tmp->account_subscription_callback)
2807 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2814 ACCOUNT_API int account_subscribe_create(account_subscribe_h* account_subscribe)
2816 if (!account_subscribe) {
2817 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2818 return ACCOUNT_ERROR_INVALID_PARAMETER;
2821 account_subscribe_s *data = (account_subscribe_s*)calloc(1,sizeof(account_subscribe_s));
2824 ACCOUNT_FATAL("OUT OF MEMORY\n");
2825 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2828 *account_subscribe = (account_subscribe_h)data;
2830 return ACCOUNT_ERROR_NONE;
2833 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2835 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2837 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2839 tmp->account_subscription_callback = callback;
2840 tmp->user_data = user_data;
2843 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2844 (vconf_callback_fn)_account_subscribe_vconf_callback,
2847 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2849 if(ret != VCONF_OK) {
2850 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2851 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2854 return ACCOUNT_ERROR_NONE;
2857 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2859 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2861 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2865 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2866 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
2867 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2868 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2871 return ACCOUNT_ERROR_NONE;
2874 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2876 account_subscribe_s* tmp = (account_subscribe_s*)user_data;
2877 char *msg = NULL, *vconf_key = NULL;
2878 char event_msg[256] ={0, };
2879 int account_id = -1;
2882 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2887 ACCOUNT_ERROR("user data required\n");
2891 if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2893 vconf_key = vconf_keynode_get_str(key);
2895 if( vconf_key == NULL){
2896 ACCOUNT_ERROR("vconf key is NULL.\n");
2899 msg = strdup(vconf_key);
2901 char* event_type = NULL;
2905 event_type = strtok_r(msg, ":", &ptr);
2906 id = strtok_r(NULL, ":", &ptr);
2908 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2910 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2912 account_id = atoi(id);
2914 if(tmp->account_subscription_callback)
2915 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2922 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2924 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2926 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2930 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2931 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
2932 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2933 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2936 return ACCOUNT_ERROR_NONE;
2939 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2941 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2943 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2945 tmp->account_subscription_callback = callback;
2946 tmp->user_data = user_data;
2949 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2950 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2953 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2955 if(ret != VCONF_OK) {
2956 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2957 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2960 return ACCOUNT_ERROR_NONE;