2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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"
30 extern MsgDbHandler dbHandle;
32 /*==================================================================================================
33 FUNCTION IMPLEMENTATION
34 ==================================================================================================*/
35 msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
37 msg_error_t err = MSG_SUCCESS;
41 pReqInfo->reqId = reqId;
44 MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
45 MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
46 MSG_DEBUG("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
47 MSG_DEBUG("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
48 MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
49 MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
50 MSG_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
52 MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
54 if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE)
56 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
57 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
58 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
60 err = MsgSubmitReqSMS(pReqInfo);
62 else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
64 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
65 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
66 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
67 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
68 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
70 err = MsgSubmitReqMMS(pReqInfo);
77 msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
79 msg_error_t err = MSG_SUCCESS;
81 // submit request based on msgType;
82 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
83 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
86 MSG_DEBUG("No Plugin for %d type", mainType);
87 return MSG_ERR_UNKNOWN;
90 // If MSG ID > 0 -> MSG in DRAFT
91 // Move Folder to OUTBOX
92 if (pReqInfo->msgInfo.msgPort.valid == false) {
93 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
95 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
96 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
99 err = plg->submitReq(pReqInfo);
105 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
107 msg_error_t err = MSG_SUCCESS;
109 MSG_RECIPIENTS_LIST_S pRecipientList;
111 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
112 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
116 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
117 MSG_DEBUG("No Plugin for %d type", msgMainType);
119 return MSG_ERR_INVALID_PLUGIN_HANDLE;
122 // If MSG ID > 0 -> MSG in DRAFT
123 // Move Folder to OUTBOX
124 /* reject_msg_support */
125 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
127 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
129 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
131 // copy whole of MMS PDU filepath to msgData
132 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
133 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
134 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
136 MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
139 err = plg->submitReq(pReqInfo);
141 if(err != MSG_SUCCESS)
143 MSG_DEBUG("Update Network Status : [%d]", err);
144 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
149 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
151 // update address list in the ase of existing message
152 if(pReqInfo->msgInfo.msgId > 0)
154 err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
156 if(err != MSG_SUCCESS)
157 MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
160 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
161 MSG_ADDRESS_INFO_S addrInfo = {0,};
164 err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
166 if (err == MSG_SUCCESS) {
167 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
168 //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
169 if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
171 MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
176 MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
179 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
180 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
182 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
185 MSG_DEBUG("New Message");
186 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
187 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
188 //pReqInfo->msgInfo.msgId = 0;
191 else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
193 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
194 if(err != MSG_SUCCESS)
197 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
198 if(err != MSG_SUCCESS)
199 return MSG_ERR_PLUGIN_STORAGE;
201 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
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);
211 char subject[MAX_SUBJECT_LEN+1];
213 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
214 if(err != MSG_SUCCESS)
215 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
217 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
219 err = plg->composeReadReport(&(pReqInfo->msgInfo));
221 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
223 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
226 /* reject_msg_support */
228 if(err != MSG_SUCCESS)
230 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
234 switch(pReqInfo->msgInfo.msgType.subType)
236 case MSG_SENDREQ_MMS:
237 case MSG_FORWARD_MMS:
238 MsgDeleteFile(pReqInfo->msgInfo.msgData);
239 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
240 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
243 case MSG_READREPLY_MMS:
244 case MSG_READRECIND_MMS:
250 // update content location from db
251 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
252 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
253 /* reject_msg_support */
254 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
255 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
256 /* reject_msg_support */
258 // Check SIM is present or not
259 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
261 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
263 MSG_DEBUG("SIM is not present...");
264 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
266 return MSG_ERR_NO_SIM;
269 if(err == MSG_SUCCESS)
270 err = plg->submitReq(pReqInfo);
272 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
273 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
275 if (err != MSG_SUCCESS)
277 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
278 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
280 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
288 msg_error_t MsgCancelReq(msg_request_id_t reqId)
290 msg_error_t err = MSG_SUCCESS;
296 msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
298 msg_error_t err = MSG_SUCCESS;
300 bool bKeepCopy = true;
302 #ifdef MSG_MMS_KEEPCOPY
303 MSG_SENDINGOPT_INFO_S sendOpt = {};
305 if (msgType.mainType == MSG_MMS_TYPE)
307 if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
309 bKeepCopy = sendOpt.bKeepCopy;
313 ret = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
318 // Move Msg to SENTBOX
319 if (Status == MSG_NETWORK_SEND_SUCCESS)
321 MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
322 if (bKeepCopy == true)
323 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
325 err = MsgStoDeleteMessage(MsgId, false);
332 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
336 memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
339 pDest->reqId = pSrc->reqId;
342 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
344 pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
346 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
348 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
349 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
350 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
352 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
354 pDest->msgInfo.nAddressCnt = 1;
356 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
357 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
358 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
359 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
360 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
362 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
363 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
365 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
366 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
367 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
368 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
369 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
370 pDest->msgInfo.priority = pSrc->msgInfo.priority;
371 pDest->msgInfo.direction = pSrc->msgInfo.direction;
373 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
375 if (pDest->msgInfo.msgPort.valid == true)
377 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
378 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
381 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
382 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
384 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
386 if (pDest->msgInfo.bTextSms == true)
388 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
389 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
393 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
395 if (pDest->sendOptInfo.bSetting == true)
397 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
398 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
400 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
402 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
404 else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
406 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
407 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
409 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
410 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
412 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
413 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
414 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;