4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JuHak Park <juhaki.park@samsung.com>,
7 * JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8 * SunBong Ha <sunbong.ha@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 * For any sort of issue you concern as to this software,
29 * you may use following point of contact.
30 * All resources contributed on this software
31 * are orinigally written by S-Core Inc., a member of Samsung Group.
33 * SeongWon Shim <seongwon.shim@samsung.com>
39 * @brief This file is the source file of implementation of account in Service Engine
42 #include "Common/CscKeys.h"
43 #include "Common/Common_Vconf.h"
44 #include "Common/Common_Define.h"
45 #include "Common/Common_Util.h"
46 #include "ServiceEngine/SE_Account.h"
47 #include "ServiceEngine/SE_Error.h"
48 #include "ServiceEngine/SE_Common.h"
49 #include "agent-framework/Utility/fw_log.h"
50 #include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
51 #include "agent-framework/DACI/DACI_Luid.h"
52 #include "agent-framework/Account/Account_Mgr.h"
53 #include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h"
54 #include "agent-framework/PlatformMonitor/EXT_PMCI.h"
55 #include "agent-framework/Device/EXT_DCI_DevInfo.h"
56 #include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
58 #define LOG_TAG "OMA_DS_SE"
60 #define MAX_DATASTORE_COUNT 3
68 static char *predefinedDatastore[][MAX_DATASTORE_COUNT][2] = {
69 { {"contacts", "text/x-vcard"}, {"calendar", "text/x-vcalendar"}, {"notes", "text/plain"} }
72 static datastore_cp_info predefinedServer[] = {
76 /* TODO have to remove after removing vconf*/
77 static SE_ErrorType __set_datastore_config_from_vconf(int accountID, char *profilePath, int content_type);
79 static SE_ErrorType __set_datastore_config_from_csc(int accountID, int index, int content_type);
80 static SE_ErrorType __add_profile(char *addr, char *id, char *password, char *access_name, int *accountID);
81 static SE_ErrorType __set_profile_info(int accountId, char *profileName, char *syncMode, char *syncType, char *interval);
82 static SE_ErrorType __set_profile_category(int accountId, int contentType, sync_category *category);
83 static SE_ErrorType __set_profile_category_cp(int accountId, int contentType, resource_cp *category);
84 static SE_ErrorType __set_periodic_sync_config(int account_id, char *syncMode, char *interval);
85 static SE_ErrorType __set_config_default_value(int accountID);
86 static SE_ErrorType __set_datastore_config_default_value(int accountID, int content_type);
88 /* TODO have to remove after removing vconf*/
89 static SE_ErrorType __set_datastore_config_from_vconf(int accountID, char *profilePath, int content_type)
93 SE_ErrorType err = SE_INTERNAL_OK;
95 char *isEnabledPath = NULL;
96 char *targeturiPath = NULL;
97 char *sourceuriPath = NULL;
101 char *datastore = NULL;
102 char datastore_target[128];
103 char datastore_source[128];
104 char datastore_id[128];
105 char datastore_pw[128];
108 char *targeturi = NULL;
109 char *sourceuri = NULL;
115 if (content_type == TYPE_CONTACT) {
116 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
117 isEnabledPath = DS_SETTING_CONTACT_ENABLED;
118 targeturiPath = DS_SETTING_CONTACT_TGTURI;
119 sourceuriPath = DS_SETTING_CONTACT_SRCURI;
120 IDPath = DS_SETTING_CONTACT_AUTHNAME;
121 PWDPath = DS_SETTING_CONTACT_AUTHPWD;
122 } else if (content_type == TYPE_CALENDAR) {
123 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
124 isEnabledPath = DS_SETTING_CALENDAR_ENABLED;
125 targeturiPath = DS_SETTING_CALENDAR_TGTURI;
126 sourceuriPath = DS_SETTING_CALENDAR_SRCURI;
127 IDPath = DS_SETTING_CALENDAR_AUTHNAME;
128 PWDPath = DS_SETTING_CALENDAR_AUTHPWD;
129 } else if (content_type == TYPE_MEMO) {
130 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
131 isEnabledPath = DS_SETTING_MEMO_ENABLED;
132 targeturiPath = DS_SETTING_MEMO_TGTURI;
133 sourceuriPath = DS_SETTING_MEMO_SRCURI;
134 IDPath = DS_SETTING_MEMO_AUTHNAME;
135 PWDPath = DS_SETTING_MEMO_AUTHPWD;
138 result = get_vconf_int(profilePath, isEnabledPath, &isEnabled);
139 if (result == false) {
140 FW_LOGE("failed in get_Vconf_int");
141 err = SE_INTERNAL_DA_ERROR;
145 targeturi = get_vconf_str(profilePath, targeturiPath);
146 sourceuri = get_vconf_str(profilePath, sourceuriPath);
147 ID = get_vconf_str(profilePath, IDPath);
148 PWD = get_vconf_str(profilePath, PWDPath);
150 sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
151 sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
152 sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
153 sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
156 result = set_config_str(accountID, datastore, "1", "string", "SE");
157 if (result == false) {
158 FW_LOGE("failed in set_config");
159 err = SE_INTERNAL_DA_ERROR;
163 result = set_config_str(accountID, datastore_target, targeturi, "string", "SE");
164 if (result == false) {
165 FW_LOGE("failed in set_config");
166 err = SE_INTERNAL_DA_ERROR;
170 result = set_config_str(accountID, datastore_id, ID, "string", "SE");
171 if (result == false) {
172 FW_LOGE("failed in set_config");
173 err = SE_INTERNAL_DA_ERROR;
177 result = set_config_str(accountID, datastore_pw, PWD, "string", "SE");
178 if (result == false) {
179 FW_LOGE("failed in set_config");
180 err = SE_INTERNAL_DA_ERROR;
185 result = set_config_str(accountID, datastore, "0", "string", "SE");
186 if (result == false) {
187 FW_LOGE("failed in set_config");
188 err = SE_INTERNAL_DA_ERROR;
193 result = set_config_str(accountID, datastore_source, sourceuri, "string", "SE");
194 if (result == false) {
195 FW_LOGE("failed in set_config");
196 err = SE_INTERNAL_DA_ERROR;
217 static SE_ErrorType __set_datastore_config_from_csc(int accountID, int index, int content_type)
221 SE_ErrorType err = SE_INTERNAL_OK;
223 char *isEnabledPath = NULL;
224 char *targeturiPath = NULL;
226 char *PWDPath = NULL;
228 char *datastore = NULL;
229 char datastore_target[128];
230 char datastore_source[128];
231 char datastore_id[128];
232 char datastore_pw[128];
235 char *targeturi = NULL;
238 char profilePath[128];
240 char *sourceuri = NULL;
244 if (content_type == TYPE_CONTACT) {
245 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
246 sourceuri = DEFINE_SOURCE_CONTACT_URI;
247 isEnabledPath = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED;
248 targeturiPath = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI;
249 IDPath = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME;
250 PWDPath = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD;
251 } else if (content_type == TYPE_CALENDAR) {
252 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
253 sourceuri = DEFINE_SOURCE_CALENDAR_URI;
254 isEnabledPath = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED;
255 targeturiPath = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI;
256 IDPath = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME;
257 PWDPath = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD;
258 } else if (content_type == TYPE_MEMO) {
259 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
260 sourceuri = DEFINE_SOURCE_MEMO_URI;
261 isEnabledPath = CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED;
262 targeturiPath = CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI;
263 IDPath = CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME;
264 PWDPath = CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD;
266 err = SE_INTERNAL_ERROR;
267 FW_LOGE("No content type");
271 sprintf(profilePath, isEnabledPath, index);
272 result = get_vconf_Int_key(profilePath, &isEnabled);
273 if (result == false) {
274 FW_LOGE("No value in vconf key = %s", profilePath);
278 sprintf(profilePath, targeturiPath, index);
279 targeturi = get_vconf_str_key(profilePath);
281 sprintf(profilePath, IDPath, index);
282 ID = get_vconf_str_key(profilePath);
284 sprintf(profilePath, PWDPath, index);
285 PWD = get_vconf_str_key(profilePath);
287 sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
288 sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
289 sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
290 sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
293 result = set_config_str(accountID, datastore, "1", "string", "SE");
294 if (result == false) {
295 FW_LOGE("failed in set_config");
296 err = SE_INTERNAL_DA_ERROR;
299 result = set_config_str(accountID, datastore_target, targeturi, "string", "SE");
300 if (result == false) {
301 FW_LOGE("failed in set_config");
302 err = SE_INTERNAL_DA_ERROR;
305 result = set_config_str(accountID, datastore_id, ID, "string", "SE");
306 if (result == false) {
307 FW_LOGE("failed in set_config");
308 err = SE_INTERNAL_DA_ERROR;
311 result = set_config_str(accountID, datastore_pw, PWD, "string", "SE");
312 if (result == false) {
313 FW_LOGE("failed in set_config");
314 err = SE_INTERNAL_DA_ERROR;
319 result = set_config_str(accountID, datastore, "0", "string", "SE");
320 if (result == false) {
321 FW_LOGE("failed in set_config");
322 err = SE_INTERNAL_DA_ERROR;
326 result = set_config_str(accountID, datastore_source, sourceuri, "string", "SE");
327 if (result == false) {
328 FW_LOGE("failed in set_config");
329 err = SE_INTERNAL_DA_ERROR;
347 static SE_ErrorType __add_profile(char *addr, char *id, char *password, char *access_name, int *accountID)
351 SE_ErrorType err = SE_INTERNAL_OK;
352 int account = addAccount(id, password, addr, NULL, 0, 0, access_name);
353 char *folderID = NULL;
355 FW_LOGV("accountID = %d", account);
358 FW_LOGE("accountID = %d", account);
359 err = SE_INTERNAL_ERROR;
363 folderID = DACI_Generate_Folder_Luid();
364 if (folderID == NULL) {
365 FW_LOGE("failed in DACI_Generate_Folder_Luid");
366 err = SE_INTERNAL_DA_ERROR;
370 folder.account_id = account;
371 folder.folder_id = folderID;
372 folder.data_store_id = TYPE_CONTACT;
373 folder.folder_type_id = 0; /* Default contacts folder */
374 folder.parent_folder_id = 0;
375 folder.service_id = "0";
376 folder.access_name = "EventHandler";
377 DACI_RETURN ret = DACI_Add_Folder(&folder, 1);
378 if (ret != DACI_SUCCESS) {
379 FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
380 FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
381 err = SE_INTERNAL_ERROR;
385 FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
387 if (folderID != NULL) {
392 folderID = DACI_Generate_Folder_Luid();
393 if (folderID == NULL) {
394 FW_LOGE("failed in DACI_Generate_Folder_Luid");
395 err = SE_INTERNAL_DA_ERROR;
398 folder.account_id = account;
399 folder.folder_id = folderID;
400 folder.data_store_id = TYPE_CALENDAR;
401 folder.folder_type_id = 0; /* Default calendars folder */
402 folder.parent_folder_id = 0;
403 folder.service_id = "1";
404 folder.access_name = "EventHandler";
405 ret = DACI_Add_Folder(&folder, 1);
406 if (ret != DACI_SUCCESS) {
407 FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
408 FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
409 err = SE_INTERNAL_ERROR;
413 FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
415 if (folderID != NULL) {
420 /* TODO : add default memo folder (Hard cording) */
421 folderID = DACI_Generate_Folder_Luid();
422 if (folderID == NULL) {
423 FW_LOGE("failed in DACI_Generate_Folder_Luid");
424 err = SE_INTERNAL_DA_ERROR;
427 folder.account_id = account;
428 folder.folder_id = folderID;
429 folder.data_store_id = TYPE_MEMO;
430 folder.folder_type_id = 0; /* Default notes folder */
431 folder.parent_folder_id = 0;
432 folder.service_id = "0";
433 folder.access_name = "EventHandler";
434 ret = DACI_Add_Folder(&folder, 1);
435 if (ret != DACI_SUCCESS) {
436 FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
437 FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
438 err = SE_INTERNAL_ERROR;
442 FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
444 if (folderID != NULL) {
449 /* call log folder ID */
450 folderID = DACI_Generate_Folder_Luid();
451 if (folderID == NULL) {
452 FW_LOGE("failed in DACI_Generate_Folder_Luid");
453 err = SE_INTERNAL_DA_ERROR;
457 folder.account_id = account;
458 folder.folder_id = folderID;
459 folder.data_store_id = TYPE_CALLLOG;
460 folder.folder_type_id = 0; /* Default call log folder */
461 folder.parent_folder_id = 0;
462 folder.service_id = "0";
463 folder.access_name = "EventHandler";
464 ret = DACI_Add_Folder(&folder, 1);
465 if (ret != DACI_SUCCESS) {
466 FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
467 FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
468 err = SE_INTERNAL_ERROR;
472 FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
474 if (folderID != NULL) {
479 *accountID = account;
485 if (folderID != NULL)
492 static SE_ErrorType __set_profile_info(int accountId, char *profileName, char *syncMode, char *syncType, char *interval)
496 SE_ErrorType err = SE_INTERNAL_OK;
499 result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
500 if (result == false) {
501 FW_LOGE("failed in set_config");
502 err = SE_INTERNAL_DA_ERROR;
506 result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
507 if (result == false) {
508 FW_LOGE("failed in set_config");
509 err = SE_INTERNAL_DA_ERROR;
513 result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , syncType, "string", "SE");
514 if (result == false) {
515 FW_LOGE("failed in set_config");
516 err = SE_INTERNAL_DA_ERROR;
520 result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
521 if (result == false) {
522 FW_LOGE("failed in set_config");
523 err = SE_INTERNAL_DA_ERROR;
535 static SE_ErrorType __set_profile_category(int accountId, int contentType, sync_category *category)
539 FW_LOGV("category->enabled : %d", category->enabled);
540 FW_LOGV("category->srcURI : %s", category->srcURI);
541 FW_LOGV("category->tgtURI : %s", category->tgtURI);
542 FW_LOGV("category->id : %s", category->id);
543 FW_LOGV("category->password : %s", category->password);
545 SE_ErrorType err = SE_INTERNAL_OK;
548 char *datastore = NULL;
549 char datastore_target[128];
550 char datastore_source[128];
551 char datastore_id[128];
552 char datastore_pw[128];
554 if (contentType == TYPE_CONTACT)
555 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
556 else if (contentType == TYPE_CALENDAR)
557 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
558 else if (contentType == TYPE_MEMO)
559 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
560 else if (contentType == TYPE_CALLLOG)
561 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
563 sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
564 sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
565 sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
566 sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
569 result = set_config_int(accountId, datastore, category->enabled, "int", "SE");
570 if (result == false) {
571 FW_LOGE("failed in set_config");
572 err = SE_INTERNAL_DA_ERROR;
576 result = set_config_str(accountId, datastore_source, category->srcURI, "string", "SE");
577 if (result == false) {
578 FW_LOGE("failed in set_config");
579 err = SE_INTERNAL_DA_ERROR;
583 result = set_config_str(accountId, datastore_target, category->tgtURI, "string", "SE");
584 if (result == false) {
585 FW_LOGE("failed in set_config");
586 err = SE_INTERNAL_DA_ERROR;
590 result = set_config_str(accountId, datastore_id, category->id, "string", "SE");
591 if (result == false) {
592 FW_LOGE("failed in set_config");
593 err = SE_INTERNAL_DA_ERROR;
597 result = set_config_str(accountId, datastore_pw, category->password, "string", "SE");
598 if (result == false) {
599 FW_LOGE("failed in set_config");
600 err = SE_INTERNAL_DA_ERROR;
611 static SE_ErrorType __set_profile_category_cp(int accountId, int contentType, resource_cp *category)
615 FW_LOGV("category->srcURI : %s", category->name);
616 FW_LOGV("category->id : %s", category->id);
617 FW_LOGV("category->password : %s", category->password);
618 FW_LOGV("category->authType : %s", category->authType);
619 FW_LOGV("category->authData : %s", category->authData);
620 FW_LOGV("category->tgtURI : %s", category->accept);
622 SE_ErrorType err = SE_INTERNAL_OK;
625 char *datastore = NULL;
626 char datastore_target[128];
627 char datastore_id[128];
628 char datastore_pw[128];
630 if (contentType == TYPE_CONTACT)
631 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
632 else if (contentType == TYPE_CALENDAR)
633 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
634 else if (contentType == TYPE_MEMO)
635 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
637 sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
638 sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
639 sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
641 result = set_config_str(accountId, datastore_target, category->name, "string", "SE");
642 if (result == false) {
643 FW_LOGE("failed in set_config");
644 err = SE_INTERNAL_DA_ERROR;
648 result = set_config_str(accountId, datastore_id, category->id, "string", "SE");
649 if (result == false) {
650 FW_LOGE("failed in set_config");
651 err = SE_INTERNAL_DA_ERROR;
655 result = set_config_str(accountId, datastore_pw, category->password, "string", "SE");
656 if (result == false) {
657 FW_LOGE("failed in set_config");
658 err = SE_INTERNAL_DA_ERROR;
669 static SE_ErrorType __set_periodic_sync_config(int account_id, char *syncMode, char *interval)
672 FW_LOGV("syncMode = %s", syncMode);
674 SE_ErrorType err = SE_INTERNAL_OK;
675 PMCI_RETURN scheduler_err;
680 pmci_alarm_t *alarm_info = (pmci_alarm_t *)calloc(1, sizeof(pmci_alarm_t));
682 result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
683 if (result == false) {
684 FW_LOGE("failed in set_config");
685 err = SE_INTERNAL_DA_ERROR;
689 alarm_id = atoi(value);
692 scheduler_err = PMCI_Remove_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarm_id);
693 if (scheduler_err != PMCI_SUCCESS) {
694 FW_LOGE("failed in PMCI_Remove_Item_To_Specific_Type");
695 err = SE_INTERNAL_SCHEDULER_ERROR;
700 if (strcmp(syncMode , DEFINE_SYNC_MODE_PERIODIC) == 0 && interval != NULL) {
702 result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , DEFINE_ALERT_TWO_WAY_STR, "string", "SE");
703 if (result == false) {
704 FW_LOGE("failed in set_config");
705 err = SE_INTERNAL_DA_ERROR;
709 int week[] = {DAY_SUN, DAY_MON, DAY_TUE, DAY_WED, DAY_THU, DAY_FRI, DAY_SAT};
711 struct tm *struct_time;
713 struct_time = localtime(¤t_time);
714 if (struct_time == NULL) {
715 FW_LOGE("struct_time is NULL");
716 err = SE_INTERNAL_ERROR;;
720 alarm_info->start_alarm_time = g_strdup_printf("%.2d-%.2d-%.2dT%.2d:%.2d:%.2dZ",
721 struct_time->tm_year+1900,
722 struct_time->tm_mon+1,
723 struct_time->tm_mday,
724 struct_time->tm_hour,
726 struct_time->tm_sec);
727 alarm_info->isDisposable = 0;
729 if (strcmp(interval, "5 minutes") == 0) {
730 FW_LOGV("5 minutes");
731 alarm_info->repeat_type = REPEAT;
732 alarm_info->repeat_value = 5*60;
733 } else if (strcmp(interval, "15 minutes") == 0) {
734 FW_LOGV("15 minutes");
735 alarm_info->repeat_type = REPEAT;
736 alarm_info->repeat_value = 15*60;
737 } else if (strcmp(interval, "1 hour") == 0) {
739 alarm_info->repeat_type = REPEAT;
740 alarm_info->repeat_value = ((1*60)*60);
741 } else if (strcmp(interval, "4 hours") == 0) {
743 alarm_info->repeat_type = REPEAT;
744 alarm_info->repeat_value = ((4*60)*60);
745 } else if (strcmp(interval, "12 hours") == 0) {
747 alarm_info->repeat_type = REPEAT;
748 alarm_info->repeat_value = ((12*60)*60);
749 } else if (strcmp(interval, "1 day") == 0) {
751 alarm_info->repeat_type = REPEAT;
752 alarm_info->repeat_value = ((24*60)*60);
753 } else if (strcmp(interval, "1 week") == 0) {
755 alarm_info->repeat_type = REPEAT_WEEKLY;
756 alarm_info->repeat_value = week[struct_time->tm_wday];
759 scheduler_err = PMCI_Add_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarm_info, &alarm_id);
760 if (scheduler_err != PMCI_SUCCESS) {
761 FW_LOGE("failed in PMCI_Add_Item_To_Specific_Type");
762 err = SE_INTERNAL_SCHEDULER_ERROR;
765 FW_LOGV("alarm_id =%d", alarm_id);
767 result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, alarm_id, "int", "SE");
768 if (result == false) {
769 FW_LOGE("failed in set_config");
770 err = SE_INTERNAL_DA_ERROR;
775 result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
776 if (result == false) {
777 FW_LOGE("failed in set_config");
778 err = SE_INTERNAL_DA_ERROR;
790 if (alarm_info != NULL) {
791 if (alarm_info->start_alarm_time != NULL)
792 free(alarm_info->start_alarm_time);
801 static SE_ErrorType __set_config_default_value(int accountID)
804 SE_ErrorType err = SE_INTERNAL_OK;
808 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, NULL, "string", "SE");
809 if (result == false) {
810 FW_LOGE("failed in set_config");
811 err = SE_INTERNAL_DA_ERROR;
815 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, NULL, "string", "SE");
816 if (result == false) {
817 FW_LOGE("failed in set_config");
818 err = SE_INTERNAL_DA_ERROR;
822 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, NULL, "string", "SE");
823 if (result == false) {
824 FW_LOGE("failed in set_config");
825 err = SE_INTERNAL_DA_ERROR;
829 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, "Push", "string", "SE");
830 if (result == false) {
831 FW_LOGE("failed in set_config");
832 err = SE_INTERNAL_DA_ERROR;
836 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , "Full", "string", "SE");
837 if (result == false) {
838 FW_LOGE("failed in set_config");
839 err = SE_INTERNAL_DA_ERROR;
843 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, "5 minutes", "string", "SE");
844 if (result == false) {
845 FW_LOGE("failed in set_config");
846 err = SE_INTERNAL_DA_ERROR;
850 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, NULL, "string", "SE");
851 if (result == false) {
852 FW_LOGE("failed in set_config");
853 err = SE_INTERNAL_DA_ERROR;
857 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, NULL, "string", "SE");
858 if (result == false) {
859 FW_LOGE("failed in set_config");
860 err = SE_INTERNAL_DA_ERROR;
864 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, "-1", "int", "SE");
865 if (result == false) {
866 FW_LOGE("failed in set_config");
867 err = SE_INTERNAL_DA_ERROR;
871 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, "-1", "int", "SE");
872 if (result == false) {
873 FW_LOGE("failed in set_config");
874 err = SE_INTERNAL_DA_ERROR;
878 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
879 if (result == false) {
880 FW_LOGE("failed in set_config");
881 err = SE_INTERNAL_DA_ERROR;
887 for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
888 err = __set_datastore_config_default_value(accountID, content_type);
889 if (err != SE_INTERNAL_OK) {
890 FW_LOGE("failed in set_DatastoreConfig");
901 static SE_ErrorType __set_datastore_config_default_value(int accountID, int contentType)
904 SE_ErrorType err = SE_INTERNAL_OK;
908 char *datastore = NULL;
909 char datastore_target[128];
910 char datastore_source[128];
911 char datastore_id[128];
912 char datastore_pw[128];
914 char datastore_dbSynced[128];
915 char datastore_lastSessionTime[128];
916 char datastore_s2c_Total[128];
917 char datastore_s2c_NrOfAdd[128];
918 char datastore_s2c_NrOfDelete[128];
919 char datastore_s2c_NrOfReplace[128];
920 char datastore_c2s_Total[128];
921 char datastore_c2s_NrOfAdd[128];
922 char datastore_c2s_NrOfDelete[128];
923 char datastore_c2s_NrOfReplace[128];
925 if (contentType == TYPE_CONTACT)
926 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
927 else if (contentType == TYPE_CALENDAR)
928 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
929 else if (contentType == TYPE_MEMO)
930 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
931 else if(contentType == TYPE_CALLLOG)
932 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
934 sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
935 sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
936 sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
937 sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
939 sprintf(datastore_dbSynced, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
940 sprintf(datastore_lastSessionTime, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
942 sprintf(datastore_s2c_Total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
943 sprintf(datastore_s2c_NrOfAdd, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
944 sprintf(datastore_s2c_NrOfDelete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
945 sprintf(datastore_s2c_NrOfReplace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
947 sprintf(datastore_c2s_Total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
948 sprintf(datastore_c2s_NrOfAdd, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
949 sprintf(datastore_c2s_NrOfDelete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
950 sprintf(datastore_c2s_NrOfReplace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
953 result = set_config_str(accountID, datastore, "0", "int", "SE");
954 if (result == false) {
955 FW_LOGE("failed in set_config");
956 err = SE_INTERNAL_DA_ERROR;
960 result = set_config_str(accountID, datastore_source, datastore, "string", "SE");
961 if (result == false) {
962 FW_LOGE("failed in set_config");
963 err = SE_INTERNAL_DA_ERROR;
967 result = set_config_str(accountID, datastore_target, NULL, "string", "SE");
968 if (result == false) {
969 FW_LOGE("failed in set_config");
970 err = SE_INTERNAL_DA_ERROR;
974 result = set_config_str(accountID, datastore_id, NULL, "string", "SE");
975 if (result == false) {
976 FW_LOGE("failed in set_config");
977 err = SE_INTERNAL_DA_ERROR;
981 result = set_config_str(accountID, datastore_pw, NULL, "string", "SE");
982 if (result == false) {
983 FW_LOGE("failed in set_config");
984 err = SE_INTERNAL_DA_ERROR;
988 result = set_config_str(accountID, datastore_dbSynced, DEFINE_DBSYNC_NO, "string", "SE");
989 if (result == false) {
990 FW_LOGE("failed in set_config");
991 err = SE_INTERNAL_DA_ERROR;
995 result = set_config_str(accountID, datastore_lastSessionTime, "-1", "int", "SE");
996 if (result == false) {
997 FW_LOGE("failed in set_config");
998 err = SE_INTERNAL_DA_ERROR;
1002 result = set_config_int(accountID, datastore_s2c_Total, 0, "int", "SE");
1003 if (result == false) {
1004 FW_LOGE("failed in set_config");
1005 err = SE_INTERNAL_DA_ERROR;
1009 result = set_config_int(accountID, datastore_s2c_NrOfAdd, 0, "int", "SE");
1010 if (result == false) {
1011 FW_LOGE("failed in set_config");
1012 err = SE_INTERNAL_DA_ERROR;
1016 result = set_config_int(accountID, datastore_s2c_NrOfDelete, 0, "int", "SE");
1017 if (result == false) {
1018 FW_LOGE("failed in set_config");
1019 err = SE_INTERNAL_DA_ERROR;
1023 result = set_config_int(accountID, datastore_s2c_NrOfReplace, 0, "int", "SE");
1024 if (result == false) {
1025 FW_LOGE("failed in set_config");
1026 err = SE_INTERNAL_DA_ERROR;
1030 result = set_config_int(accountID, datastore_c2s_Total, 0, "int", "SE");
1031 if (result == false) {
1032 FW_LOGE("failed in set_config");
1033 err = SE_INTERNAL_DA_ERROR;
1037 result = set_config_int(accountID, datastore_c2s_NrOfAdd, 0, "int", "SE");
1038 if (result == false) {
1039 FW_LOGE("failed in set_config");
1040 err = SE_INTERNAL_DA_ERROR;
1044 result = set_config_int(accountID, datastore_c2s_NrOfDelete, 0, "int", "SE");
1045 if (result == false) {
1046 FW_LOGE("failed in set_config");
1047 err = SE_INTERNAL_DA_ERROR;
1051 result = set_config_int(accountID, datastore_c2s_NrOfReplace, 0, "int", "SE");
1052 if (result == false) {
1053 FW_LOGE("failed in set_config");
1054 err = SE_INTERNAL_DA_ERROR;
1063 /*TODO have to be removed after removing vconf*/
1064 int update_all_config(char *profile, bool isAdd, int *accountId)
1066 FW_LOGV("profile = %s", profile);
1068 SE_ErrorType err = SE_INTERNAL_OK;
1069 char profilePath[128];
1070 char *profileName = NULL;
1072 char *password = NULL;
1073 char *serverIP = NULL;
1074 char *syncMode = NULL;
1075 char *syncType = NULL;
1076 char *interval = NULL;
1079 if (profile == NULL) {
1080 FW_LOGE("profile is NULL");
1081 err = SE_INTERNAL_NOT_DEFINED;
1085 DACI_RETURN da_err = DACI_Open_Agent();
1086 if (da_err != DACI_SUCCESS) {
1087 err = SE_INTERNAL_DA_ERROR;
1091 sprintf(profilePath, "%s/%s", DS_SETTINGS_PATH, profile);
1093 email = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHNAME);
1094 password = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHPWD);
1095 serverIP = get_vconf_str(profilePath, DS_SETTING_ADDR);
1097 FW_LOGV("email = %s", email);
1098 FW_LOGV("password = %s", password);
1099 FW_LOGV("serverIP = %s", serverIP);
1102 if (isAdd == true) {
1103 err = __add_profile(serverIP, email, password , "UI", &accountID);
1104 if (err != SE_INTERNAL_OK) {
1105 FW_LOGE("failed in add_Account");
1109 err = __set_config_default_value(accountID);
1110 if (err != SE_INTERNAL_OK) {
1111 FW_LOGE("failed in add_Account");
1115 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile, "string", "SE");
1116 if (result == false) {
1117 FW_LOGE("failed in set_config");
1118 err = SE_INTERNAL_DA_ERROR;
1123 accountID = get_accountid(profile, true);
1125 FW_LOGV("accountID = %d", accountID);
1127 da_err = DACI_Set_Account_Email_Address(accountID, email, "SE");
1128 if (da_err != DACI_SUCCESS) {
1129 FW_LOGE("failed in DACI_Set_Account_Email_Address = %d", da_err);
1130 err = SE_INTERNAL_ERROR;
1134 da_err = DACI_Set_Account_Password(accountID, password, "SE");
1135 if (da_err != DACI_SUCCESS) {
1136 FW_LOGE("failed in DACI_Set_Account_Email_Address = %d", da_err);
1137 err = SE_INTERNAL_ERROR;
1142 profileName = get_vconf_str(profilePath, DS_SETTING_NAME);
1143 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
1144 if (result == false) {
1145 FW_LOGE("failed in set_config");
1146 err = SE_INTERNAL_DA_ERROR;
1150 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, serverIP, "string", "SE");
1151 if (result == false) {
1152 FW_LOGE("failed in set_config");
1153 err = SE_INTERNAL_DA_ERROR;
1157 syncMode = get_vconf_str(profilePath, DS_SETTING_SYNCMODE);
1158 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
1159 if (result == false) {
1160 FW_LOGE("failed in set_config");
1161 err = SE_INTERNAL_DA_ERROR;
1165 syncType = get_vconf_str(profilePath, DS_SETTING_SYNCTYPE);
1166 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
1167 if (result == false) {
1168 FW_LOGE("failed in set_config");
1169 err = SE_INTERNAL_DA_ERROR;
1173 interval = get_vconf_str(profilePath, DS_SETTING_INTERVAL);
1174 FW_LOGV("interval %s ", interval);
1176 err = __set_periodic_sync_config(accountID, syncMode, interval);
1177 if (err != SE_INTERNAL_OK) {
1178 FW_LOGE("failed in set_periodic_sync_config");
1182 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
1183 if (result == false) {
1184 FW_LOGE("failed in set_config");
1185 err = SE_INTERNAL_DA_ERROR;
1190 for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
1191 err = __set_datastore_config_from_vconf(accountID, profilePath, content_type);
1192 if (err != SE_INTERNAL_OK) {
1193 FW_LOGE("failed in set_DatastoreConfig");
1198 *accountId = accountID;
1221 if (err != SE_INTERNAL_OK)
1228 int add_profile_csc(int index)
1230 SE_ErrorType err = SE_INTERNAL_OK;
1231 char profilePath[128];
1232 char profileDirName[128];
1233 char *profileName = NULL;
1235 char *password = NULL;
1236 char *serverIP = NULL;
1237 char *syncMode = NULL;
1238 char *syncType = NULL;
1241 DACI_RETURN da_err = DACI_Open_Agent();
1242 if (da_err != DACI_SUCCESS) {
1243 err = SE_INTERNAL_DA_ERROR;
1247 sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_ADDR, index);
1248 serverIP = get_vconf_str_key(profilePath);
1250 sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_AUTHNAME, index);
1251 id = get_vconf_str_key(profilePath);
1253 sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_AUTHPWD, index);
1254 password = get_vconf_str_key(profilePath);
1256 FW_LOGV("email = %s", id);
1257 FW_LOGV("password = %s", password);
1258 FW_LOGV("serverIP = %s", serverIP);
1261 err = __add_profile(serverIP, id, password , "CSC", &accountID);
1262 if (err != SE_INTERNAL_OK) {
1263 FW_LOGE("failed in add_Account");
1267 err = __set_config_default_value(accountID);
1268 if (err != SE_INTERNAL_OK) {
1269 FW_LOGE("failed in __set_config_default_value");
1273 /*set profile dir name in config table*/
1274 sprintf(profileDirName, "Sync%d", index);
1275 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName, "string", "SE");
1276 if (result == false) {
1277 FW_LOGE("failed in set_config");
1278 err = SE_INTERNAL_DA_ERROR;
1282 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, serverIP, "string", "SE");
1283 if (result == false) {
1284 FW_LOGE("failed in set_config");
1285 err = SE_INTERNAL_DA_ERROR;
1289 sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_NAME, index);
1290 profileName = get_vconf_str_key(profilePath);
1291 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
1292 if (result == false) {
1293 FW_LOGE("failed in set_config");
1294 err = SE_INTERNAL_DA_ERROR;
1298 sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_SYNCMODE, index);
1299 syncMode = get_vconf_str_key(profilePath);
1300 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
1301 if (result == false) {
1302 FW_LOGE("failed in set_config");
1303 err = SE_INTERNAL_DA_ERROR;
1307 sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE, index);
1308 syncType = get_vconf_str_key(profilePath);
1309 result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
1310 if (result == false) {
1311 FW_LOGE("failed in set_config");
1312 err = SE_INTERNAL_DA_ERROR;
1317 for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
1318 err = __set_datastore_config_from_csc(accountID, index, content_type);
1319 if (err != SE_INTERNAL_OK) {
1320 FW_LOGE("failed in set_DatastoreConfig");
1344 if (err != SE_INTERNAL_OK)
1350 bool add_profile_cp(char *profileName, char *addr, char *id, char *password, GList *categories, int *accountId)
1354 FW_LOGV("profileName = %s", profileName);
1355 FW_LOGV("addr = %s", addr);
1356 FW_LOGV("id = %s", id);
1357 FW_LOGV("password = %s", password);
1359 SE_ErrorType err = SE_INTERNAL_OK;
1364 DACI_RETURN da_err = DACI_Open_Agent();
1365 if (da_err != DACI_SUCCESS) {
1366 err = SE_INTERNAL_DA_ERROR;
1370 err = __add_profile(addr, id, password, "CP", &account);
1371 if (err != SE_INTERNAL_OK) {
1372 FW_LOGE("failed in add_Account");
1376 err = __set_config_default_value(account);
1377 if (err != SE_INTERNAL_OK) {
1378 FW_LOGE("failed in add_Account");
1382 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
1383 if (result == false) {
1384 FW_LOGE("failed in set_config");
1385 err = SE_INTERNAL_DA_ERROR;
1389 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
1390 if (result == false) {
1391 FW_LOGE("failed in set_config");
1392 err = SE_INTERNAL_DA_ERROR;
1397 int cnt = (int) sizeof(predefinedServer) / sizeof(datastore_cp_info);
1398 FW_LOGV("cnt = %d", cnt);
1399 for (i = 0; i < cnt; i++) {
1401 FW_LOGV("predefinedServer[%d].serverName = %s", i, predefinedServer[i].serverName);
1402 if (strcmp(predefinedServer[i].serverName, profileName) == 0) {
1405 for (j = 0; j < MAX_DATASTORE_COUNT; j++) {
1406 resource_cp *category = NULL;
1408 FW_LOGV("categories length = %d", g_list_length(categories));
1409 for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
1410 category = (resource_cp *)iter->data;
1411 FW_LOGV("category->name = %s", category->name);
1412 FW_LOGV("category->accept = %s", category->accept);
1414 FW_LOGV("predefinedDatastore[i][j][0] = %s", predefinedDatastore[i][j][0]);
1415 FW_LOGV("predefinedDatastore[i][j][1] = %s", predefinedDatastore[i][j][1]);
1417 if (predefinedDatastore[i][j][0] != NULL && category->name != NULL &&
1418 predefinedDatastore[i][j][1] != NULL && category->accept != NULL) {
1420 if (strcasecmp(predefinedDatastore[i][j][0] , category->name) == 0 &&
1421 strcmp(predefinedDatastore[i][j][1], category->accept) == 0) {
1423 err = __set_profile_category_cp(account, j, category);
1424 if (err != SE_INTERNAL_OK) {
1425 FW_LOGE("failed in __set_profile_category");
1436 *accountId = account;
1445 if (err != SE_INTERNAL_OK)
1451 bool add_profile(char *profileDirName, char *profileName, char *addr, char *id, char *password, char *syncMode, char *syncType, char *interval, GList *categories, int *accountId)
1455 FW_LOGV("profileName = %s", profileName);
1456 FW_LOGV("addr = %s", addr);
1457 FW_LOGV("id = %s", id);
1458 FW_LOGV("password = %s", password);
1459 FW_LOGV("syncMode = %s", syncMode);
1460 FW_LOGV("syncType = %s", syncType);
1461 FW_LOGV("interval = %s", interval);
1463 SE_ErrorType err = SE_INTERNAL_OK;
1468 DACI_RETURN da_err = DACI_Open_Agent();
1469 if (da_err != DACI_SUCCESS) {
1470 err = SE_INTERNAL_DA_ERROR;
1474 err = __add_profile(addr, id, password, "UI", &account);
1475 if (err != SE_INTERNAL_OK) {
1476 FW_LOGE("failed in add_Account");
1480 err = __set_config_default_value(account);
1481 if (err != SE_INTERNAL_OK) {
1482 FW_LOGE("failed in add_Account");
1486 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName, "string", "SE");
1487 if (result == false) {
1488 FW_LOGE("failed in set_config");
1489 err = SE_INTERNAL_DA_ERROR;
1493 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
1494 if (result == false) {
1495 FW_LOGE("failed in set_config");
1496 err = SE_INTERNAL_DA_ERROR;
1500 err = __set_profile_info(account, profileName, syncMode, syncType, interval);
1501 if (err != SE_INTERNAL_OK) {
1502 FW_LOGE("failed in __set_profile_info");
1506 err = __set_periodic_sync_config(account, syncMode, interval);
1507 if (err != SE_INTERNAL_OK) {
1508 FW_LOGE("failed in __set_profile_info");
1512 sync_category *category = NULL;
1514 int contentType = 0;
1515 for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
1516 category = iter->data;
1517 err = __set_profile_category(account, contentType, category);
1518 if (err != SE_INTERNAL_OK) {
1519 FW_LOGE("failed in __set_profile_category");
1525 *accountId = account;
1534 if (err != SE_INTERNAL_OK)
1540 bool edit_profile(int accountId, char *profileName, char *addr, char *id, char *password, char *syncMode, char *syncType, char *interval, GList *categories)
1543 SE_ErrorType err = SE_INTERNAL_OK;
1546 DACI_RETURN da_err = DACI_Open_Agent();
1547 if (da_err != DACI_SUCCESS) {
1548 err = SE_INTERNAL_DA_ERROR;
1552 da_err = DACI_Set_Account_Email_Address(accountId, id, "SE");
1553 if (da_err != DACI_SUCCESS) {
1554 FW_LOGE("failed in DACI_Set_Account_Email_Address");
1555 err = SE_INTERNAL_ERROR;
1560 da_err = DACI_Set_Account_Password(accountId, password, "SE");
1561 if (da_err != DACI_SUCCESS) {
1562 FW_LOGE("failed in DACI_Set_Account_Email_Address");
1563 err = SE_INTERNAL_ERROR;
1567 result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
1568 if (result == false) {
1569 FW_LOGE("failed in set_config");
1570 err = SE_INTERNAL_DA_ERROR;
1574 err = __set_profile_info(accountId, profileName, syncMode, syncType, interval);
1575 if (err != SE_INTERNAL_OK) {
1576 FW_LOGE("failed in __set_profile_info");
1580 err = __set_periodic_sync_config(accountId, syncMode, interval);
1581 if (err != SE_INTERNAL_OK) {
1582 FW_LOGE("failed in __set_profile_info");
1586 sync_category *category = NULL;
1588 int contentType = 0;
1589 for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
1590 category = iter->data;
1591 err = __set_profile_category(accountId, contentType, category);
1592 if (err != SE_INTERNAL_OK) {
1593 FW_LOGE("failed in __set_profile_category");
1605 if (err != SE_INTERNAL_OK)
1611 bool delete_profile(GList *profiles)
1614 SE_ErrorType err = SE_INTERNAL_OK;
1615 char *profileName = NULL;
1619 DACI_RETURN da_err = DACI_Open_Agent();
1620 if (da_err != DACI_SUCCESS) {
1621 err = SE_INTERNAL_DA_ERROR;
1629 for (iter = profiles; iter != NULL; iter = g_list_next(iter)) {
1630 accountId = (int *)(iter->data);
1632 FW_LOGV("accountId = %d", *accountId);
1633 /*if deleteing Account's sync mode is periodic sync it has to be deleted from schedule_tbl*/
1634 result = get_config(*accountId, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
1635 if (result == false) {
1636 FW_LOGE("failed in get_config");
1637 err = SE_INTERNAL_DA_ERROR;
1640 alarmId = atoi(value);
1642 PMCI_RETURN scheduler_err = PMCI_Remove_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarmId);
1643 if (scheduler_err != PMCI_SUCCESS) {
1644 FW_LOGE("failed in PMCI_Remove_Item_To_Specific_Type");
1645 err = SE_INTERNAL_SCHEDULER_ERROR;
1649 deleteAccount(*accountId);
1668 if(accountId != NULL)
1671 if (err != SE_INTERNAL_OK)
1677 bool get_synchronising_profile(char **profileDirName)
1681 SE_ErrorType err = SE_INTERNAL_OK;
1685 int *account_list = 0;
1686 int account_list_count = 0;
1688 DACI_RETURN da_err = DACI_Open_Agent();
1689 if (da_err != DACI_SUCCESS) {
1690 err = SE_INTERNAL_DA_ERROR;
1694 account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
1697 for (i = 0; i < account_list_count; i++) {
1698 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, &value);
1699 if (result == false) {
1700 FW_LOGE("failed in set_Config");
1701 err = SE_INTERNAL_DA_ERROR;
1705 if (strcmp(value, "1") == 0) {
1706 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName);
1707 if (result == false) {
1708 FW_LOGE("failed in get_Config");
1709 err = SE_INTERNAL_DA_ERROR;
1723 if (account_list_count > 0)
1731 if (err != SE_INTERNAL_OK)
1738 bool add_profile_calllog(int *accountId)
1742 SE_ErrorType err = SE_INTERNAL_OK;
1743 DCI_RETURN dci_err = DCI_SUCCESS;
1745 sync_category *category = NULL;
1747 char *password = NULL;
1751 DACI_RETURN da_err = DACI_Open_Agent();
1752 if (da_err != DACI_SUCCESS) {
1753 err = SE_INTERNAL_DA_ERROR;
1757 /* FIXME get id from somewhere */
1758 /*get IMEI from Platform */
1759 id = "pcwds@samsung.com";
1761 dci_err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &password);
1762 if (dci_err != DCI_SUCCESS) {
1763 FW_LOGE("failed to get devinfo");
1767 err = __add_profile(DEFINE_CALLLOG_SERVER_URL_HTTPS, id, password, "CALLLOG", &account);
1768 if (err != SE_INTERNAL_OK) {
1769 FW_LOGE("failed in add_Account");
1773 err = __set_config_default_value(account);
1774 if (err != SE_INTERNAL_OK) {
1775 FW_LOGE("failed in add_Account");
1779 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, DEFINE_CALLLOG_SERVER_URL_HTTPS, "string", "SE");
1780 if (result == false) {
1781 FW_LOGE("failed in set_config");
1782 err = SE_INTERNAL_DA_ERROR;
1786 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR, "string", "SE");
1787 if (result == false) {
1788 FW_LOGE("failed in set_config");
1789 err = SE_INTERNAL_DA_ERROR;
1793 result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, DEFINE_CALLLOG_DEFAULT_NEXT_NONCE, "string", "SE");
1794 if (result == false) {
1795 FW_LOGE("failed in set_config");
1796 err = SE_INTERNAL_DA_ERROR;
1800 category = (sync_category *)calloc(1, sizeof(sync_category));
1802 category->enabled = 1;
1803 category->srcURI = DEFINE_SOURCE_CALLLOG_URI;
1804 category->tgtURI = "./CallLog";
1806 err = __set_profile_category(account, TYPE_CALLLOG, category);
1807 if (err != SE_INTERNAL_OK) {
1808 FW_LOGE("failed in __set_profile_category");
1812 *accountId = account;
1818 if(category != NULL)
1821 if(password != NULL)
1826 if (err != SE_INTERNAL_OK)
1832 bool delete_profile_calllog()
1836 SE_ErrorType err = SE_INTERNAL_OK;
1843 if (err != SE_INTERNAL_OK)