summaryrefslogtreecommitdiff
path: root/src/agent/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/common')
-rw-r--r--src/agent/common/dm-status/oma_dm_status_db.c961
-rwxr-xr-xsrc/agent/common/dm-status/oma_dm_status_db_handler.c638
-rwxr-xr-xsrc/agent/common/dm_common.c1480
-rw-r--r--src/agent/common/util/util.c490
4 files changed, 3569 insertions, 0 deletions
diff --git a/src/agent/common/dm-status/oma_dm_status_db.c b/src/agent/common/dm-status/oma_dm_status_db.c
new file mode 100644
index 0000000..d63f22f
--- /dev/null
+++ b/src/agent/common/dm-status/oma_dm_status_db.c
@@ -0,0 +1,961 @@
+/*
+ * 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 <unistd.h>
+
+/*sync-agent*/
+#include <sync_agent.h>
+
+/*dm-agent*/
+#include "common/dm-status/oma_dm_status_db.h"
+#include "common/dm_common.h"
+
+#ifndef OMADM_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DM_DB"
+#endif
+
+/* static function define */
+static int _busy_handler(void *pData, int count);
+static DM_ERROR _query_exec(DB_HANDLER * db_handler, char *query, char *errMsg);
+static db_stmt __query_prepare(DB_HANDLER * db_handler, char *query, int size);
+static DM_ERROR __stmt_bind_text(DB_HANDLER * db_handler, db_stmt stmt, int index, const char *value);
+static DM_ERROR _stmt_bind_int(DB_HANDLER * db_handler, db_stmt stmt, int index, const int value);
+static DM_ERROR ___stmt_bind_null(DB_HANDLER * db_handler, db_stmt stmt, int index);
+static DM_ERROR __stmt_step(DB_HANDLER * db_handler, db_stmt stmt);
+/*static DM_ERROR __stmt_reset(DB_HANDLER *db_handler, db_stmt stmt);*/
+static DM_ERROR __stmt_finalize(DB_HANDLER * db_handler, db_stmt stmt);
+static char *_stmt_column_text(db_stmt stmt, int index);
+static int __stmt_column_int(db_stmt stmt, int index);
+static DM_ERROR _get_table(DB_HANDLER * db_handler, char *query, char ***result, int *row_count, int *col_count);
+static void __free_table(char **result);
+
+static int _exist_table(DB_HANDLER * db_handler, const char *table_name);
+static int _get_data_count(DB_HANDLER * db_handler, char *query, int size);
+static char *_replace_engine_status_value(ENGINE_STATUS_VALUE engine_status_value);
+
+static char *__create_table[] = {
+ /* 1. create engine_status_tbl */
+ "create table engine_status_tbl "
+ "( "
+ "engine_id integer, "
+ "engine_status integer default null, "
+ "server_id varchar(100) default null, "
+ "server_url varchar(100) default null, "
+ "correlator varchar(100) default null, "
+ "mo_path varchar(200) default null, "
+ "result_status integer not null, "
+ "ui_mode varchar(100) default null, " "task_id integer not null, " "ui_noti_type integer, " "download_click integer, " "update_time integer not null, " "constraint engine_status_tbl_pk primary key(engine_id)" ");",
+};
+
+static char *__delete_table[] = {
+ /* 1. delete engine_status_tbl */
+ "delete from engine_status_tbl",
+
+};
+
+DM_ERROR dm_open_agent(DB_HANDLER ** db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ char *errMsg = 0;
+
+ if (*db_handler == NULL) {
+ ret = sqlite3_open("/opt/dbspace/.dm_service.db", db_handler);
+ if (ret != SQLITE_OK)
+ goto FINISH;
+
+ /* register busy handler */
+ ret = sqlite3_busy_handler(*db_handler, _busy_handler, 0);
+ if (ret != SQLITE_OK) {
+ _DEBUG_INFO("fail to register busy handler", errMsg);
+ goto FINISH;
+ }
+
+ /* enable persist journal mode */
+ ret = sqlite3_exec(*db_handler, "PRAGMA journal_mode = PERSIST", 0, 0, &errMsg);
+ if (ret != SQLITE_OK) {
+ _DEBUG_INFO("fail to change journal mode: %s", errMsg);
+ goto FINISH;
+ }
+ _DEBUG_INFO("db_open success");
+ } else {
+ _DEBUG_INFO("db_already opened");
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+
+ FINISH:
+
+ _DEBUG_INFO("db_open failed(%d) : %s", ret, sqlite3_errmsg(*db_handler));
+
+ if (errMsg != NULL)
+ sqlite3_free(errMsg);
+
+ sqlite3_close(*db_handler);
+ *db_handler = 0;
+
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+}
+
+DM_ERROR dm_close_agent(DB_HANDLER * db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ ret = sqlite3_close(db_handler);
+ db_handler = 0;
+
+ if (ret != SQLITE_OK) {
+ _DEBUG_INFO("db_close failed(%d) : %s", ret, sqlite3_errmsg(db_handler));
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _DEBUG_INFO("db_close success");
+
+ _EXTERN_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+DM_ERROR dm_create_table(DB_HANDLER * db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ if ((dm_begin_transaction(db_handler) != DM_OK)) {
+ _DEBUG_INFO("mo_db_default_tbl_create failed");
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ /* 1. create engine_status_tbl */
+ if (_exist_table(db_handler, "engine_status_tbl") == 0) {
+ ret = _query_exec(db_handler, __create_table[0], "engine_status_tbl_create failed");
+ if (ret != DM_OK)
+ goto FINISH;
+ }
+
+ /* add normal engine */
+ if (dm_isExist_engine_id(db_handler, 0) == 0) {
+ engine_status status;
+ memset(&status, 0x00, sizeof(engine_status));
+ status.engine_id = 0;
+ status.engine_status = 1;
+ status.result_status = 0;
+ status.task_id = 0;
+ status.ui_noti_type = 0;
+ status.download_click = 0;
+ ret = dm_add_engine_status(db_handler, &status);
+ _DEBUG_INFO("create dm service tbl : %d", ret);
+ }
+
+ FINISH:
+
+ if (ret != DM_OK) {
+ dm_end_transaction(db_handler, TRANSACTION_ROLLBACK_);
+ ret = DM_ERR_UNKNOWN;
+ } else {
+ ret = dm_end_transaction(db_handler, TRANSACTION_COMMIT_);
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_delete_table(DB_HANDLER * db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ int i = 0;
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ if ((dm_begin_transaction(db_handler) != DM_OK)) {
+ _DEBUG_INFO("default_tbl_delete failed");
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ /* delete all default table */
+ for (i = 0; i < DB_TABLE_NAME_MAX; i++) {
+ ret = _query_exec(db_handler, __delete_table[i], "default_tbl_delete failed");
+ if (ret != DM_OK)
+ goto FINISH;
+ }
+
+ FINISH:
+
+ if (ret != DM_OK) {
+ dm_end_transaction(db_handler, TRANSACTION_ROLLBACK_);
+ ret = DM_ERR_UNKNOWN;
+ } else {
+ ret = dm_end_transaction(db_handler, TRANSACTION_COMMIT_);
+ _DEBUG_INFO("end transaction : %d", ret);
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_reset_table(DB_HANDLER * db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ if ((dm_begin_transaction(db_handler) != DM_OK)) {
+ _DEBUG_INFO("default_tbl_delete failed");
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ /*ret = dm_delete_table(db_handler);
+ if (ret != DM_OK)
+ goto FINISH; */
+
+ /* delete all default table */
+ int i = 0;
+ for (i = 0; i < DB_TABLE_NAME_MAX; i++) {
+ ret = _query_exec(db_handler, __delete_table[i], "default_tbl_delete failed");
+ if (ret != DM_OK)
+ goto FINISH;
+ }
+
+ ret = dm_init_engine_status(db_handler);
+ if (ret != DM_OK)
+ goto FINISH;
+
+ FINISH:
+
+ if (ret != DM_OK) {
+ dm_end_transaction(db_handler, TRANSACTION_ROLLBACK_);
+ ret = DM_ERR_UNKNOWN;
+ } else {
+ ret = dm_end_transaction(db_handler, TRANSACTION_COMMIT_);
+ _DEBUG_INFO("end transaction : %d", ret);
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_begin_transaction(DB_HANDLER * db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = _query_exec(db_handler, "begin immediate", "begin_transaction failed");
+ _DEBUG_INFO("begin transaction : %d", ret);
+/* if (ret == SYNC_AGENT_DA_ERR_QUERY_FAILED)
+ ret = SYNC_AGENT_DA_ERR_TRANSACTION_FAILED;*/
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_end_transaction(DB_HANDLER * db_handler, DB_TRANSACTION transaction)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ char *query = 0;
+ char *errMsg = 0;
+
+ if (transaction == TRANSACTION_COMMIT_) {
+ query = "commit transaction";
+ errMsg = "commit_transaction failed";
+ } else if (transaction == TRANSACTION_ROLLBACK_) {
+ query = "rollback transaction";
+ errMsg = "rollback_transaction failed";
+ }
+
+ ret = _query_exec(db_handler, query, errMsg);
+ if (ret == DM_ERR_UNKNOWN) {
+ if (transaction == TRANSACTION_COMMIT_) {
+ query = "rollback transaction";
+ errMsg = "rollback_transaction failed";
+ ret = _query_exec(db_handler, query, errMsg);
+ if (ret == DM_OK)
+ _DEBUG_INFO("rollback_transaction success");
+ }
+ ret = DM_ERR_UNKNOWN;
+ _DEBUG_INFO("end transaction error : %d", ret);
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_init_engine_status(DB_HANDLER * db_handler)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_ERR_UNKNOWN;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ /* add normal engine */
+ if (dm_isExist_engine_id(db_handler, 0) == 0) {
+ engine_status status;
+ memset(&status, 0x00, sizeof(engine_status));
+ status.engine_id = 0;
+ status.engine_status = 1;
+ status.result_status = 0;
+ status.task_id = 0;
+ status.ui_noti_type = 0;
+ status.download_click = 0;
+ ret = dm_add_engine_status(db_handler, &status);
+ _DEBUG_INFO("dm add engine status : %d", ret);
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_add_engine_status(DB_HANDLER * db_handler, engine_status * status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ db_stmt stmt = 0;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+ retvm_if(status == NULL, DM_ERR_UNKNOWN, "db status is NULL !!");
+
+ char *query = "insert into engine_status_tbl (engine_id, engine_status, server_id, server_url, correlator, mo_path, result_status, ui_mode, task_id, ui_noti_type, download_click, update_time) " "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+
+ stmt = __query_prepare(db_handler, query, strlen(query));
+ if (stmt == NULL) {
+ ret = DM_ERR_UNKNOWN;
+ _DEBUG_INFO("ERROR DB");
+ goto FINISH;
+ }
+
+ _stmt_bind_int(db_handler, stmt, 1, status->engine_id);
+ _stmt_bind_int(db_handler, stmt, 2, status->engine_status);
+ __stmt_bind_text(db_handler, stmt, 3, status->server_id);
+ __stmt_bind_text(db_handler, stmt, 4, status->server_url);
+ __stmt_bind_text(db_handler, stmt, 5, status->correlator);
+ __stmt_bind_text(db_handler, stmt, 6, status->mo_path);
+ _stmt_bind_int(db_handler, stmt, 7, status->result_status);
+ __stmt_bind_text(db_handler, stmt, 8, status->ui_mode);
+ _stmt_bind_int(db_handler, stmt, 9, status->task_id);
+ _stmt_bind_int(db_handler, stmt, 10, status->ui_noti_type);
+ _stmt_bind_int(db_handler, stmt, 11, status->download_click);
+ _stmt_bind_int(db_handler, stmt, 12, (int)(time(&status->update_time)));
+
+ ret = __stmt_step(db_handler, stmt);
+ if (ret != DM_OK)
+ ret = DM_ERR_UNKNOWN;
+
+ FINISH:
+
+ if (stmt != NULL)
+ __stmt_finalize(db_handler, stmt);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_delete_engine_status(DB_HANDLER * db_handler, int engine_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ db_stmt stmt = 0;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ char *query = "delete from engine_status_tbl where engine_id = ?";
+
+ stmt = __query_prepare(db_handler, query, strlen(query));
+ if (stmt == NULL) {
+ ret = DM_ERR_UNKNOWN;
+ goto FINISH;
+ }
+
+ _stmt_bind_int(db_handler, stmt, 1, engine_id);
+ ret = __stmt_step(db_handler, stmt);
+
+ FINISH:
+
+ if (stmt != NULL)
+ __stmt_finalize(db_handler, stmt);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_update_engine_status(DB_HANDLER * db_handler, engine_status * status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ db_stmt stmt = 0;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+ retvm_if(status == NULL, DM_ERR_UNKNOWN, "db status is NULL !!");
+
+ char *query = "update engine_status_tbl "
+ "set engine_status = ?, server_id = ?, server_url = ?, correlator = ?, mo_path = ?, result_status = ?, ui_mode = ?, task_id = ?, ui_noti_type = ?, download_click = ?, update_time = ? " "where engine_id = ?";
+
+ stmt = __query_prepare(db_handler, query, strlen(query));
+ if (stmt == NULL) {
+ ret = DM_ERR_UNKNOWN;
+ goto FINISH;
+ }
+
+ _stmt_bind_int(db_handler, stmt, 1, status->engine_status);
+ __stmt_bind_text(db_handler, stmt, 2, status->server_id);
+ __stmt_bind_text(db_handler, stmt, 3, status->server_url);
+ __stmt_bind_text(db_handler, stmt, 4, status->correlator);
+ __stmt_bind_text(db_handler, stmt, 5, status->mo_path);
+ _stmt_bind_int(db_handler, stmt, 6, status->result_status);
+ __stmt_bind_text(db_handler, stmt, 7, status->ui_mode);
+ _stmt_bind_int(db_handler, stmt, 8, status->task_id);
+ _stmt_bind_int(db_handler, stmt, 9, status->ui_noti_type);
+ _stmt_bind_int(db_handler, stmt, 10, status->download_click);
+ _stmt_bind_int(db_handler, stmt, 11, (int)(time(&status->update_time)));
+ _stmt_bind_int(db_handler, stmt, 12, status->engine_id);
+
+ ret = __stmt_step(db_handler, stmt);
+ if (ret != DM_OK)
+ ret = DM_ERR_UNKNOWN;
+
+ FINISH:
+
+ if (stmt != NULL)
+ __stmt_finalize(db_handler, stmt);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_update_engine_status_column(DB_HANDLER * db_handler, int engine_id, ENGINE_STATUS_VALUE engine_status_value, void *value)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ db_stmt stmt = 0;
+ char query[MAX_QUERY_LENGTH] = { 0, };
+ char *column_name = _replace_engine_status_value(engine_status_value);
+ time_t update_time;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ snprintf(query, sizeof(query), "update engine_status_tbl set %s = ?, update_time= %d where engine_id = %d", column_name, (int)(time(&update_time)), engine_id);
+
+ stmt = __query_prepare(db_handler, query, strlen(query));
+ if (stmt == NULL) {
+ ret = DM_ERR_UNKNOWN;
+ goto FINISH;
+ }
+
+ if (engine_status_value == VALUE_ENGINE_STATUS || engine_status_value == VALUE_RESULT_STATUS || engine_status_value == VALUE_TASK_ID || engine_status_value == VALUE_UI_NOTI_TYPE || engine_status_value == VALUE_DOWNLOAD_CLICK) {
+ int *engine_status = (int *)value;
+ _stmt_bind_int(db_handler, stmt, 1, *engine_status);
+ } else {
+ char *str = (char *)value;
+ __stmt_bind_text(db_handler, stmt, 1, str);
+ }
+
+ ret = __stmt_step(db_handler, stmt);
+ if (ret != DM_OK)
+ ret = DM_ERR_UNKNOWN;
+
+ FINISH:
+
+ if (stmt != NULL)
+ __stmt_finalize(db_handler, stmt);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_get_engine_status(DB_HANDLER * db_handler, int engine_id, engine_status ** status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ db_stmt stmt = 0;
+ char *query = "select * from engine_status_tbl where engine_id = ?";
+ engine_status *temp_status = 0;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ stmt = __query_prepare(db_handler, query, strlen(query));
+ if (stmt != NULL) {
+ _stmt_bind_int(db_handler, stmt, 1, engine_id);
+
+ if (__stmt_step(db_handler, stmt) == DM_ERR_MORE_DATA) {
+ temp_status = (engine_status *) calloc(1, sizeof(engine_status));
+ if (temp_status == NULL) {
+ _DEBUG_INFO("alloc fail");
+ _EXTERN_FUNC_EXIT;
+ return COMMON_ERR_ALLOC;
+ }
+ temp_status->engine_id = __stmt_column_int(stmt, 0);
+ temp_status->engine_status = __stmt_column_int(stmt, 1);
+ temp_status->server_id = _stmt_column_text(stmt, 2);
+ temp_status->server_url = _stmt_column_text(stmt, 3);
+ temp_status->correlator = _stmt_column_text(stmt, 4);
+ temp_status->mo_path = _stmt_column_text(stmt, 5);
+ temp_status->result_status = __stmt_column_int(stmt, 6);
+ temp_status->ui_mode = _stmt_column_text(stmt, 7);
+ temp_status->task_id = __stmt_column_int(stmt, 8);
+ temp_status->ui_noti_type = __stmt_column_int(stmt, 9);
+ temp_status->download_click = __stmt_column_int(stmt, 10);
+ temp_status->update_time = __stmt_column_int(stmt, 11);
+ }
+ ret = __stmt_finalize(db_handler, stmt);
+ } else {
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ (*status) = temp_status;
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR dm_get_aII_engine_status(DB_HANDLER * db_handler, engine_status ** status_list, int *count)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ engine_status *temp_status = 0;
+ char **result = 0;
+ int row_count = 0;
+ int col_count = 0;
+ int index = 6;
+ int i = 0;
+ char query[MAX_QUERY_LENGTH] = { 0, };
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ snprintf(query, sizeof(query), "select * from engine_status_tbl");
+
+ ret = _get_table(db_handler, query, &result, &row_count, &col_count);
+ if ((ret == DM_OK) && (row_count != 0) && (result != NULL)) {
+ *count = row_count;
+ temp_status = (engine_status *) calloc(row_count, sizeof(engine_status));
+ if (temp_status == NULL) {
+ _DEBUG_INFO("memory_allocation failed");
+ ret = COMMON_ERR_ALLOC;
+ goto FINISH;
+ }
+
+ for (i = 0; i < row_count; i++) {
+ temp_status[i].engine_id = ATOI(result[index]);
+ index++;
+ temp_status[i].engine_status = ATOI(result[index]);
+ index++;
+ temp_status[i].server_id = STRDUP(result[index]);
+ index++;
+ temp_status[i].server_url = STRDUP(result[index]);
+ index++;
+ temp_status[i].correlator = STRDUP(result[index]);
+ index++;
+ temp_status[i].mo_path = STRDUP(result[index]);
+ index++;
+ temp_status[i].result_status = ATOI(result[index]);
+ index++;
+ temp_status[i].ui_mode = STRDUP(result[index]);
+ index++;
+ temp_status[i].task_id = ATOI(result[index]);
+ index++;
+ temp_status[i].ui_noti_type = ATOI(result[index]);
+ index++;
+ temp_status[i].download_click = ATOI(result[index]);
+ index++;
+ temp_status[i].update_time = ATOI(result[index]);
+ index++;
+ }
+ }
+
+ FINISH:
+
+ if (result != NULL)
+ __free_table(result);
+
+ *status_list = temp_status;
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int dm_isExist_engine_id(DB_HANDLER * db_handler, int engine_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 1;
+ int dataCount = 0;
+ char query[MAX_QUERY_LENGTH] = { 0, };
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ snprintf(query, sizeof(query), "select count(*) from engine_status_tbl where engine_id = %d", engine_id);
+
+ dataCount = _get_data_count(db_handler, query, strlen(query));
+
+ if (dataCount == 0)
+ ret = 0;
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int _busy_handler(void *pData, int count)
+{
+ _INNER_FUNC_ENTER;
+
+ _DEBUG_TRACE("__busy_handler %d called", count);
+
+ /* sleep time when SQLITE_LOCK */
+ usleep(100000);
+
+ _INNER_FUNC_EXIT;
+ /* retry will be stopped if busy handler return 0 */
+ return RETRY_COUNT - count;
+}
+
+DM_ERROR _query_exec(DB_HANDLER * db_handler, char *query, char *errMsg)
+{
+ _INNER_FUNC_ENTER;
+
+ char *queryMsg = 0;
+ int ret = 0;
+
+ retvm_if(db_handler == NULL, DM_ERR_UNKNOWN, "db handler is NULL !!");
+
+ ret = sqlite3_exec(db_handler, query, 0, 0, &queryMsg);
+ if (ret != SQLITE_OK) {
+ _DEBUG_TRACE("%s(%d) : %s", errMsg, ret, queryMsg);
+
+ if (queryMsg != NULL)
+ sqlite3_free(queryMsg);
+
+/*
+ if (ret == SQLITE_BUSY)
+ return DM_ERR_UNKNOWN;
+*/
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ return DM_OK;
+ _INNER_FUNC_EXIT;
+}
+
+db_stmt __query_prepare(DB_HANDLER * db_handler, char *query, int size)
+{
+ _INNER_FUNC_ENTER;
+
+ int ret = 0;
+ db_stmt stmt = 0;
+
+ ret = sqlite3_prepare_v2(db_handler, query, size, &stmt, 0);
+ if (ret != SQLITE_OK)
+ _DEBUG_VERBOSE("sqlite3_query_prepare failed(%d) : %s ", ret, sqlite3_errmsg(db_handler));
+
+ _INNER_FUNC_EXIT;
+
+ return stmt;
+}
+
+DM_ERROR __stmt_bind_text(DB_HANDLER * db_handler, db_stmt stmt, int index, const char *value)
+{
+ _INNER_FUNC_ENTER;
+
+ int ret = 0;
+
+ if (value != NULL) {
+ ret = sqlite3_bind_text(stmt, index, value, strlen(value), SQLITE_STATIC);
+ } else {
+ ret = ___stmt_bind_null(db_handler, stmt, index);
+ if (ret == DM_OK) {
+ ret = SQLITE_OK;
+ }
+ }
+
+ if (ret != SQLITE_OK) {
+ _DEBUG_VERBOSE("sqlite3_stmt_bind_text failed(%d) : %s ", ret, sqlite3_errmsg(db_handler));
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _INNER_FUNC_EXIT;
+ return DM_OK;
+}
+
+DM_ERROR _stmt_bind_int(DB_HANDLER * db_handler, db_stmt stmt, int index, const int value)
+{
+ _INNER_FUNC_ENTER;
+
+ int ret = 0;
+
+ ret = sqlite3_bind_int(stmt, index, value);
+ if (ret != SQLITE_OK) {
+ _DEBUG_TRACE("sqlite3_stmt_bind_int failed(%d) : %s \n", ret, sqlite3_errmsg(db_handler));
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+DM_ERROR ___stmt_bind_null(DB_HANDLER * db_handler, db_stmt stmt, int index)
+{
+ _INNER_FUNC_ENTER;
+
+ int ret = 0;
+
+ ret = sqlite3_bind_null(stmt, index);
+ if (ret != SQLITE_OK) {
+ _DEBUG_VERBOSE("sqlite3_stmt_bind_null failed(%d) : %s", ret, sqlite3_errmsg(db_handler));
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _INNER_FUNC_EXIT;
+ return DM_OK;
+}
+
+DM_ERROR __stmt_step(DB_HANDLER * db_handler, db_stmt stmt)
+{
+ _INNER_FUNC_ENTER;
+ int ret = 0;
+
+ ret = sqlite3_step(stmt);
+
+ if (ret == SQLITE_ROW) {
+ _INNER_FUNC_EXIT;
+ return DM_ERR_MORE_DATA;
+ }
+
+ if (ret != SQLITE_DONE) {
+ _DEBUG_VERBOSE("sqlite3_stmt_step failed(%d) : %s", ret, sqlite3_errmsg(db_handler));
+
+/* if (ret == SQLITE_BUSY)
+ return DM_ERR_UNKNOWN;*/
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _INNER_FUNC_EXIT;
+ return DM_OK;
+}
+
+/*DM_ERROR __stmt_reset(DB_HANDLER *db_handler, db_stmt stmt)
+{
+ int ret = 0;
+
+ if (sqlite3_reset(stmt) != SQLITE_OK) {
+ _DEBUG_INFO("sqlite3_stmt_reset failed(%d) : %s", ret, sqlite3_errmsg(db_handler));
+ return DM_ERR_UNKNOWN;
+ }
+
+ return DM_OK;
+}*/
+
+DM_ERROR __stmt_finalize(DB_HANDLER * db_handler, db_stmt stmt)
+{
+ _INNER_FUNC_ENTER;
+ int ret = 0;
+
+ if (sqlite3_finalize(stmt) != SQLITE_OK) {
+ _DEBUG_VERBOSE("sqlite3_stmt_finalize failed(%d) : %s", ret, sqlite3_errmsg(db_handler));
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _INNER_FUNC_EXIT;
+ return DM_OK;
+}
+
+char *_stmt_column_text(db_stmt stmt, int index)
+{
+ _EXTERN_FUNC_ENTER;
+
+ char *temp = 0;
+ temp = (char *)sqlite3_column_text(stmt, index);
+
+ _EXTERN_FUNC_EXIT;
+
+ return STRDUP(temp);
+}
+
+int __stmt_column_int(db_stmt stmt, int index)
+{
+ _INNER_FUNC_ENTER;
+
+ _INNER_FUNC_EXIT;
+ return (int)sqlite3_column_int(stmt, index);
+}
+
+DM_ERROR _get_table(DB_HANDLER * db_handler, char *query, char ***result, int *row_count, int *col_count)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ char *errMsg;
+
+ if (db_handler == NULL) {
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ ret = sqlite3_get_table(db_handler, query, result, row_count, col_count, &errMsg);
+
+ if (ret != SQLITE_OK) {
+ _DEBUG_TRACE("sqlite3_get_table failed(%d) : %s", ret, errMsg);
+
+ __free_table(*result);
+
+ if (errMsg != NULL)
+ sqlite3_free(errMsg);
+
+ _EXTERN_FUNC_EXIT;
+
+ return DM_ERR_UNKNOWN;
+ }
+
+ _EXTERN_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+void __free_table(char **result)
+{
+ _INNER_FUNC_ENTER;
+
+ if (result != NULL)
+ sqlite3_free_table(result);
+
+ _INNER_FUNC_EXIT;
+
+}
+
+int _exist_table(DB_HANDLER * db_handler, const char *table_name)
+{
+ _INNER_FUNC_ENTER;
+
+ db_stmt stmt = 0;
+ int table_count = 0;
+ char *query = "select count(*) from sqlite_master where tbl_name= ?";
+
+ stmt = __query_prepare(db_handler, query, strlen(query));
+ if ((stmt != NULL) && (__stmt_bind_text(db_handler, stmt, 1, table_name) == DM_ERR_MORE_DATA)) {
+
+ if (__stmt_step(db_handler, stmt) == DM_ERR_MORE_DATA)
+ table_count = __stmt_column_int(stmt, 0);
+
+ __stmt_finalize(db_handler, stmt);
+
+ if (table_count > 0) {
+ _INNER_FUNC_EXIT;
+ return 1;
+ }
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return 0;
+}
+
+int _get_data_count(DB_HANDLER * db_handler, char *query, int size)
+{
+ _INNER_FUNC_ENTER;
+
+ db_stmt stmt = 0;
+ int data_count = 0;
+
+ stmt = __query_prepare(db_handler, query, size);
+ if (stmt != NULL) {
+ if (__stmt_step(db_handler, stmt) == DM_ERR_MORE_DATA)
+ data_count = __stmt_column_int(stmt, 0);
+
+ __stmt_finalize(db_handler, stmt);
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return data_count;
+}
+
+static char *_replace_engine_status_value(ENGINE_STATUS_VALUE engine_status_value)
+{
+ _INNER_FUNC_ENTER;
+
+ char *temp = 0;
+
+ switch (engine_status_value) {
+ case VALUE_ENGINE_ID:
+ temp = "engine_id";
+ break;
+ case VALUE_ENGINE_STATUS:
+ temp = "engine_status";
+ break;
+ case VALUE_SERVER_ID:
+ temp = "server_id";
+ break;
+ case VALUE_SERVER_URL:
+ temp = "server_url";
+ break;
+ case VALUE_CORRELATOR:
+ temp = "correlator";
+ break;
+ case VALUE_MO_PATH:
+ temp = "mo_path";
+ break;
+ case VALUE_RESULT_STATUS:
+ temp = "result_status";
+ break;
+ case VALUE_UI_MODE:
+ temp = "ui_mode";
+ break;
+ case VALUE_TASK_ID:
+ temp = "task_id";
+ break;
+ case VALUE_UI_NOTI_TYPE:
+ temp = "ui_noti_type";
+ break;
+ case VALUE_DOWNLOAD_CLICK:
+ temp = "download_click";
+ break;
+ case VALUE_UPDATE_TIME:
+ temp = "update_time";
+ break;
+ default:
+ temp = 0;
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return temp;
+}
diff --git a/src/agent/common/dm-status/oma_dm_status_db_handler.c b/src/agent/common/dm-status/oma_dm_status_db_handler.c
new file mode 100755
index 0000000..378da1c
--- /dev/null
+++ b/src/agent/common/dm-status/oma_dm_status_db_handler.c
@@ -0,0 +1,638 @@
+/*
+ * 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.
+ */
+
+/*sync-agent*/
+#include <sync_agent.h>
+
+/*dm-agent*/
+#include "common/dm-status/oma_dm_status_db_handler.h"
+#include "common/dm-status/oma_dm_status_db.h"
+
+#ifndef OMADM_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DM_DB"
+#endif
+
+static db_handler_mgr *pDBHandlerMgr = 0;
+
+/* static function define */
+static DM_ERROR _add_agent_handler(unsigned int key, DB_HANDLER * pHandler);
+static DM_ERROR _remove_agent_handler(unsigned int key);
+static DB_HANDLER *_get_agent_handler(unsigned int key);
+static DM_ERROR __alloc_agent_dc_handlerTable();
+static DM_ERROR __alloc_agent_dc_handlerTable_mutex();
+static DM_ERROR _free_agent_dc_handlerTable();
+static DM_ERROR _free_agent_dc_handlerTable_mutex();
+static DM_ERROR _create_agentDBHandlerMgrInfo();
+static void ___destroy_agentDBHashTableValue(void *pHandler);
+static void ___destory_agentDBHashTableKey(void *key);
+
+/* test function define*/
+/*static void __print_agentDBHashTableLog();*/
+
+/* general function implementation */
+/*
+ * ==================================
+ * external API (1. about db handler mgr)
+ * ==================================
+ */
+DM_ERROR Alloc_DB_Handler_Mgr()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ /* alloc the agentDBHandlerMgr */
+ pDBHandlerMgr = (db_handler_mgr *) calloc(1, sizeof(db_handler_mgr));
+ if (pDBHandlerMgr == NULL) {
+ _DEBUG_INFO("alloc fail");
+ _EXTERN_FUNC_EXIT;
+ return COMMON_ERR_ALLOC;
+ }
+ _DEBUG_INFO("[%s] pMoDBHandlerMgr alloc success !\n", __func__);
+
+ /* alloc the agentDBHandlerMgr information */
+ ret = _create_agentDBHandlerMgrInfo();
+ if (ret != DM_OK)
+ _DEBUG_INFO("[%s] __create_agentDBHandlerMgrInfo alloc fail !\n", __func__);
+ else
+ _DEBUG_INFO("[%s] __create_agentDBHandlerMgrInfo alloc success !\n", __func__);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR Free_DB_Handler_Mgr()
+{
+ _EXTERN_FUNC_ENTER;
+ DM_ERROR ret = DM_OK;
+
+ if (pDBHandlerMgr != NULL) {
+
+ ret = _free_agent_dc_handlerTable_mutex();
+ if (ret != DM_OK) {
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ ret = _free_agent_dc_handlerTable();
+ if (ret != DM_OK) {
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+void Free_Memory_Engine_Status(engine_status ** status, int count)
+{
+ _EXTERN_FUNC_ENTER;
+ engine_status *temp_status = *status;
+
+ int i;
+ for (i = 0; i < count; i++) {
+ MEMORY_FREE(temp_status[i].server_id);
+ MEMORY_FREE(temp_status[i].server_url);
+ MEMORY_FREE(temp_status[i].correlator);
+ MEMORY_FREE(temp_status[i].ui_mode);
+ MEMORY_FREE(temp_status[i].mo_path);
+ }
+
+ MEMORY_FREE(temp_status);
+ *status = 0;
+ _EXTERN_FUNC_EXIT;
+}
+
+/*
+ * ==================================
+ * external API (2. about agent db )
+ * ==================================
+ */
+DM_ERROR DB_Open()
+{
+ _EXTERN_FUNC_ENTER;
+ int ret = 0;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+
+ _DEBUG_INFO("db_handler is 0");
+ _DEBUG_INFO("should register db_handler to db_handler_hash_table");
+ ret = dm_open_agent(&db_handler);
+ if (ret != DM_OK) {
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ }
+
+ if (db_handler != NULL) {
+ /* add agentDB handler to agentDBHandleMgr */
+ ret = _add_agent_handler(GET_THREAD_ID, db_handler);
+ if (ret != DM_OK) {
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ }
+ }
+ } else {
+ _DEBUG_INFO("db_handler is not null");
+ _DEBUG_INFO("should not register db_handler to db_handler_hash_table");
+ }
+
+ _DEBUG_INFO("agent_db_agent_open_success");
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+}
+
+void DB_Close()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler != NULL) {
+
+ /* remove agentDB handler to agentDBHandleMgr */
+ ret = _remove_agent_handler(GET_THREAD_ID);
+ if (ret != DM_OK) {
+ _DEBUG_INFO("agent_db_agent_close_fail");
+ _EXTERN_FUNC_EXIT;
+ return;
+ }
+ _DEBUG_INFO("agent_db_agent_close_success");
+ }
+ _EXTERN_FUNC_EXIT;
+}
+
+DM_ERROR DB_Create_Table()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_create_table(db_handler);
+}
+
+DM_ERROR DB_Delete_Table()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_delete_table(db_handler);
+}
+
+DM_ERROR DB_Reset_Table()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_reset_table(db_handler);
+}
+
+DM_ERROR DB_Begin_Transaction()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_begin_transaction(db_handler);
+}
+
+DM_ERROR DB_End_Transaction(DB_TRANSACTION transaction)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_end_transaction(db_handler, transaction);
+}
+
+DM_ERROR Init_Engine_Status()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_init_engine_status(db_handler);
+}
+
+DM_ERROR Add_Engine_Status(engine_status * status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_add_engine_status(db_handler, status);
+}
+
+DM_ERROR Delete_Engine_Status(int engine_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return dm_delete_engine_status(db_handler, engine_id);
+}
+
+DM_ERROR Update_Engine_Status(engine_status * status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retvm_if(status == NULL, DM_ERR_UNKNOWN, "engine status is NULL !!");
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ int ret = dm_isExist_engine_id(db_handler, status->engine_id);
+ if (ret == 0) {
+ _EXTERN_FUNC_EXIT;
+ return dm_add_engine_status(db_handler, status);
+ } else {
+ _EXTERN_FUNC_EXIT;
+ return dm_update_engine_status(db_handler, status);
+ }
+}
+
+DM_ERROR Update_Engine_Status_Column(int engine_id, ENGINE_STATUS_VALUE engine_status_value, void *value)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_update_engine_status_column(db_handler, engine_id, engine_status_value, value);
+}
+
+DM_ERROR Get_Engine_Status(int engine_id, engine_status ** status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _EXTERN_FUNC_EXIT;
+ return dm_get_engine_status(db_handler, engine_id, status);
+}
+
+DM_ERROR Get_AII_Engine_Status(engine_status ** status_list, int *count)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return dm_get_aII_engine_status(db_handler, status_list, count);
+}
+
+int IsExist_Engine_id(int engine_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DB_HANDLER *db_handler = _get_agent_handler(GET_THREAD_ID);
+ if (db_handler == NULL) {
+ _DEBUG_INFO("[%s] no handler for key\n", __func__);
+ _EXTERN_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ _EXTERN_FUNC_EXIT;
+
+ return dm_isExist_engine_id(db_handler, engine_id);
+}
+
+/*
+ * ==================================
+ * DB module internal API
+ * ==================================
+ */
+DM_ERROR _add_agent_handler(unsigned int key, DB_HANDLER * pHandler)
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr == NULL || pDBHandlerMgr->db_handlerTable_mutex == NULL) {
+ return DM_ERR_UNKNOWN;
+ }
+
+ DM_ERROR ret = DM_OK;
+
+ unsigned int *pKey_copy = (unsigned int *)calloc(1, sizeof(unsigned int));
+ if (pKey_copy == NULL) {
+ _INNER_FUNC_EXIT;
+ return COMMON_ERR_ALLOC;
+ }
+
+ *pKey_copy = key;
+
+ pthread_mutex_lock(pDBHandlerMgr->db_handlerTable_mutex);
+ if (pDBHandlerMgr->db_handlerTable == NULL) {
+ ret = __alloc_agent_dc_handlerTable();
+ if (ret != DM_OK)
+ goto addagentHandler;
+ }
+
+ /* insert to handler */
+ _DEBUG_TRACE("[%s] Key = %d, Handler = %p !\n", __func__, key, pHandler);
+ g_hash_table_insert(pDBHandlerMgr->db_handlerTable, pKey_copy, pHandler);
+
+#ifdef DC_PRINT
+ /* For test log */
+ __print_agentDBHashTableLog();
+#endif
+ pthread_mutex_unlock(pDBHandlerMgr->db_handlerTable_mutex);
+ if(pKey_copy != NULL) {
+ free(pKey_copy);
+ }
+ _INNER_FUNC_EXIT;
+ return ret;
+
+ addagentHandler:
+ pthread_mutex_unlock(pDBHandlerMgr->db_handlerTable_mutex);
+ if(pKey_copy != NULL) {
+ free(pKey_copy);
+ }
+ _INNER_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR _remove_agent_handler(unsigned int key)
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr == NULL || pDBHandlerMgr->db_handlerTable_mutex == NULL || pDBHandlerMgr->db_handlerTable == NULL) {
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+
+ /* remove the handler to hash table */
+ pthread_mutex_lock(pDBHandlerMgr->db_handlerTable_mutex);
+ int isSuccess = g_hash_table_remove(pDBHandlerMgr->db_handlerTable, &key);
+ pthread_mutex_unlock(pDBHandlerMgr->db_handlerTable_mutex);
+
+#ifdef DC_PRINT
+ /* for test log */
+ __print_agentDBHashTableLog();
+#endif
+
+ _DEBUG_TRACE("[%s] end !\n", __func__);
+ if (isSuccess == 1) {
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return DM_ERR_UNKNOWN;
+}
+
+DB_HANDLER *_get_agent_handler(unsigned int key)
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr == NULL || pDBHandlerMgr->db_handlerTable_mutex == NULL || pDBHandlerMgr->db_handlerTable == NULL) {
+ _DEBUG_TRACE("[%s] DM_ERR_UNKNOWN !\n", __func__);
+ _INNER_FUNC_EXIT;
+
+ return 0;
+ }
+
+ /* get the handler to hash table */
+ pthread_mutex_lock(pDBHandlerMgr->db_handlerTable_mutex);
+ DB_HANDLER *pHandler = g_hash_table_lookup(pDBHandlerMgr->db_handlerTable, &key);
+ pthread_mutex_unlock(pDBHandlerMgr->db_handlerTable_mutex);
+
+#ifdef DC_PRINT
+ if (pHandler != NULL) {
+ _DEBUG_TRACE("[%s] ######### > Value Search Success(key = %d, handler = %p)\n", __func__, key, pHandler);
+ } else {
+ _DEBUG_TRACE("[%s] ######### > Value Search Fail(key = %d, handler = %p)\n", __func__, key, pHandler);
+ }
+#endif
+ _INNER_FUNC_EXIT;
+
+ return pHandler;
+}
+
+/* static function implementation */
+static DM_ERROR __alloc_agent_dc_handlerTable()
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr != NULL) {
+ pDBHandlerMgr->db_handlerTable = g_hash_table_new_full(g_int_hash, g_int_equal, ___destory_agentDBHashTableKey, ___destroy_agentDBHashTableValue);
+ if (pDBHandlerMgr->db_handlerTable == NULL) {
+ _DEBUG_TRACE("[%s] Not Create agent dc handler hash table \n", __func__);
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ } else {
+ _DEBUG_TRACE("[%s] create agent dc handler hash table \n", __func__);
+ }
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+static DM_ERROR __alloc_agent_dc_handlerTable_mutex()
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr != NULL) {
+
+ pDBHandlerMgr->db_handlerTable_mutex = (pthread_mutex_t *) calloc(1, sizeof(pthread_mutex_t));
+ if (pDBHandlerMgr->db_handlerTable_mutex == NULL) {
+ _DEBUG_TRACE("[%s] Not Create agent dc handler hash table mutex \n", __func__);
+ _INNER_FUNC_EXIT;
+ return COMMON_ERR_ALLOC;
+ } else {
+
+ if (pthread_mutex_init(pDBHandlerMgr->db_handlerTable_mutex, 0) != 0) {
+ _DEBUG_TRACE("[%s] Not init agent dc handler hash table mutex\n", __func__);
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+ }
+ _DEBUG_TRACE("[%s] Init agent dc handler hash table mutex\n", __func__);
+ }
+ }
+
+ _INNER_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+static DM_ERROR _free_agent_dc_handlerTable()
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr != NULL && pDBHandlerMgr->db_handlerTable != NULL) {
+ g_hash_table_destroy(pDBHandlerMgr->db_handlerTable);
+ _DEBUG_TRACE("[%s] db_handlerTable free success !\n", __func__);
+ pDBHandlerMgr->db_handlerTable = 0;;
+ }
+ _INNER_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+static DM_ERROR _free_agent_dc_handlerTable_mutex()
+{
+ _INNER_FUNC_ENTER;
+
+ if (pDBHandlerMgr != NULL && pDBHandlerMgr->db_handlerTable_mutex != NULL) {
+
+ int ret = pthread_mutex_destroy(pDBHandlerMgr->db_handlerTable_mutex);
+ if (ret != 0) {
+ _DEBUG_TRACE("[%s] db_handlerTable_mutex free error !\n", __func__);
+ return DM_ERR_UNKNOWN;
+ } else {
+ free(pDBHandlerMgr->db_handlerTable_mutex);
+ pDBHandlerMgr->db_handlerTable_mutex = 0;
+ _DEBUG_TRACE("[%s] db_handlerTable_mutex free success !\n", __func__);
+ }
+ }
+ _INNER_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+static DM_ERROR _create_agentDBHandlerMgrInfo()
+{
+ _INNER_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ if (pDBHandlerMgr != NULL) {
+
+ /* alloc agent db hander hash table */
+ ret = __alloc_agent_dc_handlerTable();
+ if (ret != DM_OK)
+ goto allocAgentDBHandlerMgrInfoErr;
+
+ /* alloc agent db hander hash table mutex */
+ ret = __alloc_agent_dc_handlerTable_mutex();
+ if (ret != DM_OK)
+ goto allocAgentDBHandlerMgrInfoErr;
+ }
+ _INNER_FUNC_EXIT;
+
+ return DM_OK;
+
+ allocAgentDBHandlerMgrInfoErr:
+ Free_DB_Handler_Mgr();
+
+ _INNER_FUNC_EXIT;
+ return DM_ERR_UNKNOWN;
+}
+
+static void ___destroy_agentDBHashTableValue(void *pHandler)
+{
+ _INNER_FUNC_ENTER;
+
+ _DEBUG_VERBOSE("[%s] start \n", __func__);
+ if ((DB_HANDLER *) pHandler != 0) {
+ dm_close_agent((DB_HANDLER *) pHandler);
+ }
+
+ _INNER_FUNC_EXIT;
+}
+
+static void ___destory_agentDBHashTableKey(void *key)
+{
+ _INNER_FUNC_ENTER;
+
+ _DEBUG_VERBOSE("[%s] start \n", __func__);
+ if ((unsigned int *)key != 0) {
+ free((unsigned int *)key);
+ }
+ _INNER_FUNC_EXIT;
+
+}
+
+/*
+static void __print_agentDBHashTableLog()
+{
+ _DEBUG_VERBOSE("[%s] ---------HashKeyList --------\n", __func__);
+ int size = g_hash_table_size(pDBHandlerMgr->db_handlerTable);
+ _DEBUG_VERBOSE("[%s] pDBHandlerMgr->db_handlerTable Size is %d\n", __func__, size);
+ _DEBUG_VERBOSE("[%s] ----------------------------------------\n", __func__);
+ GList *iter = 0;
+ GList *keyList = g_hash_table_get_keys(pDBHandlerMgr->db_handlerTable);
+ for (iter = keyList; iter != 0; iter = g_list_next(iter))
+ _DEBUG_VERBOSE("[%s] Handler Key %d\n", __func__, *((unsigned int *)(iter->data)));
+ _DEBUG_VERBOSE("[%s] ----------------------------------------\n", __func__);
+}
+*/
diff --git a/src/agent/common/dm_common.c b/src/agent/common/dm_common.c
new file mode 100755
index 0000000..029c0bd
--- /dev/null
+++ b/src/agent/common/dm_common.c
@@ -0,0 +1,1480 @@
+/*
+ * 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.
+ */
+
+#include <unistd.h>
+
+/*lib*/
+#include <vconf.h>
+#include <vconf-keys.h>
+
+/*sync-agent*/
+#include <sync_agent.h>
+#include <plugin/plugin_slp_sysnoti_alarm.h>
+
+/*dm-agent*/
+#include "framework/platform-event-handler/dm_platform_event_handler.h"
+#include "framework/platform-event-handler/dm_platform_event_handler_internal.h"
+#include "framework/task/oma_dm_task_register.h"
+#include "framework/task/oma_dm_task_request.h"
+#include "common/dm_common.h"
+#include "common/util/util.h"
+#include "mo-handler/dm_mo_common.h"
+#include "mo-handler/dm_mo_handler.h"
+#include "dm-engine/bootstrap/factory_bootstrap.h"
+#include "dm-engine/fumo/fumo_account.h"
+#include "dm-engine/lawmo/lawmo_account.h"
+#include "dm-engine/cp/dm_cp_security.h"
+#include "ipc_common.h"
+
+#ifndef OMADM_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "DM_COMMON"
+#endif
+
+#define MAX_TRY 3
+
+static DM_ERROR _create_engine_status_db();
+
+char *get_new_uri(char *old_object_uri)
+{
+ _EXTERN_FUNC_ENTER;
+
+ char *new_object_uri = NULL;
+ retvm_if(old_object_uri == NULL, NULL, "old_object_uri is NULL!!");
+ _DEBUG_INFO(" old_object_uri = %s ", old_object_uri);
+ new_object_uri = g_strdup_printf("%s", old_object_uri);
+
+ _EXTERN_FUNC_EXIT;
+ return new_object_uri;
+}
+
+static DM_ERROR _create_engine_status_db()
+{
+ _INNER_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ ret = Alloc_DB_Handler_Mgr();
+ _DEBUG_TRACE(" Alloc DB Handler Mgr : %d\n", ret);
+
+ ret = DB_Open();
+ _DEBUG_TRACE(" Done Open DB : %d\n", ret);
+
+ ret = DB_Create_Table();
+ _DEBUG_TRACE(" Done Create_Table : %d\n", ret);
+
+ _INNER_FUNC_EXIT;
+ return ret;
+
+}
+
+DM_ERROR init_dm()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ ret = _create_engine_status_db();
+ _DEBUG_INFO(" Done Create_engine_status_db : %d\n", ret);
+
+ ret = task_register();
+ if (ret != DM_OK) {
+ goto error;
+ }
+ /* will delete */
+ ret = register_scheduler();
+ if (ret == -1) {
+ _DEBUG_INFO("fail register alarm : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register alarm : %d ", ret);
+ }
+
+ ret = register_network();
+ if (ret == -1) {
+ _DEBUG_INFO("fail register network : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register network : %d ", ret);
+ }
+
+ ret = register_wap_push();
+ if (ret == -1) {
+ _DEBUG_INFO("fail register wap push : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register wap push : %d ", ret);
+ }
+
+ ret = register_fumo_ip_push();
+ if (ret == -1) {
+ _DEBUG_INFO("fail register fumo ip push : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register fumo ip push : %d ", ret);
+
+ /*todo temp code
+ * will integrate notification UI */
+ /*ret = register_fota_account();
+
+ if (ret == -1) {
+ _DEBUG_INFO("fail register fota account : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register fota account : %d ", ret);
+ } */
+ }
+
+ ret = register_lawmo_samsung_account();
+ if (ret == -1) {
+ _DEBUG_INFO("fail register fmm server : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register fmm server : %d ", ret);
+ }
+
+ ret = register_telephony();
+ if (ret == -1) {
+ _DEBUG_INFO("fail register telephony : %d ", ret);
+ } else {
+ _DEBUG_INFO("success register telephony : %d ", ret);
+ }
+
+ init_default_fumo_config();
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ error:
+ _EXTERN_FUNC_EXIT;
+ _DEBUG_INFO(" end error : %d \n", ret);
+ return ret;
+}
+
+DM_ERROR end_dm()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+DM_ERROR reset_dm()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ _DEBUG_INFO("--------------------------------------------------------------------------------------------");
+ /* ddf mo db reset */
+ ret = clean_dm_mo();
+ if (ret != DM_OK)
+ goto error;
+
+ /* engine status db reset */
+ //ret = DB_Delete_Table();
+ ret = DB_Reset_Table();
+ if (ret != DM_OK)
+ goto error;
+
+ /* omadm db */
+ sync_agent_empty_agent_default_table(SYNC_AGENT_DA_TABLE_NAME_CONFIG);
+ //sync_agent_empty_all_agent_table()
+
+ /*fumo, lawmo data in alarm db */
+ _DEBUG_INFO("--------------------------------------------------------------------------------------------");
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+
+ error:
+ _EXTERN_FUNC_EXIT;
+ _DEBUG_INFO(" end error : %d \n", ret);
+ return ret;
+}
+
+DM_ERROR auto_operate_service_engine()
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ engine_status *status = NULL;
+
+ if (IsExist_Engine_id(FUMO_SERVICE_ENGINE) != 0) {
+ printf("engine id VALUE : %d ", FUMO_SERVICE_ENGINE);
+ _DEBUG_INFO("engine id VALUE : %d ", FUMO_SERVICE_ENGINE);
+
+ ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
+ if (ret != DM_OK || status == NULL)
+ goto error;
+
+ if (status->engine_status == 0) {
+ ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
+ if (ret != DM_OK)
+ goto error;
+ } else {
+ ret = fumo_serviceEngine_task_request();
+ _DEBUG_INFO("fumo server engine task request : %d", ret);
+ }
+ if (status != NULL) {
+ Free_Memory_Engine_Status(&status, 1);
+ }
+ }
+
+ if (IsExist_Engine_id(LAWMO_SERVICE_ENGINE) != 0) {
+ printf("engine id VALUE : %d ", LAWMO_SERVICE_ENGINE);
+ _DEBUG_INFO("engine id VALUE : %d ", LAWMO_SERVICE_ENGINE);
+
+ ret = Get_Engine_Status(LAWMO_SERVICE_ENGINE, &status);
+ if (ret != DM_OK || status == NULL)
+ goto error;
+
+ if (status->engine_status == 0) {
+ ret = Delete_Engine_Status(LAWMO_SERVICE_ENGINE);
+ if (ret != DM_OK)
+ goto error;
+ } else {
+ ret = lawmo_serviceEngine_task_request();
+ }
+ if (status != NULL)
+ Free_Memory_Engine_Status(&status, 1);
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ error:
+
+ if (status != NULL)
+ Free_Memory_Engine_Status(&status, 1);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int register_wap_push()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 1;
+ int i = 0;
+
+ for (i = 0; i < MAX_TRY; ++i) {
+ sync_agent_pm_return_e err_wappush = sync_agnet_register_user_callback(6, NULL, 2, dm_wap_push_incomming_callback, dm_wap_push_operation_callback);
+
+ if (err_wappush != SYNC_AGENT_PM_SUCCESS) {
+ _DEBUG_INFO("failed set_WAP-PUSH_Callback()");
+ ret = -1;
+ sleep(1);
+ } else {
+ _DEBUG_INFO("WAP-PUSH SUCCESS");
+ break;
+ }
+ }
+ _EXTERN_FUNC_EXIT;
+
+ return ret;
+}
+
+int register_fumo_ip_push()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 1;
+ int i = 0;
+
+ for (i = 0; i < MAX_TRY; ++i) {
+ sync_agent_pm_return_e err_ippush = sync_agnet_register_user_callback(2, NULL, 1, dm_ip_push_callback);
+ if (err_ippush != SYNC_AGENT_PM_SUCCESS) {
+// if (err_ippush == PMCI_CONNECTION_FAIL) {
+// _DEBUG_INFO("failed set_IP-PUSH_Callback() : connection failed !!");
+//
+// } else if (err_ippush == PMCI_REGISTRATION_FAIL) {
+// _DEBUG_INFO("failed set_IP-PUSH_Callback() : registration failed !!");
+// } else {
+ _DEBUG_INFO("failed set_IP-PUSH_Callback()");
+// }
+
+ sleep(1);
+ ret = -1;
+ } else {
+ _DEBUG_INFO("IP-PUSH SUCCESS");
+ ret = 1;
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int register_lawmo_samsung_account()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 1;
+ int i = 0;
+
+ for (i = 0; i < MAX_TRY; ++i) {
+ sync_agent_pm_return_e err_samsung_account = sync_agnet_register_user_callback(4, NULL, 2, register_lawmo_account, deregister_lawmo_account);
+ if (err_samsung_account != SYNC_AGENT_PM_SUCCESS) {
+// if (err_samsung_account == PMCI_CONNECTION_FAIL) {
+// _DEBUG_INFO("failed set_SAMSUNG_ACCOUNT_Callback() : connection failed !!");
+//
+// } else if (err_samsung_account == PMCI_REGISTRATION_FAIL) {
+// _DEBUG_INFO("failed set_SAMSUNG_ACCOUNT_Callback() : registration failed !!");
+// } else {
+ _DEBUG_INFO("failed set_SAMSUNG_ACCOUNT_Callback()");
+// }
+
+ sleep(1);
+ ret = -1;
+ } else {
+ _DEBUG_INFO("SAMSUNG_ACCOUNT SUCCESS");
+ ret = 1;
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int register_telephony()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 1;
+ int i = 0;
+
+ for (i = 0; i < MAX_TRY; ++i) {
+ sync_agent_pm_return_e err_telephony = sync_agnet_register_user_callback(5, NULL, 2, dm_telephony_incomming_callback, dm_telephony_end_callback);
+ if (err_telephony != SYNC_AGENT_PM_SUCCESS) {
+ _DEBUG_INFO("failed set_TELEPHONY_Callback()");
+
+ ret = -1;
+ sleep(1);
+ } else {
+ _DEBUG_INFO("TELEPHONY_SUCCESS");
+ ret = 1;
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int register_network()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 1;
+ int i = 0;
+
+ for (i = 0; i < MAX_TRY; ++i) {
+ sync_agent_pm_return_e err_network = sync_agnet_register_user_callback(3, NULL, 2, network_on_callback, network_off_callback, network_change_callback);
+ if (err_network != SYNC_AGENT_PM_SUCCESS) {
+ _DEBUG_INFO("failed set_network_Callback()");
+ ret = -1;
+ sleep(1);
+ } else {
+ _DEBUG_INFO("NETWORK_SUCCESS");
+ ret = 1;
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int register_scheduler()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ int i = 0;
+
+ for (i = 0; i < MAX_TRY; ++i) {
+ sync_agent_pm_return_e err_alarm = sync_agnet_register_user_callback(1, NULL, 1, alarm_callback);
+ if (err_alarm != SYNC_AGENT_PM_SUCCESS) {
+ _DEBUG_INFO("Fail PMCI_Init_Specific_Type\n");
+ ret = -1;
+ sleep(1);
+ } else {
+ _DEBUG_INFO("Success PMCI_Init_Specific_Type\n");
+ ret = 1;
+ break;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+void network_cancel_callback(void *user_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int *net_session_id = (int *)(user_data);
+ sync_agent_na_result_e error;
+ error = sync_agent_cancel_msg(1, (*net_session_id));
+ _DEBUG_INFO("naci cancel msg status : %d\n", error);
+
+ _EXTERN_FUNC_EXIT;
+}
+
+void network_connection_delay()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int network_status = 0;
+ int interval = 1; //(seconds)
+ int retry_cnt = 3;
+
+ char file_name[256] = { 0, };
+ char *net_status;
+ int snd_size;
+ FILE *send_fp = NULL;
+ _DEBUG_INFO("start");
+ sleep(2);
+
+ network_status = sync_agent_check_network_status(interval, retry_cnt);
+
+ net_status = g_strdup_printf("%d", network_status);
+ snprintf(file_name, 256, "%s", "/opt/data/network_connect_status.txt");
+ send_fp = fopen(file_name, "w");
+ if (send_fp != NULL) {
+ snd_size = fwrite(net_status, strlen(net_status), 1, send_fp);
+ fclose(send_fp);
+ } else {
+ _DEBUG_INFO("fopen - network_connect_status - fail");
+ }
+
+ if (network_status != 1) {
+ _DEBUG_INFO("------------------------------------------NETOWKR CONNECT FAIL------------------------------------------");
+ }
+
+ _EXTERN_FUNC_EXIT;
+}
+
+DM_ERROR set_account_registration_alarm(char *alarm_str, CONFIG_TYPE alarm_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS;
+
+ int count = 0;
+ GList *list = NULL;
+
+ result = sync_agent_get_config_list(alarm_type, &list);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _EXTERN_FUNC_EXIT;
+ return COMMON_ERR_FW_CONFIG;
+ }
+
+ count = g_list_length(list);
+
+ _DEBUG_INFO("alarm count: %d\n", count);
+ if (count > 0 && list != NULL) {
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ } else {
+ ret = add_alarm_item(INTERVAL_1DAY, alarm_str, alarm_type);
+ if (ret != DM_OK)
+ goto error;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+
+ error:
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+void delete_account_registration_alarm(char *alarm_str, CONFIG_TYPE alarm_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ delete_alarm_item(alarm_str, alarm_type);
+
+ _EXTERN_FUNC_EXIT;
+}
+
+DM_ERROR add_alarm_item(Reminder_Interval interval, char *alarm_type, CONFIG_TYPE conf_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ /*int week[] = {DAY_SUN, DAY_MON, DAY_TUE, DAY_WED, DAY_THU, DAY_FRI, DAY_SAT}; */
+
+ time_t current_time;
+ struct tm *struct_time;
+ time(&current_time);
+ struct_time = localtime(&current_time);
+
+ pmci_alarm_s *alarm_info = (pmci_alarm_s *) calloc(1, sizeof(pmci_alarm_s));
+ if (alarm_info == NULL) {
+ _DEBUG_INFO("alloc fail");
+ _EXTERN_FUNC_EXIT;
+ return COMMON_ERR_ALLOC;
+ }
+
+ alarm_info->start_alarm_time = g_strdup_printf("%02d-%02d-%02dT%02d:%02d:%02dZ", struct_time->tm_year + 1900, struct_time->tm_mon + 1, struct_time->tm_mday, struct_time->tm_hour, struct_time->tm_min, struct_time->tm_sec);
+
+ //REALE
+ alarm_info->is_disposable = 0;
+
+ // TEST
+ //alarm_info->is_disposable = 1;
+
+ switch (interval) {
+ /*
+ case INTERVAL_NONE :
+ {
+ // 1minute
+ alarm_info->repeat_type = REPEAT ;
+ //alarm_info->repeat_value = ((1*60)*60);
+ alarm_info->repeat_value = ((1*60)*1);
+ }
+ break;
+ */
+ case INTERVAL_1HOUR:
+ {
+ /* 1 hour */
+ alarm_info->repeat_type = REPEAT;
+ alarm_info->repeat_value = ((1 * 60) * 60);
+ //alarm_info->repeat_value = ((1*60)*1);
+ }
+ break;
+ case INTERVAL_3HOURS:
+ {
+ /* 4 hour */
+ alarm_info->repeat_type = REPEAT;
+ alarm_info->repeat_value = ((3 * 60) * 60);
+ }
+ break;
+ case INTERVAL_6HOURS:
+ {
+ /* 6 hour */
+ alarm_info->repeat_type = REPEAT;
+ alarm_info->repeat_value = ((6 * 60) * 60);
+
+ }
+ break;
+ case INTERVAL_12HOURS:
+ {
+ /* 12 hour */
+ alarm_info->repeat_type = REPEAT;
+ alarm_info->repeat_value = ((12 * 60) * 60);
+
+ }
+ break;
+ case INTERVAL_1DAY:
+ {
+ /* 1 day */
+ alarm_info->repeat_type = REPEAT;
+ alarm_info->repeat_value = ((24 * 60) * 60);
+ }
+ break;
+ /*
+ case INTERVAL_7DAYS:
+ {
+ // 1 week
+ alarm_info->repeat_type = REPEAT_WEEKLY ;
+ alarm_info->repeat_value = week[struct_time->tm_wday];
+ }
+ break;
+ */
+ case INTERVAL_1MONTH:
+ {
+ alarm_info->repeat_type = REPEAT_MONTHLY;
+ alarm_info->repeat_value = 0;
+ }
+ case INTERVAL_CANCEL:
+ goto return_part;
+ break;
+ default:
+ break;
+ }
+
+ _DEBUG_INFO("######### Alarm Info #####################\n");
+ _DEBUG_INFO("time = %s\n", alarm_info->start_alarm_time);
+ _DEBUG_INFO("repeat_mode = %d, repeat_value = %d\n", alarm_info->repeat_type, alarm_info->repeat_value);
+ _DEBUG_INFO("is_disposable = %d\n", alarm_info->is_disposable);
+
+/* if(conf_type == FUMO_INTERVAL_TYPE)
+ delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);*/
+
+ int alarm_id = 0;
+ int alarm_ret = 0;
+ sync_agent_pm_return_e err = SYNC_AGENT_PM_SUCCESS;
+
+ /*add alarm service */
+ err = sync_agent_add_service_data(1, alarm_info, &alarm_id);
+ if (err != SYNC_AGENT_PM_SUCCESS) {
+ _DEBUG_INFO("Fail PMCI_Add_Item_To_Specific_Type\n");
+ ret = DM_ERR_FUMO_INTERNAL_SCHEDULER_ERROR;
+ } else {
+ /*add framework config db */
+ alarm_ret = set_alarm_config_int(conf_type, alarm_type, alarm_id, alarm_type);
+ if (alarm_ret == 0) {
+ ret = DM_ERR_FUMO_INTERNAL_SCHEDULER_ERROR;
+ }
+ }
+
+ if (alarm_info != NULL) {
+ str_free(&(alarm_info->start_alarm_time));
+ free(alarm_info);
+ alarm_info = NULL;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+
+ return_part:
+
+ if (alarm_info != NULL) {
+ str_free(&(alarm_info->start_alarm_time));
+ free(alarm_info);
+ alarm_info = NULL;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ _DEBUG_INFO("end error : %d ", ret);
+ return ret;
+}
+
+void delete_alarm_item(char *alarm_type, CONFIG_TYPE conf_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int count = 0;
+ int before_alarm_id;
+ int ret = 0;
+ sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS;
+ sync_agent_pm_return_e pm_result = SYNC_AGENT_PM_SUCCESS;
+
+ sync_agent_da_config_s *config = NULL;
+
+ GList *list = NULL;
+
+ result = sync_agent_get_config_list(conf_type, &list);
+ count = g_list_length(list);
+
+ _DEBUG_INFO("alarm count: %d\n", count);
+ if (count > 0 && list != 0) {
+ config = (sync_agent_da_config_s *) g_list_nth_data(list, 0);
+ _DEBUG_INFO("------------------------------------------alarm id : %s----------------------------------------------\n", config->value);
+ ret = chartoint(config->value, &before_alarm_id);
+ if (ret == 1) {
+ pm_result = sync_agent_remove_service_data(1, before_alarm_id);
+ _DEBUG_INFO("delete alarm %d", result);
+
+ if (pm_result == SYNC_AGENT_PM_SUCCESS) {
+ result = sync_agent_delete_config(conf_type, alarm_type);
+ _DEBUG_INFO("delete alarm config %d", result);
+ }
+ } else {
+ _DEBUG_INFO("fail get alarm id");
+ }
+ }
+
+ sync_agent_free_config_list(list);
+ _EXTERN_FUNC_EXIT;
+
+}
+
+SERVICE_SERVER_TYPE get_service_engine_type(const char *server_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retvm_if(server_id == NULL, NO_ENGINE_TYPE, "server_id is NULL!!");
+
+ _DEBUG_INFO("get- service engine type by server id : %s", server_id);
+ _EXTERN_FUNC_EXIT;
+ return get_engine_type_by_serverid(server_id);
+}
+
+DM_ERROR get_server_info(Event_Contents * pEvent_data, char **server_id, char **session_id, int *session_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if((pEvent_data) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "pEvent_data is NULL!!");
+ retvm_if((pEvent_data->server_id) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "server_id is NULL!!");
+
+ (*server_id) = strdup(pEvent_data->server_id);
+ _DEBUG_INFO(" server id : %s\n", *server_id);
+
+ if (pEvent_data->session_id != NULL) {
+ (*session_id) = strdup(pEvent_data->session_id);
+ _DEBUG_INFO(" session_id : %s\n", *session_id);
+ }
+
+ (*session_type) = pEvent_data->type;
+ _DEBUG_INFO("session type : %d\n", *session_type);
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+void get_service_engine_id(ENGINE_ID * service_engine_id, char *ui_mode)
+{
+ _EXTERN_FUNC_ENTER;
+
+ if (ui_mode == NULL)
+ return;
+
+ if (!strcmp(ui_mode, OMADM_FUMO_UI_TYPE) || !strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE)) {
+ *service_engine_id = FUMO_SERVICE_ENGINE;
+ _DEBUG_INFO("fumo service");
+ } else {
+ _DEBUG_INFO("other service");
+ }
+
+ _EXTERN_FUNC_EXIT;
+}
+
+DM_ERROR fumo_service_start(Event_Contents * pEvent_data)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ retvm_if((pEvent_data) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "pEvent_data is NULL!!");
+
+ switch (pEvent_data->noti_type) {
+ case NOTI_TYPE_NOT_SPECIFIED:
+ _DEBUG_INFO("NOTI_TYPE_NOT_SPECIFIED");
+ //temp version for gcf test
+ pEvent_data->ui_mode = strdup(OMADM_FUMO_BACKGROUND_UI_TYPE);
+ pEvent_data->noti_type = NOTI_TYPE_BACKGRUOUND;
+ ret = dm_fumo_common_task_request(pEvent_data);
+ _DEBUG_INFO("NOTI NOTI_TYPE_BACKGRUOUND : %d", ret);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ break;
+ case NOTI_TYPE_BACKGRUOUND:
+ pEvent_data->ui_mode = strdup(OMADM_FUMO_BACKGROUND_UI_TYPE);
+ ret = dm_fumo_common_task_request(pEvent_data);
+ _DEBUG_INFO("NOTI NOTI_TYPE_BACKGRUOUND : %d", ret);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ break;
+ case NOTI_TYPE_INFOMATIVE:
+ pEvent_data->ui_mode = strdup(OMADM_FUMO_BACKGROUND_UI_TYPE);
+ ret = dm_fumo_common_task_request(pEvent_data);
+ _DEBUG_INFO("NOTI NOTI_TYPE_INFOMATIVE : %d", ret);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ break;
+ case NOTI_TYPE_USERINTERACTION:
+ pEvent_data->ui_mode = strdup(OMADM_FUMO_NOTI_UI_TYPE);
+ ret = dm_fumo_ui_task_request(pEvent_data);
+ _DEBUG_INFO("NOTI NOTI_TYPE_USERINTERACTION : %d ", ret);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ break;
+ default:
+ break;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+ error:
+ event_data_free((void *)pEvent_data);
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+
+}
+
+DM_ERROR get_fumo_ui_mode(char **ui_mode)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ engine_status *status = NULL;
+ ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
+ if (ret != DM_OK) {
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ }
+
+ if (status != NULL) {
+
+ if (status->ui_mode != NULL) {
+ (*ui_mode) = strdup(status->ui_mode);
+
+ _DEBUG_INFO("==================Fumo ui : %s==================\n", *ui_mode);
+ } else {
+ _DEBUG_INFO("ui mode null");
+ }
+
+ Free_Memory_Engine_Status(&status, 1);
+
+ } else {
+ _DEBUG_INFO("status is null");
+ }
+
+ _DEBUG_INFO("end");
+ _EXTERN_FUNC_EXIT;
+ return ret;
+
+}
+
+int check_existed_fumo_reminder_interval()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int exist = 0;
+ sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS;
+ result = sync_agent_is_exist_config(FUMO_INTERVAL_TYPE, FUMO_INTERVAL, &exist);
+ _DEBUG_INFO("agent is exist result : %d", result);
+
+ _EXTERN_FUNC_EXIT;
+ return exist;
+}
+
+int init_default_fumo_config()
+{
+ _EXTERN_FUNC_ENTER;
+
+ _EXTERN_FUNC_EXIT;
+ return set_config_int(FUMO_WIFI_ONLY_TYPE, FUMO_WIFI_ONLY_CONFIG, 0, FUMO, 1);
+}
+
+int set_config_int(CONFIG_TYPE config_type, char *key, int value, char *accessName, int isFirst)
+{
+ _EXTERN_FUNC_ENTER;
+ int ret = 1;
+ sync_agent_da_return_e result;
+ sync_agent_da_config_s config;
+ int exist = 0;
+
+ config.access_name = accessName;
+ config.config_id = config_type;
+ config.key = key;
+ config.value = g_strdup_printf("%d", value);
+ config.type = "int";
+
+ result = sync_agent_is_exist_config(config_type, key, &exist);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _DEBUG_INFO("exist config fail : %d", result);
+ ret = -1;
+ } else {
+ if (exist == 0 && isFirst == 1) {
+ _DEBUG_INFO("default add config : %s\n", key);
+ result = sync_agent_add_config(&config);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _DEBUG_INFO("fail add : %d", result);
+ ret = -1;
+ } else {
+ _DEBUG_INFO("Success add config : %s, : %d\n", key, value);
+ }
+ } else {
+ result = sync_agent_update_config(&config);
+ //free config
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _DEBUG_INFO("fail update : %d", result);
+ ret = -1;
+ } else {
+ _DEBUG_INFO("Success update config : %s, : %d\n", key, value);
+ }
+ }
+ }
+
+ str_free(&(config.value));
+ _EXTERN_FUNC_EXIT;
+
+ return ret;
+}
+
+int get_config_int(CONFIG_TYPE config_id, char *key)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS;
+ sync_agent_da_config_s *config = NULL;
+ int value = 1;
+ int ret = -1;
+
+ result = sync_agent_create_config(&config);
+ if (result != SYNC_AGENT_DA_SUCCESS) {
+ _EXTERN_FUNC_EXIT;
+ return -1;
+ }
+
+ result = sync_agent_get_config(config_id, key, &config);
+ _DEBUG_INFO("---------------------------result : %d-------------------------\n", result);
+ if (result == 1) {
+ _DEBUG_INFO("Success get config value");
+
+ ret = chartoint(config->value, &value);
+ _DEBUG_INFO("result : %d , key : %s value : %d\n", result, key, value);
+
+ if (ret == 0) {
+ _DEBUG_INFO("fail get config value");
+ ret = -1;
+ goto return_part;
+ } else {
+ _DEBUG_INFO("success get config value");
+ ret = value;
+ }
+ } else {
+ _DEBUG_INFO("fail get config value");
+ }
+
+ return_part:
+
+ sync_agent_free_config(config);
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int set_alarm_config_int(CONFIG_TYPE config_type, char *key, int value, char *accessName)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ sync_agent_da_return_e result;
+ sync_agent_da_config_s config;
+ int exist = 0;
+
+ config.access_name = accessName;
+ config.config_id = config_type;
+ config.key = key;
+ config.value = g_strdup_printf("%d", value);
+ config.type = "int";
+
+ result = sync_agent_is_exist_config(config_type, key, &exist);
+ if (result != SYNC_AGENT_DA_SUCCESS)
+ ret = 0;
+
+ if (exist == 0) {
+ _DEBUG_INFO("default add config : %s\n", key);
+ result = sync_agent_add_config(&config);
+
+ if (result != SYNC_AGENT_DA_SUCCESS)
+ ret = 0;
+ } else {
+ result = sync_agent_update_config(&config);
+ _DEBUG_INFO("update alarm config db ");
+ }
+
+ ret = 1;
+ str_free(&(config.value));
+ _DEBUG_INFO("end : %d", ret);
+ _EXTERN_FUNC_EXIT;
+ return ret;
+}
+
+int get_wifi_only_config()
+{
+ _EXTERN_FUNC_ENTER;
+
+ _EXTERN_FUNC_EXIT;
+ return get_config_int(FUMO_WIFI_ONLY_TYPE, FUMO_WIFI_ONLY_CONFIG);
+}
+
+int set_wifi_only_config(int value)
+{
+ _EXTERN_FUNC_ENTER;
+
+ _EXTERN_FUNC_EXIT;
+ return set_config_int(FUMO_WIFI_ONLY_TYPE, FUMO_WIFI_ONLY_CONFIG, value, FUMO, 0);
+}
+
+DM_ERROR get_battery_state(char **battery_level)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+ sync_agent_dev_return_e err = SYNC_AGENT_DEV_RETURN_SUCCESS;
+
+ err = sync_agent_get_devinfo(2, "Battery", battery_level);
+ if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
+ goto error;
+ }
+ if ((*battery_level) == NULL) {
+ goto error;
+ }
+
+ _DEBUG_INFO("\n========battery ======== %s\n", *battery_level);
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ error:
+ _EXTERN_FUNC_EXIT;
+ return DM_GET_BATTERY_ERROR;
+}
+
+DM_ERROR get_telephony_state(int *now_calling)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+/*
+ * vconf( framework )
+ */
+ int tel_value;
+ if (vconf_get_int(VCONFKEY_CALL_STATE, &tel_value) != 0)
+ goto error;
+
+ switch (tel_value) {
+ case VCONFKEY_CALL_VOICE_CONNECTING:
+ case VCONFKEY_CALL_VOICE_ACTIVE:
+ case VCONFKEY_CALL_VIDEO_CONNECTING:
+ case VCONFKEY_CALL_VIDEO_ACTIVE:
+ (*now_calling) = 1;
+ break;
+ case VCONFKEY_CALL_OFF:
+ (*now_calling) = 0;
+ break;
+ default:
+ break;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ error:
+ _EXTERN_FUNC_EXIT;
+ return DM_TELEPHONY_ERROR;
+
+}
+
+void network_state_callback()
+{
+ _EXTERN_FUNC_ENTER;
+
+ /*typedef enum {
+ NETWORK_NONE, initial network type
+ NETWORK_3G_ON, network UMTS on
+ NETWORK_3G_OFF, network UMTS off
+ NETWORK_WIFI_ON, network WIFI on
+ NETWORK_WIFI_ON_NOT_CONNECTED, network WIFI on but not connected
+ NETWORK_WIFI_OFF, network WIFI off
+ NETWORK_WIFI_3G_ON, network UMTS and WIFI on
+ } FW_NETWORK_TYPE;
+ #endif
+ */
+
+ /*sync_agent_na_result_e err;
+ int net_type;
+ err = NACI_Get_Network_Type(&net_type);
+ if(err != SYNC_AGENT_NA_SUCCESS)
+ goto error;
+
+ switch(net_type)
+ {
+ case 1:
+ case 3:
+
+ * search db
+ * generic alert
+ * fumo (not alarm)
+ * lawmo( not alarm)
+ * deregister vconf callback
+
+ break;
+ case 0:
+ case 2:
+ case 5:
+ case 6:
+ break;
+ default:
+ break;
+ }
+
+ error: */
+ _EXTERN_FUNC_EXIT;
+ return;
+}
+
+DM_ERROR existed_sd_card_memory(int *existed_sd)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+/*
+ * vconf( framework )
+ * //only one sd card
+ */
+ int mmc_value = 0;
+ int err = 0;
+
+ err = get_mmc_state(&mmc_value);
+ if (err == 0) {
+ (*existed_sd) = 0;
+ goto error;
+ } else {
+ if (mmc_value == 1) {
+ (*existed_sd) = 1;
+
+ /*for make empty folder */
+ char *downlaod_folder = NULL;
+ char *save_folder = NULL;
+ ret = get_fota_download_dir(MEMORY_SD_CARD, &downlaod_folder);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ ret = get_fota_save_dir(MEMORY_SD_CARD, &save_folder);
+ if (ret != DM_OK) {
+ goto error;
+ }
+
+ str_free(&downlaod_folder);
+ str_free(&save_folder);
+ } else {
+ (*existed_sd) = 0;
+ }
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+ error:
+
+ _EXTERN_FUNC_EXIT;
+ return DM_SD_CARD_ERROR;
+}
+
+void get_roaming_state(int *roaming_state)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int roaming_config = 0;
+
+ if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, roaming_state) != 0) {
+ *roaming_state = -1;
+ _DEBUG_INFO("end , roaming state : %d", *roaming_state);
+ } else {
+ if (*roaming_state == 0) {
+ /*not roaming svc area */
+ _DEBUG_INFO("end , roaming state : %d", *roaming_state);
+ _EXTERN_FUNC_EXIT;
+ return;
+ } else {
+ /*roaming svc area */
+ if (vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &roaming_config) != 0) {
+ *roaming_state = -1;
+ _DEBUG_INFO("end , roaming state : %d", *roaming_state);
+ } else {
+ if (roaming_config == 1) {
+ /*
+ * do service roaming service
+ * check wifi
+ */
+ _DEBUG_INFO("end , roaming state : %d", *roaming_state);
+ return;
+ } else {
+ /*don not service at roaming svc */
+ *roaming_state = -1;
+ _DEBUG_INFO("end , roaming state : %d", *roaming_state);
+ }
+ }
+ }
+ }
+ _EXTERN_FUNC_EXIT;
+}
+
+void get_call_sate(int *call_state)
+{
+ _EXTERN_FUNC_ENTER;
+ /*0 : do service
+ * 1 : dont service
+ * 2 : ?
+ */
+ if (vconf_get_int(VCONFKEY_TELEPHONY_CALL_STATE, call_state) != 0) {
+ *call_state = -1;
+ _DEBUG_INFO("end, call state : %d", *call_state);
+ _EXTERN_FUNC_EXIT;
+ return;
+ } else {
+ if (*call_state == 0) {
+ _DEBUG_INFO("end, call state : %d", *call_state);
+ _EXTERN_FUNC_EXIT;
+ return;
+ } else {
+ *call_state = -1;
+ _DEBUG_INFO("end, call state : %d", *call_state);
+ _EXTERN_FUNC_EXIT;
+ return;
+ }
+ }
+}
+
+int get_mmc_state(int *mmc_state)
+{
+ _EXTERN_FUNC_ENTER;
+
+ if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, mmc_state) != 0)
+ goto error;
+
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ error:
+ _EXTERN_FUNC_EXIT;
+ _DEBUG_INFO("end error");
+ return 0;
+}
+
+DM_ERROR compare_memory_space(char *memory_type, long double file_size)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int err;
+ long double sizeFree;
+ long double sizeTotal;
+
+ retvm_if((memory_type) == NULL, COMMON_ERR_IS_NULL, "memory_type is NULL!!");
+
+ err = sync_agent_get_fs_mem_size(memory_type, &sizeFree, &sizeTotal);
+ if (err == 0) {
+ _EXTERN_FUNC_EXIT;
+ return DM_MEMORY_ERROR;
+ }
+
+ _DEBUG_INFO("memory free size : %f, total size : %f ", sizeFree, sizeTotal);
+ if (file_size > sizeFree) {
+ _EXTERN_FUNC_EXIT;
+ return DM_OVER_MEMORY_ERROR;
+ }
+
+ _EXTERN_FUNC_EXIT;
+
+ return DM_OK;
+}
+
+DM_ERROR get_fota_download_dir(MEMORY_TYPE type, char **download_folder)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_dev_return_e dci_down_ret = SYNC_AGENT_DEV_RETURN_SUCCESS;
+
+ switch (type) {
+ case MEMORY_INTERNAL:
+ _DEBUG_INFO("internal memory");
+ dci_down_ret = sync_agent_get_devinfo(2, "FOTADownDir", download_folder);
+ break;
+ case MEMORY_SD_CARD:
+ _DEBUG_INFO("sd card memory");
+ dci_down_ret = sync_agent_get_devinfo(2, "FOTA_SD_DownDir", download_folder);
+ break;
+ default:
+ _DEBUG_INFO("ERROR NOT USE MEMORY");
+ break;
+ }
+
+ if (dci_down_ret == SYNC_AGENT_DEV_RETURN_SUCCESS) {
+ _DEBUG_INFO(" download : %s", *download_folder);
+
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+ }
+ _DEBUG_INFO("end error : %d ", DM_MEMORY_ERROR);
+ _EXTERN_FUNC_EXIT;
+ return DM_MEMORY_ERROR;
+}
+
+DM_ERROR get_fota_save_dir(MEMORY_TYPE type, char **save_folder)
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_dev_return_e dci_down_ret = SYNC_AGENT_DEV_RETURN_SUCCESS;
+
+ switch (type) {
+ case MEMORY_INTERNAL:
+ dci_down_ret = sync_agent_get_devinfo(2, "FOTASaveDir", save_folder);
+ break;
+ case MEMORY_SD_CARD:
+ dci_down_ret = sync_agent_get_devinfo(2, "FOTA_SD_SaveDir", save_folder);
+ break;
+ default:
+ _DEBUG_INFO("ERROR NOT USE MEMORY");
+ break;
+ }
+
+ if (dci_down_ret == SYNC_AGENT_DEV_RETURN_SUCCESS) {
+ _DEBUG_INFO(" save_folder : %s", *save_folder);
+
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+ }
+ _DEBUG_INFO("end error : %d ", DM_MEMORY_ERROR);
+ _EXTERN_FUNC_EXIT;
+ return DM_MEMORY_ERROR;
+}
+
+void delete_fumo_contents(MEMORY_TYPE memory_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ _DEBUG_INFO("----------------------------------------------------------firmware update fail delete files-----------------------------------------------------------");
+ char *download_folder = NULL;
+ char *save_folder = NULL;
+
+ //FOTASaveDir //FOTADownDir
+ //dci_save_ret = sync_agent_get_devinfo(2 , "FOTADownDir" , &download_folder);
+ get_fota_download_dir(memory_type, &download_folder);
+ sync_agent_empty_directory_contents(download_folder);
+ //dci_save_ret = sync_agent_get_devinfo(2 , "FOTASaveDir" , &save_folder);
+ get_fota_save_dir(memory_type, &save_folder);
+
+ sync_agent_empty_directory_contents(save_folder);
+ _DEBUG_INFO("delete save folder ");
+
+ str_free(&save_folder);
+ str_free(&download_folder);
+
+ _EXTERN_FUNC_EXIT;
+
+}
+
+void first_server_bootstrap(char *server_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ DM_ERROR ret = DM_OK;
+
+ if (server_id == NULL) {
+ _DEBUG_INFO("server id null");
+ return;
+ }
+
+ Event_Contents *ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents) + 1);
+ if (ev_data == NULL) {
+ _DEBUG_INFO("alloc fail");
+ _EXTERN_FUNC_EXIT;
+ return;
+ }
+ ev_data->server_id = strdup(server_id);
+ ev_data->session_id = NULL;
+ ev_data->type = SERVER_BOOTSTRAP_EVENT;
+ ev_data->ui_mode = NULL;
+
+ _DEBUG_INFO("event type server bootstrap : %d", ev_data->type);
+ _DEBUG_INFO("session id : %s", ev_data->session_id);
+ _DEBUG_INFO("server id : %s", ev_data->server_id);
+
+ /* UI CONFIRM */
+ SERVICE_SERVER_TYPE engine_type;
+ engine_type = get_service_engine_type(ev_data->server_id);
+
+ switch (engine_type) {
+ case SAMSUNG_FUMO_TYPE:
+ case GCF_TYPE:
+ {
+ //when using telephony
+ //DM_ERROR get_telephony_state(int *now_calling);
+ _DEBUG_INFO("engine type : %d", engine_type);
+ ev_data->noti_type = NOTI_TYPE_BACKGRUOUND;
+ ev_data->ui_mode = strdup(OMADM_FUMO_BACKGROUND_UI_TYPE);
+
+ _DEBUG_INFO("noti type : %d", ev_data->noti_type);
+ _DEBUG_INFO("ui mode : %s", ev_data->ui_mode);
+
+ ret = dm_fumo_common_task_request(ev_data);
+ _DEBUG_INFO("dm fumo conmmon task : %d ", ret);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ }
+ break;
+ case SAMSUNG_FMM_TYPE:
+
+ _DEBUG_INFO("engine type : %d", engine_type);
+ ret = dm_lawmo_common_task_request(ev_data);
+ _DEBUG_INFO("dm lawmo conmmon task : %d ", ret);
+ if (ret != DM_OK) {
+ goto error;
+ }
+ break;
+ default:
+ _DEBUG_INFO("dm non engine ", ret);
+ break;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return;
+
+ error:
+ event_data_free((void *)ev_data);
+ _EXTERN_FUNC_EXIT;
+}
+
+int get_default_noti_type(char *ui_mode, NotI_Type noti_type)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retvm_if((ui_mode) == NULL, COMMON_ERR_IS_NULL, "ui_mode is NULL!!");
+
+ if (strcmp(OMADM_FUMO_UI_TYPE, ui_mode) == 0) {
+ _EXTERN_FUNC_EXIT;
+ return NOTI_UNKNOWN; //none type
+ } else if (strcmp(OMADM_FUMO_NOTI_UI_TYPE, ui_mode) == 0) {
+ switch (noti_type) {
+ case NOTI_TYPE_NOT_SPECIFIED:
+ case NOTI_TYPE_BACKGRUOUND:
+ case NOTI_TYPE_USERINTERACTION:
+ _EXTERN_FUNC_EXIT;
+ return NOTI_DOWNLOAD; //none type
+ break;
+ case NOTI_TYPE_INFOMATIVE:
+ _EXTERN_FUNC_EXIT;
+ return NOTI_DOWNLOAD; //connect to server
+ break;
+ default:
+ return NOTI_UNKNOWN; //none type
+ break;
+ }
+ } else if (strcmp(OMADM_FUMO_BACKGROUND_UI_TYPE, ui_mode) == 0) {
+ _EXTERN_FUNC_EXIT;
+ return NOTI_UNKNOWN; //none type
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return NOTI_UNKNOWN;
+}
+
+int wifi_only_config(char *config)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retvm_if((config) == NULL, COMMON_ERR_IS_NULL, "config is NULL!!");
+
+ if (config != NULL) {
+ if (strcmp(config, "1") == 0) {
+ _DEBUG_INFO("wifi on config");
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ } else if (strcmp(config, "0") == 0) {
+ _DEBUG_INFO("wifi off config");
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ } else {
+ _DEBUG_INFO("wifi config error");
+ }
+ } else {
+ _DEBUG_INFO("wifi config error");
+ }
+
+ _EXTERN_FUNC_EXIT;
+
+ return 0;
+}
diff --git a/src/agent/common/util/util.c b/src/agent/common/util/util.c
new file mode 100644
index 0000000..0623576
--- /dev/null
+++ b/src/agent/common/util/util.c
@@ -0,0 +1,490 @@
+/*
+ * 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 <aul.h>
+#include <unistd.h>
+#include <appsvc.h>
+#include <glib.h>
+
+/*sync-agent*/
+#include <sync_agent.h>
+
+/*dm-agent*/
+#include "common/dm_common.h"
+#include "common/util/util.h"
+#include "ipc_agent.h"
+#include "ipc_common.h"
+
+#ifndef OMADM_AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "OMA_DM_UTIL"
+#endif
+
+static void _update_csc();
+
+void str_free(char **str)
+{
+ _EXTERN_FUNC_ENTER;
+
+ if (*str == NULL) {
+ _EXTERN_FUNC_EXIT;
+ return;
+ } else {
+ free(*str);
+ *str = NULL;
+ }
+
+ _EXTERN_FUNC_EXIT;
+}
+
+int chartoint(char *data, int *value)
+{
+ _EXTERN_FUNC_ENTER;
+
+ retvm_if(data == NULL, 0, "data is NULL!!");
+
+ if (data == NULL) {
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ } else {
+ (*value) = atoi(data);
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return 0;
+}
+
+int launch_oma_dm_fumo_ui()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int result = 0;
+ _DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
+ _DEBUG_INFO("\n is launch oma fumo dm ui : %d ?\n", result);
+ result = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
+ _DEBUG_INFO("\n Is launch oma fumo dm ui , result : %d\n", result);
+ _DEBUG_INFO("\n---------------------------------------------------: %d \n", result);
+
+ if (result == 0) {
+ bundle *pBundle = NULL;
+ pBundle = bundle_create();
+ if (pBundle == NULL) {
+ _DEBUG_INFO("bundle_create fail\n");
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+ result = bundle_add(pBundle, "FOTA_UI", "3");
+ if (result == -1) {
+ bundle_free(pBundle);
+ _DEBUG_INFO("bundle_add fail\n");
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ result = aul_launch_app(OMA_DM_FUMO_UI_PKG, pBundle);
+ _DEBUG_INFO("result : %d\n", result);
+ if (result == -1) {
+ bundle_free(pBundle);
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+ bundle_free(pBundle);
+ sleep(2);
+ } else {
+ _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
+ _DEBUG_INFO("existed oma dm ui\n");
+ _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
+ }
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+int launch_om_dm_fumo_noti_ui(int noti_data, char *session_id, char *server_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int result = 0;
+ _DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
+ _DEBUG_INFO("\n is launch oma noti dm ui ? : %d\n", result);
+ result = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
+ _DEBUG_INFO("\n Is launch oma noti dm ui , result : %d\n", result);
+ _DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
+
+ if (result == 0) {
+ char *noti_type = NULL;
+ noti_type = g_strdup_printf("%d", noti_data);
+
+ bundle *pBundle = NULL;
+ pBundle = bundle_create();
+ if (pBundle == NULL) {
+ _DEBUG_INFO("bundle_create fail\n");
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ result = bundle_add(pBundle, "FOTA_NOTI", noti_type);
+ result = bundle_add(pBundle, "FOTA_SESSIONID", session_id);
+ result = bundle_add(pBundle, "FOTA_SERVERID", server_id);
+
+ if (session_id == NULL) {
+ /*if engine stoped by battery off or other exceptions */
+ result = bundle_add(pBundle, "FOTA_SESSIONID", "1111");
+ }
+ if (server_id == NULL) {
+ result = bundle_add(pBundle, "FOTA_SERVERID", "1111");
+ }
+ if (result == -1) {
+ _DEBUG_INFO("bundle_add fail\n");
+ bundle_free(pBundle);
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ result = aul_launch_app(OMA_DM_FUMO_NOTI_UI_PKG, pBundle);
+ _DEBUG_INFO("result : %d\n", result);
+
+ if (result == -1) {
+ bundle_free(pBundle);
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ str_free(&noti_type);
+ bundle_free(pBundle);
+ sleep(2);
+ } else {
+ _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
+ _DEBUG_INFO("existed oma dm noti ui\n");
+ _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
+ }
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+int launch_om_dm_fumo_alert_ui()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int ret = 0;
+ _DEBUG_INFO("OMA_DM_ALERT_UI_PKG : %s", OMA_DM_ALERT_UI_PKG);
+ ret = aul_app_is_running(OMA_DM_ALERT_UI_PKG);
+ _DEBUG_INFO("aul_app_is_running(%s) [%d] ", OMA_DM_ALERT_UI_PKG, ret);
+ if (ret == 0) {
+ bundle *b = bundle_create();
+ //appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
+ //appsvc_set_pkgname(b, OMA_DM_ALERT_UI_PKG);
+
+ //ret = appsvc_run_service(b, 0, NULL, NULL);
+ ret = aul_launch_app(OMA_DM_ALERT_UI_PKG, b);
+ _DEBUG_INFO("result : %d\n", ret);
+
+ _DEBUG_INFO("oma dm alert ui run : %d\n", ret);
+ bundle_free(b);
+ if (ret >= 0) {
+ sleep(2);
+ _EXTERN_FUNC_EXIT;
+ return 1;
+ } else {
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+ } else {
+ return 1;
+ }
+ _EXTERN_FUNC_EXIT;
+ return 0;
+}
+
+int launch_oma_dm_cp_ui(int sec_type, int ext_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ _DEBUG_INFO("Start !!");
+ int result = 0;
+ _DEBUG_INFO("OMA_DM_CP_UI_PKG : %s", OMA_DM_CP_UI_PKG);
+ _DEBUG_INFO("\n---------------------------------------------------\n");
+ _DEBUG_INFO("\n is launch oma dm cp ui ?\n");
+ result = aul_app_is_running(OMA_DM_CP_UI_PKG);
+ _DEBUG_INFO("\n Is launch oma dm cp ui, result : %d\n", result);
+ _DEBUG_INFO("\n---------------------------------------------------\n");
+
+ if (result == 0) {
+ char *pin_type = NULL;
+ pin_type = g_strdup_printf("%d", sec_type);
+ char *extId = NULL;
+ extId = g_strdup_printf("%d", ext_id);
+
+ bundle *pBundle = NULL;
+ pBundle = bundle_create();
+ if (pBundle == NULL) {
+ _DEBUG_INFO("bundle_create fail\n");
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ result = bundle_add(pBundle, "PIN_TYPE", pin_type);
+ if (result == -1) {
+ _DEBUG_INFO("bundle_add fail\n");
+ bundle_free(pBundle);
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ result = bundle_add(pBundle, "EXT_ID", extId);
+ if (result == -1) {
+ _DEBUG_INFO("bundle_add fail\n");
+ bundle_free(pBundle);
+ _EXTERN_FUNC_EXIT;
+ return 0;
+ }
+
+ result = aul_launch_app(OMA_DM_CP_UI_PKG, pBundle);
+ _DEBUG_INFO("result : %d\n", result);
+
+ if (result == -1) {
+ _EXTERN_FUNC_EXIT;
+ bundle_free(pBundle);
+ return 0;
+ }
+
+ str_free(&pin_type);
+ bundle_free(pBundle);
+ sleep(2);
+ } else {
+ _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
+ _DEBUG_INFO("existed oma dm cp ui\n");
+ _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
+ }
+ _EXTERN_FUNC_EXIT;
+ return 1;
+}
+
+void terminate_oma_dm_ui(int result_status, ENGINE_ID service_engine_id)
+{
+ _EXTERN_FUNC_ENTER;
+
+ if (result_status == DM_ERR_REMINDER_INTERVAL || result_status == DM_DOWNLOAD_POPUP || result_status == DM_INSTALL_POPUP || result_status == DM_RESUME_IDLE) {
+ _DEBUG_INFO("result status : %d", result_status);
+ return;
+ }
+
+ _DEBUG_INFO("start");
+
+ DM_ERROR ret = DM_OK;
+ int isfumo_engine = 0;
+ engine_status *status = NULL;
+ int result = 0;
+ bool cancel_flag = 0;
+
+ cancel_flag = sync_agent_check_cancel_flag();
+ if (cancel_flag) {
+ _EXTERN_FUNC_EXIT;
+ return;
+ }
+ isfumo_engine = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
+
+ if (isfumo_engine == 1) {
+ if (service_engine_id == FUMO_SERVICE_ENGINE) {
+ _DEBUG_INFO("existed engine id in db");
+ ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
+ _DEBUG_INFO("get fumo service engine : %d", ret);
+
+ if (status != NULL && status->ui_mode != NULL) {
+ result = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
+ if (result == 1) {
+ terminate_ui_status(status->ui_noti_type, status->ui_mode, result_status);
+ }
+ result = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
+ if (result == 1) {
+ terminate_ui_status(status->ui_noti_type, status->ui_mode, result_status);
+ }
+ } else {
+ _DEBUG_INFO("fumo service ui mode not existed");
+ }
+
+ if (status != NULL)
+ Free_Memory_Engine_Status(&status, 1);
+
+ ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
+ _DEBUG_INFO("delete engine status : %d", ret);
+ } else {
+ _DEBUG_INFO("fumo service not existed");
+ }
+ } else {
+ _DEBUG_INFO("fumo service not existed");
+ }
+ _EXTERN_FUNC_EXIT;
+
+}
+
+void terminate_ui_status(int noti_type, char *ui_mode, int result_status)
+{
+ _EXTERN_FUNC_ENTER;
+
+ int noti_res = 0;
+
+ _DEBUG_INFO("noti type : %d", noti_type);
+ /*noti_res = noti_engine_fail(noti_type, fail_type); */
+
+ switch (noti_type) {
+ case NOTI_ENGINE_START:
+ _DEBUG_INFO("connect to sever ui ");
+ if (result_status != DM_OK) {
+ if (result_status == DM_ERR_UNAUTHORIZED || result_status == DM_ERR_AUTHENTICATION_REQUIRED) {
+ noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_FAILURE_AUTHENTICATION);
+ } else {
+ noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_FAILURE);
+ }
+ } else {
+ noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_UPTODATA);
+ }
+ _DEBUG_INFO("connect to sever ui : %d", noti_res);
+ break;
+ case NOTI_UNKNOWN:
+ case NOTI_DOWNLOAD:
+ case NOTI_DOWNLOAD_INFO:
+ case NOTI_INSTALL:
+ //case NOTI_WIFI_ONLY_DOWNLOAD_FAIL:
+ //case NOTI_MEMORY_FULL:
+ noti_res = noti_engine_fail(noti_type, 0);
+ break;
+ case NOTI_LOW_BATTERY:
+ case NOTI_ALERT_DISPLAY:
+ case NOTI_ALERT_CONFIRMATION:
+ case NOTI_ALERT_INPUTTEXT:
+ case NOTI_ALERT_SINGLE_CHOICE:
+ case NOTI_ALERT_MULTIPLE_CHOICE:
+ break;
+ default:
+ break;
+ }
+
+ _DEBUG_INFO("cancel ui : %d", noti_res);
+ _EXTERN_FUNC_EXIT;
+
+}
+
+int check_csc()
+{
+ _EXTERN_FUNC_ENTER;
+
+ int exist = 0;
+
+ /*FIXME(temporary do not process csc for ui reason)
+ check csc_check file is existed
+ if false do csc update
+ if true check csc xml file has been changed */
+
+ /*exist = sync_agent_is_existing_fs(CSC_CHECK_PATH); */
+ /*temp value */
+ exist = 1;
+
+/*for prevent*/
+ /*if(exist == 0 ) {
+ _update_csc();
+ } */
+
+ _update_csc();
+
+ _DEBUG_INFO("update = %d", exist);
+ _EXTERN_FUNC_EXIT;
+ return exist;
+}
+
+static void _update_csc()
+{
+ _INNER_FUNC_ENTER;
+
+ //dmacc mo db update
+ /*sync_agent_write_whole_file(OMA_DS_CSC_CHECK_PATH, contents, strlen(contents), false); */
+
+ _INNER_FUNC_EXIT;
+}
+
+int get_wifi_state()
+{
+ _EXTERN_FUNC_ENTER;
+
+ sync_agent_na_result_e ret = SYNC_AGENT_NA_SUCCESS;
+ sync_agent_na_network_connection_type_e con_type = SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_UNKNOWN;
+ sync_agent_na_network_connection_state_e con_state = SYNC_AGENT_NA_NETWORK_CONNECTION_STATE_NONE;
+
+ ret = sync_agent_get_connection_type(&con_type);
+ if (ret != SYNC_AGENT_NA_SUCCESS) {
+ _DEBUG_INFO("get connection type");
+ ret = SYNC_AGENT_NA_DOWNLOAD_DATA_FAIL;
+ goto return_part;
+ }
+ _DEBUG_INFO("get connection type : %d", con_type);
+
+ ret = sync_agent_get_connection_state(&con_state);
+ _DEBUG_INFO("get connection state : %d", con_state);
+ if (ret != SYNC_AGENT_NA_SUCCESS) {
+ _DEBUG_INFO("get connection state");
+ ret = SYNC_AGENT_NA_NETWORK_UNAVAILABLE;
+ goto return_part;
+ }
+
+ if (con_type != SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_WIFI || (con_type == SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_WIFI && con_state != SYNC_AGENT_NA_NETWORK_CONNECTION_STATE_WIFI_CONNECTED)) {
+ _DEBUG_INFO("wifi only on mode download fail");
+ ret = SYNC_AGENT_NA_NETWORK_UNAVAILABLE;
+ goto return_part;
+ } else {
+ _DEBUG_INFO("wifi on mode download");
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return ret;
+
+ return_part:
+ _DEBUG_INFO("error end %d : ", ret);
+ _EXTERN_FUNC_EXIT;
+
+ return ret;
+}
+
+DM_ERROR nonce_decode(char *nextNonce, unsigned char **nextNonceDecode, unsigned int *out_len)
+{
+ _EXTERN_FUNC_ENTER;
+
+ unsigned char *tempnextNonceDecode = NULL;
+ tempnextNonceDecode = g_base64_decode(nextNonce, (unsigned int *)(out_len));
+
+ if (tempnextNonceDecode == NULL && *out_len != 0) {
+ _DEBUG_INFO("tempnextNonceDecode = NULL , out len : %d", *out_len);
+ int i = 0;
+ char *zero = "0";
+ *nextNonceDecode = (unsigned char *)calloc(1, (*out_len) + 1);
+ for (i = 0; i < (*out_len); ++i) {
+ g_strlcat((char *)(*nextNonceDecode), zero, *out_len);
+ }
+
+ } else {
+
+ _DEBUG_INFO("tempnextNonceDecode = %s, out_len = %d", tempnextNonceDecode, *out_len);
+ /**nextNonceDecode = (char *)strdup(tempnextNonceDecode);
+ str_free((char **)(&tempnextNonceDecode));*/
+ *nextNonceDecode = tempnextNonceDecode;
+ }
+
+ _EXTERN_FUNC_EXIT;
+ return DM_OK;
+
+}