3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
35 #include "MsgUtilFile.h"
36 #include "MsgException.h"
37 #include "MsgGconfWrapper.h"
38 #include "MsgPluginManager.h"
39 #include "MsgStorageHandler.h"
40 #include "MsgSubmitHandler.h"
43 /*==================================================================================================
44 FUNCTION IMPLEMENTATION
45 ==================================================================================================*/
46 MSG_ERROR_T MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
48 MSG_ERROR_T err = MSG_SUCCESS;
52 pReqInfo->reqId = reqId;
55 MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
56 MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
57 MSG_DEBUG("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
58 MSG_DEBUG("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
59 MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
60 MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
61 MSG_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
63 MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
65 if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE)
67 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
68 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
69 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
71 err = MsgSubmitReqSMS(pReqInfo);
73 else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
75 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
76 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
77 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
78 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
79 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
81 err = MsgSubmitReqMMS(pReqInfo, bScheduled);
88 MSG_ERROR_T MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
90 MSG_ERROR_T err = MSG_SUCCESS;
92 // submit request based on msgType;
93 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
94 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
98 THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
101 MSG_REQUEST_INFO_S tmpInfo = {};
103 bool bReqSentStatus = false;
105 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++)
107 MsgCopyReqInfo(pReqInfo, i, &tmpInfo);
109 // If MSG ID > 0 -> MSG in DRAFT
110 // Move Folder to OUTBOX
111 if (pReqInfo->msgInfo.msgPort.valid == false)
113 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
115 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
117 err = MsgStoUpdateMessage(&(tmpInfo.msgInfo), &(tmpInfo.sendOptInfo));
120 if (err != MSG_SUCCESS)
122 MSG_DEBUG("MsgStoUpdateMessage() Fail");
127 if (i == (pReqInfo->msgInfo.nAddressCnt -1))
129 // Request Sent Status Callback
130 bReqSentStatus = true;
133 err = plg->submitReq(&tmpInfo, bReqSentStatus);
135 if (err != MSG_SUCCESS)
140 if (i == (pReqInfo->msgInfo.nAddressCnt -1))
143 pReqInfo->msgInfo.msgId = tmpInfo.msgInfo.msgId;
151 MSG_ERROR_T MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
153 MSG_ERROR_T err = MSG_SUCCESS;
155 MSG_RECIPIENTS_LIST_S pRecipientList;
157 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
158 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
162 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
163 MSG_DEBUG("No Plugin for %d type", msgMainType);
165 return MSG_ERR_INVALID_PLUGIN_HANDLE;
168 // If MSG ID > 0 -> MSG in DRAFT
169 // Move Folder to OUTBOX
170 /* reject_msg_support */
173 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
175 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
177 // copy whole of MMS PDU filepath to msgData
178 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
179 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
180 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
182 MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
185 plg->submitReq(pReqInfo, false);
187 if(err != MSG_SUCCESS)
189 MSG_DEBUG("Update Network Status : [%d]", err);
190 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
195 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
197 // update address list in the ase of existing message
198 if(pReqInfo->msgInfo.msgId > 0)
200 err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
202 if(err != MSG_SUCCESS)
203 MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
206 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
207 MSG_ADDRESS_INFO_S addrInfo = {0,};
210 err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
212 if (err == MSG_SUCCESS) {
213 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
214 //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
215 if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
217 MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
222 MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
225 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
226 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo), addrIdx);
228 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
231 MSG_DEBUG("New Message");
232 for(int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
233 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
234 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo), i);
235 //pReqInfo->msgInfo.msgId = 0;
238 if (pReqInfo->msgInfo.msgId != pReqInfo->msgInfo.referenceId) {
239 MSG_DEBUG("Add Multi-recipient Message");
240 //multi-recipient mms case
241 pReqInfo->msgInfo.msgId = pReqInfo->msgInfo.referenceId;
244 // pReqInfo->msgInfo.msgId = pReqInfo->msgInfo.referenceId;
246 else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
248 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
249 if(err != MSG_SUCCESS)
252 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
253 if(err != MSG_SUCCESS)
254 return MSG_ERR_PLUGIN_STORAGE;
256 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
258 for(int i = 0; i < pRecipientList.recipientCnt; i++)
260 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
261 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
262 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
263 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
266 char subject[MAX_SUBJECT_LEN+1];
268 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
269 if(err != MSG_SUCCESS)
270 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
272 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
274 err = plg->composeReadReport(&(pReqInfo->msgInfo));
276 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
278 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
282 /* reject_msg_support */
284 if(err != MSG_SUCCESS)
286 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
290 switch(pReqInfo->msgInfo.msgType.subType)
292 case MSG_SENDREQ_MMS:
293 case MSG_FORWARD_MMS:
294 MsgDeleteFile(pReqInfo->msgInfo.msgData);
295 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
296 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.referenceId);
299 case MSG_READREPLY_MMS:
300 case MSG_READRECIND_MMS:
301 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
302 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
308 // update content location from db
309 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
310 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
311 /* reject_msg_support */
312 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
313 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
314 /* reject_msg_support */
316 // Check SIM is present or not
317 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
319 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
321 MSG_DEBUG("SIM is not present...");
322 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
324 return MSG_ERR_NO_SIM;
327 if(err == MSG_SUCCESS)
328 err = plg->submitReq(pReqInfo, false);
330 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
331 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
333 if (err != MSG_SUCCESS)
335 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
336 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
338 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
346 MSG_ERROR_T MsgCancelReq(MSG_REQUEST_ID_T reqId)
348 MSG_ERROR_T err = MSG_SUCCESS;
354 MSG_ERROR_T MsgUpdateSentMsg(MSG_MESSAGE_ID_T MsgId, MSG_NETWORK_STATUS_T Status)
356 MSG_ERROR_T err = MSG_SUCCESS;
358 bool bKeepCopy = true;
360 // Move Msg to SENTBOX
361 if (Status == MSG_NETWORK_SEND_SUCCESS)
363 MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
364 if (bKeepCopy == true)
365 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
367 err = MsgStoDeleteMessage(MsgId, false);
374 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
378 memset(pDest, 0x00, sizeof(pDest));
381 pDest->reqId = pSrc->reqId;
384 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
385 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
387 pDest->msgInfo.referenceId = pSrc->msgInfo.referenceId;
389 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
390 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
391 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
393 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
395 pDest->msgInfo.nAddressCnt = 1;
397 pDest->msgInfo.addressList[0].threadId = pSrc->msgInfo.addressList[addrIdx].threadId;
398 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
399 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
400 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
401 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
402 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
404 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
405 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
407 pDest->msgInfo.scheduledTime = pSrc->msgInfo.scheduledTime;
408 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
409 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
410 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
411 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
412 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
413 pDest->msgInfo.priority = pSrc->msgInfo.priority;
414 pDest->msgInfo.direction = pSrc->msgInfo.direction;
416 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
418 if (pDest->msgInfo.msgPort.valid == true)
420 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
421 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
424 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
425 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
427 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
429 if (pDest->msgInfo.bTextSms == true)
431 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
432 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
436 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
438 if (pDest->sendOptInfo.bSetting == true)
440 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
441 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
443 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
445 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
447 else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
449 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
450 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
452 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
453 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
455 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
456 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
457 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;