2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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"
28 #include "MsgUtilFunction.h"
31 /*==================================================================================================
32 FUNCTION IMPLEMENTATION
33 ==================================================================================================*/
34 msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
36 msg_error_t err = MSG_SUCCESS;
39 pReqInfo->reqId = reqId;
42 if (msg_check_dpm_policy(pReqInfo->msgInfo.msgType.mainType) == false) {
43 MSG_DEBUG("Messaging is restricted by DPM policy.");
44 MsgDbHandler *dbHandle = getDbHandle();
45 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
46 if (pReqInfo->msgInfo.msgType.subType != MSG_RETRIEVE_MMS)
48 msg_syspopup_message(true);
50 /* retrieving popup */
51 msg_syspopup_message(false);
53 return MSG_ERR_DPM_RESTRICT;
56 MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
57 MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
58 MSG_INFO("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
59 MSG_INFO("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
60 MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
61 MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
62 MSG_SEC_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
63 MSG_INFO("==== SIM Index = [%d] ====", pReqInfo->msgInfo.sim_idx);
65 MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
67 if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
68 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
69 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
70 MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
72 err = MsgSubmitReqSMS(pReqInfo);
73 } else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
74 MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
75 MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
76 MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
77 MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
78 MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
80 err = MsgSubmitReqMMS(pReqInfo);
87 msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
89 msg_error_t err = MSG_SUCCESS;
91 /* submit request based on msgType; */
92 MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
93 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
96 MsgDbHandler *dbHandle = getDbHandle();
97 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
98 MSG_ERR("No plugin for %d type", mainType);
99 return MSG_ERR_INVALID_PLUGIN_HANDLE;
102 /* If MSG ID > 0 -> MSG in DRAFT */
103 /* Move Folder to OUTBOX */
104 if (pReqInfo->msgInfo.msgPort.valid == false) {
105 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
107 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
108 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
109 if (err != MSG_SUCCESS)
113 err = plg->submitReq(pReqInfo);
118 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
120 msg_error_t err = MSG_SUCCESS;
121 MsgDbHandler *dbHandle = getDbHandle();
122 MSG_RECIPIENTS_LIST_S pRecipientList;
124 MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
126 if (sms_plg == NULL) {
127 MsgDbHandler *dbHandle = getDbHandle();
128 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
129 MSG_ERR("No plugin for %d type", MSG_SMS_TYPE);
130 return MSG_ERR_INVALID_PLUGIN_HANDLE;
133 int defaultNetworkSimId = 0;
135 err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
136 if (err != MSG_SUCCESS) {
137 MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
139 } else if (pReqInfo->msgInfo.sim_idx != defaultNetworkSimId) {
140 MSG_ERR("It is not default network SIM ID, request SIM=[%d], activated SIM=[%d]", pReqInfo->msgInfo.sim_idx, defaultNetworkSimId);
141 return MSG_ERR_INVALID_PARAMETER;
144 MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
145 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
148 MsgStoUpdateNetworkStatus(dbHandle, &(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 */
157 MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
159 if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
160 char fileName[MSG_FILENAME_LEN_MAX+1] = {0};
162 /* copy whole of MMS PDU filepath to msgData */
163 strncpy(fileName, pReqInfo->msgInfo.msgData, MSG_FILENAME_LEN_MAX);
164 memset(pReqInfo->msgInfo.msgData, 0x00, sizeof(pReqInfo->msgInfo.msgData));
165 snprintf(pReqInfo->msgInfo.msgData, sizeof(pReqInfo->msgInfo.msgData), "%s%s", MSG_IPC_DATA_PATH, fileName);
167 MSG_SEC_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
170 err = plg->submitReq(pReqInfo);
172 if(err != MSG_SUCCESS) {
173 MSG_DEBUG("Update Network Status : [%d]", err);
174 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
178 } else if ((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS)) {
179 MSG_SEC_DEBUG("msgdata file path = [%s]", pReqInfo->msgInfo.msgData);
181 if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
182 MSG_DEBUG("Not New Message.");
183 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
184 err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
186 MSG_DEBUG("New Message.");
187 pReqInfo->msgInfo.msgId = 0;
188 pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
189 err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
191 } else if (pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS) {
192 msg_read_report_status_t readStatus;
194 err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
195 if(err != MSG_SUCCESS) {
196 MSG_INFO("msg id [%d], read report could NOT send [%d]", pReqInfo->msgInfo.msgId, err);
200 memcpy(&readStatus, pReqInfo->msgInfo.msgData, sizeof(msg_read_report_status_t));
201 if (readStatus == MSG_READ_REPORT_REJECT_BY_USER) {
202 MSG_INFO("msg id [%d], read report reject by user", pReqInfo->msgInfo.msgId);
204 err = MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_NO_SENT);
209 err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
210 if(err != MSG_SUCCESS)
211 return MSG_ERR_PLUGIN_STORAGE;
213 pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
214 pReqInfo->msgInfo.addressList = pRecipientList.recipientAddr;
217 for(int i = 0; i < pRecipientList.recipientCnt; i++)
219 pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
220 pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
221 pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
222 strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
226 char subject[MAX_SUBJECT_LEN+1];
228 err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
229 if (err != MSG_SUCCESS)
230 MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
232 strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
234 err = plg->composeReadReport(&(pReqInfo->msgInfo));
235 } else if (pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS) {
236 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
239 /* reject_msg_support */
241 if(err != MSG_SUCCESS) {
242 MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
246 switch (pReqInfo->msgInfo.msgType.subType) {
247 case MSG_SENDREQ_MMS:
248 case MSG_FORWARD_MMS:
249 MsgDeleteFile(pReqInfo->msgInfo.msgData);
250 memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
251 snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%d.mms", MSG_DATA_PATH, pReqInfo->msgInfo.msgId);
254 case MSG_READREPLY_MMS:
255 case MSG_READRECIND_MMS:
261 /* update content location from db */
262 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
263 err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
264 /* reject_msg_support */
265 else if (pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
266 err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
268 /* Check SIM is present or not */
269 char keyName[MAX_VCONFKEY_NAME_LEN];
270 memset(keyName, 0x00, sizeof(keyName));
271 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
273 if (MsgSettingGetInt(keyName, &tmpval) != MSG_SUCCESS) {
274 MSG_INFO("MsgSettingGetInt() is failed");
276 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpval;
278 if(simStatus == MSG_SIM_STATUS_NOT_FOUND) {
279 MSG_DEBUG("SIM is not present...");
280 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
282 return MSG_ERR_NO_SIM;
285 if (err == MSG_SUCCESS)
286 err = plg->submitReq(pReqInfo);
288 if (err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
289 MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
291 if (err != MSG_SUCCESS) {
292 if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
293 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
295 MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
302 msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
304 msg_error_t err = MSG_SUCCESS;
306 bool bKeepCopy = true;
308 #ifdef MSG_MMS_KEEPCOPY
309 MSG_SENDINGOPT_INFO_S sendOpt = {};
311 if (msgType.mainType == MSG_MMS_TYPE) {
312 if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
313 bKeepCopy = sendOpt.bKeepCopy;
315 err = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
318 /* Move Msg to SENTBOX */
319 if (Status == MSG_NETWORK_SEND_SUCCESS) {
320 MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
321 if (bKeepCopy == true)
322 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
324 err = MsgStoDeleteMessage(MsgId, false);
327 /* Move Msg to SENTBOX */
328 if (Status == MSG_NETWORK_SEND_SUCCESS) {
329 MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and bKeepCopy is [%d]", bKeepCopy);
330 if (bKeepCopy == true)
331 err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
338 void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *pDest)
342 memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
344 /* Copy Request ID */
345 pDest->reqId = pSrc->reqId;
348 pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
350 pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
352 pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
354 pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
355 pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
356 pDest->msgInfo.msgType.classType = pSrc->msgInfo.msgType.classType;
358 pDest->msgInfo.storageId = pSrc->msgInfo.storageId;
360 pDest->msgInfo.nAddressCnt = 1;
362 pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
363 pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
364 pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
365 strncpy(pDest->msgInfo.addressList[0].addressVal, pSrc->msgInfo.addressList[addrIdx].addressVal, MAX_ADDRESS_VAL_LEN);
366 strncpy(pDest->msgInfo.addressList[0].displayName, pSrc->msgInfo.addressList[addrIdx].displayName, MAX_DISPLAY_NAME_LEN);
368 strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
369 strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
371 pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
372 pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
373 pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
374 pDest->msgInfo.bRead = pSrc->msgInfo.bRead;
375 pDest->msgInfo.bProtected = pSrc->msgInfo.bProtected;
376 pDest->msgInfo.priority = pSrc->msgInfo.priority;
377 pDest->msgInfo.direction = pSrc->msgInfo.direction;
379 pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
381 if (pDest->msgInfo.msgPort.valid == true) {
382 pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
383 pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
386 pDest->msgInfo.bTextSms = pSrc->msgInfo.bTextSms;
387 pDest->msgInfo.dataSize = pSrc->msgInfo.dataSize;
389 strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
391 if (pDest->msgInfo.bTextSms == true) {
392 memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
393 pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
396 /* Set Sending Info */
397 pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
399 if (pDest->sendOptInfo.bSetting == true) {
400 pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
401 pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
403 if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
404 pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
405 } 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;