Merge from master.
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginSmil.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 <sys/stat.h>
20 #include <ctype.h>
21
22 #include "MsgMmsMessage.h"
23 #include "MsgUtilFile.h"
24 #include "MmsPluginTypes.h"
25 #include "MmsPluginSmil.h"
26 #include "MmsPluginMIME.h"
27 #include "MmsPluginStorage.h"
28 #include "MmsPluginDebug.h"
29 #include "MmsPluginCodec.h"
30
31 #define MSG_STDSTR_SHORT                        0x7F
32
33 /* static variables */
34 static char gszEmptyRawDoc[] = "<smil><head><layout></layout></head><body></body></smil>";
35 static MmsSmilDoc *__gpaMmsSmilDoc[MMS_SMIL_MAX_DOC]={NULL, };
36 static char gszColor[MMS_SMIL_COLOR_SIZE] = {0, };
37
38
39 char *MmsSmilGetPresentationData(msg_message_id_t msgId)
40 {
41         MmsMsg *pMsg;
42
43         MmsPluginStorage::instance()->getMmsMessage(&pMsg);
44
45         if (pMsg == NULL) {
46                 MSG_DEBUG("pMsg is NULL");
47                 goto _LCATCH;
48         }
49
50         if (msgId != pMsg->msgID) {
51                 MSG_DEBUG("Invalid Message Id");
52                 return NULL;
53         }
54
55         if (!pMsg->msgBody.pPresentationBody)
56                 goto _LCATCH;
57
58         if (!pMsg->msgBody.pPresentationBody->body.pText)
59                 goto _LCATCH;
60         else
61                 return pMsg->msgBody.pPresentationBody->body.pText;
62
63 _LCATCH:
64         return NULL;
65 }
66
67 bool MmsSmilParseSmilDoc(MMS_MESSAGE_DATA_S *pMmsMsg, char *pSmilDoc)
68 {
69         xmlDocPtr doc;
70         xmlNodePtr cur;
71         MSG_DEBUG("%s", pSmilDoc);
72         doc = xmlParseMemory(pSmilDoc, strlen(pSmilDoc));
73
74         if (doc == NULL) {
75                 MSG_DEBUG("Document not parsed successfully. \n");
76                 return false;
77         }
78
79         cur = xmlDocGetRootElement(doc);
80
81         if (cur == NULL) {
82                 MSG_DEBUG("empty document\n");
83                 xmlFreeDoc(doc);
84                 return false;
85         }
86
87         if (xmlStrcmp(cur->name, (const xmlChar *) "smil")) {
88                 MSG_DEBUG("document of the wrong type, root node != smil");
89                 xmlFreeDoc(doc);
90                 return false;
91         }
92
93         MmsSmilGetElement(pMmsMsg, cur);
94
95         xmlFreeDoc(doc);
96
97         return true;
98 }
99
100 void MmsSmilGetElement(MMS_MESSAGE_DATA_S *pMmsMsg, xmlNode *a_node)
101 {
102         MSG_BEGIN();
103
104         int elementType;
105         int attrType;
106         MMS_SMIL_ROOTLAYOUT rootlayout = {};
107         static bool cmd[ELEMENT_MAX] = {false, };
108         static MMS_SMIL_REGION *pRegion;
109         static MMS_PAGE_S *pPage;
110         static MMS_MEDIA_S *pMedia;
111         static MMS_SMIL_TRANSITION *pTransition;
112         static MMS_SMIL_META *pMeta;
113
114         xmlNode *cur_node = NULL;
115
116         for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
117                 MSG_DEBUG("******* node, name: %s ***\n", cur_node->name);
118
119                 if (cur_node->type == XML_ELEMENT_NODE) {
120                         // Get Smil Element =====================================================
121                         MSG_DEBUG("*** node type: Element, name: %s ***\n", cur_node->name);
122
123                         switch (elementType = MmsSmilGetElementID((char *)cur_node->name)) {
124                         case ELEMENT_ROOTLAYOUT:
125                                 memset(cmd, 0, ELEMENT_MAX);
126                                 cmd[ELEMENT_ROOTLAYOUT] = true;
127                                 break;
128
129                         case ELEMENT_REGION:
130                                 pRegion = (MMS_SMIL_REGION *)calloc(sizeof(MMS_SMIL_REGION), 1);
131                                 memset(cmd, 0, ELEMENT_MAX);
132                                 cmd[ELEMENT_REGION] = true;
133                                 break;
134
135                         case ELEMENT_TRANSITION:
136                                 pTransition = (MMS_SMIL_TRANSITION *)calloc(sizeof(MMS_SMIL_TRANSITION), 1);
137                                 memset(cmd, 0, ELEMENT_MAX);
138                                 cmd[ELEMENT_TRANSITION] = true;
139                                 break;
140
141                         case ELEMENT_META:
142                                 pMeta = (MMS_SMIL_META *)calloc(sizeof(MMS_SMIL_META), 1);
143                                 memset(cmd, 0, ELEMENT_MAX);
144                                 cmd[ELEMENT_META] = true;
145                                 break;
146
147                         case ELEMENT_PAR:
148                                 pPage = (MMS_PAGE_S *)calloc(sizeof(MMS_PAGE_S), 1);
149                                 memset(cmd, 0, ELEMENT_MAX);
150                                 cmd[ELEMENT_PAR] = true;
151                                 break;
152
153                         case ELEMENT_PARAM: // Need to check the original element type
154                                 break;
155
156                         case ELEMENT_TEXT:
157                                 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
158                                 pMedia->mediatype = MMS_SMIL_MEDIA_TEXT;
159                                 memset(cmd, 0, ELEMENT_MAX);
160                                 cmd[ELEMENT_TEXT] = true;
161                                 break;
162
163                         case ELEMENT_IMG:
164                                 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
165                                 pMedia->mediatype = MMS_SMIL_MEDIA_IMG;
166                                 memset(cmd, 0, ELEMENT_MAX);
167                                 cmd[ELEMENT_IMG] = true;
168                                 break;
169
170                         case ELEMENT_AUDIO:
171                                 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
172                                 pMedia->mediatype = MMS_SMIL_MEDIA_AUDIO;
173                                 memset(cmd, 0, ELEMENT_MAX);
174                                 cmd[ELEMENT_AUDIO] = true;
175                                 break;
176
177                         case ELEMENT_VIDEO:
178                                 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
179                                 pMedia->mediatype = MMS_SMIL_MEDIA_VIDEO;
180                                 memset(cmd, 0, ELEMENT_MAX);
181                                 cmd[ELEMENT_VIDEO] = true;
182                                 break;
183
184                         case ELEMENT_REF:
185                                 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
186                                 pMedia->mediatype = MMS_SMIL_MEDIA_IMG_OR_VIDEO;
187                                 memset(cmd, 0, ELEMENT_MAX);
188                                 cmd[ELEMENT_REF] = true;
189                                 break;
190
191                         case ELEMENT_ANIMATE:
192                                 pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
193                                 pMedia->mediatype = MMS_SMIL_MEDIA_ANIMATE;
194                                 memset(cmd, 0, ELEMENT_MAX);
195                                 cmd[ELEMENT_ANIMATE] = true;
196                                 break;
197
198                         default:
199                                 memset(cmd, 0, ELEMENT_MAX);
200                                 break;
201                         }
202
203                         //Get Smil Attribute =====================================================
204                         xmlAttr *pAttr = cur_node->properties;
205                         SMIL_ATTRIBUTE_T paramType = ATTRIBUTE_UNKNOWN;
206
207                         for ( ; pAttr; pAttr = pAttr->next) {
208                                 MSG_DEBUG("AttributeType: (%s, %s) ", pAttr->name, pAttr->children->content);
209                                 switch (attrType = MmsSmilGetAttrID((char *)pAttr->name)) {
210                                 case ATTRIBUTE_ID:
211                                         {
212                                                 if (cmd[ELEMENT_REGION]) {
213                                                         strncpy(pRegion->szID, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
214                                                 } else if (cmd[ELEMENT_TRANSITION]) {
215                                                         strncpy(pTransition->szID, (char *)pAttr->children->content, MAX_SMIL_TRANSITION_ID - 1);
216                                                 } else if (cmd[ELEMENT_META]) {
217                                                         strncpy(pMeta->szID, (char *)pAttr->children->content, MAX_SMIL_META_ID - 1);
218                                                 }
219                                         }
220                                         break;
221
222                                 case ATTRIBUTE_TOP:
223                                         {
224                                                 int bUnitPercent;
225                                                 int value;
226
227                                                 if (strchr((char *)pAttr->children->content, '%'))
228                                                         bUnitPercent = true;
229                                                 else
230                                                         bUnitPercent = false;
231
232                                                 value = atoi((char *)pAttr->children->content);
233
234                                                 if (cmd[ELEMENT_REGION]) {
235                                                         pRegion->nTop.bUnitPercent = bUnitPercent;
236                                                         pRegion->nTop.value = value;
237                                                 }
238                                         }
239                                         break;
240
241                                 case ATTRIBUTE_LEFT:
242                                         {
243                                                 int bUnitPercent;
244                                                 int value;
245
246                                                 if (strchr((char *)pAttr->children->content, '%'))
247                                                         bUnitPercent = true;
248                                                 else
249                                                         bUnitPercent = false;
250
251                                                 value = atoi((char *)pAttr->children->content);
252
253                                                 if (cmd[ELEMENT_REGION]) {
254                                                         pRegion->nLeft.bUnitPercent = bUnitPercent;
255                                                         pRegion->nLeft.value = value;
256                                                 }
257                                         }
258                                         break;
259
260
261                                 case ATTRIBUTE_WIDTH:
262                                         {
263                                                 int bUnitPercent;
264                                                 int value;
265
266                                                 if (strchr((char *)pAttr->children->content, '%'))
267                                                         bUnitPercent = true;
268                                                 else
269                                                         bUnitPercent = false;
270
271                                                 value = atoi((char *)pAttr->children->content);
272
273                                                 if (cmd[ELEMENT_ROOTLAYOUT]) {
274                                                         rootlayout.width.bUnitPercent = bUnitPercent;
275                                                         rootlayout.width.value = value;
276                                                 } else if (cmd[ELEMENT_REGION]) {
277                                                         pRegion->width.bUnitPercent = bUnitPercent;
278                                                         pRegion->width.value = value;
279                                                 }
280                                         }
281                                         break;
282
283                                 case ATTRIBUTE_HEIGHT:
284                                         {
285                                                 int bUnitPercent;
286                                                 int value;
287
288                                                 if (strchr((char *)pAttr->children->content, '%'))
289                                                         bUnitPercent = true;
290                                                 else
291                                                         bUnitPercent = false;
292
293                                                 value = atoi((char *)pAttr->children->content);
294
295                                                 if (cmd[ELEMENT_ROOTLAYOUT]) {
296                                                         rootlayout.height.bUnitPercent = bUnitPercent;
297                                                         rootlayout.height.value = value;
298                                                 } else if (cmd[ELEMENT_REGION]) {
299                                                         pRegion->height.bUnitPercent = bUnitPercent;
300                                                         pRegion->height.value = value;
301                                                 }
302                                         }
303                                         break;
304
305                                 case ATTRIBUTE_FIT:
306                                         if (cmd[ELEMENT_REGION]) {
307                                                 if (!strcmp((char *)pAttr->children->content, "meet")) {
308                                                         pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
309                                                 } else {
310                                                         pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
311                                                 }
312                                         }
313                                         break;
314
315                                 case ATTRIBUTE_BGCOLOR:
316                                         if (cmd[ELEMENT_ROOTLAYOUT]) {
317                                                 rootlayout.bBgColor = true;
318                                                 rootlayout.bgColor = MmsSmilGetColorValue(pAttr->children->content);
319                                         } else if (cmd[ELEMENT_REGION]) {
320                                                 pRegion->bBgColor = true;
321                                                 pRegion->bgColor = MmsSmilGetColorValue(pAttr->children->content);
322                                         } else if (cmd[ELEMENT_TEXT])
323                                                 pMedia->sMedia.sText.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
324                                         else
325                                                 pMedia->sMedia.sAVI.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
326
327                                         break;
328
329                                 case ATTRIBUTE_DUR:
330                                         if (cmd[ELEMENT_PAR])
331                                                 pPage->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
332                                         else if (cmd[ELEMENT_TRANSITION])
333                                                 pTransition->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
334                                         else if (cmd[ELEMENT_TEXT])
335                                                 pMedia->sMedia.sText.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
336                                         else
337                                                 pMedia->sMedia.sAVI.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
338
339 #ifdef MMS_SMIL_ANIMATE
340                                         if (cmd[ELEMENT_ANIMATE])
341                                                 pMedia->sMedia.sAVI.nDur = MmsSmilGetTime((char *)pAttr->children->content);
342 #endif
343                                         break;
344
345                                 case ATTRIBUTE_SRC:
346                                 {
347                                         char *szSrc;
348                                         char szTmpSrc[MSG_FILEPATH_LEN_MAX] = {0,};
349                                         char szOutBuf[MSG_FILEPATH_LEN_MAX] = {0, };
350                                         int cLen;
351                                         int ret;
352                                         MsgMultipart *pPart = NULL;
353                                         MmsMsg *pMsg;
354
355                                         szSrc = MsgChangeHexString((char *)pAttr->children->content);
356                                         if (szSrc == NULL)
357                                                 break;
358
359                                         memcpy(pMedia->szSrc, szSrc, strlen(szSrc) + 1);
360                                         free(szSrc);
361
362                                         cLen = strlen(pMedia->szSrc);
363                                         if (!strncasecmp(pMedia->szSrc, "cid:", 4)) {
364                                                 strncpy(szTmpSrc, pMedia->szSrc + 4, cLen - 4);
365                                                 szTmpSrc[cLen - 4] = '\0';
366                                         } else {
367                                                 strncpy(szTmpSrc, pMedia->szSrc, cLen);
368                                                 szTmpSrc[cLen] = '\0';
369                                         }
370
371                                         MmsPluginStorage::instance()->getMmsMessage(&pMsg);
372                                         pPart = pMsg->msgBody.body.pMultipart;
373 #ifndef __SUPPORT_DRM__
374                                         ret = MmsSmilGetMediaSrcForNormalMsg(szOutBuf, szTmpSrc, pPart);
375 #else
376                                         ret = MmsSmilGetMediaSrcForNormalMsg(szOutBuf, szTmpSrc, pPart, pMedia);
377 #endif
378                                         if (ret >= 0 && strlen(szOutBuf) > 0) {
379                                                 strcpy(pMedia->szSrc, szOutBuf);
380                                                 MmsSmilGetMediaFilePath(pMedia, szTmpSrc, pMsg->msgID);
381                                         }
382                                         break;
383                                 }
384                                 case ATTRIBUTE_COLOR:
385                                         if (cmd[ELEMENT_TEXT])
386                                                 pMedia->sMedia.sText.nColor = MmsSmilGetColorValue(pAttr->children->content);
387                                         break;
388
389                                 case ATTRIBUTE_SIZE:
390                                         if (cmd[ELEMENT_TEXT])
391                                                 pMedia->sMedia.sText.nSize = atoi((char *)pAttr->children->content);
392                                         break;
393
394                                 case ATTRIBUTE_BOLD:
395                                         if (cmd[ELEMENT_TEXT]) {
396                                                 pMedia->sMedia.sText.bBold = MmsSmilGetFontAttrib((char *)pAttr->children->content);
397                                         }
398                                         break;
399
400                                 case ATTRIBUTE_UNDERLINE:
401                                         if (cmd[ELEMENT_TEXT])
402                                                 pMedia->sMedia.sText.bUnderLine = MmsSmilGetFontAttrib((char *)pAttr->children->content);
403                                         break;
404
405                                 case ATTRIBUTE_ITALIC:
406                                         if (cmd[ELEMENT_TEXT])
407                                                 pMedia->sMedia.sText.bItalic = MmsSmilGetFontAttrib((char *)pAttr->children->content);
408                                         break;
409
410                                 case ATTRIBUTE_REVERSE:
411                                         if (cmd[ELEMENT_TEXT])
412                                                 pMedia->sMedia.sText.bReverse = MmsSmilGetFontAttrib((char *)pAttr->children->content);
413                                         break;
414
415                                 case ATTRIBUTE_DIRECTION:
416                                         if (cmd[ELEMENT_TEXT])
417                                                 pMedia->sMedia.sText.nDirection = MmsSmilGetFontDirection((char *)pAttr->children->content);
418                                         break;
419                                 case ATTRIBUTE_REGION:
420                                         strncpy(pMedia->regionId, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
421                                         break;
422
423                                 case ATTRIBUTE_TRANSIN:
424                                         if (cmd[ELEMENT_TEXT])
425                                                 strncpy(pMedia->sMedia.sText.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
426                                         else
427                                                 strncpy(pMedia->sMedia.sAVI.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
428                                         break;
429
430                                 case ATTRIBUTE_TRANSOUT:
431                                         if (cmd[ELEMENT_TEXT])
432                                                 strncpy(pMedia->sMedia.sText.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
433                                         else
434                                                 strncpy(pMedia->sMedia.sAVI.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
435                                         break;
436
437                                 case ATTRIBUTE_BEGIN:
438                                         if (cmd[ELEMENT_TEXT])
439                                                 pMedia->sMedia.sText.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
440                                         else
441                                                 pMedia->sMedia.sAVI.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
442                                         break;
443
444                                 case ATTRIBUTE_END:
445                                         if (cmd[ELEMENT_TEXT])
446                                                 pMedia->sMedia.sText.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
447                                         else
448                                                 pMedia->sMedia.sAVI.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
449                                         break;
450
451                                 case ATTRIBUTE_REPEAT_COUNT:
452                                         if (cmd[ELEMENT_TEXT])
453                                                 pMedia->sMedia.sText.nRepeat = atoi((char *)pAttr->children->content);
454                                         else
455                                                 pMedia->sMedia.sAVI.nRepeat = atoi((char *)pAttr->children->content);
456                                         break;
457
458                                 case ATTRIBUTE_NAME:
459                                         if (!strcmp((char *)pAttr->children->content, "foreground-color") || !strcmp((char *)pAttr->children->content, "foregroundcolor"))
460                                                 paramType = ATTRIBUTE_FGCOLOR;
461                                         else if (!strcmp((char *)pAttr->children->content, "background-color") || !strcmp((char *)pAttr->children->content, "backgroundcolor"))
462                                                 paramType = ATTRIBUTE_BGCOLOR;
463                                         else if (!strcmp((char *)pAttr->children->content, "textsize"))
464                                                 paramType = ATTRIBUTE_SIZE;
465                                         else if (!strcmp((char *)pAttr->children->content, "textattribute"))
466                                                 paramType = ATTRIBUTE_TEXTFORMAT;
467
468                                         if (cmd[ELEMENT_META])
469                                                 strncpy(pMeta->szName, (char *)pAttr->children->content, MAX_SMIL_META_NAME - 1);
470                                         break;
471
472                                 case ATTRIBUTE_VALUE:
473                                         if (paramType == ATTRIBUTE_SIZE && cmd[ELEMENT_TEXT])
474                                                 pMedia->sMedia.sText.nSize = MmsSmilGetFontSizeValue((char *)pAttr->children->content);
475                                         else if (paramType == ATTRIBUTE_FGCOLOR && cmd[ELEMENT_TEXT])
476                                                 pMedia->sMedia.sText.nColor =  MmsSmilGetColorValue(pAttr->children->content);
477                                         else if (paramType == ATTRIBUTE_BGCOLOR && cmd[ELEMENT_TEXT])
478                                                 pMedia->sMedia.sText.nBgColor =  MmsSmilGetColorValue(pAttr->children->content);
479                                         else if (paramType == ATTRIBUTE_TEXTFORMAT && cmd[ELEMENT_TEXT]) {
480                                                 MmsSmilFontType fontType;
481
482                                                 fontType = MmsSmilGetFontTypeValue((char *)pAttr->children->content);
483
484                                                 if (fontType == MMS_SMIL_FONT_TYPE_BOLD)
485                                                         pMedia->sMedia.sText.bBold = true;
486                                                 else
487                                                         pMedia->sMedia.sText.bBold = false;
488
489                                                 if (fontType == MMS_SMIL_FONT_TYPE_ITALIC)
490                                                         pMedia->sMedia.sText.bItalic = true;
491                                                 else
492                                                         pMedia->sMedia.sText.bItalic = false;
493
494                                                 if (fontType == MMS_SMIL_FONT_TYPE_UNDERLINE)
495                                                         pMedia->sMedia.sText.bUnderLine = true;
496                                                 else
497                                                         pMedia->sMedia.sText.bUnderLine = false;
498                                         }
499                                         break;
500
501                                 case ATTRIBUTE_ALT:
502                                         strncpy(pMedia->szAlt, (char *)pAttr->children->content, MAX_SMIL_ALT_LEN - 1);
503                                         break;
504
505                                 case ATTRIBUTE_TYPE:
506                                         pTransition->nType = (MmsSmilTransType)atoi((char *)pAttr->children->content);
507
508                                         switch (pTransition->nType) {
509                                         case MMS_SMIL_TRANS_SLIDEWIPE:
510                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_FROM_LEFT;
511                                                 break;
512                                         case MMS_SMIL_TRANS_BARWIPE:
513                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_TOP_TO_BOTTOM;
514                                                 break;
515                                         case MMS_SMIL_TRANS_BARNDOORWIPE:
516                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_HORIZONTAL;
517                                                 break;
518                                         default:
519                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_NONE;
520                                                 break;
521                                         }
522
523                                         break;
524
525                                 case ATTRIBUTE_SUBTYPE:
526                                         pTransition->nSubType = (MmsSmilTransSubType)atoi((char *)pAttr->children->content);
527                                         break;
528
529                                 case ATTRIBUTE_CONTENT:
530                                         strncpy(pMeta->szContent, (char *)pAttr->children->content, MAX_SMIL_META_CONTENT - 1);
531                                         break;
532 #ifdef MMS_SMIL_ANIMATE
533                                 case ATTRIBUTE_ATTRIBUTE_NAME:
534                                         strcpy(pMedia->sMedia.sAVI.nAttributeName, (char *)pAttr->children->content);
535                                         break;
536
537                                 case ATTRIBUTE_ATTRIBUTE_TYPE:
538                                         strcpy(pMedia->sMedia.sAVI.nAttributeType, (char *)pAttr->children->content);
539                                         break;
540
541                                 case ATTRIBUTE_TARGET_ELEMENT:
542                                         strcpy(pMedia->sMedia.sAVI.nTargetElement, (char *)pAttr->children->content);
543                                         break;
544
545                                 case ATTRIBUTE_FROM:
546                                         pMedia->sMedia.sAVI.nFrom = atoi((char *)pAttr->children->content);
547                                         break;
548
549                                 case ATTRIBUTE_TO:
550                                         pMedia->sMedia.sAVI.nTo = atoi((char *)pAttr->children->content);
551                                         break;
552
553                                 case ATTRIBUTE_BY:
554                                         pMedia->sMedia.sAVI.nBy = atoi((char *)pAttr->children->content);
555                                         break;
556
557                                 case ATTRIBUTE_VALUES:
558                                         pMedia->sMedia.sAVI.nValues = atoi((char *)pAttr->children->content);
559                                         break;
560
561                                 case ATTRIBUTE_CALCMODE:
562                                         strcpy(pMedia->sMedia.sAVI.nCalcMode, (char *)pAttr->children->content);
563                                         break;
564 #endif
565                                 default:
566                                         MSG_DEBUG("Undefined Attribute was found!!!!!");
567                                 }
568                         }
569
570                         if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_REGION]) {
571                                 // Insert a region to region list
572                                 _MsgMmsAddRegion(pMmsMsg, pRegion);
573                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_PAR]) {
574                                 //Insert a page to page list
575                                 _MsgMmsAddPage(pMmsMsg, pPage);
576                         } else if (paramType == ATTRIBUTE_UNKNOWN && (cmd[ELEMENT_TEXT] ||cmd[ELEMENT_IMG] ||cmd[ELEMENT_AUDIO] ||cmd[ELEMENT_VIDEO] ||cmd[ELEMENT_ANIMATE])) {
577                                 //Insert a media to media list
578                                 _MsgMmsAddMedia(pPage, pMedia);
579                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_ROOTLAYOUT]) {
580                                 _MsgMmsSetRootLayout(pMmsMsg, &rootlayout);
581                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_TRANSITION]) {
582                                 //Insert a transition to transition list
583                                 _MsgMmsAddTransition(pMmsMsg, pTransition);
584                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_META]) {
585                                 //Insert a meta to meta list
586                                 _MsgMmsAddMeta(pMmsMsg, pMeta);
587                         }
588
589                         paramType = ATTRIBUTE_UNKNOWN;
590                 }
591
592                 MmsSmilGetElement(pMmsMsg, cur_node->children);
593         }
594
595         MSG_END();
596 }
597
598
599 int MmsSmilGetColorValue(xmlChar *content)
600 {
601         int color;
602
603         if (content[0] == '#')  // RGB value
604                 color = MmsSmilAtoIHexa((char *)&content[1]);
605         else if (content[0] == '0' && (content[1] == 'x' || content[1] == 'X'))
606                 color = MmsSmilAtoIHexa((char *)&content[2]);
607         else {
608                 MSG_DEBUG("Invalid Color Value");
609                 color = -1;
610         }
611
612         return color;
613 }
614
615 int MmsSmilAtoIHexa(char *pInput)
616 {
617         int res = 0;
618         int len = 0;
619         int temp = 1;
620         int i  = 0;
621         int j = 0;
622         char *pOutput = NULL;
623
624         MSG_DEBUG("__MmsSmilAtoIHexa() enter..\n");
625
626         len = strlen(pInput);
627         pOutput = (char *)malloc(len + 1);
628
629         if (pOutput == NULL) {
630                 MSG_DEBUG("__MmsSmilAtoIHexa: Memory full \n");
631                 goto __CATCH;
632         }
633
634         memset(pOutput, 0, len + 1);
635
636         for (i = len - 1; i >= 0; i--) {
637                 for (j = 0; j < (len - 1 - i); j++) {
638                         temp *= 16;
639                 }
640
641                 switch (pInput[i]) {
642                 case '0':
643                         pOutput[i] = 0;
644                         break;
645
646                 case '1':
647                         pOutput[i] = 1;
648                         break;
649
650                 case '2':
651                         pOutput[i] = 2;
652                         break;
653
654                 case '3':
655                         pOutput[i] = 3;
656                         break;
657
658                 case '4':
659                         pOutput[i] = 4;
660                         break;
661
662                 case '5':
663                         pOutput[i] = 5;
664                         break;
665
666                 case '6':
667                         pOutput[i] = 6;
668                         break;
669
670                 case '7':
671                         pOutput[i] = 7;
672                         break;
673
674                 case '8':
675                         pOutput[i] = 8;
676                         break;
677
678                 case '9':
679                         pOutput[i] = 9;
680                         break;
681
682                 case 'a':
683                 case 'A':
684                         pOutput[i] = 10;
685                         break;
686
687                 case 'b':
688                 case 'B':
689                         pOutput[i] = 11;
690                         break;
691
692                 case 'c':
693                 case 'C':
694                         pOutput[i] = 12;
695                         break;
696
697                 case 'd':
698                 case 'D':
699                         pOutput[i] = 13;
700                         break;
701
702                 case 'e':
703                 case 'E':
704                         pOutput[i] = 14;
705                         break;
706
707                 case 'f':
708                 case 'F':
709                         pOutput[i] = 15;
710                         break;
711                 }
712
713                 res += (pOutput[i] * temp);
714                 temp = 1;
715         }
716
717 __CATCH:
718
719         if (pOutput) {
720                 free(pOutput);
721                 pOutput = NULL;
722         }
723
724         return res;
725 }
726
727 int MmsSmilGetTime(char *pValue)
728 {
729         char *pTemp = NULL;
730         bool bMSec = false;
731         int retVal = 0;
732         int i = 0;
733         int len = 0;
734
735         if (pValue == NULL || pValue[0] == '\0')
736                 return 0;
737
738         len = strlen(pValue);
739
740         /* Default time unit -> millisecond */
741         if (strstr(pValue, "msec"))
742                 bMSec = true;
743
744         if (strstr(pValue, "ms"))
745                 bMSec = true;
746
747         pTemp = (char *)malloc(strlen(pValue) + 1);
748
749         if (NULL == pTemp) {
750                 MSG_DEBUG("__MmsSmilGetTime : malloc for <time> attribute is failed \n");
751                 return 0;
752         }
753
754         while (isdigit(pValue[i])) {
755                 pTemp[i] = pValue[i];
756                 i++;
757         }
758         pTemp[i] = '\0';
759
760         /* Detect 's' and 'ms' here */
761         retVal = atoi(pTemp);
762
763         if (bMSec == false)
764                 retVal *= 1000;
765
766         if (pTemp) {
767                 free(pTemp);
768                 pTemp = NULL;
769         }
770
771         return retVal;
772 }
773 #ifndef __SUPPORT_DRM__
774 int MmsSmilGetMediaSrcForNormalMsg(char *szOutbuf, char *szInBuf, MsgMultipart *pPart)
775 #else
776 int MmsSmilGetMediaSrcForNormalMsg(char *szOutbuf, char *szInBuf, MsgMultipart *pPart, MMS_MEDIA_S *pMedia)
777 #endif
778 {
779         char szContentID[MSG_MSG_ID_LEN + 1] = {0, };
780         char szContentLI[MSG_MSG_ID_LEN + 1] = {0, };
781         int cLen  = 0;
782         int nPart = 0;
783
784         MSG_DEBUG("szInBuf: %s", szInBuf);
785         while (pPart && pPart->pBody) {
786                 if (pPart->type.szContentID[0]) {
787                         cLen = strlen(pPart->type.szContentID);
788
789                         if (pPart->type.szContentID[0] == '<' && pPart->type.szContentID[cLen - 1] == '>') {
790                                 strncpy(szContentID, &pPart->type.szContentID[1], cLen - 2);
791                                 szContentID[cLen - 2] = '\0';
792                         } else if (pPart->type.szContentID[0] == MSG_CH_QUOT && pPart->type.szContentID[cLen-1] == MSG_CH_QUOT) {
793                                 strncpy(szContentID, &pPart->type.szContentID[1], cLen - 2);
794                                 szContentID[cLen - 2] = '\0';
795                         } else {
796                                 strncpy(szContentID, pPart->type.szContentID, cLen);
797                                 szContentID[cLen] = '\0';
798                         }
799                 } else {
800                         szContentID[0] = '\0';
801                 }
802
803                 MSG_DEBUG("szContentID: %s", szContentID);
804
805                 if (pPart->type.szContentLocation[0]) {
806                         cLen = strlen(pPart->type.szContentLocation);
807
808                         if (pPart->type.szContentLocation[0] == MSG_CH_QUOT &&
809                                 pPart->type.szContentLocation[cLen-1] == MSG_CH_QUOT) {
810                                 strncpy(szContentLI, &pPart->type.szContentLocation[1], cLen-2);
811                                 szContentLI[cLen-2] = '\0';
812                         } else {
813                                 strncpy(szContentLI, pPart->type.szContentLocation, cLen);
814                                 szContentLI[cLen] = '\0';
815                         }
816                 } else {
817                         szContentLI[0] = '\0';
818                 }
819
820                 MSG_DEBUG("szContentLocation: %s", szContentLI);
821
822                 if (strcasecmp(szContentID, szInBuf) == 0) {
823                         strcpy(szOutbuf, pPart->type.param.szFileName);
824                         MSG_DEBUG("match with szContentID");
825                         goto RETURN;
826                 } else if (strcasecmp(szContentLI, szInBuf) == 0) {
827                         strcpy(szOutbuf, pPart->type.param.szFileName);
828                         MSG_DEBUG("match with szContentLocation");
829                         goto RETURN;
830                 } else if (strcasecmp(pPart->type.param.szName, szInBuf) == 0) {
831                         strcpy(szOutbuf, pPart->type.param.szFileName);
832                         MSG_DEBUG("match with Parameter Name");
833                         goto RETURN;
834                 }
835
836                 nPart++;
837                 pPart = pPart->pNext;
838         }
839
840         return -1;
841
842 RETURN:
843 #ifdef __SUPPORT_DRM__
844         pMedia->drmType = pPart->type.drmInfo.drmType;
845
846         if (pPart->type.drmInfo.szDrm2FullPath != NULL) {
847                 MSG_DEBUG("szDrm2FullPath: %s", pPart->type.drmInfo.szDrm2FullPath);
848                 strncpy(pMedia->szDrm2FullPath, pPart->type.drmInfo.szDrm2FullPath, MSG_FILEPATH_LEN_MAX - 1);
849         }
850 #endif
851         return nPart;
852
853 }
854
855 int     MmsSmilGetElementID(char *pString)
856 {
857         if (!strcmp(pString, "smil"))
858                 return ELEMENT_SMIL;
859         else if (!strcmp(pString, "head"))
860                 return ELEMENT_HEAD;
861         else if (!strcmp(pString, "layout"))
862                 return ELEMENT_LAYOUT;
863         else if (!strcmp(pString, "root-layout"))
864                 return ELEMENT_ROOTLAYOUT;
865         else if (!strcmp(pString, "region"))
866                 return ELEMENT_REGION;
867         else if (!strcmp(pString, "body"))
868                 return ELEMENT_BODY;
869         else if (!strcmp(pString, "par"))
870                 return ELEMENT_PAR;
871         else if (!strcmp(pString, "param"))
872                 return ELEMENT_PARAM;
873         else if (!strcmp(pString, "text"))
874                 return ELEMENT_TEXT;
875         else if (!strcmp(pString, "img"))
876                 return ELEMENT_IMG;
877         else if (!strcmp(pString, "audio"))
878                 return ELEMENT_AUDIO;
879         else if (!strcmp(pString, "video"))
880                 return ELEMENT_VIDEO;
881         else if (!strcmp(pString, "ref"))
882                 return ELEMENT_REF;
883         else if (!strcmp(pString, "animate"))
884                 return ELEMENT_ANIMATE;
885         else if (!strcmp(pString, "root-layout"))
886                 return ELEMENT_HEAD;
887         else if (!strcmp(pString, "transition"))
888                 return ELEMENT_TRANSITION;
889         else if (!strcmp(pString, "meta"))
890                 return ELEMENT_META;
891         else
892                 return -1;
893 }
894
895 int     MmsSmilGetAttrID(char *pString)
896 {
897         if (!strcmp(pString, "id"))
898                 return ATTRIBUTE_ID;
899         else if (!strcmp(pString, "top"))
900                 return ATTRIBUTE_TOP;
901         else if (!strcmp(pString, "left"))
902                 return ATTRIBUTE_LEFT;
903         else if (!strcmp(pString, "width"))
904                 return ATTRIBUTE_WIDTH;
905         else if (!strcmp(pString, "height"))
906                 return ATTRIBUTE_HEIGHT;
907         else if (!strcmp(pString, "fit"))
908                 return ATTRIBUTE_FIT;
909         else if (!strcmp(pString, "backgroundColor") || !strcmp(pString, "background-color"))
910                 return ATTRIBUTE_BGCOLOR;
911         else if (!strcmp(pString, "dur"))
912                 return ATTRIBUTE_DUR;
913         else if (!strcmp(pString, "src"))
914                 return ATTRIBUTE_SRC;
915         else if (!strcmp(pString, "color"))
916                 return ATTRIBUTE_COLOR;
917         else if (!strcmp(pString, "bold"))
918                 return ATTRIBUTE_BOLD;
919         else if (!strcmp(pString, "underline"))
920                 return ATTRIBUTE_UNDERLINE;
921         else if (!strcmp(pString, "italic"))
922                 return ATTRIBUTE_ITALIC;
923         else if (!strcmp(pString, "reverse"))
924                 return ATTRIBUTE_REVERSE;
925         else if (!strcmp(pString, "direction"))
926                 return ATTRIBUTE_DIRECTION;
927         else if (!strcmp(pString, "size"))
928                 return ATTRIBUTE_SIZE;
929         else if (!strcmp(pString, "font"))
930                 return ATTRIBUTE_FONT;
931         else if (!strcmp(pString, "region"))
932                 return ATTRIBUTE_REGION;
933         else if (!strcmp(pString, "name"))
934                 return ATTRIBUTE_NAME;
935         else if (!strcmp(pString, "value"))
936                 return ATTRIBUTE_VALUE;
937         else if (!strcmp(pString, "alt"))
938                 return ATTRIBUTE_ALT;
939         else if (!strcmp(pString, "type"))
940                 return ATTRIBUTE_TYPE;
941         else if (!strcmp(pString, "subtype"))
942                 return ATTRIBUTE_SUBTYPE;
943         else if (!strcmp(pString, "content"))
944                 return ATTRIBUTE_CONTENT;
945         else if (!strcmp(pString, "transIn"))
946                 return ATTRIBUTE_TRANSIN;
947         else if (!strcmp(pString, "transOut"))
948                 return ATTRIBUTE_TRANSOUT;
949         else if (!strcmp(pString, "begin"))
950                 return ATTRIBUTE_BEGIN;
951         else if (!strcmp(pString, "end"))
952                 return ATTRIBUTE_END;
953         else if (!strcmp(pString, "repeatCount"))
954                 return ATTRIBUTE_REPEAT_COUNT;
955 #ifdef MMS_SMIL_ANIMATE
956         else if (!strcmp(pString, "attributeName"))
957                 return ATTRIBUTE_ATTRIBUTE_NAME;
958         else if (!strcmp(pString, "attributeType"))
959                 return ATTRIBUTE_ATTRIBUTE_TYPE;
960         else if (!strcmp(pString, "targetElement"))
961                 return ATTRIBUTE_TARGET_ELEMENT;
962         else if (!strcmp(pString, "from"))
963                 return ATTRIBUTE_FROM;
964         else if (!strcmp(pString, "to"))
965                 return ATTRIBUTE_TO;
966         else if (!strcmp(pString, "by"))
967                 return ATTRIBUTE_BY;
968         else if (!strcmp(pString, "values"))
969                 return ATTRIBUTE_VALUES;
970         else if (!strcmp(pString, "calcMode"))
971                 return ATTRIBUTE_CALCMODE;
972 #endif
973         else
974                 return -1;
975 }
976
977 bool MmsSmilGetFontAttrib(char *pString)
978 {
979         if (!strcmp(pString, "true"))
980                 return true;
981         else
982                 return false;
983 }
984
985 MmsTextDirection MmsSmilGetFontDirection(char *pString)
986 {
987         MmsTextDirection direction = MMS_TEXT_DIRECTION_INVALID;
988
989         if (!strcmp(pString, "right"))
990                 direction = MMS_TEXT_DIRECTION_RIGHT;
991         else if (!strcmp(pString, "down"))
992                 direction = MMS_TEXT_DIRECTION_DOWN;
993
994         return direction;
995 }
996
997 int MmsSmilGetFontSizeValue(char *pString)
998 {
999         MSG_DEBUG(" #### content = %s #### ", pString);
1000         if (!strcmp(pString, "small"))
1001                 return MMS_SMIL_FONT_SIZE_SMALL;
1002         else if (!strcmp(pString, "normal"))
1003                 return MMS_SMIL_FONT_SIZE_NORMAL;
1004         else if (!strcmp(pString, "large"))
1005                 return MMS_SMIL_FONT_SIZE_LARGE;
1006         else
1007                 return atoi(pString);
1008 }
1009
1010 MmsSmilFontType MmsSmilGetFontTypeValue(char *pString)
1011 {
1012         MSG_DEBUG(" #### content = %s #### ", pString);
1013
1014         if (!strcmp(pString, "normal"))
1015                 return MMS_SMIL_FONT_TYPE_NORMAL;
1016         else if (!strcmp(pString, "italic"))
1017                 return MMS_SMIL_FONT_TYPE_ITALIC;
1018         else if (!strcmp(pString, "bold"))
1019                 return MMS_SMIL_FONT_TYPE_BOLD;
1020         else if (!strcmp(pString, "underline"))
1021                 return MMS_SMIL_FONT_TYPE_UNDERLINE;
1022         else
1023                 return MMS_SMIL_FONT_TYPE_NORMAL;
1024 }
1025
1026 bool MmsSmilGetMediaFilePath(MMS_MEDIA_S *pMedia, char *pszTemp, int msgID)
1027 {
1028         if (!pMedia) {
1029                 MSG_DEBUG("pMedia is NULL");
1030                 return false;
1031         }
1032
1033         snprintf(pMedia->szFilePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, pMedia->szSrc);
1034         MSG_DEBUG("pMedia's filePath: %s", pMedia->szFilePath);
1035
1036         __MmsGetRealFileName(pMedia->mediatype, pMedia->szSrc, pMedia->szFileName, msgID);
1037         MSG_DEBUG("pMedia's fileName: %s", pMedia->szFileName);
1038
1039         snprintf(pMedia->szContentID, MSG_MSG_ID_LEN+1, "%s", pszTemp);
1040         MSG_DEBUG("pMedia's ContentID: %s", pMedia->szContentID);
1041
1042         return true;
1043 }
1044
1045
1046 /**     @fn             bool MMSGenerateSmilBuffer(MMS_MESSAGE_DATA_S *pstMsgBody)
1047  *      @brief  Forms Smil Buffer using pstMsgBody. \n
1048  *      @param[in/out]  pstMsgBody is Message handle. \n
1049  *      @retval TRUE                            In case of Success. \n
1050  *      @retval FALSE                           In case of failure. \n
1051  */
1052 bool MMSGenerateSmilBuffer(MMS_MESSAGE_DATA_S *pstMsgBody)
1053 {
1054         HMmsSmil hSmilDoc = INVALID_HOBJ;
1055         int nIndex;
1056         int nMediaIndex;
1057         int nTotalPageNum;
1058         int nTotalMediaNum;
1059         int nRegionCount;
1060         MMS_PAGE_S *pstPage;
1061         MMS_MEDIA_S *pstMedia;
1062         MMS_SMIL_REGION *pstRegion;
1063         char *pszRawData;
1064
1065         MSG_BEGIN();
1066
1067         hSmilDoc = MmsSmilCreateEmptySmilDoc();
1068         MSG_DEBUG("Smil Doc =%d",hSmilDoc);
1069         if (INVALID_HOBJ == hSmilDoc) {
1070                 MSG_DEBUG("Invalid SmilDoc[%d]",hSmilDoc);
1071                 return false;
1072         }
1073         // Add Root Layout to Smil Document
1074         if (false == MmsSmilAddRootLayout(hSmilDoc, &(pstMsgBody->rootlayout))) {
1075                 MSG_DEBUG("MmsSmilAddRootLayout Failed");
1076                 MmsSmilDestroyDoc(hSmilDoc);
1077         }
1078         //Add Region list to Smil Document
1079         nRegionCount = pstMsgBody->regionCnt;
1080         MSG_DEBUG(" Region Count =%d",nRegionCount);
1081         for (nIndex = 0; nIndex < nRegionCount; nIndex++) {
1082                 MSG_DEBUG("Calling _MsgMmsGetSmilRegion");
1083                 pstRegion = _MsgMmsGetSmilRegion(pstMsgBody, nIndex);
1084                 if (NULL == pstRegion) {
1085                         MSG_DEBUG("pstRegion is NULL");
1086                         MmsSmilDestroyDoc(hSmilDoc);
1087                         return false;
1088                 }
1089                 MSG_DEBUG("Calling MmsSmilAddRegion");
1090                 if (false == MmsSmilAddRegion(hSmilDoc, pstRegion)) {
1091                         MSG_DEBUG("Adding Region to smil doc failed");
1092                         MmsSmilDestroyDoc(hSmilDoc);
1093                         return false;
1094                 }
1095         }
1096         // Add page list to Smil Document
1097          nTotalPageNum = pstMsgBody->pageCnt ;
1098         MSG_DEBUG(" Page Count =%d",nTotalPageNum);
1099         for (nIndex = 0; nIndex < nTotalPageNum; nIndex++) {
1100                 MSG_DEBUG("Calling _MsgMmsGetPage");
1101                 pstPage = _MsgMmsGetPage(pstMsgBody, nIndex);
1102                 if (NULL == pstPage) {
1103                         MSG_DEBUG("pstPage is NULL");
1104                         MmsSmilDestroyDoc(hSmilDoc);
1105                         return false;
1106                 }
1107                 // Add page to smil doc
1108                 MSG_DEBUG("Calling MmsSmilAddPage");
1109                 if (false == MmsSmilAddPage(hSmilDoc, pstPage)) {
1110                         MSG_DEBUG("Adding page to smil doc failed");
1111                         MmsSmilDestroyDoc(hSmilDoc);
1112                         return false;
1113                 }
1114                 nTotalMediaNum = pstPage->mediaCnt;
1115                 MSG_DEBUG(" Media Count =%d",nTotalMediaNum);
1116                 for (nMediaIndex = 0; nMediaIndex < nTotalMediaNum; nMediaIndex++) {
1117                         MSG_DEBUG("Calling _MsgMmsGetMedia");
1118                         pstMedia = _MsgMmsGetMedia(pstPage, nMediaIndex);
1119                         if (NULL == pstMedia) {
1120                                 MSG_DEBUG("pMedia is NULL");
1121                                 MmsSmilDestroyDoc(hSmilDoc);
1122                                 return false;
1123                         }
1124                         MSG_DEBUG("Calling MmsSmilAddMedia");
1125                         if (false == MmsSmilAddMedia(hSmilDoc, nIndex, nMediaIndex, pstMedia, pstMedia->szContentID)) {
1126                                 MSG_DEBUG("MmsSmilAddMedia failed");
1127                                 MmsSmilDestroyDoc(hSmilDoc);
1128                                 return false;
1129                         }
1130                 }
1131         }
1132         MSG_DEBUG("MMSGenerateSmilBuffer: Start update template");
1133         pszRawData = MmsSmilGetRawData(hSmilDoc);
1134         if (NULL == pszRawData) {
1135                 MSG_DEBUG("MMSGenerateSmilBuffer: MmsSmilGetRawData failed");
1136                 MmsSmilDestroyDoc(hSmilDoc);
1137                 return false;
1138         }
1139
1140         char fullpath[MSG_FILEPATH_LEN_MAX] = {0,};
1141         snprintf(fullpath, MSG_FILEPATH_LEN_MAX, MSG_SMIL_FILE_PATH"%s", pstMsgBody->szSmilFilePath);
1142
1143         if (MsgWriteSmilFile(fullpath, pszRawData, strlen(pszRawData) + 1) == false) {
1144                 MSG_DEBUG("MMSGenerateSmilBuffer: MsgWriteSmilFile failed");
1145                 xmlFree((xmlChar*)pszRawData);
1146                 MmsSmilDestroyDoc(hSmilDoc);
1147                 return false;
1148         }
1149
1150         MSG_DEBUG("MMSGenerateSmilBuffer: complete update template\n");
1151         xmlFree((xmlChar*)pszRawData);
1152         MmsSmilDestroyDoc(hSmilDoc);
1153         MSG_END();
1154         return true;
1155 }
1156
1157 /**     @fn             static HMmsSmil MmsSmilCreateEmptySmilDoc(void)
1158  *      @brief  Creates default Smil Doc based on input gszEmptyRawDoc. \n
1159  *      @retval Returns Smil Document number. \n
1160  */
1161 HMmsSmil MmsSmilCreateEmptySmilDoc(void)
1162 {
1163         HMmsSmil hMmsSmil;
1164
1165         MSG_BEGIN();
1166
1167         hMmsSmil = MmsSmilCreateSmilDoc(gszEmptyRawDoc);
1168
1169         MSG_DEBUG("Create an empty smilDoc.(Handle = %d)", hMmsSmil);
1170
1171         MSG_END();
1172
1173         return hMmsSmil;
1174 }
1175
1176 /**     @fn                     static HMmsSmil MmsSmilCreateSmilDoc(char *pszRawData)
1177  *      @brief          Creates Smil Doc based on input pszRawData. \n
1178  *      @param[in]      pszRawData is smil buffer. \n
1179  *      @retval         Returns Smil Document number. \n
1180  */
1181 HMmsSmil MmsSmilCreateSmilDoc(char *pszRawData)
1182 {
1183         int nSmilDocNo = 0;
1184         xmlNodePtr stRootNode;
1185
1186         MSG_BEGIN();
1187
1188         // Destroy smil doc if present
1189         if (NULL != __gpaMmsSmilDoc[nSmilDocNo]) {
1190                 MSG_DEBUG("Calling MmsSmilDestroyDoc");
1191                 if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
1192                         MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
1193                 }
1194         }
1195
1196         for (nSmilDocNo = 0; nSmilDocNo < MMS_SMIL_MAX_DOC; nSmilDocNo++) {
1197                 if (NULL == __gpaMmsSmilDoc[nSmilDocNo])
1198                         break;
1199         }
1200
1201         if (MMS_SMIL_MAX_DOC == nSmilDocNo) {
1202                 MSG_DEBUG("SmilDoc table is full. Can't create.");
1203                 return INVALID_HOBJ;
1204         }
1205         __gpaMmsSmilDoc[nSmilDocNo] = (MmsSmilDoc*)malloc(sizeof(MmsSmilDoc));
1206         if (NULL ==  __gpaMmsSmilDoc[nSmilDocNo]) {
1207                 MSG_DEBUG("Memory Allocation Failed.");
1208                 return INVALID_HOBJ;
1209         }
1210         memset(__gpaMmsSmilDoc[nSmilDocNo], 0, sizeof(MmsSmilDoc));
1211
1212         __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc = xmlParseMemory(pszRawData, strlen(pszRawData));
1213         if (NULL == __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc) {
1214                 MSG_DEBUG("Document not parsed successfully.");
1215                 if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
1216                         MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
1217                 }
1218                 return INVALID_HOBJ;
1219         }
1220         stRootNode = xmlDocGetRootElement(__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc);
1221         if (NULL == stRootNode) {
1222                 MSG_DEBUG("Empty document\n");
1223                 if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
1224                         MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
1225                 }
1226                 return INVALID_HOBJ;
1227         }
1228         if (xmlStrcmp(stRootNode->name, (const xmlChar *) "smil")) {
1229                 MSG_DEBUG("Document of the wrong type, root node != smil");
1230                 if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
1231                         MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
1232                 }
1233                 return INVALID_HOBJ;
1234         }
1235
1236         __gpaMmsSmilDoc[nSmilDocNo]->pstRootNode = stRootNode;
1237
1238         MSG_END();
1239         return ((HMmsSmil)nSmilDocNo);
1240 }
1241
1242 /**     @fn                     static bool MmsSmilDestroyDoc(HMmsSmil hSmilDoc)
1243  *      @brief          Destroys Smil Doc. \n
1244  *      @param[in]      hSmilDoc is smil doc number. \n
1245  *      @retval TRUE                            In case of Success. \n
1246  *      @retval FALSE                           In case of failure. \n
1247  */
1248 bool MmsSmilDestroyDoc(HMmsSmil hSmilDoc)
1249 {
1250         int nSmilDocNo = (int)hSmilDoc;
1251         bool bFlag = true;
1252         MSG_BEGIN();
1253
1254         if (0 <= nSmilDocNo &&
1255                 nSmilDocNo < MMS_SMIL_MAX_DOC &&
1256                 __gpaMmsSmilDoc[nSmilDocNo]) {
1257                 if (__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc) {
1258                         xmlFreeDoc(__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc);
1259                 }
1260
1261                 if (__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode) {
1262                         //Need to Check
1263                 }
1264                 free(__gpaMmsSmilDoc[nSmilDocNo]);
1265                 __gpaMmsSmilDoc[nSmilDocNo] = NULL;
1266         } else {
1267                 MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
1268                 bFlag =  false;
1269         }
1270
1271         MSG_END();
1272         return bFlag;
1273 }
1274
1275 /**     @fn                     static bool IsValidSmilDocNo(int nSmilDocNo)
1276  *      @brief          Form Smil Doc. \n
1277  *      @param[in]      hSmilDoc is smil doc number. \n
1278  *      @retval         Returns Smil Buffer     In case of success. \n
1279  *      @retval         Returns NULL                    In case of failure. \n
1280  */
1281 bool IsValidSmilDocNo(int nSmilDocNo)
1282 {
1283         bool bIsValidSmil = false;
1284
1285         MSG_BEGIN();
1286
1287         if (0 <= nSmilDocNo &&
1288                 nSmilDocNo < MMS_SMIL_MAX_DOC &&
1289                 __gpaMmsSmilDoc[nSmilDocNo] &&
1290                 __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc) {
1291                 bIsValidSmil = true;
1292         }
1293
1294         MSG_END();
1295         return bIsValidSmil;
1296 }
1297
1298 /**     @fn                     static char  MmsSmilGetRawData(HMmsSmil hSmilDoc)
1299  *      @brief          Form Smil Doc. \n
1300  *      @param[in]      hSmilDoc is smil doc number. \n
1301  *      @retval         Returns Smil Buffer     In case of success. \n
1302  *      @retval         Returns NULL                    In case of failure. \n
1303  */
1304 char *MmsSmilGetRawData(HMmsSmil hSmilDoc)
1305 {
1306         int nSmilDocNo = (int)hSmilDoc;
1307         char *pszRawData = NULL;
1308
1309         MSG_BEGIN();
1310
1311         if (IsValidSmilDocNo(nSmilDocNo)) {
1312                 xmlSaveFormatFileEnc("-", __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc, "UTF-8", 1);
1313                 xmlDocDumpMemory(__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc, (xmlChar **)(&pszRawData) , NULL);
1314                 if (NULL == pszRawData) {
1315                         MSG_DEBUG("Invalid pSmilDoc (now wellformed document)");
1316                 }
1317                 MSG_END();
1318         } else {
1319                 MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
1320         }
1321         return pszRawData;
1322 }
1323
1324 /**     @fn                     static bool MmsSmilAddPage(HMmsSmil hSmilDoc, MMS_PAGE_S *pstSmilPage)
1325  *      @brief          Add Page to Smil Doc. \n
1326  *      @param[in]      hSmilDoc is smil doc number. \n
1327  *      @param[in]      pstSmilPage specifies page information. \n
1328  *      @retval         TRUE                            In case of Success. \n
1329  *      @retval         FALSE                           In case of failure. \n
1330  */
1331 bool MmsSmilAddPage(HMmsSmil hSmilDoc, MMS_PAGE_S *pstSmilPage)
1332 {
1333         int nSmilDocNo = hSmilDoc;
1334
1335         MSG_BEGIN();
1336
1337         bool ret = true;
1338
1339         if (IsValidSmilDocNo(nSmilDocNo)) {
1340                 xmlNodePtr pstParElement;
1341                 xmlNodePtr pstBodyElement;
1342                 xmlNodePtr pstParList;
1343                 char szBuf[MSG_STDSTR_SHORT] = {0, };
1344
1345                 pstBodyElement = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"body");
1346
1347                 if (NULL == pstBodyElement) {
1348                         MSG_DEBUG("There is no <body> node. Can't create <par> node.");
1349                         return false;
1350                 }
1351                 MSG_DEBUG("Body Element Name = %s", (char *)pstBodyElement->name);
1352                 /* Create "par"  node and insert it */
1353                 pstParElement = xmlNewNode(NULL, (xmlChar *)"par");
1354
1355                 if (NULL == pstParElement) {
1356                         MSG_DEBUG("Can't create <par> node. (from XmlParser) \n");
1357                         return false;
1358                 }
1359                 MSG_DEBUG("Par Element Name = %s", (char *)pstParElement->name);
1360
1361                 /* Add attributes to "par" */
1362                 if (pstSmilPage->nDur > 0) {
1363                         snprintf(szBuf, MSG_STDSTR_SHORT, "%dms", pstSmilPage->nDur);
1364                         xmlSetProp(pstParElement, (const xmlChar *)"dur", (const xmlChar *)szBuf);
1365                 }
1366                 /* Find the insertion point : right sibling of the last <par> node or first child of <body> */
1367
1368                 pstParList = xmlGetLastChild(pstBodyElement);
1369
1370                 if (pstParList) {
1371                         ret = __MmsSmilInsertNode(pstBodyElement, pstParList, pstParElement);
1372                 } else {
1373                         ret = __MmsInsertFirstChild(pstBodyElement, pstParElement);
1374                 }
1375         } else {
1376                 MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
1377                 return false;
1378         }
1379
1380         return ret;
1381 }
1382
1383 /**     @fn                     static bool MmsSmilAddRootLayout(HMmsSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout)
1384  *      @brief          Add Rootlayout to Smil Doc. \n
1385  *      @param[in]      hSmilDoc is smil doc number. \n
1386  *      @param[in]      pstSmilRootLayout specifies RootLayout information. \n
1387  *      @retval         TRUE                            In case of Success. \n
1388  *      @retval         FALSE                           In case of failure. \n
1389  */
1390 bool MmsSmilAddRootLayout(HMmsSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout)
1391 {
1392         int nSmilDocNo = hSmilDoc;
1393         xmlNodePtr pstRootLayout = NULL;
1394         xmlNodePtr pstLayoutList = NULL;
1395         xmlNodePtr pstRootLayoutList = NULL;
1396         char szBuf[MSG_STDSTR_SHORT] = {0, };
1397
1398         MSG_BEGIN();
1399
1400         if (IsValidSmilDocNo(nSmilDocNo)) {
1401                 pstLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"layout");
1402
1403                 if (NULL == pstLayoutList) {
1404                         MSG_DEBUG("There is no <layout> node. Can't create <root-layout> node.");
1405                         return false;
1406                 }
1407                 MSG_DEBUG("Layout Element Name = %s ", (char *)pstLayoutList->name);
1408
1409                 pstRootLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"root-layout");
1410
1411                 if (NULL != pstRootLayoutList) {
1412                         MSG_DEBUG("MmsSmilAddRootLayout: There is <root-layout> node already");
1413                         MSG_DEBUG("Root Layout Element Name = %s  type=%d\n", (char *)pstRootLayoutList->name);
1414                         return false;
1415                 }
1416                 /* Create "root-layout" node and insert it */
1417                 pstRootLayout = xmlNewNode(NULL, (xmlChar *)"root-layout");
1418                 if (NULL == pstRootLayout) {
1419                         MSG_DEBUG("Can't create <root-layout> node. (from XmlParser)");
1420                         return false;
1421                 }
1422                 MSG_DEBUG("Root Layout Element Name = %s", (char *)pstRootLayout->name);
1423
1424                 if (pstSmilRootLayout->bBgColor == true) {      // Replace value later
1425                         xmlSetProp(pstRootLayout, (const xmlChar *)"backgroundColor", (const xmlChar *)__MmsSmilFindColorValue(pstSmilRootLayout->bgColor));
1426                 }
1427
1428                 MSG_DEBUG(" Set Width");
1429                 if (true == pstSmilRootLayout->width.bUnitPercent) {
1430                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRootLayout->width.value);
1431                         xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)szBuf);
1432                 } else {
1433                         if (pstSmilRootLayout->width.value > 0) {
1434                                 snprintf(szBuf, MSG_STDSTR_SHORT, "%d", pstSmilRootLayout->width.value);
1435                                 xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)szBuf);
1436                         } else {
1437                                 xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)"100%");
1438                         }
1439                 }
1440                 MSG_DEBUG(" Set Height");
1441                 if (true == pstSmilRootLayout->height.bUnitPercent) {
1442                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRootLayout->height.value);
1443                         xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)szBuf);
1444                 } else {
1445                         if (pstSmilRootLayout->height.value > 0) {
1446                                 snprintf(szBuf, MSG_STDSTR_SHORT, "%d", pstSmilRootLayout->height.value);
1447                                 xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)szBuf);
1448                         } else {
1449                                 xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)"100%");
1450                         }
1451                 }
1452                 __MmsInsertFirstChild(pstLayoutList, pstRootLayout);
1453
1454                 return true;
1455         } else {
1456                 MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
1457                 return false;
1458         }
1459
1460 }
1461
1462
1463 /**     @fn                     static bool MmsSmilAddRegion(HMmsSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion)
1464  *      @brief          Add Region to Smil Doc. \n
1465  *      @param[in]      hSmilDoc is smil doc number. \n
1466  *      @param[in]      pstSmilRegion specifies Region information. \n
1467  *      @retval         TRUE                            In case of Success. \n
1468  *      @retval         FALSE                           In case of failure. \n
1469  */
1470 bool MmsSmilAddRegion(HMmsSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion)
1471 {
1472         int nSmilDocNo = hSmilDoc;
1473
1474         MSG_BEGIN();
1475
1476         if (IsValidSmilDocNo(nSmilDocNo)) {
1477                 int nRootWidth = 0;
1478                 int nRootHeight = 0;
1479                 xmlNodePtr pstRegion;
1480                 xmlNodePtr pstLayoutList;
1481                 xmlNodePtr pstRootLayoutList;
1482                 xmlAttrPtr pAttribute;
1483                 char szBuf[MSG_STDSTR_SHORT] = {0, };
1484
1485                 pstLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"layout");
1486                 if (NULL == pstLayoutList) {
1487                         MSG_DEBUG(" There is no <layout> node. Can't create <region> node");
1488                         return false;
1489                 }
1490                 MSG_DEBUG("Layout Element Name = %s ", (char *)pstLayoutList->name);
1491
1492                 /* Find the insertion point : right sibling of the last root-layout node or first child of pLayout */
1493                 pstRootLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"root-layout");
1494
1495                 if (NULL == pstRootLayoutList) {
1496                         MSG_DEBUG("There is no <root-layout> node. Can't create <root-layout> node.");
1497                         return false;
1498                 } else {
1499                         MSG_DEBUG("Root Layout Element Name = %s ", (char *)pstRootLayoutList->name);
1500                         pAttribute =  pstRootLayoutList->properties;
1501                 }
1502
1503                 if (NULL == pAttribute) {
1504                         MSG_DEBUG("There is no Attribute in <root-layout> node.");
1505                         return false;
1506                 }
1507
1508                 xmlAttrPtr pstAttr = pAttribute;
1509                 for ( ; pstAttr; pstAttr = pstAttr->next) {
1510                         int     attrType;
1511                         MSG_DEBUG("AttributeType: (%s, %s) ", pstAttr->name, pstAttr->children->content);
1512                         switch (attrType = MmsSmilGetAttrID((char *)pstAttr->name)) {
1513                         case ATTRIBUTE_WIDTH:
1514                                 {
1515                                         int bUnitPercent;
1516
1517                                         if (strchr((char *)pstAttr->children->content, '%'))
1518                                                 bUnitPercent = true;
1519                                         else
1520                                                 bUnitPercent = false;
1521
1522                                         nRootWidth = atoi((char *)pstAttr->children->content);
1523                                 }
1524                                 break;
1525
1526                         case ATTRIBUTE_HEIGHT:
1527                                 {
1528                                         int bUnitPercent;
1529
1530                                         if (strchr((char *)pstAttr->children->content, '%'))
1531                                                 bUnitPercent = true;
1532                                         else
1533                                                 bUnitPercent = false;
1534
1535                                         nRootHeight = atoi((char *)pstAttr->children->content);
1536                                 }
1537                                 break;
1538                         }
1539                 }
1540
1541                 /* Create "region" node and insert it */
1542                 MSG_DEBUG("Create Region Node");
1543                 pstRegion = xmlNewNode(NULL, (xmlChar *)"region");
1544                 if (NULL == pstRegion) {
1545                         MSG_DEBUG("Can't create <region> node. (from XmlParser)");
1546                         return false;
1547                 }
1548                 /* Add attributes */
1549                 if (pstSmilRegion) {
1550                         MSG_DEBUG(" [Set Attribute] : Region Id");
1551                         if (strlen(pstSmilRegion->szID) > 0) {
1552                                 xmlSetProp(pstRegion, (const xmlChar *)"id", (const xmlChar *)pstSmilRegion->szID);
1553                         }
1554
1555                         if (pstSmilRegion->bBgColor == true) {
1556                                 MSG_DEBUG(" [Set Attribute] : BkGrd Color");
1557                                 xmlSetProp(pstRegion, (const xmlChar *)"backgroundColor", (const xmlChar *)__MmsSmilFindColorValue(pstSmilRegion->bgColor));
1558                         }
1559
1560                         MSG_DEBUG(" [Set Attribute] : Width");
1561
1562                         if (true == pstSmilRegion->width.bUnitPercent) {
1563                                 if (pstSmilRegion->width.value > 0) {
1564                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->width.value);
1565                                         xmlSetProp(pstRegion, (const xmlChar *)"width", (const xmlChar *)szBuf);
1566                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->width = %d   \n", pstSmilRegion->width.value);
1567                                 }
1568                         } else {
1569                                 // Note: nRootWidth should be in terms of value(pixel) not unitpercent(%)
1570                                 // Validation should be done before this.
1571                                 if (pstSmilRegion->width.value >= 0 &&
1572                                         pstSmilRegion->width.value <= nRootWidth) {
1573                                         int iWidth = (pstSmilRegion->width.value * 100) / nRootWidth;
1574
1575                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iWidth);
1576                                         xmlSetProp(pstRegion, (const xmlChar *)"width", (const xmlChar *)szBuf);
1577                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->width= %d  iWidth = %d \n", pstSmilRegion->width.value, iWidth);
1578                                 }
1579                         }
1580                         MSG_DEBUG(" [Set Attribute] : Height");
1581                         if (true == pstSmilRegion->height.bUnitPercent) {
1582                                 if (pstSmilRegion->height.value > 0) {
1583                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->height.value);
1584                                         xmlSetProp(pstRegion, (const xmlChar *)"height", (const xmlChar *)szBuf);
1585                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->height = %d   \n", pstSmilRegion->height.value);
1586                                 }
1587                         } else {
1588                                 // Note: nRootHeight should be in terms of value(pixel) not unitpercent(%)
1589                                 // Validation should be done before this.
1590                                 if (pstSmilRegion->height.value >= 0 &&
1591                                         pstSmilRegion->height.value <= nRootHeight) {
1592                                         int iHeight = (pstSmilRegion->height.value * 100) / nRootHeight;
1593
1594                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iHeight);
1595                                         xmlSetProp(pstRegion, (const xmlChar *)"height", (const xmlChar *)szBuf);
1596                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->height = %d  iHeight = %d \n", pstSmilRegion->height.value, iHeight);
1597                                 }
1598                         }
1599                         MSG_DEBUG(" [Set Attribute] : Left");
1600                         if (true == pstSmilRegion->nLeft.bUnitPercent) {
1601                                 if (pstSmilRegion->nLeft.value > 0) {
1602                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->nLeft.value);
1603                                         xmlSetProp(pstRegion, (const xmlChar *)"left", (const xmlChar *)szBuf);
1604                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->left = %d   \n", pstSmilRegion->nLeft.value);
1605                                 }
1606                         } else {
1607                                 // Note: nRootWidth should be in terms of value(pixel) not unitpercent(%)
1608                                 // Validation should be done before this.
1609                                 if (pstSmilRegion->nLeft.value >= 0) {
1610                                         int iLeft = (pstSmilRegion->nLeft.value * 100) / nRootWidth;
1611
1612                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iLeft);
1613                                         xmlSetProp(pstRegion, (const xmlChar *)"left", (const xmlChar *)szBuf);
1614                                         MSG_DEBUG("MmsSmilAddRegion: SmilRegion->iLeft = %d       iLeft = %d \n", pstSmilRegion->nLeft.value, iLeft);
1615                                 }
1616                         }
1617                         MSG_DEBUG(" [Set Attribute] : Top");
1618                         if (true == pstSmilRegion->nTop.bUnitPercent) {
1619                                 if (pstSmilRegion->nTop.value > 0) {
1620                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->nTop.value);
1621                                         xmlSetProp(pstRegion, (const xmlChar *)"top", (const xmlChar *)szBuf);
1622                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->nTop= %d   \n", pstSmilRegion->nTop.value);
1623                                 }
1624                         } else {
1625                                 // Note: nRootHeight should be in terms of value(pixel) not unitpercent(%)
1626                                 // Validation should be done before this.
1627                                 if (pstSmilRegion->nTop.value >= 0) {
1628                                         int iTop = (pstSmilRegion->nTop.value * 100) / nRootHeight;
1629
1630                                         snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iTop);
1631                                         xmlSetProp(pstRegion, (const xmlChar *)"top", (const xmlChar *)szBuf);
1632                                         MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->nTop= %d  iTop = %d \n", pstSmilRegion->nTop.value, iTop);
1633                                 }
1634                         }
1635                         MSG_DEBUG(" [Set Attribute] : Fit");
1636                         //Fit Attribute
1637                         if (MMSUI_IMAGE_REGION_FIT_MEET == pstSmilRegion->fit) {
1638                                 xmlSetProp(pstRegion, (const xmlChar *)"fit", (const xmlChar *)"meet");
1639                         } else if (MMSUI_IMAGE_REGION_FIT_HIDDEN == pstSmilRegion->fit) {
1640                                 xmlSetProp(pstRegion, (const xmlChar *)"fit", (const xmlChar *)"hidden");
1641                         }
1642
1643                         __MmsSmilInsertNode(pstLayoutList, pstRootLayoutList, pstRegion);
1644
1645                 } else
1646                         MSG_DEBUG("There is no attribute in <region> node\n");
1647
1648                 MSG_END();
1649                 return true;
1650         } else {
1651                 MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)\n", nSmilDocNo);
1652                 return false;
1653         }
1654 }
1655
1656 /**     @fn                     static bool MmsSmilAddMedia( HMmsSmil hSmilDoc, int nPageNo, MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
1657  *      @brief          Add Media to Smil Doc. \n
1658  *      @param[in]      hSmilDoc is smil doc number. \n
1659  *      @param[in]      nPageNo specifies page number to which media belongs. \n
1660  *      @param[in]      pstSmilMedia specifies Media information. \n
1661  *      @param[in]      pszContentID specifies Content ID of media. \n
1662  *      @retval         TRUE                            In case of Success. \n
1663  *      @retval         FALSE                           In case of failure. \n
1664  */
1665 bool MmsSmilAddMedia( HMmsSmil hSmilDoc, int nPageNo, int nMediaIdx, MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
1666 {
1667         int nSmilDocNo = hSmilDoc;
1668
1669         MSG_BEGIN();
1670
1671         if (NULL == pszContentID) {
1672                 MSG_DEBUG(" Content Id is NULL");
1673                 return false;
1674         }
1675         memset(pszContentID, 0, MMS_CONTENT_ID_LEN + 1);
1676         if (IsValidSmilDocNo(nSmilDocNo)) {
1677                 int nIndex = 0;
1678                 xmlNode *pstMedia;
1679                 xmlNode *pstLastChild;
1680                 xmlNodePtr pstParList;
1681                 char *pszExt ;
1682
1683                 pstParList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"par");
1684                 if (NULL == pstParList) {
1685                         MSG_DEBUG("There is no <par> node. Can't create <media> node.");
1686                         return false;
1687                 }
1688                 MSG_DEBUG("Par Element Name = %s ", (char *)pstParList->name);
1689                 for (nIndex = 0; (pstParList &&  nIndex < nPageNo); nIndex++) {
1690                         pstParList = pstParList->next;
1691                 }
1692                 if (NULL == pstParList) {
1693                         MSG_DEBUG("There is no such page node. Can't insert <media> node.");
1694                         return false;
1695                 }
1696                 MSG_DEBUG("Par Element Name = %s ", (char *)pstParList->name);
1697                 /* Find insertion point and make a contentID */
1698
1699                 pstLastChild = xmlGetLastChild(pstParList);
1700
1701                 pszExt = strrchr(pstSmilMedia->szFileName, '.');
1702                 if (pszExt && !strrchr(pszExt, '/'))
1703                         snprintf(pszContentID, MSG_MSG_ID_LEN+1, "%lu_%lu%s", (ULONG)nPageNo, (ULONG)nMediaIdx, pszExt);
1704                 else
1705                         snprintf(pszContentID, MSG_MSG_ID_LEN+1, "%lu_%lu", (ULONG)nPageNo, (ULONG)nMediaIdx);
1706
1707                 /* Create <media> node and insert set attribute */
1708                 MSG_DEBUG(" Create Media Node");
1709                 switch (pstSmilMedia->mediatype) {
1710                 case MMS_SMIL_MEDIA_TEXT:
1711                         pstMedia = __MmsCreateTextNode(pstSmilMedia, pszContentID);
1712                         break;
1713                 case MMS_SMIL_MEDIA_AUDIO:
1714                 case MMS_SMIL_MEDIA_VIDEO:
1715                 case MMS_SMIL_MEDIA_IMG:
1716                         pstMedia = __MmsCreateMMNode(pstSmilMedia, pszContentID);
1717                         break;
1718                 default:
1719                         MSG_DEBUG("Invalid media type. Can't insert such-<media> node.");
1720                         return false;
1721                 }
1722
1723                 if (NULL == pstMedia) {
1724                         MSG_DEBUG("Can't create <media> node. (from XmlParser) (media-type:%d)", pstSmilMedia->mediatype);
1725                         return false;
1726                 }
1727
1728                 /* Find the insertion point : the last child of <par> node */
1729                 if (pstLastChild)
1730                         __MmsSmilInsertNode(pstParList, pstLastChild, pstMedia);
1731                 else
1732                         __MmsInsertFirstChild(pstParList, pstMedia);
1733
1734                 MSG_END();
1735                 return true;
1736         } else {
1737                 MSG_DEBUG("MmsSmilAddMedia: Invalid SmilDoc(hSmilDoc:%d)\n", nSmilDocNo);
1738                 return false;
1739         }
1740 }
1741
1742 /**     @fn                     static xmlNode *__MmsCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
1743  *      @brief          Create Text Element. \n
1744  *      @param[in]      pstSmilMedia specifies Media information. \n
1745  *      @param[in]      pszContentID specifies Content ID of media. \n
1746  *      @retval         Text Element node               In case of Success. \n
1747  *      @retval         NULL                            In case of failure. \n
1748  */
1749 xmlNode *__MmsCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
1750 {
1751         xmlNode *pstMedia = NULL;
1752         xmlNode *pstParam = NULL;
1753         char szBuf[MSG_STDSTR_SHORT] = {0, };
1754         char szSizeBuf[MSG_STDSTR_SHORT] = {0, };
1755
1756         MSG_BEGIN();
1757
1758         pstMedia = xmlNewNode(NULL, (xmlChar *)"text");
1759         if (NULL == pstMedia) {
1760                 MSG_DEBUG("Can't create <Text> node.");
1761                 return NULL;
1762         }
1763         MSG_DEBUG("Text Element Name = %s ", (char *)pstMedia->name);
1764
1765         /* Add attributes */
1766         if (pstSmilMedia) {
1767                 MSG_DEBUG("[Set Attribute] Region Id ");
1768                 if (strlen(pstSmilMedia->regionId) > 0) {
1769                         xmlSetProp(pstMedia, (const xmlChar *)"region", (const xmlChar *)pstSmilMedia->regionId);
1770                 }
1771                 MSG_DEBUG("[Set Attribute] Begin ");
1772                 if (pstSmilMedia->sMedia.sText.nBegin > 0) {
1773                         snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sText.nBegin);
1774                         xmlSetProp(pstMedia, (const xmlChar *)"begin", (const xmlChar *) szBuf);
1775                 }
1776                 MSG_DEBUG("[Set Attribute] Duration");
1777                 if (pstSmilMedia->sMedia.sText.nDurTime > 0) {
1778                         snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sText.nDurTime);
1779                         xmlSetProp(pstMedia, (const xmlChar *)"dur", (const xmlChar *)szBuf);
1780                 }
1781                 MSG_DEBUG("[Set Attribute] Alternate");
1782                 if (strlen(pstSmilMedia->szAlt) > 0) {
1783                         snprintf (szBuf, sizeof(szBuf), "%s", pstSmilMedia->szAlt);
1784                         xmlSetProp(pstMedia, (const xmlChar *)"alt", (const xmlChar *)szBuf);
1785                 }
1786                 MSG_DEBUG("[Set Attribute] Src");
1787
1788                 char szFilePathWithCid[MMS_CONTENT_ID_LEN + 5]; // for "cid:"
1789
1790                 snprintf (szFilePathWithCid, sizeof(szFilePathWithCid), "cid:%s", pszContentID);
1791                 _MmsSmilSetAttribute(pstMedia, (char *)"src", szFilePathWithCid);
1792
1793                 MSG_DEBUG("[Set Attribute] Font Foreground Color");
1794
1795                 if (pstSmilMedia->sMedia.sText.nColor!= SP_BLACK) {     // Chnage after getting exact values
1796                         pstParam = xmlNewNode(NULL, (xmlChar *)"param");
1797
1798                         if (NULL == pstParam) {
1799                                 MSG_DEBUG("Cannot create <param> node");
1800                                 return false;
1801                         }
1802                         xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"foreground-color");
1803                         xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)__MmsSmilFindColorValue(pstSmilMedia->sMedia.sText.nColor));
1804                         __MmsInsertFirstChild(pstMedia, pstParam);
1805                 }
1806
1807                 MSG_DEBUG("[Set Attribute] Font Background Color");
1808
1809                 if (pstSmilMedia->sMedia.sText.nBgColor != SP_BLACK) {  // Chnage after getting exact values
1810                         pstParam = xmlNewNode(NULL, (xmlChar *)"param");
1811
1812                         if (NULL == pstParam) {
1813                                 MSG_DEBUG("Cannot create <param> node");
1814                                 return false;
1815                         }
1816                         xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"background-color");
1817                         xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)__MmsSmilFindColorValue(pstSmilMedia->sMedia.sText.nBgColor));
1818                         __MmsInsertFirstChild(pstMedia, pstParam);
1819                 }
1820
1821                 MSG_DEBUG("[Set Attribute] Size");
1822                 if (pstSmilMedia->sMedia.sText.nSize > 0) {
1823                         pstParam = xmlNewNode(NULL, (xmlChar *)"param");
1824                         if (NULL == pstParam) {
1825                                 MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
1826                                 return false;
1827                         }
1828
1829                         if (pstSmilMedia->sMedia.sText.nSize  <= MMS_SMIL_FONT_SIZE_SMALL)
1830                                 strcpy(szSizeBuf, "small");
1831                         else if ((pstSmilMedia->sMedia.sText.nSize  > MMS_SMIL_FONT_SIZE_SMALL) && (pstSmilMedia->sMedia.sText.nSize  < MMS_SMIL_FONT_SIZE_LARGE))
1832                                 strcpy(szSizeBuf, "normal");
1833                         else
1834                                 strcpy(szSizeBuf, "large");
1835
1836                         xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textsize");
1837                         xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
1838                         __MmsInsertFirstChild(pstMedia, pstParam);
1839                 }
1840
1841                 if (pstSmilMedia->sMedia.sText.bBold == true) {
1842                         pstParam = xmlNewNode(NULL, (xmlChar *)"param");
1843                         if (NULL == pstParam) {
1844                                 MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
1845                                 return false;
1846                         }
1847
1848                         strcpy(szSizeBuf, "bold");
1849
1850                         xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
1851                         xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
1852                         __MmsInsertFirstChild(pstMedia, pstParam);
1853                 }
1854
1855                 if (pstSmilMedia->sMedia.sText.bItalic == true) {
1856                         pstParam = xmlNewNode(NULL, (xmlChar *)"param");
1857                         if (NULL == pstParam) {
1858                                 MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
1859                                 return false;
1860                         }
1861
1862                         strcpy(szSizeBuf, "italic");
1863
1864                         xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
1865                         xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
1866                         __MmsInsertFirstChild(pstMedia, pstParam);
1867                 }
1868
1869                 if (pstSmilMedia->sMedia.sText.bUnderLine == true) {
1870                         pstParam = xmlNewNode(NULL, (xmlChar *)"param");
1871                         if (NULL == pstParam) {
1872                                 MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
1873                                 return false;
1874                         }
1875
1876                         strcpy(szSizeBuf, "underline");
1877
1878                         xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
1879                         xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
1880                         __MmsInsertFirstChild(pstMedia, pstParam);
1881                 }
1882         }
1883
1884         MSG_END();
1885         return pstMedia;
1886 }
1887
1888 /**     @fn                     static xmlNode *__MmsCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
1889  *      @brief          Create Image/Audio/Video Element. \n
1890  *      @param[in]      pstSmilMedia specifies Media information. \n
1891  *      @param[in]      pszContentID specifies Content ID of media. \n
1892  *      @retval         Image/Audio/Video Element node  In case of Success. \n
1893  *      @retval         NULL                                                    In case of failure. \n
1894  */
1895 xmlNode *__MmsCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
1896 {
1897         xmlNode *pstMedia = NULL;
1898         char szBuf[MSG_STDSTR_SHORT] = {0, };
1899
1900         MSG_BEGIN();
1901
1902         if (!pstSmilMedia)
1903                 return NULL;
1904
1905         switch (pstSmilMedia->mediatype) {
1906         case MMS_SMIL_MEDIA_AUDIO:
1907                 pstMedia = xmlNewNode(NULL, (xmlChar *)"audio");
1908                 break;
1909
1910         case MMS_SMIL_MEDIA_VIDEO:
1911                 pstMedia = xmlNewNode(NULL, (xmlChar *)"video");
1912                 break;
1913
1914         case MMS_SMIL_MEDIA_IMG:
1915                 pstMedia = xmlNewNode(NULL, (xmlChar *)"img");
1916                 break;
1917         default:
1918                 MSG_DEBUG("Invalid media type. Can't insert such-<media> node.");
1919                 return NULL;
1920         }
1921
1922         if (pstMedia) {
1923                 char szFilePathWithCid[MMS_CONTENT_ID_LEN + 5];         // for "cid:"
1924
1925                 MSG_DEBUG("[Set Attribute] Region Id ");
1926                 if (strlen(pstSmilMedia->regionId) > 0) {
1927                         xmlSetProp(pstMedia, (const xmlChar *)"region", (const xmlChar *)pstSmilMedia->regionId);
1928                 }
1929                 MSG_DEBUG("[Set Attribute] Src ");
1930                 snprintf (szFilePathWithCid, sizeof(szFilePathWithCid), "cid:%s", pszContentID);
1931                 _MmsSmilSetAttribute(pstMedia, (char *)"src", szFilePathWithCid);
1932
1933                 MSG_DEBUG("[Set Attribute] Begin ");
1934                 if (pstSmilMedia->sMedia.sAVI.nBegin > 0) {
1935                         snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sAVI.nBegin);
1936                         xmlSetProp(pstMedia, (const xmlChar *)"begin", (const xmlChar *)szBuf);
1937                 }
1938                 MSG_DEBUG("[Set Attribute] Duration ");
1939                 if (pstSmilMedia->sMedia.sAVI.nDurTime > 0) {
1940                         snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sAVI.nDurTime);
1941                         xmlSetProp(pstMedia, (const xmlChar *)"dur", (const xmlChar *)szBuf);
1942                 }
1943                 MSG_DEBUG("[Set Attribute] Alt ");
1944                 if (strlen(pstSmilMedia->szAlt) > 0) {
1945                         snprintf (szBuf, sizeof(szBuf), "%s", pstSmilMedia->szAlt);
1946                         xmlSetProp(pstMedia, (const xmlChar *)"alt", (const xmlChar *)szBuf);
1947                 }
1948         } else {
1949                 MSG_DEBUG("There is no attribute in such-<media> node");
1950         }
1951
1952         MSG_END();
1953         return pstMedia;
1954 }
1955
1956 /**     @fn                     static bool __MmsInsertFirstChild(xmlNode *pstParent, xmlNode *pstCurr)
1957  *      @brief          Inserts first child to parent node. \n
1958  *      @param[in]      pstParent specifies Parent node. \n
1959  *      @param[in]      pstCurr specifies Child node. \n
1960  *      @retval         TRUE                            In case of Success. \n
1961  *      @retval         FALSE                           In case of failure. \n
1962  */
1963 bool __MmsInsertFirstChild(xmlNode *pstParent, xmlNode *pstCurr)
1964 {
1965         bool bFlag = true;
1966
1967         MSG_BEGIN();
1968
1969          if (NULL == xmlAddChild(pstParent, pstCurr)) {
1970                 MSG_DEBUG("%s Node not added", pstCurr->name);
1971                 bFlag = false;
1972          }
1973
1974          MSG_END();
1975          return bFlag;
1976 }
1977
1978
1979 /**     @fn                     static bool __MmsSmilInsertNode(xmlNode *pstParent, xmlNode *pstLeftSibling, xmlNode *pstCurr)
1980  *      @brief          Inserts node. \n
1981  *      @param[in]      pstParent specifies Parent node. \n
1982  *      @param[in]      pstLeftSibling specifies Left Sibling node. \n
1983  *      @param[in]      pstCurr specifies Child node. \n
1984  *      @retval         TRUE                            In case of Success. \n
1985  *      @retval         FALSE                           In case of failure. \n
1986  */
1987 bool __MmsSmilInsertNode(xmlNode *pstParent, xmlNode *pstLeftSibling, xmlNode *pstCurr)
1988 {
1989         MSG_BEGIN();
1990         bool bFlag = true;
1991
1992         if (pstLeftSibling) {
1993                 /* Parent Node is Unused */
1994
1995                 while (pstLeftSibling->next !=NULL)
1996                         pstLeftSibling = pstLeftSibling->next;
1997
1998                  if (NULL == xmlAddNextSibling(pstLeftSibling, pstCurr)) {
1999                         MSG_DEBUG("%s Node not added", pstCurr->name);
2000                         bFlag = false;
2001                  }
2002         } else {
2003                  if (NULL == xmlAddChild(pstParent, pstCurr)) {
2004                          MSG_DEBUG("%s Node not added", pstCurr->name);
2005                         bFlag = false;
2006                  }
2007         }
2008         MSG_END();
2009         return bFlag;
2010 }
2011
2012
2013 bool __MmsGetRealFileName(MmsSmilMediaType mediaType, char *pszSrc, char *pszName, int msgID)
2014 {
2015         MsgType partHeader;
2016         int partCnt;
2017         int i;
2018
2019         MSG_DEBUG("__MmsUiGetRealFileName: mediaType[%d]", mediaType);
2020         MSG_DEBUG("__MmsUiGetRealFileName: pszSrc[%s]\n", pszSrc);
2021
2022         if (!pszName) {
2023                 MSG_DEBUG("__MmsUiGetRealFileName: pszName is null\n");
2024                 return false;
2025         }
2026
2027         if (mediaType == MMS_SMIL_MEDIA_TEXT || mediaType == MMS_SMIL_MEDIA_INVALID) {
2028                 MSG_DEBUG("__MmsUiGetRealFileName: invalid mediaType(=%d)\n", mediaType);
2029                 return false;
2030         }
2031
2032         partCnt = MmsGetMediaPartCount(msgID);
2033
2034         if (partCnt < 0) {
2035                 MSG_DEBUG("__MmsUiGetRealFileName: partCnt < 0, (=%d)\n", partCnt);
2036                 return false;
2037         }
2038
2039         for (i = 0; i < partCnt; i++) {
2040                 MmsGetMediaPartHeader(i, &partHeader);
2041
2042                 if (mediaType == MMS_SMIL_MEDIA_AUDIO ||
2043                         mediaType == MMS_SMIL_MEDIA_VIDEO ||
2044                         mediaType == MMS_SMIL_MEDIA_IMG) {
2045                         if (!strcmp(partHeader.param.szFileName , pszSrc)) {
2046                                 // Found
2047                                 MSG_DEBUG("__MmsUiGetRealFileName: pszSrc[%s]\n", pszSrc);
2048                                 break;
2049                         }
2050                 }
2051         }
2052
2053         if (i == partCnt)
2054                 return false;
2055
2056         if (partHeader.param.szName[0] != '\0') {
2057                 int nameLen = strlen(partHeader.param.szName);
2058
2059                 if (nameLen > MSG_FILENAME_LEN_MAX - 1) {
2060                         ;//Need to check
2061                 } else {
2062                         strcpy(pszName, partHeader.param.szName);
2063                 }
2064
2065                 return true;
2066         }
2067         return false;
2068 }
2069
2070 /**     @fn                     static void _MmsSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue)
2071  *      @brief          Sets Attribute. \n
2072  *      @param[in]      pNode specifies node. \n
2073  *      @param[in]      szField specifies attribute field. \n
2074  *      @param[in]      szValue specifies value of field \n
2075  */
2076 void _MmsSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue)
2077 {
2078         MSG_BEGIN();
2079
2080         if (pNode && szField && strlen(szField)) {
2081                 if (szValue && strlen(szValue)) {
2082                         xmlSetProp(pNode, (const xmlChar *)szField, (const xmlChar *)szValue);
2083                 } else {
2084                         xmlSetProp(pNode, (const xmlChar *)szField, (const xmlChar *)"");
2085                 }
2086         }
2087
2088         MSG_END();
2089 }
2090
2091 /**     @fn                     static char *__MmsSmilFindColorValue(int nValue)
2092  *      @brief          Converts color to RGB. \n
2093  *      @param[in]      nValue specifies color value. \n
2094  *      @retval         RGB value. \n
2095  */
2096 char *__MmsSmilFindColorValue(int nValue)
2097 {
2098         unsigned char red = (nValue & 0xFF0000) >> 16;
2099         unsigned char green = (nValue & 0x00FF00) >> 8;
2100         unsigned char blue = nValue & 0x0000FF;
2101
2102         MSG_BEGIN();
2103
2104         snprintf(gszColor,MMS_SMIL_COLOR_SIZE, "#%02x%02x%02x", red, green, blue);
2105         MSG_DEBUG("__MmsSmilFindColorValue: gszColor %s \n", gszColor);
2106
2107         MSG_END();
2108         return gszColor;
2109 }
2110
2111 /**     @fn                     static xmlNodePtr UtilxmlStringGetNodeList(xmlNodePtr pstNode, char *pszValue)
2112  *      @brief          Get node based on pszValue. \n
2113  *      @param[in]      pNode specifies node. \n
2114  *      @param[in]      pszName specifies name field. \n
2115  *      @retval         RGB value. \n
2116  */
2117 xmlNodePtr UtilxmlStringGetNodeList(xmlNodePtr pstNode, char *pszName)
2118 {
2119         MSG_BEGIN();
2120
2121         if ((NULL != pstNode) && (NULL != pszName)) {
2122                 xmlNodePtr pstTempNode;
2123                 xmlNodePtr pstReturnNode;
2124
2125                 pstTempNode = pstNode;
2126
2127                 for ( ; pstTempNode; pstTempNode = pstTempNode->next) {
2128                         MSG_DEBUG("\n Node Name = %s[%p] children =%p \n", (char *)pstTempNode->name, pstTempNode, pstTempNode->children);
2129                         MSG_DEBUG("\n Compare Parent Node = %s[%p] \n", (char *)pstTempNode->name, pstTempNode);
2130                         if (0 == strcasecmp((char *)pstTempNode->name, pszName)) {
2131                                 return pstTempNode;
2132                         }
2133
2134                         if (pstTempNode->children) {
2135                                 MSG_DEBUG("\n Enter Inside\n");
2136                                 pstReturnNode = UtilxmlStringGetNodeList(pstTempNode->children, pszName);
2137                                 if (NULL != pstReturnNode) {
2138                                         return pstReturnNode;
2139                                 }
2140                         }
2141
2142                 }
2143         }
2144         return NULL;
2145 }
2146
2147 void MmsSmilGetElementOnlyLayout(MMS_MESSAGE_DATA_S *pMmsMsg, xmlNode *a_node)
2148 {
2149         MSG_BEGIN();
2150
2151         int elementType;
2152         int attrType;
2153         MMS_SMIL_ROOTLAYOUT rootlayout = {};
2154         static bool cmd[ELEMENT_MAX] = {false, };
2155         static MMS_SMIL_REGION *pRegion;
2156         static MMS_PAGE_S *pPage;
2157         static MMS_MEDIA_S *pMedia;
2158         static MMS_SMIL_TRANSITION *pTransition;
2159         static MMS_SMIL_META *pMeta;
2160
2161         xmlNode *cur_node = NULL;
2162
2163         for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
2164                 MSG_DEBUG("******* node, name: %s ***\n", cur_node->name);
2165
2166                 if (cur_node->type == XML_ELEMENT_NODE) {
2167                         // Get Smil Element =====================================================
2168                         MSG_DEBUG("*** node type: Element, name: %s ***\n", cur_node->name);
2169
2170                         switch (elementType = MmsSmilGetElementID((char *)cur_node->name)) {
2171                         case ELEMENT_ROOTLAYOUT:
2172                                 memset(cmd, 0, ELEMENT_MAX);
2173                                 cmd[ELEMENT_ROOTLAYOUT] = true;
2174                                 break;
2175
2176                         case ELEMENT_REGION:
2177                                 pRegion = (MMS_SMIL_REGION *)calloc(1, sizeof(MMS_SMIL_REGION));
2178                                 memset(cmd, 0, ELEMENT_MAX);
2179                                 cmd[ELEMENT_REGION] = true;
2180                                 break;
2181
2182                         case ELEMENT_TRANSITION:
2183                                 pTransition = (MMS_SMIL_TRANSITION *)calloc(1, sizeof(MMS_SMIL_TRANSITION));
2184                                 memset(cmd, 0, ELEMENT_MAX);
2185                                 cmd[ELEMENT_TRANSITION] = true;
2186                                 break;
2187
2188                         case ELEMENT_META:
2189                                 pMeta = (MMS_SMIL_META *)calloc(1, sizeof(MMS_SMIL_META));
2190                                 memset(cmd, 0, ELEMENT_MAX);
2191                                 cmd[ELEMENT_META] = true;
2192                                 break;
2193
2194                         case ELEMENT_PAR:
2195                                 pPage = (MMS_PAGE_S *)calloc(1, sizeof(MMS_PAGE_S));
2196                                 memset(cmd, 0, ELEMENT_MAX);
2197                                 cmd[ELEMENT_PAR] = true;
2198                                 break;
2199
2200                         case ELEMENT_PARAM: // Need to check the original element type
2201                                 break;
2202
2203                         case ELEMENT_TEXT:
2204                                 pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
2205                                 pMedia->mediatype = MMS_SMIL_MEDIA_TEXT;
2206                                 memset(cmd, 0, ELEMENT_MAX);
2207                                 cmd[ELEMENT_TEXT] = true;
2208                                 break;
2209
2210                         case ELEMENT_IMG:
2211                                 pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
2212                                 pMedia->mediatype = MMS_SMIL_MEDIA_IMG;
2213                                 memset(cmd, 0, ELEMENT_MAX);
2214                                 cmd[ELEMENT_IMG] = true;
2215                                 break;
2216
2217                         case ELEMENT_AUDIO:
2218                                 pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
2219                                 pMedia->mediatype = MMS_SMIL_MEDIA_AUDIO;
2220                                 memset(cmd, 0, ELEMENT_MAX);
2221                                 cmd[ELEMENT_AUDIO] = true;
2222                                 break;
2223
2224                         case ELEMENT_VIDEO:
2225                                 pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
2226                                 pMedia->mediatype = MMS_SMIL_MEDIA_VIDEO;
2227                                 memset(cmd, 0, ELEMENT_MAX);
2228                                 cmd[ELEMENT_VIDEO] = true;
2229                                 break;
2230
2231                         case ELEMENT_REF:
2232                                 pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
2233                                 pMedia->mediatype = MMS_SMIL_MEDIA_IMG_OR_VIDEO;
2234                                 memset(cmd, 0, ELEMENT_MAX);
2235                                 cmd[ELEMENT_REF] = true;
2236                                 break;
2237
2238                         case ELEMENT_ANIMATE:
2239                                 pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
2240                                 pMedia->mediatype = MMS_SMIL_MEDIA_ANIMATE;
2241                                 memset(cmd, 0, ELEMENT_MAX);
2242                                 cmd[ELEMENT_ANIMATE] = true;
2243                                 break;
2244
2245                         default:
2246                                 memset(cmd, 0, ELEMENT_MAX);
2247                                 break;
2248                         }
2249
2250                         //Get Smil Attribute =====================================================
2251                         xmlAttr *pAttr = cur_node->properties;
2252                         SMIL_ATTRIBUTE_T paramType = ATTRIBUTE_UNKNOWN;
2253
2254                         for ( ; pAttr; pAttr = pAttr->next) {
2255                                 MSG_DEBUG("AttributeType: (%s, %s) ", pAttr->name, pAttr->children->content);
2256                                 switch (attrType = MmsSmilGetAttrID((char *)pAttr->name)) {
2257                                 case ATTRIBUTE_ID:
2258                                         {
2259                                                 if (cmd[ELEMENT_REGION]) {
2260                                                         strncpy(pRegion->szID, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
2261                                                 } else if (cmd[ELEMENT_TRANSITION]) {
2262                                                         strncpy(pTransition->szID, (char *)pAttr->children->content, MAX_SMIL_TRANSITION_ID - 1);
2263                                                 } else if (cmd[ELEMENT_META]) {
2264                                                         strncpy(pMeta->szID, (char *)pAttr->children->content, MAX_SMIL_META_ID - 1);
2265                                                 }
2266                                         }
2267                                         break;
2268
2269                                 case ATTRIBUTE_TOP:
2270                                         {
2271                                                 int bUnitPercent;
2272                                                 int value;
2273
2274                                                 if (strchr((char *)pAttr->children->content, '%'))
2275                                                         bUnitPercent = true;
2276                                                 else
2277                                                         bUnitPercent = false;
2278
2279                                                 value = atoi((char *)pAttr->children->content);
2280
2281                                                 if (cmd[ELEMENT_REGION]) {
2282                                                         pRegion->nTop.bUnitPercent = bUnitPercent;
2283                                                         pRegion->nTop.value = value;
2284                                                 }
2285                                         }
2286                                         break;
2287
2288                                 case ATTRIBUTE_LEFT:
2289                                         {
2290                                                 int bUnitPercent;
2291                                                 int value;
2292
2293                                                 if (strchr((char *)pAttr->children->content, '%'))
2294                                                         bUnitPercent = true;
2295                                                 else
2296                                                         bUnitPercent = false;
2297
2298                                                 value = atoi((char *)pAttr->children->content);
2299
2300                                                 if (cmd[ELEMENT_REGION]) {
2301                                                         pRegion->nLeft.bUnitPercent = bUnitPercent;
2302                                                         pRegion->nLeft.value = value;
2303                                                 }
2304                                         }
2305                                         break;
2306
2307
2308                                 case ATTRIBUTE_WIDTH:
2309                                         {
2310                                                 int bUnitPercent;
2311                                                 int value;
2312
2313                                                 if (strchr((char *)pAttr->children->content, '%'))
2314                                                         bUnitPercent = true;
2315                                                 else
2316                                                         bUnitPercent = false;
2317
2318                                                 value = atoi((char *)pAttr->children->content);
2319
2320                                                 if (cmd[ELEMENT_ROOTLAYOUT]) {
2321                                                         rootlayout.width.bUnitPercent = bUnitPercent;
2322                                                         rootlayout.width.value = value;
2323                                                 } else if (cmd[ELEMENT_REGION]) {
2324                                                         pRegion->width.bUnitPercent = bUnitPercent;
2325                                                         pRegion->width.value = value;
2326                                                 }
2327                                         }
2328                                         break;
2329
2330                                 case ATTRIBUTE_HEIGHT:
2331                                         {
2332                                                 int bUnitPercent;
2333                                                 int value;
2334
2335                                                 if (strchr((char *)pAttr->children->content, '%'))
2336                                                         bUnitPercent = true;
2337                                                 else
2338                                                         bUnitPercent = false;
2339
2340                                                 value = atoi((char *)pAttr->children->content);
2341
2342                                                 if (cmd[ELEMENT_ROOTLAYOUT]) {
2343                                                         rootlayout.height.bUnitPercent = bUnitPercent;
2344                                                         rootlayout.height.value = value;
2345                                                 } else if (cmd[ELEMENT_REGION]) {
2346                                                         pRegion->height.bUnitPercent = bUnitPercent;
2347                                                         pRegion->height.value = value;
2348                                                 }
2349                                         }
2350                                         break;
2351
2352                                 case ATTRIBUTE_FIT:
2353                                         if (cmd[ELEMENT_REGION]) {
2354                                                 if (!strcmp((char *)pAttr->children->content, "meet")) {
2355                                                         pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
2356                                                 } else {
2357                                                         pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
2358                                                 }
2359                                         }
2360                                         break;
2361
2362                                 case ATTRIBUTE_BGCOLOR:
2363                                         if (cmd[ELEMENT_ROOTLAYOUT]) {
2364                                                 rootlayout.bBgColor = true;
2365                                                 rootlayout.bgColor = MmsSmilGetColorValue(pAttr->children->content);
2366                                         } else if (cmd[ELEMENT_REGION]) {
2367                                                 pRegion->bBgColor = true;
2368                                                 pRegion->bgColor = MmsSmilGetColorValue(pAttr->children->content);
2369                                         } else if (cmd[ELEMENT_TEXT])
2370                                                 pMedia->sMedia.sText.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
2371                                         else
2372                                                 pMedia->sMedia.sAVI.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
2373
2374                                         break;
2375
2376                                 case ATTRIBUTE_DUR:
2377                                         if (cmd[ELEMENT_PAR])
2378                                                 pPage->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
2379                                         else if (cmd[ELEMENT_TRANSITION])
2380                                                 pTransition->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
2381                                         else if (cmd[ELEMENT_TEXT])
2382                                                 pMedia->sMedia.sText.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
2383                                         else
2384                                                 pMedia->sMedia.sAVI.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
2385
2386 #ifdef MMS_SMIL_ANIMATE
2387                                         if (cmd[ELEMENT_ANIMATE])
2388                                                 pMedia->sMedia.sAVI.nDur = MmsSmilGetTime((char *)pAttr->children->content);
2389 #endif
2390                                         break;
2391
2392                                 case ATTRIBUTE_SRC:
2393                                 {
2394                                         char *szSrc;
2395                                         char szContentID[MSG_MSG_ID_LEN + 1] = {0,};
2396                                         int cLen;
2397
2398                                         szSrc = MsgChangeHexString((char *)pAttr->children->content);
2399                                         if (szSrc == NULL)
2400                                                 break;
2401
2402                                         snprintf(szContentID, sizeof(szContentID), "%s", szSrc);
2403                                         free(szSrc);
2404
2405                                         cLen = strlen(szContentID);
2406                                         if (!strncasecmp(szContentID, "cid:", 4)) {
2407                                                 strncpy(pMedia->szContentID, szContentID + 4, cLen - 4);
2408                                                 pMedia->szContentID[cLen - 4] = '\0';
2409                                         } else {
2410                                                 strncpy(pMedia->szContentID, szContentID, cLen);
2411                                                 pMedia->szContentID[cLen] = '\0';
2412                                         }
2413                                         break;
2414                                 }
2415                                 case ATTRIBUTE_COLOR:
2416                                         if (cmd[ELEMENT_TEXT])
2417                                                 pMedia->sMedia.sText.nColor = MmsSmilGetColorValue(pAttr->children->content);
2418                                         break;
2419
2420                                 case ATTRIBUTE_SIZE:
2421                                         if (cmd[ELEMENT_TEXT])
2422                                                 pMedia->sMedia.sText.nSize = atoi((char *)pAttr->children->content);
2423                                         break;
2424
2425                                 case ATTRIBUTE_BOLD:
2426                                         if (cmd[ELEMENT_TEXT]) {
2427                                                 pMedia->sMedia.sText.bBold = MmsSmilGetFontAttrib((char *)pAttr->children->content);
2428                                         }
2429                                         break;
2430
2431                                 case ATTRIBUTE_UNDERLINE:
2432                                         if (cmd[ELEMENT_TEXT])
2433                                                 pMedia->sMedia.sText.bUnderLine = MmsSmilGetFontAttrib((char *)pAttr->children->content);
2434                                         break;
2435
2436                                 case ATTRIBUTE_ITALIC:
2437                                         if (cmd[ELEMENT_TEXT])
2438                                                 pMedia->sMedia.sText.bItalic = MmsSmilGetFontAttrib((char *)pAttr->children->content);
2439                                         break;
2440
2441                                 case ATTRIBUTE_REVERSE:
2442                                         if (cmd[ELEMENT_TEXT])
2443                                                 pMedia->sMedia.sText.bReverse = MmsSmilGetFontAttrib((char *)pAttr->children->content);
2444                                         break;
2445
2446                                 case ATTRIBUTE_DIRECTION:
2447                                         if (cmd[ELEMENT_TEXT])
2448                                                 pMedia->sMedia.sText.nDirection = MmsSmilGetFontDirection((char *)pAttr->children->content);
2449                                         break;
2450                                 case ATTRIBUTE_REGION:
2451                                         strncpy(pMedia->regionId, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
2452                                         break;
2453
2454                                 case ATTRIBUTE_TRANSIN:
2455                                         if (cmd[ELEMENT_TEXT])
2456                                                 strncpy(pMedia->sMedia.sText.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
2457                                         else
2458                                                 strncpy(pMedia->sMedia.sAVI.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
2459                                         break;
2460
2461                                 case ATTRIBUTE_TRANSOUT:
2462                                         if (cmd[ELEMENT_TEXT])
2463                                                 strncpy(pMedia->sMedia.sText.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
2464                                         else
2465                                                 strncpy(pMedia->sMedia.sAVI.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
2466                                         break;
2467
2468                                 case ATTRIBUTE_BEGIN:
2469                                         if (cmd[ELEMENT_TEXT])
2470                                                 pMedia->sMedia.sText.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
2471                                         else
2472                                                 pMedia->sMedia.sAVI.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
2473                                         break;
2474
2475                                 case ATTRIBUTE_END:
2476                                         if (cmd[ELEMENT_TEXT])
2477                                                 pMedia->sMedia.sText.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
2478                                         else
2479                                                 pMedia->sMedia.sAVI.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
2480                                         break;
2481
2482                                 case ATTRIBUTE_REPEAT_COUNT:
2483                                         if (cmd[ELEMENT_TEXT])
2484                                                 pMedia->sMedia.sText.nRepeat = atoi((char *)pAttr->children->content);
2485                                         else
2486                                                 pMedia->sMedia.sAVI.nRepeat = atoi((char *)pAttr->children->content);
2487                                         break;
2488
2489                                 case ATTRIBUTE_NAME:
2490                                         if (!strcmp((char *)pAttr->children->content, "foreground-color") || !strcmp((char *)pAttr->children->content, "foregroundcolor"))
2491                                                 paramType = ATTRIBUTE_FGCOLOR;
2492                                         else if (!strcmp((char *)pAttr->children->content, "background-color") || !strcmp((char *)pAttr->children->content, "backgroundcolor"))
2493                                                 paramType = ATTRIBUTE_BGCOLOR;
2494                                         else if (!strcmp((char *)pAttr->children->content, "textsize"))
2495                                                 paramType = ATTRIBUTE_SIZE;
2496                                         else if (!strcmp((char *)pAttr->children->content, "textattribute"))
2497                                                 paramType = ATTRIBUTE_TEXTFORMAT;
2498
2499                                         if (cmd[ELEMENT_META])
2500                                                 strncpy(pMeta->szName, (char *)pAttr->children->content, MAX_SMIL_META_NAME - 1);
2501                                         break;
2502
2503                                 case ATTRIBUTE_VALUE:
2504                                         if (paramType == ATTRIBUTE_SIZE && cmd[ELEMENT_TEXT])
2505                                                 pMedia->sMedia.sText.nSize = MmsSmilGetFontSizeValue((char *)pAttr->children->content);
2506                                         else if (paramType == ATTRIBUTE_FGCOLOR && cmd[ELEMENT_TEXT])
2507                                                 pMedia->sMedia.sText.nColor =  MmsSmilGetColorValue(pAttr->children->content);
2508                                         else if (paramType == ATTRIBUTE_BGCOLOR && cmd[ELEMENT_TEXT])
2509                                                 pMedia->sMedia.sText.nBgColor =  MmsSmilGetColorValue(pAttr->children->content);
2510                                         else if (paramType == ATTRIBUTE_TEXTFORMAT && cmd[ELEMENT_TEXT]) {
2511                                                 MmsSmilFontType fontType;
2512
2513                                                 fontType = MmsSmilGetFontTypeValue((char *)pAttr->children->content);
2514
2515                                                 if (fontType == MMS_SMIL_FONT_TYPE_BOLD)
2516                                                         pMedia->sMedia.sText.bBold = true;
2517                                                 else
2518                                                         pMedia->sMedia.sText.bBold = false;
2519
2520                                                 if (fontType == MMS_SMIL_FONT_TYPE_ITALIC)
2521                                                         pMedia->sMedia.sText.bItalic = true;
2522                                                 else
2523                                                         pMedia->sMedia.sText.bItalic = false;
2524
2525                                                 if (fontType == MMS_SMIL_FONT_TYPE_UNDERLINE)
2526                                                         pMedia->sMedia.sText.bUnderLine = true;
2527                                                 else
2528                                                         pMedia->sMedia.sText.bUnderLine = false;
2529                                         }
2530                                         break;
2531
2532                                 case ATTRIBUTE_ALT:
2533                                         strncpy(pMedia->szAlt, (char *)pAttr->children->content, MAX_SMIL_ALT_LEN - 1);
2534                                         break;
2535
2536                                 case ATTRIBUTE_TYPE:
2537                                         pTransition->nType = (MmsSmilTransType)atoi((char *)pAttr->children->content);
2538
2539                                         switch (pTransition->nType) {
2540                                         case MMS_SMIL_TRANS_SLIDEWIPE:
2541                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_FROM_LEFT;
2542                                                 break;
2543                                         case MMS_SMIL_TRANS_BARWIPE:
2544                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_TOP_TO_BOTTOM;
2545                                                 break;
2546                                         case MMS_SMIL_TRANS_BARNDOORWIPE:
2547                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_HORIZONTAL;
2548                                                 break;
2549                                         default:
2550                                                 pTransition->nSubType = MMS_SMIL_TRANS_SUB_NONE;
2551                                                 break;
2552                                         }
2553
2554                                         break;
2555
2556                                 case ATTRIBUTE_SUBTYPE:
2557                                         pTransition->nSubType = (MmsSmilTransSubType)atoi((char *)pAttr->children->content);
2558                                         break;
2559
2560                                 case ATTRIBUTE_CONTENT:
2561                                         strncpy(pMeta->szContent, (char *)pAttr->children->content, MAX_SMIL_META_CONTENT - 1);
2562                                         break;
2563 #ifdef MMS_SMIL_ANIMATE
2564                                 case ATTRIBUTE_ATTRIBUTE_NAME:
2565                                         strcpy(pMedia->sMedia.sAVI.nAttributeName, (char *)pAttr->children->content);
2566                                         break;
2567
2568                                 case ATTRIBUTE_ATTRIBUTE_TYPE:
2569                                         strcpy(pMedia->sMedia.sAVI.nAttributeType, (char *)pAttr->children->content);
2570                                         break;
2571
2572                                 case ATTRIBUTE_TARGET_ELEMENT:
2573                                         strcpy(pMedia->sMedia.sAVI.nTargetElement, (char *)pAttr->children->content);
2574                                         break;
2575
2576                                 case ATTRIBUTE_FROM:
2577                                         pMedia->sMedia.sAVI.nFrom = atoi((char *)pAttr->children->content);
2578                                         break;
2579
2580                                 case ATTRIBUTE_TO:
2581                                         pMedia->sMedia.sAVI.nTo = atoi((char *)pAttr->children->content);
2582                                         break;
2583
2584                                 case ATTRIBUTE_BY:
2585                                         pMedia->sMedia.sAVI.nBy = atoi((char *)pAttr->children->content);
2586                                         break;
2587
2588                                 case ATTRIBUTE_VALUES:
2589                                         pMedia->sMedia.sAVI.nValues = atoi((char *)pAttr->children->content);
2590                                         break;
2591
2592                                 case ATTRIBUTE_CALCMODE:
2593                                         strcpy(pMedia->sMedia.sAVI.nCalcMode, (char *)pAttr->children->content);
2594                                         break;
2595 #endif
2596                                 default:
2597                                         MSG_DEBUG("Undefined Attribute was found!!!!!");
2598                                 }
2599                         }
2600
2601                         if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_REGION]) {
2602                                 // Insert a region to region list
2603                                 _MsgMmsAddRegion(pMmsMsg, pRegion);
2604                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_PAR]) {
2605                                 //Insert a page to page list
2606                                 _MsgMmsAddPage(pMmsMsg, pPage);
2607                         } else if (paramType == ATTRIBUTE_UNKNOWN && (cmd[ELEMENT_TEXT] ||cmd[ELEMENT_IMG] ||cmd[ELEMENT_AUDIO] ||cmd[ELEMENT_VIDEO] ||cmd[ELEMENT_ANIMATE] || cmd[ELEMENT_REF])) {
2608                                 //Insert a media to media list
2609                                 _MsgMmsAddMedia(pPage, pMedia);
2610                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_ROOTLAYOUT]) {
2611                                 _MsgMmsSetRootLayout(pMmsMsg, &rootlayout);
2612                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_TRANSITION]) {
2613                                 //Insert a transition to transition list
2614                                 _MsgMmsAddTransition(pMmsMsg, pTransition);
2615                         } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_META]) {
2616                                 //Insert a meta to meta list
2617                                 _MsgMmsAddMeta(pMmsMsg, pMeta);
2618                         }
2619
2620                         paramType = ATTRIBUTE_UNKNOWN;
2621                 }
2622
2623                 MmsSmilGetElementOnlyLayout(pMmsMsg, cur_node->children);
2624         }
2625
2626         MSG_END();
2627 }
2628
2629 bool MmsSmilParseSmilDocOnlyLayout(MMS_MESSAGE_DATA_S *pMmsMsg, char *pSmilDoc)
2630 {
2631         xmlDocPtr doc;
2632         xmlNodePtr cur;
2633         MSG_DEBUG("%s", pSmilDoc);
2634         doc = xmlParseMemory(pSmilDoc, strlen(pSmilDoc));
2635
2636         if (doc == NULL) {
2637                 MSG_DEBUG("Document not parsed successfully. \n");
2638                 return false;
2639         }
2640
2641         cur = xmlDocGetRootElement(doc);
2642
2643         if (cur == NULL) {
2644                 MSG_DEBUG("empty document\n");
2645                 xmlFreeDoc(doc);
2646                 return false;
2647         }
2648
2649         if (xmlStrcmp(cur->name, (const xmlChar *) "smil")) {
2650                 MSG_DEBUG("document of the wrong type, root node != smil");
2651                 xmlFreeDoc(doc);
2652                 return false;
2653         }
2654
2655         MmsSmilGetElementOnlyLayout(pMmsMsg, cur);
2656
2657         xmlFreeDoc(doc);
2658
2659         return true;
2660 }