Coverity fix: check return type
[platform/core/messaging/msg-service.git] / framework / submit-handler / MsgSubmitHandler.cpp
index 41e6825..14ac522 100755 (executable)
@@ -25,7 +25,7 @@
 #include "MsgPluginManager.h"
 #include "MsgStorageHandler.h"
 #include "MsgSubmitHandler.h"
-
+#include "MsgUtilFunction.h"
 
 
 /*==================================================================================================
@@ -39,6 +39,20 @@ msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
        pReqInfo->reqId = reqId;
        reqId++;
 
+       if (msg_check_dpm_policy(pReqInfo->msgInfo.msgType.mainType) == false) {
+               MSG_DEBUG("Messaging is restricted by DPM policy.");
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               if (pReqInfo->msgInfo.msgType.subType != MSG_RETRIEVE_MMS)
+                       /* sending popup */
+                       msg_syspopup_message(true);
+               else
+                       /* retrieving popup */
+                       msg_syspopup_message(false);
+
+               return MSG_ERR_DPM_RESTRICT;
+       }
+
        MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
        MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
        MSG_INFO("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
@@ -50,16 +64,13 @@ msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
 
        MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
 
-       if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE)
-       {
+       if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
                MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
                MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
                MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
 
                err = MsgSubmitReqSMS(pReqInfo);
-       }
-       else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
-       {
+       } else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
                MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
                MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
                MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
@@ -77,22 +88,27 @@ msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       // submit request based on msgType;
+       /* submit request based on msgType; */
        MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
        MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
 
-       if (plg == NULL)
-               return MSG_ERR_NULL_POINTER;
+       if (plg == NULL) {
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MSG_ERR("No plugin for %d type", mainType);
+               return MSG_ERR_INVALID_PLUGIN_HANDLE;
+       }
 
-       // If MSG ID > 0 -> MSG in DRAFT
-       // Move Folder to OUTBOX
+       /* If MSG ID > 0 -> MSG in DRAFT */
+       /* Move Folder to OUTBOX */
        if (pReqInfo->msgInfo.msgPort.valid == false) {
                pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
 
-       if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
-               err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
-               if (err != MSG_SUCCESS)
-                       return err;
+               if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
+                       err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
+                       if (err != MSG_SUCCESS)
+                               return err;
+               }
        }
 
        err = plg->submitReq(pReqInfo);
@@ -108,8 +124,11 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
 
        MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
 
-       if (sms_plg == NULL){
-               return MSG_ERR_NULL_POINTER;
+       if (sms_plg == NULL) {
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MSG_ERR("No plugin for %d type", MSG_SMS_TYPE);
+               return MSG_ERR_INVALID_PLUGIN_HANDLE;
        }
 
        int defaultNetworkSimId = 0;
@@ -121,50 +140,48 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
        } else if (pReqInfo->msgInfo.sim_idx != defaultNetworkSimId) {
                MSG_ERR("It is not default network SIM ID, request SIM=[%d], activated SIM=[%d]", pReqInfo->msgInfo.sim_idx, defaultNetworkSimId);
                return MSG_ERR_INVALID_PARAMETER;
-
        }
 
        MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
 
