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);
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);
83 THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
85 // If MSG ID > 0 -> MSG in DRAFT
86 // Move Folder to OUTBOX
87 if (pReqInfo->msgInfo.msgPort.valid == false) {
88 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
90 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
91 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
94 err = plg->submitReq(pReqInfo);
100 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
102 msg_error_t err = MSG_SUCCESS;
104 MSG_RECIPIENTS_LIST_S pRecipientList;
106 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
107 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
111 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
112 MSG_DEBUG("No Plugin for %d type", msgMainType);
114 return MSG_ERR_INVALID_PLUGIN_HANDLE;
117 // If MSG ID > 0 -> MSG in DRAFT
118 // Move Folder to OUTBOX
119 /* reject_msg_support */
120 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
122 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
124 char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
126 // copy whole of MMS PDU filepath to msgData
127 strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
128 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
129 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
131 MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
134 plg->submitReq(pReqInfo);
136 if(err != MSG_SUCCESS)
138 MSG_DEBUG("Update Network Status : [%d]", err);
139 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
144 else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
146 // update address list in the ase of existing message
147 if(pReqInfo->msgInfo.msgId > 0)
149 err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
151 if(err != MSG_SUCCESS)
152 MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
155 if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
156 MSG_ADDRESS_INFO_S addrInfo = {0,};
159 err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
161 if (err == MSG_SUCCESS) {
162 for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
163 //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
164 if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
166 MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
171 MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
174 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
175 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
177 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
180 MSG_DEBUG("New Message");
181 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
182 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
183 //pReqInfo->msgInfo.msgId = 0;
186 else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
188 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
189 if(err != MSG_SUCCESS)
192 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
193 if(err != MSG_SUCCESS)
194 return MSG_ERR_PLUGIN_STORAGE;
196 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
198 for(int i = 0; i < pRecipientList.recipientCnt; i++)
200 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
201 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
202 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
203 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
206 char subject[MAX_SUBJECT_LEN+1];
208 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
209 if(err != MSG_SUCCESS)
210 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
212 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
214 err = plg->composeReadReport(&(pReqInfo->msgInfo));
216 else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
218 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
221 /* reject_msg_support */
223 if(err != MSG_SUCCESS)
225 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
229 switch(pReqInfo->msgInfo.msgType.subType)
231 case MSG_SENDREQ_MMS:
232 case MSG_FORWARD_MMS:
233 MsgDeleteFile(pReqInfo->msgInfo.msgData);
234 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
235 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
238 case MSG_READREPLY_MMS:
239 case MSG_READRECIND_MMS:
245 // update content location from db
246 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
247 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
248 /* reject_msg_support */
249 else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
250 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
251 /* reject_msg_support */
253 // Check SIM is present or not
254 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
256 if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
258 MSG_DEBUG("SIM is not present...");
259 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
261 return MSG_ERR_NO_SIM;
264 if(err == MSG_SUCCESS)
265 err = plg->submitReq(pReqInfo);
267 if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
268 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
270 if (err != MSG_SUCCESS)
272 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
273 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
275 MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
283 msg_error_t MsgCancelReq(msg_request_id_t reqId)
285 msg_error_t err = MSG_SUCCESS;
291 msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
293 msg_error_t err = MSG_SUCCESS;
295 bool bKeepCopy = true;
297 #ifdef MSG_MMS_KEEPCOPY
298 MSG_SENDINGOPT_INFO_S sendOpt = {};
300 if (msgType.mainType == MSG_MMS_TYPE)
302 if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
304 bKeepCopy = sendOpt.bKeepCopy;
308 ret = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
313 // Move Msg to SENTBOX
314 if (Status == MSG_NETWORK_SEND_SUCCESS)
316 MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
317 if (bKeepCopy == true)
318 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
320 err = MsgStoDeleteMessage(MsgId, false);
327 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
331 memset(pDest, 0x00, sizeof(pDest));
334 pDest->reqId = pSrc->reqId;
337 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
339 pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
341 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
343 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
344 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
345 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
347 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
349 pDest->msgInfo.nAddressCnt = 1;
351 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
352 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
353 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
354 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
355 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
357 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
358 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
360 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
361 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
362 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
363 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
364 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
365 pDest->msgInfo.priority = pSrc->msgInfo.priority;
366 pDest->msgInfo.direction = pSrc->msgInfo.direction;
368 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
370 if (pDest->msgInfo.msgPort.valid == true)
372 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
373 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
376 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
377 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
379 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
381 if (pDest->msgInfo.bTextSms == true)
383 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
384 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
388 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
390 if (pDest->sendOptInfo.bSetting == true)
392 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
393 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
395 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
397 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
399 else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
401 pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
402 pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;
404 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.type;
405 pDest->sendOptInfo.option.mmsSendOptInfo.expiryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.expiryTime.time;
407 pDest->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime = pSrc->sendOptInfo.option.mmsSendOptInfo.bUseDeliveryCustomTime;
408 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.type;
409 pDest->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time = pSrc->sendOptInfo.option.mmsSendOptInfo.deliveryTime.time;