diff options
Diffstat (limited to 'src/agent/service-engine/se_storage.c')
-rwxr-xr-x | src/agent/service-engine/se_storage.c | 1000 |
1 files changed, 1000 insertions, 0 deletions
diff --git a/src/agent/service-engine/se_storage.c b/src/agent/service-engine/se_storage.c new file mode 100755 index 0000000..51beeff --- /dev/null +++ b/src/agent/service-engine/se_storage.c @@ -0,0 +1,1000 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @SE_Storage.c + * @version 0.1 + * @brief This file is the source file of implementation of functions which saves and gets sync results + */ + +#include <stdlib.h> + +#include <sync_agent.h> + +#include "common/common_util.h" +#include "service-engine/se_storage.h" +#include "service-engine/se_common.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SE" +#endif + +static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type); +static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time); + +static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + char *syncType = NULL; + switch (alert_type) { + case ALERT_SLOW_SYNC: + syncType = DEFINE_ALERT_SLOW_SYNC_STR; + break; + case ALERT_TWO_WAY: + syncType = DEFINE_ALERT_TWO_WAY_STR; + break; + case ALERT_ONE_WAY_FROM_CLIENT: + syncType = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR; + break; + case ALERT_ONE_WAY_FROM_SERVER: + syncType = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR; + break; + case ALERT_REFRESH_FROM_SERVER: + syncType = DEFINE_ALERT_REFRESH_FROM_SERVER_STR; + break; + case ALERT_REFRESH_FROM_CLIENT: + syncType = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR; + break; + default: + break; + } + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, syncType, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; + +} + +static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, sync_session_result, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, last_session_time, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +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) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + err = _write_sync_type(account_id, alert_type); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncType"); + goto error; + } + + err = _write_last_session_values(account_id, sync_session_result, last_session_time); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeLastSessionValues"); + goto error; + } + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + err = write_sync_resource_info(account_id, content_type, last_session_time, only_from_client, + datastoreinfo_per_content_type[content_type]->client_sync_result, datastoreinfo_per_content_type[content_type]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncResourceInfo"); + goto error; + } + + err = write_sync_statistics(account_id, content_type, true, datastoreinfo_per_content_type[content_type]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncStatistics"); + goto error; + } + + err = write_sync_statistics(account_id, content_type, false, datastoreinfo_per_content_type[content_type]->client_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncStatistics"); + goto error; + } + } + } + } + + error: + + _EXTERN_FUNC_EXIT; + return err; +} + +se_error_type_e write_sync_statistics(int account_id, int content_type, bool is_from_server, sync_result_s * sync_result) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + bool result; + char *datastore = NULL; + char *side = NULL; + char numberOfChangesPath[128]; + char addCountPath[128]; + char replaceCountPath[128]; + char deleteCountPath[128]; + + if (content_type == TYPE_CONTACT) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + else if (content_type == TYPE_CALENDAR) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + else if (content_type == TYPE_MEMO) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + else if (content_type == TYPE_CALLLOG) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + + if (is_from_server == true) + side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER; + else + side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT; + + _DEBUG_INFO("pSyncResult->numberOfChange = %d", sync_result->number_of_change); + _DEBUG_INFO("pSyncResult->add_count = %d", sync_result->add_count); + _DEBUG_INFO("pSyncResult->replace_count = %d", sync_result->replace_count); + _DEBUG_INFO("pSyncResult->delete_count = %d", sync_result->delete_count); + + snprintf(numberOfChangesPath, sizeof(numberOfChangesPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(addCountPath, sizeof(addCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(replaceCountPath, sizeof(replaceCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + snprintf(deleteCountPath, sizeof(deleteCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + + result = set_config_int(account_id, numberOfChangesPath, sync_result->number_of_change, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, addCountPath, sync_result->add_count, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, replaceCountPath, sync_result->replace_count, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, deleteCountPath, sync_result->delete_count, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _EXTERN_FUNC_EXIT; + return err; + +} + +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) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + char *datastore = NULL; + char dbSyncedPath[128]; + char lastSessionTimePath[128]; + + if (client_sync_result == NULL) { + _DEBUG_ERROR("clientSyncResult is NULL"); + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + if (server_sync_result == NULL) { + _DEBUG_ERROR("serverSyncResult is NULL"); + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + if (content_type == TYPE_CONTACT) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + else if (content_type == TYPE_CALENDAR) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + else if (content_type == TYPE_MEMO) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + else if (content_type == TYPE_CALLLOG) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + + _DEBUG_INFO("clientSyncResult->sessionResult = %d", client_sync_result->session_result); + _DEBUG_INFO("serverSyncResult->sessionResult = %d", server_sync_result->session_result); + + char *dbSynced; + if (client_sync_result->session_result == SYNC_SESSION_SUCCEEDED && (server_sync_result->session_result == SYNC_SESSION_SUCCEEDED || only_from_client)) + dbSynced = DEFINE_DBSYNC_SUCCESS; + else if (client_sync_result->session_result == SYNC_SESSION_STOPPED) + dbSynced = DEFINE_DBSYNC_STOP; + else + dbSynced = DEFINE_DBSYNC_FAIL; + + _DEBUG_INFO("dbSynced = %s", dbSynced); + + snprintf(dbSyncedPath, sizeof(dbSyncedPath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED); + snprintf(lastSessionTimePath, sizeof(lastSessionTimePath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME); + + result = set_config_str(account_id, dbSyncedPath, dbSynced, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, lastSessionTimePath, last_session_time, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _EXTERN_FUNC_EXIT; + return err; +} + +bool get_profile_data(int account_id, char **profile_name, char **addr, char **id, char **password, char **sync_mode, char **sync_type, char **interval, int *last_session_status, int *last_session_time) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + char *lastSessionStatus_str = NULL; + char *lastSessionTime_str = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + acc_err = sync_agent_create_fw_account(&fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_fw_account"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + acc_err = sync_agent_get_fw_account(account_id, &fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_update_fw_account"); + err = SE_INTERNAL_ERROR; + goto error; + } + + if (fw_account->email != NULL) + *id = strdup(fw_account->email); + + if (fw_account->password != NULL) + *password = strdup(fw_account->password); + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) { + if (config_data->value != NULL) { + *profile_name = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) { + if (config_data->value != NULL) { + *addr = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) { + if (config_data->value != NULL) { + *sync_mode = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) { + if (config_data->value != NULL) { + *sync_type = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) { + if (config_data->value != NULL) { + *interval = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) { + if (config_data->value != NULL) { + lastSessionStatus_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) { + if (config_data->value != NULL) { + lastSessionTime_str = strdup(config_data->value); + continue; + } + } + } + } + } + + if (lastSessionStatus_str != NULL) + *last_session_status = atoi(lastSessionStatus_str); + + if (lastSessionTime_str != NULL) + *last_session_time = atoi(lastSessionTime_str); + + error: + + sync_agent_free_fw_account(fw_account); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + if (lastSessionStatus_str != NULL) + free(lastSessionStatus_str); + + if (lastSessionTime_str != NULL) + free(lastSessionTime_str); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool get_profile_sync_category(int account_id, int content_type, int *enabled, char **src_uri, char **tgt_uri, char **id, char **password) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + char *datastore = NULL; + char *enabled_str = NULL; + + char datastore_source[128]; + char datastore_target[128]; + char datastore_id[128]; + char datastore_pw[128]; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + if (content_type == TYPE_CONTACT) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + else if (content_type == TYPE_CALENDAR) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + else if (content_type == TYPE_MEMO) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + else if (content_type == TYPE_CALLLOG) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + + snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (datastore != NULL) { + if (strcmp(config_data->key, datastore) == 0) { + if (config_data->value != NULL) { + enabled_str = strdup(config_data->value); + continue; + } + } + } else { + _DEBUG_ERROR("datastore is NULL !!"); + err = SE_INTERNAL_ERROR; + goto error; + } + + if (strcmp(config_data->key, datastore_source) == 0) { + if (config_data->value != NULL) { + *src_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_target) == 0) { + if (config_data->value != NULL) { + *tgt_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_id) == 0) { + if (config_data->value != NULL) { + *id = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_pw) == 0) { + if (config_data->value != NULL) { + *password = strdup(config_data->value); + continue; + } + } + } + } + } + + if (enabled_str != NULL) + *enabled = atoi(enabled_str); + + error: + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + if (enabled_str != NULL) + free(enabled_str); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; + +} + +bool get_profile_statistics(int account_id, int content_type, char **db_synced, int *last_session_time, + int *server2client_total, int *server2client_nrofadd, int *server2client_nrofdelete, int *server2client_nrofreplace, + int *client2server_total, int *client2server_nrofadd, int *client2server_nrofdelete, int *client2server_nrofreplace) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + char *datastore = NULL; + char datastore_dbsynced[128]; + char datastore_lastsessiontime[128]; + char datastore_s2c_total[128]; + char datastore_s2c_add[128]; + char datastore_s2c_replace[128]; + char datastore_s2c_delete[128]; + char datastore_c2s_total[128]; + char datastore_c2s_add[128]; + char datastore_c2s_replace[128]; + char datastore_c2s_delete[128]; + + char *lastSessionTime_str = NULL; + char *server2Client_Total_str = NULL; + char *server2Client_NrOfAdd_str = NULL; + char *server2Client_NrOfDelete_str = NULL; + char *server2Client_NrOfReplace_str = NULL; + char *client2Server_Total_str = NULL; + char *client2Server_NrOfAdd_str = NULL; + char *client2Server_NrOfDelete_str = NULL; + char *client2Server_NrOfReplace_str = NULL; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + if (content_type == TYPE_CONTACT) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + else if (content_type == TYPE_CALENDAR) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + else if (content_type == TYPE_MEMO) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + else if (content_type == TYPE_CALLLOG) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + + snprintf(datastore_dbsynced, sizeof(datastore_dbsynced), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED); + snprintf(datastore_lastsessiontime, sizeof(datastore_lastsessiontime), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME); + snprintf(datastore_s2c_total, sizeof(datastore_s2c_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(datastore_s2c_add, sizeof(datastore_s2c_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(datastore_s2c_delete, sizeof(datastore_s2c_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + snprintf(datastore_s2c_replace, sizeof(datastore_s2c_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + + snprintf(datastore_c2s_total, sizeof(datastore_c2s_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(datastore_c2s_add, sizeof(datastore_c2s_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(datastore_c2s_delete, sizeof(datastore_c2s_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + snprintf(datastore_c2s_replace, sizeof(datastore_c2s_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, datastore_dbsynced) == 0) { + if (config_data->value != NULL) { + *db_synced = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_lastsessiontime) == 0) { + if (config_data->value != NULL) { + lastSessionTime_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_total) == 0) { + if (config_data->value != NULL) { + server2Client_Total_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_add) == 0) { + if (config_data->value != NULL) { + server2Client_NrOfAdd_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_delete) == 0) { + if (config_data->value != NULL) { + server2Client_NrOfDelete_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_replace) == 0) { + if (config_data->value != NULL) { + server2Client_NrOfReplace_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_total) == 0) { + if (config_data->value != NULL) { + client2Server_Total_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_add) == 0) { + if (config_data->value != NULL) { + client2Server_NrOfAdd_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_delete) == 0) { + if (config_data->value != NULL) { + client2Server_NrOfDelete_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_replace) == 0) { + if (config_data->value != NULL) { + client2Server_NrOfReplace_str = strdup(config_data->value); + continue; + } + } + } + } + } + + if (lastSessionTime_str != NULL) + *last_session_time = atoi(lastSessionTime_str); + + if (server2Client_Total_str != NULL) + *server2client_total = atoi(server2Client_Total_str); + + if (server2Client_NrOfAdd_str != NULL) + *server2client_nrofadd = atoi(server2Client_NrOfAdd_str); + + if (server2Client_NrOfDelete_str != NULL) + *server2client_nrofdelete = atoi(server2Client_NrOfDelete_str); + + if (server2Client_NrOfReplace_str != NULL) + *server2client_nrofreplace = atoi(server2Client_NrOfReplace_str); + + if (client2Server_Total_str != NULL) + *client2server_total = atoi(client2Server_Total_str); + + if (client2Server_NrOfAdd_str != NULL) + *client2server_nrofadd = atoi(client2Server_NrOfAdd_str); + + if (client2Server_NrOfDelete_str != NULL) + *client2server_nrofdelete = atoi(client2Server_NrOfDelete_str); + + if (client2Server_NrOfReplace_str != NULL) + *client2server_nrofreplace = atoi(client2Server_NrOfReplace_str); + + error: + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + if (lastSessionTime_str != NULL) + free(lastSessionTime_str); + + if (server2Client_Total_str != NULL) + free(server2Client_Total_str); + + if (server2Client_NrOfAdd_str != NULL) + free(server2Client_NrOfAdd_str); + + if (server2Client_NrOfDelete_str != NULL) + free(server2Client_NrOfDelete_str); + + if (server2Client_NrOfReplace_str != NULL) + free(server2Client_NrOfReplace_str); + + if (client2Server_Total_str != NULL) + free(client2Server_Total_str); + + if (client2Server_NrOfAdd_str != NULL) + free(client2Server_NrOfAdd_str); + + if (client2Server_NrOfDelete_str != NULL) + free(client2Server_NrOfDelete_str); + + if (client2Server_NrOfReplace_str != NULL) + free(client2Server_NrOfReplace_str); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool get_all_profiles_data(GList ** list) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + + GList *account_info_list = NULL; + GList *account_iter = NULL; + sync_agent_fw_account_s *fw_account = NULL; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + sync_agent_ds_profile_info *profile_info = NULL; + GList *account_list = NULL; + GList *free_iter = NULL; + + sync_agent_ds_service_info *category_info = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_ACCESS_NAME; + query.access_name = "SE"; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (account_iter = account_info_list; account_iter != NULL; account_iter = g_list_next(account_iter)) { + fw_account = (sync_agent_fw_account_s *) account_iter->data; + + profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info)); + if (profile_info == NULL) { + _DEBUG_ERROR("profile_info is NULL"); + goto error; + } + + sync_agent_ds_server_info *server_info = &profile_info->server_info; + sync_agent_ds_sync_info *sync_info = &profile_info->sync_info; + + if (fw_account->email != NULL) + server_info->id = strdup(fw_account->email); + + if (fw_account->password != NULL) + server_info->password = strdup(fw_account->password); + + da_err = sync_agent_get_config_list(fw_account->account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME) == 0) { + if (config_data->value != NULL) { + profile_info->profile_dir_name = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) { + if (config_data->value != NULL) { + profile_info->profile_name = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) { + if (config_data->value != NULL) { + server_info->addr = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) { + if (config_data->value != NULL) { + sync_info->sync_mode = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) { + if (config_data->value != NULL) { + sync_info->sync_type = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) { + if (config_data->value != NULL) { + sync_info->interval = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) { + if (config_data->value != NULL) { + profile_info->last_sync_status = atoi(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) { + if (config_data->value != NULL) { + profile_info->last_sync_time = atoi(config_data->value); + continue; + } + } + } + } + } + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + + category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info)); + if (category_info == NULL) { + _DEBUG_ERROR("category_info is NULL"); + goto error; + } + + char *datastore = NULL; + + char datastore_source[128]; + char datastore_target[128]; + char datastore_id[128]; + char datastore_pw[128]; + + if (content_type == TYPE_CONTACT) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + category_info->service_type = SYNC_AGENT_CONTACT; + } else if (content_type == TYPE_CALENDAR) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + category_info->service_type = SYNC_AGENT_CALENDAR; + } else if (content_type == TYPE_MEMO) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + category_info->service_type = SYNC_AGENT_MEMO; + } else if (content_type == TYPE_CALLLOG) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + category_info->service_type = SYNC_AGENT_CALLLOG; + } + + snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, datastore) == 0) { + if (config_data->value != NULL) { + category_info->enabled = atoi(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_source) == 0) { + if (config_data->value != NULL) { + category_info->src_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_target) == 0) { + if (config_data->value != NULL) { + category_info->tgt_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_id) == 0) { + if (config_data->value != NULL) { + category_info->id = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_pw) == 0) { + if (config_data->value != NULL) { + category_info->password = strdup(config_data->value); + continue; + } + } + } + } + } + + profile_info->service_list = g_list_append(profile_info->service_list, category_info); + category_info = NULL; + } + + sync_agent_free_config_list(config_list); + config_list = NULL; + + account_list = g_list_append(account_list, profile_info); + profile_info = NULL; + } + + *list = account_list; + account_list = NULL; + + error: + + for (free_iter = account_list; free_iter != NULL; free_iter = g_list_next(free_iter)) { + sync_agent_ds_free_profile_info((ds_profile_h) free_iter->data); + _DEBUG_INFO("free sync_agent_ds_profile_info"); + } + + if (profile_info != NULL) + free(profile_info); + + sync_agent_free_fw_account_list(account_info_list); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} |