3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * @brief This file is the source file of implementation of account in Service Engine
24 #include <sync_agent.h>
25 #include <plugin/plugin_slp_sysnoti_alarm.h>
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"
37 #ifndef OMADS_AGENT_LOG
39 #define LOG_TAG "OMA_DS_SE"
42 #define MAX_DATASTORE_COUNT 3
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"}}
54 static datastore_cp_info predefinedServer[] = {
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);
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);
72 static se_error_type_e _add_profile(char *addr, char *id, char *password, char *access_name, int *account_id)
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;
81 char *folderID = NULL;
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;
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);
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;
102 _DEBUG_TRACE("account_id = %d", account);
105 _DEBUG_ERROR("account_id = %d", account);
106 err = SE_INTERNAL_ERROR;
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;
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 !!");
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");
133 char *new_folder_id = NULL;
134 ret = sync_agent_add_folder(folder, &new_folder_id);
135 sync_agent_free_folder(folder);
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;
144 _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
146 if (folderID != NULL) {
151 if (new_folder_id != NULL) {
153 new_folder_id = NULL;
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;
163 ret = sync_agent_create_folder(&folder);
164 if (ret != SYNC_AGENT_DA_SUCCESS) {
165 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
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");
177 ret = sync_agent_add_folder(folder, &new_folder_id);
178 sync_agent_free_folder(folder);
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;
188 _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
190 if (folderID != NULL) {
195 if (new_folder_id != NULL) {
197 new_folder_id = NULL;
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;
207 ret = sync_agent_create_folder(&folder);
208 if (ret != SYNC_AGENT_DA_SUCCESS) {
209 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
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");
221 ret = sync_agent_add_folder(folder, &new_folder_id);
222 sync_agent_free_folder(folder);
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;
232 _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
234 if (folderID != NULL) {
239 if (new_folder_id != NULL) {
241 new_folder_id = NULL;
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;
252 ret = sync_agent_create_folder(&folder);
253 if (ret != SYNC_AGENT_DA_SUCCESS) {
254 _DEBUG_ERROR("sync_agent_create_folder() failed !!");
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");
266 ret = sync_agent_add_folder(folder, &new_folder_id);
267 sync_agent_free_folder(folder);
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;
277 _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id);
279 if (folderID != NULL) {
284 if (new_folder_id != NULL) {
286 new_folder_id = NULL;
289 *account_id = account;
293 if (folderID != NULL)
296 sync_agent_free_fw_account(fw_account);
302 static se_error_type_e _set_profile_info(int account_id, char *profile_name, char *sync_mode, char *sync_type, char *interval)
306 se_error_type_e err = SE_INTERNAL_OK;
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;
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;
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;
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;
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;
350 static se_error_type_e _set_profile_category(int account_id, sync_service_s * category)
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);
361 se_error_type_e err = SE_INTERNAL_OK;
364 char *datastore = NULL;
365 char datastore_target[128];
366 char datastore_source[128];
367 char datastore_id[128];
368 char datastore_pw[128];
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;
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);
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;
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;
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;
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;
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;
426 static se_error_type_e _set_periodic_sync_config(int account_id, char *sync_mode, char *interval)
429 _DEBUG_TRACE("sync_mode = %s", sync_mode);
431 se_error_type_e err = SE_INTERNAL_OK;
432 sync_agent_pm_return_e scheduler_err;
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;
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;
451 alarm_id = atoi(value);
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;
462 if (strcmp(sync_mode, DEFINE_SYNC_MODE_PERIODIC) == 0 && interval != NULL) {
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;
471 int week[] = { DAY_SUN, DAY_MON, DAY_TUE, DAY_WED, DAY_THU, DAY_FRI, DAY_SAT };
473 struct tm *struct_time;
475 struct_time = localtime(¤t_time);
476 if (struct_time == NULL) {
477 _DEBUG_ERROR("struct_time is NULL");
478 err = SE_INTERNAL_ERROR;;
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;
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];
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;
521 _DEBUG_TRACE("alarm_id =%d", alarm_id);
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;
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;
544 if (alarm_info != NULL) {
545 if (alarm_info->start_alarm_time != NULL)
546 free(alarm_info->start_alarm_time);
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)
559 se_error_type_e err = SE_INTERNAL_OK;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
666 static se_error_type_e _set_profile_category_info(int account_id, sync_service_s * category, GList ** config_list)
670 retvm_if(category == NULL, SE_INTERNAL_NOT_DEFINED, "category is NULL");
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");
685 static se_error_type_e _set_profile_category_info_csc(int account_id, int content_type, int index, GList ** config_list)
689 se_error_type_e err = SE_INTERNAL_OK;
691 char *is_enabled_path = NULL;
692 char *target_uri_path = NULL;
693 char *id_path = NULL;
694 char *pwd_path = NULL;
696 char *datastore = NULL;
699 char *target_uri = NULL;
702 char profile_path[128];
704 char *source_uri = NULL;
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;
733 err = SE_INTERNAL_ERROR;
734 _DEBUG_ERROR("No content type");
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);
746 snprintf(profile_path, sizeof(profile_path), target_uri_path, index);
747 target_uri = get_vconf_str_key(profile_path);
749 snprintf(profile_path, sizeof(profile_path), id_path, index);
750 id = get_vconf_str_key(profile_path);
752 snprintf(profile_path, sizeof(profile_path), pwd_path, index);
753 pwd = get_vconf_str_key(profile_path);
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");
764 if (target_uri != NULL)
778 static se_error_type_e _set_profile_category_info_cp(int account_id, int content_type, resource_cp_s * category, GList ** config_list)
782 retvm_if(category == NULL, SE_INTERNAL_NOT_DEFINED, "category is NULL");
784 se_error_type_e err = SE_INTERNAL_OK;
785 char *sourceuri = NULL;
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;
796 err = SE_INTERNAL_ERROR;
797 _DEBUG_ERROR("No content type");
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");
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)
818 se_error_type_e err = SE_INTERNAL_OK;
822 char *datastore = NULL;
823 char datastore_target[128];
824 char datastore_source[128];
825 char datastore_id[128];
826 char datastore_pw[128];
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];
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;
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);
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);
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);
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);
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
981 static se_error_type_e ___append_config_value(int account_id, char *key, char *value, char *type, char *access_name, GList ** list)
984 se_error_type_e err = SE_INTERNAL_OK;
988 sync_agent_da_config_s *config = NULL;
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;
997 if (config != NULL) {
998 *list = g_list_append(*list, config);
1008 static se_error_type_e _get_empty_profile_dir_name(char **empty_profile_dir_name)
1011 se_error_type_e err = SE_INTERNAL_OK;
1014 char *profileDirName = NULL;
1015 int profile[MAXIMUM_ACCOUNT_COUNT] = { 0 };
1016 char profileIndex[2];
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;
1025 sync_agent_fw_account_query_s query;
1026 query.query = ACCOUNT_QUERY_BY_NONE;
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");
1034 for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1035 fw_account = (sync_agent_fw_account_s *) iter->data;
1037 if (profileDirName != NULL) {
1038 free(profileDirName);
1039 profileDirName = NULL;
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;
1049 _DEBUG_TRACE("profile_Dir_name = %s", profileDirName);
1050 if (profileDirName == NULL)
1053 strcpy(profileIndex, profileDirName + strlen(profileDirName) - 1);
1054 _DEBUG_TRACE("profileIndex = %s", profileIndex);
1056 index = atoi(profileIndex);
1057 profile[index - 1] = 1;
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);
1069 sync_agent_free_fw_account_list(account_info_list);
1071 if (profileDirName != NULL)
1072 free(profileDirName);
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)
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);
1090 se_error_type_e err = SE_INTERNAL_OK;
1092 GList *config_list = NULL;
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;
1100 err = _add_profile(addr, id, password, "SE", &account);
1101 if (err != SE_INTERNAL_OK) {
1102 _DEBUG_ERROR("failed in add_Account");
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");
1112 sync_service_s *category = 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");
1123 da_err = sync_agent_add_config_list(config_list);
1124 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1125 err = SE_INTERNAL_DA_ERROR;
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");
1135 *account_id = account;
1139 sync_agent_free_config_list(config_list);
1141 sync_agent_close_agent();
1143 _DEBUG_INFO("err = %d", err);
1147 if (err != SE_INTERNAL_OK)
1153 bool add_profile_csc(int index)
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;
1162 char *password = NULL;
1163 char *server_ip = NULL;
1164 char *sync_mode = NULL;
1165 char *sync_type = NULL;
1168 GList *config_list = NULL;
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;
1176 err = _get_empty_profile_dir_name(&profile_dir_name);
1177 if (err != SE_INTERNAL_OK) {
1178 _DEBUG_ERROR("failed in __get_empty_profileDirName");
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;
1188 snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_AUTHNAME, index);
1189 id = get_vconf_str_key(profile_path);
1191 snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_AUTHPWD, index);
1192 password = get_vconf_str_key(profile_path);
1194 snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_ADDR, index);
1195 server_ip = get_vconf_str_key(profile_path);
1197 snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_NAME, index);
1198 profile_name = get_vconf_str_key(profile_path);
1200 snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_SYNCMODE, index);
1201 sync_mode = get_vconf_str_key(profile_path);
1203 snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE, index);
1204 sync_type = get_vconf_str_key(profile_path);
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);
1213 err = _add_profile(server_ip, id, password, "SE", &account_id);
1214 if (err != SE_INTERNAL_OK) {
1215 _DEBUG_ERROR("failed in add_Account");
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");
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");
1234 da_err = sync_agent_add_config_list(config_list);
1235 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1236 err = SE_INTERNAL_DA_ERROR;
1242 if (profile_dir_name != NULL)
1243 free(profile_dir_name);
1244 if (profile_name != NULL)
1248 if (password != NULL)
1250 if (server_ip != NULL)
1252 if (sync_mode != NULL)
1254 if (sync_type != NULL)
1257 sync_agent_free_config_list(config_list);
1259 sync_agent_close_agent();
1263 if (err != SE_INTERNAL_OK)
1269 bool add_profile_cp(char *profile_name, char *addr, char *id, char *password, GList * categories, int *account_id)
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);
1278 se_error_type_e err = SE_INTERNAL_OK;
1281 char *profile_dir_name = NULL;
1282 GList *config_list = NULL;
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;
1290 err = _get_empty_profile_dir_name(&profile_dir_name);
1291 if (err != SE_INTERNAL_OK) {
1292 _DEBUG_ERROR("failed in __get_empty_profileDirName");
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;
1302 err = _add_profile(addr, id, password, "SE", &account);
1303 if (err != SE_INTERNAL_OK) {
1304 _DEBUG_ERROR("failed in add_Account");
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");
1315 int cnt = (int)sizeof(predefinedServer) / sizeof(datastore_cp_info);
1316 _DEBUG_INFO("cnt = %d", cnt);
1317 for (i = 0; i < cnt; i++) {
1319 _DEBUG_INFO("predefinedServer[%d].serverName = %s", i, predefinedServer[i].serverName);
1320 if (strcmp(predefinedServer[i].serverName, profile_name) == 0) {
1323 for (j = 0; j < MAX_DATASTORE_COUNT; j++) {
1324 resource_cp_s *category = 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);
1332 _DEBUG_INFO("predefinedDatastore[i][j][0] = %s", predefinedDatastore[i][j][0]);
1333 _DEBUG_INFO("predefinedDatastore[i][j][1] = %s", predefinedDatastore[i][j][1]);
1335 if (predefinedDatastore[i][j][0] != NULL && category->name != NULL && predefinedDatastore[i][j][1] != NULL && category->accept != NULL) {
1337 if (strcasecmp(predefinedDatastore[i][j][0], category->name) == 0 && strcmp(predefinedDatastore[i][j][1], category->accept) == 0) {
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");
1352 da_err = sync_agent_add_config_list(config_list);
1353 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1354 err = SE_INTERNAL_DA_ERROR;
1358 *account_id = account;
1362 if (profile_dir_name != NULL)
1363 free(profile_dir_name);
1365 sync_agent_free_config_list(config_list);
1367 sync_agent_close_agent();
1371 if (err != SE_INTERNAL_OK)
1377 bool add_profile_dive(int *account_id)
1381 se_error_type_e err = SE_INTERNAL_OK;
1382 sync_agent_dev_return_e dci_err = SYNC_AGENT_DEV_RETURN_SUCCESS;
1384 char *password = NULL;
1385 char *encoded_nextnonce = NULL;
1388 GList *config_list = NULL;
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;
1396 /* FIXME get id from somewhere */
1397 id = "ss.linux.test@gmail.com";
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");
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");
1412 encoded_nextnonce = g_base64_encode((unsigned char *)DEFINE_DIVE_DEFAULT_NEXT_NONCE, strlen(DEFINE_DIVE_DEFAULT_NEXT_NONCE));
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");
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);
1423 da_err = sync_agent_add_config_list(config_list);
1424 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1425 err = SE_INTERNAL_DA_ERROR;
1429 *account_id = account;
1433 if (password != NULL)
1436 sync_agent_free_config_list(config_list);
1438 sync_agent_close_agent();
1442 if (err != SE_INTERNAL_OK)
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)
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;
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;
1463 acc_err = sync_agent_create_fw_account(&fw_account);
1464 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1465 err = SE_INTERNAL_ERROR;
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");
1475 acc_err = sync_agent_update_fw_account(fw_account);
1476 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
1477 err = SE_INTERNAL_DA_ERROR;
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;
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");
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");
1500 sync_service_s *category = 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");
1513 sync_agent_free_fw_account(fw_account);
1515 sync_agent_close_agent();
1519 if (err != SE_INTERNAL_OK)
1525 bool delete_profiles(GList * profiles)
1529 se_error_type_e err = SE_INTERNAL_OK;
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;
1543 for (iter = profiles; iter != NULL; iter = g_list_next(iter)) {
1544 accountId = (int *)(iter->data);
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;
1555 alarmId = atoi(value);
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;
1564 sync_agent_delete_fw_account(*accountId);
1565 if (accountId != 0) {
1570 _DEBUG_ERROR("accountId is NULL !");
1579 if (accountId != NULL)
1582 sync_agent_close_agent();
1586 if (err != SE_INTERNAL_OK)
1592 bool delete_profile_dive()
1596 se_error_type_e err = SE_INTERNAL_OK;
1598 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1599 GList *account_info_list = NULL;
1601 sync_agent_fw_account_s *account_info = NULL;
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;
1610 sync_agent_fw_account_query_s query;
1611 query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
1612 query.access_name = "DIVE";
1614 acc_err = sync_agent_query_fw_account(&query, &account_info_list);
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);
1624 sync_agent_free_fw_account_list(account_info_list);
1626 sync_agent_close_agent();
1630 if (err != SE_INTERNAL_OK)
1636 bool delete_profile(char *access_name)
1640 se_error_type_e err = SE_INTERNAL_OK;
1642 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
1643 GList *account_info_list = NULL;
1645 sync_agent_fw_account_s *account_info = NULL;
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;
1654 sync_agent_fw_account_query_s query;
1655 query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
1656 query.access_name = access_name;
1659 acc_err = sync_agent_query_fw_account(&query, &account_info_list);
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);
1669 sync_agent_free_fw_account_list(account_info_list);
1671 sync_agent_close_agent();
1675 if (err != SE_INTERNAL_OK)
1681 bool delete_all_profiles()
1685 se_error_type_e err = SE_INTERNAL_OK;
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;
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;
1702 sync_agent_fw_account_query_s query;
1703 query.query = ACCOUNT_QUERY_BY_NONE;
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");
1711 for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1712 fw_account = (sync_agent_fw_account_s *) iter->data;
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;
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;
1737 sync_agent_delete_fw_account(fw_account->account_id);
1739 _DEBUG_ERROR("value is NULL !");
1748 sync_agent_free_fw_account_list(account_info_list);
1750 sync_agent_close_agent();
1754 if (err != SE_INTERNAL_OK)
1760 bool get_synchronising_profile(char **profile_Dir_name, char **sync_type)
1764 se_error_type_e err = SE_INTERNAL_OK;
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;
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;
1780 sync_agent_fw_account_query_s query;
1781 query.query = ACCOUNT_QUERY_BY_NONE;
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");
1789 for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
1790 fw_account = (sync_agent_fw_account_s *) iter->data;
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;
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;
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;
1825 sync_agent_free_fw_account_list(account_info_list);
1827 sync_agent_close_agent();
1831 if (err != SE_INTERNAL_OK)
1837 bool delete_all_agent_default_table()
1841 se_error_type_e err = SE_INTERNAL_OK;
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;
1849 da_err = sync_agent_empty_all_agent_default_table();
1850 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1851 err = SE_INTERNAL_DA_ERROR;
1857 sync_agent_close_agent();
1861 if (err != SE_INTERNAL_OK)