[MPR-1091] make resend failed sms to only failed recipients 18/129418/4
authorKyeonghun Lee <kh9090.lee@samsung.com>
Tue, 16 May 2017 10:02:00 +0000 (19:02 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Mon, 29 May 2017 02:21:32 +0000 (11:21 +0900)
Change-Id: Idfbff9bd3195a265dc4823849d91157a7533c17f
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
config/msg-service-db.sql
framework/storage-handler/MsgStorageManager.cpp
framework/storage-handler/MsgStorageMessage.cpp
include/utils/MsgSqliteWrapper.h
plugin/sms_plugin/SmsPluginStorage.cpp
plugin/sms_plugin/SmsPluginTransport.cpp
plugin/sms_plugin/include/SmsPluginStorage.h

index b4b5627..6893c8c 100755 (executable)
@@ -264,6 +264,14 @@ CREATE TABLE MSG_ADDRESS_TEMP_TABLE
        ADDRESS_VAL TEXT NOT NULL DEFAULT ''
 );
 
+CREATE TABLE MSG_SENTFAIL_INDEX_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       SENTFAIL_INDEX INTEGER DEFAULT 0 ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
 CREATE INDEX MSG_CONVERSATION_INDEX ON MSG_CONVERSATION_TABLE(CONV_ID);
 CREATE INDEX MSG_FOLDER_INDEX ON MSG_FOLDER_TABLE(FOLDER_ID);
 CREATE INDEX MSG_MESSAGE_INDEX ON MSG_MESSAGE_TABLE(MSG_ID, CONV_ID, FOLDER_ID);
index 1590363..ca1e821 100755 (executable)
@@ -169,6 +169,23 @@ void MsgUpdateDBtoVer3()
                else
                        MSG_SEC_DEBUG("FAIL : create %s [%d].", MSGFW_MMS_RECIPIENTS_TABLE_NAME, err);
        }
+
+       if (!dbHandle->checkTableExist(MSGFW_SENTFAIL_INDEX_TABLE_NAME)) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "CREATE TABLE %s ( "
+                               "MSG_ID INTEGER PRIMARY KEY, "
+                               "SENTFAIL_INDEX INTEGER DEFAULT 0, "
+                               "FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID));",
+                               MSGFW_SENTFAIL_INDEX_TABLE_NAME);
+
+               err = dbHandle->execQuery(sqlQuery);
+
+               if (err == MSG_SUCCESS)
+                       MSG_SEC_DEBUG("SUCCESS : create %s.", MSGFW_SENTFAIL_INDEX_TABLE_NAME);
+               else
+                       MSG_SEC_DEBUG("FAIL : create %s [%d].", MSGFW_SENTFAIL_INDEX_TABLE_NAME, err);
+       }
 }
 
 
index 8c5111d..e5e9ce4 100755 (executable)
@@ -834,6 +834,16 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                        return MSG_ERR_DB_EXEC;
                }
 
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
+                               MSGFW_SENTFAIL_INDEX_TABLE_NAME, msgId);
+
+               /* Delete Data from SENTFAIL_INDEX table */
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
+
                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));
@@ -1070,13 +1080,14 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
                                                MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
                                                MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
                                                MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
-                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_UNIQUENESS_INFO_TABLE_NAME};
+                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_UNIQUENESS_INFO_TABLE_NAME,
+                                               MSGFW_SENTFAIL_INDEX_TABLE_NAME};
 #else
        const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
                                                MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
                                                MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
                                                MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
-                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME};
+                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_SENTFAIL_INDEX_TABLE_NAME};
 #endif
 
        int listCnt = sizeof(tableList)/sizeof(char *);
@@ -1415,14 +1426,15 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
                                                MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
                                                MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
                                                MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
-                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_UNIQUENESS_INFO_TABLE_NAME};
+                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_UNIQUENESS_INFO_TABLE_NAME,
+                                               MSGFW_SENTFAIL_INDEX_TABLE_NAME};
 #else
        const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
                                                MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
                                                MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
                                                MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
                                                MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME,
-                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME};
+                                               MSGFW_MMS_RECIPIENTS_TABLE_NAME, MSGFW_SENTFAIL_INDEX_TABLE_NAME};
 #endif
 
        int listCnt = sizeof(tableList)/sizeof(char *);
index 11a4ae9..e312397 100755 (executable)
@@ -64,6 +64,7 @@
 #define MSGFW_TMP_MSGID_TABLE_NAME                     "MSG_TMP_MSGID_TABLE"
 
 #define MSGFW_ADDRESS_TEMP_TABLE_NAME          "MSG_ADDRESS_TEMP_TABLE"
+#define MSGFW_SENTFAIL_INDEX_TABLE_NAME        "MSG_SENTFAIL_INDEX_TABLE"
 
 #define MAX_QUERY_LEN                                  3072
 #define MAX_FOLDER_NAME_LEN            20
