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 functions which saves and gets sync results
26 #include <sync_agent.h>
28 #include "common/common_util.h"
29 #include "service-engine/se_storage.h"
30 #include "service-engine/se_common.h"
32 #ifndef OMADS_AGENT_LOG
34 #define LOG_TAG "OMA_DS_SE"
37 static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type);
38 static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time);
39 static int _convert_sync_mode_value(char* sync_mode_str);
40 static int _convert_sync_type_value(char* sync_type_str);
41 static int _convert_interval_value(char* interval_str);
42 static int _convert_src_uri_value(char* src_uri_str);
44 static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type)
48 se_error_type_e err = SE_INTERNAL_OK;
51 char *syncType = NULL;
54 syncType = DEFINE_ALERT_SLOW_SYNC_STR;
57 syncType = DEFINE_ALERT_TWO_WAY_STR;
59 case ALERT_ONE_WAY_FROM_CLIENT:
60 syncType = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
62 case ALERT_ONE_WAY_FROM_SERVER:
63 syncType = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
65 case ALERT_REFRESH_FROM_SERVER:
66 syncType = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
68 case ALERT_REFRESH_FROM_CLIENT:
69 syncType = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
75 result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, syncType, "string", "SE");
76 if (result == false) {
77 _DEBUG_ERROR("failed in set_Config");
78 err = SE_INTERNAL_DA_ERROR;
89 static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time)
93 se_error_type_e err = SE_INTERNAL_OK;
96 result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, sync_session_result, "int", "SE");
97 if (result == false) {
98 _DEBUG_ERROR("failed in set_config");
99 err = SE_INTERNAL_DA_ERROR;
103 result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, last_session_time, "int", "SE");
104 if (result == false) {
105 _DEBUG_ERROR("failed in set_config");
106 err = SE_INTERNAL_DA_ERROR;
116 static int _convert_sync_mode_value(char* sync_mode_str)
119 _DEBUG_INFO("sync_mode_str: [%s]", sync_mode_str);
121 int sync_mode_value = 0;
123 if (strcmp(sync_mode_str,DEFINE_SYNC_MODE_MANUAL) == 0){
124 sync_mode_value = MODE_MANUAL;
125 } else if (strcmp(sync_mode_str,DEFINE_SYNC_MODE_PERIODIC) == 0){
126 sync_mode_value = MODE_PERIODIC;
127 } else if (strcmp(sync_mode_str,DEFINE_SYNC_MODE_PUSH) == 0){
128 sync_mode_value = MODE_PUSH;
130 _DEBUG_ERROR("sync_mode_str is invalid!!");
137 return sync_mode_value;
141 static int _convert_sync_type_value(char* sync_type_str)
144 _DEBUG_INFO("sync_type_str: [%s]", sync_type_str);
146 int sync_type_value = 0;
148 if (strcmp(sync_type_str,DEFINE_ALERT_SLOW_SYNC_STR) == 0){
149 sync_type_value = SYNC_TYPE_FULL_SYNC;
150 } else if (strcmp(sync_type_str,DEFINE_ALERT_TWO_WAY_STR) == 0){
151 sync_type_value = SYNC_TYPE_UPDATE_BOTH;
152 } else if (strcmp(sync_type_str,DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) == 0){
153 sync_type_value = SYNC_TYPE_UPDATE_TO_SERVER;
154 } else if (strcmp(sync_type_str,DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) == 0){
155 sync_type_value = SYNC_TYPE_UPDATE_TO_PHONE;
156 } else if (strcmp(sync_type_str,DEFINE_ALERT_REFRESH_FROM_SERVER_STR) == 0){
157 sync_type_value = SYNC_TYPE_REFRESH_FROM_SERVER;
158 } else if (strcmp(sync_type_str,DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) == 0){
159 sync_type_value = SYNC_TYPE_REFRESH_FROM_PHONE;
161 _DEBUG_ERROR("sync_type_str is invalid!!");
168 return sync_type_value;
172 static int _convert_interval_value(char* interval_str)
175 _DEBUG_INFO("interval_str: [%s]", interval_str);
177 int interval_value = 0;
179 if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_5_MINUTES_STR) == 0){
180 interval_value = SYNC_INTERVAL_5_MINUTES;
181 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_15_MINUTES_STR) == 0){
182 interval_value = SYNC_INTERVAL_15_MINUTES;
183 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_HOUR_STR) == 0){
184 interval_value = SYNC_INTERVAL_1_HOUR;
185 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_4_HOURS_STR) == 0){
186 interval_value = SYNC_INTERVAL_4_HOURS;
187 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_12_HOURS_STR) == 0){
188 interval_value = SYNC_INTERVAL_12_HOURS;
189 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_DAY_STR) == 0){
190 interval_value = SYNC_INTERVAL_1_DAY;
191 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_WEEK_STR) == 0){
192 interval_value = SYNC_INTERVAL_1_WEEK;
193 } else if (strcmp(interval_str,DEFINE_SYNC_INTERVAL_1_MONTH_STR) == 0){
194 interval_value = SYNC_INTERVAL_1_MONTH;
196 interval_value = SYNC_INTERVAL_NONE;
203 return interval_value;
207 static int _convert_src_uri_value(char* src_uri_str)
210 _DEBUG_INFO("src_uri_str: [%s]", src_uri_str);
212 int src_uri_value = 0;
214 if (strcmp(src_uri_str,DEFINE_SOURCE_CONTACT_URI) == 0){
215 src_uri_value = SRC_URI_CONTACT;
216 } else if (strcmp(src_uri_str,DEFINE_SOURCE_CALENDAR_URI) == 0){
217 src_uri_value = SRC_URI_CALENDAR;
218 } else if (strcmp(src_uri_str,DEFINE_SOURCE_MEMO_URI) == 0){
219 src_uri_value = SRC_URI_MEMO;
220 } else if (strcmp(src_uri_str,DEFINE_SOURCE_CALLLOG_URI) == 0){
221 src_uri_value = SRC_URI_CALLLOG;
223 _DEBUG_ERROR("src_uri_str is invalid!!");
230 return src_uri_value;
234 se_error_type_e write_profile_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client)
238 se_error_type_e err = SE_INTERNAL_OK;
240 err = _write_sync_type(account_id, alert_type);
241 if (err != SE_INTERNAL_OK) {
242 _DEBUG_ERROR("failed in writeSyncType");
246 err = _write_last_session_values(account_id, sync_session_result, last_session_time);
247 if (err != SE_INTERNAL_OK) {
248 _DEBUG_ERROR("failed in writeLastSessionValues");
253 for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) {
254 if (datastoreinfo_per_content_type[content_type] != NULL) {
255 if (datastoreinfo_per_content_type[content_type]->client_sync_type) {
256 err = write_sync_resource_info(account_id, content_type, last_session_time, only_from_client,
257 datastoreinfo_per_content_type[content_type]->client_sync_result, datastoreinfo_per_content_type[content_type]->server_sync_result);
258 if (err != SE_INTERNAL_OK) {
259 _DEBUG_ERROR("failed in writeSyncResourceInfo");
263 err = write_sync_statistics(account_id, content_type, true, datastoreinfo_per_content_type[content_type]->server_sync_result);
264 if (err != SE_INTERNAL_OK) {
265 _DEBUG_ERROR("failed in writeSyncStatistics");
269 err = write_sync_statistics(account_id, content_type, false, datastoreinfo_per_content_type[content_type]->client_sync_result);
270 if (err != SE_INTERNAL_OK) {
271 _DEBUG_ERROR("failed in writeSyncStatistics");
284 se_error_type_e write_sync_statistics(int account_id, int content_type, bool is_from_server, sync_result_s * sync_result)
288 se_error_type_e err = SE_INTERNAL_OK;
291 char *datastore = NULL;
293 char numberOfChangesPath[128];
294 char addCountPath[128];
295 char replaceCountPath[128];
296 char deleteCountPath[128];
298 if (content_type == TYPE_CONTACT)
299 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
300 else if (content_type == TYPE_CALENDAR)
301 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
302 else if (content_type == TYPE_MEMO)
303 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
304 else if (content_type == TYPE_CALLLOG)
305 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
307 if (is_from_server == true)
308 side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER;
310 side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT;
312 _DEBUG_INFO("pSyncResult->numberOfChange = %d", sync_result->number_of_change);
313 _DEBUG_INFO("pSyncResult->add_count = %d", sync_result->add_count);
314 _DEBUG_INFO("pSyncResult->replace_count = %d", sync_result->replace_count);
315 _DEBUG_INFO("pSyncResult->delete_count = %d", sync_result->delete_count);
317 snprintf(numberOfChangesPath, sizeof(numberOfChangesPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
318 snprintf(addCountPath, sizeof(addCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
319 snprintf(replaceCountPath, sizeof(replaceCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
320 snprintf(deleteCountPath, sizeof(deleteCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
322 result = set_config_int(account_id, numberOfChangesPath, sync_result->number_of_change, "int", "SE");
323 if (result == false) {
324 _DEBUG_ERROR("failed in set_config");
325 err = SE_INTERNAL_DA_ERROR;
329 result = set_config_int(account_id, addCountPath, sync_result->add_count, "int", "SE");
330 if (result == false) {
331 _DEBUG_ERROR("failed in set_config");
332 err = SE_INTERNAL_DA_ERROR;
336 result = set_config_int(account_id, replaceCountPath, sync_result->replace_count, "int", "SE");
337 if (result == false) {
338 _DEBUG_ERROR("failed in set_config");
339 err = SE_INTERNAL_DA_ERROR;
343 result = set_config_int(account_id, deleteCountPath, sync_result->delete_count, "int", "SE");
344 if (result == false) {
345 _DEBUG_ERROR("failed in set_config");
346 err = SE_INTERNAL_DA_ERROR;
357 se_error_type_e write_sync_resource_info(int account_id, int content_type, int last_session_time, int only_from_client, sync_result_s * client_sync_result, sync_result_s * server_sync_result)
361 se_error_type_e err = SE_INTERNAL_OK;
363 char *datastore = NULL;
364 char dbSyncedPath[128];
365 char lastSessionTimePath[128];
367 if (client_sync_result == NULL) {
368 _DEBUG_ERROR("clientSyncResult is NULL");
369 err = SE_INTERNAL_NOT_DEFINED;
373 if (server_sync_result == NULL) {
374 _DEBUG_ERROR("serverSyncResult is NULL");
375 err = SE_INTERNAL_NOT_DEFINED;
379 if (content_type == TYPE_CONTACT)
380 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
381 else if (content_type == TYPE_CALENDAR)
382 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
383 else if (content_type == TYPE_MEMO)
384 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
385 else if (content_type == TYPE_CALLLOG)
386 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
388 _DEBUG_INFO("clientSyncResult->sessionResult = %d", client_sync_result->session_result);
389 _DEBUG_INFO("serverSyncResult->sessionResult = %d", server_sync_result->session_result);
392 if (client_sync_result->session_result == SYNC_SESSION_SUCCEEDED && (server_sync_result->session_result == SYNC_SESSION_SUCCEEDED || only_from_client))
393 dbSynced = DEFINE_DBSYNC_SUCCESS;
394 else if (client_sync_result->session_result == SYNC_SESSION_STOPPED)
395 dbSynced = DEFINE_DBSYNC_STOP;
397 dbSynced = DEFINE_DBSYNC_FAIL;
399 _DEBUG_INFO("dbSynced = %s", dbSynced);
401 snprintf(dbSyncedPath, sizeof(dbSyncedPath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
402 snprintf(lastSessionTimePath, sizeof(lastSessionTimePath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
404 result = set_config_str(account_id, dbSyncedPath, dbSynced, "string", "SE");
405 if (result == false) {
406 _DEBUG_ERROR("failed in set_config");
407 err = SE_INTERNAL_DA_ERROR;
411 result = set_config_int(account_id, lastSessionTimePath, last_session_time, "int", "SE");
412 if (result == false) {
413 _DEBUG_ERROR("failed in set_config");
414 err = SE_INTERNAL_DA_ERROR;
424 bool get_profile_data(int account_id, char **profile_dir_name, char **profile_name, char **addr, char **id, char **password, int *sync_mode, int *sync_type, int *interval, int *last_session_status, int *last_session_time)
428 se_error_type_e err = SE_INTERNAL_OK;
429 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
430 sync_agent_fw_account_s *fw_account = NULL;
432 GList *config_list = NULL;
434 sync_agent_da_config_s *config_data = NULL;
436 char *sync_mode_str = NULL;
437 char *sync_type_str = NULL;
438 char *interval_str = NULL;
439 int sync_mode_value = 0;
440 int sync_type_value = 0;
441 int interval_value = 0;
442 char *lastSessionStatus_str = NULL;
443 char *lastSessionTime_str = NULL;
445 sync_agent_da_return_e da_err = sync_agent_open_agent();
446 if (da_err != SYNC_AGENT_DA_SUCCESS) {
447 err = SE_INTERNAL_DA_ERROR;
451 acc_err = sync_agent_create_fw_account(&fw_account);
452 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
453 _DEBUG_ERROR("failed in sync_agent_create_fw_account");
454 err = SE_INTERNAL_NO_MEMORY;
458 acc_err = sync_agent_get_fw_account(account_id, &fw_account);
459 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
460 _DEBUG_ERROR("failed in sync_agent_update_fw_account");
461 err = SE_INTERNAL_ERROR;
465 if ((fw_account->account_id == 0)) {
466 _DEBUG_ERROR("Profile don't exists!!, account_id: [%d]", account_id);
467 err = SE_INTERNAL_ERROR;
471 if (fw_account->email != NULL)
472 *id = strdup(fw_account->email);
474 if (fw_account->password != NULL)
475 *password = strdup(fw_account->password);
477 da_err = sync_agent_get_config_list(account_id, &config_list);
478 if (da_err != SYNC_AGENT_DA_SUCCESS) {
479 err = SE_INTERNAL_DA_ERROR;
483 for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
484 config_data = (sync_agent_da_config_s *) iter->data;
486 if (config_data != NULL) {
487 if (config_data->key != NULL) {
489 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME) == 0) {
490 if (config_data->value != NULL) {
491 *profile_dir_name = strdup(config_data->value);
496 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) {
497 if (config_data->value != NULL) {
498 *profile_name = strdup(config_data->value);
503 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) {
504 if (config_data->value != NULL) {
505 *addr = strdup(config_data->value);
510 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) {
511 if (config_data->value != NULL) {
512 sync_mode_str = strdup(config_data->value);
517 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) {
518 if (config_data->value != NULL) {
519 sync_type_str = strdup(config_data->value);
524 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) {
525 if (config_data->value != NULL) {
526 interval_str = strdup(config_data->value);
531 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) {
532 if (config_data->value != NULL) {
533 lastSessionStatus_str = strdup(config_data->value);
538 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) {
539 if (config_data->value != NULL) {
540 lastSessionTime_str = strdup(config_data->value);
548 if (sync_mode_str != NULL) {
549 sync_mode_value = _convert_sync_mode_value(sync_mode_str);
550 _DEBUG_INFO("sync_mode_value: [%d]", sync_mode_value);
551 *sync_mode = sync_mode_value;
554 if (sync_type_str != NULL) {
555 sync_type_value = _convert_sync_type_value(sync_type_str);
556 _DEBUG_INFO("sync_type_value: [%d]", sync_type_value);
557 *sync_type = sync_type_value;
560 if (interval_str != NULL) {
561 interval_value = _convert_interval_value(interval_str);
562 _DEBUG_INFO("interval_value: [%d]", interval_value);
563 *interval = interval_value;
566 if (lastSessionStatus_str != NULL)
567 *last_session_status = atoi(lastSessionStatus_str);
569 if (lastSessionTime_str != NULL)
570 *last_session_time = atoi(lastSessionTime_str);
574 sync_agent_free_fw_account(fw_account);
576 sync_agent_free_config_list(config_list);
578 sync_agent_close_agent();
580 if (sync_mode_str != NULL) {
582 sync_mode_str = NULL;
585 if (sync_type_str != NULL) {
587 sync_type_str = NULL;
590 if (interval_str != NULL) {
595 if (lastSessionStatus_str != NULL) {
596 free(lastSessionStatus_str);
597 lastSessionStatus_str = NULL;
600 if (lastSessionTime_str != NULL) {
601 free(lastSessionTime_str);
602 lastSessionTime_str = NULL;
607 if (err != SE_INTERNAL_OK)
613 bool get_profile_sync_category(int account_id, int content_type, int *enabled, int *src_uri, char **tgt_uri, char **id, char **password)
617 se_error_type_e err = SE_INTERNAL_OK;
618 char *datastore = NULL;
619 char *enabled_str = NULL;
620 char *src_uri_str = NULL;
621 int src_uri_value = 0;
623 char datastore_source[128];
624 char datastore_target[128];
625 char datastore_id[128];
626 char datastore_pw[128];
628 GList *config_list = NULL;
630 sync_agent_da_config_s *config_data = NULL;
632 if (content_type == TYPE_CONTACT)
633 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
634 else if (content_type == TYPE_CALENDAR)
635 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
636 else if (content_type == TYPE_MEMO)
637 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
638 else if (content_type == TYPE_CALLLOG)
639 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
641 snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
642 snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
643 snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
644 snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
646 sync_agent_da_return_e da_err = sync_agent_open_agent();
647 if (da_err != SYNC_AGENT_DA_SUCCESS) {
648 err = SE_INTERNAL_DA_ERROR;
652 da_err = sync_agent_get_config_list(account_id, &config_list);
653 if (da_err != SYNC_AGENT_DA_SUCCESS) {
654 err = SE_INTERNAL_DA_ERROR;
658 for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
659 config_data = (sync_agent_da_config_s *) iter->data;
661 if (config_data != NULL) {
662 if (config_data->key != NULL) {
663 if (datastore != NULL) {
664 if (strcmp(config_data->key, datastore) == 0) {
665 if (config_data->value != NULL) {
666 enabled_str = strdup(config_data->value);
671 _DEBUG_ERROR("datastore is NULL !!");
672 err = SE_INTERNAL_ERROR;
676 if (strcmp(config_data->key, datastore_source) == 0) {
677 if (config_data->value != NULL) {
678 src_uri_str = strdup(config_data->value);
683 if (strcmp(config_data->key, datastore_target) == 0) {
684 if (config_data->value != NULL) {
685 *tgt_uri = strdup(config_data->value);
690 if (strcmp(config_data->key, datastore_id) == 0) {
691 if (config_data->value != NULL) {
692 *id = strdup(config_data->value);
697 if (strcmp(config_data->key, datastore_pw) == 0) {
698 if (config_data->value != NULL) {
699 *password = strdup(config_data->value);
707 if (enabled_str != NULL)
708 *enabled = atoi(enabled_str);
710 if (src_uri_str != NULL) {
711 src_uri_value = _convert_src_uri_value(src_uri_str);
712 *src_uri = src_uri_value;
717 sync_agent_free_config_list(config_list);
719 sync_agent_close_agent();
721 if (enabled_str != NULL) {
726 if (src_uri_str != NULL) {
733 if (err != SE_INTERNAL_OK)
740 bool get_profile_statistics(int account_id, int content_type, char **db_synced, int *last_session_time,
741 int *server2client_total, int *server2client_nrofadd, int *server2client_nrofdelete, int *server2client_nrofreplace,
742 int *client2server_total, int *client2server_nrofadd, int *client2server_nrofdelete, int *client2server_nrofreplace)
746 se_error_type_e err = SE_INTERNAL_OK;
748 char *datastore = NULL;
749 char datastore_dbsynced[128];
750 char datastore_lastsessiontime[128];
751 char datastore_s2c_total[128];
752 char datastore_s2c_add[128];
753 char datastore_s2c_replace[128];
754 char datastore_s2c_delete[128];
755 char datastore_c2s_total[128];
756 char datastore_c2s_add[128];
757 char datastore_c2s_replace[128];
758 char datastore_c2s_delete[128];
760 char *lastSessionTime_str = NULL;
761 char *server2Client_Total_str = NULL;
762 char *server2Client_NrOfAdd_str = NULL;
763 char *server2Client_NrOfDelete_str = NULL;
764 char *server2Client_NrOfReplace_str = NULL;
765 char *client2Server_Total_str = NULL;
766 char *client2Server_NrOfAdd_str = NULL;
767 char *client2Server_NrOfDelete_str = NULL;
768 char *client2Server_NrOfReplace_str = NULL;
770 GList *config_list = NULL;
772 sync_agent_da_config_s *config_data = NULL;
774 if (content_type == TYPE_CONTACT)
775 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
776 else if (content_type == TYPE_CALENDAR)
777 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
778 else if (content_type == TYPE_MEMO)
779 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
780 else if (content_type == TYPE_CALLLOG)
781 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
783 snprintf(datastore_dbsynced, sizeof(datastore_dbsynced), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
784 snprintf(datastore_lastsessiontime, sizeof(datastore_lastsessiontime), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
785 snprintf(datastore_s2c_total, sizeof(datastore_s2c_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
786 snprintf(datastore_s2c_add, sizeof(datastore_s2c_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
787 snprintf(datastore_s2c_delete, sizeof(datastore_s2c_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
788 snprintf(datastore_s2c_replace, sizeof(datastore_s2c_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
790 snprintf(datastore_c2s_total, sizeof(datastore_c2s_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
791 snprintf(datastore_c2s_add, sizeof(datastore_c2s_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
792 snprintf(datastore_c2s_delete, sizeof(datastore_c2s_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
793 snprintf(datastore_c2s_replace, sizeof(datastore_c2s_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
795 sync_agent_da_return_e da_err = sync_agent_open_agent();
796 if (da_err != SYNC_AGENT_DA_SUCCESS) {
797 err = SE_INTERNAL_DA_ERROR;
801 da_err = sync_agent_get_config_list(account_id, &config_list);
802 if (da_err != SYNC_AGENT_DA_SUCCESS) {
803 err = SE_INTERNAL_DA_ERROR;
807 for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
808 config_data = (sync_agent_da_config_s *) iter->data;
810 if (config_data != NULL) {
811 if (config_data->key != NULL) {
812 if (strcmp(config_data->key, datastore_dbsynced) == 0) {
813 if (config_data->value != NULL) {
814 *db_synced = strdup(config_data->value);
819 if (strcmp(config_data->key, datastore_lastsessiontime) == 0) {
820 if (config_data->value != NULL) {
821 lastSessionTime_str = strdup(config_data->value);
826 if (strcmp(config_data->key, datastore_s2c_total) == 0) {
827 if (config_data->value != NULL) {
828 server2Client_Total_str = strdup(config_data->value);
833 if (strcmp(config_data->key, datastore_s2c_add) == 0) {
834 if (config_data->value != NULL) {
835 server2Client_NrOfAdd_str = strdup(config_data->value);
840 if (strcmp(config_data->key, datastore_s2c_delete) == 0) {
841 if (config_data->value != NULL) {
842 server2Client_NrOfDelete_str = strdup(config_data->value);
847 if (strcmp(config_data->key, datastore_s2c_replace) == 0) {
848 if (config_data->value != NULL) {
849 server2Client_NrOfReplace_str = strdup(config_data->value);
854 if (strcmp(config_data->key, datastore_c2s_total) == 0) {
855 if (config_data->value != NULL) {
856 client2Server_Total_str = strdup(config_data->value);
861 if (strcmp(config_data->key, datastore_c2s_add) == 0) {
862 if (config_data->value != NULL) {
863 client2Server_NrOfAdd_str = strdup(config_data->value);
868 if (strcmp(config_data->key, datastore_c2s_delete) == 0) {
869 if (config_data->value != NULL) {
870 client2Server_NrOfDelete_str = strdup(config_data->value);
875 if (strcmp(config_data->key, datastore_c2s_replace) == 0) {
876 if (config_data->value != NULL) {
877 client2Server_NrOfReplace_str = strdup(config_data->value);
885 if (lastSessionTime_str != NULL)
886 *last_session_time = atoi(lastSessionTime_str);
888 if (server2Client_Total_str != NULL)
889 *server2client_total = atoi(server2Client_Total_str);
891 if (server2Client_NrOfAdd_str != NULL)
892 *server2client_nrofadd = atoi(server2Client_NrOfAdd_str);
894 if (server2Client_NrOfDelete_str != NULL)
895 *server2client_nrofdelete = atoi(server2Client_NrOfDelete_str);
897 if (server2Client_NrOfReplace_str != NULL)
898 *server2client_nrofreplace = atoi(server2Client_NrOfReplace_str);
900 if (client2Server_Total_str != NULL)
901 *client2server_total = atoi(client2Server_Total_str);
903 if (client2Server_NrOfAdd_str != NULL)
904 *client2server_nrofadd = atoi(client2Server_NrOfAdd_str);
906 if (client2Server_NrOfDelete_str != NULL)
907 *client2server_nrofdelete = atoi(client2Server_NrOfDelete_str);
909 if (client2Server_NrOfReplace_str != NULL)
910 *client2server_nrofreplace = atoi(client2Server_NrOfReplace_str);
914 sync_agent_free_config_list(config_list);
916 sync_agent_close_agent();
918 if (lastSessionTime_str != NULL)
919 free(lastSessionTime_str);
921 if (server2Client_Total_str != NULL)
922 free(server2Client_Total_str);
924 if (server2Client_NrOfAdd_str != NULL)
925 free(server2Client_NrOfAdd_str);
927 if (server2Client_NrOfDelete_str != NULL)
928 free(server2Client_NrOfDelete_str);
930 if (server2Client_NrOfReplace_str != NULL)
931 free(server2Client_NrOfReplace_str);
933 if (client2Server_Total_str != NULL)
934 free(client2Server_Total_str);
936 if (client2Server_NrOfAdd_str != NULL)
937 free(client2Server_NrOfAdd_str);
939 if (client2Server_NrOfDelete_str != NULL)
940 free(client2Server_NrOfDelete_str);
942 if (client2Server_NrOfReplace_str != NULL)
943 free(client2Server_NrOfReplace_str);
947 if (err != SE_INTERNAL_OK)
953 bool get_all_profiles_data(GList ** list)
957 se_error_type_e err = SE_INTERNAL_OK;
958 sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
960 GList *account_info_list = NULL;
961 GList *account_iter = NULL;
962 sync_agent_fw_account_s *fw_account = NULL;
964 GList *config_list = NULL;
966 sync_agent_da_config_s *config_data = NULL;
968 sync_agent_ds_profile_info *profile_info = NULL;
969 GList *account_list = NULL;
970 GList *free_iter = NULL;
972 sync_agent_ds_service_info *category_info = NULL;
973 char* sync_mode_str = NULL;
974 char* sync_type_str = NULL;
975 char* interval_str = NULL;
976 char* src_uri_str = NULL;
977 int sync_mode_value = 0;
978 int sync_type_value = 0;
979 int interval_value = 0;
980 int src_uri_value = 0;
982 sync_agent_da_return_e da_err = sync_agent_open_agent();
983 if (da_err != SYNC_AGENT_DA_SUCCESS) {
984 err = SE_INTERNAL_DA_ERROR;
988 sync_agent_fw_account_query_s query;
989 query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
990 query.access_name = "SE";
992 acc_err = sync_agent_query_fw_account(&query, &account_info_list);
993 if (acc_err != SYNC_AGENT_ACC_SUCCESS) {
994 _DEBUG_ERROR("sync_agent_query_fw_account is failed");
998 for (account_iter = account_info_list; account_iter != NULL; account_iter = g_list_next(account_iter)) {
999 fw_account = (sync_agent_fw_account_s *) account_iter->data;
1001 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
1002 if (profile_info == NULL) {
1003 _DEBUG_ERROR("profile_info is NULL");
1007 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1008 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1010 if (fw_account->email != NULL)
1011 server_info->id = strdup(fw_account->email);
1013 if (fw_account->password != NULL)
1014 server_info->password = strdup(fw_account->password);
1016 da_err = sync_agent_get_config_list(fw_account->account_id, &config_list);
1017 if (da_err != SYNC_AGENT_DA_SUCCESS) {
1018 err = SE_INTERNAL_DA_ERROR;
1022 for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
1023 config_data = (sync_agent_da_config_s *) iter->data;
1025 if (config_data != NULL) {
1026 if (config_data->key != NULL) {
1028 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_ID) == 0) {
1029 if (config_data->value != NULL) {
1030 profile_info->profile_id = atoi(config_data->value);
1035 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME) == 0) {
1036 if (config_data->value != NULL) {
1037 profile_info->profile_dir_name = strdup(config_data->value);
1042 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) {
1043 if (config_data->value != NULL) {
1044 profile_info->profile_name = strdup(config_data->value);
1049 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) {
1050 if (config_data->value != NULL) {
1051 server_info->addr = strdup(config_data->value);
1056 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) {
1057 if (config_data->value != NULL) {
1058 sync_mode_str = strdup(config_data->value);
1059 sync_mode_value = _convert_sync_mode_value(sync_mode_str);
1060 _DEBUG_INFO("sync_mode_value: [%d]", sync_mode_value);
1061 sync_info->sync_mode = sync_mode_value;
1066 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) {
1067 if (config_data->value != NULL) {
1068 sync_type_str = strdup(config_data->value);
1069 sync_type_value = _convert_sync_type_value(sync_type_str);
1070 _DEBUG_INFO("sync_type_value: [%d]", sync_type_value);
1071 sync_info->sync_type = sync_type_value;
1076 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) {
1077 if (config_data->value != NULL) {
1078 interval_str = strdup(config_data->value);
1079 interval_value = _convert_interval_value(interval_str);
1080 _DEBUG_INFO("interval_value: [%d]", interval_value);
1081 sync_info->interval =interval_value;
1086 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) {
1087 if (config_data->value != NULL) {
1088 profile_info->last_sync_status = atoi(config_data->value);
1093 if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) {
1094 if (config_data->value != NULL) {
1095 profile_info->last_sync_time = atoi(config_data->value);
1104 for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) {
1106 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1107 if (category_info == NULL) {
1108 _DEBUG_ERROR("category_info is NULL");
1112 char *datastore = NULL;
1114 char datastore_source[128];
1115 char datastore_target[128];
1116 char datastore_id[128];
1117 char datastore_pw[128];
1119 if (content_type == TYPE_CONTACT) {
1120 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
1121 category_info->service_type = SYNC_AGENT_CONTACT;
1122 } else if (content_type == TYPE_CALENDAR) {
1123 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
1124 category_info->service_type = SYNC_AGENT_CALENDAR;
1125 } else if (content_type == TYPE_MEMO) {
1126 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
1127 category_info->service_type = SYNC_AGENT_MEMO;
1128 } else if (content_type == TYPE_CALLLOG) {
1129 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
1130 category_info->service_type = SYNC_AGENT_CALLLOG;
1133 snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
1134 snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
1135 snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
1136 snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
1138 for (iter = config_list; iter != NULL; iter = g_list_next(iter)) {
1139 config_data = (sync_agent_da_config_s *) iter->data;
1141 if (config_data != NULL) {
1142 if (config_data->key != NULL) {
1143 if (strcmp(config_data->key, datastore) == 0) {
1144 if (config_data->value != NULL) {
1145 category_info->enabled = atoi(config_data->value);
1150 if (strcmp(config_data->key, datastore_source) == 0) {
1151 if (config_data->value != NULL) {
1152 src_uri_str = strdup(config_data->value);
1153 src_uri_value = _convert_src_uri_value(src_uri_str);
1154 _DEBUG_INFO("src_uri_value: [%d]", src_uri_value);
1155 category_info->src_uri = src_uri_value;
1160 if (strcmp(config_data->key, datastore_target) == 0) {
1161 if (config_data->value != NULL) {
1162 category_info->tgt_uri = strdup(config_data->value);
1167 if (strcmp(config_data->key, datastore_id) == 0) {
1168 if (config_data->value != NULL) {
1169 category_info->id = strdup(config_data->value);
1174 if (strcmp(config_data->key, datastore_pw) == 0) {
1175 if (config_data->value != NULL) {
1176 category_info->password = strdup(config_data->value);
1184 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1185 category_info = NULL;
1188 sync_agent_free_config_list(config_list);
1191 account_list = g_list_append(account_list, profile_info);
1192 profile_info = NULL;
1195 *list = account_list;
1196 account_list = NULL;
1200 if (sync_mode_str != NULL) {
1201 free(sync_mode_str);
1202 sync_mode_str = NULL;
1205 if (sync_type_str != NULL) {
1206 free(sync_type_str);
1207 sync_type_str = NULL;
1210 if (interval_str != NULL) {
1212 interval_str = NULL;
1215 if (src_uri_str != NULL) {
1220 for (free_iter = account_list; free_iter != NULL; free_iter = g_list_next(free_iter)) {
1221 sync_agent_ds_free_profile_info((ds_profile_h) free_iter->data);
1222 _DEBUG_INFO("free sync_agent_ds_profile_info");
1225 if (profile_info != NULL) {
1227 profile_info = NULL;
1230 sync_agent_free_fw_account_list(account_info_list);
1232 sync_agent_free_config_list(config_list);
1234 sync_agent_close_agent();
1238 if (err != SE_INTERNAL_OK)