2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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 "MsgException.h"
23 #include "MsgGconfWrapper.h"
24 #include "MsgPluginManager.h"
25 #include "MsgStorageHandler.h"
26 #include "MsgSubmitHandler.h"
29 /*==================================================================================================
30 FUNCTION IMPLEMENTATION
31 ==================================================================================================*/
32 MSG_ERROR_T MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
34 MSG_ERROR_T err = MSG_SUCCESS;
38 pReqInfo->reqId = reqId;
41 MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
42 MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
43 MSG_DEBUG("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
44 MSG_DEBUG("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
45 MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
46 MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
47 MSG_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
49 MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
51 if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE)
53 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
54 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
55 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
57 err = MsgSubmitReqSMS(pReqInfo);
59 else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
61 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
62 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
63 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
64 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
65 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
67 err = MsgSubmitReqMMS(pReqInfo, bScheduled);
74 MSG_ERROR_T MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
76 MSG_ERROR_T err = MSG_SUCCESS;
78 // submit request based on msgType;
79 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
80 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
84 THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
87 MSG_REQUEST_INFO_S tmpInfo = {};
89 bool bReqSentStatus = false;
91 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++)
93 MsgCopyReqInfo(pReqInfo, i, &tmpInfo);
95 // If MSG ID > 0 -> MSG in DRAFT
96 // Move Folder to OUTBOX
97 if (pReqInfo->msgInfo.msgPort.valid == false)
99 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
101 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
103 err = MsgStoUpdateMessage(&(tmpInfo.msgInfo), &(tmpInfo.sendOptInfo));
106 if (err != MSG_SUCCESS)
108 MSG_DEBUG("MsgStoUpdateMessage() Fail");
113 if (i == (pReqInfo->msgInfo.nAddressCnt -1))
115 // Request Sent Status Callback
116 bReqSentStatus = true;
119 err = plg->submitReq(&tmpInfo, bReqSentStatus);
121 if (err != MSG_SUCCESS)
126 if (i == (pReqInfo->msgInfo.nAddressCnt -1))
129 pReqInfo->msgInfo.msgId = tmpInfo.msgInfo.msgId;
137 MSG_ERROR_T MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
139 MSG_ERROR_T err = MSG_SUCCESS;
141 MSG_RECIPIENTS_LIST_S pRecipientList;
143 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
144 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
148 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
149 MSG_DEBUG("No Plugin for %d type", msgMainType);
151 return MSG_ERR_INVALID_PLUGIN_HANDLE;
154 // If MSG ID > 0 -> MSG in DRAFT
155 // Move Folder to OUTBOX
156 /* reject_msg_support */
159 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
161 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
163 // copy whole of MMS PDU filepath to msgData
164 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
165 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
166 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
168 MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
171 plg->submitReq(pReqInfo, false);
173 if(err != MSG_SUCCESS)
175 MSG_DEBUG("Update Network Status : [%d]", err);
176 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
181 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
183 // update address list in the ase of existing message
184 if(pReqInfo->msgInfo.msgId > 0)
186 err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
188 if(err != MSG_SUCCESS)
189 MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
192 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
193 MSG_ADDRESS_INFO_S addrInfo = {0,};
196 err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
198 if (err == MSG_SUCCESS) {
199 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
200 //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
201 if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
203 MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
208 MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
211 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
212 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo), addrIdx);
214 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
217 MSG_DEBUG("New Message");
218 for(int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
219 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
220 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo), i);
221 //pReqInfo->msgInfo.msgId = 0;
224 if (pReqInfo->msgInfo.msgId != pReqInfo->msgInfo.referenceId) {
225 MSG_DEBUG("Add Multi-recipient Message");
226 //multi-recipient mms case
227 pReqInfo->msgInfo.msgId = pReqInfo->msgInfo.referenceId;
230 // pReqInfo->msgInfo.msgId = pReqInfo->msgInfo.referenceId;
232 else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
234 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
235 if(err != MSG_SUCCESS)
238 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
239 if(err != MSG_SUCCESS)
240 return MSG_ERR_PLUGIN_STORAGE;
242 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
244 for(int i = 0; i < pRecipientList.recipientCnt; i++)
246 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
247 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
248 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
249 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
252 char subject[MAX_SUBJECT_LEN+1];
254 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
255 if(err != MSG_SUCCESS)
256 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
258 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
260 err = plg->composeReadReport(&(pReqInfo->msgInfo));
262 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
264 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
268 /* reject_msg_support */
270 if(err != MSG_SUCCESS)
272 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
276 switch(pReqInfo->msgInfo.msgType.subType)
278 case MSG_SENDREQ_MMS:
279 case MSG_FORWARD_MMS:
280 MsgDeleteFile(pReqInfo->msgInfo.msgData);
281 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
282 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.referenceId);
285 case MSG_READREPLY_MMS:
286 case MSG_READRECIND_MMS:
287 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
288 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
294 // update content location from db
295 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
296 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
297 /* reject_msg_support */
298 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
299 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
300 /* reject_msg_support */
302 // Check SIM is present or not
303 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
305 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
307 MSG_DEBUG("SIM is not present...");
308 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
310 return MSG_ERR_NO_SIM;
313 if(err == MSG_SUCCESS)
314 err = plg->submitReq(pReqInfo, false);
316 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
317 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
319 if (err != MSG_SUCCESS)
321 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
322 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
324 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
332 MSG_ERROR_T MsgCancelReq(MSG_REQUEST_ID_T reqId)
334 MSG_ERROR_T err = MSG_SUCCESS;
340 MSG_ERROR_T MsgUpdateSentMsg(MSG_MESSAGE_ID_T MsgId, MSG_NETWORK_STATUS_T Status)
342 MSG_ERROR_T err = MSG_SUCCESS;
344 bool bKeepCopy = true;
346 // Move Msg to SENTBOX
347 if (Status == MSG_NETWORK_SEND_SUCCESS)
349 MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
350 if (bKeepCopy == true)
351 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
353 err = MsgStoDeleteMessage(MsgId, false);
360 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
364 memset(pDest, 0x00, sizeof(pDest));
367 pDest->reqId = pSrc->reqId;
370 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
371 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
373 pDest->msgInfo.referenceId = pSrc->msgInfo.referenceId;
375 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
376 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
377 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
379 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
381 pDest->msgInfo.nAddressCnt = 1;
383 pDest->msgInfo.addressList[0].threadId = pSrc->msgInfo.addressList[addrIdx].threadId;
384 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
385 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
386 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
387 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
388 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
390 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
391 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
393 pDest->msgInfo.scheduledTime = pSrc->msgInfo.scheduledTime;
394 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
395 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
396 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
397 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
398 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
399 pDest->msgInfo.priority = pSrc->msgInfo.priority;
400 pDest->msgInfo.direction = pSrc->msgInfo.direction;
402 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
404 if (pDest->msgInfo.msgPort.valid == true)
406 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
407 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
410 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
411 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
413 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
415 if (pDest->msgInfo.bTextSms == true)
417 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
418 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
422 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
424 if (pDest->sendOptInfo.bSetting == true)
426 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
427 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
429 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
431 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
433 else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
435 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
436 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
438 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
439 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
441 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
442 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
443 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;