index 492453a..466f4ed 100755 (executable)
@@ -623,6 +623,14 @@ msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
                return MSG_ERR_DB_EXEC;
        }
 
+       /** Delete Message from msg_sentfail_index table */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SENTFAIL_INDEX_TABLE_NAME, msgId);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
+       }
+
        /**  Clear Conversation table */
        if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
                dbHandle->endTrans(false);
@@ -1137,3 +1145,51 @@ bool SmsPluginStorage::isDuplicatedCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo)
 
        return false;
 }
+
+
+msg_error_t SmsPluginStorage::setFailedIndex(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int failedIndex)
+{
+       msg_error_t err = MSG_SUCCESS;
+       char sqlQuery[MAX_QUERY_LEN+1] = {0};
+       if (failedIndex > 0) {
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT OR REPLACE INTO %s(MSG_ID, SENTFAIL_INDEX) VALUES(%d, %d);",
+                               MSGFW_SENTFAIL_INDEX_TABLE_NAME, msgId, failedIndex);
+       } else {
+               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
+                               MSGFW_SENTFAIL_INDEX_TABLE_NAME, msgId);
+       }
+
+       if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
+               err = MSG_ERR_DB_EXEC;
+
+       return err;
+}
+
+
+int SmsPluginStorage::getFailedIndex(MsgDbHandler *pDbHandle, msg_message_id_t msgId)
+{
+       int ret = 0;
+       char sqlQuery[MAX_QUERY_LEN+1] = {0};
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SENTFAIL_INDEX FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_SENTFAIL_INDEX_TABLE_NAME, msgId);
+
+       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return 0;
+
+       if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               ret = pDbHandle->columnInt(0);
+       } else {
+               pDbHandle->finalizeQuery();
+               return 0;
+       }
+
+       pDbHandle->finalizeQuery();
+
+       return ret;
+}
+
+
+msg_error_t SmsPluginStorage::deleteFailedIndex(MsgDbHandler *pDbHandle, msg_message_id_t msgId)
+{
+       return setFailedIndex(pDbHandle, msgId, 0);
+}
index 35bf189..9a84d00 100755 (executable)
@@ -113,7 +113,9 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
                MSG_INFO("MsgSettingGetString() is failed");
        }
 
-       for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
+       int failedIndex = SmsPluginStorage::instance()->getFailedIndex(dbHandle, pReqInfo->msgInfo.msgId);
+
+       for (int i = failedIndex; i < pReqInfo->msgInfo.nAddressCnt; i++) {
                /* Make SMS_SUBMIT_DATA_S from MSG_REQUEST_INFO_S */
                SMS_SUBMIT_DATA_S submitData = {{0}, };
                msgInfoToSubmitData(&(pReqInfo->msgInfo), &submitData, &(tpdu.data.submit.dcs.codingScheme), i);
@@ -301,6 +303,7 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
                                        }
                                } else {
                                        SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
+                                       SmsPluginStorage::instance()->setFailedIndex(dbHandle, pReqInfo->msgInfo.msgId, i);
 
                                        if (msisdn) {
                                                free(msisdn);
@@ -312,7 +315,7 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
                                /* Tizen Validation System */
                                MSG_SMS_VLD_INFO("%d, SMS Send Start, %s->%s, %s",  pReqInfo->msgInfo.msgId, \
                                                                                                                                                        (msisdn == NULL)?"ME":msisdn, \
-                                                                                                                                                       pReqInfo->msgInfo.addressList[0].addressVal, \
+                                                                                                                                                       pReqInfo->msgInfo.addressList[i].addressVal, \
                                                                                                                                                        "Success");
 
                                MSG_SMS_VLD_TXT("%d, [%s]", pReqInfo->msgInfo.msgId, pReqInfo->msgInfo.msgText);
@@ -365,6 +368,8 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
                                        MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL, true, pReqInfo->msgInfo.msgId);
                                }
 
+                               SmsPluginStorage::instance()->setFailedIndex(dbHandle, pReqInfo->msgInfo.msgId, i);
+
                                if (msisdn) {
                                        free(msisdn);
                                        msisdn = NULL;
@@ -377,6 +382,8 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
                }
        }
 
+       SmsPluginStorage::instance()->deleteFailedIndex(dbHandle, pReqInfo->msgInfo.msgId);
+
 _RETURN_FUNC :
        if (msisdn) {
                free(msisdn);
index f3a86b9..ed55f63 100755 (executable)
@@ -73,6 +73,10 @@ public:
        msg_error_t releasePushEvent();
        msg_error_t updateSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
        bool isDuplicatedCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo);
+
+       msg_error_t setFailedIndex(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int failedIndex);
+       int getFailedIndex(MsgDbHandler *pDbHandle, msg_message_id_t msgId);
+       msg_error_t deleteFailedIndex(MsgDbHandler *pDbHandle, msg_message_id_t msgId);
 private:
        SmsPluginStorage();
        ~SmsPluginStorage();