4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include "MsgUtilFile.h"
25 #include "MsgUtilStorage.h"
26 #include "MsgException.h"
27 #include "MsgGconfWrapper.h"
28 #include "MsgPluginManager.h"
29 #include "MsgStorageHandler.h"
30 #include "MsgSubmitHandler.h"
33 extern MsgDbHandler dbHandle;
35 /*==================================================================================================
36 FUNCTION IMPLEMENTATION
37 ==================================================================================================*/
38 msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
40 msg_error_t err = MSG_SUCCESS;
44 pReqInfo->reqId = reqId;
47 MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
48 MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
49 MSG_DEBUG("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
50 MSG_DEBUG("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
51 MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
52 MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
53 MSG_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
55 MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
57 if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE)
59 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
60 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
61 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
63 err = MsgSubmitReqSMS(pReqInfo);
65 else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
67 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
68 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
69 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
70 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
71 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
73 err = MsgSubmitReqMMS(pReqInfo);
80 msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
82 msg_error_t err = MSG_SUCCESS;
84 // submit request based on msgType;
85 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
86 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
89 MSG_DEBUG("No Plugin for %d type", mainType);
90 return MSG_ERR_UNKNOWN;
93 // If MSG ID > 0 -> MSG in DRAFT
94 // Move Folder to OUTBOX
95 if (pReqInfo->msgInfo.msgPort.valid == false) {
96 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
98 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
99 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
102 err = plg->submitReq(pReqInfo);
108 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
110 msg_error_t err = MSG_SUCCESS;
112 MSG_RECIPIENTS_LIST_S pRecipientList;
114 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
115 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
119 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
120 MSG_DEBUG("No Plugin for %d type", msgMainType);
122 return MSG_ERR_INVALID_PLUGIN_HANDLE;
125 // If MSG ID > 0 -> MSG in DRAFT
126 // Move Folder to OUTBOX
127 /* reject_msg_support */
128 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
130 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
132 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
134 // copy whole of MMS PDU filepath to msgData
135 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
136 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
137 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s/%s", MSG_IPC_DATA_PATH, fileName);
139 MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
142 err = plg->submitReq(pReqInfo);
144 if(err != MSG_SUCCESS)
146 MSG_DEBUG("Update Network Status : [%d]", err);
147 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
152 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
154 // update address list in the ase of existing message
155 if(pReqInfo->msgInfo.msgId > 0)
157 err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
159 if(err != MSG_SUCCESS)
160 MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
163 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
164 MSG_ADDRESS_INFO_S addrInfo = {0,};
167 err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
169 if (err == MSG_SUCCESS) {
170 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
171 //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
172 if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
174 MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
179 MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
182 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
183 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
185 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
188 MSG_DEBUG("New Message");
189 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
190 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
191 //pReqInfo->msgInfo.msgId = 0;
194 else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
196 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
197 if(err != MSG_SUCCESS)
200 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
201 if(err != MSG_SUCCESS)
202 return MSG_ERR_PLUGIN_STORAGE;
204 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
206 for(int i = 0; i < pRecipientList.recipientCnt; i++)
208 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
209 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
210 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
211 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
214 char subject[MAX_SUBJECT_LEN+1];
216 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
217 if(err != MSG_SUCCESS)
218 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
220 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
222 err = plg->composeReadReport(&(pReqInfo->msgInfo));
224 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
226 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
229 /* reject_msg_support */
231 if(err != MSG_SUCCESS)
233 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
237 switch(pReqInfo->msgInfo.msgType.subType)
239 case MSG_SENDREQ_MMS:
240 case MSG_FORWARD_MMS:
241 MsgDeleteFile(pReqInfo->msgInfo.msgData);
242 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
243 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s/%d.mms", MSG_DATA_PATH, pReqInfo->msgInfo.msgId);
246 case MSG_READREPLY_MMS:
247 case MSG_READRECIND_MMS:
253 // update content location from db
254 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
255 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
256 /* reject_msg_support */
257 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
258 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
259 /* reject_msg_support */
261 // Check SIM is present or not
262 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
264 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
266 MSG_DEBUG("SIM is not present...");
267 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
269 return MSG_ERR_NO_SIM;
272 if(err == MSG_SUCCESS)
273 err = plg->submitReq(pReqInfo);
275 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
276 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
278 if (err != MSG_SUCCESS)
280 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
281 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
283 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;