diff options
Diffstat (limited to 'src/agent/framework/event/oma_ds_event_handler.c')
-rwxr-xr-x | src/agent/framework/event/oma_ds_event_handler.c | 908 |
1 files changed, 908 insertions, 0 deletions
diff --git a/src/agent/framework/event/oma_ds_event_handler.c b/src/agent/framework/event/oma_ds_event_handler.c new file mode 100755 index 0000000..01d5102 --- /dev/null +++ b/src/agent/framework/event/oma_ds_event_handler.c @@ -0,0 +1,908 @@ +/* + * 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. + */ + +/** + * @OMA_DS_Event_Handler.c + * @version 0.1 + * @brief This file is the source file of implementation of event callback function(from ui) + */ + +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#include <sync_agent.h> + +#include "framework/event/oma_ds_event_handler.h" +#include "framework/event/oma_ds_platform_event_handler.h" +#include "framework/task/oma_ds_engine_controller_task.h" +#include "common/common_define.h" +#include "common/common_vconf.h" +#include "common/common_util.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +#define NOTI_KEY "OMADS" + +static void _request_manual_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data); + +static void _request_manual_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data) +{ + _INNER_FUNC_ENTER; + + unsigned int request_msg_id_to_cancel = 0; + get_manual_sync_request_id(&request_msg_id_to_cancel); + + _INNER_FUNC_EXIT; +} + +int event_callback_add_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile_dir_name = NULL; + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + char *interval = NULL; + int category_count; + int result = 0; + int account_id; + + GList *categorys = NULL; + GList *iter = NULL; + + sync_agent_get_event_data_param(request, &profile_dir_name); + sync_agent_get_event_data_param(request, &profile_name); + sync_agent_get_event_data_param(request, &addr); + sync_agent_get_event_data_param(request, &id); + sync_agent_get_event_data_param(request, &password); + sync_agent_get_event_data_param(request, &sync_mode); + sync_agent_get_event_data_param(request, &sync_type); + sync_agent_get_event_data_param(request, &interval); + sync_agent_get_event_data_param(request, &category_count); + + /* + _DEBUG_INFO("request param : %s", profile_dir_name); + _DEBUG_INFO("request param : %s", profile_name); + _DEBUG_INFO("request param : %s", addr); + _DEBUG_INFO("request param : %s", id); + _DEBUG_INFO("request param : %s", password); + _DEBUG_INFO("request param : %s", sync_mode); + _DEBUG_INFO("request param : %s", sync_type); + _DEBUG_INFO("request param : %s", interval); + _DEBUG_INFO("request param : %d", category_count); + */ + + int i = 0; + for (; i < category_count; i++) { + sync_service_s *category = (sync_service_s *) calloc(1, sizeof(sync_service_s)); + if (category == NULL) { + _DEBUG_ERROR("category is NULL !"); + + if (profile_dir_name != NULL) + free(profile_dir_name); + + if (profile_name != NULL) + free(profile_name); + + if (addr != NULL) + free(addr); + + if (id != NULL) + free(id); + + if (password != NULL) + free(password); + + if (sync_mode != NULL) + free(sync_mode); + + if (sync_type != NULL) + free(sync_type); + + if (interval != NULL) + free(interval); + + return 0; + } + + sync_agent_get_event_data_param(request, &(category->service_type)); + sync_agent_get_event_data_param(request, &(category->enabled)); + sync_agent_get_event_data_param(request, &(category->src_uri)); + sync_agent_get_event_data_param(request, &(category->tgt_uri)); + sync_agent_get_event_data_param(request, &(category->id)); + sync_agent_get_event_data_param(request, &(category->password)); + + categorys = g_list_append(categorys, category); + + /* + _DEBUG_INFO("category[i]->content_type : %d", category->content_type); + _DEBUG_INFO("category[i]->enabled : %d", category->enabled); + _DEBUG_INFO("category[i]->srcURI : %s", category->src_uri); + _DEBUG_INFO("category[i]->tgtURI : %s", category->tgt_uri); + _DEBUG_INFO("category[i]->id : %s", category->id); + _DEBUG_INFO("category[i]->password : %s", category->password); + */ + } + + /* send to engine controller */ + void *in_param_value_array[9] = { &profile_dir_name, &profile_name, &addr, &id, &password, &sync_mode, &sync_type, &interval, &categorys }; + int in_param_index_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + sync_agent_ec_value_type_e in_param_value_type_array[9] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT + }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE, 0, 9, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &account_id); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &account_id); + + for (iter = categorys; iter != NULL; iter = g_list_next(iter)) { + sync_service_s *category = (sync_service_s *) iter->data; + + if (category != NULL) + free_sync_service(category); + } + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_edit_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile_dir_name = NULL; + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + char *interval = NULL; + int category_count; + int result = 0; + + GList *categorys = NULL; + GList *iter = NULL; + + sync_agent_get_event_data_param(request, &profile_dir_name); + if (profile_dir_name == NULL) { + _DEBUG_ERROR("profile_dir_name is not defined"); + result = 0; + goto error; + } + _DEBUG_INFO("request param : %s", profile_dir_name); + + int account_id = get_account_id(profile_dir_name, false); + + sync_agent_get_event_data_param(request, &profile_name); + sync_agent_get_event_data_param(request, &addr); + sync_agent_get_event_data_param(request, &id); + sync_agent_get_event_data_param(request, &password); + sync_agent_get_event_data_param(request, &sync_mode); + sync_agent_get_event_data_param(request, &sync_type); + sync_agent_get_event_data_param(request, &interval); + sync_agent_get_event_data_param(request, &category_count); + + _DEBUG_INFO("request param : %s", profile_name); + _DEBUG_INFO("request param : %s", addr); + _DEBUG_INFO("request param : %s", id); + _DEBUG_INFO("request param : %s", password); + _DEBUG_INFO("request param : %s", sync_mode); + _DEBUG_INFO("request param : %s", sync_type); + _DEBUG_INFO("request param : %s", interval); + _DEBUG_INFO("request param : %d", category_count); + + int i = 0; + for (; i < category_count; i++) { + sync_service_s *category = (sync_service_s *) calloc(1, sizeof(sync_service_s)); + if (category == NULL) { + _DEBUG_ERROR("category is NULL !"); + + if (profile_dir_name != NULL) + free(profile_dir_name); + + if (profile_name != NULL) + free(profile_name); + + if (addr != NULL) + free(addr); + + if (id != NULL) + free(id); + + if (password != NULL) + free(password); + + if (sync_mode != NULL) + free(sync_mode); + + if (sync_type != NULL) + free(sync_type); + + if (interval != NULL) + free(interval); + + return 0; + } + + sync_agent_get_event_data_param(request, &(category->service_type)); + sync_agent_get_event_data_param(request, &(category->enabled)); + sync_agent_get_event_data_param(request, &(category->src_uri)); + sync_agent_get_event_data_param(request, &(category->tgt_uri)); + sync_agent_get_event_data_param(request, &(category->id)); + sync_agent_get_event_data_param(request, &(category->password)); + + categorys = g_list_append(categorys, category); + + _DEBUG_INFO("category[i]->content_type : %d", category->service_type); + _DEBUG_INFO("category[i]->enabled : %d", category->enabled); + _DEBUG_INFO("category[i]->srcURI : %s", category->src_uri); + _DEBUG_INFO("category[i]->tgtURI : %s", category->tgt_uri); + _DEBUG_INFO("category[i]->id : %s", category->id); + _DEBUG_INFO("category[i]->password : %s", category->password); + } + + /* send to engine controller */ + void *in_param_value_array[9] = { &account_id, &profile_name, &addr, &id, &password, &sync_mode, &sync_type, &interval, &categorys }; + int in_param_index_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + sync_agent_ec_value_type_e in_param_value_type_array[9] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT + }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE, 0, 9, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + for (iter = categorys; iter != NULL; iter = g_list_next(iter)) { + sync_service_s *category = (sync_service_s *) iter->data; + + if (category != NULL) + free_sync_service(category); + } + + if (profile_dir_name != NULL) + free(profile_dir_name); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_delete_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result = 0; + int count; + sync_agent_get_event_data_param(request, &count); + GList *profiles = NULL; + int *account_id = 0; + + int i; + char *profile = NULL; + for (i = 0; i < count; i++) { + if (profile != NULL) { + free(profile); + profile = NULL; + } + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + _DEBUG_INFO("request param : %s", profile); + + account_id = (int *)calloc(1, sizeof(int)); + if (account_id == NULL) { + _DEBUG_ERROR("account_id is NULL"); + result = 0; + goto error; + } + + *account_id = get_account_id(profile, false); + + profiles = g_list_append(profiles, account_id); + } + + /* send to engine controller */ + void *in_param_value_array[1] = { &profiles }; + int in_param_index_array[1] = { 0 }; + sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE, 0, 1, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_sync_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *profile = NULL; + int result = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + _DEBUG_INFO("request param : %s", profile); + + int account_id = get_account_id(profile, false); + char *sync_mode = strdup(DEFINE_SYNC_MODE_MANUAL); + + void *in_param_value_array[3] = { &account_id, &sync_mode, NULL }; + int in_param_index_array[3] = { 0, 1, 2 }; + sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT }; + unsigned int request_msg_id = 0; + sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0, 3, in_param_index_array, in_param_value_type_array, in_param_value_array, _request_manual_sync_task_finish_callback, NULL, (int *)&request_msg_id); + + insert_request_msg_info(SYNC_MODE_MANUAL, request_msg_id); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_cancel_sync_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *profile = NULL; + int result = 0; + bool res; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + _DEBUG_INFO("request param : %s", profile); + + res = cancel_current_sync_task(); + if (res == true) + result = 1; + else + result = 0; + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_get_profile_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result = 0; + char *profile = NULL; + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + char *interval = NULL; + int last_session_status = 0; + int last_session_time = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + _DEBUG_INFO("request param : %s", profile); + + int account_id = get_account_id(profile, false); + + int in_param_index_array[1] = { 0 }; + void *in_param_value_array[1] = { &account_id }; + sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_INT }; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_DATA, 0, 1, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profile_name); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &sync_mode); + sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &sync_type); + sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval); + sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_status); + sync_agent_get_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_time); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_name); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)addr); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)password); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_mode); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)interval); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_status); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_time); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_get_profile_sync_category_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *profile = NULL; + int content_type = 0; + int enabled = 0; + char *srcURI = NULL; + char *tgtURI = NULL; + char *id = NULL; + char *password = NULL; + int result = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + sync_agent_get_event_data_param(request, &content_type); + + _DEBUG_INFO("request param : %s", profile); + _DEBUG_INFO("request param : %d", content_type); + + int account_id = get_account_id(profile, false); + _DEBUG_INFO(" account_id: %d", account_id); + + int in_param_index_array[2] = { 0, 1 }; + void *in_param_value_array[2] = { &account_id, &content_type }; + sync_agent_ec_value_type_e in_param_value_type_array[2] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_INT }; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, 0, 2, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &enabled); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &srcURI); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &tgtURI); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + + /* + _DEBUG_INFO("result = %d", result); + _DEBUG_INFO("enabled = %d", enabled); + _DEBUG_INFO("srcURI = %s", srcURI); + _DEBUG_INFO("tgtURI = %s", tgtURI); + _DEBUG_INFO("id = %s", id); + _DEBUG_INFO("password = %s", password); + */ + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &enabled); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)srcURI); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)tgtURI); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)password); + + error: + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_get_profile_last_statistics_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile = NULL; + int content_type = 0; + char *dbSynced = "NO"; + int last_session_time = -1; + int server2Client_Total = 0; + int server2Client_NrOfAdd = 0; + int server2Client_NrOfDelete = 0; + int server2Client_NrOfReplace = 0; + int client2Server_Total = 0; + int client2Server_NrOfAdd = 0; + int client2Server_NrOrDelete = 0; + int client2Server_NrOfReplace = 0; + int result = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + sync_agent_get_event_data_param(request, &content_type); + + _DEBUG_INFO("request param : %s", profile); + _DEBUG_INFO("request param : %d", content_type); + + int account_id = get_account_id(profile, false); + + int in_param_index_array[2] = { 0, 1 }; + void *in_param_value_array[2] = { &account_id, &content_type }; + sync_agent_ec_value_type_e in_param_value_type_array[2] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_INT }; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS, 0, 2, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &dbSynced); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_time); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_Total); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfAdd); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfDelete); + sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfReplace); + sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_Total); + sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfAdd); + sync_agent_get_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOrDelete); + sync_agent_get_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfReplace); + + /* + _DEBUG_INFO("result = %d", result); + _DEBUG_INFO("dbSynced = %s\n", dbSynced); + _DEBUG_INFO("last_session_time = %d\n", last_session_time); + _DEBUG_INFO("server2Client_Total = %d\n", server2Client_Total); + _DEBUG_INFO("server2Client_NrOfAdd = %d\n", server2Client_NrOfAdd); + _DEBUG_INFO("server2Client_NrOfDelete = %d\n", server2Client_NrOfDelete); + _DEBUG_INFO("server2Client_NrOfReplace = %d\n", server2Client_NrOfReplace); + _DEBUG_INFO("client2Server_Total = %d\n", client2Server_Total); + _DEBUG_INFO("client2Server_NrOfAdd = %d\n", client2Server_NrOfAdd); + _DEBUG_INFO("client2Server_NrOrDelete = %d\n", client2Server_NrOrDelete); + _DEBUG_INFO("client2Server_NrOfReplace = %d\n", client2Server_NrOfReplace); + */ + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)dbSynced); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_time); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_Total); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfAdd); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfDelete); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfReplace); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_Total); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOfAdd); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOrDelete); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOfReplace); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_add_profile_cp_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + int category_count; + int result = 0; + int account_id; + + sync_agent_get_event_data_param(request, &profile_name); + sync_agent_get_event_data_param(request, &addr); + sync_agent_get_event_data_param(request, &id); + sync_agent_get_event_data_param(request, &password); + sync_agent_get_event_data_param(request, &category_count); + + /* + _DEBUG_INFO("request param : %s", profile_name); + _DEBUG_INFO("request param : %s", addr); + _DEBUG_INFO("request param : %s", id); + _DEBUG_INFO("request param : %s", password); + _DEBUG_INFO("request param : %d", category_count); + */ + + GList *categorys = NULL; + int i = 0; + for (; i < category_count; i++) { + resource_cp_s *category = (resource_cp_s *) calloc(1, sizeof(resource_cp_s)); + if (category == NULL) { + _DEBUG_ERROR("category is NULL !"); + + if (profile_name != NULL) + free(profile_name); + + if (addr != NULL) + free(addr); + + if (id != NULL) + free(id); + + if (password != NULL) + free(password); + + return 0; + } + + sync_agent_get_event_data_param(request, &(category->name)); + sync_agent_get_event_data_param(request, &(category->accept)); + sync_agent_get_event_data_param(request, &(category->id)); + sync_agent_get_event_data_param(request, &(category->password)); + sync_agent_get_event_data_param(request, &(category->auth_type)); + sync_agent_get_event_data_param(request, &(category->auth_data)); + + categorys = g_list_append(categorys, category); + + /* + _DEBUG_INFO("category[%d]->name : %s", i, category->name); + _DEBUG_INFO("category[%d]->accept : %s", i, category->accept); + _DEBUG_INFO("category[%d]->id : %s", i, category->id); + _DEBUG_INFO("category[%d]->password : %s", i, category->password); + _DEBUG_INFO("category[%d]->authType : %s", i, category->auth_type); + _DEBUG_INFO("category[%d]->authData : %s\n", i, category->auth_data); + */ + } + + /* send to engine controller */ + void *in_param_value_array[5] = { &profile_name, &addr, &id, &password, &categorys }; + int in_param_index_array[5] = { 0, 1, 2, 3, 4 }; + sync_agent_ec_value_type_e in_param_value_type_array[5] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT + }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP, 0, 5, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &account_id); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &account_id); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_calllog_sync_async(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *data = NULL; + int result = 0; + + sync_agent_get_event_data_param(request, &data); + if (data == NULL) { + _DEBUG_ERROR("data is NULL"); + result = 0; + goto error; + } + _DEBUG_INFO("data = %s", data); + + result = send_ip_push_sync_msg(data); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_reset_all_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result; + + /* 1. cancel current sync session */ + cancel_current_sync_task(); + + /* 2. reset all data */ + unsigned int request_msg_id = 0; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + + unsigned int out_param_count; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_RESET_ALL_DATA, 0, 0, NULL, NULL, NULL, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + _DEBUG_INFO("result = %d", result); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_get_all_profiles_data(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result = 0; + GList *profiles_data = NULL; + GList *profile_iter = NULL; + GList *category_iter = NULL; + + int profile_count = 0; + int category_count = 0; + sync_agent_ds_profile_info *profile_info = NULL; + sync_agent_ds_service_info *category_info = NULL; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_ALL_PROFILES_DATA, 0, 0, NULL, NULL, NULL, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles_data); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + _DEBUG_INFO("result = %d", result); + + if (profiles_data != NULL) { + profile_count = g_list_length(profiles_data); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_count); + _DEBUG_INFO("profile_count = %d", profile_count); + + for (profile_iter = profiles_data; profile_iter != NULL; profile_iter = g_list_next(profile_iter)) { + profile_info = (sync_agent_ds_profile_info *) profile_iter->data; + + sync_agent_ds_server_info *server_info = &profile_info->server_info; + sync_agent_ds_sync_info *sync_info = &profile_info->sync_info; + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_info->last_sync_status); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_info->last_sync_time); + + _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name); + _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name); + + _DEBUG_INFO("server_info->addr = %s", server_info->addr); + _DEBUG_INFO("server_info->id = %s", server_info->id); + _DEBUG_INFO("server_info->password = %s", server_info->password); + + _DEBUG_INFO("sync_info->sync_mode = %s", sync_info->sync_mode); + _DEBUG_INFO("sync_info->sync_type = %s", sync_info->sync_type); + _DEBUG_INFO("sync_info->interval = %s", sync_info->interval); + + _DEBUG_INFO("profile_info->last_sync_status = %d", profile_info->last_sync_status); + _DEBUG_INFO("profile_info->last_sync_time = %d", profile_info->last_sync_time); + + category_count = g_list_length(profile_info->service_list); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count); + + _DEBUG_INFO("category_count = %d", category_count); + + for (category_iter = profile_info->service_list; category_iter != NULL; category_iter = g_list_next(category_iter)) { + category_info = (sync_agent_ds_service_info *) category_iter->data; + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_info->service_type); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_info->enabled); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password); + + _DEBUG_INFO("category_info->service_type = %d", category_info->service_type); + _DEBUG_INFO("category_info->enabled = %d", category_info->enabled); + _DEBUG_INFO("category_info->src_uri = %s", category_info->src_uri); + _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri); + _DEBUG_INFO("category_info->id = %s", category_info->id); + _DEBUG_INFO("category_info->password = %s", category_info->password); + } + } + } + + _EXTERN_FUNC_EXIT; + return 0; +} |