3 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include <glib/gprintf.h>
24 #include <gio/gunixfdlist.h>
30 #include <account-private.h>
31 #include <account_free.h>
32 #include <account_ipc_marshal.h>
33 #include <account-mgr-stub.h>
35 #ifdef TIZEN_PROFILE_MOBILE
36 #include "mobile/account.h"
38 #include "wearable/account.h"
41 #include "account-error.h"
42 #include "account-types.h"
43 #include "account_internal.h"
44 #include "account_private_client.h"
46 #define ACCOUNT_DB_OPEN_READONLY 0
47 #define ACCOUNT_DB_OPEN_READWRITE 1
51 static AccountManager *_acc_mgr = NULL;
53 static char *_account_get_text(const char *text_data)
55 char *text_value = NULL;
57 if (text_data != NULL)
58 text_value = strdup(text_data);
64 _account_manager_get_instance()
66 _INFO("_account_manager_get_instance");
67 if (_acc_mgr != NULL) {
68 _INFO("instance already created.");
72 #if !GLIB_CHECK_VERSION(2, 35, 0)
76 GDBusConnection *connection = NULL;
79 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
81 _INFO("after g_bus_get_sync");
85 _ERR("Unable to connect to gdbus: %s", error->message);
86 g_clear_error(&error);
91 g_clear_error(&error);
93 /* Create the object */
95 account_manager_proxy_new_sync(connection,
96 G_DBUS_PROXY_FLAGS_NONE,
97 "org.tizen.account.manager",
98 "/org/tizen/account/manager",
104 _ERR("Unable account_manager_proxy_new_sync: %s", error->message);
105 g_clear_error(&error);
108 g_object_unref(connection);
112 g_clear_error(&error);
113 _INFO("_account_manager_get_instance end");
117 GDBusErrorEntry _account_svc_errors[] = {
118 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
119 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
120 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
121 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
122 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
123 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
124 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
125 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
126 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
127 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
128 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
129 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
130 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
131 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
132 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
133 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
134 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
135 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
138 static int _account_get_error_code(bool is_success, GError *error)
141 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
143 if (g_dbus_error_is_remote_error(error)) {
144 gchar *remote_error = g_dbus_error_get_remote_error(error);
146 _INFO("Remote error[%s]", remote_error);
148 /* FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
149 However error->message matches, so doing reverse lookup */
150 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
152 for (i = 0; i < error_enum_count; i++) {
153 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0) {
154 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
155 g_free(remote_error);
156 return _account_svc_errors[i].error_code;
159 g_free(remote_error);
162 /* All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED */
163 return ACCOUNT_ERROR_PERMISSION_DENIED;
165 return ACCOUNT_ERROR_NONE;
168 #ifdef TIZEN_PROFILE_MOBILE
169 ACCOUNT_API int account_connect(void)
171 return ACCOUNT_ERROR_NONE;
174 ACCOUNT_API int account_connect_readonly(void)
176 return ACCOUNT_ERROR_NONE;
179 ACCOUNT_API int account_disconnect(void)
181 return ACCOUNT_ERROR_NONE;
186 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
188 _INFO("1. account_insert_to_db start");
190 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
191 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
193 account_s *account_data = (account_s *)account;
194 int error_code = ACCOUNT_ERROR_NONE;
195 GError *error = NULL;
197 _INFO("2. Before _account_manager_get_instance()");
198 AccountManager *acc_mgr = _account_manager_get_instance();
199 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
202 GVariant *account_serialized = marshal_account(account_data);
204 _INFO("3. Before account_manager_call_account_add_sync");
205 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_serialized, (int)getuid(), &db_id, NULL, &error);
207 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
208 g_clear_error(&error);
210 *account_db_id = db_id;
211 account_data->id = db_id;
213 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
215 return ACCOUNT_ERROR_NONE;
218 g_clear_error(&error);
219 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
224 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
226 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
227 int error_code = ACCOUNT_ERROR_NONE;
229 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
231 GError *error = NULL;
233 AccountManager *acc_mgr = _account_manager_get_instance();
234 if (acc_mgr == NULL) {
235 _ERR("g_bus_get_sync failed");
236 return ACCOUNT_ERROR_PERMISSION_DENIED;
239 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
240 GVariant *account_serialized_old = NULL;
241 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)getuid(), &account_serialized_old, NULL, &error);
244 error_code = _account_get_error_code(is_success, error);
245 g_clear_error(&error);
246 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
249 g_clear_error(&error);
251 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
252 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_id, (int)getuid(), NULL, &error);
255 error_code = _account_get_error_code(is_success, error);
256 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error_code);
257 g_clear_error(&error);
260 g_clear_error(&error);
262 _INFO("4. Before account_delete_from_db_by_id end");
263 return ACCOUNT_ERROR_NONE;
266 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
268 int error_code = ACCOUNT_ERROR_NONE;
269 _INFO("account_delete_from_db_by_user_name start");
271 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
272 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
275 GError *error = NULL;
277 AccountManager *acc_mgr = _account_manager_get_instance();
278 if (acc_mgr == NULL) {
279 _ERR("g_bus_get_sync failed");
280 return ACCOUNT_ERROR_PERMISSION_DENIED;
283 GVariant *account_list_variant = NULL;
284 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
286 error_code = _account_get_error_code(is_success, error);
287 g_clear_error(&error);
288 if (error_code != ACCOUNT_ERROR_NONE) {
289 _ERR("account_query_account_by_user_name error=[%d]", error_code);
293 GSList *account_list = unmarshal_account_list(account_list_variant);
294 g_variant_unref(account_list_variant);
296 if (account_list == NULL)
297 return ACCOUNT_ERROR_NO_DATA;
299 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, user_name, package_name, (int)getuid(), NULL, &error);
302 error_code = _account_get_error_code(is_success, error);
303 g_clear_error(&error);
304 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
305 _account_gslist_account_free(account_list);
308 g_clear_error(&error);
310 _account_gslist_account_free(account_list);
311 return ACCOUNT_ERROR_NONE;
314 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
316 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
317 int error_code = ACCOUNT_ERROR_NONE;
319 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
321 GError *error = NULL;
323 AccountManager *acc_mgr = _account_manager_get_instance();
324 if (acc_mgr == NULL) {
325 _ERR("g_bus_get_sync failed");
326 return ACCOUNT_ERROR_PERMISSION_DENIED;
329 //First get account list of user_name, used for gSSO DB deletion
330 GVariant* account_list_variant = NULL;
331 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, (int)getuid(), &account_list_variant, NULL, &error);
333 error_code = _account_get_error_code(is_success, error);
334 if (error_code != ACCOUNT_ERROR_NONE)
339 _INFO("before unmarshal_account_list");
340 GSList* account_list = unmarshal_account_list(account_list_variant);
341 _INFO("after unmarshal_account_list");
342 if (account_list == NULL)
344 return ACCOUNT_ERROR_NO_DATA;
347 bool is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, package_name, permission, (int)getuid(), NULL, &error);
350 error_code = _account_get_error_code(is_success, error);
351 g_clear_error(&error);
352 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error_code);
355 g_clear_error(&error);
357 return ACCOUNT_ERROR_NONE;
360 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
362 _INFO("account_delete_from_db_by_package_name starting with permission");
363 return _account_delete_from_db_by_package_name(package_name, true);
366 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
368 _INFO("1. account_update_to_db_by_id start");
369 int error_code = ACCOUNT_ERROR_NONE;
371 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
372 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
374 GError *error = NULL;
376 AccountManager *acc_mgr = _account_manager_get_instance();
377 if (acc_mgr == NULL) {
378 _ERR("g_bus_get_sync failed");
379 return ACCOUNT_ERROR_PERMISSION_DENIED;
382 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
383 GVariant *account_serialized_old = NULL;
384 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &account_serialized_old, NULL, &error);
387 error_code = _account_get_error_code(is_success, error);
388 g_clear_error(&error);
389 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
392 g_clear_error(&error);
394 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
395 GVariant *account_serialized = marshal_account((account_s *)account);
396 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
399 error_code = _account_get_error_code(is_success, error);
400 g_clear_error(&error);
401 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error_code);
404 g_clear_error(&error);
406 _INFO("4. account_update_to_db_by_id end");
407 return ACCOUNT_ERROR_NONE;
410 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
413 ret = account_update_to_db_by_id(account, account_id);
418 ACCOUNT_INTERNAL_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
420 _INFO("account_update_to_db_by_id_without_permission start");
421 int error_code = ACCOUNT_ERROR_NONE;
423 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
424 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
426 GError *error = NULL;
428 AccountManager *acc_mgr = _account_manager_get_instance();
429 if (acc_mgr == NULL) {
430 _ERR("g_bus_get_sync failed");
431 return ACCOUNT_ERROR_PERMISSION_DENIED;
434 GVariant *account_serialized_old = NULL;
435 _INFO("before query() account_id[%d]", account_id);
436 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &account_serialized_old, NULL, &error);
439 error_code = _account_get_error_code(is_success, error);
440 g_clear_error(&error);
441 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
444 g_clear_error(&error);
446 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s *)account)->user_name);
447 GVariant *account_serialized = marshal_account((account_s *)account);
448 _INFO("after marshal() : account_id[%d]", account_id);
449 if (account_serialized == NULL) {
450 _ERR("Invalid input");
451 return ACCOUNT_ERROR_INVALID_PARAMETER;
454 _INFO("before call update() : account_id[%d]", account_id);
455 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
457 _INFO("after call update() : is_success=%d", is_success);
459 error_code = _account_get_error_code(is_success, error);
460 g_clear_error(&error);
461 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error_code);
464 g_clear_error(&error);
466 return ACCOUNT_ERROR_NONE;
469 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
471 _INFO("account_update_to_db_by_user_name starting");
472 int error_code = ACCOUNT_ERROR_NONE;
474 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
475 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
476 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
478 GError *error = NULL;
480 AccountManager *acc_mgr = _account_manager_get_instance();
481 if (acc_mgr == NULL) {
482 _ERR("g_bus_get_sync failed");
483 return ACCOUNT_ERROR_PERMISSION_DENIED;
486 GVariant *account_serialized_old = NULL;
487 account_s *account_data = (account_s *)account;
488 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_data->id, (int)getuid(), &account_serialized_old, NULL, &error);
491 error_code = _account_get_error_code(is_success, error);
492 g_clear_error(&error);
493 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
496 g_clear_error(&error);
498 GVariant *account_serialized = marshal_account(account_data);
499 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);
502 error_code = _account_get_error_code(is_success, error);
503 g_clear_error(&error);
504 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error_code);
507 g_clear_error(&error);
509 return ACCOUNT_ERROR_NONE;
512 ACCOUNT_API int account_create(account_h *account)
514 _INFO("account_create start");
516 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
517 return ACCOUNT_ERROR_INVALID_PARAMETER;
520 account_s *data = (account_s *)malloc(sizeof(account_s));
522 ACCOUNT_FATAL("Memory Allocation Failed");
523 return ACCOUNT_ERROR_OUT_OF_MEMORY;
526 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
528 /* Setting account as visible by default */
529 data->secret = ACCOUNT_SECRECY_VISIBLE;
531 /* Setting account as not supporting sync by default */
532 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
534 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
536 data->capablity_list = NULL;
537 data->custom_list = NULL;
539 *account = (account_h)data;
541 _INFO("account_create end");
542 return ACCOUNT_ERROR_NONE;
545 ACCOUNT_API int account_destroy(account_h account)
547 _INFO("account_destroy start");
548 account_s *data = (account_s *)account;
550 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
552 _account_free_account_with_items(data);
554 _INFO("account_destroy end");
555 return ACCOUNT_ERROR_NONE;
558 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
561 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
562 return ACCOUNT_ERROR_INVALID_PARAMETER;
566 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
567 return ACCOUNT_ERROR_INVALID_PARAMETER;
570 account_s *data = (account_s *)account;
572 _ACCOUNT_FREE(data->user_name);
573 data->user_name = _account_get_text(user_name);
574 if (data->user_name == NULL) {
575 ACCOUNT_FATAL("OUT OF MEMORY\n");
576 return ACCOUNT_ERROR_OUT_OF_MEMORY;
579 return ACCOUNT_ERROR_NONE;
582 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
585 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
586 return ACCOUNT_ERROR_INVALID_PARAMETER;
590 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
591 return ACCOUNT_ERROR_INVALID_PARAMETER;
594 account_s *data = (account_s *)account;
596 _ACCOUNT_FREE(data->display_name);
597 data->display_name = _account_get_text(display_name);
598 if (data->display_name == NULL) {
599 ACCOUNT_FATAL("OUT OF MEMORY\n");
600 return ACCOUNT_ERROR_OUT_OF_MEMORY;
603 return ACCOUNT_ERROR_NONE;
606 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
609 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
610 return ACCOUNT_ERROR_INVALID_PARAMETER;
613 if (!email_address) {
614 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
615 return ACCOUNT_ERROR_INVALID_PARAMETER;
618 account_s *data = (account_s *)account;
620 _ACCOUNT_FREE(data->email_address);
621 data->email_address = _account_get_text(email_address);
622 if (data->email_address == NULL) {
623 ACCOUNT_FATAL("OUT OF MEMORY\n");
624 return ACCOUNT_ERROR_OUT_OF_MEMORY;
627 return ACCOUNT_ERROR_NONE;
630 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
633 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
634 return ACCOUNT_ERROR_INVALID_PARAMETER;
638 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
639 return ACCOUNT_ERROR_INVALID_PARAMETER;
642 account_s *data = (account_s *)account;
644 _ACCOUNT_FREE(data->icon_path);
645 data->icon_path = _account_get_text(icon_path);
646 if (data->icon_path == NULL) {
647 ACCOUNT_FATAL("OUT OF MEMORY\n");
648 return ACCOUNT_ERROR_OUT_OF_MEMORY;
651 return ACCOUNT_ERROR_NONE;
654 ACCOUNT_API int account_set_source(account_h account, const char *source)
657 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
658 return ACCOUNT_ERROR_INVALID_PARAMETER;
662 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
663 return ACCOUNT_ERROR_INVALID_PARAMETER;
665 account_s *data = (account_s *)account;
667 _ACCOUNT_FREE(data->source);
668 data->source = _account_get_text(source);
669 if (data->source == NULL) {
670 ACCOUNT_FATAL("OUT OF MEMORY\n");
671 return ACCOUNT_ERROR_OUT_OF_MEMORY;
674 return ACCOUNT_ERROR_NONE;
677 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
680 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
681 return ACCOUNT_ERROR_INVALID_PARAMETER;
685 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
686 return ACCOUNT_ERROR_INVALID_PARAMETER;
689 account_s *data = (account_s *)account;
691 _ACCOUNT_FREE(data->package_name);
692 data->package_name = _account_get_text(package_name);
693 if (data->package_name == NULL) {
694 ACCOUNT_FATAL("OUT OF MEMORY\n");
695 return ACCOUNT_ERROR_OUT_OF_MEMORY;
698 return ACCOUNT_ERROR_NONE;
701 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
704 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
705 return ACCOUNT_ERROR_INVALID_PARAMETER;
709 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
710 return ACCOUNT_ERROR_INVALID_PARAMETER;
712 account_s *data = (account_s *)account;
714 _ACCOUNT_FREE(data->domain_name);
715 data->domain_name = _account_get_text(domain_name);
716 if (data->domain_name == NULL) {
717 ACCOUNT_FATAL("OUT OF MEMORY\n");
718 return ACCOUNT_ERROR_OUT_OF_MEMORY;
721 return ACCOUNT_ERROR_NONE;
724 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
727 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
728 return ACCOUNT_ERROR_INVALID_PARAMETER;
732 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
733 return ACCOUNT_ERROR_INVALID_PARAMETER;
736 account_s *data = (account_s *)account;
738 _ACCOUNT_FREE(data->access_token);
739 data->access_token = _account_get_text(access_token);
740 if (data->access_token == NULL) {
741 ACCOUNT_FATAL("OUT OF MEMORY\n");
742 return ACCOUNT_ERROR_OUT_OF_MEMORY;
745 return ACCOUNT_ERROR_NONE;
748 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
751 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
752 return ACCOUNT_ERROR_INVALID_PARAMETER;
756 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
757 return ACCOUNT_ERROR_INVALID_PARAMETER;
759 if (idx >= USER_TXT_CNT || idx < 0) {
760 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
761 return ACCOUNT_ERROR_INVALID_PARAMETER;
764 account_s *data = (account_s *)account;
766 _ACCOUNT_FREE(data->user_data_txt[idx]);
767 data->user_data_txt[idx] = _account_get_text(user_txt);
768 if (data->user_data_txt[idx] == NULL) {
769 ACCOUNT_FATAL("OUT OF MEMORY\n");
770 return ACCOUNT_ERROR_OUT_OF_MEMORY;
773 return ACCOUNT_ERROR_NONE;
776 ACCOUNT_API int account_set_custom(account_h account, const char *key, const char *value)
779 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
780 return ACCOUNT_ERROR_INVALID_PARAMETER;
784 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
785 return ACCOUNT_ERROR_INVALID_PARAMETER;
789 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
790 return ACCOUNT_ERROR_INVALID_PARAMETER;
793 account_s *data = (account_s *)account;
796 bool b_is_new = TRUE;
798 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
800 account_custom_s *custom_data = NULL;
801 custom_data = (account_custom_s *)iter->data;
802 ACCOUNT_SLOGD("account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
804 if (!strcmp(custom_data->key, key)) {
805 char *new_value = NULL;
806 new_value = _account_get_text(value);
807 if (new_value == NULL) {
808 ACCOUNT_FATAL("OUT OF MEMORY\n");
809 return ACCOUNT_ERROR_OUT_OF_MEMORY;
812 _ACCOUNT_FREE(custom_data->value);
813 custom_data->value = new_value;
820 int error_code = ACCOUNT_ERROR_NONE;
822 account_custom_s* custom_data = (account_custom_s *)malloc(sizeof(account_custom_s));
823 if (custom_data == NULL) {
824 ACCOUNT_FATAL("Memory Allocation Failed");
825 return ACCOUNT_ERROR_OUT_OF_MEMORY;
828 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
829 custom_data->account_id = data->id;
831 /* custom's app_id field will be automatically filled by account-svc daemon. */
832 /* custom_data->app_id = _account_get_text(data->package_name);
833 if (data->package_name != NULL && custom_data->app_id == NULL) {
834 ACCOUNT_FATAL("OUT OF MEMORY\n");
835 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
838 custom_data->key = _account_get_text(key);
839 if (custom_data->key == NULL) {
840 ACCOUNT_FATAL("OUT OF MEMORY\n");
841 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
844 custom_data->value = _account_get_text(value);
845 if (custom_data->value == NULL) {
846 ACCOUNT_FATAL("OUT OF MEMORY\n");
847 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
850 if (error_code != ACCOUNT_ERROR_NONE) {
851 _ACCOUNT_FREE(custom_data->app_id);
852 _ACCOUNT_FREE(custom_data->key);
853 _ACCOUNT_FREE(custom_data->value);
854 _ACCOUNT_FREE(custom_data);
858 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
861 return ACCOUNT_ERROR_NONE;
864 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
866 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
868 if (((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN))
869 return ACCOUNT_ERROR_INVALID_PARAMETER;
871 account_s *data = (account_s *)account;
873 data->auth_type = (int)auth_type;
875 return ACCOUNT_ERROR_NONE;
878 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
880 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
882 if (((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE))
883 return ACCOUNT_ERROR_INVALID_PARAMETER;
885 account_s *data = (account_s *)account;
887 data->secret = (int)secret;
889 return ACCOUNT_ERROR_NONE;
892 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
894 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
896 if (((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC))
897 return ACCOUNT_ERROR_INVALID_PARAMETER;
899 account_s *data = (account_s *)account;
901 data->sync_support = (int)sync_support;
903 return ACCOUNT_ERROR_NONE;
906 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
909 return ACCOUNT_ERROR_INVALID_PARAMETER;
911 if (idx >= USER_INT_CNT || idx < 0)
912 return ACCOUNT_ERROR_INVALID_PARAMETER;
914 account_s *data = (account_s *)account;
916 data->user_data_int[idx] = user_int;
918 return ACCOUNT_ERROR_NONE;
921 ACCOUNT_API int account_set_capability(account_h account, const char *capability_type, account_capability_state_e capability_value)
923 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
924 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
926 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED))
927 return ACCOUNT_ERROR_INVALID_PARAMETER;
929 account_s *data = (account_s *)account;
932 bool b_is_new = TRUE;
934 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
935 account_capability_s *cap_data = NULL;
936 cap_data = (account_capability_s *)iter->data;
938 if (!strcmp(cap_data->type, capability_type)) {
939 cap_data->value = capability_value;
946 account_capability_s *cap_data = (account_capability_s *)malloc(sizeof(account_capability_s));
947 if (cap_data == NULL) {
948 ACCOUNT_FATAL("Memory Allocation Failed");
949 return ACCOUNT_ERROR_OUT_OF_MEMORY;
952 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
954 cap_data->type = _account_get_text(capability_type);
955 if (cap_data->type == NULL) {
956 ACCOUNT_FATAL("OUT OF MEMORY\n");
957 _ACCOUNT_FREE(cap_data->type);
958 _ACCOUNT_FREE(cap_data);
959 return ACCOUNT_ERROR_OUT_OF_MEMORY;
962 cap_data->value = capability_value;
963 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
966 return ACCOUNT_ERROR_NONE;
969 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
972 return ACCOUNT_ERROR_INVALID_PARAMETER;
975 return ACCOUNT_ERROR_INVALID_PARAMETER;
977 account_s *data = (account_s *)account;
980 *user_name = _account_get_text(data->user_name);
981 if (data->user_name != NULL && *user_name == NULL) {
982 ACCOUNT_FATAL("OUT OF MEMORY\n");
983 return ACCOUNT_ERROR_OUT_OF_MEMORY;
986 return ACCOUNT_ERROR_NONE;
989 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
992 return ACCOUNT_ERROR_INVALID_PARAMETER;
995 return ACCOUNT_ERROR_INVALID_PARAMETER;
997 account_s *data = (account_s *)account;
999 (*display_name) = NULL;
1001 *display_name = _account_get_text(data->display_name);
1002 if (data->display_name != NULL && *display_name == NULL) {
1003 ACCOUNT_FATAL("OUT OF MEMORY\n");
1004 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1008 return ACCOUNT_ERROR_NONE;
1011 ACCOUNT_API int account_get_email_address(account_h account, char **email_address)
1014 return ACCOUNT_ERROR_INVALID_PARAMETER;
1017 return ACCOUNT_ERROR_INVALID_PARAMETER;
1019 account_s *data = (account_s *)account;
1021 (*email_address) = NULL;
1023 *email_address = _account_get_text(data->email_address);
1024 if (data->email_address != NULL && *email_address == NULL) {
1025 ACCOUNT_FATAL("OUT OF MEMORY\n");
1026 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1029 return ACCOUNT_ERROR_NONE;
1032 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
1035 return ACCOUNT_ERROR_INVALID_PARAMETER;
1038 return ACCOUNT_ERROR_INVALID_PARAMETER;
1040 account_s *data = (account_s *)account;
1042 (*icon_path) = NULL;
1044 *icon_path = _account_get_text(data->icon_path);
1045 if (data->icon_path != NULL && *icon_path == NULL) {
1046 ACCOUNT_FATAL("OUT OF MEMORY\n");
1047 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1050 return ACCOUNT_ERROR_NONE;
1053 ACCOUNT_API int account_get_source(account_h account, char **source)
1056 return ACCOUNT_ERROR_INVALID_PARAMETER;
1059 return ACCOUNT_ERROR_INVALID_PARAMETER;
1061 account_s *data = (account_s *)account;
1065 *source = _account_get_text(data->source);
1066 if (data->source != NULL && *source == NULL) {
1067 ACCOUNT_FATAL("OUT OF MEMORY\n");
1068 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1071 return ACCOUNT_ERROR_NONE;
1074 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1077 return ACCOUNT_ERROR_INVALID_PARAMETER;
1080 return ACCOUNT_ERROR_INVALID_PARAMETER;
1082 account_s *data = (account_s *)account;
1084 (*package_name) = NULL;
1086 *package_name = _account_get_text(data->package_name);
1087 if (data->package_name != NULL && *package_name == NULL) {
1088 ACCOUNT_FATAL("OUT OF MEMORY\n");
1089 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1093 return ACCOUNT_ERROR_NONE;
1096 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1099 return ACCOUNT_ERROR_INVALID_PARAMETER;
1102 return ACCOUNT_ERROR_INVALID_PARAMETER;
1104 account_s *data = (account_s *)account;
1106 (*domain_name) = NULL;
1108 *domain_name = _account_get_text(data->domain_name);
1109 if (data->domain_name != NULL && *domain_name == NULL) {
1110 ACCOUNT_FATAL("OUT OF MEMORY\n");
1111 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1114 return ACCOUNT_ERROR_NONE;
1117 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1120 return ACCOUNT_ERROR_INVALID_PARAMETER;
1123 return ACCOUNT_ERROR_INVALID_PARAMETER;
1125 account_s *data = (account_s *)account;
1127 (*access_token) = NULL;
1129 *access_token = _account_get_text(data->access_token);
1130 if (data->access_token != NULL && *access_token == NULL) {
1131 ACCOUNT_FATAL("OUT OF MEMORY\n");
1132 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1135 return ACCOUNT_ERROR_NONE;
1138 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1141 return ACCOUNT_ERROR_INVALID_PARAMETER;
1144 return ACCOUNT_ERROR_INVALID_PARAMETER;
1146 ACCOUNT_RETURN_VAL((user_text_index >= 0 && user_text_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1148 account_s *data = (account_s *)account;
1152 *text = _account_get_text(data->user_data_txt[user_text_index]);
1153 if (data->user_data_txt[user_text_index] != NULL && *text == NULL) {
1154 ACCOUNT_FATAL("OUT OF MEMORY\n");
1155 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1158 return ACCOUNT_ERROR_NONE;
1161 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1164 return ACCOUNT_ERROR_INVALID_PARAMETER;
1167 return ACCOUNT_ERROR_INVALID_PARAMETER;
1169 account_s *data = (account_s *)account;
1171 *auth_type = data->auth_type;
1173 return ACCOUNT_ERROR_NONE;
1176 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1179 return ACCOUNT_ERROR_INVALID_PARAMETER;
1182 return ACCOUNT_ERROR_INVALID_PARAMETER;
1184 account_s *data = (account_s *)account;
1186 *secret = data->secret;
1188 return ACCOUNT_ERROR_NONE;
1191 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1194 return ACCOUNT_ERROR_INVALID_PARAMETER;
1197 return ACCOUNT_ERROR_INVALID_PARAMETER;
1199 account_s *data = (account_s *)account;
1201 *sync_support = data->sync_support;
1203 return ACCOUNT_ERROR_NONE;
1206 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1209 return ACCOUNT_ERROR_INVALID_PARAMETER;
1212 return ACCOUNT_ERROR_INVALID_PARAMETER;
1214 account_s *data = (account_s *)account;
1216 *account_id = data->id;
1218 return ACCOUNT_ERROR_NONE;
1221 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1224 return ACCOUNT_ERROR_INVALID_PARAMETER;
1226 ACCOUNT_RETURN_VAL((user_int_index >= 0 && user_int_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1229 return ACCOUNT_ERROR_INVALID_PARAMETER;
1231 account_s *data = (account_s *)account;
1233 *integer = data->user_data_int[user_int_index];
1235 return ACCOUNT_ERROR_NONE;
1238 ACCOUNT_API int account_get_capability(account_h account, const char *capability_type, account_capability_state_e *capability_value)
1240 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1241 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1242 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1245 account_s *data = (account_s *)account;
1247 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1248 account_capability_s *cap_data = NULL;
1250 cap_data = (account_capability_s *)iter->data;
1252 if (!strcmp(capability_type, cap_data->type)) {
1253 *capability_value = cap_data->value;
1254 return ACCOUNT_ERROR_NONE;
1258 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1261 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1263 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1264 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1267 account_s *data = (account_s *)account;
1269 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1270 account_capability_s *cap_data = NULL;
1272 cap_data = (account_capability_s *)iter->data;
1274 if (callback(cap_data->type, cap_data->value, user_data) != TRUE)
1275 return ACCOUNT_ERROR_NONE;
1278 return ACCOUNT_ERROR_NONE;
1281 ACCOUNT_API int account_get_custom(account_h account, const char *key, char **value)
1283 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1284 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1285 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1288 account_s *data = (account_s *)account;
1290 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1291 account_custom_s *custom_data = NULL;
1293 custom_data = (account_custom_s *)iter->data;
1295 if (!strcmp(key, custom_data->key)) {
1297 *value = _account_get_text(custom_data->value);
1298 if (custom_data->value != NULL && *value == NULL) {
1299 ACCOUNT_FATAL("OUT OF MEMORY\n");
1300 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1303 return ACCOUNT_ERROR_NONE;
1307 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1310 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void *user_data)
1312 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1313 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1316 account_s *data = (account_s *)account;
1318 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1319 bool cb_ret = FALSE;
1320 account_custom_s *custom_data = NULL;
1322 custom_data = (account_custom_s *)iter->data;
1324 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1329 return ACCOUNT_ERROR_NONE;
1332 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1334 _INFO("account_foreach_account_from_db start");
1336 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1338 GError *error = NULL;
1340 AccountManager *acc_mgr = _account_manager_get_instance();
1341 if (acc_mgr == NULL) {
1342 _ERR("g_bus_get_sync failed");
1343 return ACCOUNT_ERROR_PERMISSION_DENIED;
1346 GVariant *account_list_variant = NULL;
1347 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, (int)getuid(), &account_list_variant, NULL, &error);
1349 int error_code = _account_get_error_code(is_success, error);
1350 g_clear_error(&error);
1352 if (error_code != ACCOUNT_ERROR_NONE)
1355 GSList *account_list = unmarshal_account_list(account_list_variant);
1356 g_variant_unref(account_list_variant);
1360 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1361 _INFO("iterating received account_list");
1362 account_s *account = NULL;
1363 account = (account_s *)iter->data;
1364 _INFO("Before _account_query_identity_info_by_id");
1366 _INFO("account->id=%d", account->id);
1367 if (callback((account_h)account, user_data) == false) {
1368 _INFO("application callback requested to discontinue.");
1371 _INFO("After one iteration callback");
1373 _account_gslist_account_free(account_list);
1375 _INFO("account_foreach_account_from_db end");
1376 return ACCOUNT_ERROR_NONE;
1379 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1381 _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1383 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1384 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT POINTER IS NULL"));
1385 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1387 GError *error = NULL;
1389 AccountManager *acc_mgr = _account_manager_get_instance();
1390 if (acc_mgr == NULL) {
1391 _ERR("g_bus_get_sync failed");
1392 return ACCOUNT_ERROR_PERMISSION_DENIED;
1395 GVariant *account_variant = NULL;
1396 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)getuid(), &account_variant, NULL, &error);
1398 int error_code = _account_get_error_code(is_success, error);
1399 g_clear_error(&error);
1400 if (error_code != ACCOUNT_ERROR_NONE)
1403 _INFO("before unmarshal_account");
1404 account_s *account_data = umarshal_account(account_variant);
1405 g_variant_unref(account_variant);
1406 _INFO("after unmarshal_account");
1408 if (account_data == NULL) {
1409 _ERR("Failed to unmarshal");
1410 return ACCOUNT_ERROR_DB_FAILED;
1413 account_s **input = (account_s **)account;
1415 _account_free_account_with_items(*input);
1417 *input = account_data;
1419 _INFO("account_query_account_by_account_id end");
1421 return ACCOUNT_ERROR_NONE;
1424 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char *user_name, void *user_data)
1426 _INFO("account_query_account_by_user_name starting");
1428 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1429 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1431 GError *error = NULL;
1433 AccountManager *acc_mgr = _account_manager_get_instance();
1434 if (acc_mgr == NULL) {
1435 _ERR("g_bus_get_sync failed");
1436 return ACCOUNT_ERROR_PERMISSION_DENIED;
1439 GVariant *account_list_variant = NULL;
1440 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
1442 int error_code = _account_get_error_code(is_success, error);
1443 g_clear_error(&error);
1444 if (error_code != ACCOUNT_ERROR_NONE)
1447 GSList *account_list = unmarshal_account_list(account_list_variant);
1448 g_variant_unref(account_list_variant);
1450 if (account_list == NULL)
1451 return ACCOUNT_ERROR_NO_DATA;
1455 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1456 _INFO("iterating received account_list");
1457 account_s *account = NULL;
1458 account = (account_s *)iter->data;
1459 if (callback((account_h)account, user_data) == false) {
1460 _INFO("application callback requested to discontinue.");
1464 _INFO("account_query_account_by_user_name end");
1466 _account_gslist_account_free(account_list);
1467 return ACCOUNT_ERROR_NONE;
1470 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1472 _INFO("account_query_account_by_package_name starting");
1474 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1475 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1477 GError *error = NULL;
1479 AccountManager *acc_mgr = _account_manager_get_instance();
1480 if (acc_mgr == NULL) {
1481 _ERR("g_bus_get_sync failed");
1482 return ACCOUNT_ERROR_PERMISSION_DENIED;
1485 GVariant *account_list_variant = NULL;
1486 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, package_name, (int)getuid(), &account_list_variant, NULL, &error);
1488 int error_code = _account_get_error_code(is_success, error);
1489 g_clear_error(&error);
1490 if (error_code != ACCOUNT_ERROR_NONE)
1493 GSList *account_list = unmarshal_account_list(account_list_variant);
1494 g_variant_unref(account_list_variant);
1496 if (account_list == NULL)
1497 return ACCOUNT_ERROR_NO_DATA;
1501 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1502 _INFO("iterating received account_list");
1503 account_s *account = NULL;
1504 account = (account_s *)iter->data;
1506 if (callback((account_h)account, user_data) == false) {
1507 _INFO("application callback requested to discontinue.");
1511 _account_gslist_account_free(account_list);
1512 _INFO("account_query_account_by_package_name end");
1513 return ACCOUNT_ERROR_NONE;
1516 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char *capability_type, account_capability_state_e capability_value, void *user_data)
1518 _INFO("account_query_account_by_capability starting");
1520 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1522 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1523 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1524 return ACCOUNT_ERROR_INVALID_PARAMETER;
1527 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1529 GError *error = NULL;
1531 AccountManager *acc_mgr = _account_manager_get_instance();
1532 if (acc_mgr == NULL) {
1533 _ERR("g_bus_get_sync failed");
1534 return ACCOUNT_ERROR_PERMISSION_DENIED;
1537 GVariant *account_list_variant = NULL;
1538 bool is_success = account_manager_call_account_query_account_by_capability_sync(acc_mgr, capability_type, capability_value, (int)getuid(), &account_list_variant, NULL, &error);
1540 int error_code = _account_get_error_code(is_success, error);
1541 g_clear_error(&error);
1542 if (error_code != ACCOUNT_ERROR_NONE)
1545 GSList *account_list = unmarshal_account_list(account_list_variant);
1546 g_variant_unref(account_list_variant);
1547 if (account_list == NULL)
1548 return ACCOUNT_ERROR_NO_DATA;
1552 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1553 _INFO("iterating received account_list");
1554 account_s *account = NULL;
1555 account = (account_s *)iter->data;
1557 if (callback((account_h)account, user_data) == false) {
1558 _INFO("application callback requested to discontinue.");
1562 _account_gslist_account_free(account_list);
1563 _INFO("account_query_account_by_capability end");
1564 return ACCOUNT_ERROR_NONE;
1567 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char *capability_type, void *user_data)
1569 _INFO("account_query_account_by_capability_type starting");
1571 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1572 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1574 GError *error = NULL;
1576 AccountManager *acc_mgr = _account_manager_get_instance();
1577 if (acc_mgr == NULL) {
1578 _ERR("g_bus_get_sync failed");
1579 return ACCOUNT_ERROR_PERMISSION_DENIED;
1582 GVariant *account_list_variant = NULL;
1583 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, capability_type, (int)getuid(), &account_list_variant, NULL, &error);
1585 int error_code = _account_get_error_code(is_success, error);
1586 g_clear_error(&error);
1587 if (error_code != ACCOUNT_ERROR_NONE)
1590 GSList *account_list = unmarshal_account_list(account_list_variant);
1591 g_variant_unref(account_list_variant);
1593 if (account_list == NULL)
1594 return ACCOUNT_ERROR_NO_DATA;
1598 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1599 _INFO("iterating received account_list");
1600 account_s *account = NULL;
1601 account = (account_s *)iter->data;
1603 if (callback((account_h)account, user_data) == false) {
1604 _INFO("application callback requested to discontinue.");
1608 _account_gslist_account_free(account_list);
1609 _INFO("account_query_account_by_capability end");
1610 return ACCOUNT_ERROR_NONE;
1613 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1615 _INFO("account_query_capability_by_account_id starting");
1617 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1618 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1620 GError *error = NULL;
1621 AccountManager *acc_mgr = _account_manager_get_instance();
1622 if (acc_mgr == NULL) {
1623 _ERR("g_bus_get_sync failed");
1624 return ACCOUNT_ERROR_PERMISSION_DENIED;
1627 GVariant *capability_list_variant = NULL;
1628 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &capability_list_variant, NULL, &error);
1630 int error_code = _account_get_error_code(is_success, error);
1631 g_clear_error(&error);
1632 if (error_code != ACCOUNT_ERROR_NONE)
1635 GSList *capability_list = unmarshal_capability_list(capability_list_variant);
1636 g_variant_unref(capability_list_variant);
1638 if (capability_list == NULL)
1639 return ACCOUNT_ERROR_NO_DATA;
1643 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter)) {
1644 _INFO("iterating received account_list");
1645 account_capability_s *capability = NULL;
1646 capability = (account_capability_s *)iter->data;
1647 if (callback(capability->type, capability->value, user_data) == false) {
1648 _INFO("application callback requested to discontinue.");
1653 _account_gslist_capability_free(capability_list);
1654 _INFO("account_query_capability_by_account_id end");
1655 return ACCOUNT_ERROR_NONE;
1658 static int _account_get_total_count(int *count, bool include_hidden)
1660 _INFO("account_get_total_count_from_db starting");
1663 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1664 return ACCOUNT_ERROR_INVALID_PARAMETER;
1667 GError *error = NULL;
1669 if (count == NULL) {
1670 _INFO("Invalid input");
1674 AccountManager *acc_mgr = _account_manager_get_instance();
1675 if (acc_mgr == NULL) {
1676 _ERR("g_bus_get_sync failed");
1677 return ACCOUNT_ERROR_PERMISSION_DENIED;
1680 int temp_count = -1;
1681 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, include_hidden, (int)getuid(), &temp_count, NULL, &error);
1682 int error_code = _account_get_error_code(is_success, error);
1683 g_clear_error(&error);
1684 if (error_code != ACCOUNT_ERROR_NONE)
1687 *count = temp_count;
1688 _INFO("account_get_total_count_from_db end");
1689 return ACCOUNT_ERROR_NONE;
1692 ACCOUNT_API int account_get_total_count_from_db(int *count)
1694 _INFO("account_get_total_count_from_db starting");
1696 return _account_get_total_count(count, true);
1699 ACCOUNT_INTERNAL_API int account_get_total_count_from_db_ex(int *count)
1701 _INFO("account_get_total_count_from_db_ex starting");
1703 return _account_get_total_count(count, false);
1706 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1708 _INFO("account_update_sync_status_by_id starting");
1709 int error_code = ACCOUNT_ERROR_NONE;
1711 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1712 if (((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1713 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1714 return ACCOUNT_ERROR_INVALID_PARAMETER;
1717 GError *error = NULL;
1719 AccountManager *acc_mgr = _account_manager_get_instance();
1720 if (acc_mgr == NULL) {
1721 _ERR("g_bus_get_sync failed");
1722 return ACCOUNT_ERROR_PERMISSION_DENIED;
1725 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_id, sync_status, (int)getuid(), NULL, &error);
1727 error_code = _account_get_error_code(is_success, error);
1728 g_clear_error(&error);
1734 ACCOUNT_API int account_type_create(account_type_h *account_type)
1736 if (!account_type) {
1737 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1738 return ACCOUNT_ERROR_INVALID_PARAMETER;
1741 account_type_s *data = (account_type_s *)malloc(sizeof(account_type_s));
1743 ACCOUNT_FATAL("Memory Allocation Failed");
1744 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1747 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1750 data->app_id = NULL;
1751 data->service_provider_id = NULL;
1752 data->icon_path = NULL;
1753 data->small_icon_path = NULL;
1754 data->multiple_account_support = false;
1755 data->label_list = NULL;
1756 data->provider_feature_list = NULL;
1758 *account_type = (account_type_h)data;
1760 return ACCOUNT_ERROR_NONE;
1763 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1765 _INFO("account_type_destroy");
1767 account_type_s *data = (account_type_s *)account_type;
1770 _ERR("Account type handle is null!");
1771 return ACCOUNT_ERROR_INVALID_PARAMETER;
1774 _account_type_free_account_type_with_items(data);
1776 return ACCOUNT_ERROR_NONE;
1779 ACCOUNT_INTERNAL_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1781 if (!account_type) {
1782 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1783 return ACCOUNT_ERROR_INVALID_PARAMETER;
1787 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1788 return ACCOUNT_ERROR_INVALID_PARAMETER;
1791 account_type_s *data = (account_type_s *)account_type;
1793 _ACCOUNT_FREE(data->app_id);
1794 data->app_id = _account_get_text(app_id);
1795 if (data->app_id == NULL) {
1796 ACCOUNT_FATAL("OUT OF MEMORY\n");
1797 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1800 return ACCOUNT_ERROR_NONE;
1803 ACCOUNT_INTERNAL_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1806 return ACCOUNT_ERROR_INVALID_PARAMETER;
1808 if (!service_provider_id)
1809 return ACCOUNT_ERROR_INVALID_PARAMETER;
1811 account_type_s *data = (account_type_s *)account_type;
1813 _ACCOUNT_FREE(data->service_provider_id);
1814 data->service_provider_id = _account_get_text(service_provider_id);
1815 if (data->service_provider_id == NULL) {
1816 ACCOUNT_FATAL("OUT OF MEMORY\n");
1817 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1820 return ACCOUNT_ERROR_NONE;
1823 ACCOUNT_INTERNAL_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1826 return ACCOUNT_ERROR_INVALID_PARAMETER;
1829 return ACCOUNT_ERROR_INVALID_PARAMETER;
1831 account_type_s *data = (account_type_s *)account_type;
1833 _ACCOUNT_FREE(data->icon_path);
1834 data->icon_path = _account_get_text(icon_path);
1835 if (data->icon_path == NULL) {
1836 ACCOUNT_FATAL("OUT OF MEMORY\n");
1837 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1840 return ACCOUNT_ERROR_NONE;
1843 ACCOUNT_INTERNAL_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
1846 return ACCOUNT_ERROR_INVALID_PARAMETER;
1848 if (!small_icon_path)
1849 return ACCOUNT_ERROR_INVALID_PARAMETER;
1851 account_type_s *data = (account_type_s *)account_type;
1853 _ACCOUNT_FREE(data->small_icon_path);
1854 data->small_icon_path = _account_get_text(small_icon_path);
1855 if (data->small_icon_path == NULL) {
1856 ACCOUNT_FATAL("OUT OF MEMORY\n");
1857 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1860 return ACCOUNT_ERROR_NONE;
1863 ACCOUNT_INTERNAL_API int account_type_set_multiple_account_support(account_type_h account_type, bool multiple_account_support)
1865 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1867 account_type_s *data = (account_type_s *)account_type;
1869 data->multiple_account_support = multiple_account_support;
1871 return ACCOUNT_ERROR_NONE;
1874 ACCOUNT_INTERNAL_API int account_type_set_label(account_type_h account_type, const char *label, const char *locale)
1876 if (!account_type) {
1877 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1878 return ACCOUNT_ERROR_INVALID_PARAMETER;
1881 if (!label || !locale)
1882 return ACCOUNT_ERROR_INVALID_PARAMETER;
1884 account_type_s *data = (account_type_s *)account_type;
1885 label_s *label_data = (label_s *)malloc(sizeof(label_s));
1886 if (label_data == NULL) {
1887 ACCOUNT_FATAL("Memory Allocation Failed");
1888 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1891 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
1893 label_data->label = _account_get_text(label);
1894 if (label_data->label == NULL) {
1895 ACCOUNT_FATAL("OUT OF MEMORY\n");
1896 _ACCOUNT_FREE(label_data);
1897 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1900 label_data->locale = _account_get_text(locale);
1901 if (label_data->locale == NULL) {
1902 ACCOUNT_FATAL("OUT OF MEMORY\n");
1903 _ACCOUNT_FREE(label_data->label);
1904 _ACCOUNT_FREE(label_data);
1905 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1908 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
1910 return ACCOUNT_ERROR_NONE;
1913 ACCOUNT_INTERNAL_API int account_type_set_provider_feature(account_type_h account_type, const char *provider_feature)
1915 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
1916 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
1918 account_type_s *data = (account_type_s *)account_type;
1920 GSList *iter = NULL;
1921 bool b_is_new = TRUE;
1923 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
1924 provider_feature_s *feature_data = NULL;
1925 feature_data = (provider_feature_s *)iter->data;
1927 if (!strcmp(feature_data->key, provider_feature)) {
1934 provider_feature_s* feature_data = (provider_feature_s *)malloc(sizeof(provider_feature_s));
1935 if (feature_data == NULL) {
1936 ACCOUNT_FATAL("Memory Allocation Failed");
1937 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1940 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
1942 feature_data->key = _account_get_text(provider_feature);
1943 if (feature_data->key == NULL) {
1944 ACCOUNT_FATAL("OUT OF MEMORY\n");
1945 _ACCOUNT_FREE(feature_data);
1946 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1949 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
1952 return ACCOUNT_ERROR_NONE;
1955 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char *app_id, void *user_data)
1957 _INFO("account_type_query_provider_feature_by_app_id start");
1959 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
1960 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1962 GError *error = NULL;
1963 gint error_code = ACCOUNT_ERROR_NONE;
1965 AccountManager *acc_mgr = _account_manager_get_instance();
1966 if (acc_mgr == NULL) {
1967 _ERR("g_bus_get_sync failed");
1968 return ACCOUNT_ERROR_PERMISSION_DENIED;
1971 GVariant *feature_list_variant = NULL;
1972 bool is_success = account_manager_call_account_type_query_provider_feature_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &feature_list_variant, NULL, &error);
1974 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
1977 error_code = _account_get_error_code(is_success, error);
1978 g_clear_error(&error);
1979 _ERR("Account IPC call returned error[%d]", error_code);
1982 g_clear_error(&error);
1984 GSList *provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
1985 if (provider_feature_list == NULL) {
1986 error_code = ACCOUNT_ERROR_NO_DATA;
1987 _ERR("[%d]", error_code);
1992 for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
1993 provider_feature_s *feature_data = NULL;
1995 feature_data = (provider_feature_s *)iter->data;
1997 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
1998 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
1999 return ACCOUNT_ERROR_NONE;
2003 _account_type_gslist_feature_free(provider_feature_list);
2004 _INFO("account_type_query_provider_feature_by_app_id end");
2008 ACCOUNT_API bool account_type_query_supported_feature(const char *app_id, const char *capability)
2010 _INFO("account_type_query_supported_feature start");
2012 if (app_id == NULL || capability == NULL) {
2013 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2017 int is_supported = 0;
2018 GError *error = NULL;
2019 gint ret = ACCOUNT_ERROR_NONE;
2021 AccountManager *acc_mgr = _account_manager_get_instance();
2022 if (acc_mgr == NULL) {
2023 _ERR("g_bus_get_sync failed");
2024 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2028 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, app_id, capability, (int)getuid(), &is_supported, NULL, &error);
2030 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2033 ret = _account_get_error_code(is_success, error);
2034 g_clear_error(&error);
2035 _ERR("Account IPC call returned error[%d]", ret);
2036 set_last_result(ret);
2039 g_clear_error(&error);
2041 set_last_result(ACCOUNT_ERROR_NONE);
2042 _INFO("account_type_query_supported_feature end");
2043 return is_supported;
2046 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2049 return ACCOUNT_ERROR_INVALID_PARAMETER;
2052 return ACCOUNT_ERROR_INVALID_PARAMETER;
2054 account_type_s *data = (account_type_s *)account_type;
2057 *app_id = _account_get_text(data->app_id);
2058 if (*app_id == NULL) {
2059 ACCOUNT_FATAL("OUT OF MEMORY\n");
2060 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2063 return ACCOUNT_ERROR_NONE;
2066 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2069 return ACCOUNT_ERROR_INVALID_PARAMETER;
2071 if (!service_provider_id)
2072 return ACCOUNT_ERROR_INVALID_PARAMETER;
2074 account_type_s *data = (account_type_s *)account_type;
2076 (*service_provider_id) = NULL;
2077 *service_provider_id = _account_get_text(data->service_provider_id);
2078 if (*service_provider_id == NULL) {
2079 ACCOUNT_FATAL("OUT OF MEMORY\n");
2080 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2083 return ACCOUNT_ERROR_NONE;
2086 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2089 return ACCOUNT_ERROR_INVALID_PARAMETER;
2092 return ACCOUNT_ERROR_INVALID_PARAMETER;
2094 account_type_s *data = (account_type_s *)account_type;
2096 (*icon_path) = NULL;
2097 *icon_path = _account_get_text(data->icon_path);
2098 if (*icon_path == NULL) {
2099 ACCOUNT_FATAL("OUT OF MEMORY\n");
2100 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2103 return ACCOUNT_ERROR_NONE;
2106 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2109 return ACCOUNT_ERROR_INVALID_PARAMETER;
2111 if (!small_icon_path)
2112 return ACCOUNT_ERROR_INVALID_PARAMETER;
2114 account_type_s *data = (account_type_s *)account_type;
2116 (*small_icon_path) = NULL;
2117 *small_icon_path = _account_get_text(data->small_icon_path);
2118 if (*small_icon_path == NULL) {
2119 ACCOUNT_FATAL("OUT OF MEMORY\n");
2120 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2124 return ACCOUNT_ERROR_NONE;
2127 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2130 return ACCOUNT_ERROR_INVALID_PARAMETER;
2132 if (!multiple_account_support)
2133 return ACCOUNT_ERROR_INVALID_PARAMETER;
2135 account_type_s *data = (account_type_s *)account_type;
2137 *multiple_account_support = data->multiple_account_support;
2139 return ACCOUNT_ERROR_NONE;
2142 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void *user_data)
2144 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2145 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2148 account_type_s *data = (account_type_s *)account_type;
2150 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2151 provider_feature_s *feature_data = NULL;
2153 feature_data = (provider_feature_s *)iter->data;
2155 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
2156 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2157 return ACCOUNT_ERROR_NONE;
2161 return ACCOUNT_ERROR_NONE;
2164 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char *locale, char **label)
2166 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2167 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2170 account_type_s *data = (account_type_s *)account_type;
2172 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2173 label_s *label_data = NULL;
2175 label_data = (label_s *)iter->data;
2179 if (!strcmp(locale, label_data->locale)) {
2180 *label = _account_get_text(label_data->label);
2181 if (*label == NULL) {
2182 ACCOUNT_FATAL("OUT OF MEMORY\n");
2183 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2186 return ACCOUNT_ERROR_NONE;
2188 gchar **tokens = g_strsplit(locale, "-", 2);
2190 if (tokens != NULL) {
2191 if ((char *)(tokens[1]) != NULL) {
2192 char *upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2193 if (upper_token == NULL) {
2194 ACCOUNT_FATAL("Memory Allocation Failed");
2196 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2199 if (upper_token != NULL) {
2200 char *converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2201 if (converted_locale == NULL) {
2202 ACCOUNT_FATAL("Memory Allocation Failed");
2203 _ACCOUNT_FREE(upper_token);
2205 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2208 if (!strcmp(converted_locale, label_data->locale)) {
2209 _ACCOUNT_FREE(converted_locale);
2210 _ACCOUNT_FREE(upper_token);
2212 *label = _account_get_text(label_data->label);
2213 if (*label == NULL) {
2214 ACCOUNT_FATAL("OUT OF MEMORY\n");
2215 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2218 return ACCOUNT_ERROR_NONE;
2220 _ACCOUNT_FREE(converted_locale);
2222 _ACCOUNT_FREE(upper_token);
2228 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2231 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2233 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2234 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2237 account_type_s *data = (account_type_s *)account_type;
2239 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2240 label_s *label_data = NULL;
2242 label_data = (label_s *)iter->data;
2244 if (callback(label_data->app_id, label_data->label, label_data->locale, user_data) != TRUE) {
2245 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2246 return ACCOUNT_ERROR_NONE;
2250 return ACCOUNT_ERROR_NONE;
2253 ACCOUNT_INTERNAL_API int account_type_insert_to_db(account_type_h account_type, int *account_type_id)
2255 _INFO("account_type_insert_to_db starting");
2257 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2258 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2260 GError *error = NULL;
2262 AccountManager *acc_mgr = _account_manager_get_instance();
2263 if (acc_mgr == NULL) {
2264 _ERR("g_bus_get_sync failed");
2265 return ACCOUNT_ERROR_PERMISSION_DENIED;
2269 GVariant *account_type_serialized = marshal_account_type((account_type_s *)account_type);
2270 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_type_serialized, (int)getuid(), &db_id, NULL, &error);
2272 int ret = _account_get_error_code(is_success, error);
2273 g_clear_error(&error);
2275 if (ret != ACCOUNT_ERROR_NONE)
2278 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2280 *account_type_id = db_id;
2282 account_type_s *account_type_data = (account_type_s *)account_type;
2283 account_type_data->id = db_id;
2285 return ACCOUNT_ERROR_NONE;
2288 ACCOUNT_INTERNAL_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char *app_id)
2290 _INFO("account_type_update_to_db_by_app_id starting");
2291 int error_code = ACCOUNT_ERROR_NONE;
2293 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2294 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2296 GError *error = NULL;
2298 AccountManager *acc_mgr = _account_manager_get_instance();
2299 if (acc_mgr == NULL) {
2300 _ERR("g_bus_get_sync failed");
2301 return ACCOUNT_ERROR_PERMISSION_DENIED;
2304 GVariant *account_type_variant = marshal_account_type((account_type_s *)account_type);
2305 if (account_type_variant == NULL) {
2306 _ERR("Failed to serialize");
2307 return ACCOUNT_ERROR_INVALID_PARAMETER;
2310 bool is_success = account_manager_call_account_type_update_to_db_by_app_id_sync(acc_mgr, account_type_variant, app_id, (int)getuid(), NULL, &error);
2312 error_code = _account_get_error_code(is_success, error);
2313 g_clear_error(&error);
2318 ACCOUNT_INTERNAL_API int account_type_delete_by_app_id(const char *app_id)
2320 _INFO("account_type_delete_by_app_id starting");
2321 int error_code = ACCOUNT_ERROR_NONE;
2323 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2325 GError *error = NULL;
2327 AccountManager *acc_mgr = _account_manager_get_instance();
2328 if (acc_mgr == NULL) {
2329 _ERR("g_bus_get_sync failed");
2330 return ACCOUNT_ERROR_PERMISSION_DENIED;
2333 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2335 error_code = _account_get_error_code(is_success, error);
2336 g_clear_error(&error);
2341 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char *app_id, void *user_data)
2343 _INFO("account_type_query_label_by_app_id starting");
2345 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2346 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2348 GError *error = NULL;
2350 AccountManager *acc_mgr = _account_manager_get_instance();
2351 if (acc_mgr == NULL) {
2352 _ERR("g_bus_get_sync failed");
2353 return ACCOUNT_ERROR_PERMISSION_DENIED;
2356 GVariant *label_list_variant = NULL;
2357 bool is_success = account_manager_call_account_type_query_label_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &label_list_variant, NULL, &error);
2359 int ret = _account_get_error_code(is_success, error);
2360 g_clear_error(&error);
2362 if (ret != ACCOUNT_ERROR_NONE)
2365 GSList *label_list = variant_to_label_list(label_list_variant);
2366 if (label_list == NULL)
2367 return ACCOUNT_ERROR_NO_DATA;
2371 for (iter = label_list; iter != NULL; iter = g_slist_next(iter)) {
2372 _INFO("iterating received account_list");
2373 label_s *label_record = NULL;
2374 label_record = (label_s *)iter->data;
2375 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false) {
2376 _INFO("application callback requested to discontinue.");
2381 _account_type_gslist_label_free(label_list);
2382 _INFO("account_type_query_label_by_app_id end");
2383 return ACCOUNT_ERROR_NONE;
2386 ACCOUNT_API int account_type_query_by_app_id(const char *app_id, account_type_h *account_type)
2388 _INFO("account_type_query_by_app_id starting");
2390 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2391 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2392 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2394 GError *error = NULL;
2396 AccountManager *acc_mgr = _account_manager_get_instance();
2397 if (acc_mgr == NULL) {
2398 _ERR("g_bus_get_sync failed");
2399 return ACCOUNT_ERROR_PERMISSION_DENIED;
2402 GVariant *account_type_variant = NULL;
2403 account_type_s *in_data = (account_type_s *)*account_type;
2405 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &account_type_variant, NULL, &error);
2407 int ret = _account_get_error_code(is_success, error);
2408 g_clear_error(&error);
2410 if (ret != ACCOUNT_ERROR_NONE)
2413 account_type_s *received_account_type = umarshal_account_type(account_type_variant);
2414 g_variant_unref(account_type_variant);
2415 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2417 in_data->id = received_account_type->id;
2418 in_data->app_id = received_account_type->app_id;
2419 in_data->service_provider_id = received_account_type->service_provider_id;
2420 in_data->icon_path = received_account_type->icon_path;
2421 in_data->small_icon_path = received_account_type->small_icon_path;
2422 in_data->multiple_account_support = received_account_type->multiple_account_support;
2423 in_data->label_list = received_account_type->label_list;
2424 in_data->provider_feature_list = received_account_type->provider_feature_list;
2426 _ACCOUNT_FREE(received_account_type);
2427 _INFO("account_type_query_by_app_id end");
2428 return ACCOUNT_ERROR_NONE;
2431 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2433 _INFO("account_type_foreach_account_type_from_db starting");
2435 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2437 GError *error = NULL;
2439 AccountManager *acc_mgr = _account_manager_get_instance();
2440 if (acc_mgr == NULL) {
2441 _ERR("g_bus_get_sync failed");
2442 return ACCOUNT_ERROR_PERMISSION_DENIED;
2445 GVariant *account_type_list_variant = NULL;
2446 _INFO("before account_type_query_all_sync()");
2447 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, (int)getuid(), &account_type_list_variant, NULL, &error);
2449 _INFO("after account_type_query_all_sync()");
2450 int ret = _account_get_error_code(is_success, error);
2451 g_clear_error(&error);
2453 if (ret != ACCOUNT_ERROR_NONE)
2456 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2457 g_variant_unref(account_type_list_variant);
2459 if (account_type_list == NULL)
2460 return ACCOUNT_ERROR_NO_DATA;
2464 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2465 _INFO("iterating received account_list");
2466 account_type_s *account_type = NULL;
2467 account_type = (account_type_s *)iter->data;
2469 if (callback((account_type_h)account_type, user_data) == false) {
2470 _INFO("application callback requested to discontinue.");
2475 _account_type_gslist_account_type_free(account_type_list);
2476 _INFO("account_type_foreach_account_type_from_db end");
2477 return ACCOUNT_ERROR_NONE;
2480 ACCOUNT_API int account_type_query_label_by_locale(const char *app_id, const char *locale, char **label)
2482 _INFO("account_type_query_label_by_locale starting");
2484 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2485 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2486 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2488 GError *error = NULL;
2490 AccountManager *acc_mgr = _account_manager_get_instance();
2491 if (acc_mgr == NULL) {
2492 _ERR("g_bus_get_sync failed");
2493 return ACCOUNT_ERROR_PERMISSION_DENIED;
2496 char *label_temp = NULL;
2497 _INFO("before account_type_query_label_by_locale_sync()");
2498 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, app_id, locale, (int)getuid(), &label_temp, NULL, &error);
2500 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2501 int ret = _account_get_error_code(is_success, error);
2502 g_clear_error(&error);
2504 if (ret != ACCOUNT_ERROR_NONE)
2507 if (label_temp == NULL)
2508 return ACCOUNT_ERROR_NO_DATA;
2511 *label = _account_get_text(label_temp);
2512 if (*label == NULL) {
2513 ACCOUNT_FATAL("OUT OF MEMORY\n");
2514 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2517 _INFO("account_type_query_label_by_locale end");
2518 return ACCOUNT_ERROR_NONE;
2522 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char *key, void *user_data)
2524 _INFO("account_type_query_by_provider_feature starting");
2526 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2527 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2529 GError *error = NULL;
2531 AccountManager *acc_mgr = _account_manager_get_instance();
2532 if (acc_mgr == NULL) {
2533 _ERR("g_bus_get_sync failed");
2534 return ACCOUNT_ERROR_PERMISSION_DENIED;
2537 GVariant *account_type_list_variant = NULL;
2538 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, key, (int)getuid(), &account_type_list_variant, NULL, &error);
2540 int ret = _account_get_error_code(is_success, error);
2541 g_clear_error(&error);
2543 if (ret != ACCOUNT_ERROR_NONE)
2546 _INFO("before unmarshal_account_type_list");
2547 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2548 g_variant_unref(account_type_list_variant);
2550 if (account_type_list == NULL)
2551 return ACCOUNT_ERROR_NO_DATA;
2555 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2556 _INFO("iterating received account_type_list");
2557 account_type_s *account_type = NULL;
2558 account_type = (account_type_s *)iter->data;
2560 if (callback((account_type_h)account_type, user_data) == false) {
2561 _INFO("Application callback requested not to continue");
2567 _account_type_gslist_account_type_free(account_type_list);
2568 _INFO("account_type_query_by_provider_feature end");
2569 return ACCOUNT_ERROR_NONE;
2572 ACCOUNT_API int account_type_query_app_id_exist(const char *app_id)
2574 _INFO("account_type_query_app_id_exist starting");
2575 int error_code = ACCOUNT_ERROR_NONE;
2577 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2579 GError *error = NULL;
2581 AccountManager *acc_mgr = _account_manager_get_instance();
2582 if (acc_mgr == NULL) {
2583 _ERR("g_bus_get_sync failed");
2584 return ACCOUNT_ERROR_PERMISSION_DENIED;
2587 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2589 error_code = _account_get_error_code(is_success, error);
2590 g_clear_error(&error);
2596 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2598 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2599 char *msg = NULL, *vconf_key = NULL;
2600 const char *key_name = NULL;
2601 char event_msg[256] = {0, };
2602 int account_id = -1;
2605 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2610 ACCOUNT_ERROR("user data required\n");
2614 key_name = vconf_keynode_get_name(key);
2616 if (key_name == NULL) {
2617 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2621 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2622 vconf_key = vconf_keynode_get_str(key);
2624 if (vconf_key == NULL) {
2625 ACCOUNT_ERROR("vconf key is NULL.\n");
2629 msg = strdup(vconf_key);
2631 ACCOUNT_FATAL("Memory Allocation Failed");
2635 char *event_type = NULL;
2639 event_type = strtok_r(msg, ":", &ptr);
2640 id = strtok_r(NULL, ":", &ptr);
2642 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2644 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2646 account_id = atoi(id);
2648 if (tmp->account_subscription_callback)
2649 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2655 ACCOUNT_API int account_subscribe_create(account_subscribe_h *account_subscribe)
2657 if (!account_subscribe) {
2658 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2659 return ACCOUNT_ERROR_INVALID_PARAMETER;
2662 account_subscribe_s *data = (account_subscribe_s *)calloc(1, sizeof(account_subscribe_s));
2664 ACCOUNT_FATAL("OUT OF MEMORY\n");
2665 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2668 *account_subscribe = (account_subscribe_h)data;
2670 return ACCOUNT_ERROR_NONE;
2673 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
2675 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2677 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2679 tmp->account_subscription_callback = callback;
2680 tmp->user_data = user_data;
2683 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2684 (vconf_callback_fn)_account_subscribe_vconf_callback,
2687 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2689 if (ret != VCONF_OK) {
2690 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2691 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2694 return ACCOUNT_ERROR_NONE;
2697 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2699 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2701 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2705 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2706 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
2707 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2708 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2711 return ACCOUNT_ERROR_NONE;
2714 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2716 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2717 char *msg = NULL, *vconf_key = NULL;
2718 char event_msg[256] = {0, };
2719 int account_id = -1;
2720 const char *key_name = NULL;
2723 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2728 ACCOUNT_ERROR("user data required\n");
2732 key_name = vconf_keynode_get_name(key);
2734 if (key_name == NULL) {
2735 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2739 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2740 vconf_key = vconf_keynode_get_str(key);
2742 if (vconf_key == NULL) {
2743 ACCOUNT_ERROR("vconf key is NULL.\n");
2746 msg = strdup(vconf_key);
2748 ACCOUNT_FATAL("Memory Allocation Failed");
2752 char *event_type = NULL;
2756 event_type = strtok_r(msg, ":", &ptr);
2757 id = strtok_r(NULL, ":", &ptr);
2759 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2761 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2763 account_id = atoi(id);
2765 if (tmp->account_subscription_callback)
2766 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2773 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2775 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2777 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2781 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2782 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
2783 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2784 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2787 return ACCOUNT_ERROR_NONE;
2790 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
2792 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2794 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2796 tmp->account_subscription_callback = callback;
2797 tmp->user_data = user_data;
2800 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2801 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2804 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2806 if (ret != VCONF_OK) {
2807 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2808 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2811 return ACCOUNT_ERROR_NONE;