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.
21 #include "MsgException.h"
22 #include "MsgUtilFile.h"
23 #include "MsgMmsMessage.h"
24 #include "MsgStorageTypes.h"
25 #include "MmsPluginDebug.h"
26 #include "MmsPluginStorage.h"
27 #include "MmsPluginMessage.h"
28 #include "MmsPluginSmil.h"
29 #include "MmsPluginDrm.h"
30 #include "MmsPluginMIME.h"
32 /*==================================================================================================
33 IMPLEMENTATION OF SmsPluginStorage - Member Functions
34 ==================================================================================================*/
35 MmsPluginStorage *MmsPluginStorage::pInstance = NULL;
38 MmsPluginStorage::MmsPluginStorage()
40 memset(&mmsMsg, 0, sizeof(MmsMsg));
44 MmsPluginStorage::~MmsPluginStorage()
46 if (dbHandle.disconnect() != MSG_SUCCESS) {
47 MSG_DEBUG("DB Disconnect Fail");
52 MmsPluginStorage *MmsPluginStorage::instance()
55 pInstance = new MmsPluginStorage();
61 void MmsPluginStorage::getMmsMessage(MmsMsg **pMmsMsg)
67 void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
75 bzero(&mmsMsg, sizeof(mmsMsg));
77 mode_t file_mode = (S_IRUSR | S_IWUSR);
79 if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
81 char szTemp[MAX_MSG_DATA_LEN + 1];
83 MMS_MESSAGE_DATA_S mmsMsgData;
84 bzero(&mmsMsgData,sizeof(MMS_MESSAGE_DATA_S));
85 if (MmsComposeMessage(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData, pFileData) != true) {
86 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
88 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
89 __MmsReleaseMmsLists(&mmsMsgData);
91 THROW(MsgException::MMS_PLG_ERROR, "MMS Message Compose Error");
94 MmsPrintFileInfoForVLD(&mmsMsgData);
96 char fileName[MSG_FILENAME_LEN_MAX+1] = {0,};
100 strcpy(szTemp,pMsgInfo->msgData);
102 snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
104 if (addMmsMsgToDB(&mmsMsg, pMsgInfo, _MsgMmsGetAttachCount(&mmsMsgData)) != MSG_SUCCESS) {
105 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
106 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
107 __MmsReleaseMmsLists(&mmsMsgData);
109 THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
112 strcpy((char *)pMsgInfo->msgData,szTemp);
114 snprintf(fileName, MSG_FILENAME_LEN_MAX+1, MSG_DATA_PATH"%d", mmsMsg.msgID);
116 pFile = MsgOpenMMSFile(fileName);
118 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
119 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
120 __MmsReleaseMmsLists(&mmsMsgData);
121 THROW(MsgException::MMS_PLG_ERROR, "MMS File open Error");
124 if (fchmod(fileno(pFile), file_mode) < 0) {
125 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
126 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
127 __MmsReleaseMmsLists(&mmsMsgData);
130 THROW(MsgException::MMS_PLG_ERROR, "chmod() error: %s", strerror(errno));
133 if (MmsEncodeSendReq(pFile, &mmsMsg) != true) {
134 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
135 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
136 __MmsReleaseMmsLists(&mmsMsgData);
139 THROW(MsgException::MMS_PLG_ERROR, "MMS Message Encode Send Req Error");
142 MsgFsync(pFile); //file is written to device immediately, it prevents missing file data from unexpected power off
145 char filepath[MSG_FILEPATH_LEN_MAX+1] = {0,};
148 snprintf((char *)filepath, MSG_FILEPATH_LEN_MAX+1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
149 if (MsgGetFileSize(filepath, &size) == false) {
150 THROW(MsgException::MMS_PLG_ERROR, "MMS Message MsgGetFileSize Error");
153 pMsgInfo->dataSize = size;
155 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
156 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
157 __MmsReleaseMmsLists(&mmsMsgData);
159 } else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
160 MSG_DEBUG("######## MmsPlgAddMessage -> MSG_NOTIFICATIONIND_MMS ###########");
162 MmsComposeNotiMessage(&mmsMsg, pMsgInfo->msgId);
164 //Need to store mms specific data (contents location, TrID, ExpiryTime, Delivery Report, message ID)
165 if (addMmsMsgToDB(&mmsMsg, pMsgInfo) != MSG_SUCCESS) {
166 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
167 THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
169 } else if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS) {
171 char szTemp[MAX_MSG_DATA_LEN + 1]= {0, };
173 if (!MmsReadMsgBody(pMsgInfo->msgId, true, true, pFileData))
174 THROW(MsgException::MMS_PLG_ERROR, "_MmsReadMsgBody Error");
176 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
178 if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS)
179 pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
181 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
182 strcpy(szTemp,pMsgInfo->msgData);
183 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
184 strncpy(pMsgInfo->msgData, pFileData, MAX_MSG_DATA_LEN);
186 MmsPluginStorage *pStorage = MmsPluginStorage::instance();
188 MMS_MESSAGE_DATA_S mmsMsgData;
189 bzero(&mmsMsgData,sizeof(MMS_MESSAGE_DATA_S));
190 if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
192 char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
194 mmsMsgData.regionCnt = 0;
195 mmsMsgData.pageCnt = 0;
196 mmsMsgData.attachCnt = 0;
197 mmsMsgData.transitionCnt = 0;
198 mmsMsgData.metaCnt = 0;
199 memset(mmsMsgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
201 pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
203 MmsSmilParseSmilDoc(&mmsMsgData, pSmilDoc);
205 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
206 strcpy(szFileName, pMsg->szFileName);
208 err = pStorage->getMsgText(&mmsMsgData, pMsgInfo->msgText);
209 MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
212 MsgMmsReleaseMmsLists(&mmsMsgData);
215 if (addMmsMsgToDB(pMsg, pMsgInfo) != MSG_SUCCESS) {
216 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
218 THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
220 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
221 strcpy((char *)pMsgInfo->msgData,szTemp);
223 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
225 } else if (pMsgInfo->msgType.subType == MSG_READREPLY_MMS || pMsgInfo->msgType.subType == MSG_READRECIND_MMS) {
226 MSG_DEBUG("######## MmsPlgAddMessage -> MSG_READREPLY_MMS || MSG_READRECIND_MMS ###########");
228 char filePath[MAX_FULL_PATH_SIZE+1] = {0, };
231 msg_read_report_status_t readStatus;
232 msg_message_id_t selectedMsgId;
235 memcpy(&readStatus, pMsgInfo->msgData, sizeof(msg_read_report_status_t));
236 memcpy(&selectedMsgId, pMsgInfo->msgData + sizeof(msg_read_report_status_t), sizeof(msg_message_id_t));
238 version = MmsPluginStorage::instance()->getMmsVersion(selectedMsgId);
240 snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
242 MmsComposeReadReportMessage(&mmsMsg, pMsgInfo, selectedMsgId);
244 if (addMmsMsgToDB(&mmsMsg, pMsgInfo) != MSG_SUCCESS) {
245 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
246 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
248 THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
251 snprintf(filePath, MAX_FULL_PATH_SIZE+1, MSG_DATA_PATH"%d", mmsMsg.msgID);
252 pFile = MsgOpenMMSFile(filePath);
254 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
255 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
259 THROW(MsgException::MMS_PLG_ERROR, "MsgOpenMMSFile error");
262 if (fchmod(fileno(pFile), file_mode) < 0) {
263 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
264 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
268 THROW(MsgException::MMS_PLG_ERROR, "chmod() error: %s", strerror(errno));
271 if (version == 0x90) {
272 MSG_DEBUG("### version 1.0 ###");
273 if (MmsEncodeReadReport10(pFile, &mmsMsg, readStatus) != true) {
274 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
278 THROW(MsgException::MMS_PLG_ERROR, "MMS Encode Read Report 1.0 Error");
281 MSG_DEBUG("### version 1.1 ###");
282 if (MmsEncodeReadReport11(pFile, &mmsMsg, readStatus) != true) {
283 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
287 THROW(MsgException::MMS_PLG_ERROR, "MMS Encode Read Report 1.1 Error");
295 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
297 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
299 } else if (pMsgInfo->msgType.subType == MSG_FORWARD_MMS) {
300 MSG_DEBUG("######## MmsPlgAddMessage -> MSG_FORWARD_MMS ###########");
302 char filePath[MAX_FULL_PATH_SIZE + 1] = {0, };
303 char szTemp[MAX_MSG_DATA_LEN + 1] = {0, };
305 MMS_MESSAGE_DATA_S mmsMsgData;
307 if (MmsComposeMessage(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData, pFileData) != true) {
308 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
309 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
310 __MmsReleaseMmsLists(&mmsMsgData);
312 THROW(MsgException::MMS_PLG_ERROR, "MMS Message Compose Error");
315 strcpy(szTemp,pMsgInfo->msgData);
317 snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN + 1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
319 if (addMmsMsgToDB(&mmsMsg, pMsgInfo, _MsgMmsGetAttachCount(&mmsMsgData)) != MSG_SUCCESS) {
320 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
321 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
322 __MmsReleaseMmsLists(&mmsMsgData);
324 THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
327 strcpy((char *)pMsgInfo->msgData,szTemp);
329 snprintf(filePath, MAX_FULL_PATH_SIZE + 1 , MSG_DATA_PATH"%d", mmsMsg.msgID);
331 pFile = MsgOpenMMSFile(filePath);
333 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
334 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
335 __MmsReleaseMmsLists(&mmsMsgData);
339 THROW(MsgException::MMS_PLG_ERROR, "MsgOpenMMSFile error");
342 if (fchmod(fileno(pFile), file_mode) < 0) {
343 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
344 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
345 __MmsReleaseMmsLists(&mmsMsgData);
349 THROW(MsgException::MMS_PLG_ERROR, "chmod() error: %s", strerror(errno));
352 if (MmsEncodeSendReq(pFile, &mmsMsg) != true) {
353 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
354 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
355 __MmsReleaseMmsLists(&mmsMsgData);
359 THROW(MsgException::MMS_PLG_ERROR, "MMS Message Encode Send Req Error");
365 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
366 MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
367 __MmsReleaseMmsLists(&mmsMsgData);
374 void MmsPluginStorage::composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
378 msg_read_report_status_t readStatus;
381 memcpy(&readStatus, pMsgInfo->msgData, sizeof(msg_read_report_status_t));
383 MSG_DEBUG("pMsgInfo->msgId = %d", pMsgInfo->msgId);
385 version = MmsPluginStorage::instance()->getMmsVersion(pMsgInfo->msgId);
387 snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d-Read-Rec.ind", pMsgInfo->msgId);
390 pMsgInfo->msgType.subType = MSG_READREPLY_MMS;
392 pMsgInfo->msgType.subType = MSG_READRECIND_MMS;
394 MmsComposeReadReportMessage(&mmsMsg, pMsgInfo, pMsgInfo->msgId);
396 pFile = MsgOpenFile(pMsgInfo->msgData, "wb+");
398 THROW(MsgException::MMS_PLG_ERROR, "MsgOpenMMSFile Error");
400 if (version == 0x90) {
401 MSG_DEBUG("### version 1.0 ###");
402 if (MmsEncodeReadReport10(pFile, &mmsMsg, readStatus) != true) {
404 THROW(MsgException::MMS_PLG_ERROR, "MMS Encode Read Report 1.0 Error");
407 MSG_DEBUG("### version 1.1 ###");
408 if (MmsEncodeReadReport11(pFile, &mmsMsg, readStatus) != true) {
410 THROW(MsgException::MMS_PLG_ERROR, "MMS Encode Read Report 1.1 Error");
418 msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, int attachCnt)
422 char sqlQuery[MAX_QUERY_LEN + 1];
425 memset(sqlQuery, 0x00, sizeof(sqlQuery));
426 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, %d, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);",
427 MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsMsg->msgID, pMmsMsg->szTrID, pMmsMsg->szMsgID, pMmsMsg->szForwardMsgID, pMmsMsg->szContentLocation,
428 pMsgInfo->msgData, pMmsMsg->mmsAttrib.version, pMmsMsg->mmsAttrib.dataType, pMmsMsg->mmsAttrib.date, pMmsMsg->mmsAttrib.bHideAddress,
429 pMmsMsg->mmsAttrib.bAskDeliveryReport, pMmsMsg->mmsAttrib.bReportAllowed, pMmsMsg->mmsAttrib.readReportAllowedType,
430 pMmsMsg->mmsAttrib.bAskReadReply, pMmsMsg->mmsAttrib.bRead, pMmsMsg->mmsAttrib.readReportSendStatus, pMmsMsg->mmsAttrib.bReadReportSent,
431 pMmsMsg->mmsAttrib.priority, pMmsMsg->mmsAttrib.bLeaveCopy, pMmsMsg->mmsAttrib.msgSize, pMmsMsg->mmsAttrib.msgClass,
432 pMmsMsg->mmsAttrib.expiryTime.time, pMmsMsg->mmsAttrib.bUseDeliveryCustomTime, pMmsMsg->mmsAttrib.deliveryTime.time, pMmsMsg->mmsAttrib.msgStatus);
434 MSG_DEBUG("\n!!!!!!!!! QUERY : %s\n", sqlQuery);
436 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
437 return MSG_ERR_DB_EXEC;
439 if (updateMmsAttachCount(pMmsMsg->msgID, attachCnt) != MSG_SUCCESS)
440 return MSG_ERR_DB_EXEC;
447 msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_filepath)
451 char sqlQuery[MAX_QUERY_LEN + 1];
454 memset(sqlQuery, 0x00, sizeof(sqlQuery));
455 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, %d, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);",
456 MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsMsg->msgID, pMmsMsg->szTrID, pMmsMsg->szMsgID, pMmsMsg->szForwardMsgID, pMmsMsg->szContentLocation,
457 raw_filepath, pMmsMsg->mmsAttrib.version, pMmsMsg->mmsAttrib.dataType, pMmsMsg->mmsAttrib.date, pMmsMsg->mmsAttrib.bHideAddress,
458 pMmsMsg->mmsAttrib.bAskDeliveryReport, pMmsMsg->mmsAttrib.bReportAllowed, pMmsMsg->mmsAttrib.readReportAllowedType,
459 pMmsMsg->mmsAttrib.bAskReadReply, pMmsMsg->mmsAttrib.bRead, pMmsMsg->mmsAttrib.readReportSendStatus, pMmsMsg->mmsAttrib.bReadReportSent,
460 pMmsMsg->mmsAttrib.priority, pMmsMsg->mmsAttrib.bLeaveCopy, pMmsMsg->mmsAttrib.msgSize, pMmsMsg->mmsAttrib.msgClass,
461 pMmsMsg->mmsAttrib.expiryTime.time, pMmsMsg->mmsAttrib.bUseDeliveryCustomTime, pMmsMsg->mmsAttrib.deliveryTime.time, pMmsMsg->mmsAttrib.msgStatus);
463 MSG_DEBUG("\n!!!!!!!!! QUERY : %s\n", sqlQuery);
465 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
466 return MSG_ERR_DB_EXEC;
473 msg_error_t MmsPluginStorage::plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
477 msg_error_t err = MSG_SUCCESS;
478 MMS_MESSAGE_DATA_S tempMmsMsg = {0,};
479 MMS_MESSAGE_DATA_S *pMmsMsg = &tempMmsMsg;
481 unsigned int nSize = 0;
484 MmsAttrib pMmsAttrib;
486 char szBuf[MSG_FILEPATH_LEN_MAX + 1] = {0, };
487 bool bMultipartRelated = false;
489 if (pSendOptInfo != NULL) {
490 char sqlQuery[MAX_QUERY_LEN + 1];
492 memset(sqlQuery, 0x00, sizeof(sqlQuery));
493 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ASK_DELIVERY_REPORT, KEEP_COPY, ASK_READ_REPLY, PRIORITY, EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME \
494 FROM %s WHERE MSG_ID = %d;", MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsg->msgId);
496 MSG_DEBUG("### SQLQuery = %s ###", sqlQuery);
498 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
499 MSG_DEBUG("MSG_ERR_DB_PREPARE");
501 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
502 pSendOptInfo->bDeliverReq = dbHandle.columnInt(0);
503 MSG_DEBUG("## delivery = %d ##", pSendOptInfo->bDeliverReq);
505 pSendOptInfo->bKeepCopy = dbHandle.columnInt(1);
506 MSG_DEBUG("## bKeepCopy = %d ##", pSendOptInfo->bKeepCopy);
508 pSendOptInfo->option.mmsSendOptInfo.bReadReq = dbHandle.columnInt(2);
509 MSG_DEBUG("## bReadReq = %d ##", pSendOptInfo->option.mmsSendOptInfo.bReadReq);
511 pSendOptInfo->option.mmsSendOptInfo.priority = dbHandle.columnInt(3);
512 MSG_DEBUG("## priority = %d ##", pSendOptInfo->option.mmsSendOptInfo.priority);
514 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = (unsigned int)dbHandle.columnInt(4);
515 MSG_DEBUG("## expiryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.expiryTime.time);
517 pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = (unsigned int)dbHandle.columnInt(5);
518 MSG_DEBUG("## bUseDeliveryCustomTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime);
520 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)dbHandle.columnInt(6);
521 MSG_DEBUG("## deliveryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time);
523 dbHandle.finalizeQuery();
524 return MSG_ERR_DB_STEP;
527 dbHandle.finalizeQuery();
530 if (MmsReadMsgBody(pMsg->msgId, true, false, NULL) == false) {
531 MSG_DEBUG("The MMS Message might include drm contents!!!");
533 #ifdef __SUPPORT_DRM__
534 if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
535 bool bRetToConvert = true;
537 bRetToConvert = MmsDrm2ConvertMsgBody(mmsHeader.msgType.szOrgFilePath);
539 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_FINISH);
543 ret = remove(mmsHeader.msgType.szOrgFilePath);
545 MSG_DEBUG("remove fail\n");
548 ret = rename(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, mmsHeader.msgType.szOrgFilePath);
550 MSG_DEBUG("rename fail\n");
553 if (MmsDrm2ReadMsgConvertedBody(pMsg, true, false, NULL) == false) {
554 MSG_DEBUG("MmsLoadMsg:MmsDrm2ReadMsgConvertedBody() returns false\n");
564 MmsGetMsgAttrib(pMsg->msgId, &pMmsAttrib);
566 pMmsMsg->regionCnt = 0;
567 pMmsMsg->pageCnt = 0;
568 pMmsMsg->attachCnt = 0;
569 pMmsMsg->transitionCnt = 0;
570 pMmsMsg->metaCnt = 0;
571 memset(pMmsMsg->szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
573 if (pMmsAttrib.contentType == MIME_MULTIPART_RELATED || pMmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
574 char *pSmilDoc = NULL;
576 pSmilDoc = MmsSmilGetPresentationData(pMsg->msgId);
581 MmsSmilParseSmilDoc(pMmsMsg, pSmilDoc);
582 MmsRemovePims(pMmsMsg);
583 bMultipartRelated = true;
586 partCnt = MmsGetMediaPartCount(pMsg->msgId);
587 MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt);
590 MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt);
594 for (int i = 0; i < partCnt; ++i) {
595 if (!MmsGetMediaPartHeader(i, &partHeader)) {
596 MSG_DEBUG("MmsUiGetMediaAttachInfo: MmsGetMediaPartHeader failed\n");
600 if (partHeader.contentSize > 0) {
601 if (!strcasecmp(partHeader.param.szFileName, "cid:")) {
602 strncpy((char *)szBuf, &partHeader.param.szFileName[4], MSG_FILEPATH_LEN_MAX);
604 strncpy((char *)szBuf, partHeader.param.szFileName, MSG_FILEPATH_LEN_MAX);
606 sprintf(partHeader.param.szFileName, MSG_DATA_PATH"%s", szBuf);
608 if (!bMultipartRelated || MmsCheckAdditionalMedia(pMmsMsg, &partHeader)) {
610 MMS_ATTACH_S *attachment = NULL;
613 attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
615 MsgGetTypeByFileName(&tempType, partHeader.param.szFileName);
616 attachment->mediatype = (MimeType)tempType;
618 strcpy(attachment->szFilePath, partHeader.param.szFileName);
620 strncpy(attachment->szFileName, partHeader.param.szName, MSG_FILENAME_LEN_MAX -1);
622 attachment->fileSize = partHeader.contentSize;
624 _MsgMmsAddAttachment(pMmsMsg, attachment);
629 *pDestMsg = _MsgMmsSerializeMessageData(pMmsMsg, &nSize);
631 MsgMmsReleaseMmsLists(pMmsMsg);
635 MmsPluginStorage::instance()->getMmsMessage(&pStoMmsMsg);
637 MmsUnregisterDecodeBuffer();
638 #ifdef __SUPPORT_DRM__
639 MmsReleaseMsgDRMInfo(&pStoMmsMsg->msgType.drmInfo);
641 MmsReleaseMsgBody(&pStoMmsMsg->msgBody, pStoMmsMsg->msgType.type);
643 pMsg->dataSize = nSize;
649 if (bMultipartRelated) {
650 MsgMmsReleaseMmsLists(pMmsMsg);
654 MSG_DEBUG("MmsPlgUpdateMessage : Update MMS Message Failed");
658 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
661 MmsUnregisterDecodeBuffer();
662 #ifdef __SUPPORT_DRM__
663 MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
665 MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
667 return MSG_ERR_STORAGE_ERROR;
672 msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
676 msg_error_t err = MSG_SUCCESS;
677 char sqlQuery[MAX_QUERY_LEN + 1];
679 MMS_MESSAGE_DATA_S mmsMsgData = {0,};
680 char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
682 bzero(&mmsMsg, sizeof(mmsMsg));
684 memset(sqlQuery, 0x00, sizeof(sqlQuery));
685 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ASK_DELIVERY_REPORT = %d, KEEP_COPY = %d, ASK_READ_REPLY = %d, EXPIRY_TIME = %d, CUSTOM_DELIVERY_TIME = %d, DELIVERY_TIME= %d, PRIORITY = %d \
686 WHERE MSG_ID = %d;", MMS_PLUGIN_MESSAGE_TABLE_NAME, pSendOptInfo->bDeliverReq, pSendOptInfo->bKeepCopy, pSendOptInfo->option.mmsSendOptInfo.bReadReq,
687 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time, pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime, pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time,
688 pSendOptInfo->option.mmsSendOptInfo.priority, pMsgInfo->msgId);
690 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
691 return MSG_ERR_DB_EXEC;
693 if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
695 if (_MsgMmsDeserializeMessageData(&mmsMsgData, pFileData) == false) {
696 MSG_DEBUG("Fail to Deserialize Message Data");
697 THROW(MsgException::MMS_PLG_ERROR, "MMS Message Compose Error");
700 if (MmsComposeSendReq(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData) != true) {
701 MmsReleaseMmsMsg(&mmsMsg);
702 MsgMmsReleaseMmsLists(&mmsMsgData);
703 THROW(MsgException::MMS_PLG_ERROR, "MMS Message MmsComposeSendReq Error");
707 snprintf(raw_filepath, sizeof(raw_filepath), MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
710 if (MmsEncodeMmsMessage(&mmsMsg, raw_filepath) == false) {
711 MSG_DEBUG("Fail to Encode Message");
712 MmsReleaseMmsMsg(&mmsMsg);
713 MsgMmsReleaseMmsLists(&mmsMsgData);
714 THROW(MsgException::MMS_PLG_ERROR, "MMS Message Encode Error");
718 err = MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
720 err = getMsgText(&mmsMsgData, pMsgInfo->msgText);
722 if (mmsMsgData.attachCnt > 0) {
723 if (updateMmsAttachCount(mmsMsg.msgID, mmsMsgData.attachCnt) != MSG_SUCCESS) {
724 MSG_DEBUG("Fail to updateMmsAttachCount");
730 if (MsgGetFileSize(raw_filepath, &size) == false) {
731 MmsReleaseMmsMsg(&mmsMsg);
732 MsgMmsReleaseMmsLists(&mmsMsgData);
733 THROW(MsgException::MMS_PLG_ERROR, "MMS Message MsgGetFileSize Error");
736 pMsgInfo->dataSize = size;
739 MmsReleaseMmsMsg(&mmsMsg);
740 MsgMmsReleaseMmsLists(&mmsMsgData);
748 msg_error_t MmsPluginStorage::updateConfMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
752 char sqlQuery[MAX_QUERY_LEN + 1];
754 MMS_RECV_DATA_S *pMmsRecvData = (MMS_RECV_DATA_S *)pMsgInfo->msgData;
756 MSG_DEBUG("###### pMsgInfo->msgData = %s #######", pMmsRecvData->retrievedFilePath);
758 memset(sqlQuery, 0x00, sizeof(sqlQuery));
759 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MESSAGE_ID = '%s', FILE_PATH = '%s' WHERE MSG_ID = %d;",
760 MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsRecvData->szMsgID, pMmsRecvData->retrievedFilePath, pMsgInfo->msgId);
762 MSG_DEBUG("SQLQuery = %s", sqlQuery);
764 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
765 return MSG_ERR_DB_EXEC;
773 msg_error_t MmsPluginStorage::updateMsgServerID(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
777 char sqlQuery[MAX_QUERY_LEN + 1];
778 memset(sqlQuery, 0x00, sizeof(sqlQuery));
780 MMS_RECV_DATA_S *pMmsRecvData = (MMS_RECV_DATA_S *)pMsgInfo->msgData;
782 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MESSAGE_ID = '%s' WHERE MSG_ID = %d;",
783 MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsRecvData->szMsgID, pMsgInfo->msgId);
785 MSG_DEBUG("SQLQuery = %s", sqlQuery);
787 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
788 return MSG_ERR_DB_EXEC;
790 if (pSendOptInfo != NULL) {
791 memset(sqlQuery, 0x00, sizeof(sqlQuery));
792 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ASK_DELIVERY_REPORT = %d, ASK_READ_REPLY = %d, PRIORITY = %d, EXPIRY_TIME = %d \
793 WHERE MSG_ID = %d;", MMS_PLUGIN_MESSAGE_TABLE_NAME, pSendOptInfo->bDeliverReq, pSendOptInfo->option.mmsSendOptInfo.bReadReq,
794 pSendOptInfo->option.mmsSendOptInfo.priority, pSendOptInfo->option.mmsSendOptInfo.expiryTime.time, pMsgInfo->msgId);
796 MSG_DEBUG("SQLQuery = %s", sqlQuery);
798 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
799 return MSG_ERR_DB_EXEC;
803 dbHandle.finalizeQuery();
811 msg_error_t MmsPluginStorage::updateNetStatus(msg_message_id_t msgId, msg_network_status_t netStatus)
813 char sqlQuery[MAX_QUERY_LEN + 1];
815 memset(sqlQuery, 0x00, sizeof(sqlQuery));
817 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d WHERE MSG_ID = %d;",
818 MSGFW_MESSAGE_TABLE_NAME, netStatus, msgId);
820 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
821 return MSG_ERR_DB_EXEC;
826 msg_error_t MmsPluginStorage::insertDeliveryReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus)
828 char sqlQuery[MAX_QUERY_LEN + 1];
829 memset(sqlQuery, 0x00, sizeof(sqlQuery));
831 //( MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME);
832 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
833 "(MSG_ID, ADDRESS_VAL, STATUS_TYPE, STATUS, TIME) "
834 "VALUES (%d, '%s', %d, %d, %d);",
835 MSGFW_REPORT_TABLE_NAME, msgId, address, MSG_REPORT_TYPE_DELIVERY, pStatus->msgStatus, (int)pStatus->handledTime);
837 MSG_DEBUG("QUERY : [%s]", sqlQuery);
839 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
840 return MSG_ERR_DB_EXEC;
845 msg_error_t MmsPluginStorage::insertReadReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus)
847 char sqlQuery[MAX_QUERY_LEN + 1];
848 memset(sqlQuery, 0x00, sizeof(sqlQuery));
850 //( MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME);
851 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
852 "(MSG_ID, ADDRESS_VAL, STATUS_TYPE, STATUS, TIME) "
853 "VALUES (%d, '%s', %d, %d, %d);",
854 MSGFW_REPORT_TABLE_NAME, msgId, address, MSG_REPORT_TYPE_READ, pStatus->readStatus, (int)pStatus->readTime);
856 MSG_DEBUG("QUERY : [%s]", sqlQuery);
858 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
859 return MSG_ERR_DB_EXEC;
864 msg_error_t MmsPluginStorage::updateMmsAttrib(msg_message_id_t msgId, MmsAttrib *attrib, MSG_SUB_TYPE_T msgSubType)
868 char sqlQuery[MAX_QUERY_LEN + 1];
870 memset(sqlQuery, 0x00, sizeof(sqlQuery));
872 if (msgSubType == MSG_NOTIFICATIONIND_MMS) {
873 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET EXPIRY_TIME = %d WHERE MSG_ID = %d;",
874 MMS_PLUGIN_MESSAGE_TABLE_NAME, attrib->expiryTime.time, msgId);
875 } else if (msgSubType == MSG_RETRIEVE_AUTOCONF_MMS || msgSubType == MSG_RETRIEVE_MANUALCONF_MMS) {
876 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ASK_DELIVERY_REPORT = %d, ASK_READ_REPLY = %d, PRIORITY = %d, VERSION = %d WHERE MSG_ID = %d;",
877 MMS_PLUGIN_MESSAGE_TABLE_NAME, attrib->bAskDeliveryReport, attrib->bAskReadReply, attrib->priority, attrib->version, msgId);
880 MSG_DEBUG("QUERY : [%s]", sqlQuery);
882 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
883 return MSG_ERR_DB_EXEC;
891 msg_error_t MmsPluginStorage::updateMmsAttachCount(msg_message_id_t msgId, int count)
895 char sqlQuery[MAX_QUERY_LEN + 1];
897 memset(sqlQuery, 0x00, sizeof(sqlQuery));
898 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ATTACHMENT_COUNT = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, count, msgId);
900 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
901 MSG_DEBUG("Fail to execute query [%s]", sqlQuery);
902 return MSG_ERR_DB_EXEC;
910 void MmsPluginStorage::getMmsFromDB(msg_message_id_t msgId, MmsMsg *pMmsMsg)
912 char sqlQuery[MAX_QUERY_LEN + 1];
914 memset(sqlQuery, 0x00, sizeof(sqlQuery));
916 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VERSION, DATA_TYPE, DATE, HIDE_ADDRESS, ASK_DELIVERY_REPORT, REPORT_ALLOWED, \
917 READ_REPORT_ALLOWED_TYPE, ASK_READ_REPLY, READ, READ_REPORT_SEND_STATUS, READ_REPORT_SENT, PRIORITY, \
918 MSG_SIZE, MSG_CLASS, EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME, MSG_STATUS, \
919 MESSAGE_ID, TRANSACTION_ID, CONTENTS_LOCATION, FILE_PATH \
920 FROM %s WHERE MSG_ID = %d;",
921 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
923 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
924 MSG_DEBUG("MSG_ERR_DB_PREPARE");
926 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
928 pMmsMsg->mmsAttrib.version = dbHandle.columnInt(i++);
929 pMmsMsg->mmsAttrib.dataType = (MmsDataType)dbHandle.columnInt(i++);
930 pMmsMsg->mmsAttrib.date = dbHandle.columnInt(i++);
931 pMmsMsg->mmsAttrib.bHideAddress = dbHandle.columnInt(i++);
932 pMmsMsg->mmsAttrib.bAskDeliveryReport = dbHandle.columnInt(i++);
933 pMmsMsg->mmsAttrib.bReportAllowed = dbHandle.columnInt(i++);
934 pMmsMsg->mmsAttrib.readReportAllowedType = (MmsRecvReadReportType)dbHandle.columnInt(i++);
935 pMmsMsg->mmsAttrib.bAskReadReply = dbHandle.columnInt(i++);
936 pMmsMsg->mmsAttrib.bRead = dbHandle.columnInt(i++);
937 pMmsMsg->mmsAttrib.readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle.columnInt(i++);
938 pMmsMsg->mmsAttrib.bReadReportSent = dbHandle.columnInt(i++);
939 pMmsMsg->mmsAttrib.priority = (MmsPriority)dbHandle.columnInt(i++);
940 pMmsMsg->mmsAttrib.msgSize = dbHandle.columnInt(i++);
941 pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)dbHandle.columnInt(i++);
942 pMmsMsg->mmsAttrib.expiryTime.time = dbHandle.columnInt(i++);
943 i++;//CUSTOM_DELIVERY_TIME
944 pMmsMsg->mmsAttrib.deliveryTime.time = dbHandle.columnInt(i++);
945 pMmsMsg->mmsAttrib.msgStatus = (msg_delivery_report_status_t)dbHandle.columnInt(i++);
946 snprintf(pMmsMsg->szMsgID, sizeof(pMmsMsg->szMsgID), "%s", dbHandle.columnText(i++));
947 snprintf(pMmsMsg->szTrID, sizeof(pMmsMsg->szTrID), "%s", dbHandle.columnText(i++));
948 snprintf(pMmsMsg->szContentLocation, sizeof(pMmsMsg->szContentLocation), "%s", dbHandle.columnText(i++));
949 snprintf(pMmsMsg->szFileName, sizeof(pMmsMsg->szFileName), "%s", dbHandle.columnText(i++));
953 dbHandle.finalizeQuery();
956 void MmsPluginStorage::getMmsAttrib(msg_message_id_t msgId, MmsMsg *pMmsMsg)
958 char sqlQuery[MAX_QUERY_LEN + 1];
960 memset(sqlQuery, 0x00, sizeof(sqlQuery));
962 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VERSION, DATA_TYPE, DATE, HIDE_ADDRESS, ASK_DELIVERY_REPORT, REPORT_ALLOWED, \
963 READ_REPORT_ALLOWED_TYPE, ASK_READ_REPLY, READ, READ_REPORT_SEND_STATUS, READ_REPORT_SENT, PRIORITY, \
964 MSG_SIZE, MSG_CLASS, EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME, MSG_STATUS FROM %s WHERE MSG_ID = %d;",
965 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
967 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
968 MSG_DEBUG("MSG_ERR_DB_PREPARE");
970 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
971 pMmsMsg->mmsAttrib.version = dbHandle.columnInt(1);
972 pMmsMsg->mmsAttrib.dataType = (MmsDataType)dbHandle.columnInt(2);
973 pMmsMsg->mmsAttrib.date = dbHandle.columnInt(3);
974 pMmsMsg->mmsAttrib.bHideAddress = dbHandle.columnInt(4);
975 pMmsMsg->mmsAttrib.bAskDeliveryReport = dbHandle.columnInt(5);
976 pMmsMsg->mmsAttrib.bReportAllowed = dbHandle.columnInt(6);
977 pMmsMsg->mmsAttrib.readReportAllowedType = (MmsRecvReadReportType)dbHandle.columnInt(7);
978 pMmsMsg->mmsAttrib.bAskReadReply = dbHandle.columnInt(8);
979 pMmsMsg->mmsAttrib.bRead = dbHandle.columnInt(9);
980 pMmsMsg->mmsAttrib.readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle.columnInt(10);
981 pMmsMsg->mmsAttrib.bReadReportSent = dbHandle.columnInt(11);
982 pMmsMsg->mmsAttrib.priority = (MmsPriority)dbHandle.columnInt(12);
983 pMmsMsg->mmsAttrib.msgSize = dbHandle.columnInt(13);
984 pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)dbHandle.columnInt(14);
985 pMmsMsg->mmsAttrib.expiryTime.time = dbHandle.columnInt(15);
986 pMmsMsg->mmsAttrib.deliveryTime.time = dbHandle.columnInt(17);
987 pMmsMsg->mmsAttrib.msgStatus = (msg_delivery_report_status_t)dbHandle.columnInt(18);
990 dbHandle.finalizeQuery();
994 msg_error_t MmsPluginStorage::getMmsMessageId(msg_message_id_t selectedMsgId, MmsMsg *pMmsMsg)
996 msg_error_t err = MSG_SUCCESS;
1000 char sqlQuery[MAX_QUERY_LEN + 1];
1002 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1004 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MESSAGE_ID FROM %s WHERE MSG_ID = %d;",
1005 MMS_PLUGIN_MESSAGE_TABLE_NAME, selectedMsgId);
1007 err = dbHandle.getTable(sqlQuery, &rowCnt);
1009 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1010 dbHandle.freeTable();
1011 MSG_DEBUG("[Error]Failed to Get Table");
1012 return MSG_ERR_DB_NORECORD;
1016 dbHandle.freeTable();
1017 MSG_DEBUG("[Error] MSG_ERR_DB_NORECORD");
1018 return MSG_ERR_DB_NORECORD;
1021 dbHandle.getColumnToString(1, MMS_MSG_ID_LEN + 1, pMmsMsg->szMsgID);
1023 dbHandle.freeTable();
1029 int MmsPluginStorage::getMmsVersion(msg_message_id_t selectedMsgId)
1031 msg_error_t err = MSG_SUCCESS;
1036 char sqlQuery[MAX_QUERY_LEN + 1];
1038 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1040 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VERSION FROM %s WHERE MSG_ID = %d;",
1041 MMS_PLUGIN_MESSAGE_TABLE_NAME, selectedMsgId);
1043 MSG_DEBUG("SqlQuery = %s", sqlQuery);
1045 err = dbHandle.getTable(sqlQuery, &rowCnt);
1047 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
1048 dbHandle.freeTable();
1049 MSG_DEBUG("[Error]Failed to Get Table");
1054 dbHandle.freeTable();
1055 MSG_DEBUG("[Error]MSG_ERR_DB_NORECORD");
1059 version = dbHandle.getColumnToInt(1);
1061 dbHandle.freeTable();
1067 msg_error_t MmsPluginStorage::getContentLocation(MSG_MESSAGE_INFO_S *pMsgInfo)
1069 char sqlQuery[MAX_QUERY_LEN + 1];
1071 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1073 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONTENTS_LOCATION FROM %s WHERE MSG_ID = %d;",
1074 MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsgInfo->msgId);
1076 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
1077 return MSG_ERR_DB_PREPARE;
1079 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1080 if (dbHandle.columnText(0) != NULL) {
1081 strncpy(pMsgInfo->msgData, (char *)dbHandle.columnText(0), (strlen((char *)dbHandle.columnText(0)) > MAX_MSG_DATA_LEN ? MAX_MSG_DATA_LEN : strlen((char *)dbHandle.columnText(0))));
1082 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
1085 dbHandle.finalizeQuery();
1087 return MSG_ERR_DB_STEP;
1090 dbHandle.finalizeQuery();
1096 /* reject_msg_support */
1097 msg_error_t MmsPluginStorage::getTrID(MSG_MESSAGE_INFO_S *pMsgInfo,char *pszTrID,int nBufferLen)
1099 char sqlQuery[MAX_QUERY_LEN + 1];
1101 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1103 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT TRANSACTION_ID FROM %s WHERE MSG_ID = %d;",
1104 MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsgInfo->msgId);
1106 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
1107 return MSG_ERR_DB_PREPARE;
1109 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1110 if (dbHandle.columnText(0) != NULL) {
1111 strncpy(pszTrID, (char *)dbHandle.columnText(0), nBufferLen - 1);
1112 pszTrID[nBufferLen-1] = '\0';
1115 dbHandle.finalizeQuery();
1117 return MSG_ERR_DB_STEP;
1120 dbHandle.finalizeQuery();
1124 /* reject_msg_support */
1126 msg_error_t MmsPluginStorage::getAddressInfo(msg_message_id_t msgId, MSG_ADDRESS_INFO_S *pAddrInfo)
1128 char sqlQuery[MAX_QUERY_LEN+1];
1131 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1133 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_TYPE, A.RECIPIENT_TYPE, A.CONTACT_ID, A.ADDRESS_VAL \
1134 FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.MSG_ID = %d;",
1135 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, msgId);
1137 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
1138 return MSG_ERR_DB_PREPARE;
1140 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1141 pAddrInfo->addressType = dbHandle.columnInt(0);
1142 pAddrInfo->recipientType = dbHandle.columnInt(1);
1143 pAddrInfo->contactId = dbHandle.columnInt(2);
1145 strncpy(pAddrInfo->addressVal, (char*)dbHandle.columnText(3), MAX_ADDRESS_VAL_LEN);
1147 dbHandle.finalizeQuery();
1148 return MSG_ERR_DB_STEP;
1151 dbHandle.finalizeQuery();
1157 msg_error_t MmsPluginStorage::getMmsRawFilePath(msg_message_id_t msgId, char *pFilepath)
1159 char sqlQuery[MAX_QUERY_LEN + 1];
1161 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1163 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
1164 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
1166 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
1167 return MSG_ERR_DB_PREPARE;
1169 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1170 if (dbHandle.columnText(0) != NULL) {
1171 strcpy(pFilepath, (char *)dbHandle.columnText(0));
1174 dbHandle.finalizeQuery();
1176 return MSG_ERR_DB_STEP;
1179 dbHandle.finalizeQuery();
1185 int MmsPluginStorage::searchMsgId(char *toNumber, char *szMsgID)
1189 msg_folder_id_t folderId = MSG_SENTBOX_ID;
1191 char sqlQuery[MAX_QUERY_LEN + 1];
1193 MmsAddrUtilRemovePlmnString(toNumber);
1195 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1197 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.MSG_ID FROM %s A, %s B \
1198 WHERE A.MSG_ID = B.MSG_ID AND A.FOLDER_ID = %d AND B.MESSAGE_ID LIKE '%%%s%%'",
1199 MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, szMsgID);
1201 MSG_DEBUG("sqlQuery [%s]", sqlQuery);
1203 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
1204 return MSG_ERR_DB_PREPARE;
1206 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1207 msgId = dbHandle.columnInt(0);
1210 dbHandle.finalizeQuery();
1216 msg_error_t MmsPluginStorage::setReadReportSendStatus(msg_message_id_t msgId, int readReportSendStatus)
1218 bool bReadReportSent = false;
1220 if ((MmsRecvReadReportSendStatus)readReportSendStatus == MMS_RECEIVE_READ_REPORT_SENT)
1221 bReadReportSent = true;
1223 bReadReportSent = false;
1225 char sqlQuery[MAX_QUERY_LEN + 1];
1227 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1229 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_REPORT_SEND_STATUS = %d, READ_REPORT_SENT = %d WHERE MSG_ID = %d;",
1230 MMS_PLUGIN_MESSAGE_TABLE_NAME, (MmsRecvReadReportSendStatus)readReportSendStatus, (int)bReadReportSent, msgId);
1232 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
1233 return MSG_ERR_DB_EXEC;
1239 msg_error_t MmsPluginStorage::getMsgText(MMS_MESSAGE_DATA_S *pMmsMsg, char *pMsgText)
1241 MMS_PAGE_S *pPage = NULL;
1242 MMS_MEDIA_S *pMedia = NULL;
1243 char *pMmsMsgText = NULL;
1247 if (pMmsMsg == NULL)
1248 return MSG_ERR_NULL_POINTER;
1250 // Get the text data from the 1st slide.
1251 for (int i = 0; i< pMmsMsg->pageCnt; ++i) {
1252 pPage = _MsgMmsGetPage(pMmsMsg, i);
1254 for (int j = 0; j < pPage->mediaCnt; ++j) {
1255 pMedia = _MsgMmsGetMedia(pPage, j);
1257 if (pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
1258 pMmsMsgText = MsgOpenAndReadMmsFile(pMedia->szFilePath, 0, -1, &textLen);
1260 strncpy(pMsgText, pMmsMsgText, MAX_MSG_TEXT_LEN);
1262 // for avoiding break character end of the string.
1263 if ((textLen >= MAX_MSG_TEXT_LEN) && pMsgText[MAX_MSG_TEXT_LEN - 1] >= 0x80) { // if it is multibyte chars by UTF8, it would be presendted by 1xxx xxxx
1264 for (int k = 1; k < 5; k++) {
1265 // the first byte of multi-byte chars of UTF8, should be larger than 1100 0000
1266 // (two byte chars start with 110x xxxx, and three byte chars start with 1110 xxxx,
1267 // four byte chars start with 1111 0xxx)
1268 if ((pMsgText[MAX_MSG_TEXT_LEN - k] >= 0xC0)) {
1269 pMsgText[MAX_MSG_TEXT_LEN - k] = '\0';
1291 msg_error_t MmsPluginStorage::insertPreviewInfo(int msgId, int type, char *value, int count)
1293 char sqlQuery[MAX_QUERY_LEN + 1];
1294 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1296 //(MSG_ID INTEGER, TYPE INTEGER, INFO TEXT)
1297 snprintf(sqlQuery, sizeof(sqlQuery),
1299 "(MSG_ID, TYPE, VALUE, COUNT)"
1300 "VALUES (%d, %d, '%s', %d);",
1301 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, type, value, count);
1303 MSG_DEBUG("QUERY : [%s]", sqlQuery);
1305 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
1306 return MSG_ERR_DB_EXEC;
1311 msg_error_t MmsPluginStorage::removePreviewInfo(int msgId)
1313 char sqlQuery[MAX_QUERY_LEN + 1];
1314 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0,};
1316 // remove thumbnail file
1317 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1318 snprintf(sqlQuery, sizeof(sqlQuery),
1319 "SELECT VALUE FROM %s "
1320 "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
1321 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
1323 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
1324 return MSG_ERR_DB_PREPARE;
1327 while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1329 memset(filePath, 0x00, sizeof(filePath));
1330 strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
1331 if (remove(filePath) == -1)
1332 MSG_DEBUG("Fail to delete file [%s]", filePath);
1334 MSG_DEBUG("Success to delete file [%s]", filePath);
1337 dbHandle.finalizeQuery();
1339 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1340 //(MSG_ID INTEGER, TYPE INTEGER, INFO TEXT)
1341 snprintf(sqlQuery, sizeof(sqlQuery),
1342 "DELETE FROM %s WHERE MSG_ID= %d;",
1343 MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
1345 MSG_DEBUG("QUERY : [%s]", sqlQuery);
1347 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
1348 return MSG_ERR_DB_EXEC;
1353 msg_error_t MmsPluginStorage::deleteMmsMessage(int msgId)
1355 char sqlQuery[MAX_QUERY_LEN + 1];
1356 char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0,};
1357 char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0,};
1360 removePreviewInfo(msgId);
1362 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1363 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
1364 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
1366 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
1367 dbHandle.endTrans(false);
1368 return MSG_ERR_DB_PREPARE;
1371 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
1372 strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
1374 snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
1377 if (remove(filePath) == -1)
1378 MSG_DEBUG("Fail to delete file [%s]", filePath);
1380 MSG_DEBUG("Success to delete file [%s]", filePath);
1382 //delete multipart files
1385 //delete multipart dir
1389 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
1390 dbHandle.finalizeQuery();
1391 dbHandle.endTrans(false);
1392 return MSG_ERR_DB_STEP;
1395 dbHandle.finalizeQuery();
1398 // Delete Data from MMS table
1399 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1400 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1401 MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
1403 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
1404 dbHandle.endTrans(false);
1405 return MSG_ERR_DB_EXEC;
1408 // Delete Data from MMS STATUS table
1409 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1410 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
1411 MSGFW_REPORT_TABLE_NAME, msgId);
1413 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
1414 dbHandle.endTrans(false);
1415 return MSG_ERR_DB_EXEC;
1421 msg_error_t MmsPluginStorage::plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
1425 msg_error_t err = MSG_SUCCESS;
1426 MMS_MESSAGE_DATA_S tempMmsMsgData = {0,};
1427 MMS_MESSAGE_DATA_S *pMmsMsg = &tempMmsMsgData;
1429 unsigned int nSize = 0;
1430 bool bMultipartRelated = false;
1432 bzero(pMmsMsg, sizeof(MMS_MESSAGE_DATA_S));
1433 pMmsMsg->regionCnt = 0;
1434 pMmsMsg->pageCnt = 0;
1435 pMmsMsg->attachCnt = 0;
1436 pMmsMsg->transitionCnt = 0;
1437 pMmsMsg->metaCnt = 0;
1438 memset(pMmsMsg->szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
1441 memset(&tempMmsMsg, 0x00, sizeof(MmsMsg));
1443 getMmsFromDB(pMsg->msgId, &tempMmsMsg);
1445 snprintf(pMmsMsg->header.contentLocation, MSG_MSG_ID_LEN, "%s", tempMmsMsg.szContentLocation);
1446 pMmsMsg->header.mmsVersion = tempMmsMsg.mmsAttrib.version;
1447 pMmsMsg->header.messageClass = tempMmsMsg.mmsAttrib.msgClass;
1448 pMmsMsg->header.mmsPriority = tempMmsMsg.mmsAttrib.priority;
1449 snprintf(pMmsMsg->header.messageID, MSG_MSG_ID_LEN, "%s", tempMmsMsg.szMsgID);
1450 snprintf(pMmsMsg->header.trID, MSG_MSG_ID_LEN, "%s", tempMmsMsg.szTrID);
1452 if (pSendOptInfo != NULL) {
1454 pSendOptInfo->bDeliverReq = tempMmsMsg.mmsAttrib.bAskDeliveryReport;
1455 MSG_DEBUG("## delivery = %d ##", pSendOptInfo->bDeliverReq);
1457 pSendOptInfo->bKeepCopy = tempMmsMsg.mmsAttrib.bLeaveCopy;
1458 MSG_DEBUG("## bKeepCopy = %d ##", pSendOptInfo->bKeepCopy);
1460 pSendOptInfo->option.mmsSendOptInfo.bReadReq = tempMmsMsg.mmsAttrib.bAskReadReply;
1461 MSG_DEBUG("## bReadReq = %d ##", pSendOptInfo->option.mmsSendOptInfo.bReadReq);
1463 pSendOptInfo->option.mmsSendOptInfo.priority = tempMmsMsg.mmsAttrib.priority;
1464 MSG_DEBUG("## priority = %d ##", pSendOptInfo->option.mmsSendOptInfo.priority);
1466 pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = tempMmsMsg.mmsAttrib.expiryTime.time;
1467 MSG_DEBUG("## expiryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.expiryTime.time);
1469 pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = tempMmsMsg.mmsAttrib.deliveryTime.time;
1470 MSG_DEBUG("## deliveryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time);
1473 switch(pMsg->msgType.subType) {
1474 case MSG_SENDREQ_MMS:
1475 case MSG_SENDCONF_MMS:
1476 case MSG_RETRIEVE_MMS:
1477 case MSG_RETRIEVE_AUTOCONF_MMS:
1478 case MSG_RETRIEVE_MANUALCONF_MMS:
1480 if (MmsReadMsgBody(pMsg->msgId, true, false, NULL) == false) {
1481 MSG_DEBUG("Fail to MmsReadMsgBody");
1486 snprintf(pMmsMsg->header.szContentType, MSG_MSG_ID_LEN, "%s", MimeGetMimeStringFromMimeInt(mmsMsg.msgType.type));
1487 pMmsMsg->header.contentType = mmsMsg.msgType.type;
1488 pMmsMsg->header.messageType = mmsMsg.mmsAttrib.msgType;
1491 if (MmsMakeMmsData(&mmsMsg, pMmsMsg) == false) {
1492 MSG_DEBUG("Fail to makeMmsMessageData");
1498 case MSG_NOTIFICATIONIND_MMS:
1499 pMmsMsg->header.messageType = MMS_MSGTYPE_NOTIFICATION_IND;
1509 *pDestMsg = _MsgMmsSerializeMessageData(pMmsMsg, &nSize);
1511 MsgMmsReleaseMmsLists(pMmsMsg);
1515 MmsPluginStorage::instance()->getMmsMessage(&pStoMmsMsg);
1517 MmsUnregisterDecodeBuffer();
1518 #ifdef __SUPPORT_DRM__
1519 MmsReleaseMsgDRMInfo(&pStoMmsMsg->msgType.drmInfo);
1521 MmsReleaseMsgBody(&pStoMmsMsg->msgBody, pStoMmsMsg->msgType.type);
1523 pMsg->dataSize = nSize;
1530 if (bMultipartRelated) {
1531 MsgMmsReleaseMmsLists(pMmsMsg);
1536 MSG_DEBUG("MmsPlgUpdateMessage : Update MMS Message Failed");
1540 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
1543 MmsUnregisterDecodeBuffer();
1544 #ifdef __SUPPORT_DRM__
1545 MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
1547 MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
1549 return MSG_ERR_STORAGE_ERROR;
1553 void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
1558 char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
1560 MMS_MESSAGE_DATA_S mmsMsgData;
1562 bzero(&mmsMsgData, sizeof(MMS_MESSAGE_DATA_S));
1563 bzero(&mmsMsg, sizeof(mmsMsg));
1565 if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
1567 if (_MsgMmsDeserializeMessageData(&mmsMsgData, pFileData) == false) {
1568 MSG_DEBUG("Fail to Deserialize Message Data");
1572 if (MmsComposeMessage(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData, pFileData) != true) {
1573 MSG_DEBUG("Fail to Compose Message");
1578 snprintf(raw_filepath, sizeof(raw_filepath), MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
1581 if (MmsEncodeMmsMessage(&mmsMsg, raw_filepath) == false) {
1582 MSG_DEBUG("Fail to Encode Message");
1587 if (addMmsMsgToDB(&mmsMsg, raw_filepath) != MSG_SUCCESS) {
1588 MSG_DEBUG("Fail to add db message");
1593 err = MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
1594 err = getMsgText(&mmsMsgData, pMsgInfo->msgText);
1596 if (mmsMsgData.attachCnt > 0) {
1597 if (updateMmsAttachCount(mmsMsg.msgID, mmsMsgData.attachCnt) != MSG_SUCCESS) {
1598 MSG_DEBUG("Fail to updateMmsAttachCount");
1603 if (MsgGetFileSize(raw_filepath, (int *)&pMsgInfo->dataSize) == false) {
1604 MSG_DEBUG("Fail to get mms file size [%s]", raw_filepath);
1608 MmsReleaseMmsMsg(&mmsMsg);
1609 MsgMmsReleaseMmsLists(&mmsMsgData);
1610 } else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
1612 MmsComposeNotiMessage(&mmsMsg, pMsgInfo->msgId);
1615 if (addMmsMsgToDB(&mmsMsg, "") != MSG_SUCCESS) {
1616 MSG_DEBUG("Fail to add db message");
1620 MmsReleaseMmsMsg(&mmsMsg);
1621 } else if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS) {
1622 MmsMsg *pMsg = NULL;
1623 char szTemp[MAX_MSG_DATA_LEN + 1]= {0, };
1625 if (!MmsReadMsgBody(pMsgInfo->msgId, true, true, pFileData))
1626 THROW(MsgException::MMS_PLG_ERROR, "_MmsReadMsgBody Error");
1628 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
1630 if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS)
1631 pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
1633 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
1634 strcpy(szTemp,pMsgInfo->msgData);
1635 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
1636 strncpy(pMsgInfo->msgData, pFileData, MAX_MSG_DATA_LEN);
1638 MmsPluginStorage *pStorage = MmsPluginStorage::instance();
1640 MMS_MESSAGE_DATA_S mmsMsgData;
1641 bzero(&mmsMsgData,sizeof(MMS_MESSAGE_DATA_S));
1642 if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
1644 char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
1646 mmsMsgData.regionCnt = 0;
1647 mmsMsgData.pageCnt = 0;
1648 mmsMsgData.attachCnt = 0;
1649 mmsMsgData.transitionCnt = 0;
1650 mmsMsgData.metaCnt = 0;
1651 memset(mmsMsgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
1653 pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
1655 MmsSmilParseSmilDoc(&mmsMsgData, pSmilDoc);
1657 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
1658 strcpy(szFileName, pMsg->szFileName);
1660 err = pStorage->getMsgText(&mmsMsgData, pMsgInfo->msgText);
1661 MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
1664 MsgMmsReleaseMmsLists(&mmsMsgData);
1667 if (addMmsMsgToDB(pMsg, pMsgInfo) != MSG_SUCCESS) {
1668 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
1670 THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
1672 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
1673 strcpy((char *)pMsgInfo->msgData,szTemp);
1675 MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
1678 MSG_DEBUG("Not support msg sub type [%d]", pMsgInfo->msgType.subType);
1687 removePreviewInfo(pMsgInfo->msgId);
1688 MmsReleaseMmsMsg(&mmsMsg);
1689 MsgMmsReleaseMmsLists(&mmsMsgData);
1691 THROW(MsgException::MMS_PLG_ERROR, "MMS add Error");