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