summaryrefslogtreecommitdiff
path: root/src/agent/framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/framework')
-rwxr-xr-xsrc/agent/framework/event/oma_ds_event_handler.c908
-rwxr-xr-xsrc/agent/framework/event/oma_ds_platform_event_handler.c355
-rwxr-xr-xsrc/agent/framework/san-parser/pm_sanparser.c633
-rwxr-xr-xsrc/agent/framework/task/oma_ds_engine_controller_task.c1137
4 files changed, 3033 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, &param_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, &param_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, &param_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, &param_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, &param_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, &param_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, &param_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, &param_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, &param_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;
+}
diff --git a/src/agent/framework/event/oma_ds_platform_event_handler.c b/src/agent/framework/event/oma_ds_platform_event_handler.c
new file mode 100755
index 0000000..ddc3547
--- /dev/null
+++ b/src/agent/framework/event/oma_ds_platform_event_handler.c
@@ -0,0 +1,355 @@
+/*
+ * 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_Platform_Event_Handler.c
+ * @version 0.1
+ * @brief This file is the source file of implementation of event callback function(from platform)
+ */
+
+#include <sync_agent.h>
+#include <plugin/plugin_slp_sysnoti_wap_push.h>
+
+#include "framework/event/oma_ds_platform_event_handler.h"
+#include "framework/task/oma_ds_engine_controller_task.h"
+#include "framework/san-parser/pm_sanparser.h"
+#include "common/common_define_internal.h"
+#include "common/common_util.h"
+
+#ifndef OMADS_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DS_COMMON"
+#endif
+
+static void _request_periodic_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_san_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_periodic_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_periodic_sync_request_id(&request_msg_id_to_cancel);
+
+ _INNER_FUNC_EXIT;
+
+}
+
+static void _request_san_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_san_sync_request_id(&request_msg_id_to_cancel);
+
+ _INNER_FUNC_EXIT;
+}
+
+int san_callback_parse(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+ san_package_s *pSanPackage = NULL;
+ int accountID = -1;
+ char *sync_mode = NULL;
+ char *server_id = 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;
+
+ pmci_san_incoming_s *incoming_data = (pmci_san_incoming_s *) user_data;
+
+ switch (incoming_data->version) {
+ case 11:
+ {
+ pSanPackage = san_package_11_parser(incoming_data->msg_body, incoming_data->msg_size);
+ }
+ break;
+ case 12:
+ {
+ pSanPackage = san_package_12_parser(incoming_data->msg_body, incoming_data->msg_size);
+ }
+ break;
+ default:
+ break;
+ }
+
+ sync_agent_da_return_e da_err = sync_agent_open_agent();
+ if (da_err != SYNC_AGENT_DA_SUCCESS) {
+ _DEBUG_ERROR("da_err = %d", da_err);
+ goto return_part;
+ }
+
+ if (pSanPackage == NULL) {
+ _DEBUG_ERROR("pSanPackage is NULL");
+ goto return_part;
+ }
+
+ 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 return_part;
+ }
+
+ for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
+ fw_account = (sync_agent_fw_account_s *) iter->data;
+ result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, &sync_mode);
+ if (result == true) {
+ /*One device MUST NOT register multi account at same server... */
+ if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) {
+ result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
+ if (result == true) {
+ /*One device MUST NOT register multi account at same server... */
+ if (strcmp(pSanPackage->server_id, server_id) == 0) {
+ accountID = fw_account->account_id;
+ break;
+ }
+ } else {
+ _DEBUG_ERROR("failed in get_Config");
+ goto return_part;
+ }
+ }
+ } else {
+ _DEBUG_ERROR("failed in get_Config");
+ goto return_part;
+ }
+
+ }
+
+ if (accountID < 0)
+ goto return_part;
+
+ char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH);
+
+ void *in_param_value_array[3] = { &accountID, &syncMode, &pSanPackage };
+ int in_param_index_array[3] = { 0, 1, 2 };
+ sync_agent_ec_value_type_e in_param_type[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_type, in_param_value_array, _request_san_sync_task_finish_callback, NULL, (int *)&request_msg_id);
+
+ insert_request_msg_info(SYNC_MODE_SAN, request_msg_id);
+
+ sync_agent_close_agent();
+
+ if (pSanPackage != NULL)
+ sanPackageParserFree((void *)pSanPackage);
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+
+ return_part:
+
+ sync_agent_free_fw_account_list(account_info_list);
+
+ if (sync_mode != NULL)
+ free(sync_mode);
+
+ if (server_id != NULL)
+ free(server_id);
+
+/* if( incoming_data != NULL){
+ if (incoming_data->msg_body != NULL)
+ free((void *)incoming_data->msg_body);
+
+ free(incoming_data);
+ }*/
+
+ if (pSanPackage != NULL)
+ sanPackageParserFree((void *)pSanPackage);
+
+ sync_agent_close_agent();
+
+ _EXTERN_FUNC_EXIT;
+ return 0;
+}
+
+void send_periodic_sync_msg(int scheduler_id, void *data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ _DEBUG_INFO("#######Scheduler Send Msg Success!!!!!##########");
+ _DEBUG_INFO("schedulerId = %d", scheduler_id);
+
+ int accountId = -1;
+ int alarmId = 0;
+ char *alarmId_str = 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;
+
+ 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 (alarmId_str != NULL)
+ free(alarmId_str);
+
+ result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str);
+ if (result == false) {
+ _DEBUG_ERROR("failed in get_Config");
+ goto error;
+ }
+ alarmId = atoi(alarmId_str);
+ _DEBUG_INFO("alarm id = %d", alarmId);
+ if (alarmId == scheduler_id) {
+ _DEBUG_INFO("account_list[i] = %d", fw_account->account_id);
+ accountId = fw_account->account_id;
+ break;
+ }
+ }
+
+ if (accountId != -1) {
+ 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
+ };
+ char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC);
+
+ void *in_param_value_array[3] = { &accountId, &syncMode, NULL };
+
+ 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_periodic_sync_task_finish_callback, NULL, (int *)&request_msg_id);
+
+ insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id);
+ }
+
+ error:
+
+ sync_agent_free_fw_account_list(account_info_list);
+
+ if (alarmId_str != NULL)
+ free(alarmId_str);
+
+ sync_agent_close_agent();
+
+ _EXTERN_FUNC_EXIT;
+}
+
+int send_ip_push_sync_msg(char *data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ san_package_s *pSanPackage = NULL;
+ char *id = NULL;
+ char *server_id = NULL;
+ int accountId = -1;
+ bool result = false;
+
+ sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS;
+ GList *account_info_list = NULL;
+ GList *iter = NULL;
+ sync_agent_fw_account_s *account_info = NULL;
+
+ 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;
+ }
+
+ result = parse_ip_push_msg(data, &pSanPackage, &id);
+ if (result != true) {
+ _DEBUG_ERROR("Failed in parseIPPushMsg");
+ goto error;
+ }
+
+ cancel_current_sync_task();
+
+ sync_agent_fw_account_query_s query;
+ query.query = ACCOUNT_QUERY_BY_ACCESS_NAME;
+ query.access_name = "DIVE";
+
+ acc_err = sync_agent_query_fw_account(&query, &account_info_list);
+
+ for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) {
+ account_info = (sync_agent_fw_account_s *) iter->data;
+
+ _DEBUG_INFO("accountId = %d", account_info->account_id);
+ result = get_config(account_info->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
+ if (result == true) {
+ if (strcmp(pSanPackage->server_id, server_id) == 0) {
+ accountId = account_info->account_id;
+ break;
+ }
+ } else {
+ _DEBUG_ERROR("failed in get_Config");
+ goto error;
+ }
+ }
+
+ if (accountId < 0)
+ goto error;
+
+ char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH);
+
+ void *in_param_value_array[3] = { &accountId, &syncMode, &pSanPackage };
+ 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_san_sync_task_finish_callback, NULL, (int *)&request_msg_id);
+
+ insert_request_msg_info(SYNC_MODE_SAN, request_msg_id);
+
+ sync_agent_free_fw_account_list(account_info_list);
+
+ if (server_id != NULL)
+ free(server_id);
+
+ if (pSanPackage != NULL)
+ sanPackageParserFree((void *)pSanPackage);
+
+ sync_agent_close_agent();
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+
+ error:
+
+ sync_agent_free_fw_account_list(account_info_list);
+
+ if (server_id != NULL)
+ free(server_id);
+
+ if (pSanPackage != NULL)
+ sanPackageParserFree((void *)pSanPackage);
+
+ sync_agent_close_agent();
+
+ _EXTERN_FUNC_EXIT;
+ return 0;
+}
diff --git a/src/agent/framework/san-parser/pm_sanparser.c b/src/agent/framework/san-parser/pm_sanparser.c
new file mode 100755
index 0000000..bbb21e7
--- /dev/null
+++ b/src/agent/framework/san-parser/pm_sanparser.c
@@ -0,0 +1,633 @@
+/*
+ * 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.
+ */
+
+/**
+ * @PM_SanParser.c
+ * @version 0.1
+ * @brief This file is the source file of implementation of San Parser
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <inttypes.h>
+#include <glib.h>
+
+#include <sync_agent.h>
+
+#include "wbxml/wbxml.h"
+#include "wbxml/wbxml_tree.h"
+#include "framework/san-parser/pm_sanparser.h"
+
+#ifndef OMADS_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DS_COMMON"
+#endif
+
+static san_content_type_s contentTypeSupported[] = {
+ {0x00, NULL},
+ {0x03, "text/plain"},
+ {0x06, "text/x-vcalendar"},
+ {0x07, "text/x-vcard"},
+ {0x0305, "text/calendar"},
+ {0x0306, "application/vnd.omads-email+xml"},
+ {0x0307, "application/vnd.omads-file+xml"},
+ {0x0308, "application/vnd.omads-folder+xml"},
+ {0x0309, "text/vcard"}
+};
+
+san_package_s *san_package_12_parser(const char *msg_body, unsigned int msg_size)
+{
+ _EXTERN_FUNC_ENTER;
+
+ unsigned int idLength = (uint8_t) msg_body[23];
+ retvm_if(msg_size < (25 + idLength), NULL, "[sanPackage12Parser] SAN package size is smaller than its minimal size specified in the spec, related to [Header] part.");
+
+ san_package_s *san = (san_package_s *) calloc(1, sizeof(san_package_s));
+ retvm_if(san == NULL, NULL, "[sanPackage12Parser] SAN package memory allocation fail. [Container]");
+
+ /* MSG BODY WITHOUT DIGEST */
+ san->msg_body_without_digest = (char *)calloc(msg_size - 16, sizeof(char));
+ if (san->msg_body_without_digest == NULL) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Msg body]");
+ goto error;
+ }
+ memcpy(san->msg_body_without_digest, msg_body + 16, msg_size - 16);
+ san->msg_body_without_digest_length = msg_size - 16;
+
+ /* DIGEST */
+ san->digest = (char *)calloc(16, sizeof(char));
+ if (san->digest == NULL) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Digest]");
+ goto error;
+ }
+ memcpy(san->digest, msg_body, 16);
+
+ /* VERSION */
+ unsigned int version = ((uint8_t) msg_body[16]) << 2;
+ version = version | ((uint8_t) msg_body[17]) >> 6;
+
+ if (version != 12) {
+ _DEBUG_ERROR("[sanPackage12Parser] Not supported SAN version %d.", version);
+ goto error;
+ }
+ san->version = version;
+
+ /* UI MODE */
+ san->ui_mode = (((uint8_t) msg_body[17]) & 0x30) >> 4;
+
+ /* INITIATOR */
+ san->initiator = (((uint8_t) msg_body[17]) & 0x08) >> 3;
+
+ /* SESSION ID */
+/*san->sessionID = ((uint8_t)msgBody[21]) << 8;
+ san->sessionID = san->sessionID | (uint8_t)msgBody[22];*/
+ san->session_id = atoi(g_strdup_printf("%02X%02X", msg_body[21], msg_body[22]));
+ _DEBUG_INFO("session id : %d \n", san->session_id);
+
+ /* SERVER ID */
+ if (idLength) {
+ san->server_id = (char *)calloc(idLength + 1, sizeof(char));
+ if (san->server_id == NULL) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Server ID]");
+ goto error;
+ }
+ memcpy(san->server_id, msg_body + 24, idLength);
+ }
+
+ san->cnt_sync_alerts = ((uint8_t) msg_body[24 + idLength]) >> 4;
+
+ if (san->cnt_sync_alerts == 0) {
+ if (msg_size > 24 + idLength + 1) {
+ _DEBUG_INFO("[sanPackage12Parser] There are remaining bytes at the end of the package. (w/o alerts info)");
+ }
+
+ /* If number of sync alerts equals 0, should sync all data store in the client */
+ _EXTERN_FUNC_EXIT;
+ return san;
+ }
+
+ san->sync_alerts = (san_sync_alert_s *) calloc(san->cnt_sync_alerts, sizeof(san_sync_alert_s));
+ if (san->sync_alerts == NULL) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [syncAlerts]");
+ goto error;
+ }
+
+ msg_body += 25 + idLength;
+ unsigned int alertLength = 25 + idLength;
+ unsigned int i;
+
+ for (i = 0; i < san->cnt_sync_alerts; i++) {
+
+ idLength = (uint8_t) msg_body[4];
+ if (msg_size < (alertLength + 5 + idLength)) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN package size is smaller than");
+ _DEBUG_ERROR("[sanPackage12Parser] its minimal size specified in the spec, related to [Alerts] part.");
+ goto error;
+ }
+ alertLength = alertLength + 5 + idLength;
+
+ /* SYNC TYPE */
+ san_sync_type_e alert_type = (((uint8_t) msg_body[0]) >> 4) + 200;
+ if (alert_type < 206 || alert_type > 210) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN doesn't support the sync type %d.", alert_type);
+ goto error;
+ }
+
+ unsigned int contentType = ((uint8_t) msg_body[1]) << 16;
+ contentType = contentType | ((uint8_t) msg_body[2]) << 8;
+ contentType = contentType | ((uint8_t) msg_body[3]);
+
+ /* CONTENT TYPE */
+ char *alert_ct = NULL;
+
+ int j;
+ int cnt = (int)sizeof(contentTypeSupported) / sizeof(san_content_type_s);
+ bool isContentSupported = false;
+
+ for (j = 0; j < cnt; j++) {
+ if (contentType == contentTypeSupported[j].type) {
+ alert_ct = contentTypeSupported[j].strType;
+ isContentSupported = true;
+ break;
+ }
+ }
+
+ if (!isContentSupported) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN doesn't support the content type %d.", contentType);
+ goto error;
+ }
+
+ /* SERVER URI */
+ char *alert_uri = NULL;
+
+ if (idLength) {
+ alert_uri = (char *)calloc(idLength + 1, sizeof(char));
+ if (alert_uri == NULL) {
+ _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Server URI]");
+ goto error;
+ }
+ memcpy(alert_uri, msg_body + 5, idLength);
+ }
+ msg_body += 5 + idLength;
+
+ san->sync_alerts[i].sync_type = alert_type;
+ san->sync_alerts[i].content_type = alert_ct;
+ san->sync_alerts[i].server_uri = alert_uri;
+
+ }
+
+ if (msg_size > alertLength) {
+ _DEBUG_INFO("[sanPackage12Parser] There are remaining bytes at the end of the package. (with alerts info)");
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return san;
+
+ error:
+
+ sanPackageParserFree(san);
+
+ _EXTERN_FUNC_EXIT;
+ return NULL;
+
+}
+
+san_package_s *san_package_11_parser(const char *msg_body, unsigned int msg_size)
+{
+ _EXTERN_FUNC_ENTER;
+
+ san_package_s *san = (san_package_s *) calloc(1, sizeof(san_package_s));
+ if (san == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [Container]");
+
+ _EXTERN_FUNC_EXIT;
+ return NULL;
+ }
+
+ WBXMLTree *wbxml_tree = NULL;
+ WBXMLError wbxml_err = wbxml_tree_from_wbxml((unsigned char *)msg_body, msg_size, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, &wbxml_tree);
+
+ if (wbxml_err != WBXML_OK) {
+ _DEBUG_ERROR("[sanPackage11Parser] Libwbxml2 failed to parse WBXML STREAM to WBXML TREE, error code : %s", wbxml_errors_string(wbxml_err));
+ goto error;
+ }
+
+ WBXMLTreeNode *synchdr_node;
+ if ((synchdr_node = wbxml_tree_node_elt_get_from_name(wbxml_tree->root, "SyncHdr", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [SyncHdr]");
+ goto error;
+ }
+ WBXMLTreeNode *child_node = NULL;
+ const char *child_node_name = NULL;
+
+ for (child_node = synchdr_node->children; child_node != NULL; child_node = child_node->next) {
+ child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name);
+
+ if ((strcmp(child_node_name, "VerDTD") == 0) || (strcmp(child_node_name, "VerProto") == 0)) {
+ char *version = NULL;
+ if (child_node->children != NULL && child_node->children->type == WBXML_TREE_TEXT_NODE && child_node->children->content != NULL) {
+
+ version = (char *)wbxml_buffer_get_cstr(child_node->children->content);
+
+ if (strcmp(version, "1.1") && strcmp(version, "SyncML/1.1")) {
+ _DEBUG_ERROR("[sanPackage11Parser] Not supported SAN version %s.", version);
+ goto error;
+ }
+ san->version = 11;
+ }
+ } else if (strcmp(child_node_name, "SessionID") == 0) {
+ char *sessionID = NULL;
+ if (child_node->children != NULL && child_node->children->type == WBXML_TREE_TEXT_NODE && child_node->children->content != NULL) {
+
+ sessionID = (char *)wbxml_buffer_get_cstr(child_node->children->content);
+
+ if (sessionID == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL sessionID detected. sessionID MUST NOT be NULL.");
+ goto error;
+ }
+ san->session_id = atoi(sessionID);
+ }
+ } else if (strcmp(child_node_name, "Source") == 0) {
+ char *serverID = NULL;
+ unsigned serverIDlen = 0;
+ WBXMLTreeNode *serverid_node;
+ if ((serverid_node = wbxml_tree_node_elt_get_from_name(child_node, "LocURI", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [LocURI]");
+ goto error;
+ }
+
+ if (serverid_node->children != NULL && serverid_node->children->type == WBXML_TREE_TEXT_NODE && serverid_node->children->content != NULL) {
+
+ serverID = (char *)wbxml_buffer_get_cstr(serverid_node->children->content);
+ serverIDlen = wbxml_buffer_len(serverid_node->children->content);
+ if (serverID == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL serverID detected. serverID MUST NOT be NULL.");
+ goto error;
+ }
+
+ san->server_id = (char *)calloc(serverIDlen, sizeof(char));
+ if (san->server_id == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [Server ID]");
+ goto error;
+ }
+ memcpy(san->server_id, serverID, serverIDlen);
+ }
+ } else if (strcmp(child_node_name, "Cred") == 0) {
+
+ san->cred = (san_cred_s *) calloc(1, sizeof(san_cred_s));
+ if (san->cred == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [cred]");
+ goto error;
+ }
+
+ char *credFormat = NULL;
+ unsigned credFormatLen = 0;
+ WBXMLTreeNode *credformat_node;
+ if ((credformat_node = wbxml_tree_node_elt_get_from_name(child_node, "Format", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Format]");
+ goto error;
+ }
+
+ if (credformat_node->children != NULL && credformat_node->children->type == WBXML_TREE_TEXT_NODE && credformat_node->children->content != NULL) {
+
+ credFormat = (char *)wbxml_buffer_get_cstr(credformat_node->children->content);
+ credFormatLen = wbxml_buffer_len(credformat_node->children->content);
+ if (credFormat == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL credFormat detected. credFormat MUST NOT be NULL.");
+ goto error;
+ }
+
+ san->cred->cred_format = (char *)calloc(credFormatLen, sizeof(char));
+ if (san->cred->cred_format == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [credFormat]");
+ goto error;
+ }
+ memcpy(san->cred->cred_format, credFormat, credFormatLen);
+ }
+
+ char *credAuth = NULL;
+ unsigned credAuthLen = 0;
+ WBXMLTreeNode *credauth_node;
+ if ((credauth_node = wbxml_tree_node_elt_get_from_name(child_node, "Type", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Type]");
+ goto error;
+ }
+
+ if (credauth_node->children != NULL && credauth_node->children->type == WBXML_TREE_TEXT_NODE && credauth_node->children->content != NULL) {
+
+ credAuth = (char *)wbxml_buffer_get_cstr(credauth_node->children->content);
+ credAuthLen = wbxml_buffer_len(credauth_node->children->content);
+ if (credAuth == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL credAuth detected. credAuth MUST NOT be NULL.");
+ goto error;
+ }
+
+ san->cred->cred_auth = (char *)calloc(credAuthLen, sizeof(char));
+ if (san->cred->cred_auth == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [credAuth]");
+ goto error;
+ }
+ memcpy(san->cred->cred_auth, credAuth, credAuthLen);
+ }
+
+ char *credData = NULL;
+ unsigned credDataLen = 0;
+ WBXMLTreeNode *creddata_node;
+ if ((creddata_node = wbxml_tree_node_elt_get_from_name(child_node, "Data", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Data]");
+ goto error;
+ }
+
+ if (creddata_node->children != NULL && creddata_node->children->type == WBXML_TREE_TEXT_NODE && creddata_node->children->content != NULL) {
+
+ credData = (char *)wbxml_buffer_get_cstr(creddata_node->children->content);
+ credDataLen = wbxml_buffer_len(creddata_node->children->content);
+ if (credData == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL credData detected. credData MUST NOT be NULL.");
+ goto error;
+ }
+
+ san->cred->cred_data = (char *)calloc(credDataLen, sizeof(char));
+ if (san->cred->cred_data == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [credData]");
+ goto error;
+ }
+ memcpy(san->cred->cred_data, credData, credDataLen);
+ }
+
+ }
+
+ }
+
+ WBXMLTreeNode *syncbody_node;
+ if ((syncbody_node = wbxml_tree_node_elt_get_from_name(wbxml_tree->root, "SyncBody", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [SyncBody]");
+ goto error;
+ }
+
+ WBXMLList *alertnode_list = wbxml_tree_node_get_all_children(syncbody_node);
+ unsigned int alertnode_list_len = wbxml_list_len(alertnode_list);
+
+ child_node = (WBXMLTreeNode *) wbxml_list_get(alertnode_list, alertnode_list_len - 1);
+ child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name);
+ if (strcmp(child_node_name, "Final") == 0)
+ san->cnt_sync_alerts = alertnode_list_len - 1;
+
+ if (san->cnt_sync_alerts == 0) {
+ /* If number of sync alerts equals 0, should sync all data store in the client */
+ return san;
+ } else {
+ san->sync_alerts = (san_sync_alert_s *) calloc(san->cnt_sync_alerts, sizeof(san_sync_alert_s));
+ if (san->sync_alerts == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [syncAlerts]");
+ goto error;
+ }
+
+ unsigned int indexNode;
+ for (indexNode = 0; indexNode < san->cnt_sync_alerts; indexNode++) {
+
+ WBXMLTreeNode *alert_node = (WBXMLTreeNode *) wbxml_list_get(alertnode_list, indexNode);
+
+ char *alertData = NULL;
+ WBXMLTreeNode *alertdata_node;
+ if ((alertdata_node = wbxml_tree_node_elt_get_from_name(alert_node, "Data", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Data]");
+ goto error;
+ }
+
+ if (alertdata_node->children != NULL && alertdata_node->children->type == WBXML_TREE_TEXT_NODE && alertdata_node->children->content != NULL) {
+
+ alertData = (char *)wbxml_buffer_get_cstr(alertdata_node->children->content);
+ if (alertData == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL alertData detected. alertData MUST NOT be NULL.");
+ goto error;
+ }
+
+ if (atoi(alertData) < 206 || atoi(alertData) > 210) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN doesn't support the sync type %d.", atoi(alertData));
+ goto error;
+ }
+
+ san->sync_alerts[indexNode].sync_type = atoi(alertData);
+ }
+
+ char *alertURI = NULL;
+ unsigned alertURIlen = 0;
+ WBXMLTreeNode *alerturi_node;
+ if ((alerturi_node = wbxml_tree_node_elt_get_from_name(alert_node, "LocURI", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [LocURI]");
+ goto error;
+ }
+
+ if (alerturi_node->children != NULL && alerturi_node->children->type == WBXML_TREE_TEXT_NODE && alerturi_node->children->content != NULL) {
+
+ alertURI = (char *)wbxml_buffer_get_cstr(alerturi_node->children->content);
+ alertURIlen = wbxml_buffer_len(alerturi_node->children->content);
+ if (alertURI == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL alertURI detected. alertURI MUST NOT be NULL.");
+ goto error;
+ }
+
+ san->sync_alerts[indexNode].server_uri = (char *)calloc(alertURIlen, sizeof(char));
+ if (san->sync_alerts[indexNode].server_uri == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [serverURI]");
+ goto error;
+ }
+ memcpy(san->sync_alerts[indexNode].server_uri, alertURI, alertURIlen);
+ }
+
+ char *alertContentType = NULL;
+ unsigned alertContentTypeLen = 0;
+ WBXMLTreeNode *alertcontenttype_node;
+ if ((alertcontenttype_node = wbxml_tree_node_elt_get_from_name(alert_node, "Type", TRUE)) == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Type]");
+ goto error;
+ }
+
+ if (alertcontenttype_node->children != NULL && alertcontenttype_node->children->type == WBXML_TREE_TEXT_NODE && alertcontenttype_node->children->content != NULL) {
+
+ alertContentType = (char *)wbxml_buffer_get_cstr(alertcontenttype_node->children->content);
+ alertContentTypeLen = wbxml_buffer_len(alertcontenttype_node->children->content);
+
+ if (alertContentType == NULL) {
+ _DEBUG_ERROR("[sanPackage11Parser] NULL alertContentType detected. alertContentType MUST NOT be NULL.");
+ goto error;
+ }
+
+ int j;
+ int cnt = (int)sizeof(contentTypeSupported) / sizeof(san_content_type_s);
+ bool isContentSupported = false;
+
+ for (j = 0; j < cnt; j++) {
+ if (contentTypeSupported[j].strType == NULL)
+ continue;
+ if (strcmp(alertContentType, contentTypeSupported[j].strType) == 0) {
+ san->sync_alerts[indexNode].content_type = contentTypeSupported[j].strType;
+ isContentSupported = true;
+ break;
+ }
+ }
+
+ if (!isContentSupported) {
+ _DEBUG_ERROR("[sanPackage11Parser] SAN doesn't support the content type %s.", alertContentType);
+ goto error;
+ }
+ }
+ }
+ }
+
+ wbxml_tree_destroy(wbxml_tree);
+
+ _EXTERN_FUNC_EXIT;
+ return san;
+
+ error:
+
+ sanPackageParserFree(san);
+
+ _EXTERN_FUNC_EXIT;
+ return NULL;
+
+}
+
+void sanPackageParserFree(void *point)
+{
+ _EXTERN_FUNC_ENTER;
+
+ san_package_s *san = (san_package_s *) point;
+ if (san != NULL) {
+ if (san->msg_body_without_digest != NULL)
+ free(san->msg_body_without_digest);
+ if (san->digest != NULL)
+ free(san->digest);
+ if (san->cred != NULL) {
+ if (san->cred->cred_format != NULL)
+ free(san->cred->cred_format);
+ if (san->cred->cred_auth != NULL)
+ free(san->cred->cred_auth);
+ if (san->cred->cred_data != NULL)
+ free(san->cred->cred_data);
+ free(san->cred);
+ }
+ if (san->server_id != NULL)
+ free(san->server_id);
+ if (san->sync_alerts != NULL) {
+ int i;
+ for (i = 0; i < san->cnt_sync_alerts; i++) {
+ if (san->sync_alerts[i].server_uri != NULL) {
+ free(san->sync_alerts[i].server_uri);
+ }
+ }
+ free(san->sync_alerts);
+ }
+ free(san);
+ }
+
+ _EXTERN_FUNC_EXIT;
+}
+
+void sanPrintMsg(san_package_s * san)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int i;
+
+ _DEBUG_INFO("Printing SAN package ============================\n\n");
+
+ _DEBUG_INFO("MsgBody without Digest :\n\t");
+ for (i = 0; i < san->msg_body_without_digest_length; i++) {
+ _DEBUG_INFO("%02x ", san->msg_body_without_digest[i]);
+ if ((i + 1) % 16 == 0)
+ _DEBUG_INFO("\n\t");
+ }
+ _DEBUG_INFO("\n");
+
+ _DEBUG_INFO("Digest : %s\n", san->digest);
+ if (san->cred != NULL) {
+ if (san->cred->cred_format != NULL)
+ _DEBUG_INFO("Cred Format : %s\n", san->cred->cred_format);
+ if (san->cred->cred_auth != NULL)
+ _DEBUG_INFO("Cred Type : %s\n", san->cred->cred_auth);
+ if (san->cred->cred_data != NULL)
+ _DEBUG_INFO("Cred Data : %s\n", san->cred->cred_data);
+ }
+ _DEBUG_INFO("Version : %d\n", san->version);
+ _DEBUG_INFO("UI mode : %d\n", san->ui_mode);
+ _DEBUG_INFO("Initiator : %d\n", san->initiator);
+ _DEBUG_INFO("Session ID : %u\n", san->session_id);
+ _DEBUG_INFO("Server ID : %s\n", san->server_id);
+ _DEBUG_INFO("No. of Sync : %u\n", san->cnt_sync_alerts);
+
+ for (i = 0; i < san->cnt_sync_alerts; i++) {
+ _DEBUG_INFO("\n\t=== Sync No. %d ============\n", i + 1);
+ _DEBUG_INFO("\tSync type : %d\n", san->sync_alerts[i].sync_type);
+ _DEBUG_INFO("\tContent type : %s\n", san->sync_alerts[i].content_type);
+ _DEBUG_INFO("\tServer URI : %s\n", san->sync_alerts[i].server_uri);
+ };
+
+ _EXTERN_FUNC_EXIT;
+}
+
+int parse_ip_push_msg(char *data, san_package_s ** san_package, char **id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retvm_if(data == NULL, 0, "data is NULL");
+
+ char *pay = NULL;
+ char *body = NULL;
+ char *decoded_body = NULL;
+ unsigned int decoded_size;
+
+ *id = strtok(data, "|");
+ pay = strtok(NULL, "|");
+ body = strtok(NULL, "|");
+
+ _DEBUG_INFO("id = %s", *id);
+ _DEBUG_INFO("pay = %s", pay);
+ _DEBUG_INFO("after = %s", body);
+
+ decoded_body = (char *)g_base64_decode(body, &decoded_size);
+
+ _DEBUG_INFO("decoded_body = %s", decoded_body);
+ _DEBUG_INFO("decoded_size = %d", decoded_size);
+
+ *san_package = san_package_12_parser(decoded_body, decoded_size);
+
+ if ((*san_package) != NULL) {
+ _DEBUG_INFO("serverId = %s", (*san_package)->server_id);
+ _DEBUG_INFO("sessionID = %d", (*san_package)->session_id);
+ _DEBUG_INFO("cntSyncAlerts = %d", (*san_package)->cnt_sync_alerts);
+ int i;
+ for (i = 0; i < (*san_package)->cnt_sync_alerts; i++) {
+ _DEBUG_INFO("syncAlerts = %d", (*san_package)->sync_alerts[i].sync_type);
+ }
+ } else {
+ _DEBUG_ERROR("pSanPackage is NULL");
+ goto error;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+
+ error:
+
+ _EXTERN_FUNC_EXIT;
+ return 0;
+}
diff --git a/src/agent/framework/task/oma_ds_engine_controller_task.c b/src/agent/framework/task/oma_ds_engine_controller_task.c
new file mode 100755
index 0000000..ba7012d
--- /dev/null
+++ b/src/agent/framework/task/oma_ds_engine_controller_task.c
@@ -0,0 +1,1137 @@
+/*
+ * 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_Engine_Controller_Task.c
+ * @version 0.1
+ * @brief This file is the source file of implementation of make and register task to Engine Controller
+ */
+
+#include <string.h>
+
+#include <sync_agent.h>
+
+#include "framework/task/oma_ds_engine_controller_task.h"
+#include "service-engine/se_account.h"
+#include "service-engine/se_sync.h"
+#include "service-engine/se_storage.h"
+
+#ifndef OMADS_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DS_COMMON"
+#endif
+
+static GList *sync_request_id_list = NULL;
+
+static void _free_sync_categorie_list(void *list);
+static void _free_delete_profile_list(void *list);
+static void _free_resource_cp_list(void *list);
+
+static void _request_msg_info_free(request_msg_info_t * info);
+static void *_string_copy_struct(void *string);
+static request_msg_info_t *_create_request_msg_info(int sync_type, unsigned int request_id);
+
+static void __free_resource_cp(resource_cp_s * resource);
+
+static void _free_sync_categorie_list(void *list)
+{
+ _INNER_FUNC_ENTER;
+ retm_if(list == NULL, "list is NULL");
+
+ GList *categories = (GList *) list;
+ GList *iter = NULL;
+ for (iter = categories; iter != NULL; iter = g_list_next(iter))
+ free_sync_service(iter->data);
+
+ g_list_free(categories);
+ _INNER_FUNC_EXIT;
+}
+
+static void _free_delete_profile_list(void *list)
+{
+ _INNER_FUNC_ENTER;
+ retm_if(list == NULL, "list is NULL");
+
+ GList *profiles = (GList *) list;
+ GList *iter = NULL;
+ for (iter = profiles; iter != NULL; iter = g_list_next(iter))
+ free(iter->data);
+
+ g_list_free(profiles);
+ _INNER_FUNC_EXIT;
+}
+
+static void _free_resource_cp_list(void *list)
+{
+ _INNER_FUNC_ENTER;
+ retm_if(list == NULL, "list is NULL");
+
+ GList *profiles = (GList *) list;
+ GList *iter = NULL;
+ for (iter = profiles; iter != NULL; iter = g_list_next(iter))
+ __free_resource_cp(iter->data);
+
+ g_list_free(profiles);
+ _INNER_FUNC_EXIT;
+}
+
+static void __free_resource_cp(resource_cp_s * resource)
+{
+ _INNER_FUNC_ENTER;
+ retm_if(resource == NULL, "resource is NULL");
+
+ if (resource->name != NULL)
+ free(resource->name);
+
+ if (resource->accept != NULL)
+ free(resource->accept);
+
+ if (resource->id != NULL)
+ free(resource->id);
+
+ if (resource->password != NULL)
+ free(resource->password);
+
+ if (resource->auth_type != NULL)
+ free(resource->auth_type);
+
+ if (resource->auth_data != NULL)
+ free(resource->auth_data);
+
+ free(resource);
+ _INNER_FUNC_EXIT;
+}
+
+static request_msg_info_t *_create_request_msg_info(int sync_type, unsigned int request_id)
+{
+ _INNER_FUNC_ENTER;
+ request_msg_info_t *pInfo = (request_msg_info_t *) calloc(1, sizeof(request_msg_info_t));
+ retvm_if(pInfo == NULL, NULL, "pInfo is NULL");
+
+ pInfo->sync_type = sync_type;
+ pInfo->request_id = request_id;
+
+ _INNER_FUNC_EXIT;
+ return pInfo;
+}
+
+static void _request_msg_info_free(request_msg_info_t * info)
+{
+ _INNER_FUNC_ENTER;
+
+ if (info != NULL)
+ free(info);
+
+ _INNER_FUNC_EXIT;
+}
+
+static void *_string_copy_struct(void *string)
+{
+ _INNER_FUNC_ENTER;
+
+ void *data = NULL;
+ data = strdup((const char *)string);
+
+ _INNER_FUNC_EXIT;
+ return data;
+}
+
+sync_agent_ec_task_spec_s *make_synchronize_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("sanPackage", NULL, sanPackageParserFree,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *param_spec_array[3] = { pParam_spec1, pParam_spec2, pParam_spec3 };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("synchronize",
+ synchronize_task_process, NULL, NULL,
+ 3, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_add_profile_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("profileDirName", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("syncType", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("interval", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_structure("categories", NULL, _free_sync_categorie_list,
+ true, false, false, NULL, false, NULL, false, NULL);
+
+ sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec11 = sync_agent_alloc_param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[11] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+ pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10, pParam_spec11
+ };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("add_profile",
+ add_profile_task_process, NULL, NULL,
+ 11, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+ sync_agent_unref_param_spec(pParam_spec4);
+ sync_agent_unref_param_spec(pParam_spec5);
+ sync_agent_unref_param_spec(pParam_spec6);
+ sync_agent_unref_param_spec(pParam_spec7);
+ sync_agent_unref_param_spec(pParam_spec8);
+ sync_agent_unref_param_spec(pParam_spec9);
+ sync_agent_unref_param_spec(pParam_spec10);
+ sync_agent_unref_param_spec(pParam_spec11);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_edit_profile_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("syncType", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("interval", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_structure("categories", NULL, _free_sync_categorie_list,
+ true, false, false, NULL, false, NULL, false, NULL);
+
+ sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[10] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+ pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10
+ };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("edit_profile",
+ edit_profile_task_process, NULL, NULL,
+ 10, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+ sync_agent_unref_param_spec(pParam_spec4);
+ sync_agent_unref_param_spec(pParam_spec5);
+ sync_agent_unref_param_spec(pParam_spec6);
+ sync_agent_unref_param_spec(pParam_spec7);
+ sync_agent_unref_param_spec(pParam_spec8);
+ sync_agent_unref_param_spec(pParam_spec9);
+ sync_agent_unref_param_spec(pParam_spec10);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_delete_profile_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("profiles", NULL, _free_delete_profile_list,
+ true, false, false, NULL, false, NULL, false, NULL);
+
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("delete_profile",
+ delete_profile_task_process, NULL, NULL,
+ 2, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_get_profile_data_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("syncType", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_structure("interval", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("lastSessionStatus", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec11 = sync_agent_alloc_param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[11] = { pParam_spec1, pParam_spec2, pParam_spec3,
+ pParam_spec4, pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8,
+ pParam_spec9, pParam_spec10, pParam_spec11
+ };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_profile_data",
+ get_profile_data_task_process, NULL, NULL,
+ 11, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+ sync_agent_unref_param_spec(pParam_spec4);
+ sync_agent_unref_param_spec(pParam_spec5);
+ sync_agent_unref_param_spec(pParam_spec6);
+ sync_agent_unref_param_spec(pParam_spec7);
+ sync_agent_unref_param_spec(pParam_spec8);
+ sync_agent_unref_param_spec(pParam_spec9);
+ sync_agent_unref_param_spec(pParam_spec10);
+ sync_agent_unref_param_spec(pParam_spec11);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_get_profile_sync_category_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_int("enabled", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("srcURI", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("tgtURI", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+
+ sync_agent_ec_param_spec_s *param_spec_array[8] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4,
+ pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8
+ };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_profile_sync_category",
+ get_profile_sync_category_task_process, NULL, NULL,
+ 8, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+ sync_agent_unref_param_spec(pParam_spec4);
+ sync_agent_unref_param_spec(pParam_spec5);
+ sync_agent_unref_param_spec(pParam_spec6);
+ sync_agent_unref_param_spec(pParam_spec7);
+ sync_agent_unref_param_spec(pParam_spec8);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_get_profile_statistics_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("dbSynced", _string_copy_struct, free,
+ false, true, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_int("server2Client_Total", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_int("server2Client_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_int("server2Client_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_int("server2Client_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("client2Server_Total", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec11 = sync_agent_alloc_param_spec_int("client2Server_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec12 = sync_agent_alloc_param_spec_int("client2Server_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec13 = sync_agent_alloc_param_spec_int("client2Server_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[13] = { pParam_spec1, pParam_spec2, pParam_spec3,
+ pParam_spec4, pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8,
+ pParam_spec9, pParam_spec10, pParam_spec11, pParam_spec12, pParam_spec13
+ };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_profile_statistics",
+ get_profile_statistics_task_process, NULL, NULL,
+ 13, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+ sync_agent_unref_param_spec(pParam_spec4);
+ sync_agent_unref_param_spec(pParam_spec5);
+ sync_agent_unref_param_spec(pParam_spec6);
+ sync_agent_unref_param_spec(pParam_spec7);
+ sync_agent_unref_param_spec(pParam_spec8);
+ sync_agent_unref_param_spec(pParam_spec9);
+ sync_agent_unref_param_spec(pParam_spec10);
+ sync_agent_unref_param_spec(pParam_spec11);
+ sync_agent_unref_param_spec(pParam_spec12);
+ sync_agent_unref_param_spec(pParam_spec13);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_reset_synchronizing_profiles_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("reset_synchronizing_profiles",
+ reset_synchronizing_profiles_task_process, NULL, NULL,
+ 0, NULL);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_add_profile_cp_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free,
+ true, false, false, NULL, false, NULL, false, NULL);
+ sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("categories", NULL, _free_resource_cp_list,
+ true, false, false, NULL, false, NULL, false, NULL);
+
+ sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[7] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+ pParam_spec6, pParam_spec7
+ };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("add_profile_cp",
+ add_profile_cp_task_process, NULL, NULL,
+ 7, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+ sync_agent_unref_param_spec(pParam_spec2);
+ sync_agent_unref_param_spec(pParam_spec3);
+ sync_agent_unref_param_spec(pParam_spec4);
+ sync_agent_unref_param_spec(pParam_spec5);
+ sync_agent_unref_param_spec(pParam_spec6);
+ sync_agent_unref_param_spec(pParam_spec7);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_refresh_from_service_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+ sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("refresh_from_service",
+ refresh_from_service_task_process, NULL, NULL,
+ 1, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_cancel_request_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("cancel_sync_request",
+ cancel_sync_request_task_process, NULL, NULL,
+ 0, NULL);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_reset_all_data_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("reset_all_data",
+ reset_all_data_task_process, NULL, NULL,
+ 1, param_spec_array);
+
+ sync_agent_unref_param_spec(pParam_spec1);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_spec_s *make_get_all_profiles_data_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+ sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("profilesData", NULL, NULL,
+ false, true, false, NULL, false, NULL, false, NULL);
+
+ sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
+
+ sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_all_profiles_data",
+ get_all_profiles_data_task_process, NULL, NULL,
+ 2, param_spec_array);
+
+ _EXTERN_FUNC_EXIT;
+ return pTask_spec;
+}
+
+sync_agent_ec_task_error_e synchronize_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ int accountId = 0;
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+ retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId);
+
+ char *syncMode = NULL;
+ sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncMode);
+
+ san_package_s *pSanPackage = NULL;
+ sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &pSanPackage);
+
+ _DEBUG_INFO("accountId = %d", accountId);
+ _DEBUG_INFO("syncMode = %s", syncMode);
+
+ bool result = synchronize(accountId, syncMode, pSanPackage);
+ if (result == false)
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e add_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ char *profileDirName = NULL;
+ char *profileName = NULL;
+ char *addr = NULL;
+ char *id = NULL;
+ char *password = NULL;
+ char *syncMode = NULL;
+ char *syncType = NULL;
+ char *interval = NULL;
+ GList *categories = NULL;
+ int accountId;
+
+ bool res;
+ int result;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileDirName);
+ sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName);
+ 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, &syncMode);
+ sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncType);
+ 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_STRUCT, &categories);
+
+ res = add_profile(profileDirName, profileName, addr, id, password, syncMode, syncType, interval, categories, &accountId);
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+ sync_agent_set_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+
+ /*step 2 : start refresh_from_service for added account */
+ void *in_param_value_array[1] = { &accountId };
+ int in_param_index_array[1] = { 0 };
+ sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_INT };
+ unsigned int request_msg_id = 0;
+ sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE, 0, 1, in_param_index_array, in_param_value_type_array, in_param_value_array, NULL, NULL, (int *)&request_msg_id);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e edit_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ int accountId;
+ char *profileName = NULL;
+ char *addr = NULL;
+ char *id = NULL;
+ char *password = NULL;
+ char *syncMode = NULL;
+ char *syncType = NULL;
+ char *interval = NULL;
+ GList *categories = NULL;
+
+ bool res;
+ int result;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+ sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName);
+ 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, &syncMode);
+ sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncType);
+ 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_STRUCT, &categories);
+
+ res = edit_profile(accountId, profileName, addr, id, password, syncMode, syncType, interval, categories);
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e delete_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ bool res;
+ int result;
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ GList *profiles = NULL;
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles);
+
+ res = delete_profiles(profiles);
+ if (res == 0) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+
+}
+
+sync_agent_ec_task_error_e get_profile_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ int accountId = 0;
+ char *profileName = NULL;
+ char *addr = NULL;
+ char *id = NULL;
+ char *password = NULL;
+ char *syncMode = NULL;
+ char *syncType = NULL;
+ char *interval = NULL;
+ int lastSessionStatus;
+ int lastSessionTime;
+ int result;
+ bool res;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+ retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId);
+
+ res = get_profile_data(accountId, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &lastSessionStatus, &lastSessionTime);
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+ sync_agent_set_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName);
+ sync_agent_set_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr);
+ sync_agent_set_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id);
+ sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password);
+ sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncMode);
+ sync_agent_set_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncType);
+ sync_agent_set_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval);
+ sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &lastSessionStatus);
+ sync_agent_set_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &lastSessionTime);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+
+}
+
+sync_agent_ec_task_error_e get_profile_sync_category_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ int accountId = 0;
+ int contentType;
+
+ int enabled = 0;
+ char *srcURI = NULL;
+ char *tgtURI = NULL;
+ char *id = NULL;
+ char *password = NULL;
+ bool res;
+ int result = 0;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+ retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId);
+
+ sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &contentType);
+
+ res = get_profile_sync_category(accountId, contentType, &enabled, &srcURI, &tgtURI, &id, &password);
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+ sync_agent_set_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &enabled);
+ sync_agent_set_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &srcURI);
+ sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &tgtURI);
+ sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id);
+ sync_agent_set_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e get_profile_statistics_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ int accountId = 0;
+ int contentType;
+
+ char *dbSynced = NULL;
+ int lastSessionTime = -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_NrOfDelete = 0;
+ int client2Server_NrOfReplace = 0;
+
+ bool res;
+ int result;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+ retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId);
+
+ sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &contentType);
+
+ res = get_profile_statistics(accountId, contentType, &dbSynced, &lastSessionTime,
+ &server2Client_Total, &server2Client_NrOfAdd, &server2Client_NrOfDelete, &server2Client_NrOfReplace, &client2Server_Total, &client2Server_NrOfAdd, &client2Server_NrOfDelete, &client2Server_NrOfReplace);
+
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+ sync_agent_set_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &dbSynced);
+ sync_agent_set_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &lastSessionTime);
+ sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_Total);
+ sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
+ sync_agent_set_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
+ sync_agent_set_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
+ sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_Total);
+ sync_agent_set_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
+ sync_agent_set_param_value(&(param_array[11]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfDelete);
+ sync_agent_set_param_value(&(param_array[12]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e reset_synchronizing_profiles_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ reset_synchronizing_profiles();
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e add_profile_cp_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ char *profileName = NULL;
+ char *addr = NULL;
+ char *id = NULL;
+ char *password = NULL;
+ GList *categories = NULL;
+ int accountId;
+
+ bool res;
+ int result;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName);
+ sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr);
+ sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id);
+ sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password);
+ sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &categories);
+
+ res = add_profile_cp(profileName, addr, id, password, categories, &accountId);
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+ sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e refresh_from_service_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ int accountId;
+ bool res;
+
+ sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId);
+
+ res = refresh_from_service_all(accountId);
+ if (res == false)
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e cancel_sync_request_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ cancel_sync_request();
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e reset_all_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+ int result = 1;
+
+ /* delete all profiles */
+ result = delete_all_profiles();
+
+ /* delete all agent default table */
+ result = delete_all_agent_default_table();
+
+ sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+}
+
+sync_agent_ec_task_error_e get_all_profiles_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
+
+ bool res;
+ int result;
+ GList *profiles_data = NULL;
+
+ res = get_all_profiles_data(&profiles_data);
+
+ if (res == false) {
+ err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
+ result = 0;
+ } else
+ result = 1;
+
+ sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result);
+ sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles_data);
+
+ _EXTERN_FUNC_EXIT;
+ return err;
+
+}
+
+void insert_request_msg_info(int sync_type, unsigned int request_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_request_id_list = g_list_prepend(sync_request_id_list, _create_request_msg_info(sync_type, request_id));
+
+ _EXTERN_FUNC_EXIT;
+}
+
+void delete_request_msg_info(unsigned int request_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ GList *iter = NULL;
+ request_msg_info_t *pMsg_info = NULL;
+
+ for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+ pMsg_info = iter->data;
+
+ if (pMsg_info->request_id == request_id) {
+ sync_request_id_list = g_list_remove_link(sync_request_id_list, iter);
+ break;
+ }
+ }
+
+ if (iter != NULL) {
+ _request_msg_info_free(iter->data);
+ g_list_free_1(iter);
+ }
+ _EXTERN_FUNC_EXIT;
+}
+
+bool get_synchronizing_request_id(unsigned int *pRequest_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ bool success = false;
+ request_msg_info_t *pMsg_info = NULL;
+ GList *iter = NULL;
+
+ for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+ pMsg_info = iter->data;
+
+ if (pMsg_info->sync_type == SYNC_MODE_MANUAL || pMsg_info->sync_type == SYNC_MODE_PERIODIC || pMsg_info->sync_type == SYNC_MODE_SAN) {
+ success = true;
+ *pRequest_id = pMsg_info->request_id;
+
+ _request_msg_info_free(pMsg_info);
+ sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return success;
+}
+
+bool get_manual_sync_request_id(unsigned int *pRequest_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ bool success = false;
+ request_msg_info_t *pMsg_info = NULL;
+ GList *iter = NULL;
+
+ for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+ pMsg_info = iter->data;
+
+ if (pMsg_info->sync_type == SYNC_MODE_MANUAL) {
+ success = true;
+ *pRequest_id = pMsg_info->request_id;
+
+ _request_msg_info_free(pMsg_info);
+ sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return success;
+}
+
+bool get_periodic_sync_request_id(unsigned int *pRequest_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ bool success = false;
+ request_msg_info_t *pMsg_info = NULL;
+ GList *iter = NULL;
+
+ for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+ pMsg_info = iter->data;
+
+ if (pMsg_info->sync_type == SYNC_MODE_PERIODIC) {
+ success = true;
+ *pRequest_id = pMsg_info->request_id;
+
+ _request_msg_info_free(pMsg_info);
+ sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return success;
+}
+
+bool get_san_sync_request_id(unsigned int *pRequest_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ bool success = false;
+ request_msg_info_t *pMsg_info = NULL;
+ GList *iter = NULL;
+
+ for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+ pMsg_info = iter->data;
+
+ if (pMsg_info->sync_type == SYNC_MODE_SAN) {
+ success = true;
+ *pRequest_id = pMsg_info->request_id;
+
+ _request_msg_info_free(pMsg_info);
+ sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return success;
+}
+
+bool get_auto_configure_request_id(unsigned int *pRequest_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ bool success = false;
+ request_msg_info_t *pMsg_info = NULL;
+ GList *iter = NULL;
+
+ for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+ pMsg_info = iter->data;
+
+ if (pMsg_info->sync_type == SYNC_MODE_AUTOCONFIG) {
+ success = true;
+ *pRequest_id = pMsg_info->request_id;
+
+ _request_msg_info_free(pMsg_info);
+ sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return success;
+}
+
+bool cancel_current_sync_task()
+{
+ _EXTERN_FUNC_ENTER;
+
+ unsigned int request_msg_id_to_cancel = 0;
+ unsigned int request_msg_id = 0;
+ bool has_autoconfig = get_auto_configure_request_id(&request_msg_id_to_cancel);
+ if (has_autoconfig) {
+ _DEBUG_INFO("has_autoconfig [%d] ", request_msg_id_to_cancel);
+ sync_agent_cancel_task(request_msg_id_to_cancel);
+ } else {
+ bool has_sync = get_synchronizing_request_id(&request_msg_id_to_cancel);
+ if (has_sync) {
+ _DEBUG_INFO("has_manual_sync [%d] ", request_msg_id_to_cancel);
+ sync_agent_cancel_task(request_msg_id_to_cancel);
+
+ /*request network session cancel */
+ sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST, 0, 0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
+ } else {
+ /* nothing to do */
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return true;
+}