3 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include <glib/gprintf.h>
24 #include <gio/gunixfdlist.h>
30 #include <account-private.h>
31 #include <account_free.h>
32 #include <account_ipc_marshal.h>
33 #include <account-mgr-stub.h>
35 #ifdef TIZEN_PROFILE_MOBILE
36 #include "mobile/account.h"
38 #include "wearable/account.h"
41 #include "account-error.h"
42 #include "account-types.h"
43 #include "account_internal.h"
44 #include "account_private_client.h"
46 #define ACCOUNT_DB_OPEN_READONLY 0
47 #define ACCOUNT_DB_OPEN_READWRITE 1
51 static AccountManager *_acc_mgr = NULL;
53 static char *_account_get_text(const char *text_data)
55 char *text_value = NULL;
57 if (text_data != NULL)
58 text_value = strdup(text_data);
64 _account_manager_get_instance()
66 _INFO("_account_manager_get_instance");
67 if (_acc_mgr != NULL) {
68 _INFO("instance already created.");
72 #if !GLIB_CHECK_VERSION(2, 35, 0)
76 GDBusConnection *connection = NULL;
79 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
81 _INFO("after g_bus_get_sync");
85 _ERR("Unable to connect to gdbus: %s", error->message);
86 g_clear_error(&error);
91 g_clear_error(&error);
93 /* Create the object */
95 account_manager_proxy_new_sync(connection,
96 G_DBUS_PROXY_FLAGS_NONE,
97 "org.tizen.account.manager",
98 "/org/tizen/account/manager",
104 _ERR("Unable account_manager_proxy_new_sync: %s", error->message);
105 g_clear_error(&error);
108 g_object_unref(connection);
112 g_clear_error(&error);
113 _INFO("_account_manager_get_instance end");
117 GDBusErrorEntry _account_svc_errors[] = {
118 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
119 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
120 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
121 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
122 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
123 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
124 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
125 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
126 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
127 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
128 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
129 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
130 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
131 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
132 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
133 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
134 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
135 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
138 static int _account_get_error_code(bool is_success, GError *error)
141 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
143 if (g_dbus_error_is_remote_error(error)) {
144 gchar *remote_error = g_dbus_error_get_remote_error(error);
146 _INFO("Remote error[%s]", remote_error);
148 /* FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
149 However error->message matches, so doing reverse lookup */
150 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
152 for (i = 0; i < error_enum_count; i++) {
153 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0) {
154 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
155 g_free(remote_error);
156 return _account_svc_errors[i].error_code;
159 g_free(remote_error);
162 /* All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED */
163 return ACCOUNT_ERROR_PERMISSION_DENIED;
165 return ACCOUNT_ERROR_NONE;
168 #ifdef TIZEN_PROFILE_MOBILE
169 ACCOUNT_API int account_connect(void)
171 return ACCOUNT_ERROR_NONE;
174 ACCOUNT_API int account_connect_readonly(void)
176 return ACCOUNT_ERROR_NONE;
179 ACCOUNT_API int account_disconnect(void)
181 return ACCOUNT_ERROR_NONE;
186 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
188 _INFO("1. account_insert_to_db start");
190 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
191 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
193 account_s *account_data = (account_s *)account;
194 int error_code = ACCOUNT_ERROR_NONE;
195 GError *error = NULL;
197 _INFO("2. Before _account_manager_get_instance()");
198 AccountManager *acc_mgr = _account_manager_get_instance();
199 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
202 GVariant *account_serialized = marshal_account(account_data);
204 _INFO("3. Before account_manager_call_account_add_sync");
205 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_serialized, (int)getuid(), &db_id, NULL, &error);
206 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
207 g_clear_error(&error);
209 *account_db_id = db_id;
210 account_data->id = db_id;
212 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
214 return ACCOUNT_ERROR_NONE;
217 g_clear_error(&error);
218 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
223 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
225 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
226 int error_code = ACCOUNT_ERROR_NONE;
228 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
230 GError *error = NULL;
232 AccountManager *acc_mgr = _account_manager_get_instance();
233 if (acc_mgr == NULL) {
234 _ERR("g_bus_get_sync failed");
235 return ACCOUNT_ERROR_PERMISSION_DENIED;
238 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
239 GVariant *account_serialized_old = NULL;
240 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);
243 error_code = _account_get_error_code(is_success, error);
244 g_clear_error(&error);
245 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
248 g_clear_error(&error);
250 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
251 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_id, (int)getuid(), NULL, &error);
254 error_code = _account_get_error_code(is_success, error);
255 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error_code);
256 g_clear_error(&error);
259 g_clear_error(&error);
261 _INFO("4. Before account_delete_from_db_by_id end");
262 return ACCOUNT_ERROR_NONE;
265 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
267 int error_code = ACCOUNT_ERROR_NONE;
268 _INFO("account_delete_from_db_by_user_name start");
270 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
271 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
274 GError *error = NULL;
276 AccountManager *acc_mgr = _account_manager_get_instance();
277 if (acc_mgr == NULL) {
278 _ERR("g_bus_get_sync failed");
279 return ACCOUNT_ERROR_PERMISSION_DENIED;
282 GVariant *account_list_variant = NULL;
283 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
285 error_code = _account_get_error_code(is_success, error);
286 g_clear_error(&error);
287 if (error_code != ACCOUNT_ERROR_NONE) {
288 _ERR("account_query_account_by_user_name error=[%d]", error_code);
292 GSList *account_list = unmarshal_account_list(account_list_variant);
293 g_variant_unref(account_list_variant);
295 if (account_list == NULL)
296 return ACCOUNT_ERROR_NO_DATA;
298 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, user_name, package_name, (int)getuid(), NULL, &error);
301 error_code = _account_get_error_code(is_success, error);
302 g_clear_error(&error);
303 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
304 _account_gslist_account_free(account_list);
307 g_clear_error(&error);
309 _account_gslist_account_free(account_list);
310 return ACCOUNT_ERROR_NONE;
313 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
315 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
316 int error_code = ACCOUNT_ERROR_NONE;
318 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
320 GError *error = NULL;
322 AccountManager *acc_mgr = _account_manager_get_instance();
323 if (acc_mgr == NULL) {
324 _ERR("g_bus_get_sync failed");
325 return ACCOUNT_ERROR_PERMISSION_DENIED;
328 //First get account list of user_name, used for gSSO DB deletion
329 GVariant* account_list_variant = NULL;
330 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);
332 error_code = _account_get_error_code(is_success, error);
333 if (error_code != ACCOUNT_ERROR_NONE)
338 _INFO("before unmarshal_account_list");
339 GSList* account_list = unmarshal_account_list(account_list_variant);
340 _INFO("after unmarshal_account_list");
341 if (account_list == NULL)
343 return ACCOUNT_ERROR_NO_DATA;
346 bool is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, package_name, permission, (int)getuid(), NULL, &error);
349 error_code = _account_get_error_code(is_success, error);
350 g_clear_error(&error);
351 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error_code);
354 g_clear_error(&error);
356 return ACCOUNT_ERROR_NONE;
359 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
361 _INFO("account_delete_from_db_by_package_name starting with permission");
362 return _account_delete_from_db_by_package_name(package_name, true);
365 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
367 _INFO("1. account_update_to_db_by_id start");
368 int error_code = ACCOUNT_ERROR_NONE;
370 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
371 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
373 GError *error = NULL;
375 AccountManager *acc_mgr = _account_manager_get_instance();
376 if (acc_mgr == NULL) {
377 _ERR("g_bus_get_sync failed");
378 return ACCOUNT_ERROR_PERMISSION_DENIED;
381 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
382 GVariant *account_serialized_old = NULL;
383 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &account_serialized_old, NULL, &error);
386 error_code = _account_get_error_code(is_success, error);
387 g_clear_error(&error);
388 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
391 g_clear_error(&error);
393 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
394 GVariant *account_serialized = marshal_account((account_s *)account);
395 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
398 error_code = _account_get_error_code(is_success, error);
399 g_clear_error(&error);
400 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error_code);
403 g_clear_error(&error);
405 _INFO("4. account_update_to_db_by_id end");
406 return ACCOUNT_ERROR_NONE;
409 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
412 ret = account_update_to_db_by_id(account, account_id);
417 ACCOUNT_INTERNAL_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
419 _INFO("account_update_to_db_by_id_without_permission start");
420 int error_code = ACCOUNT_ERROR_NONE;
422 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
423 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
425 GError *error = NULL;
427 AccountManager *acc_mgr = _account_manager_get_instance();
428 if (acc_mgr == NULL) {
429 _ERR("g_bus_get_sync failed");
430 return ACCOUNT_ERROR_PERMISSION_DENIED;
433 GVariant *account_serialized_old = NULL;
434 _INFO("before query() account_id[%d]", account_id);
435 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &account_serialized_old, NULL, &error);
438 error_code = _account_get_error_code(is_success, error);
439 g_clear_error(&error);
440 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
443 g_clear_error(&error);
445 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s *)account)->user_name);
446 GVariant *account_serialized = marshal_account((account_s *)account);
447 _INFO("after marshal() : account_id[%d]", account_id);
448 if (account_serialized == NULL) {
449 _ERR("Invalid input");
450 return ACCOUNT_ERROR_INVALID_PARAMETER;
453 _INFO("before call update() : account_id[%d]", account_id);
454 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_serialized, account_id, (int)getuid(), NULL, &error);
456 _INFO("after call update() : is_success=%d", is_success);
458 error_code = _account_get_error_code(is_success, error);
459 g_clear_error(&error);
460 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error_code);
463 g_clear_error(&error);
465 return ACCOUNT_ERROR_NONE;
468 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
470 _INFO("account_update_to_db_by_user_name starting");
471 int error_code = ACCOUNT_ERROR_NONE;
473 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
474 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
475 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
477 GError *error = NULL;
479 AccountManager *acc_mgr = _account_manager_get_instance();
480 if (acc_mgr == NULL) {
481 _ERR("g_bus_get_sync failed");
482 return ACCOUNT_ERROR_PERMISSION_DENIED;
485 GVariant *account_serialized_old = NULL;
486 account_s *account_data = (account_s *)account;
487 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);
490 error_code = _account_get_error_code(is_success, error);
491 g_clear_error(&error);
492 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error_code);
495 g_clear_error(&error);
497 GVariant *account_serialized = marshal_account(account_data);
498 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);
501 error_code = _account_get_error_code(is_success, error);
502 g_clear_error(&error);
503 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error_code);
506 g_clear_error(&error);
508 return ACCOUNT_ERROR_NONE;
511 ACCOUNT_API int account_create(account_h *account)
513 _INFO("account_create start");
515 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
516 return ACCOUNT_ERROR_INVALID_PARAMETER;
519 account_s *data = (account_s *)malloc(sizeof(account_s));
521 ACCOUNT_FATAL("Memory Allocation Failed");
522 return ACCOUNT_ERROR_OUT_OF_MEMORY;
525 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
527 /* Setting account as visible by default */
528 data->secret = ACCOUNT_SECRECY_VISIBLE;
530 /* Setting account as not supporting sync by default */
531 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
533 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
535 data->capablity_list = NULL;
536 data->custom_list = NULL;
538 *account = (account_h)data;
540 _INFO("account_create end");
541 return ACCOUNT_ERROR_NONE;
544 ACCOUNT_API int account_destroy(account_h account)
546 _INFO("account_destroy start");
547 account_s *data = (account_s *)account;
549 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
551 _account_free_account_with_items(data);
553 _INFO("account_destroy end");
554 return ACCOUNT_ERROR_NONE;
557 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
560 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
561 return ACCOUNT_ERROR_INVALID_PARAMETER;
565 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
566 return ACCOUNT_ERROR_INVALID_PARAMETER;
569 account_s *data = (account_s *)account;
571 _ACCOUNT_FREE(data->user_name);
572 data->user_name = _account_get_text(user_name);
573 if (data->user_name == NULL) {
574 ACCOUNT_FATAL("OUT OF MEMORY\n");
575 return ACCOUNT_ERROR_OUT_OF_MEMORY;
578 return ACCOUNT_ERROR_NONE;
581 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
584 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
585 return ACCOUNT_ERROR_INVALID_PARAMETER;
589 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
590 return ACCOUNT_ERROR_INVALID_PARAMETER;
593 account_s *data = (account_s *)account;
595 _ACCOUNT_FREE(data->display_name);
596 data->display_name = _account_get_text(display_name);
597 if (data->display_name == NULL) {
598 ACCOUNT_FATAL("OUT OF MEMORY\n");
599 return ACCOUNT_ERROR_OUT_OF_MEMORY;
602 return ACCOUNT_ERROR_NONE;
605 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
608 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
609 return ACCOUNT_ERROR_INVALID_PARAMETER;
612 if (!email_address) {
613 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
614 return ACCOUNT_ERROR_INVALID_PARAMETER;
617 account_s *data = (account_s *)account;
619 _ACCOUNT_FREE(data->email_address);
620 data->email_address = _account_get_text(email_address);
621 if (data->email_address == NULL) {
622 ACCOUNT_FATAL("OUT OF MEMORY\n");
623 return ACCOUNT_ERROR_OUT_OF_MEMORY;
626 return ACCOUNT_ERROR_NONE;
629 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
632 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
633 return ACCOUNT_ERROR_INVALID_PARAMETER;
637 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
638 return ACCOUNT_ERROR_INVALID_PARAMETER;
641 account_s *data = (account_s *)account;
643 _ACCOUNT_FREE(data->icon_path);
644 data->icon_path = _account_get_text(icon_path);
645 if (data->icon_path == NULL) {
646 ACCOUNT_FATAL("OUT OF MEMORY\n");
647 return ACCOUNT_ERROR_OUT_OF_MEMORY;
650 return ACCOUNT_ERROR_NONE;
653 ACCOUNT_API int account_set_source(account_h account, const char *source)
656 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
657 return ACCOUNT_ERROR_INVALID_PARAMETER;
661 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
662 return ACCOUNT_ERROR_INVALID_PARAMETER;
664 account_s *data = (account_s *)account;
666 _ACCOUNT_FREE(data->source);
667 data->source = _account_get_text(source);
668 if (data->source == NULL) {
669 ACCOUNT_FATAL("OUT OF MEMORY\n");
670 return ACCOUNT_ERROR_OUT_OF_MEMORY;
673 return ACCOUNT_ERROR_NONE;
676 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
679 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
680 return ACCOUNT_ERROR_INVALID_PARAMETER;
684 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
685 return ACCOUNT_ERROR_INVALID_PARAMETER;
688 account_s *data = (account_s *)account;
690 _ACCOUNT_FREE(data->package_name);
691 data->package_name = _account_get_text(package_name);
692 if (data->package_name == NULL) {
693 ACCOUNT_FATAL("OUT OF MEMORY\n");
694 return ACCOUNT_ERROR_OUT_OF_MEMORY;
697 return ACCOUNT_ERROR_NONE;
700 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
703 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
704 return ACCOUNT_ERROR_INVALID_PARAMETER;
708 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
709 return ACCOUNT_ERROR_INVALID_PARAMETER;
711 account_s *data = (account_s *)account;
713 _ACCOUNT_FREE(data->domain_name);
714 data->domain_name = _account_get_text(domain_name);
715 if (data->domain_name == NULL) {
716 ACCOUNT_FATAL("OUT OF MEMORY\n");
717 return ACCOUNT_ERROR_OUT_OF_MEMORY;
720 return ACCOUNT_ERROR_NONE;
723 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
726 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
727 return ACCOUNT_ERROR_INVALID_PARAMETER;
731 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
732 return ACCOUNT_ERROR_INVALID_PARAMETER;
735 account_s *data = (account_s *)account;
737 _ACCOUNT_FREE(data->access_token);
738 data->access_token = _account_get_text(access_token);
739 if (data->access_token == NULL) {
740 ACCOUNT_FATAL("OUT OF MEMORY\n");
741 return ACCOUNT_ERROR_OUT_OF_MEMORY;
744 return ACCOUNT_ERROR_NONE;
747 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
750 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
751 return ACCOUNT_ERROR_INVALID_PARAMETER;
755 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
756 return ACCOUNT_ERROR_INVALID_PARAMETER;
758 if (idx >= USER_TXT_CNT || idx < 0) {
759 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
760 return ACCOUNT_ERROR_INVALID_PARAMETER;
763 account_s *data = (account_s *)account;
765 _ACCOUNT_FREE(data->user_data_txt[idx]);
766 data->user_data_txt[idx] = _account_get_text(user_txt);
767 if (data->user_data_txt[idx] == NULL) {
768 ACCOUNT_FATAL("OUT OF MEMORY\n");
769 return ACCOUNT_ERROR_OUT_OF_MEMORY;
772 return ACCOUNT_ERROR_NONE;
775 ACCOUNT_API int account_set_custom(account_h account, const char *key, const char *value)
778 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
779 return ACCOUNT_ERROR_INVALID_PARAMETER;
783 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
784 return ACCOUNT_ERROR_INVALID_PARAMETER;
788 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
789 return ACCOUNT_ERROR_INVALID_PARAMETER;
792 account_s *data = (account_s *)account;
795 bool b_is_new = TRUE;
797 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
799 account_custom_s *custom_data = NULL;
800 custom_data = (account_custom_s *)iter->data;
801 ACCOUNT_SLOGD("account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
803 if (!strcmp(custom_data->key, key)) {
804 char *new_value = NULL;
805 new_value = _account_get_text(value);
806 if (new_value == NULL) {
807 ACCOUNT_FATAL("OUT OF MEMORY\n");
808 return ACCOUNT_ERROR_OUT_OF_MEMORY;
811 _ACCOUNT_FREE(custom_data->value);
812 custom_data->value = new_value;
819 int error_code = ACCOUNT_ERROR_NONE;
821 account_custom_s* custom_data = (account_custom_s *)malloc(sizeof(account_custom_s));
822 if (custom_data == NULL) {
823 ACCOUNT_FATAL("Memory Allocation Failed");
824 return ACCOUNT_ERROR_OUT_OF_MEMORY;
827 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
828 custom_data->account_id = data->id;
830 /* custom's app_id field will be automatically filled by account-svc daemon. */
831 /* custom_data->app_id = _account_get_text(data->package_name);
832 if (data->package_name != NULL && custom_data->app_id == NULL) {
833 ACCOUNT_FATAL("OUT OF MEMORY\n");
834 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
837 custom_data->key = _account_get_text(key);
838 if (custom_data->key == NULL) {
839 ACCOUNT_FATAL("OUT OF MEMORY\n");
840 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
843 custom_data->value = _account_get_text(value);
844 if (custom_data->value == NULL) {
845 ACCOUNT_FATAL("OUT OF MEMORY\n");
846 error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
849 if (error_code != ACCOUNT_ERROR_NONE) {
850 _ACCOUNT_FREE(custom_data->app_id);
851 _ACCOUNT_FREE(custom_data->key);
852 _ACCOUNT_FREE(custom_data->value);
853 _ACCOUNT_FREE(custom_data);
857 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
860 return ACCOUNT_ERROR_NONE;
863 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
865 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
867 if (((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN))
868 return ACCOUNT_ERROR_INVALID_PARAMETER;
870 account_s *data = (account_s *)account;
872 data->auth_type = (int)auth_type;
874 return ACCOUNT_ERROR_NONE;
877 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
879 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
881 if (((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE))
882 return ACCOUNT_ERROR_INVALID_PARAMETER;
884 account_s *data = (account_s *)account;
886 data->secret = (int)secret;
888 return ACCOUNT_ERROR_NONE;
891 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
893 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
895 if (((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC))
896 return ACCOUNT_ERROR_INVALID_PARAMETER;
898 account_s *data = (account_s *)account;
900 data->sync_support = (int)sync_support;
902 return ACCOUNT_ERROR_NONE;
905 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
908 return ACCOUNT_ERROR_INVALID_PARAMETER;
910 if (idx >= USER_INT_CNT || idx < 0)
911 return ACCOUNT_ERROR_INVALID_PARAMETER;
913 account_s *data = (account_s *)account;
915 data->user_data_int[idx] = user_int;
917 return ACCOUNT_ERROR_NONE;
920 ACCOUNT_API int account_set_capability(account_h account, const char *capability_type, account_capability_state_e capability_value)
922 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
923 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
925 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED))
926 return ACCOUNT_ERROR_INVALID_PARAMETER;
928 account_s *data = (account_s *)account;
931 bool b_is_new = TRUE;
933 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
934 account_capability_s *cap_data = NULL;
935 cap_data = (account_capability_s *)iter->data;
937 if (!strcmp(cap_data->type, capability_type)) {
938 cap_data->value = capability_value;
945 account_capability_s *cap_data = (account_capability_s *)malloc(sizeof(account_capability_s));
946 if (cap_data == NULL) {
947 ACCOUNT_FATAL("Memory Allocation Failed");
948 return ACCOUNT_ERROR_OUT_OF_MEMORY;
951 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
953 cap_data->type = _account_get_text(capability_type);
954 if (cap_data->type == NULL) {
955 ACCOUNT_FATAL("OUT OF MEMORY\n");
956 _ACCOUNT_FREE(cap_data->type);
957 _ACCOUNT_FREE(cap_data);
958 return ACCOUNT_ERROR_OUT_OF_MEMORY;
961 cap_data->value = capability_value;
962 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
965 return ACCOUNT_ERROR_NONE;
968 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
971 return ACCOUNT_ERROR_INVALID_PARAMETER;
974 return ACCOUNT_ERROR_INVALID_PARAMETER;
976 account_s *data = (account_s *)account;
979 *user_name = _account_get_text(data->user_name);
980 if (data->user_name != NULL && *user_name == NULL) {
981 ACCOUNT_FATAL("OUT OF MEMORY\n");
982 return ACCOUNT_ERROR_OUT_OF_MEMORY;
985 return ACCOUNT_ERROR_NONE;
988 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
991 return ACCOUNT_ERROR_INVALID_PARAMETER;
994 return ACCOUNT_ERROR_INVALID_PARAMETER;
996 account_s *data = (account_s *)account;
998 (*display_name) = NULL;
1000 *display_name = _account_get_text(data->display_name);
1001 if (data->display_name != NULL && *display_name == NULL) {
1002 ACCOUNT_FATAL("OUT OF MEMORY\n");
1003 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1007 return ACCOUNT_ERROR_NONE;
1010 ACCOUNT_API int account_get_email_address(account_h account, char **email_address)
1013 return ACCOUNT_ERROR_INVALID_PARAMETER;
1016 return ACCOUNT_ERROR_INVALID_PARAMETER;
1018 account_s *data = (account_s *)account;
1020 (*email_address) = NULL;
1022 *email_address = _account_get_text(data->email_address);
1023 if (data->email_address != NULL && *email_address == NULL) {
1024 ACCOUNT_FATAL("OUT OF MEMORY\n");
1025 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1028 return ACCOUNT_ERROR_NONE;
1031 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
1034 return ACCOUNT_ERROR_INVALID_PARAMETER;
1037 return ACCOUNT_ERROR_INVALID_PARAMETER;
1039 account_s *data = (account_s *)account;
1041 (*icon_path) = NULL;
1043 *icon_path = _account_get_text(data->icon_path);
1044 if (data->icon_path != NULL && *icon_path == NULL) {
1045 ACCOUNT_FATAL("OUT OF MEMORY\n");
1046 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1049 return ACCOUNT_ERROR_NONE;
1052 ACCOUNT_API int account_get_source(account_h account, char **source)
1055 return ACCOUNT_ERROR_INVALID_PARAMETER;
1058 return ACCOUNT_ERROR_INVALID_PARAMETER;
1060 account_s *data = (account_s *)account;
1064 *source = _account_get_text(data->source);
1065 if (data->source != NULL && *source == NULL) {
1066 ACCOUNT_FATAL("OUT OF MEMORY\n");
1067 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1070 return ACCOUNT_ERROR_NONE;
1073 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1076 return ACCOUNT_ERROR_INVALID_PARAMETER;
1079 return ACCOUNT_ERROR_INVALID_PARAMETER;
1081 account_s *data = (account_s *)account;
1083 (*package_name) = NULL;
1085 *package_name = _account_get_text(data->package_name);
1086 if (data->package_name != NULL && *package_name == NULL) {
1087 ACCOUNT_FATAL("OUT OF MEMORY\n");
1088 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1092 return ACCOUNT_ERROR_NONE;
1095 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1098 return ACCOUNT_ERROR_INVALID_PARAMETER;
1101 return ACCOUNT_ERROR_INVALID_PARAMETER;
1103 account_s *data = (account_s *)account;
1105 (*domain_name) = NULL;
1107 *domain_name = _account_get_text(data->domain_name);
1108 if (data->domain_name != NULL && *domain_name == NULL) {
1109 ACCOUNT_FATAL("OUT OF MEMORY\n");
1110 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1113 return ACCOUNT_ERROR_NONE;
1116 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1119 return ACCOUNT_ERROR_INVALID_PARAMETER;
1122 return ACCOUNT_ERROR_INVALID_PARAMETER;
1124 account_s *data = (account_s *)account;
1126 (*access_token) = NULL;
1128 *access_token = _account_get_text(data->access_token);
1129 if (data->access_token != NULL && *access_token == NULL) {
1130 ACCOUNT_FATAL("OUT OF MEMORY\n");
1131 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1134 return ACCOUNT_ERROR_NONE;
1137 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1140 return ACCOUNT_ERROR_INVALID_PARAMETER;
1143 return ACCOUNT_ERROR_INVALID_PARAMETER;
1145 ACCOUNT_RETURN_VAL((user_text_index >= 0 && user_text_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1147 account_s *data = (account_s *)account;
1151 *text = _account_get_text(data->user_data_txt[user_text_index]);
1152 if (data->user_data_txt[user_text_index] != NULL && *text == NULL) {
1153 ACCOUNT_FATAL("OUT OF MEMORY\n");
1154 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1157 return ACCOUNT_ERROR_NONE;
1160 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1163 return ACCOUNT_ERROR_INVALID_PARAMETER;
1166 return ACCOUNT_ERROR_INVALID_PARAMETER;
1168 account_s *data = (account_s *)account;
1170 *auth_type = data->auth_type;
1172 return ACCOUNT_ERROR_NONE;
1175 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1178 return ACCOUNT_ERROR_INVALID_PARAMETER;
1181 return ACCOUNT_ERROR_INVALID_PARAMETER;
1183 account_s *data = (account_s *)account;
1185 *secret = data->secret;
1187 return ACCOUNT_ERROR_NONE;
1190 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1193 return ACCOUNT_ERROR_INVALID_PARAMETER;
1196 return ACCOUNT_ERROR_INVALID_PARAMETER;
1198 account_s *data = (account_s *)account;
1200 *sync_support = data->sync_support;
1202 return ACCOUNT_ERROR_NONE;
1205 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1208 return ACCOUNT_ERROR_INVALID_PARAMETER;
1211 return ACCOUNT_ERROR_INVALID_PARAMETER;
1213 account_s *data = (account_s *)account;
1215 *account_id = data->id;
1217 return ACCOUNT_ERROR_NONE;
1220 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1223 return ACCOUNT_ERROR_INVALID_PARAMETER;
1225 ACCOUNT_RETURN_VAL((user_int_index >= 0 && user_int_index < USER_TXT_CNT), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1228 return ACCOUNT_ERROR_INVALID_PARAMETER;
1230 account_s *data = (account_s *)account;
1232 *integer = data->user_data_int[user_int_index];
1234 return ACCOUNT_ERROR_NONE;
1237 ACCOUNT_API int account_get_capability(account_h account, const char *capability_type, account_capability_state_e *capability_value)
1239 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1240 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1241 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1244 account_s *data = (account_s *)account;
1246 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1247 account_capability_s *cap_data = NULL;
1249 cap_data = (account_capability_s *)iter->data;
1251 if (!strcmp(capability_type, cap_data->type)) {
1252 *capability_value = cap_data->value;
1253 return ACCOUNT_ERROR_NONE;
1257 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1260 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1262 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1263 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1266 account_s *data = (account_s *)account;
1268 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1269 account_capability_s *cap_data = NULL;
1271 cap_data = (account_capability_s *)iter->data;
1273 if (callback(cap_data->type, cap_data->value, user_data) != TRUE)
1274 return ACCOUNT_ERROR_NONE;
1277 return ACCOUNT_ERROR_NONE;
1280 ACCOUNT_API int account_get_custom(account_h account, const char *key, char **value)
1282 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1283 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1284 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1287 account_s *data = (account_s *)account;
1289 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1290 account_custom_s *custom_data = NULL;
1292 custom_data = (account_custom_s *)iter->data;
1294 if (!strcmp(key, custom_data->key)) {
1296 *value = _account_get_text(custom_data->value);
1297 if (custom_data->value != NULL && *value == NULL) {
1298 ACCOUNT_FATAL("OUT OF MEMORY\n");
1299 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1302 return ACCOUNT_ERROR_NONE;
1306 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1309 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void *user_data)
1311 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1312 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1315 account_s *data = (account_s *)account;
1317 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1318 bool cb_ret = FALSE;
1319 account_custom_s *custom_data = NULL;
1321 custom_data = (account_custom_s *)iter->data;
1323 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1328 return ACCOUNT_ERROR_NONE;
1331 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1333 _INFO("account_foreach_account_from_db start");
1335 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1337 GError *error = NULL;
1339 AccountManager *acc_mgr = _account_manager_get_instance();
1340 if (acc_mgr == NULL) {
1341 _ERR("g_bus_get_sync failed");
1342 return ACCOUNT_ERROR_PERMISSION_DENIED;
1345 GVariant *account_list_variant = NULL;
1346 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, (int)getuid(), &account_list_variant, NULL, &error);
1348 int error_code = _account_get_error_code(is_success, error);
1349 g_clear_error(&error);
1351 if (error_code != ACCOUNT_ERROR_NONE)
1354 GSList *account_list = unmarshal_account_list(account_list_variant);
1355 g_variant_unref(account_list_variant);
1359 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1360 _INFO("iterating received account_list");
1361 account_s *account = NULL;
1362 account = (account_s *)iter->data;
1363 _INFO("Before _account_query_identity_info_by_id");
1365 _INFO("account->id=%d", account->id);
1366 if (callback((account_h)account, user_data) == false) {
1367 _INFO("application callback requested to discontinue.");
1370 _INFO("After one iteration callback");
1372 _account_gslist_account_free(account_list);
1374 _INFO("account_foreach_account_from_db end");
1375 return ACCOUNT_ERROR_NONE;
1378 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1380 _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1382 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1383 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT POINTER IS NULL"));
1384 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1386 GError *error = NULL;
1388 AccountManager *acc_mgr = _account_manager_get_instance();
1389 if (acc_mgr == NULL) {
1390 _ERR("g_bus_get_sync failed");
1391 return ACCOUNT_ERROR_PERMISSION_DENIED;
1394 GVariant *account_variant = NULL;
1395 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_id, (int)getuid(), &account_variant, NULL, &error);
1397 int error_code = _account_get_error_code(is_success, error);
1398 g_clear_error(&error);
1399 if (error_code != ACCOUNT_ERROR_NONE)
1402 _INFO("before unmarshal_account");
1403 account_s *account_data = umarshal_account(account_variant);
1404 _INFO("after unmarshal_account");
1406 if (account_data == NULL) {
1407 _ERR("Failed to unmarshal");
1408 return ACCOUNT_ERROR_DB_FAILED;
1411 account_s **input = (account_s **)account;
1413 _account_free_account_with_items(*input);
1415 *input = account_data;
1417 _INFO("account_query_account_by_account_id end");
1419 return ACCOUNT_ERROR_NONE;
1422 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char *user_name, void *user_data)
1424 _INFO("account_query_account_by_user_name starting");
1426 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1427 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1429 GError *error = NULL;
1431 AccountManager *acc_mgr = _account_manager_get_instance();
1432 if (acc_mgr == NULL) {
1433 _ERR("g_bus_get_sync failed");
1434 return ACCOUNT_ERROR_PERMISSION_DENIED;
1437 GVariant *account_list_variant = NULL;
1438 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, user_name, (int)getuid(), &account_list_variant, NULL, &error);
1440 int error_code = _account_get_error_code(is_success, error);
1441 g_clear_error(&error);
1442 if (error_code != ACCOUNT_ERROR_NONE)
1445 GSList *account_list = unmarshal_account_list(account_list_variant);
1446 g_variant_unref(account_list_variant);
1448 if (account_list == NULL)
1449 return ACCOUNT_ERROR_NO_DATA;
1453 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1454 _INFO("iterating received account_list");
1455 account_s *account = NULL;
1456 account = (account_s *)iter->data;
1457 if (callback((account_h)account, user_data) == false) {
1458 _INFO("application callback requested to discontinue.");
1462 _INFO("account_query_account_by_user_name end");
1464 _account_gslist_account_free(account_list);
1465 return ACCOUNT_ERROR_NONE;
1468 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1470 _INFO("account_query_account_by_package_name starting");
1472 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1473 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1475 GError *error = NULL;
1477 AccountManager *acc_mgr = _account_manager_get_instance();
1478 if (acc_mgr == NULL) {
1479 _ERR("g_bus_get_sync failed");
1480 return ACCOUNT_ERROR_PERMISSION_DENIED;
1483 GVariant *account_list_variant = NULL;
1484 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, package_name, (int)getuid(), &account_list_variant, NULL, &error);
1486 int error_code = _account_get_error_code(is_success, error);
1487 g_clear_error(&error);
1488 if (error_code != ACCOUNT_ERROR_NONE)
1491 GSList *account_list = unmarshal_account_list(account_list_variant);
1492 g_variant_unref(account_list_variant);
1494 if (account_list == NULL)
1495 return ACCOUNT_ERROR_NO_DATA;
1499 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1500 _INFO("iterating received account_list");
1501 account_s *account = NULL;
1502 account = (account_s *)iter->data;
1504 if (callback((account_h)account, user_data) == false) {
1505 _INFO("application callback requested to discontinue.");
1509 _account_gslist_account_free(account_list);
1510 _INFO("account_query_account_by_package_name end");
1511 return ACCOUNT_ERROR_NONE;
1514 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char *capability_type, account_capability_state_e capability_value, void *user_data)
1516 _INFO("account_query_account_by_capability starting");
1518 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1520 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1521 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1522 return ACCOUNT_ERROR_INVALID_PARAMETER;
1525 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) {
1531 _ERR("g_bus_get_sync failed");
1532 return ACCOUNT_ERROR_PERMISSION_DENIED;
1535 GVariant *account_list_variant = NULL;
1536 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);
1538 int error_code = _account_get_error_code(is_success, error);
1539 g_clear_error(&error);
1540 if (error_code != ACCOUNT_ERROR_NONE)
1543 GSList *account_list = unmarshal_account_list(account_list_variant);
1544 g_variant_unref(account_list_variant);
1545 if (account_list == NULL)
1546 return ACCOUNT_ERROR_NO_DATA;
1550 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1551 _INFO("iterating received account_list");
1552 account_s *account = NULL;
1553 account = (account_s *)iter->data;
1555 if (callback((account_h)account, user_data) == false) {
1556 _INFO("application callback requested to discontinue.");
1560 _account_gslist_account_free(account_list);
1561 _INFO("account_query_account_by_capability end");
1562 return ACCOUNT_ERROR_NONE;
1565 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char *capability_type, void *user_data)
1567 _INFO("account_query_account_by_capability_type starting");
1569 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1570 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1572 GError *error = NULL;
1574 AccountManager *acc_mgr = _account_manager_get_instance();
1575 if (acc_mgr == NULL) {
1576 _ERR("g_bus_get_sync failed");
1577 return ACCOUNT_ERROR_PERMISSION_DENIED;
1580 GVariant *account_list_variant = NULL;
1581 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, capability_type, (int)getuid(), &account_list_variant, NULL, &error);
1583 int error_code = _account_get_error_code(is_success, error);
1584 g_clear_error(&error);
1585 if (error_code != ACCOUNT_ERROR_NONE)
1588 GSList *account_list = unmarshal_account_list(account_list_variant);
1589 g_variant_unref(account_list_variant);
1591 if (account_list == NULL)
1592 return ACCOUNT_ERROR_NO_DATA;
1596 for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
1597 _INFO("iterating received account_list");
1598 account_s *account = NULL;
1599 account = (account_s *)iter->data;
1601 if (callback((account_h)account, user_data) == false) {
1602 _INFO("application callback requested to discontinue.");
1606 _account_gslist_account_free(account_list);
1607 _INFO("account_query_account_by_capability end");
1608 return ACCOUNT_ERROR_NONE;
1611 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1613 _INFO("account_query_capability_by_account_id starting");
1615 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1616 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1618 GError *error = NULL;
1619 AccountManager *acc_mgr = _account_manager_get_instance();
1620 if (acc_mgr == NULL) {
1621 _ERR("g_bus_get_sync failed");
1622 return ACCOUNT_ERROR_PERMISSION_DENIED;
1625 GVariant *capability_list_variant = NULL;
1626 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_id, (int)getuid(), &capability_list_variant, NULL, &error);
1628 int error_code = _account_get_error_code(is_success, error);
1629 g_clear_error(&error);
1630 if (error_code != ACCOUNT_ERROR_NONE)
1633 GSList *capability_list = unmarshal_capability_list(capability_list_variant);
1635 if (capability_list == NULL)
1636 return ACCOUNT_ERROR_NO_DATA;
1640 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter)) {
1641 _INFO("iterating received account_list");
1642 account_capability_s *capability = NULL;
1643 capability = (account_capability_s *)iter->data;
1644 if (callback(capability->type, capability->value, user_data) == false) {
1645 _INFO("application callback requested to discontinue.");
1650 _account_gslist_capability_free(capability_list);
1651 _INFO("account_query_capability_by_account_id end");
1652 return ACCOUNT_ERROR_NONE;
1655 static int _account_get_total_count(int *count, bool include_hidden)
1657 _INFO("account_get_total_count_from_db starting");
1660 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1661 return ACCOUNT_ERROR_INVALID_PARAMETER;
1664 GError *error = NULL;
1666 if (count == NULL) {
1667 _INFO("Invalid input");
1671 AccountManager *acc_mgr = _account_manager_get_instance();
1672 if (acc_mgr == NULL) {
1673 _ERR("g_bus_get_sync failed");
1674 return ACCOUNT_ERROR_PERMISSION_DENIED;
1677 int temp_count = -1;
1678 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, include_hidden, (int)getuid(), &temp_count, NULL, &error);
1679 int error_code = _account_get_error_code(is_success, error);
1680 g_clear_error(&error);
1681 if (error_code != ACCOUNT_ERROR_NONE)
1684 *count = temp_count;
1685 _INFO("account_get_total_count_from_db end");
1686 return ACCOUNT_ERROR_NONE;
1689 ACCOUNT_API int account_get_total_count_from_db(int *count)
1691 _INFO("account_get_total_count_from_db starting");
1693 return _account_get_total_count(count, true);
1696 ACCOUNT_INTERNAL_API int account_get_total_count_from_db_ex(int *count)
1698 _INFO("account_get_total_count_from_db_ex starting");
1700 return _account_get_total_count(count, false);
1703 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1705 _INFO("account_update_sync_status_by_id starting");
1706 int error_code = ACCOUNT_ERROR_NONE;
1708 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1709 if (((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1710 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1711 return ACCOUNT_ERROR_INVALID_PARAMETER;
1714 GError *error = NULL;
1716 AccountManager *acc_mgr = _account_manager_get_instance();
1717 if (acc_mgr == NULL) {
1718 _ERR("g_bus_get_sync failed");
1719 return ACCOUNT_ERROR_PERMISSION_DENIED;
1722 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_id, sync_status, (int)getuid(), NULL, &error);
1724 error_code = _account_get_error_code(is_success, error);
1725 g_clear_error(&error);
1731 ACCOUNT_API int account_type_create(account_type_h *account_type)
1733 if (!account_type) {
1734 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1735 return ACCOUNT_ERROR_INVALID_PARAMETER;
1738 account_type_s *data = (account_type_s *)malloc(sizeof(account_type_s));
1740 ACCOUNT_FATAL("Memory Allocation Failed");
1741 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1744 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1747 data->app_id = NULL;
1748 data->service_provider_id = NULL;
1749 data->icon_path = NULL;
1750 data->small_icon_path = NULL;
1751 data->multiple_account_support = false;
1752 data->label_list = NULL;
1753 data->provider_feature_list = NULL;
1755 *account_type = (account_type_h)data;
1757 return ACCOUNT_ERROR_NONE;
1760 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1762 _INFO("account_type_destroy");
1764 account_type_s *data = (account_type_s *)account_type;
1767 _ERR("Account type handle is null!");
1768 return ACCOUNT_ERROR_INVALID_PARAMETER;
1771 _account_type_free_account_type_with_items(data);
1773 return ACCOUNT_ERROR_NONE;
1776 ACCOUNT_INTERNAL_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1778 if (!account_type) {
1779 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1780 return ACCOUNT_ERROR_INVALID_PARAMETER;
1784 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1785 return ACCOUNT_ERROR_INVALID_PARAMETER;
1788 account_type_s *data = (account_type_s *)account_type;
1790 _ACCOUNT_FREE(data->app_id);
1791 data->app_id = _account_get_text(app_id);
1792 if (data->app_id == NULL) {
1793 ACCOUNT_FATAL("OUT OF MEMORY\n");
1794 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1797 return ACCOUNT_ERROR_NONE;
1800 ACCOUNT_INTERNAL_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1803 return ACCOUNT_ERROR_INVALID_PARAMETER;
1805 if (!service_provider_id)
1806 return ACCOUNT_ERROR_INVALID_PARAMETER;
1808 account_type_s *data = (account_type_s *)account_type;
1810 _ACCOUNT_FREE(data->service_provider_id);
1811 data->service_provider_id = _account_get_text(service_provider_id);
1812 if (data->service_provider_id == NULL) {
1813 ACCOUNT_FATAL("OUT OF MEMORY\n");
1814 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1817 return ACCOUNT_ERROR_NONE;
1820 ACCOUNT_INTERNAL_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1823 return ACCOUNT_ERROR_INVALID_PARAMETER;
1826 return ACCOUNT_ERROR_INVALID_PARAMETER;
1828 account_type_s *data = (account_type_s *)account_type;
1830 _ACCOUNT_FREE(data->icon_path);
1831 data->icon_path = _account_get_text(icon_path);
1832 if (data->icon_path == NULL) {
1833 ACCOUNT_FATAL("OUT OF MEMORY\n");
1834 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1837 return ACCOUNT_ERROR_NONE;
1840 ACCOUNT_INTERNAL_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
1843 return ACCOUNT_ERROR_INVALID_PARAMETER;
1845 if (!small_icon_path)
1846 return ACCOUNT_ERROR_INVALID_PARAMETER;
1848 account_type_s *data = (account_type_s *)account_type;
1850 _ACCOUNT_FREE(data->small_icon_path);
1851 data->small_icon_path = _account_get_text(small_icon_path);
1852 if (data->small_icon_path == NULL) {
1853 ACCOUNT_FATAL("OUT OF MEMORY\n");
1854 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1857 return ACCOUNT_ERROR_NONE;
1860 ACCOUNT_INTERNAL_API int account_type_set_multiple_account_support(account_type_h account_type, bool multiple_account_support)
1862 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1864 account_type_s *data = (account_type_s *)account_type;
1866 data->multiple_account_support = multiple_account_support;
1868 return ACCOUNT_ERROR_NONE;
1871 ACCOUNT_INTERNAL_API int account_type_set_label(account_type_h account_type, const char *label, const char *locale)
1873 if (!account_type) {
1874 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1875 return ACCOUNT_ERROR_INVALID_PARAMETER;
1878 if (!label || !locale)
1879 return ACCOUNT_ERROR_INVALID_PARAMETER;
1881 account_type_s *data = (account_type_s *)account_type;
1882 label_s *label_data = (label_s *)malloc(sizeof(label_s));
1883 if (label_data == NULL) {
1884 ACCOUNT_FATAL("Memory Allocation Failed");
1885 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1888 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
1890 label_data->label = _account_get_text(label);
1891 if (label_data->label == NULL) {
1892 ACCOUNT_FATAL("OUT OF MEMORY\n");
1893 _ACCOUNT_FREE(label_data);
1894 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1897 label_data->locale = _account_get_text(locale);
1898 if (label_data->locale == NULL) {
1899 ACCOUNT_FATAL("OUT OF MEMORY\n");
1900 _ACCOUNT_FREE(label_data->label);
1901 _ACCOUNT_FREE(label_data);
1902 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1905 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
1907 return ACCOUNT_ERROR_NONE;
1910 ACCOUNT_INTERNAL_API int account_type_set_provider_feature(account_type_h account_type, const char *provider_feature)
1912 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
1913 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
1915 account_type_s *data = (account_type_s *)account_type;
1917 GSList *iter = NULL;
1918 bool b_is_new = TRUE;
1920 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
1921 provider_feature_s *feature_data = NULL;
1922 feature_data = (provider_feature_s *)iter->data;
1924 if (!strcmp(feature_data->key, provider_feature)) {
1931 provider_feature_s* feature_data = (provider_feature_s *)malloc(sizeof(provider_feature_s));
1932 if (feature_data == NULL) {
1933 ACCOUNT_FATAL("Memory Allocation Failed");
1934 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1937 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
1939 feature_data->key = _account_get_text(provider_feature);
1940 if (feature_data->key == NULL) {
1941 ACCOUNT_FATAL("OUT OF MEMORY\n");
1942 _ACCOUNT_FREE(feature_data);
1943 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1946 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
1949 return ACCOUNT_ERROR_NONE;
1952 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char *app_id, void *user_data)
1954 _INFO("account_type_query_provider_feature_by_app_id start");
1956 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
1957 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1959 GError *error = NULL;
1960 gint error_code = ACCOUNT_ERROR_NONE;
1962 AccountManager *acc_mgr = _account_manager_get_instance();
1963 if (acc_mgr == NULL) {
1964 _ERR("g_bus_get_sync failed");
1965 return ACCOUNT_ERROR_PERMISSION_DENIED;
1968 GVariant *feature_list_variant = NULL;
1969 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);
1971 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
1974 error_code = _account_get_error_code(is_success, error);
1975 g_clear_error(&error);
1976 _ERR("Account IPC call returned error[%d]", error_code);
1979 g_clear_error(&error);
1981 GSList *provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
1982 if (provider_feature_list == NULL) {
1983 error_code = ACCOUNT_ERROR_NO_DATA;
1984 _ERR("[%d]", error_code);
1989 for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
1990 provider_feature_s *feature_data = NULL;
1992 feature_data = (provider_feature_s *)iter->data;
1994 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
1995 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
1996 return ACCOUNT_ERROR_NONE;
2000 _account_type_gslist_feature_free(provider_feature_list);
2001 _INFO("account_type_query_provider_feature_by_app_id end");
2005 ACCOUNT_API bool account_type_query_supported_feature(const char *app_id, const char *capability)
2007 _INFO("account_type_query_supported_feature start");
2009 if (app_id == NULL || capability == NULL) {
2010 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2014 int is_supported = 0;
2015 GError *error = NULL;
2016 gint ret = ACCOUNT_ERROR_NONE;
2018 AccountManager *acc_mgr = _account_manager_get_instance();
2019 if (acc_mgr == NULL) {
2020 _ERR("g_bus_get_sync failed");
2021 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2025 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, app_id, capability, (int)getuid(), &is_supported, NULL, &error);
2027 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2030 ret = _account_get_error_code(is_success, error);
2031 g_clear_error(&error);
2032 _ERR("Account IPC call returned error[%d]", ret);
2033 set_last_result(ret);
2036 g_clear_error(&error);
2038 set_last_result(ACCOUNT_ERROR_NONE);
2039 _INFO("account_type_query_supported_feature end");
2040 return is_supported;
2043 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2046 return ACCOUNT_ERROR_INVALID_PARAMETER;
2049 return ACCOUNT_ERROR_INVALID_PARAMETER;
2051 account_type_s *data = (account_type_s *)account_type;
2054 *app_id = _account_get_text(data->app_id);
2055 if (*app_id == NULL) {
2056 ACCOUNT_FATAL("OUT OF MEMORY\n");
2057 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2060 return ACCOUNT_ERROR_NONE;
2063 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2066 return ACCOUNT_ERROR_INVALID_PARAMETER;
2068 if (!service_provider_id)
2069 return ACCOUNT_ERROR_INVALID_PARAMETER;
2071 account_type_s *data = (account_type_s *)account_type;
2073 (*service_provider_id) = NULL;
2074 *service_provider_id = _account_get_text(data->service_provider_id);
2075 if (*service_provider_id == NULL) {
2076 ACCOUNT_FATAL("OUT OF MEMORY\n");
2077 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2080 return ACCOUNT_ERROR_NONE;
2083 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2086 return ACCOUNT_ERROR_INVALID_PARAMETER;
2089 return ACCOUNT_ERROR_INVALID_PARAMETER;
2091 account_type_s *data = (account_type_s *)account_type;
2093 (*icon_path) = NULL;
2094 *icon_path = _account_get_text(data->icon_path);
2095 if (*icon_path == NULL) {
2096 ACCOUNT_FATAL("OUT OF MEMORY\n");
2097 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2100 return ACCOUNT_ERROR_NONE;
2103 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2106 return ACCOUNT_ERROR_INVALID_PARAMETER;
2108 if (!small_icon_path)
2109 return ACCOUNT_ERROR_INVALID_PARAMETER;
2111 account_type_s *data = (account_type_s *)account_type;
2113 (*small_icon_path) = NULL;
2114 *small_icon_path = _account_get_text(data->small_icon_path);
2115 if (*small_icon_path == NULL) {
2116 ACCOUNT_FATAL("OUT OF MEMORY\n");
2117 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2121 return ACCOUNT_ERROR_NONE;
2124 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2127 return ACCOUNT_ERROR_INVALID_PARAMETER;
2129 if (!multiple_account_support)
2130 return ACCOUNT_ERROR_INVALID_PARAMETER;
2132 account_type_s *data = (account_type_s *)account_type;
2134 *multiple_account_support = data->multiple_account_support;
2136 return ACCOUNT_ERROR_NONE;
2139 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void *user_data)
2141 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2142 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2145 account_type_s *data = (account_type_s *)account_type;
2147 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2148 provider_feature_s *feature_data = NULL;
2150 feature_data = (provider_feature_s *)iter->data;
2152 if (callback(feature_data->app_id, feature_data->key, user_data) != TRUE) {
2153 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2154 return ACCOUNT_ERROR_NONE;
2158 return ACCOUNT_ERROR_NONE;
2161 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char *locale, char **label)
2163 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2164 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2167 account_type_s *data = (account_type_s *)account_type;
2169 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2170 label_s *label_data = NULL;
2172 label_data = (label_s *)iter->data;
2176 if (!strcmp(locale, label_data->locale)) {
2177 *label = _account_get_text(label_data->label);
2178 if (*label == NULL) {
2179 ACCOUNT_FATAL("OUT OF MEMORY\n");
2180 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2183 return ACCOUNT_ERROR_NONE;
2185 gchar **tokens = g_strsplit(locale, "-", 2);
2187 if (tokens != NULL) {
2188 if ((char *)(tokens[1]) != NULL) {
2189 char *upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2190 if (upper_token == NULL) {
2191 ACCOUNT_FATAL("Memory Allocation Failed");
2193 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2196 if (upper_token != NULL) {
2197 char *converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2198 if (converted_locale == NULL) {
2199 ACCOUNT_FATAL("Memory Allocation Failed");
2200 _ACCOUNT_FREE(upper_token);
2202 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2205 if (!strcmp(converted_locale, label_data->locale)) {
2206 _ACCOUNT_FREE(converted_locale);
2207 _ACCOUNT_FREE(upper_token);
2209 *label = _account_get_text(label_data->label);
2210 if (*label == NULL) {
2211 ACCOUNT_FATAL("OUT OF MEMORY\n");
2212 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2215 return ACCOUNT_ERROR_NONE;
2217 _ACCOUNT_FREE(converted_locale);
2219 _ACCOUNT_FREE(upper_token);
2225 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2228 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2230 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2231 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2234 account_type_s *data = (account_type_s *)account_type;
2236 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2237 label_s *label_data = NULL;
2239 label_data = (label_s *)iter->data;
2241 if (callback(label_data->app_id, label_data->label, label_data->locale, user_data) != TRUE) {
2242 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2243 return ACCOUNT_ERROR_NONE;
2247 return ACCOUNT_ERROR_NONE;
2250 ACCOUNT_INTERNAL_API int account_type_insert_to_db(account_type_h account_type, int *account_type_id)
2252 _INFO("account_type_insert_to_db starting");
2254 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2255 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2257 GError *error = NULL;
2259 AccountManager *acc_mgr = _account_manager_get_instance();
2260 if (acc_mgr == NULL) {
2261 _ERR("g_bus_get_sync failed");
2262 return ACCOUNT_ERROR_PERMISSION_DENIED;
2266 GVariant *account_type_serialized = marshal_account_type((account_type_s *)account_type);
2267 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_type_serialized, (int)getuid(), &db_id, NULL, &error);
2269 int ret = _account_get_error_code(is_success, error);
2270 g_clear_error(&error);
2272 if (ret != ACCOUNT_ERROR_NONE)
2275 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2277 *account_type_id = db_id;
2279 account_type_s *account_type_data = (account_type_s *)account_type;
2280 account_type_data->id = db_id;
2282 return ACCOUNT_ERROR_NONE;
2285 ACCOUNT_INTERNAL_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char *app_id)
2287 _INFO("account_type_update_to_db_by_app_id starting");
2288 int error_code = ACCOUNT_ERROR_NONE;
2290 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2291 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2293 GError *error = NULL;
2295 AccountManager *acc_mgr = _account_manager_get_instance();
2296 if (acc_mgr == NULL) {
2297 _ERR("g_bus_get_sync failed");
2298 return ACCOUNT_ERROR_PERMISSION_DENIED;
2301 GVariant *account_type_variant = marshal_account_type((account_type_s *)account_type);
2302 if (account_type_variant == NULL) {
2303 _ERR("Failed to serialize");
2304 return ACCOUNT_ERROR_INVALID_PARAMETER;
2307 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);
2309 error_code = _account_get_error_code(is_success, error);
2310 g_clear_error(&error);
2315 ACCOUNT_INTERNAL_API int account_type_delete_by_app_id(const char *app_id)
2317 _INFO("account_type_delete_by_app_id starting");
2318 int error_code = ACCOUNT_ERROR_NONE;
2320 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2322 GError *error = NULL;
2324 AccountManager *acc_mgr = _account_manager_get_instance();
2325 if (acc_mgr == NULL) {
2326 _ERR("g_bus_get_sync failed");
2327 return ACCOUNT_ERROR_PERMISSION_DENIED;
2330 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2332 error_code = _account_get_error_code(is_success, error);
2333 g_clear_error(&error);
2338 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char *app_id, void *user_data)
2340 _INFO("account_type_query_label_by_app_id starting");
2342 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2343 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2345 GError *error = NULL;
2347 AccountManager *acc_mgr = _account_manager_get_instance();
2348 if (acc_mgr == NULL) {
2349 _ERR("g_bus_get_sync failed");
2350 return ACCOUNT_ERROR_PERMISSION_DENIED;
2353 GVariant *label_list_variant = NULL;
2354 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);
2356 int ret = _account_get_error_code(is_success, error);
2357 g_clear_error(&error);
2359 if (ret != ACCOUNT_ERROR_NONE)
2362 GSList *label_list = variant_to_label_list(label_list_variant);
2363 if (label_list == NULL)
2364 return ACCOUNT_ERROR_NO_DATA;
2368 for (iter = label_list; iter != NULL; iter = g_slist_next(iter)) {
2369 _INFO("iterating received account_list");
2370 label_s *label_record = NULL;
2371 label_record = (label_s *)iter->data;
2372 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false) {
2373 _INFO("application callback requested to discontinue.");
2378 _account_type_gslist_label_free(label_list);
2379 _INFO("account_type_query_label_by_app_id end");
2380 return ACCOUNT_ERROR_NONE;
2383 ACCOUNT_API int account_type_query_by_app_id(const char *app_id, account_type_h *account_type)
2385 _INFO("account_type_query_by_app_id starting");
2387 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2388 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2389 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2391 GError *error = NULL;
2393 AccountManager *acc_mgr = _account_manager_get_instance();
2394 if (acc_mgr == NULL) {
2395 _ERR("g_bus_get_sync failed");
2396 return ACCOUNT_ERROR_PERMISSION_DENIED;
2399 GVariant *account_type_variant = NULL;
2400 account_type_s *in_data = (account_type_s *)*account_type;
2402 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, app_id, (int)getuid(), &account_type_variant, NULL, &error);
2404 int ret = _account_get_error_code(is_success, error);
2405 g_clear_error(&error);
2407 if (ret != ACCOUNT_ERROR_NONE)
2410 account_type_s *received_account_type = umarshal_account_type(account_type_variant);
2411 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2413 in_data->id = received_account_type->id;
2414 in_data->app_id = received_account_type->app_id;
2415 in_data->service_provider_id = received_account_type->service_provider_id;
2416 in_data->icon_path = received_account_type->icon_path;
2417 in_data->small_icon_path = received_account_type->small_icon_path;
2418 in_data->multiple_account_support = received_account_type->multiple_account_support;
2419 in_data->label_list = received_account_type->label_list;
2420 in_data->provider_feature_list = received_account_type->provider_feature_list;
2422 _ACCOUNT_FREE(received_account_type);
2423 _INFO("account_type_query_by_app_id end");
2424 return ACCOUNT_ERROR_NONE;
2427 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2429 _INFO("account_type_foreach_account_type_from_db starting");
2431 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2433 GError *error = NULL;
2435 AccountManager *acc_mgr = _account_manager_get_instance();
2436 if (acc_mgr == NULL) {
2437 _ERR("g_bus_get_sync failed");
2438 return ACCOUNT_ERROR_PERMISSION_DENIED;
2441 GVariant *account_type_list_variant = NULL;
2442 _INFO("before account_type_query_all_sync()");
2443 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, (int)getuid(), &account_type_list_variant, NULL, &error);
2445 _INFO("after account_type_query_all_sync()");
2446 int ret = _account_get_error_code(is_success, error);
2447 g_clear_error(&error);
2449 if (ret != ACCOUNT_ERROR_NONE)
2452 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2453 g_variant_unref(account_type_list_variant);
2455 if (account_type_list == NULL)
2456 return ACCOUNT_ERROR_NO_DATA;
2460 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2461 _INFO("iterating received account_list");
2462 account_type_s *account_type = NULL;
2463 account_type = (account_type_s *)iter->data;
2465 if (callback((account_type_h)account_type, user_data) == false) {
2466 _INFO("application callback requested to discontinue.");
2471 _account_type_gslist_account_type_free(account_type_list);
2472 _INFO("account_type_foreach_account_type_from_db end");
2473 return ACCOUNT_ERROR_NONE;
2476 ACCOUNT_API int account_type_query_label_by_locale(const char *app_id, const char *locale, char **label)
2478 _INFO("account_type_query_label_by_locale starting");
2480 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2481 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2482 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2484 GError *error = NULL;
2486 AccountManager *acc_mgr = _account_manager_get_instance();
2487 if (acc_mgr == NULL) {
2488 _ERR("g_bus_get_sync failed");
2489 return ACCOUNT_ERROR_PERMISSION_DENIED;
2492 char *label_temp = NULL;
2493 _INFO("before account_type_query_label_by_locale_sync()");
2494 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, app_id, locale, (int)getuid(), &label_temp, NULL, &error);
2496 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2497 int ret = _account_get_error_code(is_success, error);
2498 g_clear_error(&error);
2500 if (ret != ACCOUNT_ERROR_NONE)
2503 if (label_temp == NULL)
2504 return ACCOUNT_ERROR_NO_DATA;
2507 *label = _account_get_text(label_temp);
2508 if (*label == NULL) {
2509 ACCOUNT_FATAL("OUT OF MEMORY\n");
2510 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2513 _INFO("account_type_query_label_by_locale end");
2514 return ACCOUNT_ERROR_NONE;
2518 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char *key, void *user_data)
2520 _INFO("account_type_query_by_provider_feature starting");
2522 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2523 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2525 GError *error = NULL;
2527 AccountManager *acc_mgr = _account_manager_get_instance();
2528 if (acc_mgr == NULL) {
2529 _ERR("g_bus_get_sync failed");
2530 return ACCOUNT_ERROR_PERMISSION_DENIED;
2533 GVariant *account_type_list_variant = NULL;
2534 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, key, (int)getuid(), &account_type_list_variant, NULL, &error);
2536 int ret = _account_get_error_code(is_success, error);
2537 g_clear_error(&error);
2539 if (ret != ACCOUNT_ERROR_NONE)
2542 _INFO("before unmarshal_account_type_list");
2543 GSList *account_type_list = unmarshal_account_type_list(account_type_list_variant);
2544 g_variant_unref(account_type_list_variant);
2546 if (account_type_list == NULL)
2547 return ACCOUNT_ERROR_NO_DATA;
2551 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
2552 _INFO("iterating received account_type_list");
2553 account_type_s *account_type = NULL;
2554 account_type = (account_type_s *)iter->data;
2556 if (callback((account_type_h)account_type, user_data) == false) {
2557 _INFO("Application callback requested not to continue");
2563 _account_type_gslist_account_type_free(account_type_list);
2564 _INFO("account_type_query_by_provider_feature end");
2565 return ACCOUNT_ERROR_NONE;
2568 ACCOUNT_API int account_type_query_app_id_exist(const char *app_id)
2570 _INFO("account_type_query_app_id_exist starting");
2571 int error_code = ACCOUNT_ERROR_NONE;
2573 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2575 GError *error = NULL;
2577 AccountManager *acc_mgr = _account_manager_get_instance();
2578 if (acc_mgr == NULL) {
2579 _ERR("g_bus_get_sync failed");
2580 return ACCOUNT_ERROR_PERMISSION_DENIED;
2583 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, app_id, (int)getuid(), NULL, &error);
2585 error_code = _account_get_error_code(is_success, error);
2586 g_clear_error(&error);
2592 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2594 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2595 char *msg = NULL, *vconf_key = NULL;
2596 const char *key_name = NULL;
2597 char event_msg[256] = {0, };
2598 int account_id = -1;
2601 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2606 ACCOUNT_ERROR("user data required\n");
2610 key_name = vconf_keynode_get_name(key);
2612 if (key_name == NULL) {
2613 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2617 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2618 vconf_key = vconf_keynode_get_str(key);
2620 if (vconf_key == NULL) {
2621 ACCOUNT_ERROR("vconf key is NULL.\n");
2625 msg = strdup(vconf_key);
2627 ACCOUNT_FATAL("Memory Allocation Failed");
2631 char *event_type = NULL;
2635 event_type = strtok_r(msg, ":", &ptr);
2636 id = strtok_r(NULL, ":", &ptr);
2638 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2640 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2642 account_id = atoi(id);
2644 if (tmp->account_subscription_callback)
2645 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2651 ACCOUNT_API int account_subscribe_create(account_subscribe_h *account_subscribe)
2653 if (!account_subscribe) {
2654 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2655 return ACCOUNT_ERROR_INVALID_PARAMETER;
2658 account_subscribe_s *data = (account_subscribe_s *)calloc(1, sizeof(account_subscribe_s));
2660 ACCOUNT_FATAL("OUT OF MEMORY\n");
2661 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2664 *account_subscribe = (account_subscribe_h)data;
2666 return ACCOUNT_ERROR_NONE;
2669 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
2671 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2673 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2675 tmp->account_subscription_callback = callback;
2676 tmp->user_data = user_data;
2679 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2680 (vconf_callback_fn)_account_subscribe_vconf_callback,
2683 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2685 if (ret != VCONF_OK) {
2686 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2687 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2690 return ACCOUNT_ERROR_NONE;
2693 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2695 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2697 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2701 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2702 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
2703 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2704 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2707 return ACCOUNT_ERROR_NONE;
2710 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2712 account_subscribe_s *tmp = (account_subscribe_s *)user_data;
2713 char *msg = NULL, *vconf_key = NULL;
2714 char event_msg[256] = {0, };
2715 int account_id = -1;
2716 const char *key_name = NULL;
2719 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2724 ACCOUNT_ERROR("user data required\n");
2728 key_name = vconf_keynode_get_name(key);
2730 if (key_name == NULL) {
2731 ACCOUNT_ERROR("vconf_keynode_get_name(key) fail\n");
2735 if (!memcmp(key_name, VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR))) {
2736 vconf_key = vconf_keynode_get_str(key);
2738 if (vconf_key == NULL) {
2739 ACCOUNT_ERROR("vconf key is NULL.\n");
2742 msg = strdup(vconf_key);
2744 ACCOUNT_FATAL("Memory Allocation Failed");
2748 char *event_type = NULL;
2752 event_type = strtok_r(msg, ":", &ptr);
2753 id = strtok_r(NULL, ":", &ptr);
2755 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2757 ACCOUNT_SNPRINTF(event_msg, sizeof(event_msg), "%s", event_type);
2759 account_id = atoi(id);
2761 if (tmp->account_subscription_callback)
2762 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2769 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2771 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2773 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2777 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2778 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
2779 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2780 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2783 return ACCOUNT_ERROR_NONE;
2786 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void *user_data)
2788 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2790 account_subscribe_s *tmp = (account_subscribe_s *)account_subscribe;
2792 tmp->account_subscription_callback = callback;
2793 tmp->user_data = user_data;
2796 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2797 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2800 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2802 if (ret != VCONF_OK) {
2803 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2804 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2807 return ACCOUNT_ERROR_NONE;