-       if(!plg)
-       {
+       if(!plg) {
                MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
                MSG_DEBUG("No Plugin for %d type", msgMainType);
 
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
        }
 
-       //      If MSG ID > 0 -> MSG in DRAFT
-       // Move Folder to OUTBOX
+       /*      If MSG ID > 0 -> MSG in DRAFT */
+       /* Move Folder to OUTBOX */
        /* reject_msg_support */
        MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
 
-       if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
-       {
-               char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
+       if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
+               char fileName[MSG_FILENAME_LEN_MAX+1] = {0};
 
-               // copy whole of MMS PDU filepath to msgData
-               strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
-               memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
-               snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%s", MSG_IPC_DATA_PATH, fileName);
+               /* copy whole of MMS PDU filepath to msgData */
+               strncpy(fileName, pReqInfo->msgInfo.msgData, MSG_FILENAME_LEN_MAX);
+               memset(pReqInfo->msgInfo.msgData, 0x00, sizeof(pReqInfo->msgInfo.msgData));
+               int wrn = snprintf(pReqInfo->msgInfo.msgData, sizeof(pReqInfo->msgInfo.msgData), "%s%s", MSG_IPC_DATA_PATH, fileName);
+               if(wrn<0)
+                       MSG_DEBUG("snprintf was failed");
 
                MSG_SEC_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
 
-               // submit request
+               /* submit request */
                err = plg->submitReq(pReqInfo);
 
-               if(err != MSG_SUCCESS)
-               {
+               if(err != MSG_SUCCESS) {
                        MSG_DEBUG("Update Network Status : [%d]", err);
-                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
                }
 
                return err;
-       }
-       else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
-       {
-               if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
+       } else if ((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS)) {
+               MSG_SEC_DEBUG("msgdata file path = [%s]", pReqInfo->msgInfo.msgData);
+
+               if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
                        MSG_DEBUG("Not New Message.");
                        pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
                        err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
@@ -174,21 +191,17 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
                        pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
                        err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
                }
-       }
-       else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
-       {
+       } else if (pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS) {
                msg_read_report_status_t readStatus;
 
                err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
                if(err != MSG_SUCCESS) {
-
                        MSG_INFO("msg id [%d], read report could NOT send [%d]", pReqInfo->msgInfo.msgId, err);
                        return err;
                }
 
                memcpy(&readStatus, pReqInfo->msgInfo.msgData, sizeof(msg_read_report_status_t));
                if (readStatus == MSG_READ_REPORT_REJECT_BY_USER) {
-
                        MSG_INFO("msg id [%d], read report reject by user", pReqInfo->msgInfo.msgId);
 
                        err = MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_NO_SENT);
@@ -203,39 +216,37 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
                pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
                pReqInfo->msgInfo.addressList = pRecipientList.recipientAddr;
 
-//                     for(int i = 0; i < pRecipientList.recipientCnt; i++)
-//                     {
-//                             pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
-//                             pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
-//                             pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
-//                             strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
-//                     }
+               /*
+               for(int i = 0; i < pRecipientList.recipientCnt; i++)
+               {
+                       pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
+                       pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
+                       pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
+                       strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
+               }
+               */
 
                char subject[MAX_SUBJECT_LEN+1];
 
                err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
-               if(err != MSG_SUCCESS)
+               if (err != MSG_SUCCESS)
                        MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
 
                strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
 
                err = plg->composeReadReport(&(pReqInfo->msgInfo));
-       }
-       else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
-       {
+       } else if (pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS) {
                MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
        }
 
        /* reject_msg_support */
 
-       if(err != MSG_SUCCESS)
-       {
+       if(err != MSG_SUCCESS) {
                MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
                return err;
        }
 
-       switch(pReqInfo->msgInfo.msgType.subType)
-       {
+       switch (pReqInfo->msgInfo.msgType.subType) {
                case MSG_SENDREQ_MMS:
                case MSG_FORWARD_MMS:
                        MsgDeleteFile(pReqInfo->msgInfo.msgData);
@@ -250,50 +261,43 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
                        break;
        }
 
-       // update content location from db
+       /* update content location from db */
        if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
                err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
        /* reject_msg_support */
-       else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
+       else if (pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
                err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
-       /* reject_msg_support */
 
-       // Check SIM is present or not
+       /* Check SIM is present or not */
        char keyName[MAX_VCONFKEY_NAME_LEN];
        memset(keyName, 0x00, sizeof(keyName));
        snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+       int tmpval = 0;
+       if (MsgSettingGetInt(keyName, &tmpval) != MSG_SUCCESS) {
+               MSG_INFO("MsgSettingGetInt() is failed");
+       }
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpval;
 
-       if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
-       {
+       if(simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                MSG_DEBUG("SIM is not present...");
                MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
 
                return MSG_ERR_NO_SIM;
        }
 
-       if(err == MSG_SUCCESS)
+       if (err == MSG_SUCCESS)
                err = plg->submitReq(pReqInfo);
 
-       if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
+       if (err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
                MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
 
-       if (err != MSG_SUCCESS)
-       {
-               if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
+       if (err != MSG_SUCCESS) {
+               if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
                        MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
                else
                        MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
        }
 
-
-       return err;
-}
-
-msg_error_t MsgCancelReq(msg_request_id_t reqId)
-{
-       msg_error_t err = MSG_SUCCESS;
-
        return err;
 }
 
@@ -307,21 +311,15 @@ msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status
 #ifdef MSG_MMS_KEEPCOPY
        MSG_SENDINGOPT_INFO_S sendOpt = {};
 
-       if (msgType.mainType == MSG_MMS_TYPE)
-       {
+       if (msgType.mainType == MSG_MMS_TYPE) {
                if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
-               {
                        bKeepCopy = sendOpt.bKeepCopy;
-               }
                else
-               {
-                       ret = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
-               }
+                       err = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
        }
 
-       // Move Msg to SENTBOX
-       if (Status == MSG_NETWORK_SEND_SUCCESS)
-       {
+       /* Move Msg to SENTBOX */
+       if (Status == MSG_NETWORK_SEND_SUCCESS) {
                MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and  bKeepCopy is [%d]", bKeepCopy);
                if (bKeepCopy == true)
                        err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
@@ -329,9 +327,8 @@ msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status
                        err = MsgStoDeleteMessage(MsgId, false);
        }
 #else
-       // Move Msg to SENTBOX
-       if (Status == MSG_NETWORK_SEND_SUCCESS)
-       {
+       /* Move Msg to SENTBOX */
+       if (Status == MSG_NETWORK_SEND_SUCCESS) {
                MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and  bKeepCopy is [%d]", bKeepCopy);
                if (bKeepCopy == true)
                        err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
@@ -347,10 +344,10 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 
        memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
 
-       // Copy Request ID
+       /* Copy Request ID */
        pDest->reqId = pSrc->reqId;
 
-       // Copy Msg Info
+       /* Copy Msg Info */
        pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
 
        pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
@@ -384,8 +381,7 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 
        pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
 
-       if (pDest->msgInfo.msgPort.valid == true)
-       {
+       if (pDest->msgInfo.msgPort.valid == true) {
                pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
                pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
        }
@@ -395,26 +391,21 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 
        strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
 
-       if (pDest->msgInfo.bTextSms == true)
-       {
+       if (pDest->msgInfo.bTextSms == true) {
                memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
                pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
        }
 
-       // Set Sending Info
+       /* Set Sending Info */
        pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
 
-       if (pDest->sendOptInfo.bSetting == true)
-       {
+       if (pDest->sendOptInfo.bSetting == true) {
                pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
                pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
 
-               if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
-               {
+               if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
                        pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
-               }
-               else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
-               {
+               } else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
                        pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
                        pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;