2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/smack.h>
25 #include "MsgMmsTypes.h"
26 #include "MsgUtilFile.h"
27 #include "MsgMmsMessage.h"
28 #include "MsgUtilFile.h"
29 #include "MsgUtilFunction.h"
32 #include "MsgSerialize.h"
34 static void __release_glist_element(gpointer data, gpointer user_data);
35 static void __release_page_element(gpointer data, gpointer user_data);
36 static msg_error_t __releasePageList(MMS_MESSAGE_DATA_S *pMsgData);
37 static msg_error_t __releaseRegionList(MMS_MESSAGE_DATA_S *pMsgData);
38 static msg_error_t __releaseAttachList(MMS_MESSAGE_DATA_S *pMsgData);
39 static msg_error_t __releaseTransitionList(MMS_MESSAGE_DATA_S *pMsgData);
40 static msg_error_t __releaseMetaList(MMS_MESSAGE_DATA_S *pMsgData);
42 void __release_glist_element(gpointer data, gpointer user_data)
49 void __release_page_element(gpointer data, gpointer user_data)
52 MMS_PAGE_S *page = (MMS_PAGE_S *)data;
54 if (page->medialist) {
55 MMS_MEDIA_S *media = NULL;
56 int mediaCnt = g_list_length(page->medialist);
58 for (int i = 0; i < mediaCnt; i++) {
59 media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
64 g_list_free(page->medialist);
65 page->medialist = NULL;
73 msg_error_t __releasePageList(MMS_MESSAGE_DATA_S *pMsgData)
75 if (pMsgData == NULL) {
76 MSG_DEBUG("pMsgData is NULL");
77 return MSG_ERR_INVALID_PARAMETER;
80 if (pMsgData->pagelist) {
81 g_list_foreach(pMsgData->pagelist, __release_page_element, NULL);
82 g_list_free(pMsgData->pagelist);
83 pMsgData->pagelist = NULL;
86 pMsgData->pageCnt = 0;
91 msg_error_t __releaseRegionList(MMS_MESSAGE_DATA_S *pMsgData)
93 if (pMsgData == NULL) {
94 MSG_DEBUG("pMsgData is NULL");
95 return MSG_ERR_INVALID_PARAMETER;
98 if (pMsgData->regionlist) {
99 g_list_foreach(pMsgData->regionlist, __release_glist_element, NULL);
100 g_list_free(pMsgData->regionlist);
101 pMsgData->regionlist = NULL;
104 pMsgData->regionCnt = 0;
109 msg_error_t __releaseAttachList(MMS_MESSAGE_DATA_S *pMsgData)
111 if (pMsgData == NULL) {
112 MSG_DEBUG("pMsgData is NULL");
113 return MSG_ERR_INVALID_PARAMETER;
116 if (pMsgData->attachlist) {
117 g_list_foreach(pMsgData->attachlist, __release_glist_element, NULL);
118 g_list_free(pMsgData->attachlist);
119 pMsgData->attachlist = NULL;
122 pMsgData->attachCnt = 0;
127 msg_error_t __releaseTransitionList(MMS_MESSAGE_DATA_S *pMsgData)
129 if (pMsgData == NULL) {
130 MSG_DEBUG("pMsgData is NULL");
131 return MSG_ERR_INVALID_PARAMETER;
134 if (pMsgData->transitionlist) {
135 g_list_foreach(pMsgData->transitionlist, __release_glist_element, NULL);
136 g_list_free(pMsgData->transitionlist);
137 pMsgData->transitionlist = NULL;
140 pMsgData->transitionCnt = 0;
145 msg_error_t __releaseMetaList(MMS_MESSAGE_DATA_S *pMsgData)
147 if (pMsgData == NULL) {
148 MSG_DEBUG("pMsgData is NULL");
149 return MSG_ERR_INVALID_PARAMETER;
152 if (pMsgData->metalist) {
153 g_list_foreach(pMsgData->metalist, __release_glist_element, NULL);
154 g_list_free(pMsgData->metalist);
155 pMsgData->metalist = NULL;
158 pMsgData->metaCnt = 0;
163 void MsgMmsReleaseMmsLists(MMS_MESSAGE_DATA_S *pMsgData)
165 __releasePageList(pMsgData);
166 __releaseRegionList(pMsgData);
167 __releaseAttachList(pMsgData);
168 __releaseTransitionList(pMsgData);
169 __releaseMetaList(pMsgData);
172 msg_error_t _MsgMmsAddRegion(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_REGION* pRegion)
174 if(pMsgData == NULL || pRegion == NULL)
175 return MSG_ERR_INVALID_PARAMETER;
177 pMsgData->regionlist = g_list_append(pMsgData->regionlist, pRegion);
178 pMsgData->regionCnt++;
183 msg_error_t _MsgMmsAddPage(MMS_MESSAGE_DATA_S *pMsgData, MMS_PAGE_S *pPage)
185 if(pMsgData == NULL || pPage == NULL)
186 return MSG_ERR_INVALID_PARAMETER;
188 pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
190 MSG_DEBUG("MmsData's Page Count : %d", pMsgData->pageCnt);
194 msg_error_t _MsgMmsAddMedia(MMS_PAGE_S* pPage, MMS_MEDIA_S *pMedia)
196 if(pPage == NULL || pMedia == NULL)
197 return MSG_ERR_INVALID_PARAMETER;
199 pPage->medialist = g_list_append(pPage->medialist, pMedia);
201 MSG_DEBUG("Page's media count: %d", pPage->mediaCnt);
205 msg_error_t _MsgMmsAddTransition(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_TRANSITION* pTransition)
207 if(pMsgData == NULL || pTransition == NULL)
208 return MSG_ERR_INVALID_PARAMETER;
210 pMsgData->transitionlist = g_list_append(pMsgData->transitionlist, pTransition);
211 pMsgData->transitionCnt++;
216 msg_error_t _MsgMmsAddMeta(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_META* pMeta)
218 if(pMsgData == NULL || pMeta == NULL)
219 return MSG_ERR_INVALID_PARAMETER;
221 pMsgData->metalist = g_list_append(pMsgData->metalist, pMeta);
227 msg_error_t _MsgMmsAddAttachment(MMS_MESSAGE_DATA_S *pMsgData, MMS_ATTACH_S *pAttach)
229 if(pMsgData == NULL || pAttach == NULL)
230 return MSG_ERR_INVALID_PARAMETER;
232 pMsgData->attachlist = g_list_append(pMsgData->attachlist, pAttach);
233 pMsgData->attachCnt++;
238 int _MsgMmsGetPageCount(MMS_MESSAGE_DATA_S *pMsgData)
240 if (pMsgData == NULL) {
241 MSG_DEBUG("pMsgData is NULL");
247 if (pMsgData->pagelist)
248 count = g_list_length(pMsgData->pagelist);
250 MSG_DEBUG("Page Count: %d", count);
254 MMS_PAGE_S *_MsgMmsGetPage(MMS_MESSAGE_DATA_S *pMsgData, int pageIdx)
256 if (pMsgData == NULL) {
257 MSG_DEBUG("pMsgData is NULL");
261 MMS_PAGE_S *page = NULL;
263 if (pMsgData->pagelist)
264 page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
269 int _MsgMmsGetAttachCount(MMS_MESSAGE_DATA_S *pMsgData)
271 if (pMsgData == NULL) {
272 MSG_DEBUG("pMsgData is NULL");
278 if (pMsgData->attachlist)
279 count = g_list_length(pMsgData->attachlist);
281 MSG_DEBUG("Attachment Count: %d", count);
285 MMS_ATTACH_S *_MsgMmsGetAttachment(MMS_MESSAGE_DATA_S *pMsgData, int attachIdx)
287 if (pMsgData == NULL) {
288 MSG_DEBUG("pMsgData is NULL");
292 MMS_ATTACH_S *attach = NULL;
293 if (pMsgData->attachlist)
294 attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, attachIdx);
299 MMS_SMIL_REGION *_MsgMmsGetSmilRegion(MMS_MESSAGE_DATA_S *pMsgData, int regionIdx)
301 if (pMsgData == NULL) {
302 MSG_DEBUG("pMsgData is NULL");
306 MMS_SMIL_REGION *region = NULL;
308 if (pMsgData->regionlist)
309 region = (MMS_SMIL_REGION *)g_list_nth_data(pMsgData->regionlist, regionIdx);
314 MMS_MEDIA_S *_MsgMmsGetMedia(MMS_PAGE_S *pPage, int mediaIdx)
317 MSG_FATAL("pPage is NULL");
321 if (mediaIdx > pPage->mediaCnt || mediaIdx < 0) {
322 MSG_FATAL("Invalid media index = %d", mediaIdx);
326 MMS_MEDIA_S *media = NULL;
327 if (pPage->medialist)
328 media = (MMS_MEDIA_S *)g_list_nth_data(pPage->medialist, mediaIdx);
333 int _MsgMmsGetTransitionCount(MMS_MESSAGE_DATA_S *pMsgData)
335 if (pMsgData == NULL) {
336 MSG_DEBUG("pMsgData is NULL");
342 if (pMsgData->transitionlist)
343 count = g_list_length(pMsgData->transitionlist);
345 MSG_DEBUG("Transition Count: %d", count);
349 MMS_SMIL_TRANSITION *_MsgMmsGetTransition(MMS_MESSAGE_DATA_S *pMsgData, int transitionIdx)
351 if (pMsgData == NULL) {
352 MSG_DEBUG("pMsgData is NULL");
356 MMS_SMIL_TRANSITION *transition = NULL;
357 if (pMsgData->transitionlist)
358 transition = (MMS_SMIL_TRANSITION *)g_list_nth_data(pMsgData->transitionlist, transitionIdx);
363 MMS_SMIL_META *_MsgMmsGetMeta(MMS_MESSAGE_DATA_S *pMsgData, int metaIdx)
365 if (pMsgData == NULL) {
366 MSG_DEBUG("pMsgData is NULL");
370 MMS_SMIL_META *meta = NULL;
372 if (pMsgData->metalist)
373 meta = (MMS_SMIL_META *)g_list_nth_data(pMsgData->metalist, metaIdx);
378 int _MsgMmsGetMetaCount(MMS_MESSAGE_DATA_S *pMsgData)
380 if (pMsgData == NULL) {
381 MSG_DEBUG("pMsgData is NULL");
387 if (pMsgData->metalist)
388 count = g_list_length(pMsgData->metalist);
390 MSG_DEBUG("Meta Count: %d", count);
394 bool _MsgMmsSetRootLayout(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_ROOTLAYOUT *pRootlayout)
396 memcpy(&pMsgData->rootlayout, pRootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
400 char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, unsigned int *pSize)
404 if (pMsgData == NULL)
412 bufsize += sizeof(int); /* Page cnt */
414 pageCnt = pMsgData->pageCnt;
416 if (pMsgData->pagelist) {
417 for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) {
420 MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
422 mediaCnt = page->mediaCnt;
424 bufsize += sizeof(int); /* Media cnt */
426 if (page->medialist) {
427 bufsize += sizeof(MMS_MEDIA_S) * mediaCnt;
430 bufsize += sizeof(int) * 6; /* Dur, Begin, End, Min, Max, Repeat */
434 bufsize += sizeof(int); /* region count; */
436 if (pMsgData->regionlist) {
437 int elementSize = g_list_length(pMsgData->regionlist);
438 bufsize += elementSize * (sizeof(MMS_SMIL_REGION));
441 bufsize += sizeof(int); /* attachment count; */
442 if (pMsgData->attachlist) {
443 int elementSize = g_list_length(pMsgData->attachlist);
444 bufsize += elementSize * sizeof(MMS_ATTACH_S);
447 bufsize += sizeof(int); /* transition count; */
448 if (pMsgData->transitionlist) {
449 int elementSize = g_list_length(pMsgData->transitionlist);
450 bufsize += elementSize * sizeof(MMS_SMIL_TRANSITION);
453 bufsize += sizeof(int); /* meta count; */
454 if (pMsgData->metalist) {
455 int elementSize = g_list_length(pMsgData->metalist);
456 bufsize += elementSize * sizeof(MMS_SMIL_META);
459 bufsize += sizeof(MMS_SMIL_ROOTLAYOUT);
461 #ifdef FEATURE_JAVA_MMS
462 bufsize += sizeof(MMS_APPID_INFO_S);
465 int filePathLen = strlen(pMsgData->szSmilFilePath);
467 bufsize += sizeof(int) + filePathLen;
469 bufsize += sizeof(int); /* type */
470 bufsize += sizeof(MMS_HEADER_DATA_S);
471 bufsize += sizeof(MMS_MULTIPART_DATA_S);
473 MSG_DEBUG("Serialize bufsize = %d", bufsize);
475 buf = (char *)calloc(bufsize, 1);
480 int serial_index = 0;
482 memcpy(buf, &pMsgData->backup_type, sizeof(int));
483 MSG_DEBUG("[#%2d][%5d] backup type = %d", serial_index++, offset, pMsgData->backup_type);
484 offset += sizeof(int);
487 memcpy(buf + offset , &filePathLen, sizeof(int));
490 MSG_SEC_DEBUG("[#%2d][%5d] smilFilePath = %s, len = %d", serial_index++, offset, pMsgData->szSmilFilePath, filePathLen);
491 offset += sizeof(int);
493 if (filePathLen > 0) {
494 memcpy(buf + offset, pMsgData->szSmilFilePath, filePathLen);
495 offset += filePathLen;
498 /* copy page count */
499 MSG_DEBUG("[#%2d][%5d] page count = %d", serial_index++, offset, pMsgData->pageCnt);
500 memcpy(buf + offset, &(pMsgData->pageCnt), sizeof(int));
501 offset += sizeof(int);
503 if (pMsgData->pagelist) {
504 for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) {
505 MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
507 MSG_DEBUG("[#%2d][%5d][%d page] media count = %d", serial_index++, offset, pageIdx, page->mediaCnt);
508 memcpy(buf + offset, &page->mediaCnt, sizeof(int));
509 offset += sizeof(int);
511 if (page->medialist) {
512 for (int i = 0; i < page->mediaCnt; ++i) {
513 MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
514 memcpy(buf + offset, media, sizeof(MMS_MEDIA_S));
515 offset += sizeof(MMS_MEDIA_S);
516 MSG_SEC_DEBUG("[#%2d][%5d][%d page][%d media] media type [%d], drm type [%d], filepath [%s]", serial_index++, offset, pageIdx, i, media->mediatype, media->drmType, media->szFilePath);
520 memcpy(buf + offset, &page->nDur, sizeof(int));
521 offset += sizeof(int);
522 memcpy(buf + offset, &page->nBegin, sizeof(int));
523 offset += sizeof(int);
524 memcpy(buf + offset, &page->nEnd, sizeof(int));
525 offset += sizeof(int);
526 memcpy(buf + offset, &page->nMin, sizeof(int));
527 offset += sizeof(int);
528 memcpy(buf + offset, &page->nMax, sizeof(int));
529 offset += sizeof(int);
530 memcpy(buf + offset, &page->nRepeat, sizeof(int));
531 offset += sizeof(int);
535 MSG_DEBUG("[#%2d][%5d] region count = %d", serial_index++, offset, pMsgData->regionCnt);
537 memcpy(buf + offset, &pMsgData->regionCnt, sizeof(int));
538 offset += sizeof(int);
540 if (pMsgData->regionlist) {
541 for (int i = 0; i < pMsgData->regionCnt; ++i) {
542 MMS_SMIL_REGION *region = (MMS_SMIL_REGION *)g_list_nth_data(pMsgData->regionlist, i);
543 memcpy(buf + offset, region, sizeof(MMS_SMIL_REGION));
544 offset += sizeof(MMS_SMIL_REGION);
548 MSG_DEBUG("[#%2d][%5d] attach count = %d", serial_index++, offset, pMsgData->attachCnt);
550 memcpy(buf + offset, &pMsgData->attachCnt, sizeof(int));
551 offset += sizeof(int);
553 if (pMsgData->attachlist) {
554 for (int i = 0; i < pMsgData->attachCnt; ++i) {
555 MMS_ATTACH_S *attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, i);
556 memcpy(buf + offset, attach, sizeof(MMS_ATTACH_S));
557 offset += sizeof(MMS_ATTACH_S);
558 MSG_SEC_DEBUG("[#%2d][%5d][%d attach] attach filepath = %s, drm type = [%d]", serial_index++, offset, i, attach->szFilePath, attach->drmType);
562 MSG_DEBUG("[#%2d][%5d] transition count = %d", serial_index++, offset, pMsgData->transitionCnt);
564 memcpy(buf + offset, &pMsgData->transitionCnt, sizeof(int));
565 offset += sizeof(int);
566 if (pMsgData->transitionlist) {
567 for (int i = 0; i < pMsgData->transitionCnt; ++i) {
568 MMS_SMIL_TRANSITION *transition = (MMS_SMIL_TRANSITION *)g_list_nth_data(pMsgData->transitionlist, i);
569 memcpy(buf + offset, transition, sizeof(MMS_SMIL_TRANSITION));
570 offset += sizeof(MMS_SMIL_TRANSITION);
574 MSG_DEBUG("[#%2d][%5d] meta count = %d", serial_index++, offset, pMsgData->metaCnt);
575 memcpy(buf + offset, &pMsgData->metaCnt, sizeof(int));
576 offset += sizeof(int);
578 if (pMsgData->metalist) {
579 for (int i = 0; i < pMsgData->metaCnt; ++i) {
580 MMS_SMIL_META *meta = (MMS_SMIL_META *)g_list_nth_data(pMsgData->metalist, i);
582 memcpy(buf + offset, meta, sizeof(MMS_SMIL_META));
583 offset += sizeof(MMS_SMIL_META);
587 MSG_DEBUG("[#%2d][%5d] root layout", serial_index++, offset);
588 memcpy(buf + offset, &pMsgData->rootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
589 offset += sizeof(MMS_SMIL_ROOTLAYOUT);
591 #ifdef FEATURE_JAVA_MMS
592 MSG_DEBUG("[#%2d][%5d] java mms", serial_index++, offset);
593 memcpy(buf + offset, &pMsgData->msgAppId, sizeof(MMS_APPID_INFO_S));
594 offset += sizeof(MMS_APPID_INFO_S);
597 memcpy (buf + offset, &pMsgData->header, sizeof(MMS_HEADER_DATA_S));
598 MSG_DEBUG("[#%2d][%5d] mms header", serial_index++, offset);
599 offset += sizeof(MMS_HEADER_DATA_S);
601 memcpy (buf + offset, &pMsgData->smil, sizeof(MMS_MULTIPART_DATA_S));
602 MSG_DEBUG("[#%2d][%5d] mms smil", serial_index++, offset);
603 offset += sizeof(MMS_MULTIPART_DATA_S);
607 MSG_DEBUG("Expect Buffer Size: %d, Final offset : %d", bufsize, offset);
612 bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pData)
616 if (pMsgData == NULL || pData == NULL) {
617 MSG_DEBUG("param is NULL. pBody = %p, pData = %s", pMsgData, pData);
625 MMS_PAGE_S *pPage = NULL;
626 MMS_MEDIA_S *pMedia = NULL;
627 MMS_SMIL_REGION *pRegion = NULL;
628 MMS_ATTACH_S *pAttach = NULL;
629 MMS_SMIL_TRANSITION *pTransition = NULL;
630 MMS_SMIL_META *pMeta = NULL;
632 int serial_index = 0;
636 memcpy(&type, pData, sizeof(int));
637 MSG_DEBUG("[#%2d][%5d] backup type = %d", serial_index++, offset, type);
638 offset += sizeof(int);
640 pMsgData->backup_type = type;
642 memcpy(&filePathLen, pData + offset, sizeof(int));
643 MSG_DEBUG("[#%2d][%5d] smil path len = %d", serial_index, offset, filePathLen);
644 offset += sizeof(int);
646 if (filePathLen > MSG_FILEPATH_LEN_MAX) {
647 MSG_DEBUG("Smil File Path Length is abnormal.");
651 memset(pMsgData->szSmilFilePath, 0x00, MSG_FILEPATH_LEN_MAX);
653 if (filePathLen > 0) {
654 memcpy(pMsgData->szSmilFilePath, pData + offset, filePathLen);
655 MSG_DEBUG("[#%2d][%5d] smil path = %s", serial_index, offset, pMsgData->szSmilFilePath);
656 offset += filePathLen;
661 memcpy(&(pMsgData->pageCnt), pData + offset, sizeof(int));
662 MSG_DEBUG("[#%2d][%5d] page count = %d", serial_index++, offset, pMsgData->pageCnt);
663 offset += sizeof(int);
665 pageCnt = pMsgData->pageCnt;
667 for (int j = 0; j < pageCnt; ++j) {
668 pPage = (MMS_PAGE_S *)calloc(sizeof(MMS_PAGE_S), 1);
672 memcpy(&pPage->mediaCnt, pData + offset, sizeof(int));
673 MSG_DEBUG("[#%2d][%5d][%d page] media count = %d", serial_index++, offset, j, pPage->mediaCnt);
674 offset += sizeof(int);
676 for (int i = 0; i < pPage->mediaCnt; ++i) {
677 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
678 if (pMedia == NULL) {
683 memcpy(pMedia, pData + offset, sizeof(MMS_MEDIA_S));
685 offset += sizeof(MMS_MEDIA_S);
687 MSG_SEC_DEBUG("[#%2d][%5d][%d page][%d media] media type [%d], drm type [%d], filepath [%s], content type [%s]", serial_index++, offset, j, i, pMedia->mediatype, pMedia->drmType, pMedia->szFilePath, pMedia->szContentType);
689 if (strlen(pMedia->szFilePath) >0) {
690 pPage->medialist = g_list_append(pPage->medialist, pMedia);
696 pPage->mediaCnt = g_list_length(pPage->medialist);
698 memcpy(&pPage->nDur , pData + offset, sizeof(int));
699 offset += sizeof(int);
700 memcpy(&pPage->nBegin , pData + offset, sizeof(int));
701 offset += sizeof(int);
702 memcpy(&pPage->nEnd , pData + offset, sizeof(int));
703 offset += sizeof(int);
704 memcpy(&pPage->nMin , pData + offset, sizeof(int));
705 offset += sizeof(int);
706 memcpy(&pPage->nMax , pData + offset, sizeof(int));
707 offset += sizeof(int);
708 memcpy(&pPage->nRepeat , pData + offset, sizeof(int));
709 offset += sizeof(int);
711 pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
713 if (pPage->medialist) {
714 pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
722 pMsgData->pageCnt = g_list_length(pMsgData->pagelist);
724 /* Processing Region List */
725 memcpy(&pMsgData->regionCnt, pData + offset, sizeof(int));
726 MSG_DEBUG("[#%2d][%5d] region count = %d", serial_index++, offset, pMsgData->regionCnt);
727 offset += sizeof(int);
729 /* MSG_DEBUG(" pBody->regionCnt: %d", pBody->regionCnt); */
731 for (int i = 0; i < pMsgData->regionCnt; ++i) {
732 pRegion = (MMS_SMIL_REGION *)calloc(sizeof(MMS_SMIL_REGION), 1);
736 memcpy(pRegion, pData + offset, sizeof(MMS_SMIL_REGION));
737 offset += sizeof(MMS_SMIL_REGION);
739 pMsgData->regionlist = g_list_append(pMsgData->regionlist, pRegion);
742 /* Processing Attachment List */
743 memcpy(&pMsgData->attachCnt, pData + offset, sizeof(int));
744 MSG_DEBUG("[#%2d][%5d] attach count = %d", serial_index++, offset, pMsgData->attachCnt);
745 offset += sizeof(int);
747 for (int i = 0; i < pMsgData->attachCnt; ++i) {
748 pAttach = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
752 memcpy(pAttach, pData + offset, sizeof(MMS_ATTACH_S));
753 offset += sizeof(MMS_ATTACH_S);
755 MSG_SEC_DEBUG("[#%2d][%5d][%d attach] drm type [%d], attach filepath = [%s], content type = [%s]", serial_index++, offset, i, pAttach->drmType, pAttach->szFilePath, pAttach->szContentType);
756 if (strlen(pAttach->szFilePath) >0) {
757 pMsgData->attachlist = g_list_append(pMsgData->attachlist, pAttach);
764 pMsgData->attachCnt = g_list_length(pMsgData->attachlist);
766 /* Processing Transition List */
767 memcpy(&pMsgData->transitionCnt, pData + offset, sizeof(int));
768 MSG_DEBUG("[#%2d][%5d] transition count = %d", serial_index++, offset, pMsgData->transitionCnt);
769 offset += sizeof(int);
771 for (int i = 0; i < pMsgData->transitionCnt; ++i) {
772 pTransition = (MMS_SMIL_TRANSITION *)calloc(sizeof(MMS_SMIL_TRANSITION), 1);
773 if (pTransition == NULL)
776 memcpy(pTransition, pData + offset, sizeof(MMS_SMIL_TRANSITION));
777 offset += sizeof(MMS_SMIL_TRANSITION);
779 pMsgData->transitionlist = g_list_append(pMsgData->transitionlist, pTransition);
782 /* Processing Meta List */
783 memcpy(&pMsgData->metaCnt, pData + offset, sizeof(int));
784 MSG_DEBUG("[#%2d][%5d] meta count = %d", serial_index++, offset, pMsgData->metaCnt);
785 offset += sizeof(int);
787 for (int i = 0; i < pMsgData->metaCnt; ++i) {
788 pMeta = (MMS_SMIL_META *)calloc(sizeof(MMS_SMIL_META), 1);
792 memcpy(pMeta, pData + offset, sizeof(MMS_SMIL_META));
793 offset += sizeof(MMS_SMIL_META);
795 pMsgData->metalist = g_list_append(pMsgData->metalist, pMeta);
798 MSG_DEBUG("[#%2d][%5d] root layout", serial_index++, offset);
799 memcpy(&pMsgData->rootlayout, pData + offset, sizeof(MMS_SMIL_ROOTLAYOUT));
800 offset += sizeof(MMS_SMIL_ROOTLAYOUT);
802 #ifdef FEATURE_JAVA_MMS
803 MSG_DEBUG("[#%2d][%5d] java mms", serial_index++, offset);
804 memcpy(&pMsgData->msgAppId, pData + offset, sizeof(MMS_APPID_INFO_S));
805 offset += sizeof(MMS_APPID_INFO_S);
806 /* MSG_DEBUG("java_app_id valid:%d, appId:%s repleToAppId:%s", pBody->msgAppId.valid, pBody->msgAppId.appId, pBody->msgAppId.replyToAppId); */
809 memcpy(&pMsgData->header, pData + offset, sizeof(MMS_HEADER_DATA_S));
810 MSG_DEBUG("[#%2d][%5d] mms header", serial_index++, offset);
811 offset += sizeof(MMS_HEADER_DATA_S);
813 memcpy(&pMsgData->smil, pData + offset, sizeof(MMS_MULTIPART_DATA_S));
814 MSG_DEBUG("[#%2d][%5d] mms smil", serial_index++, offset);
815 offset += sizeof(MMS_MULTIPART_DATA_S);
817 MSG_DEBUG("Final offset : %d", offset);
822 void _MsgMmsAttachPrint(MMS_ATTACH_S *attach)
824 if (attach == NULL) {
825 MSG_DEBUG("Invalid Parameter");
829 MSG_DEBUG("%-25s : %d", "Attach Mimetype", attach->mediatype);
830 MSG_SEC_DEBUG("%-25s : %s", "Attach content type", attach->szContentType);
831 MSG_SEC_DEBUG("%-25s : %s", "Attach filename", attach->szFileName);
832 MSG_SEC_DEBUG("%-25s : %s", "Attach filepath", attach->szFilePath);
833 MSG_DEBUG("%-25s : %d", "Attach filesize", attach->fileSize);
834 MSG_DEBUG("%-25s : %d", "Attach drm type", attach->drmType);
835 MSG_SEC_DEBUG("%-25s : %s", "Attach drm filepath", attach->szDrm2FullPath);
838 void _MsgMmsMediaPrint(MMS_MEDIA_S *media)
841 MSG_DEBUG("Invalid Parameter");
845 if (media->mediatype == MMS_SMIL_MEDIA_INVALID) {
846 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_INVALID");
847 } else if (media->mediatype == MMS_SMIL_MEDIA_IMG) {
848 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_IMG");
849 } else if (media->mediatype == MMS_SMIL_MEDIA_AUDIO) {
850 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_AUDIO");
851 } else if (media->mediatype == MMS_SMIL_MEDIA_VIDEO) {
852 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_VIDEO");
853 } else if (media->mediatype == MMS_SMIL_MEDIA_TEXT) {
854 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_TEXT");
855 } else if (media->mediatype == MMS_SMIL_MEDIA_ANIMATE) {
856 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_ANIMATE");
857 } else if (media->mediatype == MMS_SMIL_MEDIA_IMG_OR_VIDEO) {
858 MSG_DEBUG("%-25s : %s", "Media type", "MMS_SMIL_MEDIA_REF");
860 MSG_DEBUG("%-25s : Unknown [%d]", "Media type", media->mediatype);
863 MSG_DEBUG("%-25s : %s", "Media src", media->szSrc);
864 MSG_SEC_DEBUG("%-25s : %s", "Media filename", media->szFileName);
865 MSG_SEC_DEBUG("%-25s : %s", "Media filepath", media->szFilePath);
866 MSG_SEC_DEBUG("%-25s : %s", "Media content type", media->szContentType);
867 MSG_SEC_DEBUG("%-25s : %s", "Media content id", media->szContentID);
868 MSG_SEC_DEBUG("%-25s : %s", "Media content location", media->szContentLocation);
869 MSG_SEC_DEBUG("%-25s : %s", "Media region id", media->regionId);
870 MSG_DEBUG("%-25s : %s", "Media alt", media->szAlt);
871 MSG_DEBUG("%-25s : %d", "Media drm type", media->drmType);
872 MSG_SEC_DEBUG("%-25s : %s", "Media drm filepath", media->szDrm2FullPath);
875 void _MsgMmsPagePrint(MMS_PAGE_S *page)
878 MSG_DEBUG("Invalid Parameter");
882 MSG_DEBUG("%-25s : %d", "Page duration", page->nDur);
884 if (page->medialist) {
885 int list_count = g_list_length(page->medialist);
886 MSG_DEBUG("Media Count is [%d]", list_count);
887 for (int i = 0; i < list_count; i++) {
888 MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
890 MSG_DEBUG("[%d]th Media", i);
891 _MsgMmsMediaPrint(media);
893 MSG_DEBUG("Not Exist Media Data in [%d]th", i);
899 void _MsgMmsPrint(MMS_MESSAGE_DATA_S *pMsgData)
901 if (pMsgData == NULL) {
902 MSG_DEBUG("Invalid Parameter");
906 if (pMsgData->pagelist) {
907 int list_count = g_list_length(pMsgData->pagelist);
908 MSG_DEBUG("Page Count is [%d]", list_count);
909 for (int i = 0; i < list_count; i++) {
910 MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, i);
912 MSG_DEBUG("[%d]th Page", i);
913 _MsgMmsPagePrint(page);
915 MSG_DEBUG("Not Exist Page Data in [%d]th", i);
920 if (pMsgData->attachlist) {
921 int list_count = g_list_length(pMsgData->attachlist);
922 MSG_DEBUG("Attach Count is [%d]", list_count);
923 for (int i = 0; i < list_count; i++) {
924 MMS_ATTACH_S *attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, i);
926 MSG_DEBUG("[%d]th Attach", i);
927 _MsgMmsAttachPrint(attach);
929 MSG_DEBUG("Not Exist Attach Data in [%d]th", i);
935 MMS_ADDRESS_DATA_S *MsgMmsCreateAddress(int addressType, const char *addressVal)
937 MMS_ADDRESS_DATA_S * pMmsAddressData = (MMS_ADDRESS_DATA_S * )calloc(1, sizeof(MMS_ADDRESS_DATA_S));
938 if (pMmsAddressData != NULL) {
939 pMmsAddressData->address_type = addressType;
940 pMmsAddressData->address_val = strdup(addressVal);
942 return pMmsAddressData;
945 void MsgMmsReleaseAddress(MMS_ADDRESS_DATA_S **ppMmsAddressData)
947 if (ppMmsAddressData && *ppMmsAddressData) {
948 MMS_ADDRESS_DATA_S *pMmsAddressData = *ppMmsAddressData;
950 if (pMmsAddressData->address_val) {
951 free(pMmsAddressData->address_val);
952 pMmsAddressData->address_val = NULL;
955 free(pMmsAddressData);
956 *ppMmsAddressData = NULL;
960 void MsgMmsInitMultipart(MMS_MULTIPART_DATA_S *pMmsMultipart)
963 pMmsMultipart->type = MIME_UNKNOWN;
964 pMmsMultipart->szContentType[0] = '\0';
965 pMmsMultipart->szFileName[0] = '\0';
966 pMmsMultipart->szContentID[0] = '\0';
967 pMmsMultipart->szContentLocation[0] = '\0';
968 pMmsMultipart->drmType = MSG_DRM_TYPE_NONE;
969 pMmsMultipart->szFilePath[0] = '\0';
970 pMmsMultipart->pMultipartData = NULL;
971 pMmsMultipart->nMultipartDataLen = 0;
972 pMmsMultipart->tcs_bc_level = -1;
973 pMmsMultipart->malware_allow = 0;
974 pMmsMultipart->szThumbFilePath[0] = '\0';
978 MMS_MULTIPART_DATA_S *MsgMmsCreateMultipart()
980 MMS_MULTIPART_DATA_S *pMmsMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
982 pMmsMultipart->type = MIME_UNKNOWN;
983 pMmsMultipart->szContentType[0] = '\0';
984 pMmsMultipart->szFileName[0] = '\0';
985 pMmsMultipart->szContentID[0] = '\0';
986 pMmsMultipart->szContentLocation[0] = '\0';
987 pMmsMultipart->drmType = MSG_DRM_TYPE_NONE;
988 pMmsMultipart->szFilePath[0] = '\0';
989 pMmsMultipart->pMultipartData = NULL;
990 pMmsMultipart->nMultipartDataLen = 0;
991 pMmsMultipart->tcs_bc_level = -1;
992 pMmsMultipart->malware_allow = 0;
993 pMmsMultipart->szThumbFilePath[0] = '\0';
996 return pMmsMultipart;
999 void MsgMmsReleaseMultipart(MMS_MULTIPART_DATA_S **ppMmsMultipart)
1001 if (ppMmsMultipart && *ppMmsMultipart) {
1002 MMS_MULTIPART_DATA_S *pDelMmsMultipart = *ppMmsMultipart;
1004 if (pDelMmsMultipart->pMultipartData != NULL) {
1005 g_free(pDelMmsMultipart->pMultipartData);
1006 pDelMmsMultipart->pMultipartData = NULL;
1008 g_free(pDelMmsMultipart);
1009 *ppMmsMultipart = NULL;
1013 void MsgMmsInitHeader(MMS_HEADER_DATA_S *pMmsHeaderData)
1015 if (pMmsHeaderData) {
1016 pMmsHeaderData->bcc = NULL;
1017 pMmsHeaderData->cc = NULL;
1018 pMmsHeaderData->contentLocation[0] = '\0';
1019 pMmsHeaderData->szContentType[0] = '\0';
1020 pMmsHeaderData->date = 0;
1021 pMmsHeaderData->bDeliveryReport = false;
1022 pMmsHeaderData->delivery.type = MMS_TIMETYPE_NONE;
1023 pMmsHeaderData->delivery.time = 0;
1024 pMmsHeaderData->expiry.type = MMS_TIMETYPE_NONE;
1025 pMmsHeaderData->expiry.time = 0;
1026 pMmsHeaderData->szFrom[0] = '\0';
1027 pMmsHeaderData->messageClass = -1;
1028 pMmsHeaderData->messageID[0]= '\0';
1029 pMmsHeaderData->messageType = -1;
1030 pMmsHeaderData->mmsVersion = -1;
1031 pMmsHeaderData->messageSize = 0;
1032 pMmsHeaderData->mmsPriority = -1;
1033 pMmsHeaderData->bReadReport = 0;
1034 pMmsHeaderData->bHideAddress = false;
1035 pMmsHeaderData->mmsStatus = MSG_DELIVERY_REPORT_NONE;
1036 pMmsHeaderData->szSubject[0] = '\0';
1037 pMmsHeaderData->to = NULL;
1038 pMmsHeaderData->trID[0] = '\0';
1039 pMmsHeaderData->contentClass = -1;
1043 MMS_HEADER_DATA_S *MsgMmsCreateHeader()
1045 MMS_HEADER_DATA_S *pMmsHeaderData = (MMS_HEADER_DATA_S *)calloc(1, sizeof(MMS_HEADER_DATA_S));
1046 if (pMmsHeaderData) {
1047 pMmsHeaderData->bcc = NULL; /* Bcc */
1048 pMmsHeaderData->cc = NULL; /* Cc */
1049 pMmsHeaderData->contentLocation[0] = '\0';
1050 pMmsHeaderData->szContentType[0] = '\0';
1051 pMmsHeaderData->date = 0;
1052 pMmsHeaderData->bDeliveryReport = false; /* X-Mms-Delivery-Report */
1053 pMmsHeaderData->delivery.type = MMS_TIMETYPE_NONE;
1054 pMmsHeaderData->delivery.time = 0;
1055 pMmsHeaderData->expiry.type = MMS_TIMETYPE_NONE;
1056 pMmsHeaderData->expiry.time = 0;
1057 pMmsHeaderData->szFrom[0] = '\0'; /* From */
1058 pMmsHeaderData->messageClass = -1; /* Personal | Advertisement | Informational | Auto */
1059 pMmsHeaderData->messageID[0]= '\0';
1060 pMmsHeaderData->messageType = -1; /* MmsMsgType : ex) sendreq */
1061 pMmsHeaderData->mmsVersion = -1; /* 1.0 1.3 */
1062 pMmsHeaderData->messageSize = 0; /* X-Mms-Message-Size */
1063 pMmsHeaderData->mmsPriority = -1; /* MSG_PRIORITY_TYPE_E : Low | Normal | High */
1064 pMmsHeaderData->bReadReport = 0; /* X-Mms-Read-Report */
1065 pMmsHeaderData->bHideAddress = false; /* X-Mms-Sender-Visibility */
1066 pMmsHeaderData->mmsStatus = MSG_DELIVERY_REPORT_NONE; /* X-Mms-Status */
1067 pMmsHeaderData->szSubject[0] = '\0'; /* Subject */
1068 pMmsHeaderData->to = NULL;
1069 pMmsHeaderData->trID[0] = '\0';
1070 pMmsHeaderData->contentClass = -1;/* text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich */
1072 X-Mms-Report-Allowed
1073 X-Mms-Response-Status
1075 X-Mms-Retrieve-Status
1078 X-Mms-Reply-Charging
1079 X-Mms-Reply-Charging-Deadline
1080 X-Mms-Reply-Charging-ID
1081 X-Mms-Reply-Charging-Size
1082 X-Mms-Previously-Sent-By
1083 X-Mms-Previously-Sent-Date
1088 X-Mms-Store-Status-Text
1099 X-Mms-Distribution-Indicator
1100 X-Mms-Element-Descriptor
1102 X-Mms-Recommended-Retrieval-Mode
1103 X-Mms-Recommended-Retrieval-Mode-Text
1106 X-Mms-Reply-Applic-ID
1107 X-Mms-Aux-Applic-Info
1109 X-Mms-Adaptation-Allowed
1116 return pMmsHeaderData;
1119 void MsgMmsReleaseHeader(MMS_HEADER_DATA_S **ppMmHeadersData)
1121 if (ppMmHeadersData && *ppMmHeadersData) {
1122 MMS_HEADER_DATA_S *pMmsHeaderData = *ppMmHeadersData;
1123 MsgMmsReleaseAddressList(&pMmsHeaderData->to);
1124 MsgMmsReleaseAddressList(&pMmsHeaderData->cc);
1125 MsgMmsReleaseAddressList(&pMmsHeaderData->bcc);
1126 free(pMmsHeaderData);
1128 *ppMmHeadersData = NULL;
1132 MMS_DATA_S *MsgMmsCreate()
1134 MMS_DATA_S * mms_data = (MMS_DATA_S * )calloc(1, sizeof(MMS_DATA_S));
1136 mms_data->header = NULL;
1137 mms_data->multipartlist = NULL;
1138 mms_data->smil = NULL;
1143 void MsgMmsRelease(MMS_DATA_S **ppMmsData)
1145 if (ppMmsData && *ppMmsData) {
1146 MMS_DATA_S *pMmsData = *ppMmsData;
1148 if (pMmsData->header)
1149 MsgMmsReleaseHeader(&pMmsData->header);
1152 MsgMmsReleaseMultipart(&pMmsData->smil);
1154 MsgMmsReleaseMultipartList(&pMmsData->multipartlist);
1162 static void __freeMultipartListItem(gpointer data)
1164 MMS_MULTIPART_DATA_S * pMultipart = (MMS_MULTIPART_DATA_S *)data;
1167 MsgMmsReleaseMultipart(&pMultipart);
1171 int MsgMmsReleaseMultipartList(MMSList **ppMultipartList)
1173 if (ppMultipartList && *ppMultipartList) {
1174 g_list_free_full(*ppMultipartList, __freeMultipartListItem);
1175 *ppMultipartList = NULL;
1181 static void __freeAddressListItem(gpointer data)
1183 MMS_ADDRESS_DATA_S * pAddressData = (MMS_ADDRESS_DATA_S *)data;
1185 MsgMmsReleaseAddress(&pAddressData);
1188 int MsgMmsReleaseAddressList(MMSList **ppAddressList)
1190 if (ppAddressList && *ppAddressList) {
1191 g_list_free_full(*ppAddressList, __freeAddressListItem);
1192 *ppAddressList = NULL;
1198 static void removeLessGreaterMark(const char *szSrcID, char *szDest, int destSize)
1200 char szBuf[MSG_MSG_ID_LEN + 1] = {0, };
1201 int cLen = strlen(szSrcID);
1203 if (cLen > 1 && szSrcID[0] == '<' && szSrcID[cLen - 1] == '>') {
1204 strncpy(szBuf, &szSrcID[1], cLen - 2);
1205 szBuf[cLen - 2] = '\0';
1206 } else if (cLen > 1 && szSrcID[0] == '"' && szSrcID[cLen-1] == '"') {
1207 strncpy(szBuf, &szSrcID[1], cLen - 2);
1208 szBuf[cLen - 2] = '\0';
1210 strncpy(szBuf, szSrcID, cLen);
1214 snprintf(szDest, destSize, "%s", szBuf);
1217 static bool IsMatchedMedia(MMS_MEDIA_S *media, MMS_MULTIPART_DATA_S *pMultipart)
1219 if (strlen(pMultipart->szContentID) > 0) {
1220 char szTempContentID[MSG_MSG_ID_LEN + 1] = {0, };
1221 removeLessGreaterMark(pMultipart->szContentID, szTempContentID, sizeof(szTempContentID));
1223 if (strcmp(media->szContentID, szTempContentID) == 0) {
1224 if (strlen(media->szContentLocation) > 0 && strlen(pMultipart->szContentLocation) > 0) {
1225 if (strcmp(media->szContentLocation, pMultipart->szContentLocation) == 0) {
1235 if (strcmp(media->szContentLocation, szTempContentID) == 0) {
1239 if (media->szContentID[0] != '\0') {
1240 char *pszExt = strrchr(media->szContentID, '.');
1242 char tmpContentID[MSG_MSG_ID_LEN+1] = {0};
1243 strncpy(tmpContentID, media->szContentID, strlen(media->szContentID));
1244 int extLength = strlen(pszExt);
1245 int contentIDLength = strlen(media->szContentID);
1246 tmpContentID[contentIDLength-extLength] = '\0';
1248 if (g_strcmp0(tmpContentID, szTempContentID) == 0)
1254 if (strlen(pMultipart->szContentLocation) > 0) {
1255 if (strcmp(media->szContentID, pMultipart->szContentLocation) == 0) {
1259 if (strcmp(media->szContentLocation, pMultipart->szContentLocation) == 0) {
1267 static bool MmsFindAndInsertPart(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
1269 bool insert_media = false;
1271 if (pMsgData->pagelist) {
1272 for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
1273 MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
1275 if (page && page->medialist) {
1276 for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
1277 MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
1279 if (media) { /* add media */
1280 if (IsMatchedMedia(media, pMultipart) == true) { /* matched media */
1281 insert_media = true;
1282 media->drmType = pMultipart->drmType;
1283 snprintf(media->szFilePath, sizeof(media->szFilePath), "%s", pMultipart->szFilePath);
1284 snprintf(media->szFileName, sizeof(media->szFileName), "%s", pMultipart->szFileName);
1285 snprintf(media->szContentID, sizeof(media->szContentID), "%s", pMultipart->szContentID);
1286 snprintf(media->szContentLocation, sizeof(media->szContentLocation), "%s", pMultipart->szContentLocation);
1287 snprintf(media->szContentType, sizeof(media->szContentType), "%s", pMultipart->szContentType);
1288 MSG_SEC_DEBUG("InsertPart to pageIndx [%d] mediaIdx[%d] media[%p] : path = [%s], name = [%s], cid = [%s], cl = [%s], ct = [%s]"\
1289 , pageIdx, mediaIdx, media, media->szFilePath, media->szFileName, media->szContentID, media->szContentLocation, media->szContentType);
1292 } /* end for media list */
1294 } /* end for page list */
1297 return insert_media;
1300 static bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
1304 bool isInsert = false;
1306 if (pMsgData == NULL || pMultipart == NULL) {
1310 isInsert = MmsFindAndInsertPart(pMsgData, pMultipart);
1312 if (isInsert == false) {
1313 MMS_ATTACH_S *attachment = NULL;
1314 attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
1316 attachment->drmType = pMultipart->drmType;
1317 attachment->mediatype = pMultipart->type;
1318 snprintf(attachment->szContentType, sizeof(attachment->szContentType), "%s", pMultipart->szContentType);
1319 snprintf(attachment->szFilePath, sizeof(attachment->szFilePath), "%s", pMultipart->szFilePath);
1320 snprintf(attachment->szFileName, sizeof(attachment->szFileName), "%s", pMultipart->szFileName);
1321 attachment->fileSize = MsgGetFileSize(attachment->szFilePath);
1322 MSG_SEC_DEBUG("Insert Attach to attachment[%p] : path = [%s], name = [%s], ct = [%s], size = [%d]"\
1323 , attachment, attachment->szFilePath, attachment->szFileName, attachment->szContentType, attachment->fileSize);
1326 if (_MsgMmsAddAttachment(pMsgData, attachment) != MSG_SUCCESS) {
1336 int MsgMmsConvertMmsDataToMmsMessageData(MMS_DATA_S *pSrc, MMS_MESSAGE_DATA_S *pDst)
1340 bzero(pDst, sizeof(MMS_MESSAGE_DATA_S));
1343 if (MsgAccessFile(pSrc->smil->szFilePath, F_OK)) {
1344 gchar *contents = NULL;
1347 if(g_file_get_contents((gchar*)pSrc->smil->szFilePath, (gchar**)&contents, (gsize*)&length, NULL) == FALSE)
1348 MSG_ERR("g_file_get_contents is failed");
1351 MsgSmilParseSmilDoc(pDst, contents);
1355 if (pSrc->smil->pMultipartData) {
1356 char *smil_data = (char *)calloc(1, sizeof(char)*(pSrc->smil->nMultipartDataLen + 1));
1358 memcpy(smil_data, pSrc->smil->pMultipartData, pSrc->smil->nMultipartDataLen);
1359 MsgSmilParseSmilDoc(pDst, smil_data);
1366 int len = g_list_length(pSrc->multipartlist);
1367 for (int i = 0; i < len; i++) {
1368 MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pSrc->multipartlist, i);
1370 MmsInsertPartToMmsData(pDst, multipart);
1378 int MsgMmsConvertMmsMessageDataToMmsData(MMS_MESSAGE_DATA_S *pSrc, MMS_DATA_S *pDst)
1382 char *pRawData = NULL;
1384 pDst->backup_type = pSrc->backup_type;
1386 int pageCnt = _MsgMmsGetPageCount(pSrc);
1387 if (pSrc->smil.szFilePath[0] != '\0') {
1388 MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
1390 memcpy(pMultipart, &pSrc->smil, sizeof(MMS_MULTIPART_DATA_S));
1391 pDst->smil = pMultipart;
1392 } else if (pageCnt > 0) { /* Multipart related */
1393 MsgSmilGenerateSmilDoc(pSrc, &pRawData);
1395 MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
1397 MSG_DEBUG("%s", pRawData);
1399 pMultipart->pMultipartData = pRawData;
1400 pMultipart->nMultipartDataLen = strlen(pRawData);
1401 pMultipart->type = MIME_APPLICATION_SMIL;
1402 snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", "application/smil");
1403 pDst->smil = pMultipart;
1406 MSG_DEBUG("Fail to Generate SmilDoc");
1410 for (int i = 0; i < pageCnt; ++i) {
1411 MMS_PAGE_S *pPage = _MsgMmsGetPage(pSrc, i);
1413 int mediaCnt = pPage->mediaCnt;
1414 MSG_DEBUG("PAGE %d's media Cnt: %d", i+1, mediaCnt);
1416 for (int j = 0; j < mediaCnt; ++j) {
1417 MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
1418 if ((pMedia) && (pMedia->szFilePath[0] != 0)) {
1419 MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
1421 snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szContentID);
1422 snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szContentLocation);
1423 snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
1424 snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
1425 snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
1426 pDst->multipartlist = g_list_append(pDst->multipartlist, pMultipart);
1433 /* Processing Attachment List */
1434 int attachCnt = _MsgMmsGetAttachCount(pSrc);
1436 for (int i = 0; i < attachCnt; ++i) {
1437 MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pSrc, i);
1438 if (pMedia->szFilePath[0] != 0) {
1439 MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
1441 snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szFileName);
1442 snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szFileName);
1443 snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
1444 snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
1445 snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
1447 pDst->multipartlist = g_list_append(pDst->multipartlist, pMultipart);
1457 int MsgMmsGetSmilMultipart(MMSList *pMultipartList, MMS_MULTIPART_DATA_S **smil_multipart)
1459 const char *smil_content_type = "application/smil";
1461 int len = g_list_length(pMultipartList);
1463 for (int i = 0; i < len; i++) {
1464 MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMultipartList, i);
1467 if (strcasecmp(multipart->szContentType, smil_content_type) == 0) {
1468 *smil_multipart = multipart;
1477 /* get content from filepath and save to pMultipartData */
1478 int MsgMmsSetMultipartData(MMS_MULTIPART_DATA_S *pMultipart)
1480 if (pMultipart->pMultipartData != NULL)
1483 if (g_file_get_contents((gchar*)pMultipart->szFilePath, (gchar**)&pMultipart->pMultipartData, (gsize*)&pMultipart->nMultipartDataLen, NULL) == false)
1486 /* Due to Get data for Backup message */
1487 /* memset(pMultipart->szFilePath, 0x00, sizeof(pMultipart->szFilePath)); */
1491 int MsgMmsSetMultipartListData(MMS_DATA_S *pMmsData)
1495 MMSList *multipart_list = pMmsData->multipartlist;
1497 if (multipart_list) {
1498 if (pMmsData->smil) {
1499 MsgMmsSetMultipartData(pMmsData->smil);
1502 for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
1503 MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
1506 MsgMmsSetMultipartData(pMultipart);/* app file -> data */
1515 /* pMultipartData set to file path */
1516 int MsgMmsSetMultipartFilePath(const char *dirPath, MMS_MULTIPART_DATA_S *pMultipart)
1518 if (g_file_test(dirPath, G_FILE_TEST_IS_DIR) != true) {
1519 MSG_SEC_DEBUG("g_file_test is false: [%s] is not dir or not exist", dirPath);
1523 memset(pMultipart->szFilePath, 0x00, sizeof(pMultipart->szFilePath));
1525 int wrn = snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s/%s", dirPath, pMultipart->szFileName);
1527 MSG_DEBUG("snprintf was failed");
1529 /* remove space character of original file name */
1530 msg_replace_space_char(pMultipart->szFilePath);
1532 if (!MsgCreateFile(pMultipart->szFilePath, pMultipart->pMultipartData, pMultipart->nMultipartDataLen)) {
1533 MSG_SEC_DEBUG("Fail to set content to file [%s]", pMultipart->szFilePath);
1540 int MsgMmsSetMultipartListFilePath(const char *dirPath, MMS_DATA_S *pMmsData)
1544 char working_dir[MSG_FILENAME_LEN_MAX+1] = {0, };
1546 snprintf(working_dir, sizeof(working_dir), "%s", dirPath);
1548 if (mkdir(working_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
1549 if (errno == EEXIST) {
1550 MSG_SEC_DEBUG("exist dir : [%s]", working_dir);
1552 MSG_SEC_DEBUG("Fail to Create Dir [%s]", working_dir);
1557 MMSList *multipart_list = pMmsData->multipartlist;
1559 if (pMmsData->smil) {
1560 snprintf(pMmsData->smil->szFileName, sizeof(pMmsData->smil->szFileName), "%s", "smil.smil");
1561 MsgMmsSetMultipartFilePath(working_dir, pMmsData->smil);
1564 if (multipart_list) {
1565 for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
1566 MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
1569 MsgMmsSetMultipartFilePath(working_dir, pMultipart); /* data -> svc file */
1578 int printMultipart(MMS_MULTIPART_DATA_S *multipart)
1581 MSG_DEBUG("multipart ptr [%p]", multipart);
1582 MSG_DEBUG("type : %d", multipart->type);
1583 MSG_DEBUG("type str : %s", multipart->szContentType);
1584 MSG_DEBUG("cid : %s", multipart->szContentID);
1585 MSG_DEBUG("cl : %s", multipart->szContentLocation);
1586 MSG_DEBUG("name : %s", multipart->szFileName);
1587 MSG_DEBUG("filepath : %s", multipart->szFilePath);
1588 MSG_DEBUG("tcs_bc_level : %d", multipart->tcs_bc_level);
1589 MSG_DEBUG("malware_allow : %d", multipart->malware_allow);
1590 MSG_DEBUG("thumbfilepath : %s", multipart->szThumbFilePath);
1595 int printMultipartList(MMSList *pMultipartList)
1597 int len = g_list_length(pMultipartList);
1599 for (int i = 0; i < len; i++) {
1600 MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMultipartList, i);
1603 MSG_DEBUG("[%d] multipart ptr [%p]", i, multipart);
1604 MSG_DEBUG("type : %d", multipart->type);
1605 MSG_DEBUG("type str : %s", multipart->szContentType);
1606 MSG_DEBUG("cid : %s", multipart->szContentID);
1607 MSG_DEBUG("cl : %s", multipart->szContentLocation);
1608 MSG_DEBUG("name : %s", multipart->szFileName);
1609 MSG_DEBUG("filepath : %s", multipart->szFilePath);
1610 MSG_DEBUG("tcs_bc_level : %d", multipart->tcs_bc_level);
1611 MSG_DEBUG("malware_allow : %d", multipart->malware_allow);
1612 MSG_DEBUG("thumbfilepath : %s", multipart->szThumbFilePath);
1619 void _MsgMmsMultipartPrint(MMS_MULTIPART_DATA_S *multipart)
1621 if (multipart == NULL) {
1622 MSG_DEBUG("Invalid Parameter");
1626 MSG_DEBUG("%-25s : %d", "Multipart type", multipart->type);
1627 MSG_SEC_DEBUG("%-25s : %s", "Multipart filename", multipart->szFileName);
1628 MSG_SEC_DEBUG("%-25s : %s", "Multipart filepath", multipart->szFilePath);
1629 MSG_SEC_DEBUG("%-25s : %s", "Multipart content type", multipart->szContentType);
1630 MSG_SEC_DEBUG("%-25s : %s", "Multipart content id", multipart->szContentID);
1631 MSG_SEC_DEBUG("%-25s : %s", "Multipart content location", multipart->szContentLocation);
1632 MSG_DEBUG("%-25s : %d", "Multipart drm type", multipart->drmType);
1635 bool _MsgMmsRemoveEmptyMedia(MMS_PAGE_S *pPage)
1637 MMS_MEDIA_S *pMedia = NULL;
1639 int mediaCnt = g_list_length(pPage->medialist);
1641 for (int i = 0; i < mediaCnt; i++) {
1642 GList *nth = g_list_nth(pPage->medialist, i);
1647 pMedia = (MMS_MEDIA_S *)nth->data;
1652 if (strlen(pMedia->szFilePath) == 0) {
1653 MSG_DEBUG("Found Empty Media [%d]", i);
1661 pPage->medialist = g_list_remove_all(pPage->medialist, NULL);
1663 pPage->mediaCnt = g_list_length(pPage->medialist);
1668 /* remove media object with no filepath */
1669 bool _MsgMmsRemoveEmptyObject(MMS_MESSAGE_DATA_S *pMmsMsg)
1673 int pageCnt = g_list_length(pMmsMsg->pagelist);
1675 for (int i = 0; i < pageCnt; i++) {
1676 GList *nth = g_list_nth(pMmsMsg->pagelist, i);
1681 pPage = (MMS_PAGE_S *)nth->data;
1686 _MsgMmsRemoveEmptyMedia(pPage);
1689 if (g_list_length(pPage->medialist) == 0) {
1690 MSG_DEBUG("Found Empty Page [%d]", i);
1699 pMmsMsg->pagelist = g_list_remove_all(pMmsMsg->pagelist, NULL);
1701 pMmsMsg->pageCnt = g_list_length(pMmsMsg->pagelist);
1706 int MsgMmsCheckFilepathSmack(int fd, const char* ipc_filename)
1708 int err = MSG_SUCCESS;
1710 char *app_smack_label = NULL;
1711 smack_new_label_from_socket(fd, &app_smack_label);
1712 if (app_smack_label == NULL) {
1713 return MSG_ERR_PERMISSION_DENIED;
1716 MSG_SEC_DEBUG("app_smack_label [%s]", app_smack_label);
1718 char ipc_filepath[MSG_FILEPATH_LEN_MAX+1] = {0, };
1719 snprintf(ipc_filepath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_IPC_DATA_PATH, ipc_filename);
1721 gchar *serialized_data = NULL;
1722 gsize serialized_len = 0;
1723 MSG_SEC_DEBUG("ipc_path [%s]", ipc_filepath);
1725 if (!g_file_get_contents((gchar*)ipc_filepath, (gchar**)&serialized_data, (gsize*)&serialized_len, NULL)) {
1726 MSG_FREE(app_smack_label);
1727 return MSG_ERR_PERMISSION_DENIED;
1730 MMS_DATA_S *mms_data = NULL;
1732 MsgDeserializeMmsData(serialized_data, serialized_len, &mms_data);
1735 if (mms_data->multipartlist) {
1736 int len = g_list_length(mms_data->multipartlist);
1737 for (int i = 0; i < len; i++) {
1738 MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(mms_data->multipartlist, i);
1740 err = MsgCheckFilepathSmack(app_smack_label, multipart->szFilePath);
1741 if (err != MSG_SUCCESS)
1746 if (err == MSG_SUCCESS && mms_data->smil) {
1747 err = MsgCheckFilepathSmack(app_smack_label, mms_data->smil->szFilePath);
1749 MsgMmsRelease(&mms_data);
1751 err = MSG_ERR_INVALID_PARAMETER;
1754 MSG_FREE(serialized_data);
1755 MSG_FREE(app_smack_label);