diff options
Diffstat (limited to 'src/agent/common')
-rwxr-xr-x | src/agent/common/common_define.c | 750 | ||||
-rwxr-xr-x | src/agent/common/common_util.c | 281 | ||||
-rwxr-xr-x | src/agent/common/common_vconf.c | 191 |
3 files changed, 1222 insertions, 0 deletions
diff --git a/src/agent/common/common_define.c b/src/agent/common/common_define.c new file mode 100755 index 0000000..3954bb4 --- /dev/null +++ b/src/agent/common/common_define.c @@ -0,0 +1,750 @@ +/* + * 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. + */ + +/** + * @Common_Define_Internal.c + * @version 0.1 + * @brief This file is the source file of implementation of defined Common structure + */ + +#include <sync_agent.h> + +#include "common/common_define.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +datastore_s *datastoreinfo_per_content_type[4]; + +datastore_info_s *create_datastore_info(char *target, char *source) +{ + _EXTERN_FUNC_ENTER; + + datastore_info_s *datastore_info = (datastore_info_s *) calloc(1, sizeof(datastore_info_s)); + retvm_if(datastore_info == NULL, NULL, "datastore_info is NULL"); + + if (target != NULL) + datastore_info->target = strdup(target); + if (source != NULL) + datastore_info->source = strdup(source); + + _EXTERN_FUNC_EXIT; + + return datastore_info; +} + +void free_datastore_infos(GList * datastore_infos) +{ + _EXTERN_FUNC_ENTER; + retm_if(datastore_infos == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = datastore_infos; iter != NULL; iter = g_list_next(iter)) + free_datastore_info(iter->data); + + g_list_free(datastore_infos); + + _EXTERN_FUNC_EXIT; +} + +void free_datastore_info(datastore_info_s * datastore_info) +{ + _EXTERN_FUNC_ENTER; + retm_if(datastore_info == NULL, "pDatastoreInfo is NULL"); + + if (datastore_info->target != NULL) { + free(datastore_info->target); + datastore_info->target = NULL; + } + + if (datastore_info->source != NULL) { + free(datastore_info->source); + datastore_info->source = NULL; + } + + if (datastore_info->last_anchor != NULL) { + free(datastore_info->last_anchor); + datastore_info->last_anchor = NULL; + } + + if (datastore_info->next_anchor != NULL) { + free(datastore_info->next_anchor); + datastore_info->next_anchor = NULL; + } + + free(datastore_info); + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_sync_type(datastore_info_s * datastore_info, alert_type_e sync_type) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) + datastore_info->sync_type = sync_type; + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_last_anchor(datastore_info_s * datastore_info, char *last_anchor) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) { + if (last_anchor != NULL) + datastore_info->last_anchor = strdup(last_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_next_anchor(datastore_info_s * datastore_info, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) { + if (next_anchor != NULL) + datastore_info->next_anchor = strdup(next_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_max_obj_size(datastore_info_s * datastore_info, unsigned int max_obj_size) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) + datastore_info->max_obj_size = max_obj_size; + + _EXTERN_FUNC_EXIT; +} + +changed_item_s *create_changed_item(change_type_e type, char *luid) +{ + _EXTERN_FUNC_ENTER; + + changed_item_s *changed_item = (changed_item_s *) calloc(1, sizeof(changed_item_s)); + retvm_if(changed_item == NULL, NULL, "changed_item is NULL"); + + changed_item->change_type = type; + + if (luid != NULL) + changed_item->luid = strdup(luid); + + changed_item->content_type = NULL; + + _EXTERN_FUNC_EXIT; + + return changed_item; +} + +void set_changed_item_content_type(changed_item_s * changed_item, char *content_type) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "pChangedItem is NULL"); + + if (content_type != NULL) + changed_item->content_type = strdup(content_type); + + _EXTERN_FUNC_EXIT; +} + +void free_changed_item(changed_item_s * changed_item) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "pChangedItem is NULL"); + + if (changed_item->luid != NULL) { + free(changed_item->luid); + changed_item->luid = NULL; + } + + if (changed_item->content_type != NULL) { + free(changed_item->content_type); + changed_item->content_type = NULL; + } + + if (changed_item->data != NULL) { + free(changed_item->data); + changed_item->data = NULL; + } + + if (changed_item != NULL) + free(changed_item); + + _EXTERN_FUNC_EXIT; +} + +void set_changed_item_data(changed_item_s * changed_item, char *data) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "pChangedItem is NULL"); + + if (data != NULL) + changed_item->data = strdup(data); + + _EXTERN_FUNC_EXIT; +} + +void set_changed_item_index_of_datastore(changed_item_s * changed_item, unsigned int index_of_datastore) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "changed_item is NULL"); + + changed_item->index_of_datastore = index_of_datastore; + + _EXTERN_FUNC_EXIT; +} + +changed_datastore_s *create_changed_datastore(char *source, char *target, int has_number_of_changes, unsigned int number_of_changes) +{ + _EXTERN_FUNC_ENTER; + + changed_datastore_s *changed_datastore = (changed_datastore_s *) calloc(1, sizeof(changed_datastore_s)); + retvm_if(changed_datastore == NULL, NULL, "changed_datastore is NULL"); + + if (source != NULL) + changed_datastore->source = strdup(source); + if (target != NULL) + changed_datastore->target = strdup(target); + + changed_datastore->need_sync_command = 1; + changed_datastore->number_of_changes = number_of_changes; + changed_datastore->has_number_of_changes = has_number_of_changes; + + _EXTERN_FUNC_EXIT; + + return changed_datastore; +} + +void free_changed_datastores(GList * changed_datastores) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_datastores == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = changed_datastores; iter != NULL; iter = g_list_next(iter)) + free_changed_datastore(iter->data); + + g_list_free(changed_datastores); + + _EXTERN_FUNC_EXIT; +} + +void free_changed_datastore(changed_datastore_s * changed_datastore) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_datastore == NULL, "pChangedDatastore is NULL"); + + if (changed_datastore->source != NULL) { + free(changed_datastore->source); + changed_datastore->source = NULL; + } + + if (changed_datastore->target != NULL) { + free(changed_datastore->target); + changed_datastore->target = NULL; + } + + GList *iter = NULL; + for (iter = changed_datastore->change_item; iter != NULL; iter = g_list_next(iter)) + free_changed_item(iter->data); + + g_list_free(changed_datastore->change_item); + changed_datastore->change_item = NULL; + + for (iter = changed_datastore->sent_item; iter != NULL; iter = g_list_next(iter)) + free_changed_item(iter->data); + + g_list_free(changed_datastore->sent_item); + changed_datastore->sent_item = NULL; + + if (changed_datastore != NULL) + free(changed_datastore); + + _EXTERN_FUNC_EXIT; +} + +void set_changed_datastore_changed_item(changed_datastore_s * changed_datastore, GList * changed_items) +{ + _EXTERN_FUNC_ENTER; + + if (changed_datastore != NULL) + changed_datastore->change_item = changed_items; + + _EXTERN_FUNC_EXIT; +} + +void add_changed_datastore_changed_item(changed_datastore_s * changed_datastore, changed_item_s * changed_item) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_datastore == NULL, "changed_datastore is NULL"); + + changed_datastore->change_item = g_list_append(changed_datastore->change_item, changed_item); + + _EXTERN_FUNC_EXIT; +} + +applied_status_s *create_applied_status(char *luid, change_type_e change_type, int status) +{ + _EXTERN_FUNC_ENTER; + + applied_status_s *applied_status = (applied_status_s *) calloc(1, sizeof(applied_status_s)); + retvm_if(applied_status == NULL, NULL, "appliedStatus is NULL"); + + if (luid != NULL) + applied_status->luid = strdup(luid); + + applied_status->change_type = change_type; + applied_status->status = status; + + _EXTERN_FUNC_EXIT; + + return applied_status; +} + +void free_applied_statuses(GList * applied_statuses) +{ + _EXTERN_FUNC_ENTER; + + retm_if(applied_statuses == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = applied_statuses; iter != NULL; iter = g_list_next(iter)) + free_applied_status(iter->data); + + g_list_free(applied_statuses); + + _EXTERN_FUNC_EXIT; +} + +void free_applied_status(applied_status_s * applied_status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(applied_status == NULL, "List is NULL"); + + if (applied_status->luid != NULL) { + free(applied_status->luid); + applied_status->luid = NULL; + } + + free(applied_status); + + _EXTERN_FUNC_EXIT; +} + +sending_status_s *create_sending_status(char *source, char *target) +{ + _EXTERN_FUNC_ENTER; + + sending_status_s *sending_status = (sending_status_s *) calloc(1, sizeof(sending_status_s)); + retvm_if(sending_status == NULL, NULL, "sending_status is NULL"); + + if (source != NULL) + sending_status->source = strdup(source); + + if (target != NULL) + sending_status->target = strdup(target); + + _EXTERN_FUNC_EXIT; + + return sending_status; +} + +void free_sending_statuses(GList * sending_statuses) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sending_statuses == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = sending_statuses; iter != NULL; iter = g_list_next(iter)) + free_sending_status(iter->data); + + g_list_free(sending_statuses); + + _EXTERN_FUNC_EXIT; +} + +void free_sending_status(sending_status_s * sending_status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sending_status == NULL, "pSendingStatus is NULL"); + + if (sending_status->source != NULL) { + free(sending_status->source); + sending_status->source = NULL; + } + + if (sending_status->target != NULL) { + free(sending_status->target); + sending_status->target = NULL; + } + + GList *iter = NULL; + for (iter = sending_status->items; iter != NULL; iter = g_list_next(iter)) + free_applied_status(iter->data); + + g_list_free(sending_status->items); + + free(sending_status); + + _EXTERN_FUNC_EXIT; +} + +void add_sending_status_applied_status(sending_status_s * sending_status, applied_status_s * applied_status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sending_status == NULL, "sending_status is NULL"); + + sending_status->items = g_list_append(sending_status->items, applied_status); + + _EXTERN_FUNC_EXIT; +} + +datastore_s *create_datastore(char *target, char *source) +{ + _EXTERN_FUNC_ENTER; + + datastore_s *datastore = (datastore_s *) calloc(1, sizeof(datastore_s)); + retvm_if(datastore == NULL, NULL, "datastore is NULL"); + + if (target != NULL) + datastore->target = strdup(target); + + if (source != NULL) + datastore->source = strdup(source); + + _EXTERN_FUNC_EXIT; + + return datastore; +} + +void set_datastore_content_type_info(datastore_s * datastore, int datastore_id, int folder_type_id) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + datastore->datastore_id = datastore_id; + datastore->folder_type_id = folder_type_id; + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_account_info(datastore_s * datastore, char *account_id, char *account_pw) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + if (account_id != NULL) + datastore->id = strdup(account_id); + if (account_pw != NULL) + datastore->pw = strdup(account_pw); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_client_sync_type(datastore_s * datastore, alert_type_e sync_type) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) + datastore->client_sync_type = sync_type; + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_server_sync_type(datastore_s * datastore, alert_type_e sync_type) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) + datastore->server_sync_type = sync_type; + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_client_anchor(datastore_s * datastore, char *last_anchor, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + if (last_anchor != NULL) + datastore->last_anchor_client = strdup(last_anchor); + if (next_anchor != NULL) + datastore->next_anchor_client = strdup(next_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_server_anchor(datastore_s * datastore, char *last_anchor, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + if (last_anchor != NULL) + datastore->last_anchor_server = strdup(last_anchor); + if (next_anchor != NULL) + datastore->next_anchor_server = strdup(next_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +sync_result_s *create_sync_result() +{ + _EXTERN_FUNC_ENTER; + + sync_result_s *syncResult = calloc(1, sizeof(sync_result_s)); + retvm_if(syncResult == NULL, NULL, "syncResult is NULL"); + + _EXTERN_FUNC_EXIT; + + return syncResult; +} + +sync_result_s *dup_sync_result(sync_result_s * org_sync_result) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(org_sync_result == NULL, NULL, "orgSyncResult is NULL"); + + sync_result_s *syn_cre_sult = calloc(1, sizeof(sync_result_s)); + retvm_if(syn_cre_sult == NULL, NULL, "syn_cre_sult is NULL"); + + syn_cre_sult->session_result = org_sync_result->session_result; + syn_cre_sult->number_of_change = org_sync_result->number_of_change; + syn_cre_sult->received_count = org_sync_result->received_count; + syn_cre_sult->add_count = org_sync_result->add_count; + syn_cre_sult->replace_count = org_sync_result->replace_count; + syn_cre_sult->delete_count = org_sync_result->delete_count; + + _EXTERN_FUNC_EXIT; + + return syn_cre_sult; + +} + +void set_number_of_change(sync_result_s * sync_result, unsigned int number_of_change) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->number_of_change = number_of_change; + + _EXTERN_FUNC_EXIT; +} + +void add_add_count(sync_result_s * sync_result, unsigned int add_cnt) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->add_count += add_cnt; + + _EXTERN_FUNC_EXIT; +} + +void add_receive_count(sync_result_s * sync_result, unsigned int received_count) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->received_count += received_count; + + _EXTERN_FUNC_EXIT; +} + +void add_replace_count(sync_result_s * sync_result, unsigned int replace_cnt) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->replace_count += replace_cnt; + + _EXTERN_FUNC_EXIT; +} + +void add_delete_count(sync_result_s * sync_result, unsigned int delete_cnt) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->delete_count += delete_cnt; + + _EXTERN_FUNC_EXIT; +} + +void free_pre_sync_return_obj(pre_sync_return_obj_s * pre_sync_return_obj) +{ + _EXTERN_FUNC_ENTER; + + retm_if(pre_sync_return_obj == NULL, "pre_sync_return_obj is NULL"); + + GList *iter = NULL; + for (iter = pre_sync_return_obj->datastore_info; iter != NULL; iter = g_list_next(iter)) + free_datastore_info(iter->data); + g_list_free(pre_sync_return_obj->datastore_info); + pre_sync_return_obj->datastore_info = NULL; + + if (pre_sync_return_obj->dev_id != NULL) { + free(pre_sync_return_obj->dev_id); + pre_sync_return_obj->dev_id = NULL; + } + + free(pre_sync_return_obj); + pre_sync_return_obj = NULL; + + _EXTERN_FUNC_EXIT; +} + +void free_sync_obj(sync_obj_s * sync_obj) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sync_obj == NULL, "sync_obj is NULL"); + + GList *iter = NULL; + for (iter = sync_obj->changed_datastore; iter != NULL; iter = g_list_next(iter)) + free_changed_datastore(iter->data); + g_list_free(sync_obj->changed_datastore); + sync_obj->changed_datastore = NULL; + + for (iter = sync_obj->sending_status; iter != NULL; iter = g_list_next(iter)) + free_sending_status(iter->data); + g_list_free(sync_obj->sending_status); + sync_obj->sending_status = NULL; + + free(sync_obj); + sync_obj = NULL; + + _EXTERN_FUNC_EXIT; +} + +void free_sync_return_obj(sync_return_obj_s * sync_return_obj) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sync_return_obj == NULL, "pSyncReturnObj is NULL"); + + GList *iter = NULL; + for (iter = sync_return_obj->changed_datastore; iter != NULL; iter = g_list_next(iter)) + free_changed_datastore(iter->data); + g_list_free(sync_return_obj->changed_datastore); + sync_return_obj->changed_datastore = NULL; + + for (iter = sync_return_obj->status; iter != NULL; iter = g_list_next(iter)) + free_applied_status(iter->data); + g_list_free(sync_return_obj->status); + sync_return_obj->status = NULL; + + free(sync_return_obj); + sync_return_obj = NULL; + + _EXTERN_FUNC_EXIT; +} + +void free_datastore(datastore_s * datastore) +{ + _EXTERN_FUNC_ENTER; + + retm_if(datastore == NULL, "pDatastore is NULL"); + + if (datastore->target != NULL) { + free(datastore->target); + datastore->target = NULL; + } + + if (datastore->source != NULL) { + free(datastore->source); + datastore->source = NULL; + } + + if (datastore->id != NULL) { + free(datastore->id); + datastore->id = NULL; + } + + if (datastore->pw != NULL) { + free(datastore->pw); + datastore->pw = NULL; + } + + if (datastore->last_anchor_client != NULL) { + free(datastore->last_anchor_client); + datastore->last_anchor_client = NULL; + } + + if (datastore->next_anchor_client != NULL) { + free(datastore->next_anchor_client); + datastore->next_anchor_client = NULL; + } + + if (datastore->last_anchor_server != NULL) { + free(datastore->last_anchor_server); + datastore->last_anchor_server = NULL; + } + + if (datastore->next_anchor_server != NULL) { + free(datastore->next_anchor_server); + datastore->next_anchor_server = NULL; + } + + if (datastore->client_sync_result != NULL) + free(datastore->client_sync_result); + + if (datastore->server_sync_result != NULL) + free(datastore->server_sync_result); + + free(datastore); + + _EXTERN_FUNC_EXIT; +} + +void free_sync_service(sync_service_s * category) +{ + _EXTERN_FUNC_ENTER; + + retm_if(category == NULL, "category is NULL"); + + if (category->src_uri != NULL) + free(category->src_uri); + + if (category->tgt_uri != NULL) + free(category->tgt_uri); + + if (category->id != NULL) + free(category->id); + + if (category->password != NULL) + free(category->password); + + _EXTERN_FUNC_EXIT; +} diff --git a/src/agent/common/common_util.c b/src/agent/common/common_util.c new file mode 100755 index 0000000..7c1bb70 --- /dev/null +++ b/src/agent/common/common_util.c @@ -0,0 +1,281 @@ +/* + * 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. + */ + +/** + * @Common_Util.c + * @version 0.1 + * @brief This file is the source file of implementation of utility function + */ + +#include <sync_agent.h> + +#include "common/common_util.h" +#include "common/common_define_internal.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +#define MAX_RETRY_COUNT 10 + +bool create_config_str(int account_id, char *key, char *value, char *type, char *access_name, sync_agent_da_config_s ** config) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + da_err = sync_agent_create_config(config); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_config is failed"); + goto error; + } + + (*config)->config_id = account_id; + (*config)->key = strdup(key); + (*config)->value = value != NULL ? strcmp(value, "") == 0 ? NULL : strdup(value) : NULL; + (*config)->type = strdup(type); + (*config)->access_name = strdup(access_name); + + error: + + _EXTERN_FUNC_EXIT; + + if (da_err == SYNC_AGENT_DA_SUCCESS) + return true; + else + return false; + +} + +bool set_config_str(int accountID, char *key, char *value, char *type, char *access_name) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e result; + sync_agent_da_config_s config; + + config.config_id = accountID; + config.key = key; + config.value = value != NULL ? strcmp(value, "") == 0 ? NULL : value : NULL; + config.type = type; + config.access_name = access_name; + + result = sync_agent_update_config(&config); + + _EXTERN_FUNC_EXIT; + + if (result == SYNC_AGENT_DA_SUCCESS) + return true; + else + return false; +} + +bool set_config_int(int accountID, char *key, int value, char *type, char *access_name) +{ + _EXTERN_FUNC_ENTER; + + char *value_str = NULL; + value_str = g_strdup_printf("%u", value); + + sync_agent_da_return_e result; + sync_agent_da_config_s config; + + config.config_id = accountID; + config.key = key; + config.value = value_str; + config.type = type; + config.access_name = access_name; + + result = sync_agent_update_config(&config); + + if (value_str != NULL) + free(value_str); + + _EXTERN_FUNC_EXIT; + + if (result == SYNC_AGENT_DA_SUCCESS) + return true; + else + return false; +} + +bool get_config(int account_id, char *key, char **value) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS; + sync_agent_da_config_s *config = NULL; + + *value = NULL; + + result = sync_agent_create_config(&config); + if (result != SYNC_AGENT_DA_SUCCESS) + return false; + + result = sync_agent_get_config(account_id, key, &config); + if (result == SYNC_AGENT_DA_SUCCESS) { + if (config != NULL) { + if (config->value != NULL) { + *value = strdup(config->value); + _DEBUG_INFO("value = %s", *value); + } + } + } else { + /* FIXME temporary solution + * Try MAX_RETRY_COUNT when fail to get_config + * */ + int i; + bool success = false; + for (i = 0; i < MAX_RETRY_COUNT; i++) { + result = sync_agent_get_config(account_id, key, &config); + if (result == SYNC_AGENT_DA_SUCCESS) { + if (config != NULL) { + if (config->value != NULL) { + *value = strdup(config->value); + _DEBUG_INFO("value = %s", *value); + success = true; + break; + } + } + } + } + if (success == false) { + sync_agent_free_config(config); + _EXTERN_FUNC_EXIT; + return false; + } + } + + sync_agent_free_config(config); + _EXTERN_FUNC_EXIT; + return true; +} + +int get_account_id(char *profile, bool open) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(profile == NULL, -1, "profile is NULL"); + + int accountId = -1; + char *profileDirName = NULL; + bool result; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + if (open == false) { + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + goto error; + } + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + 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 (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + + if (profileDirName != NULL) + free(profileDirName); + + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + goto error; + } + + _DEBUG_INFO("profileDirName = %s", profileDirName); + if (profileDirName == NULL) + continue; + + if (strcmp(profile, profileDirName) == 0) { + _DEBUG_INFO("account_list[i] = %d", fw_account->account_id); + accountId = fw_account->account_id; + break; + } + } + + _EXTERN_FUNC_EXIT; + + error: + + sync_agent_free_fw_account_list(account_info_list); + + if (profileDirName != NULL) + free(profileDirName); + + if (open == false) + sync_agent_close_agent(); + + return accountId; +} + +/*int convert_synctype_value(char *syncType_str) +{ + int syncType_value; + + if (strcmp(syncType_str, DEFINE_ALERT_SLOW_SYNC_STR) ==0) + syncType_value = ALERT_SLOW_SYNC ; + else if (strcmp(syncType_str, DEFINE_ALERT_TWO_WAY_STR) ==0) + syncType_value = ALERT_TWO_WAY ; + else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) ==0) + syncType_value = ALERT_ONE_WAY_FROM_CLIENT; + else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) ==0) + syncType_value = ALERT_ONE_WAY_FROM_SERVER; + else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) ==0) + syncType_value = ALERT_REFRESH_FROM_SERVER; + else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) ==0) + syncType_value = ALERT_REFRESH_FROM_CLIENT; + else + syncType_value = ALERT_UNKNOWN; + + return syncType_value; +}*/ + +/*char *convert_synctype_str(char *syncType_value) +{ + char *syncType_str = NULL; + + if (strcmp(syncType_value, DEFINE_ALERT_SLOW_SYNC_VALUE) ==0) + syncType_str = DEFINE_ALERT_SLOW_SYNC_STR; + else if (strcmp(syncType_value, DEFINE_ALERT_TWO_WAY_VALUE) ==0) + syncType_str = DEFINE_ALERT_TWO_WAY_STR; + else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0) + syncType_str = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR; + else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0) + syncType_str = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR; + else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_SERVER_VALUE) ==0) + syncType_str = DEFINE_ALERT_REFRESH_FROM_SERVER_STR; + else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_CLIENT_VALUE) ==0) + syncType_str = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR; + else + syncType_str = DEFINE_ALERT_SLOW_SYNC_STR; + + return syncType_str; +}*/ diff --git a/src/agent/common/common_vconf.c b/src/agent/common/common_vconf.c new file mode 100755 index 0000000..e874d37 --- /dev/null +++ b/src/agent/common/common_vconf.c @@ -0,0 +1,191 @@ +/* + * 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. + */ + +/** + * @Common_Util.c + * @version 0.1 + * @brief This file is the source file of implementation of wrapping vconf function + */ + +#include <vconf.h> +#include <stdio.h> +#include <stdlib.h> +#include <glib.h> +#include <string.h> + +#include <sync_agent.h> + +#include "common/common_vconf.h" + +char *get_vconf_str(char *base_key, char *key) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + char *value = NULL; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + value = vconf_get_str(path); + + if (value != NULL) { + if (strcmp(value, "") == 0) { + + if (value != NULL) + free(value); + + _EXTERN_FUNC_EXIT; + return NULL; + } else { + _EXTERN_FUNC_EXIT; + return value; + } + } else { + _EXTERN_FUNC_EXIT; + return NULL; + } + +} + +char *get_vconf_str_key(char *key) +{ + _EXTERN_FUNC_ENTER; + + char *value = NULL; + value = vconf_get_str(key); + + if (value != NULL) { + if (strcmp(value, "") == 0) { + + if (value != NULL) + free(value); + + _EXTERN_FUNC_EXIT; + return NULL; + } else { + _EXTERN_FUNC_EXIT; + return value; + } + } else { + _EXTERN_FUNC_EXIT; + return NULL; + } +} + +bool get_vconf_int(char *base_key, char *key, int *value) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + int temp = 0; + int result; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + result = vconf_get_int(path, &temp); + + _EXTERN_FUNC_EXIT; + + if (result == 0) { + *value = temp; + return true; + } else + return false; +} + +bool get_vconf_int_key(char *key, int *value) +{ + _EXTERN_FUNC_ENTER; + + int temp = 0; + int result; + + result = vconf_get_int(key, &temp); + + _EXTERN_FUNC_EXIT; + + if (result == 0) { + *value = temp; + return true; + } else + return false; +} + +bool set_vconf_str(char *base_key, char *key, char *value) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + int result; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + result = vconf_set_str(path, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} + +bool set_vconf_str_key(char *key, char *value) +{ + _EXTERN_FUNC_ENTER; + + int result; + result = vconf_set_str(key, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} + +bool set_vconf_int(char *base_key, char *key, int value) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + int result; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + result = vconf_set_int(path, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} + +bool set_vconf_int_key(char *key, int value) +{ + _EXTERN_FUNC_ENTER; + + int result; + + result = vconf_set_int(key, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} |