2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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.
18 #include "MsgException.h"
19 #include "MsgGconfWrapper.h"
20 #include "MsgUtilFile.h"
21 #include "MmsPluginDebug.h"
22 #include "MmsPluginTypes.h"
23 #include "MmsPluginMain.h"
24 #include "MmsPluginTransport.h"
25 #include "MmsPluginStorage.h"
26 #include "MmsPluginInternal.h"
27 #include "MmsPluginEventHandler.h"
28 #include "MmsPluginCodec.h"
30 /*==================================================================================================
31 FUNCTION IMPLEMENTATION
32 ==================================================================================================*/
33 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
35 if (pPluginHandle == NULL) {
36 MSG_DEBUG("MMS plugin: create handler error ");
37 return MSG_ERR_NULL_POINTER;
39 pPluginHandle->pfInitialize = MmsInitialize;
40 pPluginHandle->pfFinalize = MmsFinalize;
41 pPluginHandle->pfRegisterListener = MmsRegisterListener;
42 pPluginHandle->pfSubmitRequest = MmsSubmitRequest;
43 pPluginHandle->pfAddMessage = MmsAddMessage;
44 pPluginHandle->pfProcessReceivedInd = MmsProcessReceivedInd;
45 pPluginHandle->pfUpdateMessage = MmsUpdateMessage;
46 pPluginHandle->pfGetMmsMessage = MmsGetMmsMessage;
47 pPluginHandle->pfUpdateRejectStatus = MmsUpdateRejectStatus;
48 pPluginHandle->pfComposeReadReport = MmsComposeReadReport;
49 pPluginHandle->pfRestoreMsg = MmsRestoreMsg;
51 MSG_DEBUG("MMS plugin: create handler OK");
52 MSG_DEBUG ("MMS plugin %p", pPluginHandle);
59 msg_error_t MmsPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
63 if (pPluginHandle != NULL) {
74 msg_error_t MmsInitialize()
87 msg_error_t MmsFinalize()
97 msg_error_t MmsRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
101 MmsPluginEventHandler::instance()->registerListener(pListener);
109 msg_error_t MmsSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
114 MmsPluginTransport::instance()->submitRequest(pReqInfo);
115 } catch (MsgException& e) {
116 MSG_FATAL("%s", e.what());
117 return MSG_ERR_PLUGIN_TRANSPORT;
118 } catch (exception& e) {
119 MSG_FATAL("%s", e.what());
120 return MSG_ERR_PLUGIN_TRANSPORT;
129 msg_error_t MmsAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
134 MmsPluginStorage::instance()->addMessage(pMsgInfo, pSendOptInfo, pFileData);
135 } catch (MsgException& e) {
136 MSG_FATAL("%s", e.what());
137 return MSG_ERR_PLUGIN_TRANSPORT;
138 } catch (exception& e) {
139 MSG_FATAL("%s", e.what());
140 return MSG_ERR_PLUGIN_TRANSPORT;
149 msg_error_t MmsProcessReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
153 MSG_DEBUG("MMS Plugin ProcessReceivedInd");
156 MmsPluginInternal::instance()->processReceivedInd(pMsgInfo, pRequest, bReject);
157 } catch (MsgException& e) {
158 MSG_FATAL("%s", e.what());
159 return MSG_ERR_PLUGIN_TRANSPORT;
160 } catch (exception& e) {
161 MSG_FATAL("%s", e.what());
162 return MSG_ERR_PLUGIN_TRANSPORT;
171 msg_error_t MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
175 msg_error_t err = MSG_SUCCESS;
178 if (pMsgInfo->networkStatus == MSG_NETWORK_NOT_SEND || pMsgInfo->networkStatus == MSG_NETWORK_SENDING) {
179 err = MmsPluginStorage::instance()->updateMessage(pMsgInfo, pSendOptInfo, pFileData);
181 //[Update Message ID & File path only in case of retrieve. Else update Message ID]
182 if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
183 err = MmsPluginStorage::instance()->updateConfMessage(pMsgInfo);
185 err = MmsPluginStorage::instance()->updateMsgServerID(pMsgInfo, pSendOptInfo);
188 } catch (MsgException& e) {
189 MSG_FATAL("%s", e.what());
190 return MSG_ERR_PLUGIN_STORAGE;
191 } catch (exception& e) {
192 MSG_FATAL("%s", e.what());
193 return MSG_ERR_PLUGIN_STORAGE;
202 msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg)
206 msg_error_t err = MSG_SUCCESS;
209 err = MmsPluginStorage::instance()->plgGetMmsMessage(pMsg, pSendOptInfo, pDestMsg);
210 } catch (MsgException& e) {
211 MSG_FATAL("%s", e.what());
212 return MSG_ERR_PLUGIN_STORAGE;
213 } catch (exception& e) {
214 MSG_FATAL("%s", e.what());
215 return MSG_ERR_PLUGIN_STORAGE;
224 msg_error_t MmsUpdateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
228 msg_error_t err = MSG_SUCCESS;
231 char szTrID[MMS_TR_ID_LEN + 1] = {0x00};
234 err = MmsPluginStorage::instance()->getTrID(pMsgInfo,szTrID,sizeof(szTrID));
235 if (err != MSG_SUCCESS)
236 MSG_DEBUG("MmsPlgUpdRejectStatus : Get MMS Transacation id Failed");
238 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
239 MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed);
240 if (MmsPluginInternal::instance()->encodeNotifyRespInd(szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pMsgInfo->msgData)) {
241 MSG_DEBUG("MmsPlgUpdRejectStatus : Encode Notify Response Success");
242 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
243 pMsgInfo->bTextSms = true;
245 MSG_DEBUG("MmsPlgSetRejectStatus : Encode Notify Response Failed");
246 } catch (MsgException& e) {
247 MSG_FATAL("%s", e.what());
248 return MSG_ERR_PLUGIN_STORAGE;
249 } catch (exception& e) {
250 MSG_FATAL("%s", e.what());
251 return MSG_ERR_PLUGIN_STORAGE;
254 if (err != MSG_SUCCESS)
255 MSG_DEBUG("MmsPlgSetRejectStatus : Update MMS Message Failed");
263 msg_error_t MmsComposeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
268 MmsPluginStorage::instance()->composeReadReport(pMsgInfo);
269 } catch (MsgException& e) {
270 MSG_FATAL("%s", e.what());
271 return MSG_ERR_PLUGIN_STORAGE;
272 } catch (exception& e) {
273 MSG_FATAL("%s", e.what());
274 return MSG_ERR_PLUGIN_STORAGE;
283 msg_error_t MmsRestoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char *pRcvBody, int rcvdBodyLen, char *filePath)
287 if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
291 MmsRegisterDecodeBuffer();
293 if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
294 MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
297 if (!MmsBinaryDecodeMsgHeader(pFile, rcvdBodyLen))
298 MSG_DEBUG("Decoding Header Failed \r\n");
303 MSG_DEBUG(":::%d :%s ",rcvdBodyLen, pRcvBody);
306 snprintf(filePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"BODY_%lu.DATA", random() % 1000000000 + 1);
308 return MSG_ERR_NULL_POINTER;
312 if (!MsgOpenCreateAndOverwriteFile(filePath, (char*)pRcvBody,rcvdBodyLen))
313 return MSG_ERR_PLUGIN_STORAGE;
321 msg_error_t MmsDeleteMessage(msg_message_id_t msgId)
326 MmsPluginStorage::instance()->deleteMmsMessage(msgId);
327 } catch (MsgException& e) {
328 MSG_FATAL("%s", e.what());
329 return MSG_ERR_PLUGIN_STORAGE;
330 } catch (exception& e) {
331 MSG_FATAL("%s", e.what());
332 return MSG_ERR_PLUGIN_STORAGE;