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