3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
36 #include "MmsPluginTypes.h"
37 #include "MmsPluginMain.h"
38 #include "MmsPluginTransport.h"
40 #include "MsgException.h"
42 #include "MmsPluginMain.h"
43 #include "MmsPluginMessage.h"
44 #include "MmsPluginStorage.h"
45 #include "MmsPluginInternal.h"
46 #include "MmsPluginEventHandler.h"
47 #include "MsgGconfWrapper.h"
48 #include "MmsPluginCodec.h"
49 #include "MsgUtilFile.h"
50 #include "MmsPluginUserAgent.h"
53 /*==================================================================================================
54 FUNCTION IMPLEMENTATION
55 ==================================================================================================*/
56 MSG_ERROR_T MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
58 if (pPluginHandle == NULL) {
59 MSG_DEBUG("MMS plugin: create handler error ");
60 return MSG_ERR_NULL_POINTER;
62 pPluginHandle->pfInitialize = MmsInitialize;
63 pPluginHandle->pfFinalize = MmsFinalize;
64 pPluginHandle->pfRegisterListener = MmsRegisterListener;
65 pPluginHandle->pfSubmitRequest = MmsSubmitRequest;
66 pPluginHandle->pfAddMessage = MmsAddMessage;
67 pPluginHandle->pfProcessReceivedInd = MmsProcessReceivedInd;
68 pPluginHandle->pfUpdateMessage = MmsUpdateMessage;
69 pPluginHandle->pfGetMmsMessage = MmsGetMmsMessage;
70 pPluginHandle->pfUpdateRejectStatus = MmsUpdateRejectStatus;
71 pPluginHandle->pfComposeReadReport = MmsComposeReadReport;
72 pPluginHandle->pfRestoreMsg = MmsRestoreMsg;
74 MSG_DEBUG("MMS plugin: create handler OK");
75 MSG_DEBUG ("MMS plugin %p", pPluginHandle);
82 MSG_ERROR_T MmsPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
86 if (pPluginHandle != NULL) {
97 MSG_ERROR_T MmsInitialize()
110 MSG_ERROR_T MmsFinalize()
120 MSG_ERROR_T MmsRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
124 MmsPluginEventHandler::instance()->registerListener(pListener);
132 MSG_ERROR_T MmsSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo, bool bReqCb)
137 MmsPluginTransport::instance()->submitRequest(pReqInfo);
138 } catch (MsgException& e) {
139 MSG_FATAL("%s", e.what());
140 return MSG_ERR_PLUGIN_TRANSPORT;
141 } catch (exception& e) {
142 MSG_FATAL("%s", e.what());
143 return MSG_ERR_PLUGIN_TRANSPORT;
152 MSG_ERROR_T MmsAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
157 MmsPluginStorage::instance()->addMessage(pMsgInfo, pSendOptInfo, pFileData);
158 } catch (MsgException& e) {
159 MSG_FATAL("%s", e.what());
160 return MSG_ERR_PLUGIN_TRANSPORT;
161 } catch (exception& e) {
162 MSG_FATAL("%s", e.what());
163 return MSG_ERR_PLUGIN_TRANSPORT;
172 MSG_ERROR_T MmsProcessReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
176 MSG_DEBUG("MMS Plugin ProcessReceivedInd");
179 MmsPluginInternal::instance()->processReceivedInd(pMsgInfo, pRequest, bReject);
180 } catch (MsgException& e) {
181 MSG_FATAL("%s", e.what());
182 return MSG_ERR_PLUGIN_TRANSPORT;
183 } catch (exception& e) {
184 MSG_FATAL("%s", e.what());
185 return MSG_ERR_PLUGIN_TRANSPORT;
194 MSG_ERROR_T MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
198 MSG_ERROR_T err = MSG_SUCCESS;
201 if (pMsgInfo->networkStatus == MSG_NETWORK_NOT_SEND) {
202 err = MmsPluginStorage::instance()->updateMessage(pMsgInfo, pSendOptInfo, pFileData);
204 //[Update Message ID & File path only in case of retrieve. Else update Message ID]
205 if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
206 err = MmsPluginStorage::instance()->updateConfMessage(pMsgInfo);
208 err = MmsPluginStorage::instance()->updateMsgServerID(pMsgInfo, pSendOptInfo);
211 } catch (MsgException& e) {
212 MSG_FATAL("%s", e.what());
213 return MSG_ERR_PLUGIN_STORAGE;
214 } catch (exception& e) {
215 MSG_FATAL("%s", e.what());
216 return MSG_ERR_PLUGIN_STORAGE;
225 MSG_ERROR_T MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg)
229 MSG_ERROR_T err = MSG_SUCCESS;
232 err = MmsPluginStorage::instance()->plgGetMmsMessage(pMsg, pSendOptInfo, pMmsMsg, pDestMsg);
233 } catch (MsgException& e) {
234 MSG_FATAL("%s", e.what());
235 return MSG_ERR_PLUGIN_STORAGE;
236 } catch (exception& e) {
237 MSG_FATAL("%s", e.what());
238 return MSG_ERR_PLUGIN_STORAGE;
247 MSG_ERROR_T MmsUpdateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
251 MSG_ERROR_T err = MSG_SUCCESS;
254 char szTrID[MMS_TR_ID_LEN + 1] = {0x00};
257 err = MmsPluginStorage::instance()->getTrID(pMsgInfo,szTrID,sizeof(szTrID));
258 if (err != MSG_SUCCESS)
259 MSG_DEBUG("MmsPlgUpdRejectStatus : Get MMS Transacation id Failed");
261 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
262 MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed);
263 if (MmsPluginInternal::instance()->encodeNotifyRespInd(szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pMsgInfo->msgData)) {
264 MSG_DEBUG("MmsPlgUpdRejectStatus : Encode Notify Response Success");
265 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
266 pMsgInfo->bTextSms = true;
268 MSG_DEBUG("MmsPlgSetRejectStatus : Encode Notify Response Failed");
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;
277 if (err != MSG_SUCCESS)
278 MSG_DEBUG("MmsPlgSetRejectStatus : Update MMS Message Failed");
286 MSG_ERROR_T MmsComposeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
291 MmsPluginStorage::instance()->composeReadReport(pMsgInfo);
292 } catch (MsgException& e) {
293 MSG_FATAL("%s", e.what());
294 return MSG_ERR_PLUGIN_STORAGE;
295 } catch (exception& e) {
296 MSG_FATAL("%s", e.what());
297 return MSG_ERR_PLUGIN_STORAGE;
306 MSG_ERROR_T MmsRestoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char *pRcvBody, int rcvdBodyLen, char *filePath)
310 if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
313 _MmsRegisterDecodeBuffer(gszMmsLoadBuf1, gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
315 if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
316 MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
319 if (!MmsBinaryDecodeMsgHeader(pFile, rcvdBodyLen))
320 MSG_DEBUG("Decoding Header Failed \r\n");
325 MSG_DEBUG(":::%d :%s ",rcvdBodyLen, pRcvBody);
328 snprintf(filePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"BODY_%lu.DATA", random() % 1000000000 + 1);
330 return MSG_ERR_NULL_POINTER;
334 if (!MsgOpenCreateAndOverwriteFile(filePath, (char*)pRcvBody,rcvdBodyLen))
335 return MSG_ERR_PLUGIN_STORAGE;