Fix build error
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginAppBase.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 "MsgMmsMessage.h"
18 #include "MmsPluginDebug.h"
19 #include "MmsPluginStorage.h"
20 #include "MmsPluginMessage.h"
21 #include "MmsPluginMIME.h"
22 #include "MmsPluginAppBase.h"
23 #include "MmsPluginUtil.h"
24 #include "MmsPluginTcs.h"
25 #include "MsgUtilFile.h"
26
27 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath);
28
29 MmsPluginAppBase::MmsPluginAppBase(){}
30
31 MmsPluginAppBase::MmsPluginAppBase(MMS_DATA_S *pMmsData)
32 {
33         setMmsData(pMmsData);
34 }
35
36 MmsPluginAppBase::MmsPluginAppBase(MmsMsg *pMmsMsg)
37 {
38         setMmsData(pMmsMsg);
39 }
40
41 MmsPluginAppBase::~MmsPluginAppBase()
42 {
43         MsgMmsReleaseMmsLists(&mmsMsgData);
44 }
45
46 void MmsPluginAppBase::setMmsData(MmsMsg *pMmsMsg)
47 {
48         MmsConvertMsgData(pMmsMsg, &mmsMsgData);
49 }
50
51 void MmsPluginAppBase::setMmsData(MMS_DATA_S *pMmsData)
52 {
53         MsgMmsConvertMmsDataToMmsMessageData(pMmsData, &mmsMsgData);
54 }
55
56 void MmsPluginAppBase::makePreviewInfo(msg_message_id_t  msgId, bool allow_malware, const char *raw_filepath)
57 {
58         MmsMakePreviewInfo(msgId, &mmsMsgData, allow_malware, raw_filepath);
59 }
60
61 void MmsPluginAppBase::getFirstPageTextFilePath(char *textBuf, int textBufSize)
62 {
63
64         MMS_PAGE_S *pPage = NULL;
65         MMS_MEDIA_S *pMedia = NULL;
66
67         MMS_MESSAGE_DATA_S *pMmsMsgData = &mmsMsgData;
68
69         if (pMmsMsgData == NULL)
70                 return;
71
72         // Get the text data from the 1st slide.
73         if (pMmsMsgData->pageCnt > 0) {
74
75                 pPage = _MsgMmsGetPage(pMmsMsgData, 0);
76
77                 if (pPage) {
78
79                         for (int j = 0; j < pPage->mediaCnt; ++j) {
80
81                                 pMedia = _MsgMmsGetMedia(pPage, j);
82
83                                 if (pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
84
85                                         MimeType mimeType = MIME_UNKNOWN;
86
87                                         MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
88
89                                         if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
90                                                 MSG_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
91                                         } else {
92                                                 MSG_DEBUG("Text path : [%s]", pMedia->szFilePath);
93                                                 snprintf(textBuf, textBufSize, "%s", pMedia->szFilePath);//Set Text Filepath of First Pages
94                                         }
95                                         break;
96                                 }
97                         }
98                 }
99         }
100
101         return;
102 }
103
104
105 //FIXME::need to move AppBase
106 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath)
107 {
108         MMS_PAGE_S *pPage = NULL;
109         MMS_MEDIA_S *pMedia = NULL;
110         int bc_level = -1;
111
112         int ref_attach_count = 0;
113         const char * attachment_name = NULL;
114
115         if (pMmsMsg == NULL)
116                 return MSG_ERR_NULL_POINTER;
117
118         MmsPluginStorage::instance()->removePreviewInfo(msgId); //remove exist previnfo
119
120         //scan malware in raw file
121         if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
122                 int tcs_ret = 0; // MmsPluginTcsScanFile(raw_filepath, &bc_level);
123                 if (tcs_ret == 0) {
124                         if (bc_level > -1) {
125                                 MSG_DEBUG("malware exist, level = %d", bc_level);
126                                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_MALWARE, "malware", bc_level);
127                         }
128                 }
129         }
130
131         //check ref type and increase attach count
132         if (pMmsMsg->pageCnt > 0) {
133                 for (int i = 0; i < pMmsMsg->pageCnt; i++) {
134                         pPage = _MsgMmsGetPage(pMmsMsg, i);
135                         if (pPage) {
136                                 for (int j = 0; j < pPage->mediaCnt; j++) {
137                                         pMedia = _MsgMmsGetMedia(pPage, j);
138                                         if (pMedia) { //IF Vobject type add to Attach in Preview data
139
140                                                 MimeType mimeType = MIME_UNKNOWN;
141                                                 MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
142                                                 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD) {
143
144                                                         MSG_DEBUG("Unsupported File [%s] It will be add to attach list", pMedia->szFilePath);
145
146                                                         ref_attach_count++;
147
148                                                         if (attachment_name == NULL) {
149                                                                 attachment_name = pMedia->szFileName;
150                                                         }
151                                                 }
152
153                                         }
154                                 }
155                         }
156                 }
157         }
158
159
160         if (pMmsMsg->pageCnt > 0) {
161
162                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
163
164                 pPage = _MsgMmsGetPage(pMmsMsg, 0);
165
166                 if (pPage) {
167                         for (int j = 0; j < pPage->mediaCnt; j++) {
168
169                                 pMedia = _MsgMmsGetMedia(pPage, j);
170
171                                 if (pMedia == NULL) {
172                                         MSG_ERR("[%d]th pMedia is NULL", j);
173                                         continue;
174                                 }
175
176                                 MSG_SEC_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
177
178                                 if (allow_malware == false && bc_level > -1) {
179                                         if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
180                                                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
181                                         }
182                                 } else {
183
184                                         if (j == 0) { //First Page, First Media
185                                                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_1ST_MEDIA, pMedia->szFilePath);
186                                         }
187
188                                         if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
189                                                 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
190                                                 char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
191                                                 char *pszExt = NULL;
192
193                                                 memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
194                                                 memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
195
196                                                 MSG_DEBUG("drm type = %d, %s", pMedia->drmType, pMedia->szFilePath);
197
198                                                 if (pMedia->drmType == MSG_DRM_TYPE_NONE) {
199
200                                                         snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
201
202                                                         if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
203                                                                 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.png", MSG_THUMBNAIL_PATH, szFileName);
204                                                         } else {
205                                                                 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
206                                                         }
207
208                                                         if (MmsMakeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
209                                                                 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
210                                                                         MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
211                                                                 } else {
212                                                                         MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
213                                                                 }
214                                                         } else {
215                                                                 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
216                                                         }
217                                                 }
218                                         } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
219                                                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
220                                         }
221                                 }
222                         }
223                 } // end for
224         } else {
225                 MSG_DEBUG("There is no page");
226         }
227
228         int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
229         if (attachCnt > 0) {
230
231                 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
232
233                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
234                 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt); // for Get Message
235
236                 if (attachment_name == NULL) {
237                         attachment_name = pAttach->szFileName;
238                 }
239
240         } else {
241                 MSG_DEBUG("There is no attachment");
242         }
243
244         if (attachCnt + ref_attach_count > 0 && attachment_name) {
245
246                 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, attachment_name, attachCnt + ref_attach_count);
247                 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt + ref_attach_count);
248         }
249
250         return MSG_SUCCESS;
251 }