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.
18 #include "MsgException.h"
19 #include "MsgGconfWrapper.h"
20 #include "MsgUtilFile.h"
21 #include "MsgUtilFunction.h"
22 #include "MsgMmsMessage.h"
23 #include "MsgSerialize.h"
24 #include "MmsPluginDebug.h"
25 #include "MmsPluginTypes.h"
26 #include "MmsPluginMain.h"
27 #include "MmsPluginTransport.h"
28 #include "MmsPluginStorage.h"
29 #include "MmsPluginInternal.h"
30 #include "MmsPluginEventHandler.h"
31 #include "MmsPluginCodec.h"
33 /*==================================================================================================
34 FUNCTION IMPLEMENTATION
35 ==================================================================================================*/
36 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
38 if (pPluginHandle == NULL) {
39 MSG_DEBUG("MMS plugin: create handler error ");
40 return MSG_ERR_NULL_POINTER;
42 pPluginHandle->pfInitialize = MmsInitialize;
43 pPluginHandle->pfFinalize = MmsFinalize;
44 pPluginHandle->pfRegisterListener = MmsRegisterListener;
45 pPluginHandle->pfSubmitRequest = MmsSubmitRequest;
46 pPluginHandle->pfAddMessage = MmsAddMessage;
47 pPluginHandle->pfProcessReceivedInd = MmsProcessReceivedInd;
48 pPluginHandle->pfUpdateMessage = MmsUpdateMessage;
49 pPluginHandle->pfGetMmsMessage = MmsGetMmsMessage;
50 pPluginHandle->pfUpdateRejectStatus = MmsUpdateRejectStatus;
51 pPluginHandle->pfComposeReadReport = MmsComposeReadReport;
52 pPluginHandle->pfRestoreMsg = MmsRestoreMsg;
54 MSG_DEBUG("MMS plugin: create handler OK");
55 MSG_DEBUG("MMS plugin %p", pPluginHandle);
62 msg_error_t MmsPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
66 if (pPluginHandle != NULL) {
77 msg_error_t MmsInitialize()
81 /* remove temp files */
82 /* MsgMmsInitDir(); */
90 msg_error_t MmsFinalize()
100 msg_error_t MmsRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
104 MmsPluginEventHandler::instance()->registerListener(pListener);
112 msg_error_t MmsSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
117 if (msg_check_dpm_policy(pReqInfo->msgInfo.msgType.mainType) == false) {
118 MSG_DEBUG("Messaging is restricted by DPM policy.");
119 return MSG_ERR_DPM_RESTRICT;
122 MmsPluginTransport::instance()->submitRequest(pReqInfo);
123 } catch (MsgException& e) {
124 MSG_FATAL("%s", e.what());
126 if (e.errorCode() == MsgException::REQ_EXIST_ERROR)
129 return MSG_ERR_PLUGIN_TRANSPORT;
130 } catch (exception& e) {
131 MSG_FATAL("%s", e.what());
132 return MSG_ERR_PLUGIN_TRANSPORT;
141 msg_error_t MmsAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
146 MmsPluginStorage::instance()->addMessage(pMsgInfo, pSendOptInfo, pFileData);
147 } catch (MsgException& e) {
148 MSG_FATAL("%s", e.what());
149 return MSG_ERR_PLUGIN_TRANSPORT;
150 } catch (exception& e) {
151 MSG_FATAL("%s", e.what());
152 return MSG_ERR_PLUGIN_TRANSPORT;
161 msg_error_t MmsProcessReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
165 MSG_DEBUG("MMS Plugin ProcessReceivedInd");
168 MmsPluginInternal::instance()->processReceivedInd(pMsgInfo, pRequest, bReject);
169 } catch (MsgException& e) {
170 MSG_FATAL("%s", e.what());
171 return MSG_ERR_PLUGIN_TRANSPORT;
172 } catch (exception& e) {
173 MSG_FATAL("%s", e.what());
174 return MSG_ERR_PLUGIN_TRANSPORT;
183 msg_error_t MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
187 msg_error_t err = MSG_SUCCESS;
190 if (pMsgInfo->networkStatus == MSG_NETWORK_NOT_SEND || pMsgInfo->networkStatus == MSG_NETWORK_SENDING) { /* draft update */
191 err = MmsPluginStorage::instance()->updateMessage(pMsgInfo, pSendOptInfo, pFileData);
193 /* [Update Message ID & File path only in case of retrieve. Else update Message ID] */
194 if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) { /* retrieve conf */
195 err = MmsPluginStorage::instance()->updateConfMessage(pMsgInfo);
197 err = MmsPluginStorage::instance()->updateMsgServerID(pMsgInfo, pSendOptInfo); /* update send conf */
200 } catch (MsgException& e) {
201 MSG_FATAL("%s", e.what());
202 return MSG_ERR_PLUGIN_STORAGE;
203 } catch (exception& e) {
204 MSG_FATAL("%s", e.what());
205 return MSG_ERR_PLUGIN_STORAGE;
214 msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
218 msg_error_t err = MSG_SUCCESS;
221 err = MmsPluginStorage::instance()->getMessage(pMsg, pSendOptInfo, pDestMsg);
222 } catch (MsgException& e) {
223 MSG_FATAL("%s", e.what());
224 return MSG_ERR_PLUGIN_STORAGE;
225 } catch (exception& e) {
226 MSG_FATAL("%s", e.what());
227 return MSG_ERR_PLUGIN_STORAGE;
236 msg_error_t MmsUpdateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
240 msg_error_t err = MSG_SUCCESS;
243 char szTrID[MMS_TR_ID_LEN + 1] = {0x00};
246 err = MmsPluginStorage::instance()->getTrID(pMsgInfo, szTrID, sizeof(szTrID));
247 if (err != MSG_SUCCESS)
248 MSG_DEBUG("MmsPlgUpdRejectStatus : Get MMS Transacation id Failed");
250 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
251 if (MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed) != MSG_SUCCESS)
252 MSG_INFO("MsgSettingGetBool() is failed");
254 if (MmsPluginInternal::instance()->encodeNotifyRespInd(szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pMsgInfo->msgData)) {
255 MSG_DEBUG("MmsPlgUpdRejectStatus : Encode Notify Response Success");
256 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
257 pMsgInfo->bTextSms = true;
259 MSG_DEBUG("MmsPlgSetRejectStatus : Encode Notify Response Failed");
261 } catch (MsgException& e) {
262 MSG_FATAL("%s", e.what());
263 return MSG_ERR_PLUGIN_STORAGE;
264 } catch (exception& e) {
265 MSG_FATAL("%s", e.what());
266 return MSG_ERR_PLUGIN_STORAGE;
269 if (err != MSG_SUCCESS)
270 MSG_DEBUG("MmsPlgSetRejectStatus : Update MMS Message Failed");
278 msg_error_t MmsComposeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
283 MmsPluginStorage::instance()->composeReadReport(pMsgInfo);
284 } catch (MsgException& e) {
285 MSG_FATAL("%s", e.what());
286 return MSG_ERR_PLUGIN_STORAGE;
287 } catch (exception& e) {
288 MSG_FATAL("%s", e.what());
289 return MSG_ERR_PLUGIN_STORAGE;
297 /* FIXME::It used for kies but not now */
298 msg_error_t MmsRestoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char *pRcvBody, int rcvdBodyLen, char *filePath)
302 if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
306 MmsRegisterDecodeBuffer();
308 if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
309 MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
312 if (!MmsBinaryDecodeMsgHeader(pFile, rcvdBodyLen))
313 MSG_DEBUG("Decoding Header Failed \r\n");
318 MSG_DEBUG(":::%d :%s ", rcvdBodyLen, pRcvBody);
321 snprintf(filePath, MAX_FULL_PATH_SIZE, "%sBODY_%lu.DATA", MSG_DATA_PATH, random() % 1000000000 + 1);
323 return MSG_ERR_NULL_POINTER;
326 /* create temp file */
327 if (!MsgOpenCreateAndOverwriteFile(filePath, (char*)pRcvBody, rcvdBodyLen))
328 return MSG_ERR_PLUGIN_STORAGE;
336 msg_error_t MmsDeleteMessage(msg_message_id_t msgId)
341 MmsPluginStorage::instance()->deleteMmsMessage(msgId);
342 } catch (MsgException& e) {
343 MSG_FATAL("%s", e.what());
344 return MSG_ERR_PLUGIN_STORAGE;
345 } catch (exception& e) {
346 MSG_FATAL("%s", e.what());
347 return MSG_ERR_PLUGIN_STORAGE;