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 "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 THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
88 // If MSG ID > 0 -> MSG in DRAFT
89 // Move Folder to OUTBOX
90 if (pReqInfo->msgInfo.msgPort.valid == false) {
91 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
93 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
94 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
97 err = plg->submitReq(pReqInfo);
103 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
105 msg_error_t err = MSG_SUCCESS;
107 MSG_RECIPIENTS_LIST_S pRecipientList;
109 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
110 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
114 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
115 MSG_DEBUG("No Plugin for %d type", msgMainType);
117 return MSG_ERR_INVALID_PLUGIN_HANDLE;
120 // If MSG ID > 0 -> MSG in DRAFT
121 // Move Folder to OUTBOX
122 /* reject_msg_support */
123 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
125 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
127 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
129 // copy whole of MMS PDU filepath to msgData
130 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
131 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
132 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
134 MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
137 plg->submitReq(pReqInfo);
139 if(err != MSG_SUCCESS)
141 MSG_DEBUG("Update Network Status : [%d]", err);
142 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
147 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
149 // update address list in the ase of existing message
150 if(pReqInfo->msgInfo.msgId > 0)
152 err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
154 if(err != MSG_SUCCESS)
155 MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
158 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
159 MSG_ADDRESS_INFO_S addrInfo = {0,};
162 err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
164 if (err == MSG_SUCCESS) {
165 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
166 //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
167 if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
169 MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
174 MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
177 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
178 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
180 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
183 MSG_DEBUG("New Message");
184 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
185 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
186 //pReqInfo->msgInfo.msgId = 0;
189 else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
191 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
192 if(err != MSG_SUCCESS)
195 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
196 if(err != MSG_SUCCESS)
197 return MSG_ERR_PLUGIN_STORAGE;
199 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
201 for(int i = 0; i < pRecipientList.recipientCnt; i++)
203 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
204 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
205 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
206 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
209 char subject[MAX_SUBJECT_LEN+1];
211 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
212 if(err != MSG_SUCCESS)
213 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
215 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
217 err = plg->composeReadReport(&(pReqInfo->msgInfo));
219 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
221 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
224 /* reject_msg_support */
226 if(err != MSG_SUCCESS)
228 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
232 switch(pReqInfo->msgInfo.msgType.subType)
234 case MSG_SENDREQ_MMS:
235 case MSG_FORWARD_MMS:
236 MsgDeleteFile(pReqInfo->msgInfo.msgData);
237 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
238 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
241 case MSG_READREPLY_MMS:
242 case MSG_READRECIND_MMS:
248 // update content location from db
249 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
250 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
251 /* reject_msg_support */
252 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
253 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
254 /* reject_msg_support */
256 // Check SIM is present or not
257 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
259 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
261 MSG_DEBUG("SIM is not present...");
262 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
264 return MSG_ERR_NO_SIM;
267 if(err == MSG_SUCCESS)
268 err = plg->submitReq(pReqInfo);
270 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
271 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
273 if (err != MSG_SUCCESS)
275 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
276 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
278 MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
286 msg_error_t MsgCancelReq(msg_request_id_t reqId)
288 msg_error_t err = MSG_SUCCESS;
294 msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
296 msg_error_t err = MSG_SUCCESS;
298 bool bKeepCopy = true;
300 #ifdef MSG_MMS_KEEPCOPY
301 MSG_SENDINGOPT_INFO_S sendOpt = {};
303 if (msgType.mainType == MSG_MMS_TYPE)
305 if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
307 bKeepCopy = sendOpt.bKeepCopy;
311 ret = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
316 // Move Msg to SENTBOX
317 if (Status == MSG_NETWORK_SEND_SUCCESS)
319 MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
320 if (bKeepCopy == true)
321 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
323 err = MsgStoDeleteMessage(MsgId, false);
330 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
334 memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
337 pDest->reqId = pSrc->reqId;
340 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
342 pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
344 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
346 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
347 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
348 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
350 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
352 pDest->msgInfo.nAddressCnt = 1;
354 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
355 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
356 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
357 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
358 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
360 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
361 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
363 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
364 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
365 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
366 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
367 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
368 pDest->msgInfo.priority = pSrc->msgInfo.priority;
369 pDest->msgInfo.direction = pSrc->msgInfo.direction;
371 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
373 if (pDest->msgInfo.msgPort.valid == true)
375 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
376 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
379 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
380 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
382 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
384 if (pDest->msgInfo.bTextSms == true)
386 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
387 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
391 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
393 if (pDest->sendOptInfo.bSetting == true)
395 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
396 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
398 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
400 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
402 else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
404 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
405 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
407 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
408 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
410 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
411 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
412 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;