update tizen source
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginUserAgent.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
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>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
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.
21 *
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.
28 *
29 */
30
31 #include <glib.h>
32 #include <curl/curl.h>
33 #include "MmsPluginUserAgent.h"
34 #include "MmsPluginEventHandler.h"
35 #include "MsgGconfWrapper.h"
36 #include "MmsPluginInternal.h"
37 #include "MsgUtilFile.h"
38 #include "MmsPluginCodec.h"
39 #include "MsgException.h"
40 #include "MmsPluginDrm.h"
41 #include "MmsPluginStorage.h"
42
43
44 extern MmsHeader mmsHeader;
45
46 void PRINT_PDU_TYPE(MMS_PDU_TYPE_T pduType)
47 {
48         switch (pduType) {
49         case eMMS_SEND_REQ:
50                 MSG_DEBUG("[SEND_REQ]");
51                 break;
52         case eMMS_SEND_CONF:
53                 MSG_DEBUG("[MMS_SEND_CONF]");
54                 break;
55         case eMMS_RETRIEVE_AUTO:
56                 MSG_DEBUG("[MMS_RETRIEVE_AUTO]");
57                 break;
58         case eMMS_RETRIEVE_MANUAL:
59                 MSG_DEBUG("[MMS_RETRIEVE_MANUAL]");
60                 break;
61         case eMMS_RETRIEVE_AUTO_CONF:
62                 MSG_DEBUG("[MMS_RETRIEVE_AUTO_CONF]");
63                 break;
64         case eMMS_RETRIEVE_MANUAL_CONF:
65                 MSG_DEBUG("[MMS_RETRIEVE_MANUAL_CONF]");
66                 break;
67         case eMMS_DELIVERY_IND:
68                 MSG_DEBUG("[MMS_DELIVERY_IND]");
69                 break;
70         case eMMS_NOTIFICATION_IND:
71                 MSG_DEBUG("[MMS_NOTIFICATION_IND]");
72                 break;
73         case eMMS_NOTIFYRESP_IND:
74                 MSG_DEBUG("[MMS_NOTIFYRESP_IND]");
75                 break;
76         case eMMS_ACKNOWLEDGE_IND:
77                 MSG_DEBUG("[MMS_ACKNOWLEDGE_IND]");
78                 break;
79         case eMMS_FORWARD_REQ:
80                 MSG_DEBUG("[MMS_FORWARD_REQ]");
81                 break;
82         case eMMS_FORWARD_CONF:
83                 MSG_DEBUG("[MMS_FORWARD_CONF]");
84                 break;
85         case eMMS_CANCEL_REQ:
86                 MSG_DEBUG("[MMS_CANCEL_REQ]");
87                 break;
88         case eMMS_CANCEL_CONF:
89                 MSG_DEBUG("[MMS_CANCEL_CONF]");
90                 break;
91         case eMMS_DELETE_REQ:
92                 MSG_DEBUG("[MMS_DELETE_REQ]");
93                 break;
94         case eMMS_DELETE_CONF:
95                 MSG_DEBUG("[MMS_DELETE_CONF]");
96                 break;
97         case eMMS_READREC_IND:
98                 MSG_DEBUG("[MMS_READREC_IND]");
99                 break;
100         case eMMS_READORIG_IND:
101                 MSG_DEBUG("[MMS_READORIG_IND]");
102                 break;
103         case eMMS_MBOX_STORE_REQ:
104                 MSG_DEBUG("[MMS_MBOX_STORE_REQ]");
105                 break;
106         case eMMS_MBOX_STORE_CONF:
107                 MSG_DEBUG("[MMS_MBOX_STORE_CONF]");
108                 break;
109         case eMMS_MBOX_VIEW_REQ:
110                 MSG_DEBUG("[MMS_MBOX_VIEW_REQ]");
111                 break;
112         case eMMS_MBOX_VIEW_CONF:
113                 MSG_DEBUG("[MMS_MBOX_VIEW_CONF]");
114                 break;
115         case eMMS_MBOX_UPLOAD_REQ:
116                 MSG_DEBUG("[MMS_MBOX_UPLOAD_REQ]");
117                 break;
118         case eMMS_MBOX_UPLOAD_CONF:
119                 MSG_DEBUG("[MMS_MBOX_UPLOAD_CONF]");
120                 break;
121         case eMMS_MBOX_DELETE_REQ:
122                 MSG_DEBUG("[MMS_MBOX_DELETE_REQ]");
123                 break;
124         case eMMS_MBOX_DELETE_CONF:
125                 MSG_DEBUG("[MMS_MBOX_DELETE_CONF]");
126                 break;
127         default:
128                 MSG_DEBUG("[Unknown PDU Type]");
129                 break;
130         }
131 }
132
133
134 void PRINT_QUEUE_ENTITY(mmsTranQEntity *entity)
135 {
136         MSG_DEBUG("Entity: msgId: %d", entity->msgId);
137         MSG_DEBUG("Entity: completed: %d", entity->isCompleted);
138         MSG_DEBUG("Entity: eMmsPduType: %d", entity->eMmsPduType);
139         MSG_DEBUG("Entity: eHttpCmdType: %d", entity->eHttpCmdType);
140         MSG_DEBUG("Entity: GetLen: %d", entity->getDataLen);
141         MSG_DEBUG("Entity: GetData: (%s)", entity->pGetData);
142         MSG_DEBUG("Entity: postLen: %d", entity->postDataLen);
143         MSG_DEBUG("Entity: pPostData: (%s)", entity->pPostData);
144 }
145
146 void updatePduType(mmsTranQEntity *qEntity)
147 {
148         switch(qEntity->eMmsPduType) {
149         case eMMS_SEND_REQ:
150                 qEntity->eMmsPduType = eMMS_SEND_CONF;
151                 break;
152         case eMMS_RETRIEVE_AUTO:
153                 qEntity->eMmsPduType = eMMS_RETRIEVE_AUTO_CONF;
154                 break;
155         case eMMS_RETRIEVE_MANUAL:
156                 qEntity->eMmsPduType = eMMS_RETRIEVE_MANUAL_CONF;
157                 break;
158         case eMMS_RETRIEVE_AUTO_CONF:
159                 qEntity->eMmsPduType = eMMS_NOTIFYRESP_IND;
160                 break;
161         case eMMS_READREC_IND:
162                 qEntity->eMmsPduType = eMMS_SEND_CONF;
163                 break;
164         case eMMS_READREPORT_REQ:
165                 qEntity->eMmsPduType = eMMS_SEND_CONF;
166                 break;
167         case eMMS_RETRIEVE_MANUAL_CONF:
168                 qEntity->eMmsPduType = eMMS_ACKNOWLEDGE_IND;
169                 break;
170         case eMMS_DELETE_REQ:
171                 qEntity->eMmsPduType = eMMS_DELETE_CONF;
172                 break;
173         case eMMS_FORWARD_REQ:
174                 qEntity->eMmsPduType = eMMS_FORWARD_CONF;
175                 break;
176         case eMMS_MBOX_STORE_REQ:
177                 qEntity->eMmsPduType = eMMS_MBOX_STORE_CONF;
178                 break;
179         case eMMS_MBOX_VIEW_REQ:
180                 qEntity->eMmsPduType = eMMS_MBOX_VIEW_CONF;
181                 break;
182         case eMMS_MBOX_UPLOAD_REQ:
183                 qEntity->eMmsPduType = eMMS_MBOX_UPLOAD_CONF;
184                 break;
185         case eMMS_MBOX_DELETE_REQ:
186                 qEntity->eMmsPduType = eMMS_MBOX_DELETE_CONF;
187                 break;
188
189         MSG_DEBUG("Update PDU Type:");
190         PRINT_PDU_TYPE(qEntity->eMmsPduType);
191
192         default:
193                 break;
194         }
195
196 }
197
198 MmsPluginUaManager *MmsPluginUaManager::pInstance = NULL;
199
200 MmsPluginUaManager::MmsPluginUaManager()
201 {
202         running = false;
203         mmsTranQ.clear();
204 }
205
206 MmsPluginUaManager::~MmsPluginUaManager()
207 {
208         if (pInstance) {
209                 delete pInstance;
210                 pInstance = NULL;
211         }
212 }
213
214 MmsPluginUaManager *MmsPluginUaManager::instance()
215 {
216         if (!pInstance)
217                 pInstance = new MmsPluginUaManager();
218
219         return pInstance;
220 }
221
222 void MmsPluginUaManager::start()
223 {
224         bool bStart = true;
225
226         MutexLocker lock(mx);
227
228         if (!running) {
229
230                 running = true;
231                 MsgThread::start();
232         }
233 }
234
235 MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity)
236 {
237         MMS_NET_ERROR_T ret = eMMS_UNKNOWN;
238         int retryCount = 0;
239
240         MSG_DEBUG("request Submit:");
241         PRINT_PDU_TYPE(qEntity->eMmsPduType);
242         PRINT_QUEUE_ENTITY(qEntity);
243
244         MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
245
246         while (retryCount < RETRY_MAX) {
247                 ret = httpAgent->cmdRequest(qEntity->eHttpCmdType);
248
249                 // Process result
250                 if (ret == eMMS_HTTP_SENT_SUCCESS) {
251                         MSG_DEBUG("Submit request sent");
252                         break;
253                 } else if (ret == eMMS_HTTP_ERROR_NETWORK) {
254                         retryCount++;
255                         MSG_DEBUG("HTTP sent timeout and try again: %d", retryCount);
256                         continue;
257                 } else {
258                         MSG_DEBUG("Unexpected Error %d", ret);
259                         break;
260                 }
261         }
262
263         return ret;
264 }
265
266 MMS_NET_ERROR_T MmsPluginUaManager::waitingConf(mmsTranQEntity *qEntity)
267 {
268         MMS_NET_ERROR_T ret = eMMS_HTTP_ERROR_UNKNOWN;
269         MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
270         MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPldCd = NULL;
271
272         pMmsPldCd = pHttpAgent->getMmsPldCd();
273
274         if (qEntity->pGetData) {
275                 free(qEntity->pGetData);
276                 qEntity->pGetData = NULL;
277         }
278         qEntity->getDataLen = pMmsPldCd->bufOffset;
279         qEntity->pGetData = (char *)calloc(1, pMmsPldCd->bufOffset + 1);
280
281         memcpy(qEntity->pGetData, pMmsPldCd->final_content_buf, pMmsPldCd->bufOffset);
282         free(pMmsPldCd->final_content_buf);
283         pMmsPldCd->final_content_buf = NULL;
284         pMmsPldCd->bufOffset = 0;
285
286         MSG_DEBUG("dataLen:%d  pData:(%s)", qEntity->getDataLen, qEntity->pGetData);
287
288         ret = eMMS_HTTP_CONF_SUCCESS;
289
290         return ret;
291 }
292
293 void MmsPluginUaManager::run()
294 {
295         MSG_BEGIN();
296
297         MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
298         MmsPluginHttpAgent *httpAgent = MmsPluginHttpAgent::instance();
299
300         int trId;
301         CURL *session = NULL;
302
303         int msgId;
304
305         while (1) {
306                 if (mmsTranQ.empty()) {
307                         lock();
308                         wait();
309                         unlock();
310                 }
311
312                 // Request CM Open
313                 if (!(cmAgent->open())) {
314                         MSG_DEBUG("Cm Open Failed");
315
316                         // delete all request from reqQEntities
317                         goto CLEANUP;
318                 }
319
320                 httpAgent->SetMMSProfile();
321
322                 while (!mmsTranQ.empty()) {
323
324                         MSG_DEBUG("###### mmsTranQ.size [%d]", mmsTranQ.size());
325
326                         mmsTranQEntity reqEntity;
327                         memset(&reqEntity, 0, sizeof(mmsTranQEntity));
328
329                         mmsTranQ.front(&reqEntity);
330
331                         reqEntity.isCompleted = false;
332
333                         PRINT_QUEUE_ENTITY(&reqEntity);
334
335                         if (reqEntity.eMmsPduType == eMMS_RETRIEVE_AUTO) {
336                                 msgId = reqEntity.msgId;
337                                 MmsPluginStorage::instance()->updateNetStatus(msgId, MSG_NETWORK_RETRIEVING);
338                         }
339
340                         if (httpAgent->cmdRequest(eHTTP_CMD_INIT_SESSION) == eMMS_HTTP_SESSION_OPEN_FAILED) {
341                                 MSG_DEBUG("HTTP session open failed");
342                                 // cm close
343                                 cmAgent->close();
344                                 // delete all request from reqQEntities
345                                 goto CLEANUP;
346                         }
347
348                         // MMS Transaction
349                         MSG_DEBUG("\n\n ===================  MMS Transaction Start ========================");
350
351                         do {
352                                 httpAgent->setSession(&reqEntity);
353
354                                 if (submitHandler(&reqEntity) != eMMS_HTTP_SENT_SUCCESS) {
355                                         MSG_DEBUG("Transaction Error: submit failed");
356
357                                         MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
358                                         mmsTranQ.pop_front();
359                                         //try to next mmsTranQ
360                                         break;
361                                 }
362
363                                 MSG_DEBUG("submitHandler(&reqEntity) success.");
364                                 trId = httpAgent->getHttpConfigData()->transactionId;
365
366                                 MSG_DEBUG("#### MMS PDU TYPE = %d ####", reqEntity.eMmsPduType);
367
368                                 if (reqEntity.eMmsPduType == eMMS_NOTIFYRESP_IND ||
369                                         reqEntity.eMmsPduType == eMMS_ACKNOWLEDGE_IND ||
370                                         reqEntity.eMmsPduType == eMMS_READREC_IND ||
371                                         reqEntity.eMmsPduType == eMMS_CANCEL_CONF) {
372                                         reqEntity.isCompleted = true;
373
374                                         mmsTranQ.pop_front();
375
376                                         MSG_DEBUG("Transaction Completed");
377                                         break;
378                                 } else {
379                                         // change MmsPduType from XXX.req to XXX.conf for waiting
380                                         MSG_DEBUG("Update Pdutype");
381                                         updatePduType(&reqEntity);
382                                         MSG_DEBUG("Waiting Conf");
383                                 }
384
385                                 mmsTranQ.pop_front();
386
387                                 //////// Waiting Conf //////////////////////
388                                 MMS_NET_ERROR_T networkErr;
389
390                                 if ((networkErr = waitingConf(&reqEntity)) == eMMS_HTTP_CONF_SUCCESS) {
391                                         bool bReportAllowed;
392                                         char retrievedFilePath[MAX_FULL_PATH_SIZE+1] = {0,};
393
394                                         // process Http data
395                                         try {
396                                                 if (processReceivedData(reqEntity.msgId, reqEntity.pGetData, reqEntity.getDataLen, retrievedFilePath) == false) {
397                                                         MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
398                                                         break;
399                                                 }
400                                         } catch (MsgException& e) {
401                                                 MSG_FATAL("%s", e.what());
402                                                 MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
403                                                 break;
404
405                                         } catch (exception& e) {
406                                                 MSG_FATAL("%s", e.what());
407                                                 MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
408                                                 break;
409                                         }
410
411                                         if (reqEntity.eMmsPduType != (MMS_PDU_TYPE_T)mmsHeader.type) {
412                                                 if (!(reqEntity.eMmsPduType == eMMS_RETRIEVE_MANUAL_CONF && mmsHeader.type == MMS_MSGTYPE_RETRIEVE_CONF)) {
413                                                         MSG_DEBUG("FAIL::type mismatched req:%d received:%d", reqEntity.eMmsPduType, mmsHeader.type);
414
415                                                         MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
416                                                         break;
417                                                 }
418                                         }
419
420                                         MSG_DEBUG("conf received successfully");
421
422                                         try {
423                                                 MmsPluginEventHandler::instance()->handleMmsReceivedData(&reqEntity, retrievedFilePath);
424                                         } catch (MsgException& e) {
425                                                 MSG_FATAL("%s", e.what());
426                                                 break;
427                                         } catch (exception& e) {
428                                                 MSG_FATAL("%s", e.what());
429                                                 break;
430                                         }
431
432                                         MsgSettingGetBool(MMS_RECV_DELIVERY_RECEIPT, &bReportAllowed);
433
434                                         MSG_DEBUG("conf received successfully -2");
435                                         MSG_DEBUG("reqEntity.eMmsPduType [%d]", reqEntity.eMmsPduType);
436
437                                         // send NotifyResponseInd
438                                         if (reqEntity.eMmsPduType == eMMS_RETRIEVE_AUTO_CONF) {
439                                                 char filepath[MAX_FULL_PATH_SIZE] = {0};
440                                                 // change MmsPduType for ind or ack
441                                                 // make the PDU and then attach to reqEntity also.
442                                                 updatePduType(&reqEntity);
443
444                                                 MSG_DEBUG("#### eMmsPduType:%d ####", reqEntity.eMmsPduType);
445
446                                                 //update http command type & encode m-notify-response-ind
447                                                 reqEntity.eHttpCmdType = eHTTP_CMD_POST_TRANSACTION;
448
449                                                 try {
450                                                         MmsPluginInternal::instance()->encodeNotifyRespInd(reqEntity.transactionId, MMS_MSGSTATUS_RETRIEVED, bReportAllowed, filepath);
451                                                         //m-notification-resp-ind encoding      if err is not MSG_SUCCESS then should set x-mms-status to deferred
452                                                         if (MsgGetFileSize(filepath, &reqEntity.postDataLen) == false) {
453                                                                 MSG_DEBUG("MsgGetFileSize: failed");
454                                                                 break;
455                                                         }
456                                                 } catch (MsgException& e) {
457                                                         MSG_FATAL("%s", e.what());
458                                                         break;
459                                                 } catch (exception& e) {
460                                                         MSG_FATAL("%s", e.what());
461                                                         break;
462                                                 }
463
464                                                 if (reqEntity.pPostData) {
465                                                         free(reqEntity.pPostData);
466                                                         reqEntity.pPostData = NULL;
467                                                 }
468
469                                                 reqEntity.pPostData = MsgOpenAndReadMmsFile(filepath, 0, -1, &reqEntity.postDataLen);
470
471                                                 mmsTranQ.push_front(reqEntity);
472
473                                                 remove(filepath);
474
475                                                 MSG_DEBUG("Submit Ind");
476                                         } else if (reqEntity.eMmsPduType == eMMS_RETRIEVE_MANUAL_CONF) {
477                                                 /* saved msg trId should be checked  */
478                                                 // Send Acknowledge Ind
479                                                 char filepath[MAX_FULL_PATH_SIZE] = {0};
480                                                 // change MmsPduType for ind or ack
481                                                 // make the PDU and then attach to reqEntity also.
482                                                 updatePduType(&reqEntity);
483
484                                                 MSG_DEBUG("#### eMmsPduType:%d ####", reqEntity.eMmsPduType);
485
486                                                 //update http command type & encode m-notify-response-ind
487                                                 reqEntity.eHttpCmdType = eHTTP_CMD_POST_TRANSACTION;
488
489                                                 try {
490                                                         MmsPluginInternal::instance()->encodeAckInd(reqEntity.transactionId, bReportAllowed, filepath);
491                                                         if (MsgGetFileSize(filepath, &reqEntity.postDataLen) == false) {
492                                                                 MSG_DEBUG("MsgGetFileSize: failed");
493                                                                 break;
494                                                         }
495                                                 } catch (MsgException& e) {
496                                                         MSG_FATAL("%s", e.what());
497                                                         break;
498                                                 } catch (exception& e) {
499                                                         MSG_FATAL("%s", e.what());
500                                                         break;
501                                                 }
502
503                                                 if (reqEntity.pPostData) {
504                                                         free(reqEntity.pPostData);
505                                                         reqEntity.pPostData = NULL;
506                                                 }
507
508                                                 reqEntity.pPostData = MsgOpenAndReadMmsFile(filepath, 0, -1, &reqEntity.postDataLen);
509
510                                                 mmsTranQ.push_front(reqEntity);
511
512                                                 remove(filepath); // not ipc
513
514                                                 MSG_DEBUG("Submit Ack");
515                                         } else {
516                                                 reqEntity.isCompleted = true;
517
518                                                 MSG_DEBUG("Transaction complete");
519                                         }
520                                 } else {
521                                         MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
522                                         break;
523                                 }
524                         } while (reqEntity.isCompleted == false);
525
526                         MSG_DEBUG("==== MMS Transaction Completed ====\n\n");
527
528                         if (reqEntity.pPostData) {
529                                 free(reqEntity.pPostData);
530                                 reqEntity.pPostData = NULL;
531                         }
532
533                         if (reqEntity.pGetData) {
534                                 free(reqEntity.pGetData);
535                                 reqEntity.pGetData = NULL;
536                         }
537
538                         // Http Session Close
539                         httpAgent->clearSession();
540                 }
541
542                 // Request CM Close
543                 cmAgent->close();
544
545         }
546
547 CLEANUP:
548         MSG_DEBUG("CLEANUP");
549
550         while (!mmsTranQ.empty()) {
551                 MSG_DEBUG("clear mmsTranQ");
552
553                 mmsTranQEntity reqEntity;
554                 memset(&reqEntity, 0, sizeof(mmsTranQEntity));
555
556                 mmsTranQ.front(&reqEntity);
557
558                 // notify send fail to APP
559                 MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
560
561                 if (reqEntity.pGetData) {
562                         MSG_DEBUG("free pGetData");
563                         free(reqEntity.pGetData);
564                         reqEntity.pGetData = NULL;
565                 }
566
567                 if (reqEntity.pPostData) {
568                         MSG_DEBUG("free pPostData");
569                         free(reqEntity.pPostData);
570                         reqEntity.pPostData = NULL;
571                 }
572
573                 mmsTranQ.pop_front();
574         }
575
576         mmsTranQ.clear();
577         MutexLocker locker(mx);
578         running = false;
579
580         MSG_END();
581
582         return;
583 }
584
585 void MmsPluginUaManager::getMmsPduData(mmsTranQEntity *qEntity)
586 {
587         mmsTranQ.front(qEntity);
588 }
589
590 void MmsPluginUaManager::addMmsReqEntity(mmsTranQEntity req)
591 {
592         MSG_DEBUG("New MMS Tran Added");
593         mmsTranQ.push_back(req);
594         lock();
595         signal();
596         unlock();
597 }
598
599 bool MmsPluginUaManager::processReceivedData(int msgId, char *pRcvdBody, int rcvdBodyLen, char *retrievedFilePath)
600 {
601         MSG_BEGIN();
602
603         char fileName[MSG_FILENAME_LEN_MAX] = {0};
604         FILE *pFile = NULL;
605
606         MSG_DEBUG(":::%d :%s ", rcvdBodyLen, pRcvdBody);
607
608         _MmsInitHeader();
609         _MmsRegisterDecodeBuffer(gszMmsLoadBuf1,  gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
610
611         if (MsgCreateFileName(fileName) == false)
612                 return false;
613
614         snprintf(retrievedFilePath, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s", fileName);
615
616         MSG_DEBUG("retrievedFilePaths [%s]", retrievedFilePath);
617
618         // create temp file
619         if (!MsgOpenCreateAndOverwriteFile(retrievedFilePath, (char *)pRcvdBody, rcvdBodyLen)) {
620                 MSG_DEBUG( "_MmsUaInitMsgDecoder: creating temporary file failed(msgID=%d)\n", msgId);
621                 return false;
622         }
623
624         if (_MmsReadMsgBody(msgId, true, true, retrievedFilePath) == false) {
625                 MSG_DEBUG("The MMS Message might include drm contents!!!");
626
627 #ifdef __SUPPORT_DRM__
628                 if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
629                         bool bRetToConvert = true;
630                         MSG_MESSAGE_INFO_S pMsg = {0, };
631
632                         pMsg.msgId = msgId;
633
634                         bRetToConvert = MmsDrm2ConvertMsgBody(mmsHeader.msgType.szOrgFilePath);
635
636                         MmsDrm2SetConvertState(MMS_DRM2_CONVERT_FINISH);
637
638                         if (bRetToConvert) {
639                                 remove(mmsHeader.msgType.szOrgFilePath);
640                                 rename(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, mmsHeader.msgType.szOrgFilePath);
641
642                                 if (MmsDrm2ReadMsgConvertedBody(&pMsg, true, true, retrievedFilePath) == false) {
643                                         MSG_DEBUG("MmsLoadMsg:MmsDrm2ReadMsgConvertedBody() returns false\n");
644                                         goto ERR_MMS_UA_PROCESS_CONF;
645                                 }
646                         }
647                 }
648 #endif
649         }
650
651         MSG_END();
652
653         return true;
654
655 ERR_MMS_UA_PROCESS_CONF:
656         {
657                 MmsMsg *pMsg;
658                 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
659
660
661                 _MmsInitHeader();
662                 _MmsUnregisterDecodeBuffer();
663
664 #ifdef __SUPPORT_DRM__
665                 _MsgFreeDRMInfo(&pMsg->msgType.drmInfo);
666 #endif
667                 _MsgFreeBody(&pMsg->msgBody, pMsg->msgType.type);
668
669                 return false;
670         }
671 }
672