2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "MsgUtilFile.h"
22 #include "MsgUtilStorage.h"
23 #include "MsgException.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgPluginManager.h"
26 #include "MsgStorageHandler.h"
27 #include "MsgSubmitHandler.h"
31 /*==================================================================================================
32 FUNCTION IMPLEMENTATION
33 ==================================================================================================*/
34 msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
36 msg_error_t err = MSG_SUCCESS;
39 pReqInfo->reqId = reqId;
42 MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
43 MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
44 MSG_INFO("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
45 MSG_INFO("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
46 MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
47 MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
48 MSG_SEC_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
49 MSG_INFO("==== SIM Index = [%d] ====", pReqInfo->msgInfo.sim_idx);
51 MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
53 if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
54 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
55 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
56 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
58 err = MsgSubmitReqSMS(pReqInfo);
59 } else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
60 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
61 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
62 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
63 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
64 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
66 err = MsgSubmitReqMMS(pReqInfo);
73 msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
75 msg_error_t err = MSG_SUCCESS;
77 /* submit request based on msgType; */
78 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
79 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
82 MsgDbHandler *dbHandle = getDbHandle();
83 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
84 MSG_ERR("No plugin for %d type", mainType);
85 return MSG_ERR_INVALID_PLUGIN_HANDLE;
88 /* If MSG ID > 0 -> MSG in DRAFT */
89 /* Move Folder to OUTBOX */
90 if (pReqInfo->msgInfo.msgPort.valid == false) {
91 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
93 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
94 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
95 if (err != MSG_SUCCESS)
99 err = plg->submitReq(pReqInfo);
104 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
106 msg_error_t err = MSG_SUCCESS;
107 MsgDbHandler *dbHandle = getDbHandle();
108 MSG_RECIPIENTS_LIST_S pRecipientList;
110 MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
112 if (sms_plg == NULL) {
113 MsgDbHandler *dbHandle = getDbHandle();
114 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
115 MSG_ERR("No plugin for %d type", MSG_SMS_TYPE);
116 return MSG_ERR_INVALID_PLUGIN_HANDLE;
119 int defaultNetworkSimId = 0;
121 err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
122 if (err != MSG_SUCCESS) {
123 MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
125 } else if (pReqInfo->msgInfo.sim_idx != defaultNetworkSimId) {
126 MSG_ERR("It is not default network SIM ID, request SIM=[%d], activated SIM=[%d]", pReqInfo->msgInfo.sim_idx, defaultNetworkSimId);
127 return MSG_ERR_INVALID_PARAMETER;
130 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
131 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
134 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
135 MSG_DEBUG("No Plugin for %d type", msgMainType);
137 return MSG_ERR_INVALID_PLUGIN_HANDLE;
140 /* If MSG ID > 0 -> MSG in DRAFT */
141 /* Move Folder to OUTBOX */
142 /* reject_msg_support */
143 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
145 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
146 char fileName[MSG_FILENAME_LEN_MAX+1] = {0};
148 /* copy whole of MMS PDU filepath to msgData */
149 strncpy(fileName, pReqInfo->msgInfo.msgData, MSG_FILENAME_LEN_MAX);
150 memset(pReqInfo->msgInfo.msgData, 0x00, sizeof(pReqInfo->msgInfo.msgData));
151 snprintf(pReqInfo->msgInfo.msgData, sizeof(pReqInfo->msgInfo.msgData), "%s%s", MSG_IPC_DATA_PATH, fileName);
153 MSG_SEC_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
156 err = plg->submitReq(pReqInfo);
158 if(err != MSG_SUCCESS) {
159 MSG_DEBUG("Update Network Status : [%d]", err);
160 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
164 } else if ((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS)) {
165 MSG_SEC_DEBUG("msgdata file path = [%s]", pReqInfo->msgInfo.msgData);
167 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
168 MSG_DEBUG("Not New Message.");
169 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
170 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
172 MSG_DEBUG("New Message.");
173 pReqInfo->msgInfo.msgId = 0;
174 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
175 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
177 } else if (pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS) {
178 msg_read_report_status_t readStatus;
180 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
181 if(err != MSG_SUCCESS) {
182 MSG_INFO("msg id [%d], read report could NOT send [%d]", pReqInfo->msgInfo.msgId, err);
186 memcpy(&readStatus, pReqInfo->msgInfo.msgData, sizeof(msg_read_report_status_t));
187 if (readStatus == MSG_READ_REPORT_REJECT_BY_USER) {
188 MSG_INFO("msg id [%d], read report reject by user", pReqInfo->msgInfo.msgId);
190 err = MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_NO_SENT);
195 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
196 if(err != MSG_SUCCESS)
197 return MSG_ERR_PLUGIN_STORAGE;
199 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
200 pReqInfo->msgInfo.addressList = pRecipientList.recipientAddr;
203 for(int i = 0; i < pRecipientList.recipientCnt; i++)
205 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
206 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
207 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
208 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
212 char subject[MAX_SUBJECT_LEN+1];
214 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
215 if (err != MSG_SUCCESS)
216 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
218 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
220 err = plg->composeReadReport(&(pReqInfo->msgInfo));
221 } else if (pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS) {
222 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
225 /* reject_msg_support */
227 if(err != MSG_SUCCESS) {
228 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
232 switch (pReqInfo->msgInfo.msgType.subType) {
233 case MSG_SENDREQ_MMS:
234 case MSG_FORWARD_MMS:
235 MsgDeleteFile(pReqInfo->msgInfo.msgData);
236 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
237 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%d.mms", MSG_DATA_PATH, pReqInfo->msgInfo.msgId);
240 case MSG_READREPLY_MMS:
241 case MSG_READRECIND_MMS:
247 /* update content location from db */
248 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
249 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
250 /* reject_msg_support */
251 else if (pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
252 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
254 /* Check SIM is present or not */
255 char keyName[MAX_VCONFKEY_NAME_LEN];
256 memset(keyName, 0x00, sizeof(keyName));
257 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
258 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
260 if(simStatus == MSG_SIM_STATUS_NOT_FOUND) {
261 MSG_DEBUG("SIM is not present...");
262 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
264 return MSG_ERR_NO_SIM;
267 if (err == MSG_SUCCESS)
268 err = plg->submitReq(pReqInfo);
270 if (err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
271 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
273 if (err != MSG_SUCCESS) {
274 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
275 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
277 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
283 msg_error_t MsgCancelReq(msg_request_id_t reqId)
285 msg_error_t err = MSG_SUCCESS;
291 msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
293 msg_error_t err = MSG_SUCCESS;
295 bool bKeepCopy = true;
297 #ifdef MSG_MMS_KEEPCOPY
298 MSG_SENDINGOPT_INFO_S sendOpt = {};
300 if (msgType.mainType == MSG_MMS_TYPE) {
301 if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
302 bKeepCopy = sendOpt.bKeepCopy;
304 ret = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
307 /* Move Msg to SENTBOX */
308 if (Status == MSG_NETWORK_SEND_SUCCESS) {
309 MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
310 if (bKeepCopy == true)
311 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
313 err = MsgStoDeleteMessage(MsgId, false);
316 /* Move Msg to SENTBOX */
317 if (Status == MSG_NETWORK_SEND_SUCCESS) {
318 MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
319 if (bKeepCopy == true)
320 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
327 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
331 memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
333 /* Copy Request ID */
334 pDest->reqId = pSrc->reqId;
337 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
339 pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
341 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
343 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
344 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
345 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
347 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
349 pDest->msgInfo.nAddressCnt = 1;
351 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
352 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
353 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
354 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
355 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
357 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
358 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
360 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
361 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
362 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
363 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
364 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
365 pDest->msgInfo.priority = pSrc->msgInfo.priority;
366 pDest->msgInfo.direction = pSrc->msgInfo.direction;
368 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
370 if (pDest->msgInfo.msgPort.valid == true) {
371 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
372 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
375 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
376 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
378 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
380 if (pDest->msgInfo.bTextSms == true) {
381 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
382 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
385 /* Set Sending Info */
386 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
388 if (pDest->sendOptInfo.bSetting == true) {
389 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
390 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
392 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
393 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
394 } else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
395 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
396 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
398 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
399 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
401 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
402 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
403 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;