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