remove dependency of security-server for applying cynara.
[platform/core/api/libaccount-service.git] / src / accounts / client / account.c
1 /*
2  *
3  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 #include <gio/gio.h>
20 #include <stdlib.h>
21 #include <glib.h>
22 #include <fcntl.h>
23 #include <glib/gprintf.h>
24 #ifdef G_OS_UNIX
25 #include <gio/gunixfdlist.h>
26 #include <unistd.h>
27 #endif
28 #include <vconf.h>
29
30 #include "account.h"
31 #include "account-error.h"
32 #include "account-private.h"
33 #include "account-types.h"
34 #include "account_ipc_marshal.h"
35
36 #include "dbg.h"
37 #include "account-mgr-stub.h"
38
39 #define ACCOUNT_DB_OPEN_READONLY 0
40 #define ACCOUNT_DB_OPEN_READWRITE 1
41
42 #define VCONF_OK 0
43
44 static AccountManager *_acc_mgr = NULL;
45
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);
49
50 static int _account_free_capability_items(account_capability_s *data)
51 {
52         _ACCOUNT_FREE(data->type);
53         _ACCOUNT_FREE(data->package_name);
54         _ACCOUNT_FREE(data->user_name);
55
56         return ACCOUNT_ERROR_NONE;
57 }
58
59 static int _account_custom_item_free(account_custom_s *data)
60 {
61         _ACCOUNT_FREE(data->app_id);
62         _ACCOUNT_FREE(data->key);
63         _ACCOUNT_FREE(data->value);
64
65         return ACCOUNT_ERROR_NONE;
66 }
67
68 static int _account_custom_gslist_free(GSList* list)
69 {
70         if(!list){
71                 return ACCOUNT_ERROR_INVALID_PARAMETER;
72         }
73
74         GSList* iter;
75
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);
80         }
81
82         g_slist_free(list);
83         list = NULL;
84
85         return ACCOUNT_ERROR_NONE;
86 }
87
88 static int _account_list_free(GList* list)
89 {
90         if(!list){
91                 return ACCOUNT_ERROR_INVALID_PARAMETER;
92         }
93
94         g_list_free_full(list, g_free);
95         list = NULL;
96
97         return ACCOUNT_ERROR_NONE;
98 }
99
100 static int _account_free_account_items(account_s *data)
101 {
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);
110
111         int i;
112         for(i=0;i<USER_TXT_CNT;i++)
113                 _ACCOUNT_FREE(data->user_data_txt[i]);
114
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);
120
121         return ACCOUNT_ERROR_NONE;
122 }
123
124 static int _account_gslist_free(GSList* list)
125 {
126         if(!list){
127                 return ACCOUNT_ERROR_INVALID_PARAMETER;
128         }
129
130         GSList* iter;
131
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);
136         }
137
138         g_slist_free(list);
139         list = NULL;
140
141         return ACCOUNT_ERROR_NONE;
142 }
143
144 static int _account_glist_free(GList* list)
145 {
146         if(!list){
147                 return ACCOUNT_ERROR_INVALID_PARAMETER;
148         }
149
150         GList* iter;
151
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);
156         }
157
158         g_list_free(list);
159         list = NULL;
160
161         return ACCOUNT_ERROR_NONE;
162 }
163
164 static char *_account_get_text(const char *text_data)
165 {
166         char *text_value = NULL;
167
168         if (text_data != NULL) {
169                 text_value = strdup(text_data);
170         }
171         return text_value;
172 }
173
174 //FIXME : add true singleton logic
175 AccountManager *
176 _account_manager_get_instance ()
177 {
178         _INFO("_account_manager_get_instance");
179         if (_acc_mgr != NULL)
180         {
181                 _INFO("instance already created.");
182                 return _acc_mgr;
183         }
184
185 #if !GLIB_CHECK_VERSION(2,35,0)
186         g_type_init();
187 #endif
188
189         GDBusConnection *connection = NULL;
190         GError *error = NULL;
191
192         connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
193
194         _INFO("after g_bus_get_sync");
195
196
197         /* Create the object */
198         _acc_mgr =
199                 account_manager_proxy_new_sync(connection,
200                                                                                  G_DBUS_PROXY_FLAGS_NONE,
201                                                                                  "org.tizen.account.manager",
202                                                                                 "/org/tizen/account/manager",
203                                                                                 NULL,
204                                                                                  &error);
205         _INFO("_account_manager_get_instance end");
206         return _acc_mgr;
207 }
208
209 GDBusErrorEntry _account_svc_errors[] =
210 {
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"},
229 };
230
231 static int _account_get_error_code(bool is_success, GError *error)
232 {
233         if (!is_success)
234         {
235                 _INFO("Received error Domain[%d] Message[%s] Code[%d]", error->domain, error->message, error->code);
236
237                 if (g_dbus_error_is_remote_error(error))
238                 {
239                         gchar *remote_error = g_dbus_error_get_remote_error(error);
240                         if (remote_error)
241                         {
242                                 _INFO("Remote error[%s]", remote_error);
243
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);
247                                 int i = 0;
248                                 for (i = 0; i < error_enum_count; i++)
249                                 {
250                                         if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0)
251                                         {
252                                                 _INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
253                                                 return _account_svc_errors[i].error_code;
254                                         }
255                                 }
256                         }
257                 }
258                 //All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED
259                 return ACCOUNT_ERROR_PERMISSION_DENIED;
260         }
261         return ACCOUNT_ERROR_NONE;
262 }
263
264 ACCOUNT_API int account_connect(void)
265 {
266         return ACCOUNT_ERROR_NONE;
267 }
268
269 ACCOUNT_API int account_connect_readonly(void)
270 {
271         return ACCOUNT_ERROR_NONE;
272 }
273
274 ACCOUNT_API int account_disconnect(void)
275 {
276         return ACCOUNT_ERROR_NONE;
277 }
278
279
280 ACCOUNT_API int account_insert_to_db(account_h account, int *account_db_id)
281 {
282         _INFO("1. account_insert_to_db start");
283         char* account_db_path = ACCOUNT_DB_NAME;
284
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"));
287
288         account_s *account_data = (account_s*) account;
289         int error_code = ACCOUNT_ERROR_NONE;
290         GError *error = NULL;
291
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.");
295
296         int db_id = -1;
297         GVariant* account_serialized = marshal_account(account_data);
298
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.");
302
303         *account_db_id = db_id;
304         account_data->id = db_id;
305
306         _INFO("4. account_insert_to_db end, added db id [%d] [%d] [%d]", db_id, *account_db_id, account_data->id);
307
308         return ACCOUNT_ERROR_NONE;
309
310 CATCH:
311         //Failed to get dbus.
312         _ERR("account_manager_call_account_add_sync()=[%d]", error_code);
313
314         return error_code;
315 }
316
317 ACCOUNT_API int account_delete_from_db_by_id(int account_db_id)
318 {
319         _INFO("1. account_delete_from_db_by_id starting [%d]", account_db_id);
320         char* account_db_path = ACCOUNT_DB_NAME;
321
322         ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
323
324         GError *error = NULL;
325
326         AccountManager* acc_mgr = _account_manager_get_instance();
327         if (acc_mgr == NULL)
328         {
329                 _ERR("g_bus_get_sync failed");
330                 return ACCOUNT_ERROR_PERMISSION_DENIED;
331         }
332
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);
336
337         if (!is_success)
338         {
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);
341         }
342
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);
345
346         if (!is_success)
347         {
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);
350         }
351
352         _INFO("4. Before account_delete_from_db_by_id end");
353         return ACCOUNT_ERROR_NONE;
354 }
355
356 ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *package_name)
357 {
358         _INFO("account_delete_from_db_by_user_name start");
359         char* account_db_path = ACCOUNT_DB_NAME;
360
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!"));
363
364
365         GError *error = NULL;
366
367         AccountManager* acc_mgr = _account_manager_get_instance();
368         if (acc_mgr == NULL)
369         {
370                 _ERR("g_bus_get_sync failed");
371                 return ACCOUNT_ERROR_PERMISSION_DENIED;
372         }
373
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);
376
377         int error_code = _account_get_error_code(is_success, error);
378         if (error_code != ACCOUNT_ERROR_NONE)
379         {
380                 _ERR("account_query_account_by_user_name error=[%d]", error_code);
381                 return error_code;
382         }
383
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)
388         {
389                 return ACCOUNT_ERROR_NO_DATA;
390         }
391
392         //TODO free account_list, account_list_variant
393
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);
395
396         if (!is_success)
397         {
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);
400         }
401
402         return ACCOUNT_ERROR_NONE;
403 }
404
405 int _account_delete_from_db_by_package_name(const char *package_name, bool permission)
406 {
407         _INFO("_account_delete_from_db_by_package_name starting permission opions = %d", permission);
408         char* account_db_path = ACCOUNT_DB_NAME;
409
410         ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
411
412         GError *error = NULL;
413
414         AccountManager* acc_mgr = _account_manager_get_instance();
415         if (acc_mgr == NULL)
416         {
417                 _ERR("g_bus_get_sync failed");
418                 return ACCOUNT_ERROR_PERMISSION_DENIED;
419         }
420
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);
424
425         int error_code = _account_get_error_code(is_success, error);
426         if (error_code != ACCOUNT_ERROR_NONE)
427         {
428                 return error_code;
429         }
430
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)
435         {
436                 return ACCOUNT_ERROR_NO_DATA;
437         }
438
439         is_success = account_manager_call_account_delete_from_db_by_package_name_sync(acc_mgr, account_db_path, package_name, permission, NULL, &error);
440
441         if (!is_success)
442         {
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);
445         }
446
447         return ACCOUNT_ERROR_NONE;
448 }
449
450 ACCOUNT_API int account_delete_from_db_by_package_name(const char *package_name)
451 {
452         _INFO("account_delete_from_db_by_package_name starting with permission");
453         return _account_delete_from_db_by_package_name(package_name, true);
454 }
455
456 ACCOUNT_API int account_delete_from_db_by_package_name_without_permission(const char *package_name)
457 {
458         _INFO("account_delete_from_db_by_package_name starting without permission");
459         return _account_delete_from_db_by_package_name(package_name, false);
460 }
461
462 ACCOUNT_API int account_update_to_db_by_id(account_h account, int account_id)
463 {
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;
467
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"));
470
471         GError *error = NULL;
472
473         AccountManager* acc_mgr = _account_manager_get_instance();
474         if (acc_mgr == NULL)
475         {
476                 _ERR("g_bus_get_sync failed");
477                 return ACCOUNT_ERROR_PERMISSION_DENIED;
478         }
479
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);
483
484         if (!is_success)
485         {
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);
488         }
489
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);
493
494         if (!is_success)
495         {
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);
498         }
499
500         _INFO("4. account_update_to_db_by_id end");
501         return ACCOUNT_ERROR_NONE;
502 }
503
504 ACCOUNT_API int account_update_to_db_by_id_ex(account_h account, int account_id)
505 {
506         int ret = -1;
507         ret = account_update_to_db_by_id(account, account_id);
508
509         return ret;
510 }
511
512 ACCOUNT_API int account_update_to_db_by_id_without_permission(account_h account, int account_id)
513 {
514         //First we will update account db
515         //Then we will update gSSO DB, if it fails then we will rollback account db updates
516
517         _INFO("account_update_to_db_by_id_without_permission start");
518         char* account_db_path = ACCOUNT_DB_NAME;
519
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"));
522
523         GError *error = NULL;
524
525         AccountManager* acc_mgr = _account_manager_get_instance();
526         if (acc_mgr == NULL)
527         {
528                 _ERR("g_bus_get_sync failed");
529                 return ACCOUNT_ERROR_PERMISSION_DENIED;
530         }
531
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);
535
536         if (!is_success)
537         {
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);
540         }
541
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)
546         {
547                 _ERR("Invalid input");
548                 return ACCOUNT_ERROR_INVALID_PARAMETER;
549         }
550
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);
553
554         _INFO("after call update() : is_success=%d", is_success);
555         if (!is_success)
556         {
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);
559         }
560
561         return ACCOUNT_ERROR_NONE;
562 }
563
564 ACCOUNT_API int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
565 {
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;
569
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"));
573
574         GError *error = NULL;
575
576         AccountManager* acc_mgr = _account_manager_get_instance();
577         if (acc_mgr == NULL)
578         {
579                 _ERR("g_bus_get_sync failed");
580                 return ACCOUNT_ERROR_PERMISSION_DENIED;
581         }
582
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);
586
587         if (!is_success)
588         {
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);
591         }
592
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);
595
596         if (!is_success)
597         {
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);
600         }
601
602         return ACCOUNT_ERROR_NONE;
603 }
604
605 ACCOUNT_API int account_create(account_h *account)
606 {
607         if (!account) {
608                 ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
609                 return ACCOUNT_ERROR_INVALID_PARAMETER;
610         }
611
612         account_s *data = (account_s*)malloc(sizeof(account_s));
613
614         if (data == NULL) {
615                 ACCOUNT_FATAL("Memory Allocation Failed");
616                 return ACCOUNT_ERROR_OUT_OF_MEMORY;
617         }
618         ACCOUNT_MEMSET(data, 0, sizeof(account_s));
619
620         /*Setting account as visible by default*/
621         data->secret = ACCOUNT_SECRECY_VISIBLE;
622
623         /*Setting account as not supporting sync by default*/
624         data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
625
626         data->auth_type = ACCOUNT_AUTH_TYPE_INVALID;
627
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;
633
634         *account = (account_h)data;
635
636         return ACCOUNT_ERROR_NONE;
637 }
638
639 ACCOUNT_API int account_destroy(account_h account)
640 {
641         account_s *data = (account_s*)account;
642
643         ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
644
645         _account_free_account_items(data);
646         _ACCOUNT_FREE(data);
647
648         return ACCOUNT_ERROR_NONE;
649 }
650
651 ACCOUNT_API int account_set_user_name(account_h account, const char *user_name)
652 {
653         if (!account) {
654                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
655                 return ACCOUNT_ERROR_INVALID_PARAMETER;
656         }
657
658         if (!user_name) {
659                 ACCOUNT_SLOGE("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
660                 return ACCOUNT_ERROR_INVALID_PARAMETER;
661         }
662
663         account_s *data = (account_s*)account;
664
665         _ACCOUNT_FREE(data->user_name);
666         data->user_name = _account_get_text(user_name);
667
668         return ACCOUNT_ERROR_NONE;
669 }
670
671 ACCOUNT_API int account_set_display_name(account_h account, const char *display_name)
672 {
673         if (!account) {
674                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
675                 return ACCOUNT_ERROR_INVALID_PARAMETER;
676         }
677
678         if (!display_name) {
679                 ACCOUNT_SLOGE("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
680                 return ACCOUNT_ERROR_INVALID_PARAMETER;
681         }
682
683         account_s *data = (account_s*)account;
684
685         _ACCOUNT_FREE(data->display_name);
686         data->display_name = _account_get_text(display_name);
687
688         return ACCOUNT_ERROR_NONE;
689 }
690
691 ACCOUNT_API int account_set_email_address(account_h account, const char *email_address)
692 {
693         if (!account) {
694                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
695                 return ACCOUNT_ERROR_INVALID_PARAMETER;
696         }
697
698         if (!email_address) {
699                 ACCOUNT_SLOGE("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
700                 return ACCOUNT_ERROR_INVALID_PARAMETER;
701         }
702
703         account_s *data = (account_s*)account;
704
705         _ACCOUNT_FREE(data->email_address);
706         data->email_address = _account_get_text(email_address);
707
708         return ACCOUNT_ERROR_NONE;
709 }
710
711 ACCOUNT_API int account_set_icon_path(account_h account, const char *icon_path)
712 {
713         if (!account) {
714                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
715                 return ACCOUNT_ERROR_INVALID_PARAMETER;
716         }
717
718         if (!icon_path) {
719                 ACCOUNT_SLOGE("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
720                 return ACCOUNT_ERROR_INVALID_PARAMETER;
721         }
722
723         account_s *data = (account_s*)account;
724
725         _ACCOUNT_FREE(data->icon_path);
726         data->icon_path = _account_get_text(icon_path);
727
728         return ACCOUNT_ERROR_NONE;
729 }
730
731 ACCOUNT_API int account_set_source(account_h account, const char *source)
732 {
733         if (!account) {
734                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
735                 return ACCOUNT_ERROR_INVALID_PARAMETER;
736         }
737
738         if (!source) {
739                 ACCOUNT_SLOGE("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
740                 return ACCOUNT_ERROR_INVALID_PARAMETER;
741         }
742         account_s *data = (account_s*)account;
743
744         _ACCOUNT_FREE(data->source);
745         data->source = _account_get_text(source);
746
747         return ACCOUNT_ERROR_NONE;
748 }
749
750 ACCOUNT_API int account_set_package_name(account_h account, const char *package_name)
751 {
752         if (!account) {
753                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
754                 return ACCOUNT_ERROR_INVALID_PARAMETER;
755         }
756
757         if (!package_name) {
758                 ACCOUNT_SLOGE("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
759                 return ACCOUNT_ERROR_INVALID_PARAMETER;
760         }
761
762         account_s *data = (account_s*)account;
763
764         _ACCOUNT_FREE(data->package_name);
765         data->package_name = _account_get_text(package_name);
766
767         return ACCOUNT_ERROR_NONE;
768 }
769
770 ACCOUNT_API int account_set_domain_name(account_h account, const char *domain_name)
771 {
772         if (!account) {
773                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
774                 return ACCOUNT_ERROR_INVALID_PARAMETER;
775         }
776
777         if (!domain_name) {
778                 ACCOUNT_SLOGE("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
779                 return ACCOUNT_ERROR_INVALID_PARAMETER;
780         }
781         account_s *data = (account_s*)account;
782
783         _ACCOUNT_FREE(data->domain_name);
784         data->domain_name = _account_get_text(domain_name);
785
786         return ACCOUNT_ERROR_NONE;
787 }
788
789 ACCOUNT_API int account_set_access_token(account_h account, const char *access_token)
790 {
791         if (!account) {
792                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
793                 return ACCOUNT_ERROR_INVALID_PARAMETER;
794         }
795
796         if (!access_token) {
797                 ACCOUNT_SLOGE("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
798                 return ACCOUNT_ERROR_INVALID_PARAMETER;
799         }
800
801         account_s *data = (account_s*)account;
802
803         _ACCOUNT_FREE(data->access_token);
804         data->access_token = _account_get_text(access_token);
805
806         return ACCOUNT_ERROR_NONE;
807 }
808
809 ACCOUNT_API int account_set_user_text(account_h account, int idx, const char *user_txt)
810 {
811         if (!account) {
812                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
813                 return ACCOUNT_ERROR_INVALID_PARAMETER;
814         }
815
816         if (!user_txt) {
817                 ACCOUNT_SLOGE("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
818                 return ACCOUNT_ERROR_INVALID_PARAMETER;
819         }
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;
823         }
824
825         account_s *data = (account_s*)account;
826
827         _ACCOUNT_FREE(data->user_data_txt[idx]);
828         data->user_data_txt[idx] = _account_get_text(user_txt);
829
830         return ACCOUNT_ERROR_NONE;
831 }
832
833 ACCOUNT_API int account_set_custom(account_h account, const char* key, const char* value)
834 {
835         if (!account) {
836                 ACCOUNT_SLOGE("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
837                 return ACCOUNT_ERROR_INVALID_PARAMETER;
838         }
839
840         if (!key) {
841                 ACCOUNT_SLOGE("(%s)-(%d) key is NULL.\n", __FUNCTION__, __LINE__);
842                 return ACCOUNT_ERROR_INVALID_PARAMETER;
843         }
844
845         if (!value) {
846                 ACCOUNT_SLOGE("(%s)-(%d) value is NULL.\n", __FUNCTION__, __LINE__);
847                 return ACCOUNT_ERROR_INVALID_PARAMETER;
848         }
849
850         account_s *data = (account_s*)account;
851
852         GSList *iter;
853         bool b_is_new = TRUE;
854
855         for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
856
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);
860
861                 if(!strcmp(custom_data->key, key)) {
862                         _ACCOUNT_FREE(custom_data->value);
863                         custom_data->value = _account_get_text(value);
864                         b_is_new = FALSE;
865                 }
866         }
867
868         if(b_is_new) {
869                 account_custom_s* custom_data = (account_custom_s*)malloc(sizeof(account_custom_s));
870
871                 if (custom_data == NULL) {
872                         return ACCOUNT_ERROR_OUT_OF_MEMORY;
873                 }
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);
880         }
881
882         return ACCOUNT_ERROR_NONE;
883 }
884
885 ACCOUNT_API int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
886 {
887         ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n",  __FUNCTION__, __LINE__));
888
889         if ( ((int)auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN)) {
890                 return ACCOUNT_ERROR_INVALID_PARAMETER;
891         }
892
893         account_s *data = (account_s*)account;
894
895         data->auth_type = (int)auth_type;
896
897         return ACCOUNT_ERROR_NONE;
898 }
899
900 ACCOUNT_API int account_set_secret(account_h account, const account_secrecy_state_e secret)
901 {
902         ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n",      __FUNCTION__, __LINE__));
903
904         if ( ((int)secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE)) {
905                 return ACCOUNT_ERROR_INVALID_PARAMETER;
906         }
907
908         account_s *data = (account_s*)account;
909
910         data->secret = (int)secret;
911
912         return ACCOUNT_ERROR_NONE;
913 }
914
915 ACCOUNT_API int account_set_sync_support(account_h account, const account_sync_state_e sync_support)
916 {
917         ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n",      __FUNCTION__, __LINE__));
918
919         if ( ((int)sync_support < 0) || (sync_support > ACCOUNT_SUPPORTS_SYNC)) {
920                 return ACCOUNT_ERROR_INVALID_PARAMETER;
921         }
922
923         account_s *data = (account_s*)account;
924
925         data->sync_support= (int)sync_support;
926
927         return ACCOUNT_ERROR_NONE;
928 }
929
930 ACCOUNT_API int account_set_user_int(account_h account, int idx, const int user_int)
931 {
932         if (!account) {
933                 return ACCOUNT_ERROR_INVALID_PARAMETER;
934         }
935
936         if (idx >= USER_INT_CNT ||idx < 0) {
937                 return ACCOUNT_ERROR_INVALID_PARAMETER;
938         }
939
940         account_s *data = (account_s*)account;
941
942         data->user_data_int[idx] = user_int;
943
944         return ACCOUNT_ERROR_NONE;
945 }
946
947 ACCOUNT_API int account_set_capability(account_h account, const char* capability_type, account_capability_state_e capability_value)
948 {
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"));
951
952         if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED)) {
953                 return ACCOUNT_ERROR_INVALID_PARAMETER;
954         }
955
956         account_s *data = (account_s*)account;
957
958         GSList *iter = NULL;
959         bool b_is_new = TRUE;
960
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;
964
965                 if(!strcmp(cap_data->type, capability_type)) {
966                         cap_data->value = capability_value;
967                         b_is_new = FALSE;
968                         break;
969                 }
970         }
971
972         if(b_is_new) {
973                 account_capability_s* cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
974
975                 if (cap_data == NULL)
976                         return ACCOUNT_ERROR_OUT_OF_MEMORY;
977                 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
978
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);
982         }
983
984         return ACCOUNT_ERROR_NONE;
985 }
986
987 ACCOUNT_API int account_get_user_name(account_h account, char **user_name)
988 {
989         if (!account) {
990                 return ACCOUNT_ERROR_INVALID_PARAMETER;
991         }
992
993         if (!user_name) {
994                 return ACCOUNT_ERROR_INVALID_PARAMETER;
995         }
996
997         account_s *data = (account_s*)account;
998
999         (*user_name) = NULL;
1000         *user_name = _account_get_text(data->user_name);
1001
1002         return ACCOUNT_ERROR_NONE;
1003 }
1004
1005 ACCOUNT_API int account_get_display_name(account_h account, char **display_name)
1006 {
1007         if (!account) {
1008                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1009         }
1010
1011         if (!display_name) {
1012                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1013         }
1014
1015         account_s *data = (account_s*)account;
1016
1017         (*display_name) = NULL;
1018
1019         *display_name = _account_get_text(data->display_name);
1020
1021         return ACCOUNT_ERROR_NONE;
1022 }
1023
1024 ACCOUNT_API int account_get_email_address(account_h account,char **email_address)
1025 {
1026         if (!account) {
1027                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1028         }
1029
1030         if (!email_address) {
1031                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1032         }
1033
1034         account_s *data = (account_s*)account;
1035
1036         (*email_address) = NULL;
1037
1038         *email_address = _account_get_text(data->email_address);
1039
1040         return ACCOUNT_ERROR_NONE;
1041 }
1042
1043 ACCOUNT_API int  account_get_icon_path(account_h account, char **icon_path)
1044 {
1045         if (!account) {
1046                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1047         }
1048
1049         if (!icon_path) {
1050                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1051         }
1052
1053         account_s *data = (account_s*)account;
1054
1055         (*icon_path) = NULL;
1056
1057         *icon_path = _account_get_text(data->icon_path);
1058
1059         return ACCOUNT_ERROR_NONE;
1060 }
1061
1062 ACCOUNT_API int account_get_source(account_h account, char **source)
1063 {
1064         if (!account) {
1065                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1066         }
1067
1068         if (!source) {
1069                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1070         }
1071
1072         account_s *data = (account_s*)account;
1073
1074         (*source) = NULL;
1075
1076         *source = _account_get_text(data->source);
1077
1078         return ACCOUNT_ERROR_NONE;
1079 }
1080
1081 ACCOUNT_API int account_get_package_name(account_h account, char **package_name)
1082 {
1083         if (!account) {
1084                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1085         }
1086
1087         if (!package_name) {
1088                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1089         }
1090
1091         account_s *data = (account_s*)account;
1092
1093         (*package_name) = NULL;
1094
1095         *package_name = _account_get_text(data->package_name);
1096
1097         return ACCOUNT_ERROR_NONE;
1098 }
1099
1100 ACCOUNT_API int account_get_domain_name(account_h account, char **domain_name)
1101 {
1102         if (!account) {
1103                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1104         }
1105
1106         if (!domain_name) {
1107                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1108         }
1109
1110         account_s *data = (account_s*)account;
1111
1112         (*domain_name) = NULL;
1113
1114         *domain_name = _account_get_text(data->domain_name);
1115
1116         return ACCOUNT_ERROR_NONE;
1117 }
1118
1119 ACCOUNT_API int account_get_access_token(account_h account, char **access_token)
1120 {
1121         if (!account) {
1122                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1123         }
1124
1125         if (!access_token) {
1126                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1127         }
1128
1129         account_s *data = (account_s*)account;
1130
1131         (*access_token) = NULL;
1132
1133         *access_token = _account_get_text(data->access_token);
1134
1135         return ACCOUNT_ERROR_NONE;
1136 }
1137
1138 ACCOUNT_API int account_get_user_text(account_h account, int user_text_index, char **text)
1139 {
1140         if (!account) {
1141                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1142         }
1143
1144         if (!text) {
1145                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1146         }
1147         ACCOUNT_RETURN_VAL((user_text_index >=0 && user_text_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1148
1149         account_s *data = (account_s*)account;
1150
1151         (*text) = NULL;
1152
1153         *text = _account_get_text(data->user_data_txt[user_text_index]);
1154
1155         return ACCOUNT_ERROR_NONE;
1156 }
1157
1158 ACCOUNT_API int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1159 {
1160         if (!account) {
1161                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1162         }
1163         if (!auth_type) {
1164                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1165         }
1166
1167         account_s* data = (account_s*)account;
1168
1169         *auth_type = data->auth_type;
1170
1171         return ACCOUNT_ERROR_NONE;
1172 }
1173
1174 ACCOUNT_API int account_get_secret(account_h account, account_secrecy_state_e *secret)
1175 {
1176         if (!account) {
1177                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1178         }
1179         if (!secret) {
1180                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1181         }
1182
1183         account_s* data = (account_s*)account;
1184
1185         *secret = data->secret;
1186
1187         return ACCOUNT_ERROR_NONE;
1188 }
1189
1190 ACCOUNT_API int account_get_sync_support(account_h account, account_sync_state_e *sync_support)
1191 {
1192         if (!account) {
1193                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1194         }
1195         if (!sync_support) {
1196                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1197         }
1198
1199         account_s* data = (account_s*)account;
1200
1201         *sync_support = data->sync_support;
1202
1203         return ACCOUNT_ERROR_NONE;
1204 }
1205
1206 ACCOUNT_API int account_get_account_id(account_h account, int *account_id)
1207 {
1208         if (!account) {
1209                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1210         }
1211         if (!account_id) {
1212                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1213         }
1214
1215         account_s *data = (account_s*)account;
1216
1217         *account_id = data->id;
1218
1219         return ACCOUNT_ERROR_NONE;
1220 }
1221
1222 ACCOUNT_API int account_get_user_int(account_h account, int user_int_index, int *integer)
1223 {
1224         if (!account) {
1225                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1226         }
1227
1228         ACCOUNT_RETURN_VAL((user_int_index >=0 && user_int_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1229
1230         if (!integer) {
1231                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1232         }
1233
1234         account_s *data = (account_s*)account;
1235
1236         *integer = data->user_data_int[user_int_index];
1237
1238         return ACCOUNT_ERROR_NONE;
1239 }
1240
1241 ACCOUNT_API int account_get_capability(account_h account, const char* capability_type, account_capability_state_e* capability_value)
1242 {
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"));
1246
1247         GSList *iter;
1248         account_s *data = (account_s*)account;
1249
1250         _ERR("before for()");
1251         for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1252                 account_capability_s *cap_data = NULL;
1253
1254                 cap_data = (account_capability_s*)iter->data;
1255
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;
1261                 }
1262         }
1263         _ERR("after for()");
1264
1265         return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1266 }
1267
1268 ACCOUNT_API int account_get_capability_all(account_h account, capability_cb callback, void *user_data)
1269 {
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"));
1272
1273         GSList *iter;
1274         account_s *data = (account_s*)account;
1275
1276         for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1277                 account_capability_s *cap_data = NULL;
1278
1279                 cap_data = (account_capability_s*)iter->data;
1280
1281                 if(callback(cap_data->type, cap_data->value, user_data)!=TRUE){
1282                         return ACCOUNT_ERROR_NONE;
1283                 }
1284         }
1285
1286         return ACCOUNT_ERROR_NONE;
1287 }
1288
1289 ACCOUNT_API int account_get_custom(account_h account, const char* key, char** value)
1290 {
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"));
1294
1295         GSList *iter;
1296         account_s *data = (account_s*)account;
1297
1298         _ERR("before for()");
1299         for (iter = data->custom_list; iter != NULL; iter = g_slist_next(iter)) {
1300                 account_custom_s *custom_data = NULL;
1301
1302                 custom_data = (account_custom_s*)iter->data;
1303
1304                 _ERR("key = %s, custom_data->key = %s", key, custom_data->key);
1305                 _ERR("value = %s, custom_data->value = %s", value, custom_data->value);
1306
1307                 if(!strcmp(key, custom_data->key)) {
1308                         (*value) = NULL;
1309                         *value = _account_get_text(custom_data->value);
1310                         return ACCOUNT_ERROR_NONE;
1311                 }
1312         }
1313         _ERR("after for()");
1314
1315         return ACCOUNT_ERROR_RECORD_NOT_FOUND;
1316 }
1317
1318 ACCOUNT_API int account_get_custom_all(account_h account, account_custom_cb callback, void* user_data)
1319 {
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"));
1322
1323         GSList *iter;
1324         account_s *data = (account_s*)account;
1325
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;
1329
1330                 custom_data = (account_custom_s*)iter->data;
1331
1332                 cb_ret = callback(custom_data->key, custom_data->value, user_data);
1333                 if(!cb_ret) {
1334                         break;
1335                 }
1336         }
1337
1338         return ACCOUNT_ERROR_NONE;
1339 }
1340
1341 ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_data)
1342 {
1343         _INFO("account_type_foreach_account_type_from_db start");
1344         char* account_db_path = ACCOUNT_DB_NAME;
1345
1346         ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
1347
1348         GError *error = NULL;
1349
1350         AccountManager* acc_mgr = _account_manager_get_instance();
1351         if (acc_mgr == NULL)
1352         {
1353                 _ERR("g_bus_get_sync failed");
1354                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1355         }
1356
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);
1359
1360         int error_code = _account_get_error_code(is_success, error);
1361         if (error_code != ACCOUNT_ERROR_NONE)
1362         {
1363                 return error_code;
1364         }
1365
1366         _INFO("before unmarshal_account_list");
1367         GSList* account_list = unmarshal_account_list(account_list_variant);
1368         _INFO("after unmarshal_account_list");
1369         GSList* iter;
1370
1371         for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1372         {
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");
1377
1378                 _INFO("account->id=%d", account->id);
1379                 if (callback((account_h)account, user_data) == false)
1380                 {
1381                         _INFO("application callback requested to discontinue.");
1382                         break;
1383                 }
1384                 _INFO("After one iteration callback");
1385         }
1386         _INFO("account_foreach_account_from_db end");
1387
1388         return ACCOUNT_ERROR_NONE;
1389 }
1390
1391 ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h *account)
1392 {
1393         _INFO("account_query_account_by_account_id start [%d]", account_db_id);
1394         char* account_db_path = ACCOUNT_DB_NAME;
1395
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"));
1398
1399         GError *error = NULL;
1400
1401         AccountManager* acc_mgr = _account_manager_get_instance();
1402         if (acc_mgr == NULL)
1403         {
1404                 _ERR("g_bus_get_sync failed");
1405                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1406         }
1407
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);
1410
1411         int error_code = _account_get_error_code(is_success, error);
1412         if (error_code != ACCOUNT_ERROR_NONE)
1413         {
1414                 return error_code;
1415         }
1416
1417         _INFO("before unmarshal_account");
1418         account_s* account_data = umarshal_account(account_variant);
1419         _INFO("after unmarshal_account");
1420
1421         if (account_data == NULL)
1422         {
1423                 _ERR("Failed to unmarshal");
1424                 return ACCOUNT_ERROR_DB_FAILED;
1425         }
1426
1427         *account = (account_h) account_data;
1428
1429         _INFO("account_query_account_by_account_id end");
1430
1431         return ACCOUNT_ERROR_NONE;
1432 }
1433
1434 ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const char* user_name, void* user_data)
1435 {
1436         _INFO("account_query_account_by_user_name starting");
1437         char* account_db_path = ACCOUNT_DB_NAME;
1438
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"));
1441
1442         GError *error = NULL;
1443
1444         AccountManager* acc_mgr = _account_manager_get_instance();
1445         if (acc_mgr == NULL)
1446         {
1447                 _ERR("g_bus_get_sync failed");
1448                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1449         }
1450
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);
1453
1454         int error_code = _account_get_error_code(is_success, error);
1455         if (error_code != ACCOUNT_ERROR_NONE)
1456         {
1457                 return error_code;
1458         }
1459
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)
1464         {
1465                 return ACCOUNT_ERROR_NO_DATA;
1466         }
1467
1468         GSList* iter;
1469
1470         for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1471         {
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)
1476                 {
1477                         _INFO("application callback requested to discontinue.");
1478                         break;
1479                 }
1480         }
1481         _INFO("account_query_account_by_user_name end");
1482
1483         return ACCOUNT_ERROR_NONE;
1484 }
1485
1486 ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const char *package_name, void *user_data)
1487 {
1488         _INFO("account_query_account_by_package_name starting");
1489         char* account_db_path = ACCOUNT_DB_NAME;
1490
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"));
1493
1494         GError *error = NULL;
1495
1496         AccountManager* acc_mgr = _account_manager_get_instance();
1497         if (acc_mgr == NULL)
1498         {
1499                 _ERR("g_bus_get_sync failed");
1500                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1501         }
1502
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);
1505
1506         int error_code = _account_get_error_code(is_success, error);
1507         if (error_code != ACCOUNT_ERROR_NONE)
1508         {
1509                 return error_code;
1510         }
1511
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)
1516         {
1517                 return ACCOUNT_ERROR_NO_DATA;
1518         }
1519
1520         GSList* iter;
1521
1522         for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1523         {
1524                 _INFO("iterating received account_list");
1525                 account_s *account = NULL;
1526                 account = (account_s*)iter->data;
1527
1528                 if (callback((account_h)account, user_data) == false)
1529                 {
1530                         _INFO("application callback requested to discontinue.");
1531                         break;
1532                 }
1533         }
1534         _INFO("account_query_account_by_package_name end");
1535         return ACCOUNT_ERROR_NONE;
1536 }
1537
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)
1539 {
1540         _INFO("account_query_account_by_capability starting");
1541         char* account_db_path = ACCOUNT_DB_NAME;
1542
1543         ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("capability_type IS NULL"));
1544
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;
1548         }
1549
1550         ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
1551
1552         GError *error = NULL;
1553
1554         AccountManager* acc_mgr = _account_manager_get_instance();
1555         if (acc_mgr == NULL)
1556         {
1557                 _ERR("g_bus_get_sync failed");
1558                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1559         }
1560
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);
1563
1564         int error_code = _account_get_error_code(is_success, error);
1565         if (error_code != ACCOUNT_ERROR_NONE)
1566         {
1567                 return error_code;
1568         }
1569
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)
1574         {
1575                 return ACCOUNT_ERROR_NO_DATA;
1576         }
1577
1578         GSList* iter;
1579
1580         for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1581         {
1582                 _INFO("iterating received account_list");
1583                 account_s *account = NULL;
1584                 account = (account_s*)iter->data;
1585
1586                 if (callback((account_h)account, user_data) == false)
1587                 {
1588                         _INFO("application callback requested to discontinue.");
1589                         break;
1590                 }
1591         }
1592         _INFO("account_query_account_by_capability end");
1593         return ACCOUNT_ERROR_NONE;
1594 }
1595
1596 ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, const char* capability_type, void* user_data)
1597 {
1598         _INFO("account_query_account_by_capability_type starting");
1599         char* account_db_path = ACCOUNT_DB_NAME;
1600
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"));
1603
1604         GError *error = NULL;
1605
1606         AccountManager* acc_mgr = _account_manager_get_instance();
1607         if (acc_mgr == NULL)
1608         {
1609                 _ERR("g_bus_get_sync failed");
1610                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1611         }
1612
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);
1615
1616         int error_code = _account_get_error_code(is_success, error);
1617         if (error_code != ACCOUNT_ERROR_NONE)
1618         {
1619                 return error_code;
1620         }
1621
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)
1626         {
1627                 return ACCOUNT_ERROR_NO_DATA;
1628         }
1629
1630         GSList* iter;
1631
1632         for (iter = account_list; iter != NULL; iter = g_slist_next(iter))
1633         {
1634                 _INFO("iterating received account_list");
1635                 account_s *account = NULL;
1636                 account = (account_s*)iter->data;
1637
1638                 if (callback((account_h)account, user_data) == false)
1639                 {
1640                         _INFO("application callback requested to discontinue.");
1641                         break;
1642                 }
1643         }
1644         _INFO("account_query_account_by_capability end");
1645         return ACCOUNT_ERROR_NONE;
1646 }
1647
1648 ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data)
1649 {
1650         _INFO("account_query_capability_by_account_id starting");
1651         char* account_db_path = ACCOUNT_DB_NAME;
1652
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"));
1655
1656         GError *error = NULL;
1657         AccountManager* acc_mgr = _account_manager_get_instance();
1658         if (acc_mgr == NULL)
1659         {
1660                 _ERR("g_bus_get_sync failed");
1661                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1662         }
1663
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);
1666
1667         int error_code = _account_get_error_code(is_success, error);
1668         if (error_code != ACCOUNT_ERROR_NONE)
1669         {
1670                 return error_code;
1671         }
1672
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)
1677         {
1678                 return ACCOUNT_ERROR_NO_DATA;
1679         }
1680
1681         GSList* iter;
1682
1683         for (iter = capability_list; iter != NULL; iter = g_slist_next(iter))
1684         {
1685                 _INFO("iterating received account_list");
1686                 account_capability_s *capability = NULL;
1687                 capability = (account_capability_s*)iter->data;
1688                 _INFO("");
1689                 if (callback(capability->type, capability->value, user_data) == false)
1690                 {
1691                         _INFO("application callback requested to discontinue.");
1692                         break;
1693                 }
1694                 _INFO("");
1695         }
1696         _INFO("account_query_capability_by_account_id end");
1697         return ACCOUNT_ERROR_NONE;
1698 }
1699
1700 static int _account_get_total_count(int *count, bool include_hidden)
1701 {
1702         _INFO("account_get_total_count_from_db starting");
1703         char* account_db_path = ACCOUNT_DB_NAME;
1704
1705         if (!count)
1706         {
1707                 ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
1708                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1709         }
1710
1711         GError *error = NULL;
1712
1713         if (count == NULL)
1714         {
1715                 _INFO("Invalid input");
1716                 return -1;
1717         }
1718
1719         AccountManager* acc_mgr = _account_manager_get_instance();
1720         if (acc_mgr == NULL)
1721         {
1722                 _ERR("g_bus_get_sync failed");
1723                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1724         }
1725
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)
1730         {
1731                 return error_code;
1732         }
1733
1734         *count = temp_count;
1735         _INFO("account_get_total_count_from_db end");
1736         return ACCOUNT_ERROR_NONE;
1737 }
1738
1739 ACCOUNT_API int account_get_total_count_from_db(int *count)
1740 {
1741         _INFO("account_get_total_count_from_db starting");
1742
1743         return _account_get_total_count(count, true);
1744 }
1745
1746 ACCOUNT_API int account_get_total_count_from_db_ex(int *count)
1747 {
1748         _INFO("account_get_total_count_from_db_ex starting");
1749
1750         return _account_get_total_count(count, false);
1751 }
1752
1753 ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const account_sync_state_e sync_status)
1754 {
1755         _INFO("account_update_sync_status_by_id starting");
1756         char* account_db_path = ACCOUNT_DB_NAME;
1757
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;
1762         }
1763
1764         GError *error = NULL;
1765
1766         AccountManager* acc_mgr = _account_manager_get_instance();
1767         if (acc_mgr == NULL)
1768         {
1769                 _ERR("g_bus_get_sync failed");
1770                 return ACCOUNT_ERROR_PERMISSION_DENIED;
1771         }
1772
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);
1774
1775         return _account_get_error_code(is_success, error);
1776 }
1777
1778 static int _account_type_free_label_items(label_s *data)
1779 {
1780         _ACCOUNT_FREE(data->app_id);
1781         _ACCOUNT_FREE(data->label);
1782         _ACCOUNT_FREE(data->locale);
1783
1784         return ACCOUNT_ERROR_NONE;
1785 }
1786
1787 static int _account_type_gslist_free(GSList* list)
1788 {
1789         ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
1790
1791         GSList* iter;
1792
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);
1797         }
1798
1799         g_slist_free(list);
1800         list = NULL;
1801
1802         return ACCOUNT_ERROR_NONE;
1803 }
1804
1805 static int _account_type_item_free(account_type_s *data)
1806 {
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);
1811
1812         return ACCOUNT_ERROR_NONE;
1813 }
1814
1815 static int _account_type_glist_free(GList* list)
1816 {
1817         ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Glist is NULL"));
1818
1819         GList* iter;
1820
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);
1825         }
1826
1827         g_list_free(list);
1828         list = NULL;
1829
1830         return ACCOUNT_ERROR_NONE;
1831 }
1832
1833 static int _account_type_free_account_type_items(account_type_s *data)
1834 {
1835         _account_type_item_free(data);
1836
1837         _account_type_gslist_free(data->label_list);
1838         _account_type_glist_free(data->account_type_list);
1839
1840         return ACCOUNT_ERROR_NONE;
1841 }
1842
1843 ACCOUNT_API int account_type_create(account_type_h *account_type)
1844 {
1845         if (!account_type) {
1846                 ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
1847                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1848         }
1849
1850         account_type_s *data = (account_type_s*)malloc(sizeof(account_type_s));
1851
1852         if (data == NULL)
1853         {
1854                 ACCOUNT_ERROR("Memory Allocation Failed");
1855                 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1856         }
1857
1858         ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
1859
1860         data->id = -1;
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;
1869
1870         *account_type = (account_type_h)data;
1871
1872         return ACCOUNT_ERROR_NONE;
1873 }
1874
1875 ACCOUNT_API int account_type_destroy(account_type_h account_type)
1876 {
1877         _INFO("account_type_destroy");
1878
1879         account_type_s *data = (account_type_s*)account_type;
1880
1881         if (data == NULL)
1882         {
1883                 _ERR("Account type handle is null!");
1884                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1885         }
1886
1887         _account_type_free_account_type_items(data);
1888         _ACCOUNT_FREE(data);
1889
1890         return ACCOUNT_ERROR_NONE;
1891 }
1892
1893 ACCOUNT_API int account_type_set_app_id(account_type_h account_type, const char *app_id)
1894 {
1895         return ACCOUNT_ERROR_NONE;
1896 }
1897
1898 ACCOUNT_API int account_type_set_app_id_internal(account_type_h account_type, const char *app_id)
1899 {
1900         if (!account_type) {
1901                 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
1902                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1903         }
1904
1905         if (!app_id) {
1906                 ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
1907                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1908         }
1909
1910         account_type_s *data = (account_type_s*)account_type;
1911
1912         _ACCOUNT_FREE(data->app_id);
1913         data->app_id = _account_get_text(app_id);
1914
1915         return ACCOUNT_ERROR_NONE;
1916 }
1917
1918 ACCOUNT_API int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
1919 {
1920         return ACCOUNT_ERROR_NONE;
1921 }
1922
1923 ACCOUNT_API int account_type_set_service_provider_id_internal(account_type_h account_type, const char *service_provider_id)
1924 {
1925         if (!account_type) {
1926                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1927         }
1928
1929         if (!service_provider_id) {
1930                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1931         }
1932
1933         account_type_s *data = (account_type_s*)account_type;
1934
1935         _ACCOUNT_FREE(data->service_provider_id);
1936         data->service_provider_id = _account_get_text(service_provider_id);
1937
1938         return ACCOUNT_ERROR_NONE;
1939 }
1940
1941 ACCOUNT_API int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
1942 {
1943         return ACCOUNT_ERROR_NONE;
1944 }
1945
1946 ACCOUNT_API int account_type_set_icon_path_internal(account_type_h account_type, const char *icon_path)
1947 {
1948         if (!account_type) {
1949                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1950         }
1951
1952         if (!icon_path) {
1953                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1954         }
1955
1956         account_type_s *data = (account_type_s*)account_type;
1957
1958         _ACCOUNT_FREE(data->icon_path);
1959         data->icon_path = _account_get_text(icon_path);
1960
1961         return ACCOUNT_ERROR_NONE;
1962 }
1963
1964 ACCOUNT_API int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
1965 {
1966         return ACCOUNT_ERROR_NONE;
1967 }
1968
1969 ACCOUNT_API int account_type_set_small_icon_path_internal(account_type_h account_type, const char *small_icon_path)
1970 {
1971         if (!account_type) {
1972                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1973         }
1974
1975         if (!small_icon_path) {
1976                 return ACCOUNT_ERROR_INVALID_PARAMETER;
1977         }
1978
1979         account_type_s *data = (account_type_s*)account_type;
1980
1981         _ACCOUNT_FREE(data->small_icon_path);
1982         data->small_icon_path = _account_get_text(small_icon_path);
1983
1984         return ACCOUNT_ERROR_NONE;
1985 }
1986
1987 ACCOUNT_API int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
1988 {
1989         return ACCOUNT_ERROR_NONE;
1990 }
1991
1992 ACCOUNT_API int account_type_set_multiple_account_support_internal(account_type_h account_type, const bool multiple_account_support)
1993 {
1994         ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n",  __FUNCTION__, __LINE__));
1995
1996         account_type_s *data = (account_type_s*)account_type;
1997
1998         data->multiple_account_support = multiple_account_support;
1999
2000         return ACCOUNT_ERROR_NONE;
2001 }
2002
2003 ACCOUNT_API int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
2004 {
2005         return ACCOUNT_ERROR_NONE;
2006 }
2007
2008 ACCOUNT_API int account_type_set_label_internal(account_type_h account_type, const char* label, const char* locale)
2009 {
2010         if (!account_type) {
2011                 ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
2012                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2013         }
2014
2015         if(!label || !locale) {
2016                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2017         }
2018
2019         account_type_s *data = (account_type_s*)account_type;
2020         label_s *label_data = (label_s*)malloc(sizeof(label_s));
2021
2022         if (label_data == NULL) {
2023                 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2024         }
2025         ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
2026
2027         label_data->label = _account_get_text(label);
2028         label_data->locale = _account_get_text(locale);
2029
2030         data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
2031
2032         return ACCOUNT_ERROR_NONE;
2033 }
2034
2035 ACCOUNT_API int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature)
2036 {
2037         return ACCOUNT_ERROR_NONE;
2038 }
2039
2040 ACCOUNT_API int account_type_set_provider_feature_internal(account_type_h account_type, const char* provider_feature)
2041 {
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"));
2044
2045         account_type_s *data = (account_type_s*)account_type;
2046
2047         GSList *iter = NULL;
2048         bool b_is_new = TRUE;
2049
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;
2053
2054                 if(!strcmp(feature_data->key, provider_feature)) {
2055                         b_is_new = FALSE;
2056                         break;
2057                 }
2058         }
2059
2060         if(b_is_new) {
2061                 provider_feature_s* feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
2062
2063                 if (feature_data == NULL)
2064                         return ACCOUNT_ERROR_OUT_OF_MEMORY;
2065                 ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
2066
2067                 feature_data->key = _account_get_text(provider_feature);
2068                 data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
2069         }
2070
2071         return ACCOUNT_ERROR_NONE;
2072 }
2073
2074 ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
2075 {
2076         _INFO("account_type_query_provider_feature_by_app_id start");
2077         char* account_db_path = ACCOUNT_DB_NAME;
2078
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"));
2081
2082         GError *error = NULL;
2083         gint error_code = ACCOUNT_ERROR_NONE;
2084
2085         AccountManager* acc_mgr = _account_manager_get_instance();
2086         if (acc_mgr == NULL)
2087         {
2088                 _ERR("g_bus_get_sync failed");
2089                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2090         }
2091
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);
2094
2095         _INFO("account_manager_call_account_type_query_provider_feature_by_app_id_sync end=[%d]", is_success);
2096
2097         if (!is_success)
2098         {
2099                 error_code = error->code;
2100                 _ERR("Account IPC call returned error[%d]", error_code);
2101                 return error_code;
2102         }
2103
2104         GSList* provider_feature_list = variant_to_provider_feature_list(feature_list_variant);
2105         if (provider_feature_list == NULL)
2106         {
2107                 error_code = ACCOUNT_ERROR_NO_DATA;
2108                 _ERR("[%d]", error_code);
2109                 return error_code;
2110         }
2111
2112         GSList *iter;
2113         for (iter = provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2114                 provider_feature_s *feature_data = NULL;
2115
2116                 feature_data = (provider_feature_s*)iter->data;
2117
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;
2121                 }
2122         }
2123
2124         _INFO("account_type_query_provider_feature_by_app_id end");
2125         return error_code;
2126 }
2127
2128 ACCOUNT_API bool account_type_query_supported_feature(const char* app_id, const char* capability)
2129 {
2130         _INFO("account_type_query_supported_feature start");
2131         char* account_db_path = ACCOUNT_DB_NAME;
2132
2133         if (app_id == NULL || capability == NULL)
2134         {
2135                 set_last_result(ACCOUNT_ERROR_INVALID_PARAMETER);
2136                 return false;
2137         }
2138
2139         int is_supported = 0;
2140         GError *error = NULL;
2141         gint ret = ACCOUNT_ERROR_NONE;
2142
2143         AccountManager* acc_mgr = _account_manager_get_instance();
2144         if (acc_mgr == NULL)
2145         {
2146                 _ERR("g_bus_get_sync failed");
2147                 set_last_result(ACCOUNT_ERROR_PERMISSION_DENIED);
2148                 return false;
2149         }
2150
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);
2152
2153         _INFO("account_manager_call_account_type_query_supported_feature_sync end=[%d]", is_success);
2154
2155         if (!is_success)
2156         {
2157                 ret = error->code;
2158                 _ERR("Account IPC call returned error[%d]", ret);
2159                 set_last_result(ret);
2160                 return false;
2161         }
2162
2163         set_last_result(ACCOUNT_ERROR_NONE);
2164         _INFO("account_type_query_supported_feature end");
2165         return is_supported;
2166 }
2167
2168 ACCOUNT_API int account_type_get_app_id(account_type_h account_type, char **app_id)
2169 {
2170         if (!account_type) {
2171                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2172         }
2173
2174         if (!app_id) {
2175                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2176         }
2177
2178         account_type_s *data = (account_type_s*)account_type;
2179
2180         (*app_id) = NULL;
2181         *app_id = _account_get_text(data->app_id);
2182
2183         return ACCOUNT_ERROR_NONE;
2184 }
2185
2186 ACCOUNT_API int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
2187 {
2188         if (!account_type) {
2189                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2190         }
2191
2192         if (!service_provider_id) {
2193                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2194         }
2195
2196         account_type_s *data = (account_type_s*)account_type;
2197
2198         (*service_provider_id) = NULL;
2199         *service_provider_id = _account_get_text(data->service_provider_id);
2200
2201         return ACCOUNT_ERROR_NONE;
2202 }
2203
2204 ACCOUNT_API int account_type_get_icon_path(account_type_h account_type, char **icon_path)
2205 {
2206         if (!account_type) {
2207                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2208         }
2209
2210         if (!icon_path) {
2211                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2212         }
2213
2214         account_type_s *data = (account_type_s*)account_type;
2215
2216         (*icon_path) = NULL;
2217         *icon_path = _account_get_text(data->icon_path);
2218
2219         return ACCOUNT_ERROR_NONE;
2220 }
2221
2222 ACCOUNT_API int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
2223 {
2224         if (!account_type) {
2225                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2226         }
2227
2228         if (!small_icon_path) {
2229                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2230         }
2231
2232         account_type_s *data = (account_type_s*)account_type;
2233
2234         (*small_icon_path) = NULL;
2235         *small_icon_path = _account_get_text(data->small_icon_path);
2236
2237         return ACCOUNT_ERROR_NONE;
2238 }
2239
2240 ACCOUNT_API int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
2241 {
2242         if (!account_type) {
2243                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2244         }
2245         if (!multiple_account_support) {
2246                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2247         }
2248
2249         account_type_s *data = (account_type_s*)account_type;
2250
2251         *multiple_account_support = data->multiple_account_support;
2252
2253         return ACCOUNT_ERROR_NONE;
2254 }
2255
2256 ACCOUNT_API int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void* user_data)
2257 {
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"));
2260
2261         GSList *iter;
2262         account_type_s *data = (account_type_s*)account_type;
2263
2264         for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
2265                 provider_feature_s *feature_data = NULL;
2266
2267                 feature_data = (provider_feature_s*)iter->data;
2268
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;
2272                 }
2273         }
2274
2275         return ACCOUNT_ERROR_NONE;
2276 }
2277
2278 ACCOUNT_API int account_type_get_label_by_locale(account_type_h account_type, const char* locale, char** label)
2279 {
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"));
2282
2283         GSList *iter;
2284         account_type_s *data = (account_type_s*)account_type;
2285
2286         for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2287                 label_s *label_data = NULL;
2288
2289                 label_data = (label_s*)iter->data;
2290
2291                 *label = NULL;
2292
2293                 if(!strcmp(locale, label_data->locale)) {
2294                         *label = _account_get_text(label_data->label);
2295                         return ACCOUNT_ERROR_NONE;
2296                 }
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);
2306                                                 g_strfreev(tokens);
2307                                                 *label = _account_get_text(label_data->label);
2308                                                 return ACCOUNT_ERROR_NONE;
2309                                         }
2310                                         _ACCOUNT_FREE(converted_locale);
2311                                 }
2312                                 _ACCOUNT_FREE(upper_token);
2313                         }
2314                 }
2315                 g_strfreev(tokens);
2316         }
2317
2318         return ACCOUNT_ERROR_RECORD_NOT_FOUND;
2319 }
2320
2321 ACCOUNT_API int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
2322 {
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"));
2325
2326         GSList *iter;
2327         account_type_s *data = (account_type_s*)account_type;
2328
2329         for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
2330                 label_s *label_data = NULL;
2331
2332                 label_data = (label_s*)iter->data;
2333
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;
2337                 }
2338         }
2339
2340         return ACCOUNT_ERROR_NONE;
2341 }
2342
2343 ACCOUNT_API int account_type_insert_to_db(account_type_h account_type, int* account_type_id)
2344 {
2345         return ACCOUNT_ERROR_NONE;
2346 }
2347
2348 ACCOUNT_API int account_type_insert_to_db_internal(account_type_h account_type, int* account_type_id)
2349 {
2350         _INFO("account_type_insert_to_db starting");
2351         char* account_db_path = ACCOUNT_DB_NAME;
2352
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"));
2355
2356         GError *error = NULL;
2357
2358         AccountManager* acc_mgr = _account_manager_get_instance();
2359         if (acc_mgr == NULL)
2360         {
2361                 _ERR("g_bus_get_sync failed");
2362                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2363         }
2364
2365         int db_id = -1;
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);
2368
2369         int ret = _account_get_error_code(is_success, error);
2370         if (ret != ACCOUNT_ERROR_NONE)
2371         {
2372                 return ret;
2373         }
2374
2375         _INFO("account_type_insert_to_db end id=[%d]", db_id);
2376
2377         *account_type_id = db_id;
2378
2379         account_type_s* account_type_data = (account_type_s*)account_type;
2380         account_type_data->id = db_id;
2381
2382         return ACCOUNT_ERROR_NONE;
2383 }
2384
2385 ACCOUNT_API int account_type_update_to_db_by_app_id(const account_type_h account_type, const char* app_id)
2386 {
2387         return ACCOUNT_ERROR_NONE;
2388 }
2389
2390 ACCOUNT_API int account_type_update_to_db_by_app_id_internal(const account_type_h account_type, const char* app_id)
2391 {
2392         _INFO("account_type_update_to_db_by_app_id starting");
2393         char* account_db_path = ACCOUNT_DB_NAME;
2394
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"));
2397
2398         GError *error = NULL;
2399
2400         AccountManager* acc_mgr = _account_manager_get_instance();
2401         if (acc_mgr == NULL)
2402         {
2403                 _ERR("g_bus_get_sync failed");
2404                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2405         }
2406
2407         GVariant* account_type_variant = marshal_account_type((account_type_s*) account_type);
2408         if (account_type_variant == NULL)
2409         {
2410                 _ERR("Failed to serialize");
2411                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2412         }
2413
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);
2415
2416         return _account_get_error_code(is_success, error);
2417 }
2418
2419 ACCOUNT_API int account_type_delete_by_app_id(const char* app_id)
2420 {
2421         return ACCOUNT_ERROR_NONE;
2422 }
2423
2424 ACCOUNT_API int account_type_delete_by_app_id_internal(const char* app_id)
2425 {
2426         _INFO("account_type_delete_by_app_id starting");
2427         char* account_db_path = ACCOUNT_DB_NAME;
2428
2429         ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2430
2431         GError *error = NULL;
2432
2433         AccountManager* acc_mgr = _account_manager_get_instance();
2434         if (acc_mgr == NULL)
2435         {
2436                 _ERR("g_bus_get_sync failed");
2437                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2438         }
2439
2440         bool is_success = account_manager_call_account_type_delete_by_app_id_sync(acc_mgr, account_db_path, app_id, NULL, &error);
2441
2442         return _account_get_error_code(is_success, error);
2443 }
2444
2445 ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
2446 {
2447         _INFO("account_type_query_label_by_app_id starting");
2448         char* account_db_path = ACCOUNT_DB_NAME;
2449
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"));
2452
2453         GError *error = NULL;
2454
2455         AccountManager* acc_mgr = _account_manager_get_instance();
2456         if (acc_mgr == NULL)
2457         {
2458                 _ERR("g_bus_get_sync failed");
2459                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2460         }
2461
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);
2464
2465         int ret = _account_get_error_code(is_success, error);
2466         if (ret != ACCOUNT_ERROR_NONE)
2467         {
2468                 return ret;
2469         }
2470
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)
2475         {
2476                 return ACCOUNT_ERROR_NO_DATA;
2477         }
2478
2479         GSList* iter;
2480
2481         for (iter = label_list; iter != NULL; iter = g_slist_next(iter))
2482         {
2483                 _INFO("iterating received account_list");
2484                 label_s *label_record = NULL;
2485                 label_record = (label_s*)iter->data;
2486                 _INFO("");
2487                 if (callback(label_record->app_id, label_record->label, label_record->locale, user_data) == false)
2488                 {
2489                         _INFO("application callback requested to discontinue.");
2490                         break;
2491                 }
2492                 _INFO("");
2493         }
2494         _INFO("account_type_query_label_by_app_id end");
2495         return ACCOUNT_ERROR_NONE;
2496 }
2497
2498 ACCOUNT_API int account_type_query_by_app_id(const char* app_id, account_type_h *account_type)
2499 {
2500         _INFO("account_type_query_by_app_id starting");
2501         char* account_db_path = ACCOUNT_DB_NAME;
2502
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"));
2506
2507         GError *error = NULL;
2508
2509         AccountManager* acc_mgr = _account_manager_get_instance();
2510         if (acc_mgr == NULL)
2511         {
2512                 _ERR("g_bus_get_sync failed");
2513                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2514         }
2515
2516         GVariant* account_type_variant = NULL;
2517         account_type_s *in_data = (account_type_s*) (*account_type);
2518
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);
2520
2521         int ret = _account_get_error_code(is_success, error);
2522         if (ret != ACCOUNT_ERROR_NONE)
2523         {
2524                 return ret;
2525         }
2526
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"));
2531
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;
2541
2542         _INFO("account_type_query_by_app_id end");
2543         return ACCOUNT_ERROR_NONE;
2544 }
2545
2546 ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callback, void *user_data)
2547 {
2548         _INFO("account_type_foreach_account_type_from_db starting");
2549         char* account_db_path = ACCOUNT_DB_NAME;
2550
2551         ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT Callback IS NULL"));
2552
2553         GError *error = NULL;
2554
2555         AccountManager* acc_mgr = _account_manager_get_instance();
2556         if (acc_mgr == NULL)
2557         {
2558                 _ERR("g_bus_get_sync failed");
2559                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2560         }
2561
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);
2565
2566         _INFO("after account_type_query_all_sync()");
2567         int ret = _account_get_error_code(is_success, error);
2568         if (ret != ACCOUNT_ERROR_NONE)
2569         {
2570                 return ret;
2571         }
2572
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)
2577         {
2578                 return ACCOUNT_ERROR_NO_DATA;
2579         }
2580
2581         GSList* iter;
2582
2583         for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2584         {
2585                 _INFO("iterating received account_list");
2586                 account_type_s *account_type = NULL;
2587                 account_type = (account_type_s*)iter->data;
2588
2589                 if (callback((account_type_h)account_type, user_data) == false)
2590                 {
2591                         _INFO("application callback requested to discontinue.");
2592                         break;
2593                 }
2594         }
2595         _INFO("account_foreach_account_from_db end");
2596         return ACCOUNT_ERROR_NONE;
2597 }
2598
2599 ACCOUNT_API int account_type_query_label_by_locale(const char* app_id, const char* locale, char** label)
2600 {
2601         _INFO("account_type_query_label_by_locale starting");
2602         char* account_db_path = ACCOUNT_DB_NAME;
2603
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"));
2607
2608         GError *error = NULL;
2609
2610         AccountManager* acc_mgr = _account_manager_get_instance();
2611         if (acc_mgr == NULL)
2612         {
2613                 _ERR("g_bus_get_sync failed");
2614                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2615         }
2616
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);
2620
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)
2624         {
2625                 return ret;
2626         }
2627
2628         if (label_temp == NULL)
2629         {
2630                 return ACCOUNT_ERROR_NO_DATA;
2631         }
2632
2633         *label = _account_get_text(label_temp);
2634         _INFO("account_type_query_label_by_locale end");
2635         return ACCOUNT_ERROR_NONE;
2636
2637 }
2638
2639 ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, const char* key, void* user_data)
2640 {
2641         _INFO("account_type_query_by_provider_feature starting");
2642         char* account_db_path = ACCOUNT_DB_NAME;
2643
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"));
2646
2647         GError *error = NULL;
2648
2649         AccountManager* acc_mgr = _account_manager_get_instance();
2650         if (acc_mgr == NULL)
2651         {
2652                 _ERR("g_bus_get_sync failed");
2653                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2654         }
2655
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);
2658
2659         int ret = _account_get_error_code(is_success, error);
2660         if (ret != ACCOUNT_ERROR_NONE)
2661         {
2662                 return ret;
2663         }
2664
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)
2669         {
2670                 return ACCOUNT_ERROR_NO_DATA;
2671         }
2672
2673         GSList* iter;
2674
2675         for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter))
2676         {
2677                 _INFO("iterating received account_type_list");
2678                 account_type_s *account_type = NULL;
2679                 account_type = (account_type_s*)iter->data;
2680                 _INFO("");
2681                 if (callback((account_type_h)account_type, user_data) == false)
2682                 {
2683                         _INFO("Application callback requested not to continue");
2684                         break;
2685                 }
2686                 _INFO("");
2687         }
2688         _INFO("account_type_query_by_provider_feature end");
2689         return ACCOUNT_ERROR_NONE;
2690 }
2691
2692 ACCOUNT_API int account_type_query_app_id_exist(const char* app_id)
2693 {
2694         _INFO("account_type_query_app_id_exist starting");
2695         char* account_db_path = ACCOUNT_DB_NAME;
2696
2697         ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
2698
2699         GError *error = NULL;
2700
2701         AccountManager* acc_mgr = _account_manager_get_instance();
2702         if (acc_mgr == NULL)
2703         {
2704                 _ERR("g_bus_get_sync failed");
2705                 return ACCOUNT_ERROR_PERMISSION_DENIED;
2706         }
2707
2708         bool is_success = account_manager_call_account_type_query_app_id_exist_sync(acc_mgr, account_db_path, app_id, NULL, &error);
2709
2710         return _account_get_error_code(is_success, error);
2711 }
2712
2713
2714 static void _account_subscribe_vconf_callback(keynode_t *key, void *user_data)
2715 {
2716         account_subscribe_s* tmp = (account_subscribe_s*)user_data;
2717         char *msg = NULL, *vconf_key = NULL;
2718         char event_msg[256] ={0, };
2719         int account_id = -1;
2720
2721         if(!key) {
2722                 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2723                 return;
2724         }
2725
2726         if(!tmp) {
2727                 ACCOUNT_ERROR("user data required\n");
2728                 return;
2729         }
2730
2731         if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2732         {
2733                 vconf_key = vconf_keynode_get_str(key);
2734
2735                 if( vconf_key == NULL){
2736                         ACCOUNT_ERROR("vconf key is NULL.\n");
2737                         return;
2738                 }
2739                 msg = strdup(vconf_key);
2740
2741                 char* event_type = NULL;
2742                 char* id = NULL;
2743                 char* ptr = NULL;
2744
2745                 event_type = strtok_r(msg, ":", &ptr);
2746                 id = strtok_r(NULL, ":", &ptr);
2747
2748                 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2749
2750                 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2751
2752                 account_id = atoi(id);
2753
2754                 if(tmp->account_subscription_callback)
2755                         tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2756         }
2757
2758         _ACCOUNT_FREE(msg);
2759
2760 }
2761
2762 ACCOUNT_API int account_subscribe_create(account_subscribe_h* account_subscribe)
2763 {
2764         if (!account_subscribe) {
2765                 ACCOUNT_SLOGE("account is NULL.\n", __FUNCTION__, __LINE__);
2766                 return ACCOUNT_ERROR_INVALID_PARAMETER;
2767         }
2768
2769         account_subscribe_s *data = (account_subscribe_s*)calloc(1,sizeof(account_subscribe_s));
2770
2771         if(!data) {
2772                 ACCOUNT_FATAL("OUT OF MEMORY\n");
2773                 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2774         }
2775
2776         *account_subscribe = (account_subscribe_h)data;
2777
2778         return ACCOUNT_ERROR_NONE;
2779 }
2780
2781 ACCOUNT_API int account_subscribe_notification(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2782 {
2783         ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n",  __FUNCTION__, __LINE__));
2784
2785         account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2786
2787         tmp->account_subscription_callback = callback;
2788         tmp->user_data = user_data;
2789
2790         int ret = -1;
2791         ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2792                                 (vconf_callback_fn)_account_subscribe_vconf_callback,
2793                                 (void*)tmp);
2794
2795         ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2796
2797         if(ret != VCONF_OK) {
2798                 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2799                 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2800         }
2801
2802         return ACCOUNT_ERROR_NONE;
2803 }
2804
2805 ACCOUNT_API int account_unsubscribe_notification(account_subscribe_h account_subscribe)
2806 {
2807         ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n",  __FUNCTION__, __LINE__));
2808
2809         account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2810
2811         _ACCOUNT_FREE(tmp);
2812
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;
2817         }
2818
2819         return ACCOUNT_ERROR_NONE;
2820 }
2821
2822 static void _account_subscribe_vconf_callback_ex(keynode_t *key, void *user_data)
2823 {
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;
2828
2829         if(!key) {
2830                 ACCOUNT_ERROR("No subscribtion msg !!!!!\n");
2831                 return;
2832         }
2833
2834         if(!tmp) {
2835                 ACCOUNT_ERROR("user data required\n");
2836                 return;
2837         }
2838
2839         if(!memcmp(vconf_keynode_get_name(key), VCONFKEY_ACCOUNT_MSG_STR, strlen(VCONFKEY_ACCOUNT_MSG_STR)))
2840         {
2841                 vconf_key = vconf_keynode_get_str(key);
2842
2843                 if( vconf_key == NULL){
2844                         ACCOUNT_ERROR("vconf key is NULL.\n");
2845                         return;
2846                 }
2847                 msg = strdup(vconf_key);
2848
2849                 char* event_type = NULL;
2850                 char* id = NULL;
2851                 char* ptr = NULL;
2852
2853                 event_type = strtok_r(msg, ":", &ptr);
2854                 id = strtok_r(NULL, ":", &ptr);
2855
2856                 ACCOUNT_SLOGD("msg(%s), event_type(%s), id(%s)", msg, event_type, id);
2857
2858                 ACCOUNT_SNPRINTF(event_msg,sizeof(event_msg),"%s", event_type);
2859
2860                 account_id = atoi(id);
2861
2862                 if(tmp->account_subscription_callback)
2863                         tmp->account_subscription_callback(event_msg, account_id, tmp->user_data);
2864         }
2865
2866         _ACCOUNT_FREE(msg);
2867
2868 }
2869
2870 ACCOUNT_API int account_unsubscribe_notification_ex(account_subscribe_h account_subscribe)
2871 {
2872         ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n",  __FUNCTION__, __LINE__));
2873
2874         account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2875
2876         _ACCOUNT_FREE(tmp);
2877
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;
2882         }
2883
2884         return ACCOUNT_ERROR_NONE;
2885 }
2886
2887 ACCOUNT_API int account_subscribe_notification_ex(account_subscribe_h account_subscribe, account_event_cb callback, void* user_data)
2888 {
2889         ACCOUNT_RETURN_VAL((account_subscribe != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account subscribe handle is NULL.\n",  __FUNCTION__, __LINE__));
2890
2891         account_subscribe_s* tmp =(account_subscribe_s*)account_subscribe;
2892
2893         tmp->account_subscription_callback = callback;
2894         tmp->user_data = user_data;
2895
2896         int ret = -1;
2897         ret = vconf_notify_key_changed(VCONFKEY_ACCOUNT_MSG_STR,
2898                                 (vconf_callback_fn)_account_subscribe_vconf_callback_ex,
2899                                 (void*)tmp);
2900
2901         ACCOUNT_SLOGI("vconf_notify_key_changed ret = %d", ret);
2902
2903         if(ret != VCONF_OK) {
2904                 ACCOUNT_ERROR("Vconf Subscription Failed ret = %d", ret);
2905                 return ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL;
2906         }
2907
2908         return ACCOUNT_ERROR_NONE;
2909 }