Merge from master.
[framework/messaging/msg-service.git] / utils / MsgMmsMessage.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.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://floralicense.org
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <glib.h>
20
21 #include "MsgTypes.h"
22 #include "MsgMmsTypes.h"
23 #include "MsgMmsMessage.h"
24 #include "MsgDebug.h"
25
26 static void __release_glist_element(gpointer data, gpointer user_data);
27 static void __release_page_element(gpointer data, gpointer user_data);
28 static msg_error_t __releasePageList(MMS_MESSAGE_DATA_S *pMsgData);
29 static msg_error_t __releaseRegionList(MMS_MESSAGE_DATA_S *pMsgData);
30 static msg_error_t __releaseAttachList(MMS_MESSAGE_DATA_S *pMsgData);
31 static msg_error_t __releaseTransitionList(MMS_MESSAGE_DATA_S *pMsgData);
32 static msg_error_t __releaseMetaList(MMS_MESSAGE_DATA_S *pMsgData);
33
34 void __release_glist_element(gpointer data, gpointer user_data)
35 {
36         if(data != NULL) {
37                 free(data);
38         }
39 }
40
41 void __release_page_element(gpointer data, gpointer user_data)
42 {
43         if(data != NULL) {
44                 MMS_PAGE_S *page = (MMS_PAGE_S *)data;
45
46                 if (page->medialist) {
47                         MMS_MEDIA_S *media = NULL;
48                         int mediaCnt = g_list_length(page->medialist);
49
50                         for (int i = 0; i < mediaCnt; i++) {
51                                 media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
52                                 if (media)
53                                         free(media);
54                         }
55
56                         g_list_free(page->medialist);
57                         page->medialist = NULL;
58                         page->mediaCnt = 0;
59                 }
60
61                 free(page);
62         }
63 }
64
65 msg_error_t __releasePageList(MMS_MESSAGE_DATA_S *pMsgData)
66 {
67         if (pMsgData == NULL) {
68                 MSG_DEBUG("pMsgData is NULL");
69                 return MSG_ERR_INVALID_PARAMETER;
70         }
71
72         if (pMsgData->pagelist) {
73                 g_list_foreach(pMsgData->pagelist, __release_page_element, NULL);
74                 g_list_free(pMsgData->pagelist);
75                 pMsgData->pagelist = NULL;
76         }
77
78         pMsgData->pageCnt = 0;
79
80         return MSG_SUCCESS;
81 }
82
83 msg_error_t __releaseRegionList(MMS_MESSAGE_DATA_S *pMsgData)
84 {
85         if (pMsgData == NULL) {
86                 MSG_DEBUG("pMsgData is NULL");
87                 return MSG_ERR_INVALID_PARAMETER;
88         }
89
90         if (pMsgData->regionlist) {
91                 g_list_foreach(pMsgData->regionlist, __release_glist_element, NULL);
92                 g_list_free(pMsgData->regionlist);
93                 pMsgData->regionlist = NULL;
94         }
95
96         pMsgData->regionCnt = 0;
97
98         return MSG_SUCCESS;
99 }
100
101 msg_error_t __releaseAttachList(MMS_MESSAGE_DATA_S *pMsgData)
102 {
103         if (pMsgData == NULL) {
104                 MSG_DEBUG("pMsgData is NULL");
105                 return MSG_ERR_INVALID_PARAMETER;
106         }
107
108         if (pMsgData->attachlist) {
109                 g_list_foreach(pMsgData->attachlist, __release_glist_element, NULL);
110                 g_list_free(pMsgData->attachlist);
111                 pMsgData->attachlist = NULL;
112         }
113
114         pMsgData->attachCnt = 0;
115
116         return MSG_SUCCESS;
117 }
118
119 msg_error_t __releaseTransitionList(MMS_MESSAGE_DATA_S *pMsgData)
120 {
121         if (pMsgData == NULL) {
122                 MSG_DEBUG("pMsgData is NULL");
123                 return MSG_ERR_INVALID_PARAMETER;
124         }
125
126         if (pMsgData->transitionlist) {
127                 g_list_foreach(pMsgData->transitionlist, __release_glist_element, NULL);
128                 g_list_free(pMsgData->transitionlist);
129                 pMsgData->transitionlist = NULL;
130         }
131
132         pMsgData->transitionCnt = 0;
133
134         return MSG_SUCCESS;
135 }
136
137 msg_error_t __releaseMetaList(MMS_MESSAGE_DATA_S *pMsgData)
138 {
139         if (pMsgData == NULL) {
140                 MSG_DEBUG("pMsgData is NULL");
141                 return MSG_ERR_INVALID_PARAMETER;
142         }
143
144         if (pMsgData->metalist) {
145                 g_list_foreach(pMsgData->metalist, __release_glist_element, NULL);
146                 g_list_free(pMsgData->metalist);
147                 pMsgData->metalist = NULL;
148         }
149
150         pMsgData->metaCnt = 0;
151
152         return MSG_SUCCESS;
153 }
154
155 void MsgMmsReleaseMmsLists(MMS_MESSAGE_DATA_S *pMsgData)
156 {
157         __releasePageList(pMsgData);
158         __releaseRegionList(pMsgData);
159         __releaseAttachList(pMsgData);
160         __releaseTransitionList(pMsgData);
161         __releaseMetaList(pMsgData);
162 }
163
164 msg_error_t _MsgMmsAddRegion(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_REGION* pRegion)
165 {
166         if(pMsgData == NULL || pRegion == NULL)
167                 return MSG_ERR_INVALID_PARAMETER;
168
169         pMsgData->regionlist = g_list_append(pMsgData->regionlist, pRegion);
170         pMsgData->regionCnt++;
171
172         return MSG_SUCCESS;
173 }
174
175 msg_error_t _MsgMmsAddPage(MMS_MESSAGE_DATA_S *pMsgData, MMS_PAGE_S *pPage)
176 {
177         if(pMsgData == NULL || pPage == NULL)
178                 return MSG_ERR_INVALID_PARAMETER;
179
180         pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
181         pMsgData->pageCnt++;
182         MSG_DEBUG("MmsData's Page Count : %d", pMsgData->pageCnt);
183         return MSG_SUCCESS;
184 }
185
186 msg_error_t _MsgMmsAddMedia(MMS_PAGE_S* pPage, MMS_MEDIA_S *pMedia)
187 {
188         if(pPage == NULL || pMedia == NULL)
189                 return MSG_ERR_INVALID_PARAMETER;
190
191         pPage->medialist = g_list_append(pPage->medialist, pMedia);
192         pPage->mediaCnt++;
193         MSG_DEBUG("Page's media count: %d", pPage->mediaCnt);
194         return MSG_SUCCESS;
195 }
196
197 msg_error_t _MsgMmsAddTransition(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_TRANSITION* pTransition)
198 {
199         if(pMsgData == NULL || pTransition == NULL)
200                 return MSG_ERR_INVALID_PARAMETER;
201
202         pMsgData->transitionlist = g_list_append(pMsgData->transitionlist, pTransition);
203         pMsgData->transitionCnt++;
204
205         return MSG_SUCCESS;
206 }
207
208 msg_error_t _MsgMmsAddMeta(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_META* pMeta)
209 {
210         if(pMsgData == NULL || pMeta == NULL)
211                 return MSG_ERR_INVALID_PARAMETER;
212
213         pMsgData->metalist = g_list_append(pMsgData->metalist, pMeta);
214         pMsgData->metaCnt++;
215
216         return MSG_SUCCESS;
217 }
218
219 msg_error_t _MsgMmsAddAttachment(MMS_MESSAGE_DATA_S *pMsgData, MMS_ATTACH_S *pAttach)
220 {
221         if(pMsgData == NULL || pAttach == NULL)
222                 return MSG_ERR_INVALID_PARAMETER;
223
224         pMsgData->attachlist = g_list_append(pMsgData->attachlist, pAttach);
225         pMsgData->attachCnt++;
226
227         return MSG_SUCCESS;
228 }
229
230 int _MsgMmsGetPageCount(MMS_MESSAGE_DATA_S *pMsgData)
231 {
232         if (pMsgData == NULL) {
233                 MSG_DEBUG("pMsgData is NULL");
234                 return 0;
235         }
236
237         int count = 0;
238
239         if (pMsgData->pagelist)
240                 count = g_list_length(pMsgData->pagelist);
241
242         MSG_DEBUG("Page Count: %d", count);
243         return count;
244 }
245
246 MMS_PAGE_S *_MsgMmsGetPage(MMS_MESSAGE_DATA_S *pMsgData, int pageIdx)
247 {
248         if (pMsgData == NULL) {
249                 MSG_DEBUG("pMsgData is NULL");
250                 return NULL;
251         }
252
253         MMS_PAGE_S *page = NULL;
254
255         if (pMsgData->pagelist)
256                 page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
257
258         return page;
259 }
260
261 int _MsgMmsGetAttachCount(MMS_MESSAGE_DATA_S *pMsgData)
262 {
263         if (pMsgData == NULL) {
264                 MSG_DEBUG("pMsgData is NULL");
265                 return 0;
266         }
267
268         int count = 0;
269
270         if (pMsgData->attachlist)
271                 count = g_list_length(pMsgData->attachlist);
272
273         MSG_DEBUG("Attachment Count: %d", count);
274         return count;
275 }
276
277 MMS_ATTACH_S *_MsgMmsGetAttachment(MMS_MESSAGE_DATA_S *pMsgData, int attachIdx)
278 {
279         if (pMsgData == NULL) {
280                 MSG_DEBUG("pMsgData is NULL");
281                 return NULL;
282         }
283
284         MMS_ATTACH_S *attach = NULL;
285         if (pMsgData->attachlist)
286                 attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, attachIdx);
287
288         return attach;
289 }
290
291 MMS_SMIL_REGION *_MsgMmsGetSmilRegion(MMS_MESSAGE_DATA_S *pMsgData, int regionIdx)
292 {
293         if (pMsgData == NULL) {
294                 MSG_DEBUG("pMsgData is NULL");
295                 return NULL;
296         }
297
298         MMS_SMIL_REGION *region = NULL;
299
300         if (pMsgData->regionlist)
301                 region = (MMS_SMIL_REGION *)g_list_nth_data(pMsgData->regionlist, regionIdx);
302
303         return region;
304 }
305
306 MMS_MEDIA_S *_MsgMmsGetMedia(MMS_PAGE_S *pPage, int mediaIdx)
307 {
308         if (!pPage) {
309                 MSG_FATAL("pPage is NULL");
310                 return NULL;
311         }
312
313         if (mediaIdx > pPage->mediaCnt || mediaIdx < 0) {
314                 MSG_FATAL("Invalid media index = %d", mediaIdx);
315                 return NULL;
316         }
317
318         MMS_MEDIA_S *media = NULL;
319         if (pPage->medialist)
320                 media = (MMS_MEDIA_S *)g_list_nth_data(pPage->medialist, mediaIdx);
321
322         return media;
323
324 }
325
326 int _MsgMmsGetTransitionCount(MMS_MESSAGE_DATA_S *pMsgData)
327 {
328         if (pMsgData == NULL) {
329                 MSG_DEBUG("pMsgData is NULL");
330                 return 0;
331         }
332
333         int count = 0;
334
335         if (pMsgData->transitionlist)
336                 count = g_list_length(pMsgData->transitionlist);
337
338         MSG_DEBUG("Transition Count: %d", count);
339         return count;
340 }
341
342 MMS_SMIL_TRANSITION *_MsgMmsGetTransition(MMS_MESSAGE_DATA_S *pMsgData, int transitionIdx)
343 {
344         if (pMsgData == NULL) {
345                 MSG_DEBUG("pMsgData is NULL");
346                 return NULL;
347         }
348
349         MMS_SMIL_TRANSITION *transition = NULL;
350         if (pMsgData->transitionlist)
351                 transition = (MMS_SMIL_TRANSITION *)g_list_nth_data(pMsgData->transitionlist, transitionIdx);
352
353         return transition;
354 }
355
356 MMS_SMIL_META *_MsgMmsGetMeta(MMS_MESSAGE_DATA_S *pMsgData, int metaIdx)
357 {
358         if (pMsgData == NULL) {
359                 MSG_DEBUG("pMsgData is NULL");
360                 return NULL;
361         }
362
363         MMS_SMIL_META *meta = NULL;
364
365         if (pMsgData->metalist)
366                 meta = (MMS_SMIL_META *)g_list_nth_data(pMsgData->metalist, metaIdx);
367
368         return meta;
369 }
370
371 int     _MsgMmsGetMetaCount(MMS_MESSAGE_DATA_S *pMsgData)
372 {
373         if (pMsgData == NULL) {
374                 MSG_DEBUG("pMsgData is NULL");
375                 return 0;
376         }
377
378         int count = 0;
379
380         if (pMsgData->metalist)
381                 count = g_list_length(pMsgData->metalist);
382
383         MSG_DEBUG("Meta Count: %d", count);
384         return count;
385 }
386
387 bool _MsgMmsSetRootLayout(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_ROOTLAYOUT *pRootlayout)
388 {
389         memcpy(&pMsgData->rootlayout, pRootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
390         return true;
391 }
392
393 char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, size_t *pSize)
394 {
395         MSG_BEGIN();
396
397         if (pMsgData == NULL)
398                 return NULL;
399
400         int bufsize = 0;
401         int offset = 0;
402         int pageCnt = 0;
403         char *buf = NULL;
404
405         bufsize += sizeof(int); // Page cnt
406
407         pageCnt = pMsgData->pageCnt;
408
409         if (pMsgData->pagelist) {
410
411                 for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) {
412
413                         int mediaCnt = 0;
414
415                         MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
416
417                         mediaCnt = page->mediaCnt;
418
419                         bufsize += sizeof(int); // Media cnt
420
421                         if (page->medialist) {
422                                 bufsize += sizeof(MMS_MEDIA_S) * mediaCnt;
423                         }
424
425                         bufsize += sizeof(int) * 6;//Dur, Begin, End, Min, Max, Repeat
426                 }
427         }
428
429         bufsize += sizeof(int); // region count;
430
431         if (pMsgData->regionlist) {
432                 int elementSize = g_list_length(pMsgData->regionlist);
433                 bufsize += elementSize * (sizeof(MMS_SMIL_REGION));
434         }
435
436         bufsize += sizeof(int); // attachment count;
437         if (pMsgData->attachlist) {
438                 int elementSize = g_list_length(pMsgData->attachlist);
439                 bufsize += elementSize * sizeof(MMS_ATTACH_S);
440         }
441
442         bufsize += sizeof(int); // transition count;
443         if (pMsgData->transitionlist) {
444                 int elementSize = g_list_length(pMsgData->transitionlist);
445                 bufsize += elementSize * sizeof(MMS_SMIL_TRANSITION);
446         }
447
448         bufsize += sizeof(int); // meta count;
449         if (pMsgData->metalist) {
450                 int elementSize = g_list_length(pMsgData->metalist);
451                 bufsize += elementSize * sizeof(MMS_SMIL_META);
452         }
453
454         bufsize += sizeof(MMS_SMIL_ROOTLAYOUT);
455
456 #ifdef FEATURE_JAVA_MMS
457         bufsize += sizeof(MMS_APPID_INFO_S);
458 #endif
459
460         int filePathLen = strlen(pMsgData->szSmilFilePath);
461
462         bufsize += sizeof(int) + filePathLen;
463
464         bufsize += sizeof(int); // type
465         bufsize += sizeof(MMS_HEADER_DATA_S);
466         bufsize += sizeof(MMS_MULTIPART_DATA_S);
467
468         MSG_DEBUG("Serialize bufsize = %d", bufsize);
469
470         buf = (char *)calloc(bufsize, 1);
471
472         int serial_index = 0;
473
474         memcpy(buf, &pMsgData->backup_type, sizeof(int));
475         MSG_DEBUG("[#%2d][%5d] backup type = %d",serial_index++, offset, pMsgData->backup_type);
476         offset += sizeof(int);
477
478         //smilFilePath
479         memcpy(buf + offset , &filePathLen, sizeof(int));
480
481         // copy file path
482         MSG_DEBUG("[#%2d][%5d] smilFilePath = %s, len = %d",serial_index++, offset, pMsgData->szSmilFilePath, filePathLen);
483         offset += sizeof(int);
484
485         if (filePathLen > 0) {
486                 memcpy(buf + offset, pMsgData->szSmilFilePath, filePathLen);
487                 offset += filePathLen;
488         }
489
490         // copy page count
491         MSG_DEBUG("[#%2d][%5d] page count = %d",serial_index++, offset, pMsgData->pageCnt);
492         memcpy(buf + offset, &(pMsgData->pageCnt), sizeof(int));
493         offset += sizeof(int);
494
495         if (pMsgData->pagelist) {
496
497                 for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++) {
498                         MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
499
500                         MSG_DEBUG("[#%2d][%5d][%d page] media count = %d",serial_index++, offset, pageIdx, page->mediaCnt);
501                         memcpy(buf + offset, &page->mediaCnt, sizeof(int));
502                         offset += sizeof(int);
503
504                         if (page->medialist) {
505                                 for (int i = 0; i < page->mediaCnt; ++ i) {
506                                         MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
507                                         memcpy(buf + offset, media, sizeof(MMS_MEDIA_S));
508                                         offset += sizeof(MMS_MEDIA_S);
509                                 }
510                         }
511
512                         memcpy(buf + offset, &page->nDur, sizeof(int));
513                         offset += sizeof(int);
514                         memcpy(buf + offset, &page->nBegin, sizeof(int));
515                         offset += sizeof(int);
516                         memcpy(buf + offset, &page->nEnd, sizeof(int));
517                         offset += sizeof(int);
518                         memcpy(buf + offset, &page->nMin, sizeof(int));
519                         offset += sizeof(int);
520                         memcpy(buf + offset, &page->nMax, sizeof(int));
521                         offset += sizeof(int);
522                         memcpy(buf + offset, &page->nRepeat, sizeof(int));
523                         offset += sizeof(int);
524                 }
525         }
526
527         MSG_DEBUG("[#%2d][%5d] region count = %d",serial_index++, offset, pMsgData->regionCnt);
528
529         memcpy(buf + offset, &pMsgData->regionCnt, sizeof(int));
530         offset += sizeof(int);
531
532         if (pMsgData->regionlist) {
533                 for (int i = 0; i < pMsgData->regionCnt; ++ i) {
534                         MMS_SMIL_REGION *region = (MMS_SMIL_REGION *)g_list_nth_data(pMsgData->regionlist, i);
535                         memcpy(buf + offset, region, sizeof(MMS_SMIL_REGION));
536                         offset += sizeof(MMS_SMIL_REGION);
537                 }
538         }
539
540         MSG_DEBUG("[#%2d][%5d] attach count = %d",serial_index++, offset, pMsgData->attachCnt);
541
542         memcpy(buf + offset, &pMsgData->attachCnt, sizeof(int));
543         offset += sizeof(int);
544
545         if (pMsgData->attachlist) {
546                 for (int i = 0; i < pMsgData->attachCnt; ++ i) {
547                         MMS_ATTACH_S *attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, i);
548                         memcpy(buf + offset, attach, sizeof(MMS_ATTACH_S));
549                         offset += sizeof(MMS_ATTACH_S);
550                 }
551         }
552
553         MSG_DEBUG("[#%2d][%5d] transition count = %d",serial_index++, offset, pMsgData->transitionCnt);
554
555         memcpy(buf + offset, &pMsgData->transitionCnt, sizeof(int));
556         offset += sizeof(int);
557         if (pMsgData->transitionlist) {
558                 for (int i = 0; i < pMsgData->transitionCnt; ++ i) {
559                         MMS_SMIL_TRANSITION *transition = (MMS_SMIL_TRANSITION *)g_list_nth_data(pMsgData->transitionlist, i);
560                         memcpy(buf + offset, transition, sizeof(MMS_SMIL_TRANSITION));
561                         offset += sizeof(MMS_SMIL_TRANSITION);
562                 }
563         }
564
565         MSG_DEBUG("[#%2d][%5d] meta count = %d",serial_index++, offset, pMsgData->metaCnt);
566         memcpy(buf + offset, &pMsgData->metaCnt, sizeof(int));
567         offset += sizeof(int);
568
569         if (pMsgData->metalist) {
570                 for (int i = 0; i < pMsgData->metaCnt; ++ i) {
571                         MMS_SMIL_META *meta = (MMS_SMIL_META *)g_list_nth_data(pMsgData->metalist, i);
572
573                         memcpy(buf + offset, meta, sizeof(MMS_SMIL_META));
574                         offset += sizeof(MMS_SMIL_META);
575                 }
576         }
577
578         MSG_DEBUG("[#%2d][%5d] root layout",serial_index++, offset);
579         memcpy(buf + offset, &pMsgData->rootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
580         offset += sizeof(MMS_SMIL_ROOTLAYOUT);
581
582 #ifdef FEATURE_JAVA_MMS
583         MSG_DEBUG("[#%2d][%5d] java mms",serial_index++, offset);
584         memcpy(buf + offset, &pMsgData->msgAppId, sizeof(MMS_APPID_INFO_S));
585         offset += sizeof(MMS_APPID_INFO_S);
586 #endif
587
588         memcpy (buf + offset, &pMsgData->header, sizeof(MMS_HEADER_DATA_S));
589         MSG_DEBUG("[#%2d][%5d] mms header",serial_index++, offset);
590         offset += sizeof(MMS_HEADER_DATA_S);
591
592         memcpy (buf + offset, &pMsgData->smil, sizeof(MMS_MULTIPART_DATA_S));
593         MSG_DEBUG("[#%2d][%5d] mms smil",serial_index++, offset);
594         offset += sizeof(MMS_MULTIPART_DATA_S);
595
596         *pSize = offset;
597
598         MSG_DEBUG("Expect Buffer Size: %d, Final offset : %d", bufsize, offset);
599         MSG_END();
600         return buf;
601 }
602
603 bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pData)
604 {
605         MSG_BEGIN();
606
607         if (pMsgData == NULL || pData == NULL) {
608                 MSG_DEBUG("param is NULL. pBody = %x, pData = %x", pMsgData, pData);
609                 return false;
610         }
611
612         int offset = 0;
613         int pageCnt = 0;
614         int filePathLen = 0;
615
616         MMS_PAGE_S *pPage = NULL;
617         MMS_MEDIA_S *pMedia = NULL;
618         MMS_SMIL_REGION *pRegion = NULL;
619         MMS_ATTACH_S *pAttach = NULL;
620         MMS_SMIL_TRANSITION *pTransition = NULL;
621         MMS_SMIL_META *pMeta = NULL;
622
623         int serial_index = 0;
624
625         int type;
626
627         memcpy(&type, pData, sizeof(int));
628         MSG_DEBUG("[#%2d][%5d] backup type = %d",serial_index++, offset, type);
629         offset += sizeof(int);
630
631         pMsgData->backup_type = type;
632
633         memcpy(&filePathLen, pData + offset, sizeof(int));
634         MSG_DEBUG("[#%2d][%5d] smil path len = %d",serial_index, offset, filePathLen);
635         offset += sizeof(int);
636
637         if (filePathLen > MSG_FILEPATH_LEN_MAX) {
638                 MSG_DEBUG("Smil File Path Length is abnormal.");
639                 return false;
640         }
641
642         memset(pMsgData->szSmilFilePath, 0x00, MSG_FILEPATH_LEN_MAX);
643
644         if (filePathLen > 0) {
645                 memcpy(pMsgData->szSmilFilePath, pData + offset, filePathLen);
646                 MSG_DEBUG("[#%2d][%5d] smil path = %s",serial_index, offset, pMsgData->szSmilFilePath);
647                 offset += filePathLen;
648         }
649
650         serial_index++;
651
652         memcpy(&(pMsgData->pageCnt), pData + offset, sizeof(int));
653         MSG_DEBUG("[#%2d][%5d] page count = %d",serial_index++, offset, pMsgData->pageCnt);
654         offset += sizeof(int);
655
656         pageCnt = pMsgData->pageCnt;
657
658         for (int j = 0; j < pageCnt; ++j) {
659                 pPage = (MMS_PAGE_S *)calloc(sizeof(MMS_PAGE_S), 1);
660
661                 memcpy(&pPage->mediaCnt, pData + offset, sizeof(int));
662                 MSG_DEBUG("[#%2d][%5d][%d page] media count = %d", serial_index++, offset, j, pPage->mediaCnt);
663                 offset += sizeof(int);
664
665                 for (int i = 0; i < pPage->mediaCnt; ++i) {
666                         pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
667
668                         memcpy(pMedia, pData + offset, sizeof(MMS_MEDIA_S));
669
670                         offset += sizeof(MMS_MEDIA_S);
671
672                         pPage->medialist = g_list_append(pPage->medialist, pMedia);
673                 }
674
675                 memcpy(&pPage->nDur , pData + offset, sizeof(int));
676                 offset += sizeof(int);
677                 memcpy(&pPage->nBegin , pData + offset, sizeof(int));
678                 offset += sizeof(int);
679                 memcpy(&pPage->nEnd , pData + offset, sizeof(int));
680                 offset += sizeof(int);
681                 memcpy(&pPage->nMin , pData + offset, sizeof(int));
682                 offset += sizeof(int);
683                 memcpy(&pPage->nMax , pData + offset, sizeof(int));
684                 offset += sizeof(int);
685                 memcpy(&pPage->nRepeat , pData + offset, sizeof(int));
686                 offset += sizeof(int);
687
688                 pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
689         }
690
691         //Processing Region List
692         memcpy(&pMsgData->regionCnt, pData + offset, sizeof(int));
693         MSG_DEBUG("[#%2d][%5d] region count = %d",serial_index++, offset, pMsgData->regionCnt);
694         offset += sizeof(int);
695
696         //MSG_DEBUG(" pBody->regionCnt: %d", pBody->regionCnt);
697
698         for (int i = 0; i < pMsgData->regionCnt; ++i) {
699                 pRegion = (MMS_SMIL_REGION *)calloc(sizeof(MMS_SMIL_REGION), 1);
700
701                 memcpy(pRegion, pData + offset, sizeof(MMS_SMIL_REGION));
702                 offset += sizeof(MMS_SMIL_REGION);
703
704                 pMsgData->regionlist = g_list_append(pMsgData->regionlist, pRegion);
705         }
706
707         //Processing Attachment List
708         memcpy(&pMsgData->attachCnt, pData + offset, sizeof(int));
709         MSG_DEBUG("[#%2d][%5d] attach count = %d",serial_index++, offset, pMsgData->attachCnt);
710         offset += sizeof(int);
711
712         for (int i = 0; i < pMsgData->attachCnt; ++i) {
713                 pAttach = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
714
715                 memcpy(pAttach, pData + offset, sizeof(MMS_ATTACH_S));
716                 offset += sizeof(MMS_ATTACH_S);
717
718                 pMsgData->attachlist = g_list_append(pMsgData->attachlist, pAttach);
719         }
720
721         //Processing Transition List
722         memcpy(&pMsgData->transitionCnt, pData + offset, sizeof(int));
723         MSG_DEBUG("[#%2d][%5d] transition count = %d",serial_index++, offset, pMsgData->transitionCnt);
724         offset += sizeof(int);
725
726         for (int i = 0; i < pMsgData->transitionCnt; ++i) {
727                 pTransition = (MMS_SMIL_TRANSITION *)calloc(sizeof(MMS_SMIL_TRANSITION), 1);
728
729                 memcpy(pTransition, pData + offset, sizeof(MMS_SMIL_TRANSITION));
730
731                 offset += sizeof(MMS_SMIL_TRANSITION);
732
733                 pMsgData->transitionlist = g_list_append(pMsgData->transitionlist, pTransition);
734         }
735
736         //Processing Meta List
737         memcpy(&pMsgData->metaCnt, pData + offset, sizeof(int));
738         MSG_DEBUG("[#%2d][%5d] meta count = %d",serial_index++, offset, pMsgData->metaCnt);
739         offset += sizeof(int);
740
741         for (int i = 0; i < pMsgData->metaCnt; ++i) {
742                 pMeta = (MMS_SMIL_META *)calloc(sizeof(MMS_SMIL_META), 1);
743
744                 memcpy(pMeta, pData + offset, sizeof(MMS_SMIL_META));
745
746                 offset += sizeof(MMS_SMIL_META);
747
748                 pMsgData->metalist = g_list_append(pMsgData->metalist, pMeta);
749         }
750
751         MSG_DEBUG("[#%2d][%5d] root layout",serial_index++, offset);
752         memcpy(&pMsgData->rootlayout, pData + offset, sizeof(MMS_SMIL_ROOTLAYOUT));
753         offset += sizeof(MMS_SMIL_ROOTLAYOUT);
754
755 #ifdef FEATURE_JAVA_MMS
756         MSG_DEBUG("[#%2d][%5d] java mms",serial_index++, offset);
757         memcpy(&pMsgData->msgAppId, pData + offset, sizeof(MMS_APPID_INFO_S));
758         offset += sizeof(MMS_APPID_INFO_S);
759 //      MSG_DEBUG("java_app_id valid:%d, appId:%s repleToAppId:%s", pBody->msgAppId.valid, pBody->msgAppId.appId, pBody->msgAppId.replyToAppId);
760 #endif
761
762         memcpy(&pMsgData->header, pData + offset, sizeof(MMS_HEADER_DATA_S));
763         MSG_DEBUG("[#%2d][%5d] mms header",serial_index++, offset);
764         offset += sizeof(MMS_HEADER_DATA_S);
765
766         memcpy(&pMsgData->smil, pData + offset, sizeof(MMS_MULTIPART_DATA_S));
767         MSG_DEBUG("[#%2d][%5d] mms smil",serial_index++, offset);
768         offset += sizeof(MMS_MULTIPART_DATA_S);
769
770         MSG_DEBUG("Final offset : %d", offset);
771         MSG_END();
772         return true;
773 }
774