3 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include <glib/gprintf.h>
25 #include <gio/gunixfdlist.h>
31 #include "account-error.h"
32 #include "account-private.h"
33 #include "account-types.h"
34 #include "account_ipc_marshal.h"
37 #include "account-mgr-stub.h"
39 #define ACCOUNT_DB_OPEN_READONLY 0
40 #define ACCOUNT_DB_OPEN_READWRITE 1
44 static AccountManager *_acc_mgr = NULL;
46 static char *_account_get_text(const char *text_data);
47 static int _account_gslist_free(GSList* list);
48 static int _account_glist_free(GList* list);
50 static int _account_free_capability_items(account_capability_s *data)
52 _ACCOUNT_FREE(data->type);
53 _ACCOUNT_FREE(data->package_name);
54 _ACCOUNT_FREE(data->user_name);
56 return ACCOUNT_ERROR_NONE;
59 static int _account_custom_item_free(account_custom_s *data)
61 _ACCOUNT_FREE(data->app_id);
62 _ACCOUNT_FREE(data->key);
63 _ACCOUNT_FREE(data->value);
65 return ACCOUNT_ERROR_NONE;
68 static int _account_custom_gslist_free(GSList* list)
71 return ACCOUNT_ERROR_INVALID_PARAMETER;
76 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
77 account_custom_s *custom_data = (account_custom_s*)iter->data;
78 _account_custom_item_free(custom_data);
79 _ACCOUNT_FREE(custom_data);
85 return ACCOUNT_ERROR_NONE;
88 static int _account_list_free(GList* list)
91 return ACCOUNT_ERROR_INVALID_PARAMETER;
94 g_list_free_full(list, g_free);
97 return ACCOUNT_ERROR_NONE;
100 static int _account_free_account_items(account_s *data)
102 _ACCOUNT_FREE(data->user_name);
103 _ACCOUNT_FREE(data->email_address);
104 _ACCOUNT_FREE(data->display_name);
105 _ACCOUNT_FREE(data->icon_path);
106 _ACCOUNT_FREE(data->source);
107 _ACCOUNT_FREE(data->package_name);
108 _ACCOUNT_FREE(data->domain_name);
109 _ACCOUNT_FREE(data->access_token);
112 for(i=0;i<USER_TXT_CNT;i++)
113 _ACCOUNT_FREE(data->user_data_txt[i]);
115 _account_gslist_free(data->capablity_list);
116 _account_glist_free(data->account_list);
117 _account_custom_gslist_free(data->custom_list);
118 _account_list_free(data->domain_list);
119 _account_list_free(data->mechanism_list);
121 return ACCOUNT_ERROR_NONE;
124 static int _account_gslist_free(GSList* list)
127 return ACCOUNT_ERROR_INVALID_PARAMETER;
132 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
133 account_capability_s *cap_data = (account_capability_s*)iter->data;
134 _account_free_capability_items(cap_data);
135 _ACCOUNT_FREE(cap_data);
141 return ACCOUNT_ERROR_NONE;
144 static int _account_glist_free(GList* list)
147 return ACCOUNT_ERROR_INVALID_PARAMETER;
152 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
153 account_s *account_record = (account_s*)iter->data;
154 _account_free_account_items(account_record);
155 _ACCOUNT_FREE(account_record);
161 return ACCOUNT_ERROR_NONE;
164 static char *_account_get_text(const char *text_data)
166 char *text_value = NULL;
168 if (text_data != NULL) {
169 text_value = strdup(text_data);
174 //FIXME : add true singleton logic
176 _account_manager_get_instance ()
178 _INFO("_account_manager_get_instance");
179 if (_acc_mgr != NULL)
181 _INFO("instance already created.");
185 #if !GLIB_CHECK_VERSION(2,35,0)
189 GDBusConnection *connection = NULL;
190 GError *error = NULL;
192 connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
194 _INFO("after g_bus_get_sync");
197 /* Create the object */
199 account_manager_proxy_new_sync(connection,
200 G_DBUS_PROXY_FLAGS_NONE,
201 "org.tizen.account.manager",
202 "/org/tizen/account/manager",
205 _INFO("_account_manager_get_instance end");
209 GDBusErrorEntry _account_svc_errors[] =
211 {ACCOUNT_ERROR_NONE, _ACCOUNT_SVC_ERROR_PREFIX".NoError"},
212 {ACCOUNT_ERROR_OUT_OF_MEMORY, _ACCOUNT_SVC_ERROR_PREFIX".OutOfMemory"},
213 {ACCOUNT_ERROR_INVALID_PARAMETER, _ACCOUNT_SVC_ERROR_PREFIX".InvalidParameter"},
214 {ACCOUNT_ERROR_DUPLICATED, _ACCOUNT_SVC_ERROR_PREFIX".Duplicated"},
215 {ACCOUNT_ERROR_NO_DATA, _ACCOUNT_SVC_ERROR_PREFIX".NoData"},
216 {ACCOUNT_ERROR_RECORD_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".RecordNotFound"},
217 {ACCOUNT_ERROR_DB_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".DBFailed"},
218 {ACCOUNT_ERROR_DB_NOT_OPENED, _ACCOUNT_SVC_ERROR_PREFIX".DBNotOpened"},
219 {ACCOUNT_ERROR_QUERY_SYNTAX_ERROR, _ACCOUNT_SVC_ERROR_PREFIX".QuerySynTaxError"},
220 {ACCOUNT_ERROR_ITERATOR_END, _ACCOUNT_SVC_ERROR_PREFIX".IteratorEnd"},
221 {ACCOUNT_ERROR_NOTI_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".NotiFalied"},
222 {ACCOUNT_ERROR_PERMISSION_DENIED, _ACCOUNT_SVC_ERROR_PREFIX".PermissionDenied"},
223 {ACCOUNT_ERROR_XML_PARSE_FAILED, _ACCOUNT_SVC_ERROR_PREFIX".XMLParseFailed"},
224 {ACCOUNT_ERROR_XML_FILE_NOT_FOUND, _ACCOUNT_SVC_ERROR_PREFIX".FileNotFound"},
225 {ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL, _ACCOUNT_SVC_ERROR_PREFIX".SubscriptionFailed"},
226 {ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, _ACCOUNT_SVC_ERROR_PREFIX".NotRegisteredProvider"},
227 {ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE, _ACCOUNT_SVC_ERROR_PREFIX".NotAllowMultiple"},
228 {ACCOUNT_ERROR_DATABASE_BUSY, _ACCOUNT_SVC_ERROR_PREFIX".database_busy"},
231 static int _account_get_error_code(bool is_success, GError *error)
235 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
237 if (g_dbus_error_is_remote_error(error))
239 gchar *remote_error = g_dbus_error_get_remote_error(error);
242 _INFO("Remote error[%s]", remote_error);
244 //FIXME: Temp fix, error->code sent from daemon is not the same as the one received.
245 //However error->message matches, so doing reverse lookup
246 int error_enum_count = G_N_ELEMENTS(_account_svc_errors);
248 for (i = 0; i < error_enum_count; i++)
250 if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0)
252 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
253 return _account_svc_errors[i].error_code;
258 //All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED
259 return ACCOUNT_ERROR_PERMISSION_DENIED;
261 return ACCOUNT_ERROR_NONE;
264 ACCOUNT_API int account_connect(void)
266 return ACCOUNT_ERROR_NONE;
269 ACCOUNT_API int account_connect_readonly(void)
271 return ACCOUNT_ERROR_NONE;
274 ACCOUNT_API int account_disconnect(void)
276 return ACCOUNT_ERROR_NONE;
280 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
282 _INFO("1. account_insert_to_db start");
283 char* account_db_path = ACCOUNT_DB_NAME;
285 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
286 ACCOUNT_RETURN_VAL((account_db_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
288 account_s *account_data = (account_s*) account;
289 int error_code = ACCOUNT_ERROR_NONE;
290 GError *error = NULL;
292 _INFO("2. Before _account_manager_get_instance()");
293 AccountManager* acc_mgr = _account_manager_get_instance();
294 ACCOUNT_CATCH_ERROR((acc_mgr != NULL), {}, ACCOUNT_ERROR_PERMISSION_DENIED, "Failed to get dbus.");
297 GVariant* account_serialized = marshal_account(account_data);
299 _INFO("3. Before account_manager_call_account_add_sync");
300 bool is_success = account_manager_call_account_add_sync(acc_mgr, account_db_path, account_serialized, &db_id, NULL, &error);
301 ACCOUNT_CATCH_ERROR((is_success != false), {}, _account_get_error_code(is_success, error), "Failed to get dbus.");
303 *account_db_id = db_id;
304 account_data->id = db_id;
306 _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
308 return ACCOUNT_ERROR_NONE;
311 //Failed to get dbus.
312 _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
317 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
319 _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
320 char* account_db_path = ACCOUNT_DB_NAME;
322 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
324 GError *error = NULL;
326 AccountManager* acc_mgr = _account_manager_get_instance();
329 _ERR("g_bus_get_sync failed");
330 return ACCOUNT_ERROR_PERMISSION_DENIED;
333 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
334 GVariant *account_serialized_old = NULL;
335 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_db_id, &account_serialized_old, NULL, &error);
339 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
340 return _account_get_error_code(is_success, error);
343 _INFO("3. Before account_manager_call_account_delete_from_db_by_id_sync");
344 is_success = account_manager_call_account_delete_from_db_by_id_sync(acc_mgr, account_db_path, account_db_id, NULL, &error);
348 _ERR("account_manager_call_account_delete_from_db_by_id_sync failed [%d]", error->code);
349 return _account_get_error_code(is_success, error);
352 _INFO("4. Before account_delete_from_db_by_id end");
353 return ACCOUNT_ERROR_NONE;
356 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
358 _INFO("account_delete_from_db_by_user_name start");
359 char* account_db_path = ACCOUNT_DB_NAME;
361 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
362 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
365 GError *error = NULL;
367 AccountManager* acc_mgr = _account_manager_get_instance();
370 _ERR("g_bus_get_sync failed");
371 return ACCOUNT_ERROR_PERMISSION_DENIED;
374 GVariant* account_list_variant = NULL;
375 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, account_db_path, user_name, &account_list_variant, NULL, &error);
377 int error_code = _account_get_error_code(is_success, error);
378 if (error_code != ACCOUNT_ERROR_NONE)
380 _ERR("account_query_account_by_user_name error=[%d]", error_code);
384 _INFO("before unmarshal_account_list");
385 GSList* account_list = unmarshal_account_list(account_list_variant);
386 _INFO("after unmarshal_account_list");
387 if (account_list == NULL)
389 return ACCOUNT_ERROR_NO_DATA;
392 //TODO free account_list, account_list_variant
394 is_success = account_manager_call_account_delete_from_db_by_user_name_sync(acc_mgr, account_db_path, user_name, package_name, NULL, &error);
398 _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error->code);
399 return _account_get_error_code(is_success, error);
402 return ACCOUNT_ERROR_NONE;
405 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
407 _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
408 char* account_db_path = ACCOUNT_DB_NAME;
410 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
412 GError *error = NULL;
414 AccountManager* acc_mgr = _account_manager_get_instance();
417 _ERR("g_bus_get_sync failed");
418 return ACCOUNT_ERROR_PERMISSION_DENIED;
421 //First get account list of user_name, used for gSSO DB deletion
422 GVariant* account_list_variant = NULL;
423 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, &account_list_variant, NULL, &error);
425 int error_code = _account_get_error_code(is_success, error);
426 if (error_code != ACCOUNT_ERROR_NONE)
431 _INFO("before unmarshal_account_list");
432 GSList* account_list = unmarshal_account_list(account_list_variant);
433 _INFO("after unmarshal_account_list");
434 if (account_list == NULL)
436 return ACCOUNT_ERROR_NO_DATA;
439 is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, account_db_path, package_name, permission, NULL, &error);
443 _ERR("account_manager_call_account_delete_from_db_by_package_name_sync failed [%d]", error->code);
444 return _account_get_error_code(is_success, error);
447 return ACCOUNT_ERROR_NONE;
450 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
452 _INFO("account_delete_from_db_by_package_name starting with permission");
453 return _account_delete_from_db_by_package_name(package_name, true);
456 ACCOUNT_API int account_delete_from_db_by_package_name_without_permission(const char *package_name)
458 _INFO("account_delete_from_db_by_package_name starting without permission");
459 return _account_delete_from_db_by_package_name(package_name, false);
462 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
464 //First we will update account db
465 _INFO("1. account_update_to_db_by_id start");
466 char* account_db_path = ACCOUNT_DB_NAME;
468 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
469 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
471 GError *error = NULL;
473 AccountManager* acc_mgr = _account_manager_get_instance();
476 _ERR("g_bus_get_sync failed");
477 return ACCOUNT_ERROR_PERMISSION_DENIED;
480 _INFO("2. Before account_manager_call_account_query_account_by_account_id_sync");
481 GVariant *account_serialized_old = NULL;
482 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_id, &account_serialized_old, NULL, &error);
486 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
487 return _account_get_error_code(is_success, error);
490 _INFO("3. Before account_manager_call_account_update_to_db_by_id_sync");
491 GVariant* account_serialized = marshal_account((account_s*) account);
492 is_success = account_manager_call_account_update_to_db_by_id_sync(acc_mgr, account_db_path, account_serialized, account_id, NULL, &error);
496 _ERR("account_manager_call_account_update_to_db_by_id_sync failed [%d]", error->code);
497 return _account_get_error_code(is_success, error);
500 _INFO("4. account_update_to_db_by_id end");
501 return ACCOUNT_ERROR_NONE;
504 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
507 ret = account_update_to_db_by_id(account, account_id);
512 ACCOUNT_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
514 //First we will update account db
515 //Then we will update gSSO DB, if it fails then we will rollback account db updates
517 _INFO("account_update_to_db_by_id_without_permission start");
518 char* account_db_path = ACCOUNT_DB_NAME;
520 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
521 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
523 GError *error = NULL;
525 AccountManager* acc_mgr = _account_manager_get_instance();
528 _ERR("g_bus_get_sync failed");
529 return ACCOUNT_ERROR_PERMISSION_DENIED;
532 GVariant *account_serialized_old = NULL;
533 _INFO("before query() account_id[%d]", account_id);
534 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_id, &account_serialized_old, NULL, &error);
538 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
539 return _account_get_error_code(is_success, error);
542 _INFO("before marshal() : account_id[%d], user_name=%s", account_id, ((account_s*)account)->user_name);
543 GVariant* account_serialized = marshal_account((account_s*) account);
544 _INFO("after marshal() : account_id[%d]", account_id);
545 if (account_serialized == NULL)
547 _ERR("Invalid input");
548 return ACCOUNT_ERROR_INVALID_PARAMETER;
551 _INFO("before call update() : account_id[%d]", account_id);
552 is_success = account_manager_call_account_update_to_db_by_id_ex_sync(acc_mgr, account_db_path, account_serialized, account_id, NULL, &error);
554 _INFO("after call update() : is_success=%d", is_success);
557 _ERR("account_manager_call_account_update_to_db_by_id_ex_sync failed [%d]", error->code);
558 return _account_get_error_code(is_success, error);
561 return ACCOUNT_ERROR_NONE;
564 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
566 //First we will update account db
567 _INFO("account_update_to_db_by_user_name starting");
568 char* account_db_path = ACCOUNT_DB_NAME;
570 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
571 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
572 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
574 GError *error = NULL;
576 AccountManager* acc_mgr = _account_manager_get_instance();
579 _ERR("g_bus_get_sync failed");
580 return ACCOUNT_ERROR_PERMISSION_DENIED;
583 GVariant *account_serialized_old = NULL;
584 account_s *account_data = (account_s*) account;
585 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_data->id, &account_serialized_old, NULL, &error);
589 _ERR("account_manager_call_account_query_account_by_account_id_sync failed [%d]", error->code);
590 return _account_get_error_code(is_success, error);
593 GVariant* account_serialized = marshal_account(account_data);
594 is_success = account_manager_call_account_update_to_db_by_user_name_sync(acc_mgr, account_db_path, account_serialized, user_name, package_name, NULL, &error);
598 _ERR("account_manager_call_account_update_to_db_by_user_name_sync failed [%d]", error->code);
599 return _account_get_error_code(is_success, error);
602 return ACCOUNT_ERROR_NONE;
605 ACCOUNT_API int account_create(account_h *account)
608 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
609 return ACCOUNT_ERROR_INVALID_PARAMETER;
612 account_s *data = (account_s*)malloc(sizeof(account_s));
615 ACCOUNT_FATAL("Memory Allocation Failed");
616 return ACCOUNT_ERROR_OUT_OF_MEMORY;
618 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
620 /*Setting account as visible by default*/
621 data->secret = ACCOUNT_SECRECY_VISIBLE;
623 /*Setting account as not supporting sync by default*/
624 data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
626 data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
628 data->account_list = NULL;
629 data->capablity_list = NULL;
630 data->custom_list = NULL;
631 data->domain_list = NULL;
632 data->mechanism_list = NULL;
634 *account = (account_h)data;
636 return ACCOUNT_ERROR_NONE;
639 ACCOUNT_API int account_destroy(account_h account)
641 account_s *data = (account_s*)account;
643 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
645 _account_free_account_items(data);
648 return ACCOUNT_ERROR_NONE;
651 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
654 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
655 return ACCOUNT_ERROR_INVALID_PARAMETER;
659 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
660 return ACCOUNT_ERROR_INVALID_PARAMETER;
663 account_s *data = (account_s*)account;
665 _ACCOUNT_FREE(data->user_name);
666 data->user_name = _account_get_text(user_name);
668 return ACCOUNT_ERROR_NONE;
671 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
674 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
675 return ACCOUNT_ERROR_INVALID_PARAMETER;
679 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
680 return ACCOUNT_ERROR_INVALID_PARAMETER;
683 account_s *data = (account_s*)account;
685 _ACCOUNT_FREE(data->display_name);
686 data->display_name = _account_get_text(display_name);
688 return ACCOUNT_ERROR_NONE;
691 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
694 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
695 return ACCOUNT_ERROR_INVALID_PARAMETER;
698 if (!email_address) {
699 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
700 return ACCOUNT_ERROR_INVALID_PARAMETER;
703 account_s *data = (account_s*)account;
705 _ACCOUNT_FREE(data->email_address);
706 data->email_address = _account_get_text(email_address);
708 return ACCOUNT_ERROR_NONE;
711 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
714 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
715 return ACCOUNT_ERROR_INVALID_PARAMETER;
719 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
720 return ACCOUNT_ERROR_INVALID_PARAMETER;
723 account_s *data = (account_s*)account;
725 _ACCOUNT_FREE(data->icon_path);
726 data->icon_path = _account_get_text(icon_path);
728 return ACCOUNT_ERROR_NONE;
731 ACCOUNT_API int account_set_source(account_h account, const char *source)
734 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
735 return ACCOUNT_ERROR_INVALID_PARAMETER;
739 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
740 return ACCOUNT_ERROR_INVALID_PARAMETER;
742 account_s *data = (account_s*)account;
744 _ACCOUNT_FREE(data->source);
745 data->source = _account_get_text(source);
747 return ACCOUNT_ERROR_NONE;
750 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
753 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
754 return ACCOUNT_ERROR_INVALID_PARAMETER;
758 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
759 return ACCOUNT_ERROR_INVALID_PARAMETER;
762 account_s *data = (account_s*)account;
764 _ACCOUNT_FREE(data->package_name);
765 data->package_name = _account_get_text(package_name);
767 return ACCOUNT_ERROR_NONE;
770 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
773 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
774 return ACCOUNT_ERROR_INVALID_PARAMETER;
778 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
779 return ACCOUNT_ERROR_INVALID_PARAMETER;
781 account_s *data = (account_s*)account;
783 _ACCOUNT_FREE(data->domain_name);
784 data->domain_name = _account_get_text(domain_name);
786 return ACCOUNT_ERROR_NONE;
789 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
792 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
793 return ACCOUNT_ERROR_INVALID_PARAMETER;
797 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
798 return ACCOUNT_ERROR_INVALID_PARAMETER;
801 account_s *data = (account_s*)account;
803 _ACCOUNT_FREE(data->access_token);
804 data->access_token = _account_get_text(access_token);
806 return ACCOUNT_ERROR_NONE;
809 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
812 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
813 return ACCOUNT_ERROR_INVALID_PARAMETER;
817 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
818 return ACCOUNT_ERROR_INVALID_PARAMETER;
820 if (idx >= USER_TXT_CNT || idx < 0) {
821 ACCOUNT_SLOGE("(%s)-(%d) idx rage should be between 0-4.\n", __FUNCTION__, __LINE__);
822 return ACCOUNT_ERROR_INVALID_PARAMETER;
825 account_s *data = (account_s*)account;
827 _ACCOUNT_FREE(data->user_data_txt[idx]);
828 data->user_data_txt[idx] = _account_get_text(user_txt);
830 return ACCOUNT_ERROR_NONE;
833 ACCOUNT_API int account_set_custom(account_h account, const char* key, const char* value)
836 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
837 return ACCOUNT_ERROR_INVALID_PARAMETER;
841 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
842 return ACCOUNT_ERROR_INVALID_PARAMETER;
846 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
847 return ACCOUNT_ERROR_INVALID_PARAMETER;
850 account_s *data = (account_s*)account;
853 bool b_is_new = TRUE;
855 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
857 account_custom_s* custom_data = NULL;
858 custom_data = (account_custom_s*)iter->data;
859 ACCOUNT_SLOGD( "account_custom_s->key = %s, account_custom_s->value = %s \n", custom_data->key, custom_data->value);
861 if(!strcmp(custom_data->key, key)) {
862 _ACCOUNT_FREE(custom_data->value);
863 custom_data->value = _account_get_text(value);
869 account_custom_s* custom_data = (account_custom_s*)malloc(sizeof(account_custom_s));
871 if (custom_data == NULL) {
872 return ACCOUNT_ERROR_OUT_OF_MEMORY;
874 ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
875 custom_data->account_id = data->id;
876 custom_data->app_id = _account_get_text(data->package_name);
877 custom_data->key = _account_get_text(key);
878 custom_data->value = _account_get_text(value);
879 data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
882 return ACCOUNT_ERROR_NONE;
885 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
887 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
889 if ( ((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN)) {
890 return ACCOUNT_ERROR_INVALID_PARAMETER;
893 account_s *data = (account_s*)account;
895 data->auth_type = (int)auth_type;
897 return ACCOUNT_ERROR_NONE;
900 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
902 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
904 if ( ((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE)) {
905 return ACCOUNT_ERROR_INVALID_PARAMETER;
908 account_s *data = (account_s*)account;
910 data->secret = (int)secret;
912 return ACCOUNT_ERROR_NONE;
915 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
917 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
919 if ( ((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC)) {
920 return ACCOUNT_ERROR_INVALID_PARAMETER;
923 account_s *data = (account_s*)account;
925 data->sync_support= (int)sync_support;
927 return ACCOUNT_ERROR_NONE;
930 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
933 return ACCOUNT_ERROR_INVALID_PARAMETER;
936 if (idx >= USER_INT_CNT ||idx < 0) {
937 return ACCOUNT_ERROR_INVALID_PARAMETER;
940 account_s *data = (account_s*)account;
942 data->user_data_int[idx] = user_int;
944 return ACCOUNT_ERROR_NONE;
947 ACCOUNT_API int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_value)
949 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account handle is null"));
950 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is null"));
952 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED)) {
953 return ACCOUNT_ERROR_INVALID_PARAMETER;
956 account_s *data = (account_s*)account;
959 bool b_is_new = TRUE;
961 for(iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
962 account_capability_s *cap_data = NULL;
963 cap_data = (account_capability_s*)iter->data;
965 if(!strcmp(cap_data->type, capability_type)) {
966 cap_data->value = capability_value;
973 account_capability_s* cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
975 if (cap_data == NULL)
976 return ACCOUNT_ERROR_OUT_OF_MEMORY;
977 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
979 cap_data->type = _account_get_text(capability_type);
980 cap_data->value = capability_value;
981 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
984 return ACCOUNT_ERROR_NONE;
987 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
990 return ACCOUNT_ERROR_INVALID_PARAMETER;
994 return ACCOUNT_ERROR_INVALID_PARAMETER;
997 account_s *data = (account_s*)account;
1000 *user_name = _account_get_text(data->user_name);
1002 return ACCOUNT_ERROR_NONE;
1005 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
1008 return ACCOUNT_ERROR_INVALID_PARAMETER;
1011 if (!display_name) {
1012 return ACCOUNT_ERROR_INVALID_PARAMETER;
1015 account_s *data = (account_s*)account;
1017 (*display_name) = NULL;
1019 *display_name = _account_get_text(data->display_name);
1021 return ACCOUNT_ERROR_NONE;
1024 ACCOUNT_API int account_get_email_address(account_h account,char **email_address)
1027 return ACCOUNT_ERROR_INVALID_PARAMETER;
1030 if (!email_address) {
1031 return ACCOUNT_ERROR_INVALID_PARAMETER;
1034 account_s *data = (account_s*)account;
1036 (*email_address) = NULL;
1038 *email_address = _account_get_text(data->email_address);
1040 return ACCOUNT_ERROR_NONE;
1043 ACCOUNT_API int account_get_icon_path(account_h account, char **icon_path)
1046 return ACCOUNT_ERROR_INVALID_PARAMETER;
1050 return ACCOUNT_ERROR_INVALID_PARAMETER;
1053 account_s *data = (account_s*)account;
1055 (*icon_path) = NULL;
1057 *icon_path = _account_get_text(data->icon_path);
1059 return ACCOUNT_ERROR_NONE;
1062 ACCOUNT_API int account_get_source(account_h account, char **source)
1065 return ACCOUNT_ERROR_INVALID_PARAMETER;
1069 return ACCOUNT_ERROR_INVALID_PARAMETER;
1072 account_s *data = (account_s*)account;
1076 *source = _account_get_text(data->source);
1078 return ACCOUNT_ERROR_NONE;
1081 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1084 return ACCOUNT_ERROR_INVALID_PARAMETER;
1087 if (!package_name) {
1088 return ACCOUNT_ERROR_INVALID_PARAMETER;
1091 account_s *data = (account_s*)account;
1093 (*package_name) = NULL;
1095 *package_name = _account_get_text(data->package_name);
1097 return ACCOUNT_ERROR_NONE;
1100 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1103 return ACCOUNT_ERROR_INVALID_PARAMETER;
1107 return ACCOUNT_ERROR_INVALID_PARAMETER;
1110 account_s *data = (account_s*)account;
1112 (*domain_name) = NULL;
1114 *domain_name = _account_get_text(data->domain_name);
1116 return ACCOUNT_ERROR_NONE;
1119 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1122 return ACCOUNT_ERROR_INVALID_PARAMETER;
1125 if (!access_token) {
1126 return ACCOUNT_ERROR_INVALID_PARAMETER;
1129 account_s *data = (account_s*)account;
1131 (*access_token) = NULL;
1133 *access_token = _account_get_text(data->access_token);
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;
1145 return ACCOUNT_ERROR_INVALID_PARAMETER;
1147 ACCOUNT_RETURN_VAL((user_text_index >=0 && user_text_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1149 account_s *data = (account_s*)account;
1153 *text = _account_get_text(data->user_data_txt[user_text_index]);
1155 return ACCOUNT_ERROR_NONE;
1158 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1161 return ACCOUNT_ERROR_INVALID_PARAMETER;
1164 return ACCOUNT_ERROR_INVALID_PARAMETER;
1167 account_s* data = (account_s*)account;
1169 *auth_type = data->auth_type;
1171 return ACCOUNT_ERROR_NONE;
1174 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1177 return ACCOUNT_ERROR_INVALID_PARAMETER;
1180 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;
1195 if (!sync_support) {
1196 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;
1215 account_s *data = (account_s*)account;
1217 *account_id = data->id;
1219 return ACCOUNT_ERROR_NONE;
1222 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1225 return ACCOUNT_ERROR_INVALID_PARAMETER;
1228 ACCOUNT_RETURN_VAL((user_int_index >=0 && user_int_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1231 return ACCOUNT_ERROR_INVALID_PARAMETER;
1234 account_s *data = (account_s*)account;
1236 *integer = data->user_data_int[user_int_index];
1238 return ACCOUNT_ERROR_NONE;
1241 ACCOUNT_API int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value)
1243 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1244 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type is NULL"));
1245 ACCOUNT_RETURN_VAL((capability_value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_value is NULL"));
1248 account_s *data = (account_s*)account;
1250 _ERR("before for()");
1251 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1252 account_capability_s *cap_data = NULL;
1254 cap_data = (account_capability_s*)iter->data;
1256 _ERR("capability_type = %s, data->type = %s", capability_type, cap_data->type);
1257 _ERR("capability_value = %d, data->value= %d", capability_value, cap_data->value);
1258 if(!strcmp(capability_type, cap_data->type)) {
1259 *capability_value = cap_data->value;
1260 return ACCOUNT_ERROR_NONE;
1263 _ERR("after for()");
1265 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1268 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1270 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1271 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1274 account_s *data = (account_s*)account;
1276 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1277 account_capability_s *cap_data = NULL;
1279 cap_data = (account_capability_s*)iter->data;
1281 if(callback(cap_data->type, cap_data->value, user_data)!=TRUE){
1282 return ACCOUNT_ERROR_NONE;
1286 return ACCOUNT_ERROR_NONE;
1289 ACCOUNT_API int account_get_custom(account_h account, const char* key, char** value)
1291 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1292 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO KEY TO REQUEST"));
1293 ACCOUNT_RETURN_VAL((value != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("VALUE POINTER IS NULL"));
1296 account_s *data = (account_s*)account;
1298 _ERR("before for()");
1299 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1300 account_custom_s *custom_data = NULL;
1302 custom_data = (account_custom_s*)iter->data;
1304 _ERR("key = %s, custom_data->key = %s", key, custom_data->key);
1305 _ERR("value = %s, custom_data->value = %s", value, custom_data->value);
1307 if(!strcmp(key, custom_data->key)) {
1309 *value = _account_get_text(custom_data->value);
1310 return ACCOUNT_ERROR_NONE;
1313 _ERR("after for()");
1315 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1318 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void* user_data)
1320 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1321 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1324 account_s *data = (account_s*)account;
1326 for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1327 bool cb_ret = FALSE;
1328 account_custom_s *custom_data = NULL;
1330 custom_data = (account_custom_s*)iter->data;
1332 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1338 return ACCOUNT_ERROR_NONE;
1341 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1343 _INFO("account_type_foreach_account_type_from_db start");
1344 char* account_db_path = ACCOUNT_DB_NAME;
1346 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1348 GError *error = NULL;
1350 AccountManager* acc_mgr = _account_manager_get_instance();
1351 if (acc_mgr == NULL)
1353 _ERR("g_bus_get_sync failed");
1354 return ACCOUNT_ERROR_PERMISSION_DENIED;
1357 GVariant* account_list_variant = NULL;
1358 bool is_success = account_manager_call_account_query_all_sync(acc_mgr, account_db_path, &account_list_variant, NULL, &error);
1360 int error_code = _account_get_error_code(is_success, error);
1361 if (error_code != ACCOUNT_ERROR_NONE)
1366 _INFO("before unmarshal_account_list");
1367 GSList* account_list = unmarshal_account_list(account_list_variant);
1368 _INFO("after unmarshal_account_list");
1371 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1373 _INFO("iterating received account_list");
1374 account_s *account = NULL;
1375 account = (account_s*)iter->data;
1376 _INFO("Before _account_query_identity_info_by_id");
1378 _INFO("account->id=%d", account->id);
1379 if (callback((account_h)account, user_data) == false)
1381 _INFO("application callback requested to discontinue.");
1384 _INFO("After one iteration callback");
1386 _INFO("account_foreach_account_from_db end");
1388 return ACCOUNT_ERROR_NONE;
1391 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1393 _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1394 char* account_db_path = ACCOUNT_DB_NAME;
1396 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1397 ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
1399 GError *error = NULL;
1401 AccountManager* acc_mgr = _account_manager_get_instance();
1402 if (acc_mgr == NULL)
1404 _ERR("g_bus_get_sync failed");
1405 return ACCOUNT_ERROR_PERMISSION_DENIED;
1408 GVariant* account_variant = NULL;
1409 bool is_success = account_manager_call_account_query_account_by_account_id_sync(acc_mgr, account_db_path, account_db_id, &account_variant, NULL, &error);
1411 int error_code = _account_get_error_code(is_success, error);
1412 if (error_code != ACCOUNT_ERROR_NONE)
1417 _INFO("before unmarshal_account");
1418 account_s* account_data = umarshal_account(account_variant);
1419 _INFO("after unmarshal_account");
1421 if (account_data == NULL)
1423 _ERR("Failed to unmarshal");
1424 return ACCOUNT_ERROR_DB_FAILED;
1427 *account = (account_h) account_data;
1429 _INFO("account_query_account_by_account_id end");
1431 return ACCOUNT_ERROR_NONE;
1434 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char* user_name, void* user_data)
1436 _INFO("account_query_account_by_user_name starting");
1437 char* account_db_path = ACCOUNT_DB_NAME;
1439 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1440 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1442 GError *error = NULL;
1444 AccountManager* acc_mgr = _account_manager_get_instance();
1445 if (acc_mgr == NULL)
1447 _ERR("g_bus_get_sync failed");
1448 return ACCOUNT_ERROR_PERMISSION_DENIED;
1451 GVariant* account_list_variant = NULL;
1452 bool is_success = account_manager_call_account_query_account_by_user_name_sync(acc_mgr, account_db_path, user_name, &account_list_variant, NULL, &error);
1454 int error_code = _account_get_error_code(is_success, error);
1455 if (error_code != ACCOUNT_ERROR_NONE)
1460 _INFO("before unmarshal_account_list");
1461 GSList* account_list = unmarshal_account_list(account_list_variant);
1462 _INFO("after unmarshal_account_list");
1463 if (account_list == NULL)
1465 return ACCOUNT_ERROR_NO_DATA;
1470 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1472 _INFO("iterating received account_list");
1473 account_s *account = NULL;
1474 account = (account_s*)iter->data;
1475 if (callback((account_h)account, user_data) == false)
1477 _INFO("application callback requested to discontinue.");
1481 _INFO("account_query_account_by_user_name end");
1483 return ACCOUNT_ERROR_NONE;
1486 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1488 _INFO("account_query_account_by_package_name starting");
1489 char* account_db_path = ACCOUNT_DB_NAME;
1491 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1492 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1494 GError *error = NULL;
1496 AccountManager* acc_mgr = _account_manager_get_instance();
1497 if (acc_mgr == NULL)
1499 _ERR("g_bus_get_sync failed");
1500 return ACCOUNT_ERROR_PERMISSION_DENIED;
1503 GVariant* account_list_variant = NULL;
1504 bool is_success = account_manager_call_account_query_account_by_package_name_sync(acc_mgr, account_db_path, package_name, &account_list_variant, NULL, &error);
1506 int error_code = _account_get_error_code(is_success, error);
1507 if (error_code != ACCOUNT_ERROR_NONE)
1512 _INFO("before unmarshal_account_list");
1513 GSList* account_list = unmarshal_account_list(account_list_variant);
1514 _INFO("after unmarshal_account_list");
1515 if (account_list == NULL)
1517 return ACCOUNT_ERROR_NO_DATA;
1522 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1524 _INFO("iterating received account_list");
1525 account_s *account = NULL;
1526 account = (account_s*)iter->data;
1528 if (callback((account_h)account, user_data) == false)
1530 _INFO("application callback requested to discontinue.");
1534 _INFO("account_query_account_by_package_name end");
1535 return ACCOUNT_ERROR_NONE;
1538 ACCOUNT_API int account_query_account_by_capability(account_cb callback, const char* capability_type, account_capability_state_e capability_value, void *user_data)
1540 _INFO("account_query_account_by_capability starting");
1541 char* account_db_path = ACCOUNT_DB_NAME;
1543 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1545 if (((int)capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
1546 ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1547 return ACCOUNT_ERROR_INVALID_PARAMETER;
1550 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1552 GError *error = NULL;
1554 AccountManager* acc_mgr = _account_manager_get_instance();
1555 if (acc_mgr == NULL)
1557 _ERR("g_bus_get_sync failed");
1558 return ACCOUNT_ERROR_PERMISSION_DENIED;
1561 GVariant* account_list_variant = NULL;
1562 bool is_success = account_manager_call_account_query_account_by_capability_sync(acc_mgr, account_db_path, capability_type, capability_value, &account_list_variant, NULL, &error);
1564 int error_code = _account_get_error_code(is_success, error);
1565 if (error_code != ACCOUNT_ERROR_NONE)
1570 _INFO("before unmarshal_account_list");
1571 GSList* account_list = unmarshal_account_list(account_list_variant);
1572 _INFO("after unmarshal_account_list");
1573 if (account_list == NULL)
1575 return ACCOUNT_ERROR_NO_DATA;
1580 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1582 _INFO("iterating received account_list");
1583 account_s *account = NULL;
1584 account = (account_s*)iter->data;
1586 if (callback((account_h)account, user_data) == false)
1588 _INFO("application callback requested to discontinue.");
1592 _INFO("account_query_account_by_capability end");
1593 return ACCOUNT_ERROR_NONE;
1596 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char* capability_type, void* user_data)
1598 _INFO("account_query_account_by_capability_type starting");
1599 char* account_db_path = ACCOUNT_DB_NAME;
1601 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1602 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1604 GError *error = NULL;
1606 AccountManager* acc_mgr = _account_manager_get_instance();
1607 if (acc_mgr == NULL)
1609 _ERR("g_bus_get_sync failed");
1610 return ACCOUNT_ERROR_PERMISSION_DENIED;
1613 GVariant* account_list_variant = NULL;
1614 bool is_success = account_manager_call_account_query_account_by_capability_type_sync(acc_mgr, account_db_path, capability_type, &account_list_variant, NULL, &error);
1616 int error_code = _account_get_error_code(is_success, error);
1617 if (error_code != ACCOUNT_ERROR_NONE)
1622 _INFO("before unmarshal_account_list");
1623 GSList* account_list = unmarshal_account_list(account_list_variant);
1624 _INFO("after unmarshal_account_list");
1625 if (account_list == NULL)
1627 return ACCOUNT_ERROR_NO_DATA;
1632 for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1634 _INFO("iterating received account_list");
1635 account_s *account = NULL;
1636 account = (account_s*)iter->data;
1638 if (callback((account_h)account, user_data) == false)
1640 _INFO("application callback requested to discontinue.");
1644 _INFO("account_query_account_by_capability end");
1645 return ACCOUNT_ERROR_NONE;
1648 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1650 _INFO("account_query_capability_by_account_id starting");
1651 char* account_db_path = ACCOUNT_DB_NAME;
1653 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1654 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1656 GError *error = NULL;
1657 AccountManager* acc_mgr = _account_manager_get_instance();
1658 if (acc_mgr == NULL)
1660 _ERR("g_bus_get_sync failed");
1661 return ACCOUNT_ERROR_PERMISSION_DENIED;
1664 GVariant* capability_list_variant = NULL;
1665 bool is_success = account_manager_call_account_query_capability_by_account_id_sync(acc_mgr, account_db_path, account_id, &capability_list_variant, NULL, &error);
1667 int error_code = _account_get_error_code(is_success, error);
1668 if (error_code != ACCOUNT_ERROR_NONE)
1673 _INFO("before unmarshal_capability_list");
1674 GSList* capability_list = unmarshal_capability_list(capability_list_variant);
1675 _INFO("after unmarshal_capability_list");
1676 if (capability_list == NULL)
1678 return ACCOUNT_ERROR_NO_DATA;
1683 for (iter = capability_list; iter != NULL; iter = g_slist_next(iter))
1685 _INFO("iterating received account_list");
1686 account_capability_s *capability = NULL;
1687 capability = (account_capability_s*)iter->data;
1689 if (callback(capability->type, capability->value, user_data) == false)
1691 _INFO("application callback requested to discontinue.");
1696 _INFO("account_query_capability_by_account_id end");
1697 return ACCOUNT_ERROR_NONE;
1700 static int _account_get_total_count(int *count, bool include_hidden)
1702 _INFO("account_get_total_count_from_db starting");
1703 char* account_db_path = ACCOUNT_DB_NAME;
1707 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1708 return ACCOUNT_ERROR_INVALID_PARAMETER;
1711 GError *error = NULL;
1715 _INFO("Invalid input");
1719 AccountManager* acc_mgr = _account_manager_get_instance();
1720 if (acc_mgr == NULL)
1722 _ERR("g_bus_get_sync failed");
1723 return ACCOUNT_ERROR_PERMISSION_DENIED;
1726 int temp_count = -1;
1727 bool is_success = account_manager_call_account_get_total_count_from_db_sync(acc_mgr, account_db_path, include_hidden, &temp_count, NULL, &error);
1728 int error_code = _account_get_error_code(is_success, error);
1729 if (error_code != ACCOUNT_ERROR_NONE)
1734 *count = temp_count;
1735 _INFO("account_get_total_count_from_db end");
1736 return ACCOUNT_ERROR_NONE;
1739 ACCOUNT_API int account_get_total_count_from_db(int *count)
1741 _INFO("account_get_total_count_from_db starting");
1743 return _account_get_total_count(count, true);
1746 ACCOUNT_API int account_get_total_count_from_db_ex(int *count)
1748 _INFO("account_get_total_count_from_db_ex starting");
1750 return _account_get_total_count(count, false);
1753 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1755 _INFO("account_update_sync_status_by_id starting");
1756 char* account_db_path = ACCOUNT_DB_NAME;
1758 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1759 if ( ((int)sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
1760 ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
1761 return ACCOUNT_ERROR_INVALID_PARAMETER;
1764 GError *error = NULL;
1766 AccountManager* acc_mgr = _account_manager_get_instance();
1767 if (acc_mgr == NULL)
1769 _ERR("g_bus_get_sync failed");
1770 return ACCOUNT_ERROR_PERMISSION_DENIED;
1773 bool is_success = account_manager_call_account_update_sync_status_by_id_sync(acc_mgr, account_db_path, account_db_id, sync_status, NULL, &error);
1775 return _account_get_error_code(is_success, error);
1778 static int _account_type_free_label_items(label_s *data)
1780 _ACCOUNT_FREE(data->app_id);
1781 _ACCOUNT_FREE(data->label);
1782 _ACCOUNT_FREE(data->locale);
1784 return ACCOUNT_ERROR_NONE;
1787 static int _account_type_gslist_free(GSList* list)
1789 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
1793 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
1794 label_s *label_data = (label_s*)iter->data;
1795 _account_type_free_label_items(label_data);
1796 _ACCOUNT_FREE(label_data);
1802 return ACCOUNT_ERROR_NONE;
1805 static int _account_type_item_free(account_type_s *data)
1807 _ACCOUNT_FREE(data->app_id);
1808 _ACCOUNT_FREE(data->service_provider_id);
1809 _ACCOUNT_FREE(data->icon_path);
1810 _ACCOUNT_FREE(data->small_icon_path);
1812 return ACCOUNT_ERROR_NONE;
1815 static int _account_type_glist_free(GList* list)
1817 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Glist is NULL"));
1821 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
1822 account_type_s *account_type_record = (account_type_s*)iter->data;
1823 _account_type_item_free(account_type_record);
1824 _ACCOUNT_FREE(account_type_record);
1830 return ACCOUNT_ERROR_NONE;
1833 static int _account_type_free_account_type_items(account_type_s *data)
1835 _account_type_item_free(data);
1837 _account_type_gslist_free(data->label_list);
1838 _account_type_glist_free(data->account_type_list);
1840 return ACCOUNT_ERROR_NONE;
1843 ACCOUNT_API int account_type_create(account_type_h *account_type)
1845 if (!account_type) {
1846 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1847 return ACCOUNT_ERROR_INVALID_PARAMETER;
1850 account_type_s *data = (account_type_s*)malloc(sizeof(account_type_s));
1854 ACCOUNT_ERROR("Memory Allocation Failed");
1855 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1858 ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1861 data->app_id = NULL;
1862 data->service_provider_id = NULL;
1863 data->icon_path = NULL;
1864 data->small_icon_path = NULL;
1865 data->multiple_account_support = false;
1866 data->label_list = NULL;
1867 data->account_type_list = NULL;
1868 data->provider_feature_list = NULL;
1870 *account_type = (account_type_h)data;
1872 return ACCOUNT_ERROR_NONE;
1875 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1877 _INFO("account_type_destroy");
1879 account_type_s *data = (account_type_s*)account_type;
1883 _ERR("Account type handle is null!");
1884 return ACCOUNT_ERROR_INVALID_PARAMETER;
1887 _account_type_free_account_type_items(data);
1888 _ACCOUNT_FREE(data);
1890 return ACCOUNT_ERROR_NONE;
1893 ACCOUNT_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1895 return ACCOUNT_ERROR_NONE;
1898 ACCOUNT_API int account_type_set_app_id_internal(account_type_h account_type, const char *app_id)
1900 if (!account_type) {
1901 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1902 return ACCOUNT_ERROR_INVALID_PARAMETER;
1906 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1907 return ACCOUNT_ERROR_INVALID_PARAMETER;
1910 account_type_s *data = (account_type_s*)account_type;
1912 _ACCOUNT_FREE(data->app_id);
1913 data->app_id = _account_get_text(app_id);
1915 return ACCOUNT_ERROR_NONE;
1918 ACCOUNT_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1920 return ACCOUNT_ERROR_NONE;
1923 ACCOUNT_API int account_type_set_service_provider_id_internal(account_type_h account_type, const char *service_provider_id)
1925 if (!account_type) {
1926 return ACCOUNT_ERROR_INVALID_PARAMETER;
1929 if (!service_provider_id) {
1930 return ACCOUNT_ERROR_INVALID_PARAMETER;
1933 account_type_s *data = (account_type_s*)account_type;
1935 _ACCOUNT_FREE(data->service_provider_id);
1936 data->service_provider_id = _account_get_text(service_provider_id);
1938 return ACCOUNT_ERROR_NONE;
1941 ACCOUNT_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1943 return ACCOUNT_ERROR_NONE;
1946 ACCOUNT_API int account_type_set_icon_path_internal(account_type_h account_type, const char *icon_path)
1948 if (!account_type) {
1949 return ACCOUNT_ERROR_INVALID_PARAMETER;
1953 return ACCOUNT_ERROR_INVALID_PARAMETER;
1956 account_type_s *data = (account_type_s*)account_type;
1958 _ACCOUNT_FREE(data->icon_path);
1959 data->icon_path = _account_get_text(icon_path);
1961 return ACCOUNT_ERROR_NONE;
1964 ACCOUNT_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
1966 return ACCOUNT_ERROR_NONE;
1969 ACCOUNT_API int account_type_set_small_icon_path_internal(account_type_h account_type, const char *small_icon_path)
1971 if (!account_type) {
1972 return ACCOUNT_ERROR_INVALID_PARAMETER;
1975 if (!small_icon_path) {
1976 return ACCOUNT_ERROR_INVALID_PARAMETER;
1979 account_type_s *data = (account_type_s*)account_type;
1981 _ACCOUNT_FREE(data->small_icon_path);
1982 data->small_icon_path = _account_get_text(small_icon_path);
1984 return ACCOUNT_ERROR_NONE;
1987 ACCOUNT_API int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
1989 return ACCOUNT_ERROR_NONE;
1992 ACCOUNT_API int account_type_set_multiple_account_support_internal(account_type_h account_type, const bool multiple_account_support)
1994 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1996 account_type_s *data = (account_type_s*)account_type;
1998 data->multiple_account_support = multiple_account_support;
2000 return ACCOUNT_ERROR_NONE;
2003 ACCOUNT_API int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
2005 return ACCOUNT_ERROR_NONE;
2008 ACCOUNT_API int account_type_set_label_internal(account_type_h account_type, const char* label, const char* locale)
2010 if (!account_type) {
2011 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
2012 return ACCOUNT_ERROR_INVALID_PARAMETER;
2015 if(!label || !locale) {
2016 return ACCOUNT_ERROR_INVALID_PARAMETER;
2019 account_type_s *data = (account_type_s*)account_type;
2020 label_s *label_data = (label_s*)malloc(sizeof(label_s));
2022 if (label_data == NULL) {
2023 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2025 ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
2027 label_data->label = _account_get_text(label);
2028 label_data->locale = _account_get_text(locale);
2030 data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
2032 return ACCOUNT_ERROR_NONE;
2035 ACCOUNT_API int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature)
2037 return ACCOUNT_ERROR_NONE;
2040 ACCOUNT_API int account_type_set_provider_feature_internal(account_type_h account_type, const char* provider_feature)
2042 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
2043 ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
2045 account_type_s *data = (account_type_s*)account_type;
2047 GSList *iter = NULL;
2048 bool b_is_new = TRUE;
2050 for(iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2051 provider_feature_s *feature_data = NULL;
2052 feature_data = (provider_feature_s*)iter->data;
2054 if(!strcmp(feature_data->key, provider_feature)) {
2061 provider_feature_s* feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
2063 if (feature_data == NULL)
2064 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2065 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
2067 feature_data->key = _account_get_text(provider_feature);
2068 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
2071 return ACCOUNT_ERROR_NONE;
2074 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
2076 _INFO("account_type_query_provider_feature_by_app_id start");
2077 char* account_db_path = ACCOUNT_DB_NAME;
2079 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2080 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2082 GError *error = NULL;
2083 gint error_code = ACCOUNT_ERROR_NONE;
2085 AccountManager* acc_mgr = _account_manager_get_instance();
2086 if (acc_mgr == NULL)
2088 _ERR("g_bus_get_sync failed");
2089 return ACCOUNT_ERROR_PERMISSION_DENIED;
2092 GVariant* feature_list_variant = NULL;
2093 bool is_success = account_manager_call_account_type_query_provider_feature_by_app_id_sync(acc_mgr, account_db_path, app_id, &feature_list_variant, NULL, &error);
2095 _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
2099 error_code = error->code;
2100 _ERR("Account IPC call returned error[%d]", error_code);
2104 GSList* provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
2105 if (provider_feature_list == NULL)
2107 error_code = ACCOUNT_ERROR_NO_DATA;
2108 _ERR("[%d]", error_code);
2113 for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2114 provider_feature_s *feature_data = NULL;
2116 feature_data = (provider_feature_s*)iter->data;
2118 if(callback(feature_data->app_id, feature_data->key, user_data)!=TRUE) {
2119 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2120 return ACCOUNT_ERROR_NONE;
2124 _INFO("account_type_query_provider_feature_by_app_id end");
2128 ACCOUNT_API bool account_type_query_supported_feature(const char* app_id, const char* capability)
2130 _INFO("account_type_query_supported_feature start");
2131 char* account_db_path = ACCOUNT_DB_NAME;
2133 if (app_id == NULL || capability == NULL)
2135 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2139 int is_supported = 0;
2140 GError *error = NULL;
2141 gint ret = ACCOUNT_ERROR_NONE;
2143 AccountManager* acc_mgr = _account_manager_get_instance();
2144 if (acc_mgr == NULL)
2146 _ERR("g_bus_get_sync failed");
2147 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2151 bool is_success = account_manager_call_account_type_query_supported_feature_sync(acc_mgr, account_db_path, app_id, capability, &is_supported, NULL, &error);
2153 _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2158 _ERR("Account IPC call returned error[%d]", ret);
2159 set_last_result(ret);
2163 set_last_result(ACCOUNT_ERROR_NONE);
2164 _INFO("account_type_query_supported_feature end");
2165 return is_supported;
2168 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2170 if (!account_type) {
2171 return ACCOUNT_ERROR_INVALID_PARAMETER;
2175 return ACCOUNT_ERROR_INVALID_PARAMETER;
2178 account_type_s *data = (account_type_s*)account_type;
2181 *app_id = _account_get_text(data->app_id);
2183 return ACCOUNT_ERROR_NONE;
2186 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2188 if (!account_type) {
2189 return ACCOUNT_ERROR_INVALID_PARAMETER;
2192 if (!service_provider_id) {
2193 return ACCOUNT_ERROR_INVALID_PARAMETER;
2196 account_type_s *data = (account_type_s*)account_type;
2198 (*service_provider_id) = NULL;
2199 *service_provider_id = _account_get_text(data->service_provider_id);
2201 return ACCOUNT_ERROR_NONE;
2204 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2206 if (!account_type) {
2207 return ACCOUNT_ERROR_INVALID_PARAMETER;
2211 return ACCOUNT_ERROR_INVALID_PARAMETER;
2214 account_type_s *data = (account_type_s*)account_type;
2216 (*icon_path) = NULL;
2217 *icon_path = _account_get_text(data->icon_path);
2219 return ACCOUNT_ERROR_NONE;
2222 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2224 if (!account_type) {
2225 return ACCOUNT_ERROR_INVALID_PARAMETER;
2228 if (!small_icon_path) {
2229 return ACCOUNT_ERROR_INVALID_PARAMETER;
2232 account_type_s *data = (account_type_s*)account_type;
2234 (*small_icon_path) = NULL;
2235 *small_icon_path = _account_get_text(data->small_icon_path);
2237 return ACCOUNT_ERROR_NONE;
2240 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2242 if (!account_type) {
2243 return ACCOUNT_ERROR_INVALID_PARAMETER;
2245 if (!multiple_account_support) {
2246 return ACCOUNT_ERROR_INVALID_PARAMETER;
2249 account_type_s *data = (account_type_s*)account_type;
2251 *multiple_account_support = data->multiple_account_support;
2253 return ACCOUNT_ERROR_NONE;
2256 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void* user_data)
2258 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2259 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2262 account_type_s *data = (account_type_s*)account_type;
2264 for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2265 provider_feature_s *feature_data = NULL;
2267 feature_data = (provider_feature_s*)iter->data;
2269 if(callback(feature_data->app_id, feature_data->key, user_data)!=TRUE) {
2270 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2271 return ACCOUNT_ERROR_NONE;
2275 return ACCOUNT_ERROR_NONE;
2278 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char* locale, char** label)
2280 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2281 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
2284 account_type_s *data = (account_type_s*)account_type;
2286 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2287 label_s *label_data = NULL;
2289 label_data = (label_s*)iter->data;
2293 if(!strcmp(locale, label_data->locale)) {
2294 *label = _account_get_text(label_data->label);
2295 return ACCOUNT_ERROR_NONE;
2297 gchar** tokens = g_strsplit(locale, "-", 2);
2298 if(tokens != NULL) {
2299 if((char*)(tokens[1]) != NULL) {
2300 char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
2301 if(upper_token != NULL) {
2302 char* converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
2303 if(!strcmp(converted_locale, label_data->locale)) {
2304 _ACCOUNT_FREE(converted_locale);
2305 _ACCOUNT_FREE(upper_token);
2307 *label = _account_get_text(label_data->label);
2308 return ACCOUNT_ERROR_NONE;
2310 _ACCOUNT_FREE(converted_locale);
2312 _ACCOUNT_FREE(upper_token);
2318 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2321 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2323 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
2324 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
2327 account_type_s *data = (account_type_s*)account_type;
2329 for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2330 label_s *label_data = NULL;
2332 label_data = (label_s*)iter->data;
2334 if(callback(label_data->app_id, label_data->label, label_data->locale, user_data)!=TRUE) {
2335 ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
2336 return ACCOUNT_ERROR_NONE;
2340 return ACCOUNT_ERROR_NONE;
2343 ACCOUNT_API int account_type_insert_to_db(account_type_h account_type, int* account_type_id)
2345 return ACCOUNT_ERROR_NONE;
2348 ACCOUNT_API int account_type_insert_to_db_internal(account_type_h account_type, int* account_type_id)
2350 _INFO("account_type_insert_to_db starting");
2351 char* account_db_path = ACCOUNT_DB_NAME;
2353 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
2354 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
2356 GError *error = NULL;
2358 AccountManager* acc_mgr = _account_manager_get_instance();
2359 if (acc_mgr == NULL)
2361 _ERR("g_bus_get_sync failed");
2362 return ACCOUNT_ERROR_PERMISSION_DENIED;
2366 GVariant* account_type_serialized = marshal_account_type((account_type_s*) account_type);
2367 bool is_success = account_manager_call_account_type_add_sync(acc_mgr, account_db_path, account_type_serialized, &db_id, NULL, &error);
2369 int ret = _account_get_error_code(is_success, error);
2370 if (ret != ACCOUNT_ERROR_NONE)
2375 _INFO("account_type_insert_to_db end id=[%d]", db_id);
2377 *account_type_id = db_id;
2379 account_type_s* account_type_data = (account_type_s*)account_type;
2380 account_type_data->id = db_id;
2382 return ACCOUNT_ERROR_NONE;
2385 ACCOUNT_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char* app_id)
2387 return ACCOUNT_ERROR_NONE;
2390 ACCOUNT_API int account_type_update_to_db_by_app_id_internal(const account_type_h account_type, const char* app_id)
2392 _INFO("account_type_update_to_db_by_app_id starting");
2393 char* account_db_path = ACCOUNT_DB_NAME;
2395 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
2396 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2398 GError *error = NULL;
2400 AccountManager* acc_mgr = _account_manager_get_instance();
2401 if (acc_mgr == NULL)
2403 _ERR("g_bus_get_sync failed");
2404 return ACCOUNT_ERROR_PERMISSION_DENIED;
2407 GVariant* account_type_variant = marshal_account_type((account_type_s*) account_type);
2408 if (account_type_variant == NULL)
2410 _ERR("Failed to serialize");
2411 return ACCOUNT_ERROR_INVALID_PARAMETER;
2414 bool is_success = account_manager_call_account_type_update_to_db_by_app_id_sync(acc_mgr, account_db_path, account_type_variant, app_id, NULL, &error);
2416 return _account_get_error_code(is_success, error);
2419 ACCOUNT_API int account_type_delete_by_app_id(const char* app_id)
2421 return ACCOUNT_ERROR_NONE;
2424 ACCOUNT_API int account_type_delete_by_app_id_internal(const char* app_id)
2426 _INFO("account_type_delete_by_app_id starting");
2427 char* account_db_path = ACCOUNT_DB_NAME;
2429 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2431 GError *error = NULL;
2433 AccountManager* acc_mgr = _account_manager_get_instance();
2434 if (acc_mgr == NULL)
2436 _ERR("g_bus_get_sync failed");
2437 return ACCOUNT_ERROR_PERMISSION_DENIED;
2440 bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, account_db_path, app_id, NULL, &error);
2442 return _account_get_error_code(is_success, error);
2445 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
2447 _INFO("account_type_query_label_by_app_id starting");
2448 char* account_db_path = ACCOUNT_DB_NAME;
2450 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2451 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2453 GError *error = NULL;
2455 AccountManager* acc_mgr = _account_manager_get_instance();
2456 if (acc_mgr == NULL)
2458 _ERR("g_bus_get_sync failed");
2459 return ACCOUNT_ERROR_PERMISSION_DENIED;
2462 GVariant* label_list_variant = NULL;
2463 bool is_success = account_manager_call_account_type_query_label_by_app_id_sync(acc_mgr, account_db_path, app_id, &label_list_variant, NULL, &error);
2465 int ret = _account_get_error_code(is_success, error);
2466 if (ret != ACCOUNT_ERROR_NONE)
2471 _INFO("before variant_to_label_list");
2472 GSList* label_list = variant_to_label_list (label_list_variant);
2473 _INFO("after variant_to_label_list");
2474 if (label_list == NULL)
2476 return ACCOUNT_ERROR_NO_DATA;
2481 for (iter = label_list; iter != NULL; iter = g_slist_next(iter))
2483 _INFO("iterating received account_list");
2484 label_s *label_record = NULL;
2485 label_record = (label_s*)iter->data;
2487 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false)
2489 _INFO("application callback requested to discontinue.");
2494 _INFO("account_type_query_label_by_app_id end");
2495 return ACCOUNT_ERROR_NONE;
2498 ACCOUNT_API int account_type_query_by_app_id(const char* app_id, account_type_h *account_type)
2500 _INFO("account_type_query_by_app_id starting");
2501 char* account_db_path = ACCOUNT_DB_NAME;
2503 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2504 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE'S POINTER IS NULL"));
2505 ACCOUNT_RETURN_VAL((*account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE IS NULL"));
2507 GError *error = NULL;
2509 AccountManager* acc_mgr = _account_manager_get_instance();
2510 if (acc_mgr == NULL)
2512 _ERR("g_bus_get_sync failed");
2513 return ACCOUNT_ERROR_PERMISSION_DENIED;
2516 GVariant* account_type_variant = NULL;
2517 account_type_s *in_data = (account_type_s*) (*account_type);
2519 bool is_success = account_manager_call_account_type_query_by_app_id_sync(acc_mgr, account_db_path, app_id, &account_type_variant, NULL, &error);
2521 int ret = _account_get_error_code(is_success, error);
2522 if (ret != ACCOUNT_ERROR_NONE)
2527 _INFO("before umarshal_account_type");
2528 account_type_s* received_account_type = umarshal_account_type (account_type_variant);
2529 _INFO("after umarshal_account_type");
2530 ACCOUNT_RETURN_VAL((received_account_type != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("INVALID DATA RECEIVED FROM SVC"));
2532 in_data->id = received_account_type->id;
2533 in_data->app_id = received_account_type->app_id;
2534 in_data->service_provider_id = received_account_type->service_provider_id;
2535 in_data->icon_path = received_account_type->icon_path;
2536 in_data->small_icon_path = received_account_type->small_icon_path;
2537 in_data->multiple_account_support = received_account_type->multiple_account_support;
2538 in_data->label_list = received_account_type->label_list;
2539 in_data->account_type_list = received_account_type->account_type_list;
2540 in_data->provider_feature_list = received_account_type->provider_feature_list;
2542 _INFO("account_type_query_by_app_id end");
2543 return ACCOUNT_ERROR_NONE;
2546 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2548 _INFO("account_type_foreach_account_type_from_db starting");
2549 char* account_db_path = ACCOUNT_DB_NAME;
2551 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2553 GError *error = NULL;
2555 AccountManager* acc_mgr = _account_manager_get_instance();
2556 if (acc_mgr == NULL)
2558 _ERR("g_bus_get_sync failed");
2559 return ACCOUNT_ERROR_PERMISSION_DENIED;
2562 GVariant* account_type_list_variant = NULL;
2563 _INFO("before account_type_query_all_sync()");
2564 bool is_success = account_manager_call_account_type_query_all_sync(acc_mgr, account_db_path, &account_type_list_variant, NULL, &error);
2566 _INFO("after account_type_query_all_sync()");
2567 int ret = _account_get_error_code(is_success, error);
2568 if (ret != ACCOUNT_ERROR_NONE)
2573 _INFO("before unmarshal_account_type_list");
2574 GSList* account_type_list = unmarshal_account_type_list(account_type_list_variant);
2575 _INFO("after unmarshal_account_type_list");
2576 if (account_type_list == NULL)
2578 return ACCOUNT_ERROR_NO_DATA;
2583 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2585 _INFO("iterating received account_list");
2586 account_type_s *account_type = NULL;
2587 account_type = (account_type_s*)iter->data;
2589 if (callback((account_type_h)account_type, user_data) == false)
2591 _INFO("application callback requested to discontinue.");
2595 _INFO("account_foreach_account_from_db end");
2596 return ACCOUNT_ERROR_NONE;
2599 ACCOUNT_API int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label)
2601 _INFO("account_type_query_label_by_locale starting");
2602 char* account_db_path = ACCOUNT_DB_NAME;
2604 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
2605 ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO LOCALE"));
2606 ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
2608 GError *error = NULL;
2610 AccountManager* acc_mgr = _account_manager_get_instance();
2611 if (acc_mgr == NULL)
2613 _ERR("g_bus_get_sync failed");
2614 return ACCOUNT_ERROR_PERMISSION_DENIED;
2617 char* label_temp = NULL;
2618 _INFO("before account_type_query_label_by_locale_sync()");
2619 bool is_success = account_manager_call_account_type_query_label_by_locale_sync(acc_mgr, account_db_path, app_id, locale, &label_temp, NULL, &error);
2621 _INFO("after account_type_query_label_by_locale_sync() : is_success=%d", is_success);
2622 int ret = _account_get_error_code(is_success, error);
2623 if (ret != ACCOUNT_ERROR_NONE)
2628 if (label_temp == NULL)
2630 return ACCOUNT_ERROR_NO_DATA;
2633 *label = _account_get_text(label_temp);
2634 _INFO("account_type_query_label_by_locale end");
2635 return ACCOUNT_ERROR_NONE;
2639 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char* key, void* user_data)
2641 _INFO("account_type_query_by_provider_feature starting");
2642 char* account_db_path = ACCOUNT_DB_NAME;
2644 ACCOUNT_RETURN_VAL((key != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
2645 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2647 GError *error = NULL;
2649 AccountManager* acc_mgr = _account_manager_get_instance();
2650 if (acc_mgr == NULL)
2652 _ERR("g_bus_get_sync failed");
2653 return ACCOUNT_ERROR_PERMISSION_DENIED;
2656 GVariant* account_type_list_variant = NULL;
2657 bool is_success = account_manager_call_account_type_query_by_provider_feature_sync(acc_mgr, account_db_path, key, &account_type_list_variant, NULL, &error);
2659 int ret = _account_get_error_code(is_success, error);
2660 if (ret != ACCOUNT_ERROR_NONE)
2665 _INFO("before unmarshal_account_type_list");
2666 GSList* account_type_list = unmarshal_account_type_list(account_type_list_variant);
2667 _INFO("after unmarshal_account_type_list");
2668 if (account_type_list == NULL)
2670 return ACCOUNT_ERROR_NO_DATA;
2675 for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2677 _INFO("iterating received account_type_list");
2678 account_type_s *account_type = NULL;
2679 account_type = (account_type_s*)iter->data;
2681 if (callback((account_type_h)account_type, user_data) == false)
2683 _INFO("Application callback requested not to continue");
2688 _INFO("account_type_query_by_provider_feature end");
2689 return ACCOUNT_ERROR_NONE;
2692 ACCOUNT_API int account_type_query_app_id_exist(const char* app_id)
2694 _INFO("account_type_query_app_id_exist starting");
2695 char* account_db_path = ACCOUNT_DB_NAME;
2697 ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2699 GError *error = NULL;
2701 AccountManager* acc_mgr = _account_manager_get_instance();
2702 if (acc_mgr == NULL)
2704 _ERR("g_bus_get_sync failed");
2705 return ACCOUNT_ERROR_PERMISSION_DENIED;
2708 bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, account_db_path, app_id, NULL, &error);
2710 return _account_get_error_code(is_success, error);
2714 static void _account_subscribe_vconf_callback(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;
2722 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2727 ACCOUNT_ERROR("user data required\n");
2731 if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2733 vconf_key = vconf_keynode_get_str(key);
2735 if( vconf_key == NULL){
2736 ACCOUNT_ERROR("vconf key is NULL.\n");
2739 msg = strdup(vconf_key);
2741 char* event_type = NULL;
2745 event_type = strtok_r(msg, ":", &ptr);
2746 id = strtok_r(NULL, ":", &ptr);
2748 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2750 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2752 account_id = atoi(id);
2754 if(tmp->account_subscription_callback)
2755 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2762 ACCOUNT_API int account_subscribe_create(account_subscribe_h* account_subscribe)
2764 if (!account_subscribe) {
2765 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2766 return ACCOUNT_ERROR_INVALID_PARAMETER;
2769 account_subscribe_s *data = (account_subscribe_s*)calloc(1,sizeof(account_subscribe_s));
2772 ACCOUNT_FATAL("OUT OF MEMORY\n");
2773 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2776 *account_subscribe = (account_subscribe_h)data;
2778 return ACCOUNT_ERROR_NONE;
2781 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2783 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2785 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2787 tmp->account_subscription_callback = callback;
2788 tmp->user_data = user_data;
2791 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2792 (vconf_callback_fn)_account_subscribe_vconf_callback,
2795 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2797 if(ret != VCONF_OK) {
2798 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2799 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2802 return ACCOUNT_ERROR_NONE;
2805 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2807 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2809 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2813 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2814 (vconf_callback_fn)_account_subscribe_vconf_callback) != 0) {
2815 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2816 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2819 return ACCOUNT_ERROR_NONE;
2822 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2824 account_subscribe_s* tmp = (account_subscribe_s*)user_data;
2825 char *msg = NULL, *vconf_key = NULL;
2826 char event_msg[256] ={0, };
2827 int account_id = -1;
2830 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2835 ACCOUNT_ERROR("user data required\n");
2839 if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2841 vconf_key = vconf_keynode_get_str(key);
2843 if( vconf_key == NULL){
2844 ACCOUNT_ERROR("vconf key is NULL.\n");
2847 msg = strdup(vconf_key);
2849 char* event_type = NULL;
2853 event_type = strtok_r(msg, ":", &ptr);
2854 id = strtok_r(NULL, ":", &ptr);
2856 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2858 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2860 account_id = atoi(id);
2862 if(tmp->account_subscription_callback)
2863 tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2870 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2872 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2874 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2878 if (vconf_ignore_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2879 (vconf_callback_fn)_account_subscribe_vconf_callback_ex) != 0) {
2880 ACCOUNT_ERROR("Vconf Subscription Failed !!!!!\n");
2881 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2884 return ACCOUNT_ERROR_NONE;
2887 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2889 ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n", __FUNCTION__, __LINE__));
2891 account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2893 tmp->account_subscription_callback = callback;
2894 tmp->user_data = user_data;
2897 ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2898 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2901 ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2903 if(ret != VCONF_OK) {
2904 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2905 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2908 return ACCOUNT_ERROR_NONE;