merge from 2.4
[platform/core/api/libaccount-service.git] / src / account.c
index b22d3c2..d0dde3b 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <dbg.h>
 #include <account-private.h>
+#include <account_free.h>
 #include <account_ipc_marshal.h>
 #include <account-mgr-stub.h>
 
 
 static AccountManager *_acc_mgr = NULL;
 
-static char *_account_get_text(const char *text_data);
-static int _account_gslist_free(GSList* list);
-static int _account_glist_free(GList* list);
-
-static int _account_free_capability_items(account_capability_s *data)
-{
-       if(!data) {
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       _ACCOUNT_FREE(data->type);
-       _ACCOUNT_FREE(data->package_name);
-       _ACCOUNT_FREE(data->user_name);
-
-       return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_free_custom_items(account_custom_s *data)
-{
-       if(!data) {
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       _ACCOUNT_FREE(data->app_id);
-       _ACCOUNT_FREE(data->key);
-       _ACCOUNT_FREE(data->value);
-
-       return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_capability_gslist_free(GSList* list)
-{
-       if(!list){
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       GSList* iter;
-
-       for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
-               account_capability_s *capability_data = (account_capability_s*)iter->data;
-               _account_free_capability_items(capability_data);
-               _ACCOUNT_FREE(capability_data);
-       }
-
-       g_slist_free(list);
-       list = NULL;
-
-       return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_custom_gslist_free(GSList* list)
-{
-       if(!list){
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       GSList* iter;
-
-       for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
-               account_custom_s *custom_data = (account_custom_s*)iter->data;
-               _account_free_custom_items(custom_data);
-               _ACCOUNT_FREE(custom_data);
-       }
-
-       g_slist_free(list);
-       list = NULL;
-
-       return ACCOUNT_ERROR_NONE;
-}
-/*
-static int _account_list_free(GList* list)
-{
-       if(!list){
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       g_list_free_full(list, g_free);
-       list = NULL;
-
-       return ACCOUNT_ERROR_NONE;
-}
-*/
-
-static int _account_free_account_items(account_s *data)
-{
-       if(!data) {
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       _ACCOUNT_FREE(data->user_name);
-       _ACCOUNT_FREE(data->email_address);
-       _ACCOUNT_FREE(data->display_name);
-       _ACCOUNT_FREE(data->icon_path);
-       _ACCOUNT_FREE(data->source);
-       _ACCOUNT_FREE(data->package_name);
-       _ACCOUNT_FREE(data->domain_name);
-       _ACCOUNT_FREE(data->access_token);
-
-       int i;
-       for(i=0;i<USER_TXT_CNT;i++)
-               _ACCOUNT_FREE(data->user_data_txt[i]);
-
-       _account_capability_gslist_free(data->capablity_list);
-       _account_glist_free(data->account_list);
-       _account_custom_gslist_free(data->custom_list);
-
-       return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_gslist_free(GSList* list)
-{
-       if(!list){
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       GSList* iter;
-
-       for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
-               account_s *account_record = (account_s*)iter->data;
-               _account_free_account_items(account_record);
-               _ACCOUNT_FREE(account_record);
-       }
-
-       g_slist_free(list);
-       list = NULL;
-
-       return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_glist_free(GList* list)
-{
-       if(!list){
-               return ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-
-       GList* iter;
-
-       for (iter = list; iter != NULL; iter = g_list_next(iter)) {
-               account_s *account_record = (account_s*)iter->data;
-               _account_free_account_items(account_record);
-               _ACCOUNT_FREE(account_record);
-       }
-
-       g_list_free(list);
-       list = NULL;
-
-       return ACCOUNT_ERROR_NONE;
-}
-
 static char *_account_get_text(const char *text_data)
 {
        char *text_value = NULL;
@@ -308,9 +160,11 @@ static int _account_get_error_code(bool is_success, GError *error)
                                        if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0)
                                        {
                                                _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
+                                               g_free(remote_error);
                                                return _account_svc_errors[i].error_code;
                                        }
                                }
+                               g_free(remote_error);
                        }
                }
                //All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED
@@ -466,12 +320,12 @@ ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *packa
                error_code = _account_get_error_code(is_success, error);
                g_clear_error(&error);
                _ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
-               _account_gslist_free(account_list);
+               _account_gslist_account_free(account_list);
                return error_code;
        }
        g_clear_error(&error);
 
-       _account_gslist_free(account_list);
+       _account_gslist_account_free(account_list);
        return ACCOUNT_ERROR_NONE;
 }
 
@@ -739,8 +593,7 @@ ACCOUNT_API int account_destroy(account_h account)
 
        ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
 
-       _account_free_account_items(data);
-       _ACCOUNT_FREE(data);
+       _account_free_account_with_items(data);
 
        _INFO("account_destroy end");
        return ACCOUNT_ERROR_NONE;
@@ -1473,7 +1326,7 @@ ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_
                }
                _INFO("After one iteration callback");
        }
-       _account_gslist_free(account_list);
+       _account_gslist_account_free(account_list);
 
        _INFO("account_foreach_account_from_db end");
        return ACCOUNT_ERROR_NONE;
@@ -1518,8 +1371,7 @@ ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h
 
        account_s **input = (account_s **)account;
 
-       _account_free_account_items(*input);
-       _ACCOUNT_FREE(*input);
+       _account_free_account_with_items(*input);
 
        *input = account_data;
 
@@ -1577,7 +1429,7 @@ ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const ch
        }
        _INFO("account_query_account_by_user_name end");
 
-       _account_gslist_free(account_list);
+       _account_gslist_account_free(account_list);
        return ACCOUNT_ERROR_NONE;
 }
 
