[Internal: Bug fixed ] When getting profile_info from profile_id that don't exists...
[framework/system/oma-ds-agent.git] / src / agent / service-engine / se_storage.c
1 /*
2  * oma-ds-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  *   @SE_Storage.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of functions which saves and gets sync results
22  */
23
24 #include <stdlib.h>
25
26 #include <sync_agent.h>
27
28 #include "common/common_util.h"
29 #include "service-engine/se_storage.h"
30 #include "service-engine/se_common.h"
31
32 #ifndef OMADS_AGENT_LOG
33 #undef LOG_TAG
34 #define LOG_TAG "OMA_DS_SE"
35 #endif
36
37 static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type);
38 static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time);
39 static int  _convert_sync_mode_value(char* sync_mode_str);
40 static int  _convert_sync_type_value(char* sync_type_str);
41 static int  _convert_interval_value(char* interval_str);
42 static int  _convert_src_uri_value(char* src_uri_str);
43
44 static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type)
45 {
46         _INNER_FUNC_ENTER;
47
48         se_error_type_e err = SE_INTERNAL_OK;
49         bool result;
50
51         char *syncType = NULL;
52         switch (alert_type) {
53         case ALERT_SLOW_SYNC:
54                 syncType = DEFINE_ALERT_SLOW_SYNC_STR;
55                 break;
56         case ALERT_TWO_WAY:
57                 syncType = DEFINE_ALERT_TWO_WAY_STR;
58                 break;
59         case ALERT_ONE_WAY_FROM_CLIENT:
60                 syncType = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
61                 break;
62         case ALERT_ONE_WAY_FROM_SERVER:
63                 syncType = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
64                 break;
65         case ALERT_REFRESH_FROM_SERVER:
66                 syncType = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
67                 break;
68         case ALERT_REFRESH_FROM_CLIENT:
69                 syncType = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
70                 break;
71         default:
72                 break;
73         }
74
75         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, syncType, "string", "SE");
76         if (result == false) {
77                 _DEBUG_ERROR("failed in set_Config");
78                 err = SE_INTERNAL_DA_ERROR;
79                 goto error;
80         }
81
82  error:
83
84         _INNER_FUNC_EXIT;
85         return err;
86
87 }
88
89 static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time)
90 {
91         _INNER_FUNC_ENTER;
92
93         se_error_type_e err = SE_INTERNAL_OK;
94         bool result;
95
96         result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, sync_session_result, "int", "SE");
97         if (result == false) {
98                 _DEBUG_ERROR("failed in set_config");
99                 err = SE_INTERNAL_DA_ERROR;
100                 goto error;
101         }
102
103         result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, last_session_time, "int", "SE");
104         if (result == false) {
105                 _DEBUG_ERROR("failed in set_config");
106                 err = SE_INTERNAL_DA_ERROR;
107                 goto error;
108         }
109
110  error:
111
112         _INNER_FUNC_EXIT;
113         return err;
114 }
115
116 static int  _convert_sync_mode_value(char* sync_mode_str)
117 {
118         _INNER_FUNC_ENTER;
119         _DEBUG_INFO("sync_mode_str: [%s]", sync_mode_str);
120
121         int sync_mode_value = 0;
122
123         if (strcmp(sync_mode_str,DEFINE_SYNC_MODE_MANUAL) == 0){
124                 sync_mode_value = MODE_MANUAL;
125         } else if (strcmp(sync_mode_str,DEFINE_SYNC_MODE_PERIODIC) == 0){
126                 sync_mode_value = MODE_PERIODIC;
127         } else if (strcmp(sync_mode_str,DEFINE_SYNC_MODE_PUSH) == 0){
128                 sync_mode_value = MODE_PUSH;
129         } else {
130                 _DEBUG_ERROR("sync_mode_str is invalid!!");
131                 goto error;
132         }
133
134  error:
135
136         _INNER_FUNC_EXIT;
137         return sync_mode_value;
138
139 }
140
141 static int _convert_sync_type_value(char* sync_type_str)
142 {
143         _INNER_FUNC_ENTER;
144         _DEBUG_INFO("sync_type_str: [%s]", sync_type_str);
145
146         int sync_type_value = 0;
147
148         if (strcmp(sync_type_str,DEFINE_ALERT_SLOW_SYNC_STR) == 0){
149                 sync_type_value = SYNC_TYPE_FULL_SYNC;
150         } else if (strcmp(sync_type_str,DEFINE_ALERT_TWO_WAY_STR) == 0){
151                 sync_type_value = SYNC_TYPE_UPDATE_BOTH;
152         } else if (strcmp(sync_type_str,DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) == 0){
153                 sync_type_value = SYNC_TYPE_UPDATE_TO_SERVER;
154         } else if (strcmp(sync_type_str,DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) == 0){
155                 sync_type_value = SYNC_TYPE_UPDATE_TO_PHONE;
156         } else if (strcmp(sync_type_str,DEFINE_ALERT_REFRESH_FROM_SERVER_STR) == 0){
157                 sync_type_value = SYNC_TYPE_REFRESH_FROM_SERVER;
158         } else if (strcmp(sync_type_str,DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) == 0){
159                 sync_type_value = SYNC_TYPE_REFRESH_FROM_PHONE;
160         } else {
161                 _DEBUG_ERROR("sync_type_str is invalid!!");
162                 goto error;
163         }
164
165  error:
166
167         _INNER_FUNC_EXIT;
168         return sync_type_value;
169
170 }
171
172 static int _convert_interval_value(char* interval_str)
173 {
174         _INNER_FUNC_ENTER;
175         _DEBUG_INFO("interval_str: [%s]", interval_str);
176
177         int interval_value = 0;
178
179         if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_5_MINUTES_STR) == 0){
180                 interval_value = SYNC_INTERVAL_5_MINUTES;
181         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_15_MINUTES_STR) == 0){
182                 interval_value = SYNC_INTERVAL_15_MINUTES;
183         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_HOUR_STR) == 0){
184                 interval_value = SYNC_INTERVAL_1_HOUR;
185         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_4_HOURS_STR) == 0){
186                 interval_value = SYNC_INTERVAL_4_HOURS;
187         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_12_HOURS_STR) == 0){
188                 interval_value = SYNC_INTERVAL_12_HOURS;
189         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_DAY_STR) == 0){
190                 interval_value = SYNC_INTERVAL_1_DAY;
191         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_WEEK_STR) == 0){
192                 interval_value = SYNC_INTERVAL_1_WEEK;
193         } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_MONTH_STR) == 0){
194                 interval_value = SYNC_INTERVAL_1_MONTH;
195         } else {
196                 interval_value = SYNC_INTERVAL_NONE;
197                 goto error;
198         }
199
200  error:
201
202         _INNER_FUNC_EXIT;
203         return interval_value;
204
205 }
206
207 static int _convert_src_uri_value(char* src_uri_str)
208 {
209         _INNER_FUNC_ENTER;
210         _DEBUG_INFO("src_uri_str: [%s]", src_uri_str);
211
212         int src_uri_value = 0;
213
214         if (strcmp(src_uri_str,DEFINE_SOURCE_CONTACT_URI) == 0){
215                 src_uri_value = SRC_URI_CONTACT;
216         } else if (strcmp(src_uri_str,DEFINE_SOURCE_CALENDAR_URI) == 0){
217                 src_uri_value = SRC_URI_CALENDAR;
218         } else if (strcmp(src_uri_str,DEFINE_SOURCE_MEMO_URI) == 0){
219                 src_uri_value = SRC_URI_MEMO;
220         } else if (strcmp(src_uri_str,DEFINE_SOURCE_CALLLOG_URI) == 0){
221                 src_uri_value = SRC_URI_CALLLOG;
222         } else {
223                 _DEBUG_ERROR("src_uri_str is invalid!!");
224                 goto error;
225         }
226
227  error:
228
229         _INNER_FUNC_EXIT;
230         return src_uri_value;
231
232 }
233
234 se_error_type_e write_profile_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client)
235 {
236         _EXTERN_FUNC_ENTER;
237
238         se_error_type_e err = SE_INTERNAL_OK;
239
240         err = _write_sync_type(account_id, alert_type);
241         if (err != SE_INTERNAL_OK) {
242                 _DEBUG_ERROR("failed in writeSyncType");
243                 goto error;
244         }
245
246         err = _write_last_session_values(account_id, sync_session_result, last_session_time);
247         if (err != SE_INTERNAL_OK) {
248                 _DEBUG_ERROR("failed in writeLastSessionValues");
249                 goto error;
250         }
251
252         int content_type;
253         for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) {
254                 if (datastoreinfo_per_content_type[content_type] != NULL) {
255                         if (datastoreinfo_per_content_type[content_type]->client_sync_type) {
256                                 err = write_sync_resource_info(account_id, content_type, last_session_time, only_from_client,
257                                                                datastoreinfo_per_content_type[content_type]->client_sync_result, datastoreinfo_per_content_type[content_type]->server_sync_result);
258                                 if (err != SE_INTERNAL_OK) {
259                                         _DEBUG_ERROR("failed in writeSyncResourceInfo");
260                                         goto error;
261                                 }
262
263                                 err = write_sync_statistics(account_id, content_type, true, datastoreinfo_per_content_type[content_type]->server_sync_result);
264                                 if (err != SE_INTERNAL_OK) {
265                                         _DEBUG_ERROR("failed in writeSyncStatistics");
266                                         goto error;
267                                 }
268
269                                 err = write_sync_statistics(account_id, content_type, false, datastoreinfo_per_content_type[content_type]->client_sync_result);
270                                 if (err != SE_INTERNAL_OK) {
271                                         _DEBUG_ERROR("failed in writeSyncStatistics");
272                                         goto error;
273                                 }
274                         }
275                 }
276         }
277
278  error:
279
280         _EXTERN_FUNC_EXIT;
281         return err;
282 }
283
284 se_error_type_e write_sync_statistics(int account_id, int content_type, bool is_from_server, sync_result_s * sync_result)
285 {
286         _EXTERN_FUNC_ENTER;
287
288         se_error_type_e err = SE_INTERNAL_OK;
289
290         bool result;
291         char *datastore = NULL;
292         char *side = NULL;
293         char numberOfChangesPath[128];
294         char addCountPath[128];
295         char replaceCountPath[128];
296         char deleteCountPath[128];
297
298         if (content_type == TYPE_CONTACT)
299                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
300         else if (content_type == TYPE_CALENDAR)
301                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
302         else if (content_type == TYPE_MEMO)
303                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
304         else if (content_type == TYPE_CALLLOG)
305                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
306
307         if (is_from_server == true)
308                 side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER;
309         else
310                 side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT;
311
312         _DEBUG_INFO("pSyncResult->numberOfChange = %d", sync_result->number_of_change);
313         _DEBUG_INFO("pSyncResult->add_count = %d", sync_result->add_count);
314         _DEBUG_INFO("pSyncResult->replace_count = %d", sync_result->replace_count);
315         _DEBUG_INFO("pSyncResult->delete_count = %d", sync_result->delete_count);
316
317         snprintf(numberOfChangesPath, sizeof(numberOfChangesPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
318         snprintf(addCountPath, sizeof(addCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
319         snprintf(replaceCountPath, sizeof(replaceCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
320         snprintf(deleteCountPath, sizeof(deleteCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
321
322         result = set_config_int(account_id, numberOfChangesPath, sync_result->number_of_change, "int", "SE");
323         if (result == false) {
324                 _DEBUG_ERROR("failed in set_config");
325                 err = SE_INTERNAL_DA_ERROR;
326                 goto error;
327         }
328
329         result = set_config_int(account_id, addCountPath, sync_result->add_count, "int", "SE");
330         if (result == false) {
331                 _DEBUG_ERROR("failed in set_config");
332                 err = SE_INTERNAL_DA_ERROR;
333                 goto error;
334         }
335
336         result = set_config_int(account_id, replaceCountPath, sync_result->replace_count, "int", "SE");
337         if (result == false) {
338                 _DEBUG_ERROR("failed in set_config");
339                 err = SE_INTERNAL_DA_ERROR;
340                 goto error;
341         }
342
343         result = set_config_int(account_id, deleteCountPath, sync_result->delete_count, "int", "SE");
344         if (result == false) {
345                 _DEBUG_ERROR("failed in set_config");
346                 err = SE_INTERNAL_DA_ERROR;
347                 goto error;
348         }
349
350  error:
351
352         _EXTERN_FUNC_EXIT;
353         return err;
354
355 }
356
357 se_error_type_e write_sync_resource_info(int account_id, int content_type, int last_session_time, int only_from_client, sync_result_s * client_sync_result, sync_result_s * server_sync_result)
358 {
359         _EXTERN_FUNC_ENTER;
360
361         se_error_type_e err = SE_INTERNAL_OK;
362         bool result;
363         char *datastore = NULL;
364         char dbSyncedPath[128];
365         char lastSessionTimePath[128];
366
367         if (client_sync_result == NULL) {
368                 _DEBUG_ERROR("clientSyncResult is NULL");
369                 err = SE_INTERNAL_NOT_DEFINED;
370                 goto error;
371         }
372
373         if (server_sync_result == NULL) {
374                 _DEBUG_ERROR("serverSyncResult is NULL");
375                 err = SE_INTERNAL_NOT_DEFINED;
376                 goto error;
377         }
378
379         if (content_type == TYPE_CONTACT)
380                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
381         else if (content_type == TYPE_CALENDAR)
382                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
383         else if (content_type == TYPE_MEMO)
384                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
385         else if (content_type == TYPE_CALLLOG)
386                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
387
388         _DEBUG_INFO("clientSyncResult->sessionResult = %d", client_sync_result->session_result);
389         _DEBUG_INFO("serverSyncResult->sessionResult = %d", server_sync_result->session_result);
390
391         char *dbSynced;
392         if (client_sync_result->session_result == SYNC_SESSION_SUCCEEDED && (server_sync_result->session_result == SYNC_SESSION_SUCCEEDED || only_from_client))
393                 dbSynced = DEFINE_DBSYNC_SUCCESS;
394         else if (client_sync_result->session_result == SYNC_SESSION_STOPPED)
395                 dbSynced = DEFINE_DBSYNC_STOP;
396         else
397                 dbSynced = DEFINE_DBSYNC_FAIL;
398
399         _DEBUG_INFO("dbSynced = %s", dbSynced);
400
401         snprintf(dbSyncedPath, sizeof(dbSyncedPath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
402         snprintf(lastSessionTimePath, sizeof(lastSessionTimePath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
403
404         result = set_config_str(account_id, dbSyncedPath, dbSynced, "string", "SE");
405         if (result == false) {
406                 _DEBUG_ERROR("failed in set_config");
407                 err = SE_INTERNAL_DA_ERROR;
408                 goto error;
409         }
410
411         result = set_config_int(account_id, lastSessionTimePath, last_session_time, "int", "SE");
412         if (result == false) {
413                 _DEBUG_ERROR("failed in set_config");
414                 err = SE_INTERNAL_DA_ERROR;
415                 goto error;
416         }
417
418  error:
419
420         _EXTERN_FUNC_EXIT;
421         return err;
422 }
423
424 bool get_profile_data(int account_id, char **profile_dir_name, char **profile_name, char **addr, char **id, char **password, int *sync_mode, int *sync_type, int *interval, int *last_session_status, int *last_session_time)
425 {
426         _EXTERN_FUNC_ENTER;
427
428         se_error_type_e err = SE_INTERNAL_OK;
429         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
430         sync_agent_fw_account_s *fw_account = NULL;
431
432         GList *config_list = NULL;
433         GList *iter = NULL;
434         sync_agent_da_config_s *config_data = NULL;
435
436         char *sync_mode_str = NULL;
437         char *sync_type_str = NULL;
438         char *interval_str = NULL;
439         int sync_mode_value = 0;
440         int sync_type_value = 0;
441         int interval_value = 0;
442         char *lastSessionStatus_str = NULL;
443         char *lastSessionTime_str = NULL;
444
445         sync_agent_da_return_e da_err = sync_agent_open_agent();
446         if (da_err != SYNC_AGENT_DA_SUCCESS) {
447                 err = SE_INTERNAL_DA_ERROR;
448                 goto error;
449         }
450
451         acc_err = sync_agent_create_fw_account(&fw_account);
452         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
453                 _DEBUG_ERROR("failed in sync_agent_create_fw_account");
454                 err = SE_INTERNAL_NO_MEMORY;
455                 goto error;
456         }
457
458         acc_err = sync_agent_get_fw_account(account_id, &fw_account);
459         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
460                 _DEBUG_ERROR("failed in sync_agent_update_fw_account");
461                 err = SE_INTERNAL_ERROR;
462                 goto error;
463         }
464
465         if ((fw_account->account_id == 0)) {
466                 _DEBUG_ERROR("Profile don't exists!!, account_id: [%d]", account_id);
467                 err = SE_INTERNAL_ERROR;
468                 goto error;
469         }
470
471         if (fw_account->email != NULL)
472                 *id = strdup(fw_account->email);
473
474         if (fw_account->password != NULL)
475                 *password = strdup(fw_account->password);
476
477         da_err = sync_agent_get_config_list(account_id, &config_list);
478         if (da_err != SYNC_AGENT_DA_SUCCESS) {
479                 err = SE_INTERNAL_DA_ERROR;
480                 goto error;
481         }
482
483         for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
484                 config_data = (sync_agent_da_config_s *) iter->data;
485
486                 if (config_data != NULL) {
487                         if (config_data->key != NULL) {
488
489                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME) == 0) {
490                                         if (config_data->value != NULL) {
491                                                 *profile_dir_name = strdup(config_data->value);
492                                                 continue;
493                                         }
494                                 }
495
496                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) {
497                                         if (config_data->value != NULL) {
498                                                 *profile_name = strdup(config_data->value);
499                                                 continue;
500                                         }
501                                 }
502
503                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) {
504                                         if (config_data->value != NULL) {
505                                                 *addr = strdup(config_data->value);
506                                                 continue;
507                                         }
508                                 }
509
510                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) {
511                                         if (config_data->value != NULL) {
512                                                 sync_mode_str = strdup(config_data->value);
513                                                 continue;
514                                         }
515                                 }
516
517                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) {
518                                         if (config_data->value != NULL) {
519                                                 sync_type_str = strdup(config_data->value);
520                                                 continue;
521                                         }
522                                 }
523
524                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) {
525                                         if (config_data->value != NULL) {
526                                                 interval_str = strdup(config_data->value);
527                                                 continue;
528                                         }
529                                 }
530
531                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) {
532                                         if (config_data->value != NULL) {
533                                                 lastSessionStatus_str = strdup(config_data->value);
534                                                 continue;
535                                         }
536                                 }
537
538                                 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) {
539                                         if (config_data->value != NULL) {
540                                                 lastSessionTime_str = strdup(config_data->value);
541                                                 continue;
542                                         }
543                                 }
544                         }
545                 }
546         }
547
548         if (sync_mode_str != NULL) {
549                 sync_mode_value = _convert_sync_mode_value(sync_mode_str);
550                 _DEBUG_INFO("sync_mode_value: [%d]", sync_mode_value);
551                 *sync_mode = sync_mode_value;
552         }
553
554         if (sync_type_str != NULL) {
555                 sync_type_value = _convert_sync_type_value(sync_type_str);
556                 _DEBUG_INFO("sync_type_value: [%d]", sync_type_value);
557                 *sync_type = sync_type_value;
558         }
559
560         if (interval_str != NULL) {
561                 interval_value = _convert_interval_value(interval_str);
562                 _DEBUG_INFO("interval_value: [%d]", interval_value);
563                 *interval = interval_value;
564         }
565
566         if (lastSessionStatus_str != NULL)
567                 *last_session_status = atoi(lastSessionStatus_str);
568
569         if (lastSessionTime_str != NULL)
570                 *last_session_time = atoi(lastSessionTime_str);
571
572  error:
573
574         sync_agent_free_fw_account(fw_account);
575
576         sync_agent_free_config_list(config_list);
577
578         sync_agent_close_agent();
579
580         if (sync_mode_str != NULL) {
581                 free(sync_mode_str);
582                 sync_mode_str = NULL;
583         }
584
585         if (sync_type_str != NULL) {
586                 free(sync_type_str);
587                 sync_type_str = NULL;
588         }
589
590         if (interval_str != NULL) {
591                 free(interval_str);
592                 interval_str = NULL;
593         }
594
595         if (lastSessionStatus_str != NULL) {
596                 free(lastSessionStatus_str);
597                 lastSessionStatus_str = NULL;
598         }
599
600         if (lastSessionTime_str != NULL) {
601                 free(lastSessionTime_str);
602                 lastSessionTime_str = NULL;
603         }
604
605         _EXTERN_FUNC_EXIT;
606
607         if (err != SE_INTERNAL_OK)
608                 return false;
609         else
610                 return true;
611 }
612
613 bool get_profile_sync_category(int account_id, int content_type, int *enabled, int *src_uri, char **tgt_uri, char **id, char **password)
614 {
615         _EXTERN_FUNC_ENTER;
616
617         se_error_type_e err = SE_INTERNAL_OK;
618         char *datastore = NULL;
619         char *enabled_str = NULL;
620         char *src_uri_str = NULL;
621         int src_uri_value = 0;
622
623         char datastore_source[128];
624         char datastore_target[128];
625         char datastore_id[128];
626         char datastore_pw[128];
627
628         GList *config_list = NULL;
629         GList *iter = NULL;
630         sync_agent_da_config_s *config_data = NULL;
631
632         if (content_type == TYPE_CONTACT)
633                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
634         else if (content_type == TYPE_CALENDAR)
635                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
636         else if (content_type == TYPE_MEMO)
637                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
638         else if (content_type == TYPE_CALLLOG)
639                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
640
641         snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
642         snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
643         snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
644         snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
645
646         sync_agent_da_return_e da_err = sync_agent_open_agent();
647         if (da_err != SYNC_AGENT_DA_SUCCESS) {
648                 err = SE_INTERNAL_DA_ERROR;
649                 goto error;
650         }
651
652         da_err = sync_agent_get_config_list(account_id, &config_list);
653         if (da_err != SYNC_AGENT_DA_SUCCESS) {
654                 err = SE_INTERNAL_DA_ERROR;
655                 goto error;
656         }
657
658         for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
659                 config_data = (sync_agent_da_config_s *) iter->data;
660
661                 if (config_data != NULL) {
662                         if (config_data->key != NULL) {
663                                 if (datastore != NULL) {
664                                         if (strcmp(config_data->key, datastore) == 0) {
665                                                 if (config_data->value != NULL) {
666                                                         enabled_str = strdup(config_data->value);
667                                                         continue;
668                                                 }
669                                         }
670                                 } else {
671                                         _DEBUG_ERROR("datastore is NULL !!");
672                                         err = SE_INTERNAL_ERROR;
673                                         goto error;
674                                 }
675
676                                 if (strcmp(config_data->key, datastore_source) == 0) {
677                                         if (config_data->value != NULL) {
678                                                 src_uri_str = strdup(config_data->value);
679                                                 continue;
680                                         }
681                                 }
682
683                                 if (strcmp(config_data->key, datastore_target) == 0) {
684                                         if (config_data->value != NULL) {
685                                                 *tgt_uri = strdup(config_data->value);
686                                                 continue;
687                                         }
688                                 }
689
690                                 if (strcmp(config_data->key, datastore_id) == 0) {
691                                         if (config_data->value != NULL) {
692                                                 *id = strdup(config_data->value);
693                                                 continue;
694                                         }
695                                 }
696
697                                 if (strcmp(config_data->key, datastore_pw) == 0) {
698                                         if (config_data->value != NULL) {
699                                                 *password = strdup(config_data->value);
700                                                 continue;
701                                         }
702                                 }
703                         }
704                 }
705         }
706
707         if (enabled_str != NULL)
708                 *enabled = atoi(enabled_str);
709
710         if (src_uri_str != NULL) {
711                 src_uri_value = _convert_src_uri_value(src_uri_str);
712                 *src_uri = src_uri_value;
713         }
714
715  error:
716
717         sync_agent_free_config_list(config_list);
718
719         sync_agent_close_agent();
720
721         if (enabled_str != NULL) {
722                 free(enabled_str);
723                 enabled_str = NULL;
724         }
725
726         if (src_uri_str != NULL) {
727                 free(src_uri_str);
728                 src_uri_str = NULL;
729         }
730
731         _EXTERN_FUNC_EXIT;
732
733         if (err != SE_INTERNAL_OK)
734                 return false;
735         else
736                 return true;
737
738 }
739
740 bool get_profile_statistics(int account_id, int content_type, char **db_synced, int *last_session_time,
741                             int *server2client_total, int *server2client_nrofadd, int *server2client_nrofdelete, int *server2client_nrofreplace,
742                             int *client2server_total, int *client2server_nrofadd, int *client2server_nrofdelete, int *client2server_nrofreplace)
743 {
744         _EXTERN_FUNC_ENTER;
745
746         se_error_type_e err = SE_INTERNAL_OK;
747
748         char *datastore = NULL;
749         char datastore_dbsynced[128];
750         char datastore_lastsessiontime[128];
751         char datastore_s2c_total[128];
752         char datastore_s2c_add[128];
753         char datastore_s2c_replace[128];
754         char datastore_s2c_delete[128];
755         char datastore_c2s_total[128];
756         char datastore_c2s_add[128];
757         char datastore_c2s_replace[128];
758         char datastore_c2s_delete[128];
759
760         char *lastSessionTime_str = NULL;
761         char *server2Client_Total_str = NULL;
762         char *server2Client_NrOfAdd_str = NULL;
763         char *server2Client_NrOfDelete_str = NULL;
764         char *server2Client_NrOfReplace_str = NULL;
765         char *client2Server_Total_str = NULL;
766         char *client2Server_NrOfAdd_str = NULL;
767         char *client2Server_NrOfDelete_str = NULL;
768         char *client2Server_NrOfReplace_str = NULL;
769
770         GList *config_list = NULL;
771         GList *iter = NULL;
772         sync_agent_da_config_s *config_data = NULL;
773
774         if (content_type == TYPE_CONTACT)
775                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
776         else if (content_type == TYPE_CALENDAR)
777                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
778         else if (content_type == TYPE_MEMO)
779                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
780         else if (content_type == TYPE_CALLLOG)
781                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
782
783         snprintf(datastore_dbsynced, sizeof(datastore_dbsynced), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
784         snprintf(datastore_lastsessiontime, sizeof(datastore_lastsessiontime), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
785         snprintf(datastore_s2c_total, sizeof(datastore_s2c_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
786         snprintf(datastore_s2c_add, sizeof(datastore_s2c_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
787         snprintf(datastore_s2c_delete, sizeof(datastore_s2c_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
788         snprintf(datastore_s2c_replace, sizeof(datastore_s2c_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
789
790         snprintf(datastore_c2s_total, sizeof(datastore_c2s_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
791         snprintf(datastore_c2s_add, sizeof(datastore_c2s_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
792         snprintf(datastore_c2s_delete, sizeof(datastore_c2s_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
793         snprintf(datastore_c2s_replace, sizeof(datastore_c2s_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
794
795         sync_agent_da_return_e da_err = sync_agent_open_agent();
796         if (da_err != SYNC_AGENT_DA_SUCCESS) {
797                 err = SE_INTERNAL_DA_ERROR;
798                 goto error;
799         }
800
801         da_err = sync_agent_get_config_list(account_id, &config_list);
802         if (da_err != SYNC_AGENT_DA_SUCCESS) {
803                 err = SE_INTERNAL_DA_ERROR;
804                 goto error;
805         }
806
807         for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
808                 config_data = (sync_agent_da_config_s *) iter->data;
809
810                 if (config_data != NULL) {
811                         if (config_data->key != NULL) {
812                                 if (strcmp(config_data->key, datastore_dbsynced) == 0) {
813                                         if (config_data->value != NULL) {
814                                                 *db_synced = strdup(config_data->value);
815                                                 continue;
816                                         }
817                                 }
818
819                                 if (strcmp(config_data->key, datastore_lastsessiontime) == 0) {
820                                         if (config_data->value != NULL) {
821                                                 lastSessionTime_str = strdup(config_data->value);
822                                                 continue;
823                                         }
824                                 }
825
826                                 if (strcmp(config_data->key, datastore_s2c_total) == 0) {
827                                         if (config_data->value != NULL) {
828                                                 server2Client_Total_str = strdup(config_data->value);
829                                                 continue;
830                                         }
831                                 }
832
833                                 if (strcmp(config_data->key, datastore_s2c_add) == 0) {
834                                         if (config_data->value != NULL) {
835                                                 server2Client_NrOfAdd_str = strdup(config_data->value);
836                                                 continue;
837                                         }
838                                 }
839
840                                 if (strcmp(config_data->key, datastore_s2c_delete) == 0) {
841                                         if (config_data->value != NULL) {
842                                                 server2Client_NrOfDelete_str = strdup(config_data->value);
843                                                 continue;
844                                         }
845                                 }
846
847                                 if (strcmp(config_data->key, datastore_s2c_replace) == 0) {
848                                         if (config_data->value != NULL) {
849                                                 server2Client_NrOfReplace_str = strdup(config_data->value);
850                                                 continue;
851                                         }
852                                 }
853
854                                 if (strcmp(config_data->key, datastore_c2s_total) == 0) {
855                                         if (config_data->value != NULL) {
856                                                 client2Server_Total_str = strdup(config_data->value);
857                                                 continue;
858                                         }
859                                 }
860
861                                 if (strcmp(config_data->key, datastore_c2s_add) == 0) {
862                                         if (config_data->value != NULL) {
863                                                 client2Server_NrOfAdd_str = strdup(config_data->value);
864                                                 continue;
865                                         }
866                                 }
867
868                                 if (strcmp(config_data->key, datastore_c2s_delete) == 0) {
869                                         if (config_data->value != NULL) {
870                                                 client2Server_NrOfDelete_str = strdup(config_data->value);
871                                                 continue;
872                                         }
873                                 }
874
875                                 if (strcmp(config_data->key, datastore_c2s_replace) == 0) {
876                                         if (config_data->value != NULL) {
877                                                 client2Server_NrOfReplace_str = strdup(config_data->value);
878                                                 continue;
879                                         }
880                                 }
881                         }
882                 }
883         }
884
885         if (lastSessionTime_str != NULL)
886                 *last_session_time = atoi(lastSessionTime_str);
887
888         if (server2Client_Total_str != NULL)
889                 *server2client_total = atoi(server2Client_Total_str);
890
891         if (server2Client_NrOfAdd_str != NULL)
892                 *server2client_nrofadd = atoi(server2Client_NrOfAdd_str);
893
894         if (server2Client_NrOfDelete_str != NULL)
895                 *server2client_nrofdelete = atoi(server2Client_NrOfDelete_str);
896
897         if (server2Client_NrOfReplace_str != NULL)
898                 *server2client_nrofreplace = atoi(server2Client_NrOfReplace_str);
899
900         if (client2Server_Total_str != NULL)
901                 *client2server_total = atoi(client2Server_Total_str);
902
903         if (client2Server_NrOfAdd_str != NULL)
904                 *client2server_nrofadd = atoi(client2Server_NrOfAdd_str);
905
906         if (client2Server_NrOfDelete_str != NULL)
907                 *client2server_nrofdelete = atoi(client2Server_NrOfDelete_str);
908
909         if (client2Server_NrOfReplace_str != NULL)
910                 *client2server_nrofreplace = atoi(client2Server_NrOfReplace_str);
911
912  error:
913
914         sync_agent_free_config_list(config_list);
915
916         sync_agent_close_agent();
917
918         if (lastSessionTime_str != NULL)
919                 free(lastSessionTime_str);
920
921         if (server2Client_Total_str != NULL)
922                 free(server2Client_Total_str);
923
924         if (server2Client_NrOfAdd_str != NULL)
925                 free(server2Client_NrOfAdd_str);
926
927         if (server2Client_NrOfDelete_str != NULL)
928                 free(server2Client_NrOfDelete_str);
929
930         if (server2Client_NrOfReplace_str != NULL)
931                 free(server2Client_NrOfReplace_str);
932
933         if (client2Server_Total_str != NULL)
934                 free(client2Server_Total_str);
935
936         if (client2Server_NrOfAdd_str != NULL)
937                 free(client2Server_NrOfAdd_str);
938
939         if (client2Server_NrOfDelete_str != NULL)
940                 free(client2Server_NrOfDelete_str);
941
942         if (client2Server_NrOfReplace_str != NULL)
943                 free(client2Server_NrOfReplace_str);
944
945         _EXTERN_FUNC_EXIT;
946
947         if (err != SE_INTERNAL_OK)
948                 return false;
949         else
950                 return true;
951 }
952
953 bool get_all_profiles_data(GList ** list)
954 {
955         _EXTERN_FUNC_ENTER;
956
957         se_error_type_e err = SE_INTERNAL_OK;
958         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
959
960         GList *account_info_list = NULL;
961         GList *account_iter = NULL;
962         sync_agent_fw_account_s *fw_account = NULL;
963
964         GList *config_list = NULL;
965         GList *iter = NULL;
966         sync_agent_da_config_s *config_data = NULL;
967
968         sync_agent_ds_profile_info *profile_info = NULL;
969         GList *account_list = NULL;
970         GList *free_iter = NULL;
971
972         sync_agent_ds_service_info *category_info = NULL;
973         char* sync_mode_str = NULL;
974         char* sync_type_str = NULL;
975         char* interval_str = NULL;
976         char* src_uri_str = NULL;
977         int sync_mode_value = 0;
978         int sync_type_value = 0;
979         int interval_value = 0;
980         int src_uri_value = 0;
981
982         sync_agent_da_return_e da_err = sync_agent_open_agent();
983         if (da_err != SYNC_AGENT_DA_SUCCESS) {
984                 err = SE_INTERNAL_DA_ERROR;
985                 goto error;
986         }
987
988         sync_agent_fw_account_query_s query;
989         query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
990         query.access_name = "SE";
991
992         acc_err = sync_agent_query_fw_account(&query, &account_info_list);
993         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
994                 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
995                 goto error;
996         }
997
998         for (account_iter = account_info_list; account_iter != NULL; account_iter = g_list_next(account_iter)) {
999                 fw_account = (sync_agent_fw_account_s *) account_iter->data;
1000
1001                 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
1002                 if (profile_info == NULL) {
1003                         _DEBUG_ERROR("profile_info is NULL");
1004                         goto error;
1005                 }
1006
1007                 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1008                 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1009
1010                 if (fw_account->email != NULL)
1011                         server_info->id = strdup(fw_account->email);
1012
1013                 if (fw_account->password != NULL)
1014                         server_info->password = strdup(fw_account->password);
1015
1016                 da_err = sync_agent_get_config_list(fw_account->account_id, &config_list);
1017                 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1018                         err = SE_INTERNAL_DA_ERROR;
1019                         goto error;
1020                 }
1021
1022                 for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
1023                         config_data = (sync_agent_da_config_s *) iter->data;
1024
1025                         if (config_data != NULL) {
1026                                 if (config_data->key != NULL) {
1027
1028                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_ID) == 0) {
1029                                                 if (config_data->value != NULL) {
1030                                                         profile_info->profile_id = atoi(config_data->value);
1031                                                         continue;
1032                                                 }
1033                                         }
1034
1035                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME) == 0) {
1036                                                 if (config_data->value != NULL) {
1037                                                         profile_info->profile_dir_name = strdup(config_data->value);
1038                                                         continue;
1039                                                 }
1040                                         }
1041
1042                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) {
1043                                                 if (config_data->value != NULL) {
1044                                                         profile_info->profile_name = strdup(config_data->value);
1045                                                         continue;
1046                                                 }
1047                                         }
1048
1049                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) {
1050                                                 if (config_data->value != NULL) {
1051                                                         server_info->addr = strdup(config_data->value);
1052                                                         continue;
1053                                                 }
1054                                         }
1055
1056                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) {
1057                                                 if (config_data->value != NULL) {
1058                                                         sync_mode_str = strdup(config_data->value);
1059                                                         sync_mode_value = _convert_sync_mode_value(sync_mode_str);
1060                                                         _DEBUG_INFO("sync_mode_value: [%d]", sync_mode_value);
1061                                                         sync_info->sync_mode = sync_mode_value;
1062                                                         continue;
1063                                                 }
1064                                         }
1065
1066                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) {
1067                                                 if (config_data->value != NULL) {
1068                                                         sync_type_str = strdup(config_data->value);
1069                                                         sync_type_value = _convert_sync_type_value(sync_type_str);
1070                                                         _DEBUG_INFO("sync_type_value: [%d]", sync_type_value);
1071                                                         sync_info->sync_type = sync_type_value;
1072                                                         continue;
1073                                                 }
1074                                         }
1075
1076                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) {
1077                                                 if (config_data->value != NULL) {
1078                                                         interval_str = strdup(config_data->value);
1079                                                         interval_value = _convert_interval_value(interval_str);
1080                                                         _DEBUG_INFO("interval_value: [%d]", interval_value);
1081                                                         sync_info->interval =interval_value;
1082                                                         continue;
1083                                                 }
1084                                         }
1085
1086                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) {
1087                                                 if (config_data->value != NULL) {
1088                                                         profile_info->last_sync_status = atoi(config_data->value);
1089                                                         continue;
1090                                                 }
1091                                         }
1092
1093                                         if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) {
1094                                                 if (config_data->value != NULL) {
1095                                                         profile_info->last_sync_time = atoi(config_data->value);
1096                                                         continue;
1097                                                 }
1098                                         }
1099                                 }
1100                         }
1101                 }
1102
1103                 int content_type;
1104                 for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) {
1105
1106                         category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1107                         if (category_info == NULL) {
1108                                 _DEBUG_ERROR("category_info is NULL");
1109                                 goto error;
1110                         }
1111
1112                         char *datastore = NULL;
1113
1114                         char datastore_source[128];
1115                         char datastore_target[128];
1116                         char datastore_id[128];
1117                         char datastore_pw[128];
1118
1119                         if (content_type == TYPE_CONTACT) {
1120                                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
1121                                 category_info->service_type = SYNC_AGENT_CONTACT;
1122                         } else if (content_type == TYPE_CALENDAR) {
1123                                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
1124                                 category_info->service_type = SYNC_AGENT_CALENDAR;
1125                         } else if (content_type == TYPE_MEMO) {
1126                                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
1127                                 category_info->service_type = SYNC_AGENT_MEMO;
1128                         } else if (content_type == TYPE_CALLLOG) {
1129                                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
1130                                 category_info->service_type = SYNC_AGENT_CALLLOG;
1131                         }
1132
1133                         snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
1134                         snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
1135                         snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
1136                         snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
1137
1138                         for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
1139                                 config_data = (sync_agent_da_config_s *) iter->data;
1140
1141                                 if (config_data != NULL) {
1142                                         if (config_data->key != NULL) {
1143                                                 if (strcmp(config_data->key, datastore) == 0) {
1144                                                         if (config_data->value != NULL) {
1145                                                                 category_info->enabled = atoi(config_data->value);
1146                                                                 continue;
1147                                                         }
1148                                                 }
1149
1150                                                 if (strcmp(config_data->key, datastore_source) == 0) {
1151                                                         if (config_data->value != NULL) {
1152                                                                 src_uri_str = strdup(config_data->value);
1153                                                                 src_uri_value = _convert_src_uri_value(src_uri_str);
1154                                                                 _DEBUG_INFO("src_uri_value: [%d]", src_uri_value);
1155                                                                 category_info->src_uri = src_uri_value;
1156                                                                 continue;
1157                                                         }
1158                                                 }
1159
1160                                                 if (strcmp(config_data->key, datastore_target) == 0) {
1161                                                         if (config_data->value != NULL) {
1162                                                                 category_info->tgt_uri = strdup(config_data->value);
1163                                                                 continue;
1164                                                         }
1165                                                 }
1166
1167                                                 if (strcmp(config_data->key, datastore_id) == 0) {
1168                                                         if (config_data->value != NULL) {
1169                                                                 category_info->id = strdup(config_data->value);
1170                                                                 continue;
1171                                                         }
1172                                                 }
1173
1174                                                 if (strcmp(config_data->key, datastore_pw) == 0) {
1175                                                         if (config_data->value != NULL) {
1176                                                                 category_info->password = strdup(config_data->value);
1177                                                                 continue;
1178                                                         }
1179                                                 }
1180                                         }
1181                                 }
1182                         }
1183
1184                         profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1185                         category_info = NULL;
1186                 }
1187
1188                 sync_agent_free_config_list(config_list);
1189                 config_list = NULL;
1190
1191                 account_list = g_list_append(account_list, profile_info);
1192                 profile_info = NULL;
1193         }
1194
1195         *list = account_list;
1196         account_list = NULL;
1197
1198  error:
1199
1200         if (sync_mode_str != NULL) {
1201                 free(sync_mode_str);
1202                 sync_mode_str = NULL;
1203         }
1204
1205         if (sync_type_str != NULL) {
1206                 free(sync_type_str);
1207                 sync_type_str = NULL;
1208         }
1209
1210         if (interval_str != NULL) {
1211                 free(interval_str);
1212                 interval_str = NULL;
1213         }
1214
1215         if (src_uri_str != NULL) {
1216                 free(src_uri_str);
1217                 src_uri_str = NULL;
1218         }
1219
1220         for (free_iter = account_list; free_iter != NULL; free_iter = g_list_next(free_iter)) {
1221                 sync_agent_ds_free_profile_info((ds_profile_h) free_iter->data);
1222                 _DEBUG_INFO("free sync_agent_ds_profile_info");
1223         }
1224
1225         if (profile_info != NULL) {
1226                 free(profile_info);
1227                 profile_info = NULL;
1228         }
1229
1230         sync_agent_free_fw_account_list(account_info_list);
1231
1232         sync_agent_free_config_list(config_list);
1233
1234         sync_agent_close_agent();
1235
1236         _EXTERN_FUNC_EXIT;
1237
1238         if (err != SE_INTERNAL_OK)
1239                 return false;
1240         else
1241                 return true;
1242 }