summaryrefslogtreecommitdiff
path: root/src/agent/framework/platform-event-handler/dm_platform_event_handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/framework/platform-event-handler/dm_platform_event_handler.c')
-rwxr-xr-xsrc/agent/framework/platform-event-handler/dm_platform_event_handler.c973
1 files changed, 973 insertions, 0 deletions
diff --git a/src/agent/framework/platform-event-handler/dm_platform_event_handler.c b/src/agent/framework/platform-event-handler/dm_platform_event_handler.c
new file mode 100755
index 0000000..c91a434
--- /dev/null
+++ b/src/agent/framework/platform-event-handler/dm_platform_event_handler.c
@@ -0,0 +1,973 @@
+/*
+ * oma-dm-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.
+ */
+
+/*lib*/
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/*sync-agent*/
+#include <sync_agent.h>
+#include <plugin/plugin_slp_sysnoti_wap_push.h>
+
+/*common*/
+#include "common/dm_common_def.h"
+#include "common/dm_common.h"
+#include "common/util/util.h"
+#include "framework/task/oma_dm_task_request.h"
+#include "framework/platform-event-handler/dm_platform_event_handler.h"
+#include "framework/san-parser/pm_sanparser.h"
+#include "dm-engine/fumo/fumo_account.h"
+#include "dm-engine/fumo/fumo_engine.h"
+#include "dm-engine/lawmo/lawmo_account.h"
+#include "dm-engine/lawmo/lawmo_engine.h"
+#include "dm-engine/cp/dm_cp_processor.h"
+#include "dm-engine/cp/dm_cp_security.h"
+#include "mo-handler/dm_mo_common.h"
+
+#ifndef OMADM_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DM_CP_PEH"
+#endif
+
+static DM_ERROR _fumo_interval_alarm(int item_id);
+static DM_ERROR _fumo_account_registration_alarm(int item_id);
+static DM_ERROR _lawmo_account_registration_alarm(int item_id);
+static DM_ERROR _send_event_ds(char *event_msg);
+static int _dm_notification_operation(const char *out_message, unsigned int outlen);
+
+static int _dm_notification_operation(const char *out_message, unsigned int outlen)
+{
+ _INNER_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if((out_message) == NULL, COMMON_ERR_IS_NULL, "out_message is NULL!!");
+
+ SanPackage *pSanPackage = NULL;
+ Event_Contents *ev_data = NULL;
+ int is_exist = 0;
+ pSanPackage = sanpackage_noti_parser((char *)out_message, outlen);
+ if (pSanPackage != NULL) {
+ ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
+ if (ev_data == NULL) {
+ _DEBUG_TRACE("calloc failed !!");
+ free_sanpackageparser(pSanPackage);
+ return COMMON_ERR_ALLOC;
+ }
+ ev_data->type = IP_PUSH_EVENT;
+ if ((pSanPackage->sessionID) == NULL || (pSanPackage->serverID) == NULL) {
+ _DEBUG_TRACE("san message null");
+ goto error;
+ }
+ ev_data->session_id = strdup((char *)pSanPackage->sessionID);
+ ev_data->server_id = strdup((char *)pSanPackage->serverID);
+ ev_data->noti_type = pSanPackage->uiMode;
+
+ _DEBUG_TRACE("event type ip push : %d", ev_data->type);
+ _DEBUG_TRACE("session id : %s", ev_data->session_id);
+ _DEBUG_TRACE("server id : %s", ev_data->server_id);
+ _DEBUG_TRACE("noti type : %d", ev_data->noti_type);
+
+ /* UI CONFIRM */
+ SERVICE_SERVER_TYPE engine_type;
+ engine_type = get_service_engine_type(ev_data->server_id);
+ _DEBUG_TRACE("engine type : %d", engine_type);
+
+ switch (engine_type) {
+ case SAMSUNG_FUMO_TYPE:
+ {
+ /*
+ * check samsung dm acc
+ */
+ ret = is_exist_dmacc(SAMSUNG_FUMO_TYPE, &is_exist);
+ if (ret != DM_OK || is_exist == 0) {
+ _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
+ goto error;
+ }
+
+ ret = fumo_service_start(ev_data);
+ if (ret != DM_OK)
+ goto error;
+ }
+ break;
+ case GCF_TYPE:
+ {
+ /*
+ * check gcf dm acc
+ */
+ ret = is_exist_dmacc(GCF_TYPE, &is_exist);
+ if (ret != DM_OK || is_exist == 0) {
+ _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
+ goto error;
+ }
+
+ ret = fumo_service_start(ev_data);
+ if (ret != DM_OK)
+ goto error;
+ }
+ break;
+ case SAMSUNG_FMM_TYPE:
+ {
+
+ /*
+ * check gcf dm acc
+ */
+ ret = is_exist_dmacc(SAMSUNG_FMM_TYPE, &is_exist);
+ if (ret != DM_OK || is_exist == 0) {
+ _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
+ goto error;
+ }
+
+ ret = dm_lawmo_common_task_request(ev_data);
+ if (ret != DM_OK)
+ goto error;
+
+ }
+ break;
+ default:
+ _DEBUG_TRACE("dm non engine ", ret);
+ break;
+ }
+
+ } else {
+ _DEBUG_TRACE("san message null");
+ goto error;
+ }
+
+ free_sanpackageparser(pSanPackage);
+ _INNER_FUNC_EXIT;
+ return 1;
+
+ error:
+ event_data_free((void *)ev_data);
+ free_sanpackageparser(pSanPackage);
+ _INNER_FUNC_EXIT;
+ _DEBUG_INFO("end error");
+ return 0;
+}
+
+int dm_wap_push_incomming_callback(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if((user_data) == NULL, -1, "user_data is NULL!!");
+
+ pmci_san_incoming_s *incomming_struct = (pmci_san_incoming_s *) user_data;
+ if (incomming_struct != NULL) {
+ /* db open */
+ int db_ret = 0;
+ db_ret = sync_agent_open_agent();
+ _DEBUG_INFO("OPEN DACI : %d", db_ret);
+
+ /* generate ext_id */
+ int ext_id = -1;
+ char **ext_id_list = NULL;
+ while (1) {
+ ext_id_list = sync_agent_generate_item_luid(1, 1);
+ if (ext_id_list == NULL) {
+ ret = -1;
+ return ret;
+ }
+ ext_id = atoi(ext_id_list[0]);
+ _DEBUG_INFO("ext_id : %d", ext_id);
+
+ /* create folder for generated ext_id */
+ char folder_name[50] = { 0, };
+ snprintf(folder_name, sizeof(folder_name), "%s/%d", CP_DATA_REPOSITORY_PATH, ext_id);
+ _DEBUG_INFO("folder name : %s", folder_name);
+
+ int folder_ret = sync_agent_create_directory(folder_name);
+ if (folder_ret != 1) {
+ _DEBUG_INFO("sync_agent_create_directory( ext_id : %d ) failed !!", ext_id);
+ _DEBUG_INFO("retry sync_agent_generate_item_luid() !!");
+// return DM_ERR_UNKNOWN;
+ if (ext_id_list[0] != NULL)
+ free(ext_id_list[0]);
+
+ if (ext_id_list != NULL)
+ free(ext_id_list);
+
+ ext_id = -1;
+ ext_id_list = NULL;
+ } else {
+ _DEBUG_INFO("sync_agent_create_directory( ext_id : %d ) success !!", ext_id);
+ if (ext_id_list[0] != NULL)
+ free(ext_id_list[0]);
+
+ if (ext_id_list != NULL)
+ free(ext_id_list);
+
+ break;
+ }
+ }
+
+ db_ret = sync_agent_close_agent();
+ _DEBUG_INFO("CLOSE DACI : %d", db_ret);
+
+ // switch( version )
+ switch (incomming_struct->version) {
+ case 13: /*SAN_DM_XML = 13 */
+ {
+ /*pSanPackage = sanPackage11Parser( msgBody, msgSize ) ; */
+ }
+ break;
+ case 14: /*SAN_DM_WBXML = 14 */
+ {
+ /*pSanPackage = sanPackage12Parser( msgBody, msgSize ) ; */
+ }
+ break;
+ case 15: /*SAN_DM_NOTI = 15 */
+ {
+ int result = _dm_notification_operation(incomming_struct->msg_body, incomming_struct->msg_size);
+ _DEBUG_INFO("wap push parser : %d", result);
+ }
+ break;
+ case 16: /*SAN_CP_XML = 16 */
+ {
+ // CP_ERROR result = process_Recieved_CP_XML(msgBody, msgSize);
+ CP_ERROR result = process_Recieved_CP_XML(incomming_struct->msg_body, incomming_struct->msg_size, ext_id);
+ _DEBUG_INFO("xml cp parser : %d", result);
+ }
+ break;
+ case 17: /*SAN_CP_WBXML = 17 */
+ {
+ // CP_ERROR result = process_Recieved_CP_WBXML(msgBody, msgSize);
+ CP_ERROR result = process_Recieved_CP_WBXML(incomming_struct->msg_body, incomming_struct->msg_size, ext_id);
+ _DEBUG_INFO("wxml cp parser : %d", result);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ _DEBUG_INFO("end");
+
+ if (ret == DM_OK)
+ ret = 1;
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int dm_wap_push_operation_callback(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if((user_data) == NULL, -1, "user_data is NULL!!");
+
+ CP_ERROR err = CP_ERROR_SUCCESS;
+
+ pmci_san_operation_s *operation_struct = (pmci_san_operation_s *) user_data;
+ if (operation_struct != NULL) {
+
+ process_Set_msgId(operation_struct->msg_id);
+ _DEBUG_INFO("msg id : %d", operation_struct->msg_id);
+ _DEBUG_INFO("ext id : %d", operation_struct->ext_id);
+
+ if (operation_struct->msg_id == -1 && operation_struct->ext_id == -1) { // delete all
+ _DEBUG_INFO("operation : delete all !!");
+
+ err = process_Delete_All_CP_Data();
+ if (err != CP_ERROR_SUCCESS) {
+ _DEBUG_INFO("process_Delete_All_CP_Data() fail !!");
+ // ret = DM_ERR_CP
+ goto return_part;
+ } else {
+ _DEBUG_INFO("process_Delete_All_CP_Data() success !!");
+ }
+ } else if (operation_struct->msg_id == -1 && operation_struct->ext_id != -1) { // delete 1 msg
+ _DEBUG_INFO("operation : delete 1 msg !!");
+
+ err = process_Delete_CP_Data(operation_struct->ext_id);
+ if (err != CP_ERROR_SUCCESS) {
+ _DEBUG_INFO("process_Delete_CP_Data() fail !!");
+ // ret = DM_ERR_CP
+ goto return_part;
+ } else {
+ _DEBUG_INFO("process_Delete_CP_Data() success !!");
+ }
+ } else { // install
+ _DEBUG_INFO("operation : install !!");
+
+ int is_correct = -1;
+ err = process_Check_Pincode(1, NULL, &is_correct, operation_struct->ext_id);
+ if (err != CP_ERROR_SUCCESS) {
+ _DEBUG_INFO("process_Check_Pincode() fail !!");
+ // ret = DM_ERR_CP
+ goto return_part;
+ } else {
+ _DEBUG_INFO("process_Check_Pincode() success !!");
+
+ /* process_Setting_CP() */
+ if (is_correct == 1) {
+ _DEBUG_INFO("NETWPIN case - Valid PIN !!");
+
+ err = process_Setting_CP(operation_struct->ext_id);
+ if (err != CP_ERROR_SUCCESS) {
+ _DEBUG_INFO("process_Setting_CP() fail !!");
+ goto return_part;
+ } else {
+ _DEBUG_INFO("process_Setting_CP() success !!");
+ }
+ } else if (is_correct == 0) {
+ _DEBUG_INFO("NETWPIN case - Invalid PIN !!");
+ err = CP_ERROR_FAIL;
+ }
+ }
+ }
+ }
+
+ return_part:
+ if (operation_struct != NULL)
+ free(operation_struct);
+
+ if (ret == DM_OK)
+ ret = 1;
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int dm_ip_push_callback(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if((user_data) == NULL, -1, "user_data is NULL!!");
+
+ OPER_MODE operationMode;
+ operationMode = OPER_SERVER_INITIATION_FROM_IP;
+ char *pushmessage = NULL;
+ //ip_push_struct->message = strdup("IPP_20111216000000000000000001|DM|Ft4/CLTiWx/Y0AK+fBIayALoAAAAlPcKeDZnMXExNHI3NQ==");
+
+ pushmessage = (char *)user_data;
+
+ _DEBUG_INFO("user_data : %s", (char *)user_data);
+ _DEBUG_INFO("push contents : %s", pushmessage);
+
+ if (pushmessage != NULL) {
+ char *app_type = strchr(pushmessage, '|') + 1;
+ char *message = NULL;
+ message = strstr(app_type, "DS|");
+
+ if (message != NULL) {
+ _DEBUG_INFO("DS event : %s", message);
+ ret = _send_event_ds(message);
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ }
+
+ message = strchr(app_type, '|') + 1;
+ _DEBUG_INFO("message :%s", message);
+
+ unsigned int outlen = 0;
+ unsigned char *out_message = g_base64_decode(message, &outlen);
+
+ int result = _dm_notification_operation((const char *)out_message, outlen);
+ _DEBUG_INFO("ip push parser : %d", result);
+
+ } else {
+ _DEBUG_INFO("push message null");
+ //do nothing
+ goto error;
+ }
+
+ str_free(&pushmessage);
+
+ if (ret == DM_OK) {
+ ret = 1;
+ }
+
+ _EXTERN_FUNC_EXIT;
+
+ return ret;
+
+ error:
+ str_free(&pushmessage);
+
+ _EXTERN_FUNC_EXIT;
+ _DEBUG_INFO("end error ");
+ return ret;
+
+}
+
+int dm_telephony_incomming_callback(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ _DEBUG_INFO("----------------------------------------------------incomming tel----------------------------------------------------");
+
+ DM_ERROR ret = DM_OK;
+ int is_exist = 0;
+ engine_status *status = NULL;
+
+ /*ret = DB_Open();
+ _DEBUG_INFO("dm db open = %d", ret); */
+
+ is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
+ _DEBUG_INFO("is engine : %d", is_exist);
+
+ if (is_exist != 0) {
+ ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
+ if (ret != DM_OK)
+ goto error;
+
+ if (status != NULL) {
+ if (status->ui_mode != NULL) {
+ if (strcmp(status->ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE) != 0) {
+
+ if (status->engine_status == DM_SERVICE_ING || status->engine_status == DM_SERVICE_UNKNOWN) {
+ _DEBUG_INFO("cancel fumo task id = %d ", status->task_id);
+ cancel_task(status->task_id);
+ _DEBUG_INFO("terminate ui");
+ terminate_oma_dm_ui(DM_ERR_NOT_FOUND, FUMO_SERVICE_ENGINE);
+ } else {
+ /*do nothing */
+ }
+ } else {
+ /*do nothing */
+ _DEBUG_INFO("back ground ui");
+ }
+ } else {
+ /*do nothing */
+ }
+ } else {
+ /*do nothing */
+ }
+ } else {
+ /*do nothing */
+ }
+ /*sleep(1);
+ DB_Close(); */
+ if (status != NULL) {
+ Free_Memory_Engine_Status(&status, 1);
+ }
+
+ if (ret == DM_OK) {
+ ret = 1;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ error:
+ /*sleep(1);
+ DB_Close(); */
+ if (status != NULL) {
+ Free_Memory_Engine_Status(&status, 1);
+ }
+ _DEBUG_INFO("ERROR END = %d", ret);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int dm_telephony_end_callback(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ _DEBUG_INFO("----------------------------------------------------end tel----------------------------------------------------");
+
+ DM_ERROR ret = DM_OK;
+ sync_agent_da_return_e err = SYNC_AGENT_DA_SUCCESS;
+
+ engine_status *status = NULL;
+ int is_exist = 0;
+ int is_alarm = 0;
+ char *server_id = NULL;
+
+ /*ret = DB_Open();
+ _DEBUG_INFO("dm db open = %d", ret);
+ */
+ err = sync_agent_open_agent();
+ _DEBUG_INFO("sync agent db open = %d", ret);
+
+ is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
+ _DEBUG_INFO("is engine : %d", is_exist);
+ if (is_exist == 0) {
+ sleep(1);
+ //DB_Close();
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ }
+
+ ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
+ if (ret != DM_OK) {
+ sleep(1);
+ //DB_Close();
+ _DEBUG_INFO("sync agent db close = %d", ret);
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ }
+
+ if (status != NULL && status->ui_mode != NULL) {
+ if (!strcmp(status->ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE)) {
+
+ is_alarm = check_existed_fumo_reminder_interval();
+ if (is_alarm == 1) {
+ _DEBUG_INFO("have alarm");
+ } else {
+ sleep(5);
+
+ ret = get_Serverid(SAMSUNG_FUMO_TYPE, &server_id);
+ if (ret != DM_OK) {
+ sleep(1);
+ //DB_Close();
+ err = sync_agent_close_agent();
+ _DEBUG_INFO("sync agent db close = %d", ret);
+ Free_Memory_Engine_Status(&status, 1);
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ }
+
+ if (server_id != NULL) {
+ //current time > alarm time
+ Event_Contents *ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
+ ev_data->type = UI_EVENT;
+ ev_data->session_id = NULL;
+ ev_data->server_id = server_id;
+ ev_data->noti_type = NOTI_TYPE_USERINTERACTION;
+ ev_data->ui_mode = strdup(OMADM_FUMO_NOTI_UI_TYPE);
+
+ ret = dm_fumo_common_task_request(ev_data);
+ if (ret != DM_OK) {
+ //DB_Close();
+ err = sync_agent_close_agent();
+ _DEBUG_INFO("sync agent db close = %d", ret);
+ Free_Memory_Engine_Status(&status, 1);
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ }
+ } else {
+ _DEBUG_INFO("server id is null");
+ }
+ }
+ }
+ }
+
+ if (ret == DM_OK) {
+ ret = 1;
+ }
+
+ sleep(1);
+ //DB_Close();
+ err = sync_agent_close_agent();
+ _DEBUG_INFO("sync agent db close = %d", ret);
+ Free_Memory_Engine_Status(&status, 1);
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+int network_on_callback()
+{
+ _EXTERN_FUNC_ENTER;
+ _DEBUG_INFO("network on");
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+int network_off_callback()
+{
+ _EXTERN_FUNC_ENTER;
+ _DEBUG_INFO("network off");
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+int network_change_callback()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ _DEBUG_INFO("changed network");
+
+ ret = 1;
+/*for prevent*/
+/*
+ * int config = 0;
+
+ //each company's
+ //check alarm
+
+ if(config == 0) {
+ _DEBUG_INFO("wifi only off mode download");
+ } else if (config == 1) {
+ ret = get_wifi_state();
+ _DEBUG_INFO("wifi only mode : %d", ret);
+ if (ret != SYNC_AGENT_NA_SUCCESS) {
+ return 0;
+ }
+
+ ret = auto_operate_service_engine();
+ if(ret !=DM_OK ) {
+ _DEBUG_INFO("error : %d", ret);
+ return 0;
+ }
+ }*/
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int alarm_callback(int item_id, void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+ _DEBUG_INFO("#######Scheduler Send Msg Success!!!!!########## : %d", item_id);
+
+ DM_ERROR ret = DM_OK;
+ int value = -1;
+ int count = 0;
+
+ int exist = 0;
+ sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS;
+ sync_agent_da_config_s *config = NULL;
+ GList *list = NULL;
+
+ int db_ret = 0;
+ db_ret = sync_agent_open_agent();
+
+ result = sync_agent_is_exist_config(FUMO_INTERVAL_TYPE, FUMO_INTERVAL, &exist);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+
+ _DEBUG_INFO("exist : %d", exist);
+
+ if (exist != 0) {
+ result = sync_agent_get_config_list(FUMO_INTERVAL_TYPE, &list);
+ count = g_list_length(list);
+ _DEBUG_INFO("count : %d", count);
+ if (count != 0 && list != NULL) {
+ config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
+ if (chartoint(config->value, &value) == 1) {
+ if (value == item_id) {
+ ret = _fumo_interval_alarm(item_id);
+ if (ret != DM_OK) {
+ sync_agent_free_config_list(list);
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+ }
+ }
+ }
+ count = 0;
+ value = -1;
+ sync_agent_free_config_list(list);
+ list = NULL;
+ } else {
+
+ result = sync_agent_remove_service_data(1, item_id);
+ _DEBUG_INFO("delete alarm %d", result);
+
+ }
+
+ result = sync_agent_is_exist_config(FUMO_ACCOUNT_ALARM_TYPE, FUMO_ACCOUNT_ALARM, &exist);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+
+ _DEBUG_INFO("exist : %d", exist);
+
+ if (exist != 0) {
+ result = sync_agent_get_config_list(FUMO_ACCOUNT_ALARM_TYPE, &list);
+ count = g_list_length(list);
+ _DEBUG_INFO("count : %d", count);
+ if (count != 0 && list != NULL) {
+ config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
+ if (chartoint(config->value, &value) == 1) {
+ if (value == item_id) {
+ ret = _fumo_account_registration_alarm(item_id);
+ if (ret != DM_OK) {
+ sync_agent_free_config_list(list);
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+ }
+ }
+ }
+ count = 0;
+ value = -1;
+ sync_agent_free_config_list(list);
+ list = NULL;
+ }
+
+ result = sync_agent_is_exist_config(LAWMO_ACCOUNT_ALARM_TYPE, LAWMO_ACCOUNT_ALARM, &exist);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+
+ _DEBUG_INFO("exist : %d", exist);
+
+ if (exist != 0) {
+ result = sync_agent_get_config_list(LAWMO_ACCOUNT_ALARM_TYPE, &list);
+ count = g_list_length(list);
+ _DEBUG_INFO("count : %d", count);
+ if (count != 0 && list != NULL) {
+ config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
+ if (chartoint(config->value, &value) == 1) {
+ if (value == item_id) {
+ ret = _lawmo_account_registration_alarm(item_id);
+ if (ret != DM_OK) {
+ sync_agent_free_config_list(list);
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+ }
+ }
+ }
+ count = 0;
+ value = -1;
+ sync_agent_free_config_list(list);
+ list = NULL;
+ }
+
+ db_ret = sync_agent_close_agent();
+ _DEBUG_INFO("CLOSE DACI : %d", db_ret);
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+static DM_ERROR _fumo_interval_alarm(int item_id)
+{
+ _INNER_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ char *server_id = NULL;
+ engine_status *status = NULL;
+ Event_Contents *ev_data = NULL;
+ int is_exist = 0;
+
+ ret = DB_Open();
+ _DEBUG_TRACE("status db : %d", ret);
+
+ /*
+ * check samsung dm acc
+ */
+ ret = is_exist_dmacc(SAMSUNG_FUMO_TYPE, &is_exist);
+ if (ret != DM_OK || is_exist == 0) {
+ _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
+ goto error;
+ }
+
+ if (IsExist_Engine_id(FUMO_SERVICE_ENGINE) != 0) {
+ ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
+ if (ret != DM_OK)
+ goto error;
+
+ _DEBUG_TRACE(" result =[%d]\n", ret);
+ /*update engine_status */
+ if (status != NULL) {
+ if (status->server_id != NULL) {
+ server_id = strdup(status->server_id);
+ }
+
+ status->engine_status = DM_SERVICE_ING;
+ if (status->download_click == RESUME_STATUS_INSTALL_IDLE) {
+ status->download_click = RESUME_STATUS_INSTALL;
+ } else if (status->download_click == RESUME_STATUS_DOWNLOAD_IDLE) {
+ status->download_click = RESUME_STATUS_DOWNLOAD;
+ } else {
+ status->download_click = RESUME_STATUS_DOWNLOAD;
+ }
+
+ ret = Update_Engine_Status(status);
+ _DEBUG_TRACE(" update engine status : %d \n", ret);
+
+ DB_Close();
+
+ Free_Memory_Engine_Status(&status, 1);
+ }
+ } else {
+
+ }
+
+ /*************************************************/
+
+ if (server_id == NULL) {
+ ret = get_Serverid(SAMSUNG_FUMO_TYPE, &server_id);
+ if (ret != DM_OK || server_id == NULL)
+ goto error;
+ }
+
+ ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
+ if (ev_data == NULL) {
+ _DEBUG_TRACE("calloc failed !!");
+ ret = COMMON_ERR_ALLOC;
+ goto error;
+ }
+ ev_data->type = UI_EVENT;
+ ev_data->session_id = NULL;
+ ev_data->server_id = strdup(server_id);
+ ev_data->noti_type = NOTI_TYPE_USERINTERACTION;
+ ev_data->ui_mode = strdup(OMADM_FUMO_NOTI_UI_TYPE);
+
+ _DEBUG_TRACE("alarm : %s", ev_data->server_id);
+ ret = dm_fumo_common_task_request(ev_data);
+ if (ret != DM_OK) {
+ goto error;
+ }
+
+ str_free(&server_id);
+
+ _INNER_FUNC_EXIT;
+ return ret;
+
+ error:
+ str_free(&server_id);
+ event_data_free((void *)ev_data);
+
+ DB_Close();
+ if (status != NULL)
+ Free_Memory_Engine_Status(&status, 1);
+
+ _DEBUG_TRACE("end error : %d", ret);
+ _INNER_FUNC_EXIT;
+ return ret;
+}
+
+static DM_ERROR _fumo_account_registration_alarm(int item_id)
+{
+ _INNER_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ ret = register_fota_account();
+ if (ret == 0) {
+ _DEBUG_TRACE("fail register fota account : %d ", ret);
+ ret = DM_ERR_FOTA_ACCOUNT_REGISTRATION;
+ } else {
+ _DEBUG_TRACE("success register fota account : %d ", ret);
+ }
+
+ _INNER_FUNC_EXIT;
+ return ret;
+}
+
+static DM_ERROR _lawmo_account_registration_alarm(int item_id)
+{
+ _INNER_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ ret = register_lawmo_account(item_id, NULL);
+ if (ret == 0) {
+ _DEBUG_TRACE("fail register lawmo account : %d ", ret);
+ ret = DM_ERR_LAWMO_ACCOUNT_REGISTRATION;
+ } else {
+ _DEBUG_TRACE("success register lawmo account : %d ", ret);
+ }
+
+ _INNER_FUNC_EXIT;
+ return ret;
+}
+
+static DM_ERROR _send_event_ds(char *event_msg)
+{
+ _INNER_FUNC_ENTER;
+
+ int client_len;
+ int client_sockfd;
+ struct sockaddr_un clientaddr;
+ int event_type = 9;
+ char *msg = NULL;
+
+ retvm_if((event_msg) == NULL, DM_ERR_EVENT_DS, "event_msg is NULL!!");
+
+ msg = strchr(event_msg, '|') + 1;
+ _DEBUG_TRACE("msg = %s", msg);
+
+ sync_agent_event_data_s *event = sync_agent_create_event(event_type);
+ if (event == NULL) {
+ _DEBUG_TRACE("event is NULL");
+ _INNER_FUNC_EXIT;
+ return DM_ERR_EVENT_DS;
+ }
+
+ sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, msg);
+
+ client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (client_sockfd == -1) {
+ _DEBUG_TRACE("socket create Error!!");
+ sync_agent_free_event(event);
+ _INNER_FUNC_EXIT;
+ return DM_ERR_EVENT_DS;
+ }
+
+ bzero(&clientaddr, sizeof(clientaddr));
+ clientaddr.sun_family = AF_UNIX;
+
+ int str_len = 0;
+
+ str_len = g_strlcpy(clientaddr.sun_path, IPC_DS, (int)sizeof(clientaddr.sun_path));
+ if (str_len >= sizeof(clientaddr.sun_path)) {
+ _DEBUG_TRACE("buffer overflow");
+ sync_agent_free_event(event);
+ close(client_sockfd);
+ _INNER_FUNC_EXIT;
+ return CP_ERROR_FAIL;
+ }
+
+ client_len = sizeof(clientaddr);
+
+ if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0) {
+ _DEBUG_TRACE("socket connect error");
+ sync_agent_free_event(event);
+ close(client_sockfd);
+ _INNER_FUNC_EXIT;
+ return DM_ERR_EVENT_DS;
+ }
+
+ int send_data_size = (event->data - event->size) + 1;
+ int write_ret = write(client_sockfd, (void *)(event->size), send_data_size);
+ _DEBUG_TRACE("write ret : %d", write_ret);
+ close(client_sockfd);
+ sync_agent_free_event(event);
+
+ _INNER_FUNC_EXIT;
+ return DM_OK;
+}
+
+void event_data_free(void *event_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retm_if((event_data) == NULL, "event_data is NULL!!");
+
+ Event_Contents *pEvent_data = (Event_Contents *) event_data;
+
+ pEvent_data->type = 0;
+ pEvent_data->noti_type = 0;
+ str_free(&(pEvent_data->server_id));
+ str_free(&(pEvent_data->session_id));
+ str_free(&(pEvent_data->ui_mode));
+
+ free(pEvent_data);
+
+ _EXTERN_FUNC_EXIT;
+}