@@ -1629,7 +1481,7 @@ ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const
                        break;
                }
        }
-       _account_gslist_free(account_list);
+       _account_gslist_account_free(account_list);
        _INFO("account_query_account_by_package_name end");
        return ACCOUNT_ERROR_NONE;
 }
@@ -1687,7 +1539,7 @@ ACCOUNT_API int account_query_account_by_capability(account_cb callback, const c
                        break;
                }
        }
-       _account_gslist_free(account_list);
+       _account_gslist_account_free(account_list);
        _INFO("account_query_account_by_capability end");
        return ACCOUNT_ERROR_NONE;
 }
@@ -1740,7 +1592,7 @@ ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, co
                        break;
                }
        }
-       _account_gslist_free(account_list);
+       _account_gslist_account_free(account_list);
        _INFO("account_query_account_by_capability end");
        return ACCOUNT_ERROR_NONE;
 }
@@ -1794,7 +1646,7 @@ ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, i
                _INFO("");
        }
 
-       _account_capability_gslist_free(capability_list);
+        _account_gslist_capability_free(capability_list);
        _INFO("account_query_capability_by_account_id end");
        return ACCOUNT_ERROR_NONE;
 }
@@ -1880,6 +1732,7 @@ ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const accoun
        return error_code;
 }
 
+/*
 static int _account_type_free_label_items(label_s *data)
 {
        if(!data) {
@@ -1976,6 +1829,7 @@ static int _account_type_gslist_free(GSList* list)
 
        return ACCOUNT_ERROR_NONE;
 }
+*/
 
 /*
 static int _account_type_glist_free(GList* list)
@@ -2041,8 +1895,7 @@ ACCOUNT_API int account_type_destroy(account_type_h account_type)
                return ACCOUNT_ERROR_INVALID_PARAMETER;
        }
 
-       _account_type_free_account_type_items(data);
-       _ACCOUNT_FREE(data);
+       _account_type_free_account_type_with_items(data);
 
        return ACCOUNT_ERROR_NONE;
 }
@@ -2244,7 +2097,7 @@ ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_c
                }
        }
 
-       _account_type_provider_feature_gslist_free(provider_feature_list);
+       _account_type_gslist_feature_free(provider_feature_list);
        _INFO("account_type_query_provider_feature_by_app_id end");
        return error_code;
 }
@@ -2610,7 +2463,7 @@ ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, co
                _INFO("");
        }
 
-       _account_type_label_gslist_free(label_list);
+       _account_type_gslist_label_free(label_list);
        _INFO("account_type_query_label_by_app_id end");
        return ACCOUNT_ERROR_NONE;
 }
@@ -2713,7 +2566,7 @@ ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callba
                }
        }
 
-       _account_type_gslist_free(account_type_list);
+       _account_type_gslist_account_type_free(account_type_list);
        _INFO("account_type_foreach_account_type_from_db end");
        return ACCOUNT_ERROR_NONE;
 }
@@ -2811,7 +2664,7 @@ ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback,
                _INFO("");
        }
 
-       _account_type_gslist_free(account_type_list);
+       _account_type_gslist_account_type_free(account_type_list);
        _INFO("account_type_query_by_provider_feature end");
        return ACCOUNT_ERROR_NONE;
 }