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)
55 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
56 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
57 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
59 err = MsgSubmitReqSMS(pReqInfo);
61 else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
63 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
64 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
65 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
66 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
67 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
69 err = MsgSubmitReqMMS(pReqInfo);
76 msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
78 msg_error_t err = MSG_SUCCESS;
80 // submit request based on msgType;
81 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
82 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
85 THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
87 // If MSG ID > 0 -> MSG in DRAFT
88 // Move Folder to OUTBOX
89 if (pReqInfo->msgInfo.msgPort.valid == false) {
90 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
92 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
93 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
96 err = plg->submitReq(pReqInfo);
101 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
103 msg_error_t err = MSG_SUCCESS;
104 MsgDbHandler *dbHandle = getDbHandle();
105 MSG_RECIPIENTS_LIST_S pRecipientList;
107 MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
109 if (sms_plg == NULL){
110 THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", MSG_SMS_TYPE);
113 int defaultNetworkSimId = 0;
115 err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
116 if (err != MSG_SUCCESS) {
117 MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
119 } else if (pReqInfo->msgInfo.sim_idx != defaultNetworkSimId) {
120 MSG_ERR("It is not default network SIM ID, request SIM=[%d], activated SIM=[%d]", pReqInfo->msgInfo.sim_idx, defaultNetworkSimId);
121 return MSG_ERR_INVALID_PARAMETER;
125 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
126 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
130 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
131 MSG_DEBUG("No Plugin for %d type", msgMainType);
133 return MSG_ERR_INVALID_PLUGIN_HANDLE;
136 // If MSG ID > 0 -> MSG in DRAFT
137 // Move Folder to OUTBOX
138 /* reject_msg_support */
139 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
141 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
143 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
145 // copy whole of MMS PDU filepath to msgData
146 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
147 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
148 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%s", MSG_IPC_DATA_PATH, fileName);
150 MSG_SEC_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
153 err = plg->submitReq(pReqInfo);
155 if(err != MSG_SUCCESS)
157 MSG_DEBUG("Update Network Status : [%d]", err);
158 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
163 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
165 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
166 MSG_DEBUG("Not New Message.");
167 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
168 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
170 MSG_DEBUG("New Message.");
171 pReqInfo->msgInfo.msgId = 0;
172 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
173 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
176 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) {
183 MSG_INFO("msg id [%d], read report could NOT send [%d]", pReqInfo->msgInfo.msgId, err);
187 memcpy(&readStatus, pReqInfo->msgInfo.msgData, sizeof(msg_read_report_status_t));
188 if (readStatus == MSG_READ_REPORT_REJECT_BY_USER) {
190 MSG_INFO("msg id [%d], read report reject by user", pReqInfo->msgInfo.msgId);
192 err = MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_NO_SENT);
197 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
198 if(err != MSG_SUCCESS)
199 return MSG_ERR_PLUGIN_STORAGE;
201 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
202 pReqInfo->msgInfo.addressList = pRecipientList.recipientAddr;
204 // for(int i = 0; i < pRecipientList.recipientCnt; i++)
206 // pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
207 // pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
208 // pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
209 // 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));
222 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
224 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
227 /* reject_msg_support */
229 if(err != MSG_SUCCESS)
231 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
235 switch(pReqInfo->msgInfo.msgType.subType)
237 case MSG_SENDREQ_MMS:
238 case MSG_FORWARD_MMS:
239 MsgDeleteFile(pReqInfo->msgInfo.msgData);
240 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
241 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%d.mms", MSG_DATA_PATH, pReqInfo->msgInfo.msgId);
244 case MSG_READREPLY_MMS:
245 case MSG_READRECIND_MMS:
251 // update content location from db
252 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
253 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
254 /* reject_msg_support */
255 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
256 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
257 /* reject_msg_support */
259 // Check SIM is present or not
260 char keyName[MAX_VCONFKEY_NAME_LEN];
261 memset(keyName, 0x00, sizeof(keyName));
262 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
263 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
265 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
267 MSG_DEBUG("SIM is not present...");
268 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
270 return MSG_ERR_NO_SIM;
273 if(err == MSG_SUCCESS)
274 err = plg->submitReq(pReqInfo);
276 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
277 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
279 if (err != MSG_SUCCESS)
281 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
282 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
284 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
291 msg_error_t MsgCancelReq(msg_request_id_t reqId)
293 msg_error_t err = MSG_SUCCESS;
299 msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
301 msg_error_t err = MSG_SUCCESS;
303 bool bKeepCopy = true;
305 #ifdef MSG_MMS_KEEPCOPY
306 MSG_SENDINGOPT_INFO_S sendOpt = {};
308 if (msgType.mainType == MSG_MMS_TYPE)
310 if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
312 bKeepCopy = sendOpt.bKeepCopy;
316 ret = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
321 // Move Msg to SENTBOX
322 if (Status == MSG_NETWORK_SEND_SUCCESS)
324 MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
325 if (bKeepCopy == true)
326 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
328 err = MsgStoDeleteMessage(MsgId, false);
335 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
339 memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
342 pDest->reqId = pSrc->reqId;
345 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
347 pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
349 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
351 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
352 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
353 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
355 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
357 pDest->msgInfo.nAddressCnt = 1;
359 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
360 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
361 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
362 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
363 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
365 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
366 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
368 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
369 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
370 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
371 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
372 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
373 pDest->msgInfo.priority = pSrc->msgInfo.priority;
374 pDest->msgInfo.direction = pSrc->msgInfo.direction;
376 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
378 if (pDest->msgInfo.msgPort.valid == true)
380 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
381 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
384 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
385 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
387 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
389 if (pDest->msgInfo.bTextSms == true)
391 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
392 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
396 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
398 if (pDest->sendOptInfo.bSetting == true)
400 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
401 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
403 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
405 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
407 else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
409 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
410 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
412 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
413 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
415 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
416 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
417 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;