Fixed N_SE-47122 disable dlog message
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginMain.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
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
7 *
8 *    http://floralicense.org/license/
9 *
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.
15 */
16
17 #include <stdio.h>
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"
29
30 /*==================================================================================================
31                                                         FUNCTION IMPLEMENTATION
32 ==================================================================================================*/
33 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
34 {
35         if (pPluginHandle == NULL) {
36                 MSG_DEBUG("MMS plugin: create handler error ");
37                 return MSG_ERR_NULL_POINTER;
38         } else {
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;
50
51                 MSG_DEBUG("MMS plugin: create handler OK");
52                 MSG_DEBUG ("MMS plugin %p", pPluginHandle);
53         }
54
55         return MSG_SUCCESS;
56 }
57
58
59 msg_error_t MmsPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
60 {
61         MSG_BEGIN();
62
63         if (pPluginHandle != NULL) {
64                 free(pPluginHandle);
65                 pPluginHandle = NULL;
66         }
67
68         MSG_END();
69
70         return MSG_SUCCESS;
71 }
72
73
74 msg_error_t MmsInitialize()
75 {
76         MSG_BEGIN();
77
78         // remove temp files
79         MsgMmsInitDir();
80
81         MSG_END();
82
83         return MSG_SUCCESS;
84 }
85
86
87 msg_error_t MmsFinalize()
88 {
89         MSG_BEGIN();
90
91         MSG_END();
92
93         return MSG_SUCCESS;
94 }
95
96
97 msg_error_t MmsRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
98 {
99         MSG_BEGIN();
100
101         MmsPluginEventHandler::instance()->registerListener(pListener);
102
103         MSG_END();
104
105         return MSG_SUCCESS;
106 }
107
108
109 msg_error_t MmsSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
110 {
111         MSG_BEGIN();
112
113         try {
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;
121         }
122
123         MSG_END();
124
125         return MSG_SUCCESS;
126 }
127
128
129 msg_error_t MmsAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
130 {
131         MSG_BEGIN();
132
133         try {
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;
141         }
142
143         //MSG_END();
144
145         return MSG_SUCCESS;
146 }
147
148
149 msg_error_t MmsProcessReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
150 {
151         MSG_BEGIN();
152
153         MSG_DEBUG("MMS Plugin ProcessReceivedInd");
154
155         try {
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;
163         }
164
165         MSG_END();
166
167         return MSG_SUCCESS;
168 }
169
170
171 msg_error_t MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo,  char *pFileData)
172 {
173         MSG_BEGIN();
174
175         msg_error_t err = MSG_SUCCESS;
176
177         try {
178                 if (pMsgInfo->networkStatus == MSG_NETWORK_NOT_SEND || pMsgInfo->networkStatus == MSG_NETWORK_SENDING) {
179                         err = MmsPluginStorage::instance()->updateMessage(pMsgInfo, pSendOptInfo, pFileData);
180                 } else {
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);
184                         } else {
185                                 err = MmsPluginStorage::instance()->updateMsgServerID(pMsgInfo, pSendOptInfo);
186                         }
187                 }
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;
194         }
195
196         MSG_END();
197
198         return err;
199 }
200
201
202 msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg)
203 {
204         MSG_BEGIN();
205
206         msg_error_t     err = MSG_SUCCESS;
207
208         try {
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;
216         }
217
218         MSG_END();
219
220         return err;
221 }
222
223
224 msg_error_t MmsUpdateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
225 {
226         MSG_BEGIN();
227
228         msg_error_t err = MSG_SUCCESS;
229
230         try {
231                 char szTrID[MMS_TR_ID_LEN + 1] = {0x00};
232                 bool bReportAllowed;
233
234                 err = MmsPluginStorage::instance()->getTrID(pMsgInfo,szTrID,sizeof(szTrID));
235                 if (err != MSG_SUCCESS)
236                         MSG_DEBUG("MmsPlgUpdRejectStatus : Get MMS Transacation id Failed");
237
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;
244                 } else
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;
252         }
253
254         if (err != MSG_SUCCESS)
255                 MSG_DEBUG("MmsPlgSetRejectStatus : Update MMS Message Failed");
256
257         MSG_END();
258
259         return err;
260 }
261
262
263 msg_error_t MmsComposeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
264 {
265         MSG_BEGIN();
266
267         try {
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;
275         }
276
277         MSG_END();
278
279         return MSG_SUCCESS;
280 }
281
282
283 msg_error_t MmsRestoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char *pRcvBody, int rcvdBodyLen, char *filePath)
284 {
285         MSG_BEGIN();
286
287         if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
288                 FILE *pFile;
289
290                 MmsInitHeader();
291                 MmsRegisterDecodeBuffer();
292
293                 if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
294                         MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
295                 } else {
296                         //Decode Header
297                         if (!MmsBinaryDecodeMsgHeader(pFile, rcvdBodyLen))
298                                 MSG_DEBUG("Decoding Header Failed \r\n");
299
300                         MsgCloseFile(pFile);
301                 }
302         } else {
303                 MSG_DEBUG(":::%d :%s ",rcvdBodyLen, pRcvBody);
304
305                 if (filePath) {
306                         snprintf(filePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"BODY_%lu.DATA", random() % 1000000000 + 1);
307                 } else {
308                         return MSG_ERR_NULL_POINTER;
309                 }
310
311                 // create temp file
312                 if (!MsgOpenCreateAndOverwriteFile(filePath, (char*)pRcvBody,rcvdBodyLen))
313                         return MSG_ERR_PLUGIN_STORAGE;
314         }
315
316         MSG_END();
317
318         return MSG_SUCCESS;
319 }
320
321 msg_error_t MmsDeleteMessage(msg_message_id_t msgId)
322 {
323         MSG_BEGIN();
324
325         try {
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;
333         }
334
335         MSG_END();
336         return MSG_SUCCESS;
337 }