From: Kyeonghun Lee Date: Tue, 6 Dec 2016 10:47:46 +0000 (+0900) Subject: [MPR-868] Add duplication logic for CB Messages X-Git-Tag: accepted/tizen/3.0/common/20161209.161220~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45b4257faf9801bcdea24f1ff4860b1fe0e6ed7a;p=platform%2Fcore%2Fmessaging%2Fmsg-service.git [MPR-868] Add duplication logic for CB Messages Change-Id: I6651f53faf86f7eb65411c4978e6c239db3e2950 Signed-off-by: Kyeonghun Lee --- diff --git a/config/msg-service-db.sql b/config/msg-service-db.sql index 716d46b..f0dc291 100755 --- a/config/msg-service-db.sql +++ b/config/msg-service-db.sql @@ -97,6 +97,7 @@ CREATE TABLE MSG_CBMSG_TABLE ( MSG_ID INTEGER PRIMARY KEY , CB_MSG_ID INTEGER NOT NULL , + SERIAL_NUM INTEGER NOT NULL , FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) ); diff --git a/framework/storage-handler/MsgStorageManager.cpp b/framework/storage-handler/MsgStorageManager.cpp index 6acf115..5734763 100755 --- a/framework/storage-handler/MsgStorageManager.cpp +++ b/framework/storage-handler/MsgStorageManager.cpp @@ -116,6 +116,19 @@ void MsgUpdateDBtoVer2() MSG_SEC_DEBUG("SUCCESS : alter %s.", MSGFW_MESSAGE_TABLE_NAME); else MSG_SEC_DEBUG("FAIL : create %s [%d].", MSGFW_MESSAGE_TABLE_NAME, err); + + memset(sqlQuery, 0x00, sizeof(sqlQuery)); + snprintf(sqlQuery, sizeof(sqlQuery), + "ALTER TABLE %s " + "ADD COLUMN SERIAL_NUM INTEGER NOT NULL;", + MSGFW_CB_MSG_TABLE_NAME); + + err = dbHandle->execQuery(sqlQuery); + + if (err == MSG_SUCCESS) + MSG_SEC_DEBUG("SUCCESS : alter %s.", MSGFW_CB_MSG_TABLE_NAME); + else + MSG_SEC_DEBUG("FAIL : create %s [%d].", MSGFW_CB_MSG_TABLE_NAME, err); } diff --git a/framework/storage-handler/MsgStorageMessage.cpp b/framework/storage-handler/MsgStorageMessage.cpp index bbb72e4..436b86c 100755 --- a/framework/storage-handler/MsgStorageMessage.cpp +++ b/framework/storage-handler/MsgStorageMessage.cpp @@ -830,7 +830,8 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication) return MSG_ERR_DB_EXEC; } - if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS) { + if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS + || (msgType.subType >= MSG_CMAS_PRESIDENTIAL && msgType.subType <= MSG_CMAS_OPERATOR_DEFINED)) { memset(sqlQuery, 0x00, sizeof(sqlQuery)); snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_CB_MSG_TABLE_NAME, msgId); diff --git a/framework/storage-handler/MsgStorageUtil.cpp b/framework/storage-handler/MsgStorageUtil.cpp index ab73816..5dcec40 100755 --- a/framework/storage-handler/MsgStorageUtil.cpp +++ b/framework/storage-handler/MsgStorageUtil.cpp @@ -760,8 +760,8 @@ msg_error_t MsgStoAddCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo) /** Add CB Msg in MSG_CBMSG_TABLE */ memset(sqlQuery, 0x00, sizeof(sqlQuery)); - snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);", - MSGFW_CB_MSG_TABLE_NAME, rowId, cbMsgId); + snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);", + MSGFW_CB_MSG_TABLE_NAME, rowId, cbMsgId, pMsgInfo->serialNum); if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) { dbHandle->endTrans(false); diff --git a/include/common/MsgInternalTypes.h b/include/common/MsgInternalTypes.h index 11832dd..1c695d9 100755 --- a/include/common/MsgInternalTypes.h +++ b/include/common/MsgInternalTypes.h @@ -266,6 +266,7 @@ typedef struct { int sim_idx; char msgURL[MMS_LOCATION_LEN + 1]; bool bRestricted; /**< Indicates whether the message is restricted by DPM(Device Policy Manager) or not. */ + unsigned short serialNum; /**< Indicates the serial number of a cell broadcast message. */ } MSG_MESSAGE_INFO_S; diff --git a/plugin/sms_plugin/SmsPluginCbMsgHandler.cpp b/plugin/sms_plugin/SmsPluginCbMsgHandler.cpp index 48d95ff..7f89671 100755 --- a/plugin/sms_plugin/SmsPluginCbMsgHandler.cpp +++ b/plugin/sms_plugin/SmsPluginCbMsgHandler.cpp @@ -138,22 +138,27 @@ void SmsPluginCbMsgHandler::handleCbMsg(TapiHandle *handle, TelSmsCbMsg_t *pCbMs err = SmsPluginStorage::instance()->checkMessage(&msgInfo); if (err == MSG_SUCCESS) { - MSG_CB_MSG_S cbOutMsg = {0, }; - - /*cbOutMsg.type = MSG_CB_SMS; */ - cbOutMsg.type = msgInfo.msgType.subType; - cbOutMsg.receivedTime = cbMsg->recvTime; - cbOutMsg.serialNum = encodeCbSerialNum(CbMsgPage.pageHeader.serialNum); - cbOutMsg.messageId = cbMsg->msgId; - cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData; - memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText)); - - cbOutMsg.cbTextLen = convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), cbMsg); - memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type)); - memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3); - err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo); - if (err != MSG_SUCCESS) - MSG_WARN("callbackMsgIncoming() Error !! [%d]", err); + bool is_duplicated = SmsPluginStorage::instance()->isDuplicatedCBMsg(&msgInfo); + if (is_duplicated == false) { + MSG_CB_MSG_S cbOutMsg = {0, }; + + /*cbOutMsg.type = MSG_CB_SMS; */ + cbOutMsg.type = msgInfo.msgType.subType; + cbOutMsg.receivedTime = cbMsg->recvTime; + cbOutMsg.serialNum = cbMsg->serialNum; + cbOutMsg.messageId = cbMsg->msgId; + cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData; + memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText)); + + cbOutMsg.cbTextLen = convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), cbMsg); + memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type)); + memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3); + err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo); + if (err != MSG_SUCCESS) + MSG_WARN("callbackMsgIncoming() Error !! [%d]", err); + } else { + MSG_DEBUG("This cb message is duplicated"); + } } else { MSG_WARN("checkMessage() Error !! [%d]", err); } @@ -676,6 +681,7 @@ void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCb pCbMsg->classType = CbPage->pageHeader.dcs.classType; pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme; pCbMsg->recvTime = CbPage->pageHeader.recvTime; + pCbMsg->serialNum = encodeCbSerialNum(CbPage->pageHeader.serialNum); cbPageMap::iterator it; int offset = 0; @@ -708,6 +714,7 @@ void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCb void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex) { pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId; + pMsgInfo->serialNum = pCbMsg->serialNum; pMsgInfo->folderId = MSG_CBMSGBOX_ID; diff --git a/plugin/sms_plugin/SmsPluginStorage.cpp b/plugin/sms_plugin/SmsPluginStorage.cpp index 9ed6a22..5fd8645 100755 --- a/plugin/sms_plugin/SmsPluginStorage.cpp +++ b/plugin/sms_plugin/SmsPluginStorage.cpp @@ -1115,3 +1115,25 @@ msg_error_t SmsPluginStorage::updateSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo) MSG_END(); return MSG_SUCCESS; } + + +bool SmsPluginStorage::isDuplicatedCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo) +{ + msg_error_t err = MSG_SUCCESS; + MsgDbHandler *dbHandle = getDbHandle(); + char sqlQuery[MAX_QUERY_LEN+1] = {0}; + int rowCnt = 0; + + snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SERIAL_NUM = %d", + MSGFW_CB_MSG_TABLE_NAME, pMsgInfo->serialNum); + + err = dbHandle->getTable(sqlQuery, &rowCnt, NULL); + if (err == MSG_SUCCESS) { + dbHandle->freeTable(); + return true; + } + + dbHandle->freeTable(); + + return false; +} diff --git a/plugin/sms_plugin/include/SmsPluginStorage.h b/plugin/sms_plugin/include/SmsPluginStorage.h index d2b5673..f3a86b9 100755 --- a/plugin/sms_plugin/include/SmsPluginStorage.h +++ b/plugin/sms_plugin/include/SmsPluginStorage.h @@ -72,6 +72,7 @@ public: msg_error_t getnthPushEvent(int index, int *appcode); msg_error_t releasePushEvent(); msg_error_t updateSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo); + bool isDuplicatedCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo); private: SmsPluginStorage(); ~SmsPluginStorage(); diff --git a/plugin/sms_plugin/include/SmsPluginTypes.h b/plugin/sms_plugin/include/SmsPluginTypes.h index c7c4c1a..7a95d76 100755 --- a/plugin/sms_plugin/include/SmsPluginTypes.h +++ b/plugin/sms_plugin/include/SmsPluginTypes.h @@ -739,6 +739,7 @@ typedef struct _SMS_CBMSG_PAGE_S { typedef struct _SMS_CBMSG_S { SMS_CBMSG_TYPE_T cbMsgType; /*CBS Msg or SCHEDULE Msg or CBS41 Msg */ unsigned short msgId; /**< Message identifier code */ + unsigned short serialNum; /* Serial number */ SMS_MSG_CLASS_T classType; /**< The message class */ SMS_CODING_SCHEME_T codingScheme; /**< How to encode a message. */ time_t recvTime; /**< Msg Recv Time */