Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / service-engine / se_account.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_Account.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of account in Service Engine
22  */
23
24 #include <sync_agent.h>
25 #include <plugin/plugin_slp_sysnoti_alarm.h>
26
27 #include "common/csc_keys.h"
28 #include "common/common_vconf.h"
29 #include "common/common_define.h"
30 #include "common/common_util.h"
31 #include "framework/event/oma_ds_platform_event_handler.h"
32 #include "service-engine/se_account.h"
33 #include "service-engine/se_error.h"
34 #include "service-engine/se_common.h"
35 #include "service-engine/se_notification.h"
36
37 #ifndef OMADS_AGENT_LOG
38 #undef LOG_TAG
39 #define LOG_TAG "OMA_DS_SE"
40 #endif
41
42 #define MAX_DATASTORE_COUNT 3
43
44 typedef struct {
45         char *serverName;
46         int index;
47 } datastore_cp_info;
48
49 static char *predefinedDatastore[][MAX_DATASTORE_COUNT][2] = {
50         {{"contacts", "text/x-vcard"}, {"calendar", "text/x-vcalendar"}, {"notes", "text/plain"}},
51         {{"Contacts", "text/x-vcard"}, {"Calendar", "text/x-vcalendar"}, {"Notes", "text/plain"}}
52 };
53
54 static datastore_cp_info predefinedServer[] = {
55         {"O3SIS SyncML", 0},
56         {"Everdroid", 1}
57 };
58
59 static se_error_type_e _add_profile(char *addr, char *id, char *password, char *access_name, int *account_id);
60 static se_error_type_e _set_profile_info(int account_id, char *profile_name, char *sync_mode, char *sync_type, char *interval);
61 static se_error_type_e _set_profile_category(int account_id, sync_service_s * category);
62 static se_error_type_e _set_periodic_sync_config(int account_id, char *sync_mode, char *interval);
63 static se_error_type_e _get_empty_profile_dir_name(char **empty_profile_dir_name);
64
65 static se_error_type_e _set_profile_info_into_config_list(int account_id, char *profile_dir_name, char *addr, char *profile_name, char *sync_mode, char *sync_type, char *interval, char *nonce, char *server_id, GList ** config_list);
66 static se_error_type_e _set_profile_category_info(int account_id, sync_service_s * category, GList ** config_list);
67 static se_error_type_e _set_profile_category_info_csc(int account_id, int content_type, int index, GList ** config_list);
68 static se_error_type_e _set_profile_category_info_cp(int account_id, int content_type, resource_cp_s * category, GList ** config_list);
69 static se_error_type_e __set_profile_category_info_into_cofnig_list(int account_id, int content_type, int enabled, char *src_uri, char *tgt_uri, char *id, char *password, GList ** config_list);
70 static se_error_type_e ___append_config_value(int account_id, char *key, char *value, char *type, char *access_name, GList ** list);
71
72 static se_error_type_e _add_profile(char *addr, char *id, char *password, char *access_name, int *account_id)
73 {
74         _INNER_FUNC_ENTER;
75
76         se_error_type_e err = SE_INTERNAL_OK;
77         sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
78         sync_agent_fw_account_s *fw_account = NULL;
79
80         int account;
81         char *folderID = NULL;
82
83         account_err = sync_agent_create_fw_account(&fw_account);
84         if (account_err != SYNC_AGENT_ACC_SUCCESS) {
85                 _DEBUG_ERROR("sync_agent_create_fw_account is fail");
86                 err = SE_INTERNAL_ERROR;
87                 goto error;
88         }
89
90         fw_account->email = strdup(id);
91         fw_account->password = strdup(password);
92         fw_account->enable = 1;
93         fw_account->access_name = strdup(access_name);
94
95         account_err = sync_agent_add_fw_account(fw_account, &account);
96         if (account_err != SYNC_AGENT_ACC_SUCCESS) {
97                 _DEBUG_ERROR("sync_agent_add_fw_account is fail");
98                 err = SE_INTERNAL_ERROR;
99                 goto error;
100         }
101
102         _DEBUG_TRACE("account_id = %d", account);
103
104         if (account < 0) {
105                 _DEBUG_ERROR("account_id = %d", account);
106                 err = SE_INTERNAL_ERROR;
107                 goto error;
108         }
109
110         folderID = sync_agent_generate_folder_luid();
111         if (folderID == NULL) {
112                 _DEBUG_ERROR("failed in sync_agent_generate_folder_luid");
113                 err = SE_INTERNAL_DA_ERROR;
114                 goto error;
115         }
116
117         sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
118         sync_agent_da_folder_s *folder = NULL;
119         ret = sync_agent_create_folder(&folder);
120         if (ret != SYNC_AGENT_DA_SUCCESS) {
121                 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
122                 goto error;
123         }
124
125         folder->account_id = account;
126         folder->folder_id = strdup(folderID);
127         folder->data_store_id = TYPE_CONTACT;
128         folder->folder_type_id = 0;     /* Default contacts folder */
129         folder->parent_folder_id = NULL;
130         folder->service_id = strdup("0");
131         folder->access_name = strdup("EventHandler");
132
133         char *new_folder_id = NULL;
134         ret = sync_agent_add_folder(folder, &new_folder_id);
135         sync_agent_free_folder(folder);
136         folder = NULL;
137         if (ret != SYNC_AGENT_DA_SUCCESS) {
138                 _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!");
139                 _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!");
140                 err = SE_INTERNAL_ERROR;
141                 goto error;
142         }
143
144         _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
145
146         if (folderID != NULL) {
147                 free(folderID);
148                 folderID = NULL;
149         }
150
151         if (new_folder_id != NULL) {
152                 free(new_folder_id);
153                 new_folder_id = NULL;
154         }
155
156         folderID = sync_agent_generate_folder_luid();
157         if (folderID == NULL) {
158                 _DEBUG_ERROR("failed in sync_agent_generate_folder_luid");
159                 err = SE_INTERNAL_DA_ERROR;
160                 goto error;
161         }
162
163         ret = sync_agent_create_folder(&folder);
164         if (ret != SYNC_AGENT_DA_SUCCESS) {
165                 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
166                 goto error;
167         }
168
169         folder->account_id = account;
170         folder->folder_id = strdup(folderID);
171         folder->data_store_id = TYPE_CALENDAR;
172         folder->folder_type_id = 0;     /* Default contacts folder */
173         folder->parent_folder_id = NULL;
174         folder->service_id = strdup("1");
175         folder->access_name = strdup("EventHandler");
176
177         ret = sync_agent_add_folder(folder, &new_folder_id);
178         sync_agent_free_folder(folder);
179         folder = NULL;
180
181         if (ret != SYNC_AGENT_DA_SUCCESS) {
182                 _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!");
183                 _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!");
184                 err = SE_INTERNAL_ERROR;
185                 goto error;
186         }
187
188         _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
189
190         if (folderID != NULL) {
191                 free(folderID);
192                 folderID = NULL;
193         }
194
195         if (new_folder_id != NULL) {
196                 free(new_folder_id);
197                 new_folder_id = NULL;
198         }
199
200         folderID = sync_agent_generate_folder_luid();
201         if (folderID == NULL) {
202                 _DEBUG_ERROR("failed in sync_agent_generate_folder_luid");
203                 err = SE_INTERNAL_DA_ERROR;
204                 goto error;
205         }
206
207         ret = sync_agent_create_folder(&folder);
208         if (ret != SYNC_AGENT_DA_SUCCESS) {
209                 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
210                 goto error;
211         }
212
213         folder->account_id = account;
214         folder->folder_id = strdup(folderID);
215         folder->data_store_id = TYPE_MEMO;
216         folder->folder_type_id = 0;     /* Default contacts folder */
217         folder->parent_folder_id = NULL;
218         folder->service_id = strdup("0");
219         folder->access_name = strdup("EventHandler");
220
221         ret = sync_agent_add_folder(folder, &new_folder_id);
222         sync_agent_free_folder(folder);
223         folder = NULL;
224
225         if (ret != SYNC_AGENT_DA_SUCCESS) {
226                 _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!");
227                 _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!");
228                 err = SE_INTERNAL_ERROR;
229                 goto error;
230         }
231
232         _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
233
234         if (folderID != NULL) {
235                 free(folderID);
236                 folderID = NULL;
237         }
238
239         if (new_folder_id != NULL) {
240                 free(new_folder_id);
241                 new_folder_id = NULL;
242         }
243
244         /* call log folder ID */
245         folderID = sync_agent_generate_folder_luid();
246         if (folderID == NULL) {
247                 _DEBUG_ERROR("failed in sync_agent_generate_folder_luid");
248                 err = SE_INTERNAL_DA_ERROR;
249                 goto error;
250         }
251
252         ret = sync_agent_create_folder(&folder);
253         if (ret != SYNC_AGENT_DA_SUCCESS) {
254                 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
255                 goto error;
256         }
257
258         folder->account_id = account;
259         folder->folder_id = strdup(folderID);
260         folder->data_store_id = TYPE_CALLLOG;
261         folder->folder_type_id = 0;     /* Default contacts folder */
262         folder->parent_folder_id = NULL;
263         folder->service_id = strdup("0");
264         folder->access_name = strdup("EventHandler");
265
266         ret = sync_agent_add_folder(folder, &new_folder_id);
267         sync_agent_free_folder(folder);
268         folder = NULL;
269
270         if (ret != SYNC_AGENT_DA_SUCCESS) {
271                 _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!");
272                 _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!");
273                 err = SE_INTERNAL_ERROR;
274                 goto error;
275         }
276
277         _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
278
279         if (folderID != NULL) {
280                 free(folderID);
281                 folderID = NULL;
282         }
283
284         if (new_folder_id != NULL) {
285                 free(new_folder_id);
286                 new_folder_id = NULL;
287         }
288
289         *account_id = account;
290
291  error:
292
293         if (folderID != NULL)
294                 free(folderID);
295
296         sync_agent_free_fw_account(fw_account);
297
298         _INNER_FUNC_EXIT;
299         return err;
300 }
301
302 static se_error_type_e _set_profile_info(int account_id, char *profile_name, char *sync_mode, char *sync_type, char *interval)
303 {
304         _INNER_FUNC_ENTER;
305
306         se_error_type_e err = SE_INTERNAL_OK;
307         bool result;
308
309         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_NAME, profile_name, "string", "SE");
310         if (result == false) {
311                 _DEBUG_ERROR("failed in set_config");
312                 err = SE_INTERNAL_DA_ERROR;
313                 goto error;
314         }
315
316         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, sync_mode, "string", "SE");
317         if (result == false) {
318                 _DEBUG_ERROR("failed in set_config");
319                 err = SE_INTERNAL_DA_ERROR;
320                 goto error;
321         }
322
323         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, sync_type, "string", "SE");
324         if (result == false) {
325                 _DEBUG_ERROR("failed in set_config");
326                 err = SE_INTERNAL_DA_ERROR;
327                 goto error;
328         }
329
330         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, sync_type, "string", "SE");
331         if (result == false) {
332                 _DEBUG_ERROR("failed in set_config");
333                 err = SE_INTERNAL_DA_ERROR;
334                 goto error;
335         }
336
337         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
338         if (result == false) {
339                 _DEBUG_ERROR("failed in set_config");
340                 err = SE_INTERNAL_DA_ERROR;
341                 goto error;
342         }
343
344  error:
345
346         _INNER_FUNC_EXIT;
347         return err;
348 }
349
350 static se_error_type_e _set_profile_category(int account_id, sync_service_s * category)
351 {
352         _INNER_FUNC_ENTER;
353
354         _DEBUG_TRACE("category->content_type : %d", category->service_type);
355         _DEBUG_TRACE("category->enabled : %d", category->enabled);
356         _DEBUG_TRACE("category->src_uri : %s", category->src_uri);
357         _DEBUG_TRACE("category->tgt_uri : %s", category->tgt_uri);
358         _DEBUG_TRACE("category->id : %s", category->id);
359         _DEBUG_TRACE("category->password : %s", category->password);
360
361         se_error_type_e err = SE_INTERNAL_OK;
362         bool result;
363
364         char *datastore = NULL;
365         char datastore_target[128];
366         char datastore_source[128];
367         char datastore_id[128];
368         char datastore_pw[128];
369
370         if (category->service_type == TYPE_CONTACT)
371                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
372         else if (category->service_type == TYPE_CALENDAR)
373                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
374         else if (category->service_type == TYPE_MEMO)
375                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
376         else if (category->service_type == TYPE_CALLLOG)
377                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
378
379         snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
380         snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
381         snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
382         snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
383
384         result = set_config_int(account_id, datastore, category->enabled, "int", "SE");
385         if (result == false) {
386                 _DEBUG_ERROR("failed in set_config");
387                 err = SE_INTERNAL_DA_ERROR;
388                 goto error;
389         }
390
391         result = set_config_str(account_id, datastore_source, category->src_uri, "string", "SE");
392         if (result == false) {
393                 _DEBUG_ERROR("failed in set_config");
394                 err = SE_INTERNAL_DA_ERROR;
395                 goto error;
396         }
397
398         result = set_config_str(account_id, datastore_target, category->tgt_uri, "string", "SE");
399         if (result == false) {
400                 _DEBUG_ERROR("failed in set_config");
401                 err = SE_INTERNAL_DA_ERROR;
402                 goto error;
403         }
404
405         result = set_config_str(account_id, datastore_id, category->id, "string", "SE");
406         if (result == false) {
407                 _DEBUG_ERROR("failed in set_config");
408                 err = SE_INTERNAL_DA_ERROR;
409                 goto error;
410         }
411
412         result = set_config_str(account_id, datastore_pw, category->password, "string", "SE");
413         if (result == false) {
414                 _DEBUG_ERROR("failed in set_config");
415                 err = SE_INTERNAL_DA_ERROR;
416                 goto error;
417         }
418
419  error:
420
421         _INNER_FUNC_EXIT;
422         return err;
423
424 }
425
426 static se_error_type_e _set_periodic_sync_config(int account_id, char *sync_mode, char *interval)
427 {
428         _INNER_FUNC_ENTER;
429         _DEBUG_TRACE("sync_mode = %s", sync_mode);
430
431         se_error_type_e err = SE_INTERNAL_OK;
432         sync_agent_pm_return_e scheduler_err;
433         bool result;
434         char *value = NULL;
435         int alarm_id = 0;
436
437         pmci_alarm_s *alarm_info = (pmci_alarm_s *) calloc(1, sizeof(pmci_alarm_s));
438         if (alarm_info == NULL) {
439                 _DEBUG_ERROR("alarm_info is NULL");
440                 err = SE_INTERNAL_NO_MEMORY;
441                 goto error;
442         }
443
444         result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
445         if (result == false) {
446                 _DEBUG_ERROR("failed in set_config");
447                 err = SE_INTERNAL_DA_ERROR;
448                 goto error;
449         }
450
451         alarm_id = atoi(value);
452
453         if (alarm_id != 0) {
454                 scheduler_err = sync_agent_remove_service_data(1, alarm_id);
455                 if (scheduler_err != SYNC_AGENT_PM_SUCCESS) {
456                         _DEBUG_ERROR("failed in sync_agent_remove_service_data");
457                         err = SE_INTERNAL_SCHEDULER_ERROR;
458                         goto error;
459                 }
460         }
461
462         if (strcmp(sync_mode, DEFINE_SYNC_MODE_PERIODIC) == 0 && interval != NULL) {
463
464                 result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, DEFINE_ALERT_TWO_WAY_STR, "string", "SE");
465                 if (result == false) {
466                         _DEBUG_ERROR("failed in set_config");
467                         err = SE_INTERNAL_DA_ERROR;
468                         goto error;
469                 }
470
471                 int week[] = { DAY_SUN, DAY_MON, DAY_TUE, DAY_WED, DAY_THU, DAY_FRI, DAY_SAT };
472                 time_t current_time;
473                 struct tm *struct_time;
474                 time(&current_time);
475                 struct_time = localtime(&current_time);
476                 if (struct_time == NULL) {
477                         _DEBUG_ERROR("struct_time is NULL");
478                         err = SE_INTERNAL_ERROR;;
479                         goto error;
480                 }
481
482                 alarm_info->start_alarm_time = g_strdup_printf("%.2d-%.2d-%.2dT%.2d:%.2d:%.2dZ", struct_time->tm_year + 1900, struct_time->tm_mon + 1, struct_time->tm_mday, struct_time->tm_hour, struct_time->tm_min, struct_time->tm_sec);
483                 alarm_info->is_disposable = 0;
484
485                 if (strcmp(interval, "5 minutes") == 0) {
486                         _DEBUG_TRACE("5 minutes");
487                         alarm_info->repeat_type = REPEAT;
488                         alarm_info->repeat_value = 5 * 60;
489                 } else if (strcmp(interval, "15 minutes") == 0) {
490                         _DEBUG_TRACE("15 minutes");
491                         alarm_info->repeat_type = REPEAT;
492                         alarm_info->repeat_value = 15 * 60;
493                 } else if (strcmp(interval, "1 hour") == 0) {
494                         _DEBUG_TRACE("1 hour");
495                         alarm_info->repeat_type = REPEAT;
496                         alarm_info->repeat_value = ((1 * 60) * 60);
497                 } else if (strcmp(interval, "4 hours") == 0) {
498                         _DEBUG_TRACE("4 hours");
499                         alarm_info->repeat_type = REPEAT;
500                         alarm_info->repeat_value = ((4 * 60) * 60);
501                 } else if (strcmp(interval, "12 hours") == 0) {
502                         _DEBUG_TRACE("12 hours");
503                         alarm_info->repeat_type = REPEAT;
504                         alarm_info->repeat_value = ((12 * 60) * 60);
505                 } else if (strcmp(interval, "1 day") == 0) {
506                         _DEBUG_TRACE("1 day");
507                         alarm_info->repeat_type = REPEAT;
508                         alarm_info->repeat_value = ((24 * 60) * 60);
509                 } else if (strcmp(interval, "1 week") == 0) {
510                         _DEBUG_TRACE("1 week");
511                         alarm_info->repeat_type = REPEAT_WEEKLY;
512                         alarm_info->repeat_value = week[struct_time->tm_wday];
513                 }
514
515                 scheduler_err = sync_agent_add_service_data(1, alarm_info, &alarm_id);
516                 if (scheduler_err != SYNC_AGENT_PM_SUCCESS) {
517                         _DEBUG_ERROR("failed in sync_agent_add_service_data");
518                         err = SE_INTERNAL_SCHEDULER_ERROR;
519                         goto error;
520                 }
521                 _DEBUG_TRACE("alarm_id =%d", alarm_id);
522
523                 result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, alarm_id, "int", "SE");
524                 if (result == false) {
525                         _DEBUG_ERROR("failed in set_config");
526                         err = SE_INTERNAL_DA_ERROR;
527                         goto error;
528                 }
529
530         } else {
531                 result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
532                 if (result == false) {
533                         _DEBUG_ERROR("failed in set_config");
534                         err = SE_INTERNAL_DA_ERROR;
535                         goto error;
536                 }
537         }
538
539  error:
540
541         if (value != NULL)
542                 free(value);
543
544         if (alarm_info != NULL) {
545                 if (alarm_info->start_alarm_time != NULL)
546                         free(alarm_info->start_alarm_time);
547
548                 free(alarm_info);
549         }
550
551         _INNER_FUNC_EXIT;
552         return err;
553 }
554
555 static se_error_type_e _set_profile_info_into_config_list(int account_id, char *profile_dir_name, char *addr, char *profile_name, char *sync_mode, char *sync_type, char *interval, char *nonce, char *server_id, GList ** config_list)
556 {
557         _INNER_FUNC_ENTER;
558
559         se_error_type_e err = SE_INTERNAL_OK;
560         bool result;
561
562         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile_dir_name, "string", "SE", config_list);
563         if (result == false) {
564                 _DEBUG_ERROR("failed in _append_config_value");
565                 err = SE_INTERNAL_DA_ERROR;
566                 goto error;
567         }
568
569         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE", config_list);
570         if (result == false) {
571                 _DEBUG_ERROR("failed in _append_config_value");
572                 err = SE_INTERNAL_DA_ERROR;
573                 goto error;
574         }
575
576         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_NAME, profile_name, "string", "SE", config_list);
577         if (result == false) {
578                 _DEBUG_ERROR("failed in _append_config_value");
579                 err = SE_INTERNAL_DA_ERROR;
580                 goto error;
581         }
582
583         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, sync_mode != NULL ? sync_mode : "Push", "string", "SE", config_list);
584         if (result == false) {
585                 _DEBUG_ERROR("failed in _append_config_value");
586                 err = SE_INTERNAL_DA_ERROR;
587                 goto error;
588         }
589
590         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, sync_type != NULL ? sync_type : "Full", "string", "SE", config_list);
591         if (result == false) {
592                 _DEBUG_ERROR("failed in _append_config_value");
593                 err = SE_INTERNAL_DA_ERROR;
594                 goto error;
595         }
596
597         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, sync_type != NULL ? sync_type : "Full", "string", "SE", config_list);
598         if (result == false) {
599                 _DEBUG_ERROR("failed in _append_config_value");
600                 err = SE_INTERNAL_DA_ERROR;
601                 goto error;
602         }
603
604         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval != NULL ? interval : "5 minutes", "string", "SE", config_list);
605         if (result == false) {
606                 _DEBUG_ERROR("failed in _append_config_value");
607                 err = SE_INTERNAL_DA_ERROR;
608                 goto error;
609         }
610
611         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, nonce, "string", "SE", config_list);
612         if (result == false) {
613                 _DEBUG_ERROR("failed in _append_config_value");
614                 err = SE_INTERNAL_DA_ERROR;
615                 goto error;
616         }
617
618         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, server_id, "string", "SE", config_list);
619         if (result == false) {
620                 _DEBUG_ERROR("failed in _append_config_value");
621                 err = SE_INTERNAL_DA_ERROR;
622                 goto error;
623         }
624
625         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, "-1", "int", "SE", config_list);
626         if (result == false) {
627                 _DEBUG_ERROR("failed in _append_config_value");
628                 err = SE_INTERNAL_DA_ERROR;
629                 goto error;
630         }
631
632         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, "-1", "int", "SE", config_list);
633         if (result == false) {
634                 _DEBUG_ERROR("failed in _append_config_value");
635                 err = SE_INTERNAL_DA_ERROR;
636                 goto error;
637         }
638
639         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE", config_list);
640         if (result == false) {
641                 _DEBUG_ERROR("failed in _append_config_value");
642                 err = SE_INTERNAL_DA_ERROR;
643                 goto error;
644         }
645
646         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "0", "int", "SE", config_list);
647         if (result == false) {
648                 _DEBUG_ERROR("failed in _append_config_value");
649                 err = SE_INTERNAL_DA_ERROR;
650                 goto error;
651         }
652
653         result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_RESUME, "0", "int", "SE", config_list);
654         if (result == false) {
655                 _DEBUG_ERROR("failed in _append_config_value");
656                 err = SE_INTERNAL_DA_ERROR;
657                 goto error;
658         }
659
660  error:
661
662         _INNER_FUNC_EXIT;
663         return err;
664 }
665
666 static se_error_type_e _set_profile_category_info(int account_id, sync_service_s * category, GList ** config_list)
667 {
668         _INNER_FUNC_ENTER;
669
670         retvm_if(category == NULL, SE_INTERNAL_NOT_DEFINED, "category is NULL");
671
672         se_error_type_e err = SE_INTERNAL_OK;
673         err = __set_profile_category_info_into_cofnig_list(account_id, category->service_type, category->enabled, category->src_uri, category->tgt_uri, category->id, category->password, config_list);
674         if (err != SE_INTERNAL_OK) {
675                 _DEBUG_ERROR("failed in _set_profile_category_info_into_cofnig_list");
676                 goto error;
677         }
678
679  error:
680
681         _INNER_FUNC_EXIT;
682         return err;
683 }
684
685 static se_error_type_e _set_profile_category_info_csc(int account_id, int content_type, int index, GList ** config_list)
686 {
687         _INNER_FUNC_ENTER;
688
689         se_error_type_e err = SE_INTERNAL_OK;
690
691         char *is_enabled_path = NULL;
692         char *target_uri_path = NULL;
693         char *id_path = NULL;
694         char *pwd_path = NULL;
695
696         char *datastore = NULL;
697
698         int is_enabled = 0;
699         char *target_uri = NULL;
700         char *id = NULL;
701         char *pwd = NULL;
702         char profile_path[128];
703
704         char *source_uri = NULL;
705
706         bool result;
707
708         if (content_type == TYPE_CONTACT) {
709                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
710                 source_uri = DEFINE_SOURCE_CONTACT_URI;
711                 is_enabled_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED;
712                 target_uri_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI;
713                 id_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME;
714                 pwd_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD;
715         } else if (content_type == TYPE_CALENDAR) {
716                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
717                 source_uri = DEFINE_SOURCE_CALENDAR_URI;
718                 is_enabled_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED;
719                 target_uri_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI;
720                 id_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME;
721                 pwd_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD;
722         } else if (content_type == TYPE_MEMO) {
723                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
724                 source_uri = DEFINE_SOURCE_MEMO_URI;
725                 is_enabled_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED;
726                 target_uri_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI;
727                 id_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME;
728                 pwd_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD;
729         } else if (content_type == TYPE_CALLLOG) {
730                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
731                 source_uri = DEFINE_SOURCE_CALLLOG_URI;
732         } else {
733                 err = SE_INTERNAL_ERROR;
734                 _DEBUG_ERROR("No content type");
735                 goto error;
736         }
737
738         if (content_type != TYPE_CALLLOG) {
739                 snprintf(profile_path, sizeof(profile_path), is_enabled_path, index);
740                 result = get_vconf_int_key(profile_path, &is_enabled);
741                 if (result == false) {
742                         _DEBUG_ERROR("No value in vconf key = %s", profile_path);
743                         goto error;
744                 }
745
746                 snprintf(profile_path, sizeof(profile_path), target_uri_path, index);
747                 target_uri = get_vconf_str_key(profile_path);
748
749                 snprintf(profile_path, sizeof(profile_path), id_path, index);
750                 id = get_vconf_str_key(profile_path);
751
752                 snprintf(profile_path, sizeof(profile_path), pwd_path, index);
753                 pwd = get_vconf_str_key(profile_path);
754         }
755
756         err = __set_profile_category_info_into_cofnig_list(account_id, content_type, is_enabled, source_uri, target_uri, id, pwd, config_list);
757         if (err != SE_INTERNAL_OK) {
758                 _DEBUG_ERROR("failed in _set_profile_category_info_into_cofnig_list");
759                 goto error;
760         }
761
762  error:
763
764         if (target_uri != NULL)
765                 free(target_uri);
766
767         if (id != NULL)
768                 free(id);
769
770         if (pwd != NULL)
771                 free(pwd);
772
773         _INNER_FUNC_EXIT;
774         return err;
775
776 }
777
778 static se_error_type_e _set_profile_category_info_cp(int account_id, int content_type, resource_cp_s * category, GList ** config_list)
779 {
780         _INNER_FUNC_ENTER;
781
782         retvm_if(category == NULL, SE_INTERNAL_NOT_DEFINED, "category is NULL");
783
784         se_error_type_e err = SE_INTERNAL_OK;
785         char *sourceuri = NULL;
786
787         if (content_type == TYPE_CONTACT)
788                 sourceuri = DEFINE_SOURCE_CONTACT_URI;
789         else if (content_type == TYPE_CALENDAR)
790                 sourceuri = DEFINE_SOURCE_CALENDAR_URI;
791         else if (content_type == TYPE_MEMO)
792                 sourceuri = DEFINE_SOURCE_MEMO_URI;
793         else if (content_type == TYPE_CALLLOG)
794                 sourceuri = DEFINE_SOURCE_CALLLOG_URI;
795         else {
796                 err = SE_INTERNAL_ERROR;
797                 _DEBUG_ERROR("No content type");
798                 goto error;
799         }
800
801         err = __set_profile_category_info_into_cofnig_list(account_id, content_type, 0, sourceuri, category->name, category->id, category->password, config_list);
802         if (err != SE_INTERNAL_OK) {
803                 _DEBUG_ERROR("failed in _set_profile_category_info_into_cofnig_list");
804                 goto error;
805         }
806
807  error:
808
809         _INNER_FUNC_EXIT;
810         return err;
811
812 }
813
814 static se_error_type_e __set_profile_category_info_into_cofnig_list(int account_id, int content_type, int enabled, char *src_uri, char *tgt_uri, char *id, char *password, GList ** config_list)
815 {
816         _INNER_FUNC_ENTER;
817
818         se_error_type_e err = SE_INTERNAL_OK;
819         bool result;
820         char *enable = NULL;
821
822         char *datastore = NULL;
823         char datastore_target[128];
824         char datastore_source[128];
825         char datastore_id[128];
826         char datastore_pw[128];
827
828         char datastore_dbSynced[128];
829         char datastore_lastSessionTime[128];
830         char datastore_s2c_Total[128];
831         char datastore_s2c_NrOfAdd[128];
832         char datastore_s2c_NrOfDelete[128];
833         char datastore_s2c_NrOfReplace[128];
834         char datastore_c2s_Total[128];
835         char datastore_c2s_NrOfAdd[128];
836         char datastore_c2s_NrOfDelete[128];
837         char datastore_c2s_NrOfReplace[128];
838
839         if (content_type == TYPE_CONTACT)
840                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
841         else if (content_type == TYPE_CALENDAR)
842                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
843         else if (content_type == TYPE_MEMO)
844                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
845         else if (content_type == TYPE_CALLLOG)
846                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
847
848         snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
849         snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
850         snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
851         snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
852
853         snprintf(datastore_dbSynced, sizeof(datastore_dbSynced), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
854         snprintf(datastore_lastSessionTime, sizeof(datastore_lastSessionTime), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
855
856         snprintf(datastore_s2c_Total, sizeof(datastore_s2c_Total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
857         snprintf(datastore_s2c_NrOfAdd, sizeof(datastore_s2c_NrOfAdd), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
858         snprintf(datastore_s2c_NrOfDelete, sizeof(datastore_s2c_NrOfDelete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
859         snprintf(datastore_s2c_NrOfReplace, sizeof(datastore_s2c_NrOfReplace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
860
861         snprintf(datastore_c2s_Total, sizeof(datastore_c2s_Total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
862         snprintf(datastore_c2s_NrOfAdd, sizeof(datastore_c2s_NrOfAdd), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
863         snprintf(datastore_c2s_NrOfDelete, sizeof(datastore_c2s_NrOfDelete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
864         snprintf(datastore_c2s_NrOfReplace, sizeof(datastore_c2s_NrOfReplace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
865
866         enable = g_strdup_printf("%u", enabled);
867         result = ___append_config_value(account_id, datastore, enable, "int", "SE", config_list);
868         if (result == false) {
869                 _DEBUG_ERROR("failed in create_config_str");
870                 err = SE_INTERNAL_DA_ERROR;
871                 goto error;
872         }
873
874         result = ___append_config_value(account_id, datastore_source, src_uri, "string", "SE", config_list);
875         if (result == false) {
876                 _DEBUG_ERROR("failed in create_config_str");
877                 err = SE_INTERNAL_DA_ERROR;
878                 goto error;
879         }
880
881         result = ___append_config_value(account_id, datastore_target, tgt_uri, "string", "SE", config_list);
882         if (result == false) {
883                 _DEBUG_ERROR("failed in create_config_str");
884                 err = SE_INTERNAL_DA_ERROR;
885                 goto error;
886         }
887
888         result = ___append_config_value(account_id, datastore_id, id, "string", "SE", config_list);
889         if (result == false) {
890                 _DEBUG_ERROR("failed in create_config_str");
891                 err = SE_INTERNAL_DA_ERROR;
892                 goto error;
893         }
894
895         result = ___append_config_value(account_id, datastore_pw, password, "string", "SE", config_list);
896         if (result == false) {
897                 _DEBUG_ERROR("failed in create_config_str");
898                 err = SE_INTERNAL_DA_ERROR;
899                 goto error;
900         }
901
902         result = ___append_config_value(account_id, datastore_dbSynced, DEFINE_DBSYNC_NO, "string", "SE", config_list);
903         if (result == false) {
904                 _DEBUG_ERROR("failed in create_config_str");
905                 err = SE_INTERNAL_DA_ERROR;
906                 goto error;
907         }
908
909         result = ___append_config_value(account_id, datastore_lastSessionTime, "-1", "int", "SE", config_list);
910         if (result == false) {
911                 _DEBUG_ERROR("failed in create_config_str");
912                 err = SE_INTERNAL_DA_ERROR;
913                 goto error;
914         }
915
916         result = ___append_config_value(account_id, datastore_s2c_Total, 0, "int", "SE", config_list);
917         if (result == false) {
918                 _DEBUG_ERROR("failed in create_config_str");
919                 err = SE_INTERNAL_DA_ERROR;
920                 goto error;
921         }
922
923         result = ___append_config_value(account_id, datastore_s2c_NrOfAdd, 0, "int", "SE", config_list);
924         if (result == false) {
925                 _DEBUG_ERROR("failed in create_config_str");
926                 err = SE_INTERNAL_DA_ERROR;
927                 goto error;
928         }
929
930         result = ___append_config_value(account_id, datastore_s2c_NrOfDelete, 0, "int", "SE", config_list);
931         if (result == false) {
932                 _DEBUG_ERROR("failed in create_config_str");
933                 err = SE_INTERNAL_DA_ERROR;
934                 goto error;
935         }
936
937         result = ___append_config_value(account_id, datastore_s2c_NrOfReplace, 0, "int", "SE", config_list);
938         if (result == false) {
939                 _DEBUG_ERROR("failed in create_config_str");
940                 err = SE_INTERNAL_DA_ERROR;
941                 goto error;
942         }
943
944         result = ___append_config_value(account_id, datastore_c2s_Total, 0, "int", "SE", config_list);
945         if (result == false) {
946                 _DEBUG_ERROR("failed in create_config_str");
947                 err = SE_INTERNAL_DA_ERROR;
948                 goto error;
949         }
950
951         result = ___append_config_value(account_id, datastore_c2s_NrOfAdd, 0, "int", "SE", config_list);
952         if (result == false) {
953                 _DEBUG_ERROR("failed in create_config_str");
954                 err = SE_INTERNAL_DA_ERROR;
955                 goto error;
956         }
957
958         result = ___append_config_value(account_id, datastore_c2s_NrOfDelete, 0, "int", "SE", config_list);
959         if (result == false) {
960                 _DEBUG_ERROR("failed in create_config_str");
961                 err = SE_INTERNAL_DA_ERROR;
962                 goto error;
963         }
964
965         result = ___append_config_value(account_id, datastore_c2s_NrOfReplace, 0, "int", "SE", config_list);
966         if (result == false) {
967                 _DEBUG_ERROR("failed in create_config_str");
968                 err = SE_INTERNAL_DA_ERROR;
969                 goto error;
970         }
971
972  error:
973
974         if (enable != NULL)
975                 free(enable);
976
977         _INNER_FUNC_EXIT;
978         return err;
979 }
980
981 static se_error_type_e ___append_config_value(int account_id, char *key, char *value, char *type, char *access_name, GList ** list)
982 {
983         _INNER_FUNC_ENTER;
984         se_error_type_e err = SE_INTERNAL_OK;
985
986         bool result;
987
988         sync_agent_da_config_s *config = NULL;
989
990         result = create_config_str(account_id, key, value, type, access_name, &config);
991         if (result == false) {
992                 _DEBUG_ERROR("failed in create_config_str");
993                 err = SE_INTERNAL_DA_ERROR;
994                 goto error;
995         }
996
997         if (config != NULL) {
998                 *list = g_list_append(*list, config);
999                 config = NULL;
1000         }
1001
1002  error:
1003
1004         _INNER_FUNC_EXIT;
1005         return err;
1006 }
1007
1008 static se_error_type_e _get_empty_profile_dir_name(char **empty_profile_dir_name)
1009 {
1010         _INNER_FUNC_ENTER;
1011         se_error_type_e err = SE_INTERNAL_OK;
1012
1013         bool result;
1014         char *profileDirName = NULL;
1015         int profile[MAXIMUM_ACCOUNT_COUNT] = { 0 };
1016         char profileIndex[2];
1017         int index;
1018         int i;
1019
1020         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1021         sync_agent_fw_account_s *fw_account = NULL;
1022         GList *account_info_list = NULL;
1023         GList *iter = NULL;
1024
1025         sync_agent_fw_account_query_s query;
1026         query.query = ACCOUNT_QUERY_BY_NONE;
1027
1028         acc_err = sync_agent_query_fw_account(&query, &account_info_list);
1029         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1030                 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
1031                 goto error;
1032         }
1033
1034         for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1035                 fw_account = (sync_agent_fw_account_s *) iter->data;
1036
1037                 if (profileDirName != NULL) {
1038                         free(profileDirName);
1039                         profileDirName = NULL;
1040                 }
1041
1042                 result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
1043                 if (result == false) {
1044                         _DEBUG_ERROR("failed in get_Config");
1045                         err = SE_INTERNAL_DA_ERROR;
1046                         goto error;
1047                 }
1048
1049                 _DEBUG_TRACE("profile_Dir_name = %s", profileDirName);
1050                 if (profileDirName == NULL)
1051                         continue;
1052
1053                 strcpy(profileIndex, profileDirName + strlen(profileDirName) - 1);
1054                 _DEBUG_TRACE("profileIndex = %s", profileIndex);
1055
1056                 index = atoi(profileIndex);
1057                 profile[index - 1] = 1;
1058         }
1059
1060         for (i = 0; i < MAXIMUM_ACCOUNT_COUNT; i++) {
1061                 if (profile[i] != 1) {
1062                         *empty_profile_dir_name = g_strdup_printf("Sync%d", i + 1);
1063                         break;
1064                 }
1065         }
1066
1067  error:
1068
1069         sync_agent_free_fw_account_list(account_info_list);
1070
1071         if (profileDirName != NULL)
1072                 free(profileDirName);
1073
1074         _INNER_FUNC_EXIT;
1075         return err;
1076 }
1077
1078 bool add_profile(char *profile_dir_name, char *profile_name, char *addr, char *id, char *password, char *sync_mode, char *sync_type, char *interval, GList * categories, int *account_id)
1079 {
1080         _EXTERN_FUNC_ENTER;
1081
1082         _DEBUG_INFO("profile_name = %s", profile_name);
1083         _DEBUG_INFO("addr = %s", addr);
1084         _DEBUG_INFO("id = %s", id);
1085         _DEBUG_INFO("password = %s", password);
1086         _DEBUG_INFO("sync_mode = %s", sync_mode);
1087         _DEBUG_INFO("sync_type = %s", sync_type);
1088         _DEBUG_INFO("interval = %s", interval);
1089
1090         se_error_type_e err = SE_INTERNAL_OK;
1091         int account = -1;
1092         GList *config_list = NULL;
1093
1094         sync_agent_da_return_e da_err = sync_agent_open_agent();
1095         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1096                 err = SE_INTERNAL_DA_ERROR;
1097                 goto error;
1098         }
1099
1100         err = _add_profile(addr, id, password, "SE", &account);
1101         if (err != SE_INTERNAL_OK) {
1102                 _DEBUG_ERROR("failed in add_Account");
1103                 goto error;
1104         }
1105
1106         err = _set_profile_info_into_config_list(account, profile_dir_name, addr, profile_name, sync_mode, sync_type, interval, NULL, NULL, &config_list);
1107         if (err != SE_INTERNAL_OK) {
1108                 _DEBUG_ERROR("failed in add_Account");
1109                 goto error;
1110         }
1111
1112         sync_service_s *category = NULL;
1113         GList *iter = NULL;
1114         for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
1115                 category = iter->data;
1116                 err = _set_profile_category_info(account, category, &config_list);
1117                 if (err != SE_INTERNAL_OK) {
1118                         _DEBUG_ERROR("failed in __set_profile_category");
1119                         goto error;
1120                 }
1121         }
1122
1123         da_err = sync_agent_add_config_list(config_list);
1124         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1125                 err = SE_INTERNAL_DA_ERROR;
1126                 goto error;
1127         }
1128
1129         err = _set_periodic_sync_config(account, sync_mode, interval);
1130         if (err != SE_INTERNAL_OK) {
1131                 _DEBUG_ERROR("failed in _set_periodic_sync_config");
1132                 goto error;
1133         }
1134
1135         *account_id = account;
1136
1137  error:
1138
1139         sync_agent_free_config_list(config_list);
1140
1141         sync_agent_close_agent();
1142
1143         _DEBUG_INFO("err = %d", err);
1144
1145         _EXTERN_FUNC_EXIT;
1146
1147         if (err != SE_INTERNAL_OK)
1148                 return false;
1149         else
1150                 return true;
1151 }
1152
1153 bool add_profile_csc(int index)
1154 {
1155         _EXTERN_FUNC_ENTER;
1156
1157         se_error_type_e err = SE_INTERNAL_OK;
1158         char profile_path[128];
1159         char *profile_dir_name = NULL;
1160         char *profile_name = NULL;
1161         char *id = NULL;
1162         char *password = NULL;
1163         char *server_ip = NULL;
1164         char *sync_mode = NULL;
1165         char *sync_type = NULL;
1166         int account_id;
1167
1168         GList *config_list = NULL;
1169
1170         sync_agent_da_return_e da_err = sync_agent_open_agent();
1171         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1172                 err = SE_INTERNAL_DA_ERROR;
1173                 goto error;
1174         }
1175
1176         err = _get_empty_profile_dir_name(&profile_dir_name);
1177         if (err != SE_INTERNAL_OK) {
1178                 _DEBUG_ERROR("failed in __get_empty_profileDirName");
1179                 goto error;
1180         }
1181
1182         if (profile_dir_name == NULL) {
1183                 _DEBUG_ERROR("Maximum profiles count is %d, no more profile", MAXIMUM_ACCOUNT_COUNT);
1184                 err = SE_INTERNAL_ERROR;
1185                 goto error;
1186         }
1187
1188         snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_AUTHNAME, index);
1189         id = get_vconf_str_key(profile_path);
1190
1191         snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_AUTHPWD, index);
1192         password = get_vconf_str_key(profile_path);
1193
1194         snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_ADDR, index);
1195         server_ip = get_vconf_str_key(profile_path);
1196
1197         snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_NAME, index);
1198         profile_name = get_vconf_str_key(profile_path);
1199
1200         snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_SYNCMODE, index);
1201         sync_mode = get_vconf_str_key(profile_path);
1202
1203         snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE, index);
1204         sync_type = get_vconf_str_key(profile_path);
1205
1206         _DEBUG_INFO("email = %s", id);
1207         _DEBUG_INFO("password = %s", password);
1208         _DEBUG_INFO("serverIP = %s", server_ip);
1209         _DEBUG_INFO("profileName = %s", profile_name);
1210         _DEBUG_INFO("syncMode = %s", sync_mode);
1211         _DEBUG_INFO("syncType = %s", sync_type);
1212
1213         err = _add_profile(server_ip, id, password, "SE", &account_id);
1214         if (err != SE_INTERNAL_OK) {
1215                 _DEBUG_ERROR("failed in add_Account");
1216                 goto error;
1217         }
1218
1219         err = _set_profile_info_into_config_list(account_id, profile_dir_name, server_ip, profile_name, sync_mode, sync_type, NULL, NULL, NULL, &config_list);
1220         if (err != SE_INTERNAL_OK) {
1221                 _DEBUG_ERROR("failed in add_Account");
1222                 goto error;
1223         }
1224
1225         int content_type;
1226         for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) {
1227                 err = _set_profile_category_info_csc(account_id, content_type, index, &config_list);
1228                 if (err != SE_INTERNAL_OK) {
1229                         _DEBUG_ERROR("failed in set_DatastoreConfig");
1230                         goto error;
1231                 }
1232         }
1233
1234         da_err = sync_agent_add_config_list(config_list);
1235         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1236                 err = SE_INTERNAL_DA_ERROR;
1237                 goto error;
1238         }
1239
1240  error:
1241
1242         if (profile_dir_name != NULL)
1243                 free(profile_dir_name);
1244         if (profile_name != NULL)
1245                 free(profile_name);
1246         if (id != NULL)
1247                 free(id);
1248         if (password != NULL)
1249                 free(password);
1250         if (server_ip != NULL)
1251                 free(server_ip);
1252         if (sync_mode != NULL)
1253                 free(sync_mode);
1254         if (sync_type != NULL)
1255                 free(sync_type);
1256
1257         sync_agent_free_config_list(config_list);
1258
1259         sync_agent_close_agent();
1260
1261         _EXTERN_FUNC_EXIT;
1262
1263         if (err != SE_INTERNAL_OK)
1264                 return false;
1265         else
1266                 return true;
1267 }
1268
1269 bool add_profile_cp(char *profile_name, char *addr, char *id, char *password, GList * categories, int *account_id)
1270 {
1271         _EXTERN_FUNC_ENTER;
1272
1273         _DEBUG_INFO("profilename = %s", profile_name);
1274         _DEBUG_INFO("addr = %s", addr);
1275         _DEBUG_INFO("id = %s", id);
1276         _DEBUG_INFO("password = %s", password);
1277
1278         se_error_type_e err = SE_INTERNAL_OK;
1279         int account = -1;
1280
1281         char *profile_dir_name = NULL;
1282         GList *config_list = NULL;
1283
1284         sync_agent_da_return_e da_err = sync_agent_open_agent();
1285         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1286                 err = SE_INTERNAL_DA_ERROR;
1287                 goto error;
1288         }
1289
1290         err = _get_empty_profile_dir_name(&profile_dir_name);
1291         if (err != SE_INTERNAL_OK) {
1292                 _DEBUG_ERROR("failed in __get_empty_profileDirName");
1293                 goto error;
1294         }
1295
1296         if (profile_dir_name == NULL) {
1297                 _DEBUG_ERROR("Maximum profiles count is %d, no more profile", MAXIMUM_ACCOUNT_COUNT);
1298                 err = SE_INTERNAL_ERROR;
1299                 goto error;
1300         }
1301
1302         err = _add_profile(addr, id, password, "SE", &account);
1303         if (err != SE_INTERNAL_OK) {
1304                 _DEBUG_ERROR("failed in add_Account");
1305                 goto error;
1306         }
1307
1308         err = _set_profile_info_into_config_list(account, profile_dir_name, addr, profile_name, NULL, NULL, NULL, NULL, NULL, &config_list);
1309         if (err != SE_INTERNAL_OK) {
1310                 _DEBUG_ERROR("failed in add_Account");
1311                 goto error;
1312         }
1313
1314         int i;
1315         int cnt = (int)sizeof(predefinedServer) / sizeof(datastore_cp_info);
1316         _DEBUG_INFO("cnt = %d", cnt);
1317         for (i = 0; i < cnt; i++) {
1318
1319                 _DEBUG_INFO("predefinedServer[%d].serverName = %s", i, predefinedServer[i].serverName);
1320                 if (strcmp(predefinedServer[i].serverName, profile_name) == 0) {
1321
1322                         int j;
1323                         for (j = 0; j < MAX_DATASTORE_COUNT; j++) {
1324                                 resource_cp_s *category = NULL;
1325                                 GList *iter = NULL;
1326                                 _DEBUG_INFO("categories length = %d", g_list_length(categories));
1327                                 for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
1328                                         category = (resource_cp_s *) iter->data;
1329                                         _DEBUG_INFO("category->name = %s", category->name);
1330                                         _DEBUG_INFO("category->accept = %s", category->accept);
1331
1332                                         _DEBUG_INFO("predefinedDatastore[i][j][0] = %s", predefinedDatastore[i][j][0]);
1333                                         _DEBUG_INFO("predefinedDatastore[i][j][1] = %s", predefinedDatastore[i][j][1]);
1334
1335                                         if (predefinedDatastore[i][j][0] != NULL && category->name != NULL && predefinedDatastore[i][j][1] != NULL && category->accept != NULL) {
1336
1337                                                 if (strcasecmp(predefinedDatastore[i][j][0], category->name) == 0 && strcmp(predefinedDatastore[i][j][1], category->accept) == 0) {
1338
1339                                                         err = _set_profile_category_info_cp(account, j, category, &config_list);
1340                                                         if (err != SE_INTERNAL_OK) {
1341                                                                 _DEBUG_ERROR("failed in __set_profile_category");
1342                                                                 goto error;
1343                                                         }
1344                                                         break;
1345                                                 }
1346                                         }
1347                                 }
1348                         }
1349                 }
1350         }
1351
1352         da_err = sync_agent_add_config_list(config_list);
1353         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1354                 err = SE_INTERNAL_DA_ERROR;
1355                 goto error;
1356         }
1357
1358         *account_id = account;
1359
1360  error:
1361
1362         if (profile_dir_name != NULL)
1363                 free(profile_dir_name);
1364
1365         sync_agent_free_config_list(config_list);
1366
1367         sync_agent_close_agent();
1368
1369         _EXTERN_FUNC_EXIT;
1370
1371         if (err != SE_INTERNAL_OK)
1372                 return false;
1373         else
1374                 return true;
1375 }
1376
1377 bool add_profile_dive(int *account_id)
1378 {
1379         _EXTERN_FUNC_ENTER;
1380
1381         se_error_type_e err = SE_INTERNAL_OK;
1382         sync_agent_dev_return_e dci_err = SYNC_AGENT_DEV_RETURN_SUCCESS;
1383         char *id = NULL;
1384         char *password = NULL;
1385         char *encoded_nextnonce = NULL;
1386         int account = -1;
1387
1388         GList *config_list = NULL;
1389
1390         sync_agent_da_return_e da_err = sync_agent_open_agent();
1391         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1392                 err = SE_INTERNAL_DA_ERROR;
1393                 goto error;
1394         }
1395
1396         /* FIXME  get id from somewhere */
1397         id = "ss.linux.test@gmail.com";
1398
1399         /*get IMEI from Platform */
1400         dci_err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &password);
1401         if (dci_err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
1402                 _DEBUG_ERROR("failed to get devinfo");
1403                 goto error;
1404         }
1405
1406         err = _add_profile(DEFINE_DIVE_SERVER_URL_HTTPS, id, password, "DIVE", &account);
1407         if (err != SE_INTERNAL_OK) {
1408                 _DEBUG_ERROR("failed in add_Account");
1409                 goto error;
1410         }
1411
1412         encoded_nextnonce = g_base64_encode((unsigned char *)DEFINE_DIVE_DEFAULT_NEXT_NONCE, strlen(DEFINE_DIVE_DEFAULT_NEXT_NONCE));
1413
1414         err = _set_profile_info_into_config_list(account, NULL, DEFINE_DIVE_SERVER_URL_HTTPS, NULL, NULL, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR, NULL, encoded_nextnonce, DEFINE_DIVE_SERVER_ID, &config_list);
1415         if (err != SE_INTERNAL_OK) {
1416                 _DEBUG_ERROR("failed in add_Account");
1417                 goto error;
1418         }
1419
1420         /*set calllog config value */
1421         __set_profile_category_info_into_cofnig_list(account, TYPE_CALLLOG, 1, DEFINE_SOURCE_CALLLOG_URI, "./CallLog", NULL, NULL, &config_list);
1422
1423         da_err = sync_agent_add_config_list(config_list);
1424         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1425                 err = SE_INTERNAL_DA_ERROR;
1426                 goto error;
1427         }
1428
1429         *account_id = account;
1430
1431  error:
1432
1433         if (password != NULL)
1434                 free(password);
1435
1436         sync_agent_free_config_list(config_list);
1437
1438         sync_agent_close_agent();
1439
1440         _EXTERN_FUNC_EXIT;
1441
1442         if (err != SE_INTERNAL_OK)
1443                 return false;
1444         else
1445                 return true;
1446 }
1447
1448 bool edit_profile(int account_id, char *profile_name, char *addr, char *id, char *password, char *sync_mode, char *sync_type, char *interval, GList * categories)
1449 {
1450         _EXTERN_FUNC_ENTER;
1451
1452         se_error_type_e err = SE_INTERNAL_OK;
1453         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1454         sync_agent_fw_account_s *fw_account = NULL;
1455         bool result;
1456
1457         sync_agent_da_return_e da_err = sync_agent_open_agent();
1458         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1459                 err = SE_INTERNAL_DA_ERROR;
1460                 goto error;
1461         }
1462
1463         acc_err = sync_agent_create_fw_account(&fw_account);
1464         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1465                 err = SE_INTERNAL_ERROR;
1466                 goto error;
1467         }
1468
1469         fw_account->account_id = account_id;
1470         fw_account->email = strdup(id);
1471         fw_account->password = strdup(password);
1472         fw_account->enable = 1;
1473         fw_account->access_name = strdup("SE");
1474
1475         acc_err = sync_agent_update_fw_account(fw_account);
1476         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1477                 err = SE_INTERNAL_DA_ERROR;
1478                 goto error;
1479         }
1480
1481         result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
1482         if (result == false) {
1483                 _DEBUG_ERROR("failed in set_config");
1484                 err = SE_INTERNAL_DA_ERROR;
1485                 goto error;
1486         }
1487
1488         err = _set_profile_info(account_id, profile_name, sync_mode, sync_type, interval);
1489         if (err != SE_INTERNAL_OK) {
1490                 _DEBUG_ERROR("failed in __set_profile_info");
1491                 goto error;
1492         }
1493
1494         err = _set_periodic_sync_config(account_id, sync_mode, interval);
1495         if (err != SE_INTERNAL_OK) {
1496                 _DEBUG_ERROR("failed in __set_profile_info");
1497                 goto error;
1498         }
1499
1500         sync_service_s *category = NULL;
1501         GList *iter = NULL;
1502         for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
1503                 category = iter->data;
1504                 err = _set_profile_category(account_id, category);
1505                 if (err != SE_INTERNAL_OK) {
1506                         _DEBUG_ERROR("failed in __set_profile_category");
1507                         goto error;
1508                 }
1509         }
1510
1511  error:
1512
1513         sync_agent_free_fw_account(fw_account);
1514
1515         sync_agent_close_agent();
1516
1517         _EXTERN_FUNC_EXIT;
1518
1519         if (err != SE_INTERNAL_OK)
1520                 return false;
1521         else
1522                 return true;
1523 }
1524
1525 bool delete_profiles(GList * profiles)
1526 {
1527         _EXTERN_FUNC_ENTER;
1528
1529         se_error_type_e err = SE_INTERNAL_OK;
1530         int *accountId = 0;
1531         char *value = NULL;
1532
1533         sync_agent_da_return_e da_err = sync_agent_open_agent();
1534         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1535                 err = SE_INTERNAL_DA_ERROR;
1536                 goto error;
1537         }
1538
1539         GList *iter = NULL;
1540         int alarmId = 0;
1541
1542         bool result;
1543         for (iter = profiles; iter != NULL; iter = g_list_next(iter)) {
1544                 accountId = (int *)(iter->data);
1545
1546                 if (accountId != NULL) {
1547                         _DEBUG_INFO("accountId = %d", *accountId);
1548                         /*if deleteing Account's sync mode is periodic sync it has to be deleted from schedule_tbl */
1549                         result = get_config(*accountId, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
1550                         if (result == false) {
1551                                 _DEBUG_ERROR("failed in get_config");
1552                                 err = SE_INTERNAL_DA_ERROR;
1553                                 goto error;
1554                         }
1555                         alarmId = atoi(value);
1556                         if (alarmId != 0) {
1557                                 sync_agent_pm_return_e scheduler_err = sync_agent_remove_service_data(1, alarmId);
1558                                 if (scheduler_err != SYNC_AGENT_PM_SUCCESS) {
1559                                         _DEBUG_ERROR("failed in sync_agent_remove_service_data");
1560                                         err = SE_INTERNAL_SCHEDULER_ERROR;
1561                                         goto error;
1562                                 }
1563                         }
1564                         sync_agent_delete_fw_account(*accountId);
1565                         if (accountId != 0) {
1566                                 free(accountId);
1567                                 accountId = 0;
1568                         }
1569                 } else {
1570                         _DEBUG_ERROR("accountId is NULL !");
1571                 }
1572         }
1573
1574  error:
1575
1576         if (value != NULL)
1577                 free(value);
1578
1579         if (accountId != NULL)
1580                 free(accountId);
1581
1582         sync_agent_close_agent();
1583
1584         _EXTERN_FUNC_EXIT;
1585
1586         if (err != SE_INTERNAL_OK)
1587                 return false;
1588         else
1589                 return true;
1590 }
1591
1592 bool delete_profile_dive()
1593 {
1594         _EXTERN_FUNC_ENTER;
1595
1596         se_error_type_e err = SE_INTERNAL_OK;
1597
1598         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1599         GList *account_info_list = NULL;
1600         GList *iter = NULL;
1601         sync_agent_fw_account_s *account_info = NULL;
1602
1603         sync_agent_da_return_e da_err = sync_agent_open_agent();
1604         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1605                 _DEBUG_ERROR("failed in sync_agent_open_agent");
1606                 err = SE_INTERNAL_DA_ERROR;
1607                 goto error;
1608         }
1609
1610         sync_agent_fw_account_query_s query;
1611         query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
1612         query.access_name = "DIVE";
1613
1614         acc_err = sync_agent_query_fw_account(&query, &account_info_list);
1615
1616         for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1617                 account_info = (sync_agent_fw_account_s *) iter->data;
1618                 _DEBUG_INFO("accountId = %d", account_info->account_id);
1619                 sync_agent_delete_fw_account(account_info->account_id);
1620         }
1621
1622  error:
1623
1624         sync_agent_free_fw_account_list(account_info_list);
1625
1626         sync_agent_close_agent();
1627
1628         _EXTERN_FUNC_EXIT;
1629
1630         if (err != SE_INTERNAL_OK)
1631                 return false;
1632         else
1633                 return true;
1634 }
1635
1636 bool delete_profile(char *access_name)
1637 {
1638         _EXTERN_FUNC_ENTER;
1639
1640         se_error_type_e err = SE_INTERNAL_OK;
1641
1642         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1643         GList *account_info_list = NULL;
1644         GList *iter = NULL;
1645         sync_agent_fw_account_s *account_info = NULL;
1646
1647         sync_agent_da_return_e da_err = sync_agent_open_agent();
1648         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1649                 _DEBUG_ERROR("failed in sync_agent_open_agent");
1650                 err = SE_INTERNAL_DA_ERROR;
1651                 goto error;
1652         }
1653
1654         sync_agent_fw_account_query_s query;
1655         query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
1656         query.access_name = access_name;
1657
1658         /*delete account */
1659         acc_err = sync_agent_query_fw_account(&query, &account_info_list);
1660
1661         for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1662                 account_info = (sync_agent_fw_account_s *) iter->data;
1663                 _DEBUG_INFO("accountId = %d", account_info->account_id);
1664                 sync_agent_delete_fw_account(account_info->account_id);
1665         }
1666
1667  error:
1668
1669         sync_agent_free_fw_account_list(account_info_list);
1670
1671         sync_agent_close_agent();
1672
1673         _EXTERN_FUNC_EXIT;
1674
1675         if (err != SE_INTERNAL_OK)
1676                 return false;
1677         else
1678                 return true;
1679 }
1680
1681 bool delete_all_profiles()
1682 {
1683         _EXTERN_FUNC_ENTER;
1684
1685         se_error_type_e err = SE_INTERNAL_OK;
1686
1687         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1688         sync_agent_fw_account_s *fw_account = NULL;
1689         GList *account_info_list = NULL;
1690         GList *iter = NULL;
1691
1692         int alarm_id = 0;
1693         bool result;
1694         char *value = NULL;
1695
1696         sync_agent_da_return_e da_err = sync_agent_open_agent();
1697         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1698                 err = SE_INTERNAL_DA_ERROR;
1699                 goto error;
1700         }
1701
1702         sync_agent_fw_account_query_s query;
1703         query.query = ACCOUNT_QUERY_BY_NONE;
1704
1705         acc_err = sync_agent_query_fw_account(&query, &account_info_list);
1706         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1707                 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
1708                 goto error;
1709         }
1710
1711         for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1712                 fw_account = (sync_agent_fw_account_s *) iter->data;
1713
1714                 _DEBUG_INFO("accountId = %d", fw_account->account_id);
1715                 /*if deleteing Account's sync mode is periodic sync it has to be deleted from schedule_tbl */
1716                 result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
1717                 if (result == false) {
1718                         _DEBUG_ERROR("failed in get_config");
1719                         err = SE_INTERNAL_DA_ERROR;
1720                         goto error;
1721                 }
1722
1723                 if (value != NULL) {
1724                         alarm_id = atoi(value);
1725                         if (alarm_id != 0) {
1726                                 sync_agent_pm_return_e scheduler_err = sync_agent_remove_service_data(1, alarm_id);
1727                                 if (scheduler_err != SYNC_AGENT_PM_SUCCESS) {
1728                                         _DEBUG_ERROR("failed in sync_agent_remove_service_data");
1729                                         err = SE_INTERNAL_SCHEDULER_ERROR;
1730                                         goto error;
1731                                 }
1732                         }
1733
1734                         free(value);
1735                         value = NULL;
1736
1737                         sync_agent_delete_fw_account(fw_account->account_id);
1738                 } else {
1739                         _DEBUG_ERROR("value is NULL !");
1740                 }
1741         }
1742
1743  error:
1744
1745         if (value != NULL)
1746                 free(value);
1747
1748         sync_agent_free_fw_account_list(account_info_list);
1749
1750         sync_agent_close_agent();
1751
1752         _EXTERN_FUNC_EXIT;
1753
1754         if (err != SE_INTERNAL_OK)
1755                 return false;
1756         else
1757                 return true;
1758 }
1759
1760 bool get_synchronising_profile(char **profile_Dir_name, char **sync_type)
1761 {
1762         _EXTERN_FUNC_ENTER;
1763
1764         se_error_type_e err = SE_INTERNAL_OK;
1765
1766         bool result;
1767         char *value = NULL;
1768
1769         sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1770         sync_agent_fw_account_s *fw_account = NULL;
1771         GList *account_info_list = NULL;
1772         GList *iter = NULL;
1773
1774         sync_agent_da_return_e da_err = sync_agent_open_agent();
1775         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1776                 err = SE_INTERNAL_DA_ERROR;
1777                 goto error;
1778         }
1779
1780         sync_agent_fw_account_query_s query;
1781         query.query = ACCOUNT_QUERY_BY_NONE;
1782
1783         acc_err = sync_agent_query_fw_account(&query, &account_info_list);
1784         if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1785                 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
1786                 goto error;
1787         }
1788
1789         for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1790                 fw_account = (sync_agent_fw_account_s *) iter->data;
1791
1792                 result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, &value);
1793                 if (result == false) {
1794                         _DEBUG_ERROR("failed in set_Config");
1795                         err = SE_INTERNAL_DA_ERROR;
1796                         goto error;
1797                 }
1798
1799                 if (strcmp(value, "1") == 0) {
1800                         result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile_Dir_name);
1801                         if (result == false) {
1802                                 _DEBUG_ERROR("failed in get_Config");
1803                                 err = SE_INTERNAL_DA_ERROR;
1804                                 goto error;
1805                         }
1806
1807                         result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, sync_type);
1808                         if (result == false) {
1809                                 _DEBUG_ERROR("failed in get_Config");
1810                                 err = SE_INTERNAL_DA_ERROR;
1811                                 goto error;
1812                         }
1813                         break;
1814                 }
1815
1816                 free(value);
1817                 value = NULL;
1818         }
1819
1820  error:
1821
1822         if (value != NULL)
1823                 free(value);
1824
1825         sync_agent_free_fw_account_list(account_info_list);
1826
1827         sync_agent_close_agent();
1828
1829         _EXTERN_FUNC_EXIT;
1830
1831         if (err != SE_INTERNAL_OK)
1832                 return false;
1833         else
1834                 return true;
1835 }
1836
1837 bool delete_all_agent_default_table()
1838 {
1839         _EXTERN_FUNC_ENTER;
1840
1841         se_error_type_e err = SE_INTERNAL_OK;
1842
1843         sync_agent_da_return_e da_err = sync_agent_open_agent();
1844         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1845                 err = SE_INTERNAL_DA_ERROR;
1846                 goto error;
1847         }
1848
1849         da_err = sync_agent_empty_all_agent_default_table();
1850         if (da_err != SYNC_AGENT_DA_SUCCESS) {
1851                 err = SE_INTERNAL_DA_ERROR;
1852                 goto error;
1853         }
1854
1855  error:
1856
1857         sync_agent_close_agent();
1858
1859         _EXTERN_FUNC_EXIT;
1860
1861         if (err != SE_INTERNAL_OK)
1862                 return false;
1863         else
1864                 return true;
1865 }