Fix memory leak
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include <string.h>
26 #include <sys/vfs.h>
27 #include <glib/gstdio.h>
28 #include <sys/stat.h>
29 #include <string.h>
30 #include <dirent.h>
31 #include <ctype.h>
32 #include <aul/aul.h>
33 #include <mm_file.h>
34 #include <mm_error.h>
35 #include <libexif/exif-data.h>
36 #include <media-thumbnail.h>
37 #include <media-util.h>
38 #include <grp.h>
39 #include <pwd.h>
40 #include "uuid.h"
41 #include "media-util-err.h"
42 #include "media-svc-util.h"
43 #include "media-svc-db-utils.h"
44 #include "media-svc-debug.h"
45 #include "media-svc-env.h"
46 #include "media-svc-hash.h"
47 #include "media-svc-album.h"
48 #include "media-svc-localize-utils.h"
49 #include "media-svc-localize_ch.h"
50 #include "media-svc-localize_tw.h"
51
52 #define MEDIA_SVC_FILE_EXT_LEN_MAX                              6                       /**<  Maximum file ext lenth*/
53 #define GLOBAL_USER    0 /*#define     tzplatform_getenv(TZ_GLOBAL) //TODO */
54
55 /* Define data structures for media type and mime type */
56 #define MEDIA_SVC_CATEGORY_UNKNOWN      0x00000000      /**< Default */
57 #define MEDIA_SVC_CATEGORY_ETC          0x00000001      /**< ETC category */
58 #define MEDIA_SVC_CATEGORY_IMAGE        0x00000002      /**< Image category */
59 #define MEDIA_SVC_CATEGORY_VIDEO        0x00000004      /**< Video category */
60 #define MEDIA_SVC_CATEGORY_MUSIC        0x00000008      /**< Music category */
61 #define MEDIA_SVC_CATEGORY_SOUND        0x00000010      /**< Sound category */
62
63 #define CONTENT_TYPE_NUM 5
64 #define MUSIC_MIME_NUM 29
65 #define SOUND_MIME_NUM 1
66 #define MIME_TYPE_LENGTH 255
67 #define MIME_LENGTH 50
68 #define _3GP_FILE ".3gp"
69 #define _MP4_FILE ".mp4"
70 #define _ASF_FILE ".asf"
71
72 typedef struct {
73         char content_type[15];
74         int category_by_mime;
75 } _media_svc_content_table_s;
76
77 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
78         {"audio", MEDIA_SVC_CATEGORY_SOUND},
79         {"image", MEDIA_SVC_CATEGORY_IMAGE},
80         {"video", MEDIA_SVC_CATEGORY_VIDEO},
81         {"application", MEDIA_SVC_CATEGORY_ETC},
82         {"text", MEDIA_SVC_CATEGORY_ETC},
83 };
84
85 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
86         /*known mime types of normal files*/
87         "mpeg",
88         "ogg",
89         "x-ms-wma",
90         "x-flac",
91         "mp4",
92         /* known mime types of drm files*/
93         "mp3",
94         "x-mp3", /*alias of audio/mpeg*/
95         "x-mpeg", /*alias of audio/mpeg*/
96         "3gpp",
97         "x-ogg", /*alias of  audio/ogg*/
98         "vnd.ms-playready.media.pya:*.pya", /*playready*/
99         "wma",
100         "aac",
101         "x-m4a", /*alias of audio/mp4*/
102         /* below mimes are rare*/
103         "x-vorbis+ogg",
104         "x-flac+ogg",
105         "x-matroska",
106         "ac3",
107         "mp2",
108         "x-ape",
109         "x-ms-asx",
110         "vnd.rn-realaudio",
111
112         "x-vorbis", /*alias of audio/x-vorbis+ogg*/
113         "vorbis", /*alias of audio/x-vorbis+ogg*/
114         "x-oggflac",
115         "x-mp2", /*alias of audio/mp2*/
116         "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
117         "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
118         "x-wav",
119 };
120
121 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
122         "x-smaf",
123 };
124
125 typedef enum {
126         MEDIA_SVC_EXTRACTED_FIELD_NONE                  = 0x00000001,
127         MEDIA_SVC_EXTRACTED_FIELD_TITLE                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
128         MEDIA_SVC_EXTRACTED_FIELD_DESC                  = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
129         MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT             = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
130         MEDIA_SVC_EXTRACTED_FIELD_AUTHOR                = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
131         MEDIA_SVC_EXTRACTED_FIELD_ARTIST                = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
132         MEDIA_SVC_EXTRACTED_FIELD_GENRE                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
133         MEDIA_SVC_EXTRACTED_FIELD_ALBUM                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
134         MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM              = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
135         MEDIA_SVC_EXTRACTED_FIELD_YEAR                  = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
136         MEDIA_SVC_EXTRACTED_FIELD_CATEGORY              = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
137         MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST          = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
138 } media_svc_extracted_field_e;
139
140 static char *_media_svc_get_thumb_path(uid_t uid);
141
142 char *_media_info_generate_uuid(void)
143 {
144         uuid_t uuid_value;
145         static char uuid_unparsed[50];
146
147         uuid_generate(uuid_value);
148         uuid_unparse(uuid_value, uuid_unparsed);
149
150         /*media_svc_debug("UUID : %s", uuid_unparsed); */
151         return uuid_unparsed;
152 }
153
154 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
155 {
156         if (!x_src || strlen(x_src) == 0) {
157                 media_svc_error("x_src is NULL");
158                 return;
159         }
160
161         if (max_len < 1) {
162                 media_svc_error("length is Wrong");
163                 return;
164         }
165
166         strncpy(x_dst, x_src, max_len - 1);
167         x_dst[max_len - 1] = '\0';
168 }
169
170 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
171 {
172         int len = 0;
173
174         if (!STRING_VALID(src)) {
175                 media_svc_error("invalid src");
176                 return MS_MEDIA_ERR_INVALID_PARAMETER;
177         }
178
179         SAFE_FREE(*dst);
180
181         len = strlen(src) + 1;
182         *dst = malloc(len);
183
184         if (*dst == NULL) {
185                 media_svc_error("malloc failed");
186                 return MS_MEDIA_ERR_INTERNAL;
187         }
188
189         strncpy(*dst, src, len);
190         char *p = *dst;
191         p[len - 1] = '\0';
192
193         return MS_MEDIA_ERR_NONE;
194 }
195
196 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
197 {
198         if (!STRING_VALID(src)) {
199                 media_svc_error("invalid src");
200                 return MS_MEDIA_ERR_INVALID_PARAMETER;
201         }
202
203         SAFE_FREE(*dst);
204
205         *dst = malloc(copysize + 1);
206
207         if (*dst == NULL) {
208                 media_svc_error("malloc failed");
209                 return MS_MEDIA_ERR_INTERNAL;
210         }
211
212         strncpy(*dst, src, copysize);
213         char *p = *dst;
214         p[copysize] = '\0';
215
216         return MS_MEDIA_ERR_NONE;
217 }
218
219 static int __media_svc_split_to_double(char *input, double *arr)
220 {
221         char tmp_arr[255] = {0, };
222         int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
223
224         if (!STRING_VALID(input)) {
225                 media_svc_error("Invalid parameter");
226                 return MS_MEDIA_ERR_INVALID_PARAMETER;
227         }
228         memset(tmp_arr, 0x0, sizeof(tmp_arr));
229
230         /*media_svc_debug("input: [%s]", input); */
231
232         len = strlen(input);
233
234         for (idx = 0; idx < (len + 1); idx++) {
235                 if (input[idx] == ' ') {
236                         continue;
237                 } else if ((input[idx] == ', ') || (idx == len)) {
238                         arr[arr_idx] = atof(tmp_arr);
239                         arr_idx++;
240                         str_idx = 0;
241                         /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
242                         memset(tmp_arr, 0x0, sizeof(tmp_arr));
243                 } else {
244                         tmp_arr[str_idx] = input[idx];
245                         str_idx++;
246                 }
247         }
248
249         if (arr_idx != 3) {
250                 media_svc_error("Error when parsing GPS [%d]", arr_idx);
251                 return MS_MEDIA_ERR_INTERNAL;
252         }
253
254         return MS_MEDIA_ERR_NONE;
255 }
256
257 static int __media_svc_get_exif_info(ExifData *ed,
258                                      char *buf,
259                                      int *i_value,
260                                      double *d_value,
261                                      int ifdtype,
262                                      long tagtype)
263 {
264         ExifEntry *entry;
265         ExifTag tag;
266
267         if (ed == NULL) {
268                 /*media_svc_debug("ExifData is NULL"); */
269                 return MS_MEDIA_ERR_INVALID_PARAMETER;
270         }
271
272         tag = tagtype;
273
274         entry = exif_data_get_entry(ed, tag);
275         if (entry) {
276                 /* Get the contents of the tag in human-readable form */
277                 if (tag == EXIF_TAG_ORIENTATION ||
278                     tag == EXIF_TAG_PIXEL_X_DIMENSION ||
279                     tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
280
281                         if (i_value == NULL) {
282                                 media_svc_error("i_value is NULL");
283                                 return MS_MEDIA_ERR_INVALID_PARAMETER;
284                         }
285
286                         ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
287                         short exif_value = exif_get_short(entry->data, mByteOrder);
288                         /*media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag, ifd), exif_value); */
289                         *i_value = (int)exif_value;
290
291                 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
292
293                         if (d_value == NULL) {
294                                 media_svc_error("d_value is NULL");
295                                 return MS_MEDIA_ERR_INVALID_PARAMETER;
296                         }
297
298                         /* Get the contents of the tag in human-readable form */
299                         char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
300                         exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
301                         gps_buf[strlen(gps_buf)] = '\0';
302                         int ret = MS_MEDIA_ERR_NONE;
303                         /*media_svc_debug("%s: [%s]", exif_tag_get_name_in_ifd(tag, ifd), gps_buf); */
304
305                         double tmp_arr[3] = { 0.0, 0.0, 0.0 };
306
307                         ret = __media_svc_split_to_double(gps_buf, tmp_arr);
308                         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
309
310                         *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
311                         /*media_svc_debug("GPS value is [%f], %f, %f, %f", *d_value, tmp_arr[0], tmp_arr[1], tmp_arr[2]); */
312                 } else {
313
314                         if (buf == NULL) {
315                                 media_svc_error("buf is NULL");
316                                 return MS_MEDIA_ERR_INVALID_PARAMETER;
317                         }
318
319                         exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
320                         buf[strlen(buf)] = '\0';
321                 }
322         }
323
324         return MS_MEDIA_ERR_NONE;
325 }
326
327 time_t __media_svc_get_timeline_from_str(const char *timstr)
328 {
329         struct tm t;
330         time_t modified_t = 0;
331         time_t rawtime;
332         struct tm timeinfo;
333
334         if (!STRING_VALID(timstr)) {
335                 media_svc_error("Invalid Parameter");
336                 return 0;
337         }
338
339         /*Exif Format : %Y:%m:%d %H:%M:%S
340         Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
341         memset(&t, 0x00, sizeof(struct tm));
342
343         tzset();
344         time(&rawtime);
345         localtime_r(&rawtime, &timeinfo);
346
347         if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
348                 t.tm_isdst = timeinfo.tm_isdst;
349                 if (t.tm_isdst != 0) {
350                         media_svc_error("DST %d", t.tm_isdst);
351                 }
352
353                 modified_t = mktime(&t);
354                 if (modified_t > 0) {
355                         return modified_t;
356                 } else {
357                         media_svc_error("Failed to get timeline : [%s] [%d:%d:%d: %d:%d:%d]", timstr, t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
358                 }
359         } else {
360                 media_svc_error("Failed to get timeline : [%s]", timstr);
361         }
362
363         return 0;
364 }
365
366 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
367 {
368         int idx = 0;
369
370         *category = MEDIA_SVC_CATEGORY_UNKNOWN;
371
372         /*categorize from mimetype */
373         for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
374                 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
375                         *category = (*category | content_category[idx].category_by_mime);
376                         break;
377                 }
378         }
379
380         /*in application type, exitst sound file ex) x-smafs */
381         if (*category & MEDIA_SVC_CATEGORY_ETC) {
382                 int prefix_len = strlen(content_category[0].content_type);
383
384                 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
385                         if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
386                                 *category ^= MEDIA_SVC_CATEGORY_ETC;
387                                 *category |= MEDIA_SVC_CATEGORY_SOUND;
388                                 break;
389                         }
390                 }
391
392                 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
393                         *category ^= MEDIA_SVC_CATEGORY_ETC;
394                         *category |= MEDIA_SVC_CATEGORY_SOUND;
395                 }
396         }
397
398         /*check music file in soun files. */
399         if (*category & MEDIA_SVC_CATEGORY_SOUND) {
400                 int prefix_len = strlen(content_category[0].content_type) + 1;
401
402                 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
403                         if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
404                                 *category ^= MEDIA_SVC_CATEGORY_SOUND;
405                                 *category |= MEDIA_SVC_CATEGORY_MUSIC;
406                                 break;
407                         }
408                 }
409
410                 /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
411                 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
412                         *category ^= MEDIA_SVC_CATEGORY_SOUND;
413                         *category |= MEDIA_SVC_CATEGORY_ETC;
414                 }
415         } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
416                 /*some video files don't have video stream. in this case it is categorize as music. */
417                 char *ext = NULL;
418                 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
419                 ext = strrchr(path, '.');
420                 if (ext != NULL) {
421                         if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0) || (strncasecmp(ext, _ASF_FILE, 5) == 0)) {
422                                 int audio = 0;
423                                 int video = 0;
424                                 int err = 0;
425
426                                 err = mm_file_get_stream_info(path, &audio, &video);
427                                 if (err == 0) {
428                                         if (audio > 0 && video == 0) {
429                                                 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
430                                                 *category |= MEDIA_SVC_CATEGORY_MUSIC;
431                                         }
432                                 }
433                                 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
434                         }
435                 }
436         }
437
438         return MS_MEDIA_ERR_NONE;
439 }
440
441 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
442 {
443         int ret = MS_MEDIA_ERR_NONE;
444         int category = 0;
445
446         media_svc_media_type_e type;
447
448         ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
449         if (ret != MS_MEDIA_ERR_NONE) {
450                 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
451         }
452
453         if (category & MEDIA_SVC_CATEGORY_SOUND)                type = MEDIA_SVC_MEDIA_TYPE_SOUND;
454         else if (category & MEDIA_SVC_CATEGORY_MUSIC)   type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
455         else if (category & MEDIA_SVC_CATEGORY_IMAGE)   type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
456         else if (category & MEDIA_SVC_CATEGORY_VIDEO)   type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
457         else    type = MEDIA_SVC_MEDIA_TYPE_OTHER;
458
459         *media_type = type;
460
461         return ret;
462 }
463
464 /*
465 drm_contentifo is not NULL, if the file is OMA DRM.
466 If the file is not OMA DRM, drm_contentinfo must be NULL.
467 */
468 static int __media_svc_get_mime_type(const char *path, char *mimetype)
469 {
470         if (path == NULL)
471                 return MS_MEDIA_ERR_INVALID_PARAMETER;
472
473         /*in case of normal files or failure to get mime in drm */
474         if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
475                 media_svc_error("aul_get_mime_from_file fail");
476                 return MS_MEDIA_ERR_INTERNAL;
477         }
478
479         return MS_MEDIA_ERR_NONE;
480 }
481
482 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
483 {
484         int i = 0;
485
486         for (i = strlen(file_path); i >= 0; i--) {
487                 if (file_path[i] == '.') {
488                         _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
489                         return true;
490                 }
491
492                 if (file_path[i] == '/') {
493                         return false;
494                 }
495         }
496         return false;
497 }
498
499 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
500 {
501         char *err_attr_name = NULL;
502         double gps_value = 0.0;
503         int mmf_error = MM_ERROR_NONE;
504
505         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
506         if (mmf_error == MM_ERROR_NONE) {
507                 if (longitude != NULL) {
508                         *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
509                 }
510         } else {
511                 SAFE_FREE(err_attr_name);
512         }
513
514         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
515         if (mmf_error == MM_ERROR_NONE) {
516                 if (latitude != NULL) {
517                         *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
518                 }
519         } else {
520                 SAFE_FREE(err_attr_name);
521         }
522
523         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
524         if (mmf_error == MM_ERROR_NONE) {
525                 if (altitude != NULL) {
526                         *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
527                 }
528         } else {
529                 SAFE_FREE(err_attr_name);
530         }
531
532         return MS_MEDIA_ERR_NONE;
533 }
534
535 static int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
536 {
537         media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
538
539         if (!image) {
540                 media_svc_error("invalid image..");
541                 return MS_MEDIA_ERR_INVALID_PARAMETER;
542         }
543
544         struct statfs fs;
545         if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) {
546                 media_svc_error("error in statfs");
547                 return MS_MEDIA_ERR_INTERNAL;
548         }
549
550         long bsize_kbytes = fs.f_bsize >> 10;
551
552         if ((bsize_kbytes * fs.f_bavail) < 1024) {
553                 media_svc_error("not enought space...");
554                 return MS_MEDIA_ERR_INTERNAL;
555         }
556
557         FILE *fp = NULL;
558         int nwrite = -1;
559         if (image != NULL && size > 0) {
560                 fp = fopen(image_path, "w");
561
562                 if (fp == NULL) {
563                         media_svc_error("failed to open file");
564                         return MS_MEDIA_ERR_INTERNAL;
565                 }
566
567                 nwrite = fwrite(image, 1, size, fp);
568                 if (nwrite != size) {
569                         media_svc_error("failed to write thumbnail");
570                         fclose(fp);
571                         return MS_MEDIA_ERR_INTERNAL;
572                 }
573                 fclose(fp);
574         }
575
576         return MS_MEDIA_ERR_NONE;
577 }
578
579 static char *_media_svc_get_title_from_filepath(const char *path)
580 {
581         char *filename = NULL;
582         char *title = NULL;
583         char    *ext = NULL;
584         int filename_len = -1;
585         int new_title_len = -1;
586
587         if (!path) {
588                 media_svc_error("path is NULL");
589                 return NULL;
590         }
591
592         filename = g_path_get_basename(path);
593         if (!STRING_VALID(filename)) {
594                 media_svc_error("wrong file name");
595                 SAFE_FREE(filename);
596                 return NULL;
597         }
598
599         filename_len = strlen(filename);
600
601         ext = g_strrstr(filename, ".");
602         if (!ext) {
603                 media_svc_error("there is no file extention");
604                 return filename;
605         }
606
607         new_title_len = filename_len - strlen(ext);
608         if (new_title_len < 1) {
609                 media_svc_error("title length is zero");
610                 SAFE_FREE(filename);
611                 return NULL;
612         }
613
614         title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
615
616         SAFE_FREE(filename);
617
618         media_svc_debug("extract title is [%s]", title);
619
620         return title;
621 }
622
623 int _media_svc_rename_file(const char *old_name, const char *new_name)
624 {
625         if ((old_name == NULL) || (new_name == NULL)) {
626                 media_svc_error("invalid file name");
627                 return MS_MEDIA_ERR_INVALID_PARAMETER;
628         }
629
630         if (rename(old_name, new_name) < 0) {
631                 media_svc_stderror(" ");
632                 return MS_MEDIA_ERR_INTERNAL;
633         }
634
635         return MS_MEDIA_ERR_NONE;
636 }
637
638 int _media_svc_remove_file(const char *path)
639 {
640         int result = -1;
641
642         result = remove(path);
643         if (result == 0) {
644                 media_svc_debug("success to remove file");
645                 return MS_MEDIA_ERR_NONE;
646         } else {
647                 media_svc_stderror("fail to remove file result");
648                 return MS_MEDIA_ERR_INTERNAL;
649         }
650 }
651
652 int _media_svc_remove_all_files_in_dir(const char *dir_path)
653 {
654         struct dirent entry;
655         struct dirent *result;
656         struct stat st;
657         char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
658         DIR *dir = NULL;
659
660         dir = opendir(dir_path);
661         if (dir == NULL) {
662                 media_svc_error("%s is not exist", dir_path);
663                 return MS_MEDIA_ERR_INVALID_PARAMETER;
664         }
665
666         while (!readdir_r(dir, &entry, &result)) {
667                 if (result == NULL)
668                         break;
669
670                 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) {
671                         continue;
672                 }
673                 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
674
675                 if (stat(filename, &st) != 0) {
676                         continue;
677                 }
678                 if (S_ISDIR(st.st_mode)) {
679                         continue;
680                 }
681                 if (unlink(filename) != 0) {
682                         media_svc_stderror("failed to remove");
683                         closedir(dir);
684                         return MS_MEDIA_ERR_INTERNAL;
685                 }
686         }
687
688         closedir(dir);
689         return MS_MEDIA_ERR_NONE;
690 }
691
692 static int _mkdir(const char *dir, mode_t mode)
693 {
694         char tmp[256];
695         char *p = NULL;
696         size_t len;
697
698         snprintf(tmp, sizeof(tmp), "%s", dir);
699         len = strlen(tmp);
700         if (tmp[len - 1] == '/')
701                 tmp[len - 1] = 0;
702         for (p = tmp + 1; *p; p++)
703                 if (*p == '/') {
704                         *p = 0;
705                         mkdir(tmp, mode);
706                         *p = '/';
707                 }
708         return mkdir(tmp, mode);
709 }
710
711 char *_media_svc_get_thumb_internal_path(uid_t uid)
712 {
713         char *result_psswd = NULL;
714         struct group *grpinfo = NULL;
715         if (uid == getuid()) {
716                 result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
717                 grpinfo = getgrnam("users");
718                 if (grpinfo == NULL) {
719                         media_svc_error("getgrnam(users) returns NULL !");
720                         if(result_psswd)
721                                 free(result_psswd);
722                         return NULL;
723                 }
724         } else {
725                 struct passwd *userinfo = getpwuid(uid);
726                 if (userinfo == NULL) {
727                         media_svc_error("getpwuid(%d) returns NULL !", uid);
728                         return NULL;
729                 }
730                 grpinfo = getgrnam("users");
731                 if (grpinfo == NULL) {
732                         media_svc_error("getgrnam(users) returns NULL !");
733                         return NULL;
734                 }
735                 /* Compare git_t type and not group name */
736                 if (grpinfo->gr_gid != userinfo->pw_gid) {
737                         media_svc_error("UID [%d] does not belong to 'users' group!", uid);
738                         return NULL;
739                 }
740                 asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
741         }
742
743         _mkdir(result_psswd, S_IRWXU | S_IRWXG | S_IRWXO);
744
745         return result_psswd;
746 }
747
748 char *_media_svc_get_thumb_external_path(uid_t uid)
749 {
750         char *result_psswd = NULL;
751         struct group *grpinfo = NULL;
752         if (uid == getuid()) {
753                 result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
754                 grpinfo = getgrnam("users");
755                 if (grpinfo == NULL) {
756                         media_svc_error("getgrnam(users) returns NULL !");
757                         if(result_psswd)
758                                 free(result_psswd);
759                         return NULL;
760                 }
761         } else {
762                 struct passwd *userinfo = getpwuid(uid);
763                 if (userinfo == NULL) {
764                         media_svc_error("getpwuid(%d) returns NULL !", uid);
765                         return NULL;
766                 }
767                 grpinfo = getgrnam("users");
768                 if (grpinfo == NULL) {
769                         media_svc_error("getgrnam(users) returns NULL !");
770                         return NULL;
771                 }
772                 /* Compare git_t type and not group name */
773                 if (grpinfo->gr_gid != userinfo->pw_gid) {
774                         media_svc_error("UID [%d] does not belong to 'users' group!", uid);
775                         return NULL;
776                 }
777                 asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
778         }
779
780         _mkdir(result_psswd, S_IRWXU | S_IRWXG | S_IRWXO);
781
782         return result_psswd;
783 }
784
785 static int __media_svc_check_thumb_dir(char *thumb_dir)
786 {
787         int ret = 0;
788         DIR *dir = NULL;
789
790         dir = opendir(thumb_dir);
791         if (dir != NULL) {
792                 closedir(dir);
793         } else {
794                 media_svc_stderror("opendir fail");
795                 if (errno == ENOENT) {
796                         media_svc_error("[%s] is not exit. So, make it", thumb_dir);
797                         ret = mkdir(thumb_dir, 0777);
798                         if (ret < 0) {
799                                 media_svc_error("make fail");
800                                 goto ERROR;
801                         }
802                 } else {
803                         goto ERROR;
804                 }
805
806                 ret = chmod(thumb_dir, 0777);
807                 if (ret != 0) {
808                         media_svc_stderror("chmod failed");
809                 }
810                 ret = chown(thumb_dir, 5000, 5000);
811                 if (ret != 0) {
812                         media_svc_stderror("chown failed");
813                 }
814         }
815
816         return MS_MEDIA_ERR_NONE;
817
818 ERROR:
819         return -1;
820 }
821
822 static char *_media_svc_get_thumb_path(uid_t uid)
823 {
824         char *result_psswd = NULL;
825         struct group *grpinfo = NULL;
826         if (uid == getuid()) {
827                 result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
828                 grpinfo = getgrnam("users");
829                 if (grpinfo == NULL) {
830                         media_svc_error("getgrnam(users) returns NULL !");
831                         if(result_psswd)
832                                 free(result_psswd);
833                         return NULL;
834                 }
835         } else {
836                 struct passwd *userinfo = getpwuid(uid);
837                 if (userinfo == NULL) {
838                         media_svc_error("getpwuid(%d) returns NULL !", uid);
839                         return NULL;
840                 }
841                 grpinfo = getgrnam("users");
842                 if (grpinfo == NULL) {
843                         media_svc_error("getgrnam(users) returns NULL !");
844                         return NULL;
845                 }
846                 /* Compare git_t type and not group name */
847                 if (grpinfo->gr_gid != userinfo->pw_gid) {
848                         media_svc_error("UID [%d] does not belong to 'users' group!", uid);
849                         return NULL;
850                 }
851                 asprintf(&result_psswd, "%s/data/file-manager-service/.thumb", userinfo->pw_dir);
852         }
853
854         _mkdir(result_psswd, S_IRWXU | S_IRWXG | S_IRWXO);
855
856         return result_psswd;
857 }
858
859 int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
860 {
861         int ret = MS_MEDIA_ERR_NONE;
862         char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
863         char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
864         char *thumb_dir = NULL;
865         char hash[255 + 1];
866         char *thumbfile_ext = NULL;
867
868         thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
869
870         ret = __media_svc_check_thumb_dir(thumb_dir);
871         if (ret != MS_MEDIA_ERR_NONE) {
872                 media_svc_error("__media_svc_check_thumb_dir");
873                 return MS_MEDIA_ERR_INTERNAL;
874         }
875
876         memset(file_ext, 0, sizeof(file_ext));
877         if (!__media_svc_get_file_ext(pathname, file_ext)) {
878                 media_svc_error("get file ext fail");
879         }
880
881         ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
882         if (ret != MS_MEDIA_ERR_NONE) {
883                 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
884                 return MS_MEDIA_ERR_INTERNAL;
885         }
886
887         /*media_svc_debug("img format is [%s]", img_format); */
888
889         if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
890                 thumbfile_ext = "jpg";
891         } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
892                 thumbfile_ext = "png";
893         } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
894                 thumbfile_ext = "gif";
895         } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
896                 thumbfile_ext = "bmp";
897         } else {
898                 media_svc_error("Not proper img format");
899                 return MS_MEDIA_ERR_INTERNAL;
900         }
901
902         snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
903         _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
904         /*media_svc_debug("thumb_path is [%s]", thumb_path); */
905
906         return MS_MEDIA_ERR_NONE;
907 }
908
909 int _media_svc_get_file_time(const char *full_path)
910 {
911         struct stat statbuf;
912         int fd = 0;
913
914         memset(&statbuf, 0, sizeof(struct stat));
915         fd = stat(full_path, &statbuf);
916         if (fd == -1) {
917                 media_svc_error("stat(%s) fails.", full_path);
918                 return MS_MEDIA_ERR_INTERNAL;
919         }
920
921         return statbuf.st_mtime;
922 }
923
924 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
925                               const char *path, media_svc_media_type_e *media_type, bool refresh)
926 {
927         int ret = MS_MEDIA_ERR_NONE;
928         char *media_uuid = NULL;
929         char *file_name = NULL;
930         struct stat st;
931         bool drm_type = false;
932         char mime_type[256] = {0};
933
934         ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
935         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
936
937         memset(&st, 0, sizeof(struct stat));
938         if (stat(path, &st) == 0) {
939                 content_info->modified_time = st.st_mtime;
940                 content_info->timeline = content_info->modified_time;
941                 content_info->size = st.st_size;
942                 /*media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size); */
943         } else {
944                 media_svc_stderror("stat failed");
945         }
946
947         /* Set default GPS value before extracting meta information */
948         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
949         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
950         content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
951
952         /* Set filename to title for all media */
953         char *title = NULL;
954         title = _media_svc_get_title_from_filepath(content_info->path);
955         if (title) {
956                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
957                 if (ret != MS_MEDIA_ERR_NONE)
958                         media_svc_error("strcpy error");
959                 SAFE_FREE(title);
960         } else {
961                 media_svc_error("Can't extract title");
962                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
963                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
964         }
965
966         /* Set default value before extracting meta information */
967         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
968         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
969
970         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
971         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
972
973         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
974         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
975
976         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
977         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
978
979         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
980         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
981
982         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
983         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
984
985         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
986         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
987
988         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
989         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
990
991         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
992         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
993
994         /* refresh is TRUE when file modified. so only modified_time and size are changed*/
995         if (refresh) {
996                 media_svc_debug("refresh");
997                 return MS_MEDIA_ERR_NONE;
998         }
999
1000         ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1001         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1002
1003         content_info->storage_type = storage_type;
1004         time(&content_info->added_time);
1005
1006         media_uuid = _media_info_generate_uuid();
1007         if (media_uuid == NULL) {
1008                 _media_svc_destroy_content_info(content_info);
1009                 return MS_MEDIA_ERR_INTERNAL;
1010         }
1011
1012         ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1013         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1014
1015         file_name = g_path_get_basename(path);
1016         ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1017         SAFE_FREE(file_name);
1018         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1019
1020         /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1021         if drm_contentinfo is not NULL, the file is OMA DRM.*/
1022         ret = __media_svc_get_mime_type(path, mime_type);
1023         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1024
1025         media_svc_debug("mime [%s]", mime_type);
1026         content_info->is_drm = drm_type;
1027
1028         ret = __media_svc_get_media_type(path, mime_type, media_type);
1029         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1030
1031         if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1032                 media_svc_error("invalid media_type condition[%d]", *media_type);
1033                 return MS_MEDIA_ERR_INVALID_PARAMETER;
1034         }
1035
1036         ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1037         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1038
1039         media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1040
1041         content_info->media_type = *media_type;
1042
1043         content_info->played_count = 0;
1044         content_info->last_played_time = 0;
1045         content_info->last_played_position = 0;
1046         content_info->favourate = 0;
1047         content_info->media_meta.rating = 0;
1048
1049         return MS_MEDIA_ERR_NONE;
1050 }
1051
1052 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid)
1053 {
1054         int ret = MS_MEDIA_ERR_NONE;
1055         double value = 0.0;
1056         int orient_value = 0;
1057         int exif_width = 0;
1058         int exif_height = 0;
1059         ExifData *ed = NULL;
1060         int has_datetaken = FALSE;
1061         int datetaken_size = 19;
1062         double fnumber = 0.0;
1063         int iso = 0;
1064         char *path = NULL;
1065
1066         char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1067         char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1068         char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1069         char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1070
1071         memset(buf, 0x00, sizeof(buf));
1072         memset(description_buf, 0x00, sizeof(description_buf));
1073         memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1074         memset(model_buf, 0x00, sizeof(model_buf));
1075
1076         if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1077                 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1078                 return MS_MEDIA_ERR_INVALID_PARAMETER;
1079         }
1080
1081         path = content_info->path;
1082         if (!STRING_VALID(path)) {
1083                 media_svc_error("Invalid Path");
1084                 return MS_MEDIA_ERR_INVALID_PARAMETER;
1085         }
1086
1087         /* Load an ExifData object from an EXIF file */
1088         ed = exif_data_new_from_file(path);
1089
1090         if (!ed) {
1091                 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1092         }
1093
1094         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1095                 if (strlen(buf) != 0) {
1096                         if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1097
1098                                 if (strcmp(buf, "S") == 0) {
1099                                         value = -1 * value;
1100                                 }
1101
1102                                 content_info->media_meta.latitude = value;
1103                         } else {
1104                                 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1105                         }
1106                 } else {
1107                         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1108                 }
1109         } else {
1110                 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1111         }
1112
1113         memset(buf, 0x00, sizeof(buf));
1114
1115         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1116                 if (strlen(buf) != 0) {
1117                         if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1118                                 if (strcmp(buf, "W") == 0) {
1119                                         value = -1 * value;
1120                                 }
1121                                 content_info->media_meta.longitude = value;
1122                         } else {
1123                                 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1124                         }
1125                 } else {
1126                         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1127                 }
1128         } else {
1129                 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1130         }
1131
1132         memset(buf, 0x00, sizeof(buf));
1133
1134         if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1135                 if (strlen(description_buf) == 0) {
1136                         /*media_svc_debug("Use 'No description'"); */
1137                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1138                         if (ret != MS_MEDIA_ERR_NONE)
1139                                 media_svc_error("strcpy error");
1140                 } else {
1141                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1142                         if (ret != MS_MEDIA_ERR_NONE)
1143                                 media_svc_error("strcpy error");
1144                 }
1145         } else {
1146                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1147                 if (ret != MS_MEDIA_ERR_NONE)
1148                         media_svc_error("strcpy error");
1149         }
1150
1151         memset(buf, 0x00, sizeof(buf));
1152
1153         if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1154                 if (strlen(buf) == 0) {
1155                         /*media_svc_debug("time  is NULL"); */
1156                 } else {
1157 #if 0
1158                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
1159 #else
1160                         ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1161 #endif
1162                         if (ret != MS_MEDIA_ERR_NONE) {
1163                                 media_svc_error("strcpy error");
1164                         } else {
1165                                 has_datetaken = TRUE;
1166                                 /* This is same as recorded_date */
1167                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1168                                 if (ret != MS_MEDIA_ERR_NONE)
1169                                         media_svc_error("strcpy error");
1170                         }
1171                 }
1172         }
1173
1174         memset(buf, 0x00, sizeof(buf));
1175
1176         if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1177                 if (strlen(buf) == 0) {
1178                         /*media_svc_debug("time  is NULL"); */
1179                 } else {
1180 #if 0
1181                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
1182 #else
1183                         ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1184 #endif
1185                         if (ret != MS_MEDIA_ERR_NONE) {
1186                                 media_svc_error("strcpy error");
1187                         } else {
1188                                 has_datetaken = TRUE;
1189                                 /* This is same as recorded_date */
1190                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1191                                 if (ret != MS_MEDIA_ERR_NONE)
1192                                         media_svc_error("strcpy error");
1193                         }
1194                 }
1195         }
1196
1197         if (has_datetaken) {
1198                 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1199                 if (content_info->timeline == 0) {
1200                         content_info->timeline = content_info->modified_time;
1201                 } else {
1202                         media_svc_debug("Timeline : %ld", content_info->timeline);
1203                 }
1204         }
1205
1206         /* Get exposure_time value from exif. */
1207         if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1208                 if (strlen(exposure_time_buf) == 0) {
1209                         media_svc_error("exposure_time_buf is NULL");
1210                 } else {
1211                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1212                         if (ret != MS_MEDIA_ERR_NONE)
1213                                 media_svc_error("strcpy error");
1214                 }
1215         }
1216
1217         /* Get fnumber value from exif. */
1218         if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_IFD_0, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1219                 if (fnumber > 0.0) {
1220                         content_info->media_meta.fnumber = fnumber;
1221                 } else {
1222                         content_info->media_meta.fnumber = 0.0;
1223                 }
1224         } else {
1225                 content_info->media_meta.fnumber = 0.0;
1226         }
1227
1228         /* Get iso value from exif. */
1229         if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_IFD_0, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1230                 if (iso > 0) {
1231                         content_info->media_meta.iso = iso;
1232                 } else {
1233                         content_info->media_meta.iso = 0;
1234                 }
1235         } else {
1236                 content_info->media_meta.iso = 0;
1237         }
1238
1239         /* Get model value from exif. */
1240         if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1241                 if (strlen(model_buf) == 0) {
1242                         media_svc_error("model_buf is NULL");
1243                 } else {
1244                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1245                         if (ret != MS_MEDIA_ERR_NONE)
1246                                 media_svc_error("strcpy error");
1247                 }
1248         }
1249
1250         /* Get orientation value from exif. */
1251         if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1252                 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
1253                         content_info->media_meta.orientation = orient_value;
1254                 } else {
1255                         content_info->media_meta.orientation = 0;
1256                 }
1257         } else {
1258                 content_info->media_meta.orientation = 0;
1259         }
1260
1261         /* Get width value from exif. */
1262         if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1263                 if (exif_width > 0) {
1264                         content_info->media_meta.width = exif_width;
1265                 } else {
1266                         content_info->media_meta.width = 0;
1267                 }
1268         } else {
1269                 content_info->media_meta.width = 0;
1270         }
1271
1272         /* Get height value from exif. */
1273         if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1274                 if (exif_height > 0) {
1275                         content_info->media_meta.height = exif_height;
1276                 } else {
1277                         content_info->media_meta.height = 0;
1278                 }
1279         } else {
1280                 content_info->media_meta.height = 0;
1281         }
1282
1283         if (ed != NULL) exif_data_unref(ed);
1284
1285         return MS_MEDIA_ERR_NONE;
1286 }
1287
1288 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1289 {
1290         MMHandleType tag = 0;
1291         char *p = NULL;
1292         int size = -1;
1293         int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1294         int mmf_error = MM_ERROR_NONE;
1295         char *err_attr_name = NULL;
1296         char *title = NULL;
1297         int album_id = 0;
1298         int ret = MS_MEDIA_ERR_NONE;
1299
1300         /*Get Content Tag attribute ===========*/
1301         mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1302
1303         if (mmf_error == MM_ERROR_NONE) {
1304                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1305                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1306                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1307                         if (ret != MS_MEDIA_ERR_NONE)
1308                                 media_svc_error("strcpy error");
1309
1310                         /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1311                 } else {
1312                         SAFE_FREE(err_attr_name);
1313                         /*media_svc_debug("album - unknown"); */
1314                 }
1315
1316                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1317                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1318                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1319                         if (ret != MS_MEDIA_ERR_NONE)
1320                                 media_svc_error("strcpy error");
1321                         /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1322                 } else {
1323                         SAFE_FREE(err_attr_name);
1324                         /*media_svc_debug("artist - unknown"); */
1325                 }
1326
1327                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1328                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1329                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1330                         if (ret != MS_MEDIA_ERR_NONE)
1331                                 media_svc_error("strcpy error");
1332                         /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1333                 } else {
1334                         SAFE_FREE(err_attr_name);
1335                         /*media_svc_debug("album_artist - unknown"); */
1336                 }
1337
1338                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1339                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1340                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1341                         if (ret != MS_MEDIA_ERR_NONE)
1342                                 media_svc_error("strcpy error");
1343
1344                         /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1345                         /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1346                         /*
1347                         if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1348                                 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1349                         }
1350                         */
1351                 } else {
1352                         SAFE_FREE(err_attr_name);
1353                         /*media_svc_debug("genre - unknown"); */
1354                 }
1355
1356                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1357                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* &&   (!isspace(*p))*/) {
1358                         if (!isspace(*p)) {
1359                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1360                                 if (ret != MS_MEDIA_ERR_NONE)
1361                                         media_svc_error("strcpy error");
1362
1363                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1364                         } else {
1365                                 int idx = 0;
1366
1367                                 for (idx = 0; idx < size; idx++) {
1368                                         if (isspace(*p)) {
1369                                                 media_svc_debug("SPACE [%s]", p);
1370                                                 p++;
1371                                                 continue;
1372                                         } else {
1373                                                 media_svc_debug("Not SPACE [%s]", p);
1374                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1375                                                 if (ret != MS_MEDIA_ERR_NONE)
1376                                                         media_svc_error("strcpy error");
1377                                                 break;
1378                                         }
1379                                 }
1380
1381                                 if (idx == size) {
1382                                         media_svc_debug("Can't extract title. All string is space");
1383                                         title = _media_svc_get_title_from_filepath(content_info->path);
1384                                         if (title) {
1385                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1386                                                 if (ret != MS_MEDIA_ERR_NONE)
1387                                                         media_svc_error("strcpy error");
1388                                                 SAFE_FREE(title);
1389                                         } else {
1390                                                 media_svc_error("Can't extract title");
1391                                         }
1392                                 }
1393                         }
1394                 } else {
1395                         SAFE_FREE(err_attr_name);
1396                         title = _media_svc_get_title_from_filepath(content_info->path);
1397                         if (title) {
1398                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1399                                 if (ret != MS_MEDIA_ERR_NONE)
1400                                         media_svc_error("strcpy error");
1401                                 SAFE_FREE(title);
1402                         } else {
1403                                 media_svc_error("Can't extract title");
1404                         }
1405                 }
1406
1407                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1408                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1409                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1410                         if (ret != MS_MEDIA_ERR_NONE)
1411                                 media_svc_error("strcpy error");
1412                         /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1413                 } else {
1414                         SAFE_FREE(err_attr_name);
1415                 }
1416
1417                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1418                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1419                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1420                         if (ret != MS_MEDIA_ERR_NONE)
1421                                 media_svc_error("strcpy error");
1422                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1423                         /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1424                 } else {
1425                         /*media_svc_debug("composer - unknown"); */
1426                         SAFE_FREE(err_attr_name);
1427                 }
1428
1429                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1430                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1431                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1432                         if (ret != MS_MEDIA_ERR_NONE)
1433                                 media_svc_error("strcpy error");
1434                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1435                         /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1436                 } else {
1437                         /*media_svc_debug("copyright - unknown"); */
1438                         SAFE_FREE(err_attr_name);
1439                 }
1440
1441                 mmf_error = mm_file_destroy_tag_attrs(tag);
1442                 if (mmf_error != MM_ERROR_NONE) {
1443                         media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1444                 }
1445         }       else {
1446                 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1447                 char *title = NULL;
1448                 media_svc_error("no tag information");
1449
1450                 title = _media_svc_get_title_from_filepath(content_info->path);
1451                 if (title) {
1452                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1453                         if (ret != MS_MEDIA_ERR_NONE)
1454                                 media_svc_error("strcpy error");
1455                         SAFE_FREE(title);
1456                 } else {
1457                         media_svc_error("Can't extract title");
1458                 }
1459
1460                 content_info->album_id = album_id;
1461         }
1462
1463         return MS_MEDIA_ERR_NONE;
1464 }
1465
1466 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid)
1467 {
1468         MMHandleType content = 0;
1469         MMHandleType tag = 0;
1470         char *p = NULL;
1471         void *image = NULL;
1472         int size = -1;
1473         int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1474         int mmf_error = MM_ERROR_NONE;
1475         bool thumb_extracted_from_drm = FALSE;
1476         char *err_attr_name = NULL;
1477         char *title = NULL;
1478         bool extract_thumbnail = FALSE;
1479         bool append_album = FALSE;
1480         int album_id = 0;
1481         int ret = MS_MEDIA_ERR_NONE;
1482         int cdis_value = 0;
1483
1484         /*Get Content Tag attribute ===========*/
1485         mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1486
1487         if (mmf_error == MM_ERROR_NONE) {
1488                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1489                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1490                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1491                         if (ret != MS_MEDIA_ERR_NONE)
1492                                 media_svc_error("strcpy error");
1493
1494                         /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1495                 } else {
1496                         SAFE_FREE(err_attr_name);
1497                         /*media_svc_debug("album - unknown"); */
1498                 }
1499
1500                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1501                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1502                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1503                         if (ret != MS_MEDIA_ERR_NONE)
1504                                 media_svc_error("strcpy error");
1505                         /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1506                 } else {
1507                         SAFE_FREE(err_attr_name);
1508                         /*media_svc_debug("artist - unknown"); */
1509                 }
1510
1511                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1512                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1513                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1514                         if (ret != MS_MEDIA_ERR_NONE)
1515                                 media_svc_error("strcpy error");
1516                         /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1517                 } else {
1518                         SAFE_FREE(err_attr_name);
1519                         /*media_svc_debug("album_artist - unknown"); */
1520                 }
1521
1522                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1523                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1524                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1525                         if (ret != MS_MEDIA_ERR_NONE)
1526                                 media_svc_error("strcpy error");
1527
1528                         /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1529                         /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1530                         /*
1531                         if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1532                                 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1533                         }
1534                         */
1535                 } else {
1536                         SAFE_FREE(err_attr_name);
1537                         /*media_svc_debug("genre - unknown"); */
1538                 }
1539
1540                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1541                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* &&   (!isspace(*p))*/) {
1542                         if (!isspace(*p)) {
1543                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1544                                 if (ret != MS_MEDIA_ERR_NONE)
1545                                         media_svc_error("strcpy error");
1546
1547                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1548                         } else {
1549                                 int idx = 0;
1550
1551                                 for (idx = 0; idx < size; idx++) {
1552                                         if (isspace(*p)) {
1553                                                 media_svc_debug("SPACE [%s]", p);
1554                                                 p++;
1555                                                 continue;
1556                                         } else {
1557                                                 media_svc_debug("Not SPACE [%s]", p);
1558                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1559                                                 if (ret != MS_MEDIA_ERR_NONE)
1560                                                         media_svc_error("strcpy error");
1561                                                 break;
1562                                         }
1563                                 }
1564
1565                                 if (idx == size) {
1566                                         media_svc_debug("Can't extract title. All string is space");
1567                                         title = _media_svc_get_title_from_filepath(content_info->path);
1568                                         if (title) {
1569                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1570                                                 if (ret != MS_MEDIA_ERR_NONE)
1571                                                         media_svc_error("strcpy error");
1572                                                 SAFE_FREE(title);
1573                                         } else {
1574                                                 media_svc_error("Can't extract title");
1575                                         }
1576                                 }
1577                         }
1578                 } else {
1579                         SAFE_FREE(err_attr_name);
1580                         title = _media_svc_get_title_from_filepath(content_info->path);
1581                         if (title) {
1582                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1583                                 if (ret != MS_MEDIA_ERR_NONE)
1584                                         media_svc_error("strcpy error");
1585                                 SAFE_FREE(title);
1586                         } else {
1587                                 media_svc_error("Can't extract title");
1588                         }
1589                 }
1590
1591                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1592                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1593                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1594                         if (ret != MS_MEDIA_ERR_NONE)
1595                                 media_svc_error("strcpy error");
1596                         /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1597                 } else {
1598                         SAFE_FREE(err_attr_name);
1599                 }
1600
1601                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1602                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1603                         if (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1604                                 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1605                                 char time_info[64] = {0, };
1606                                 char p_value[64] = {0, };
1607                                 int idx = 0;
1608                                 memset(time_info, 0x00, sizeof(time_info));
1609                                 memset(p_value, 0x00, sizeof(p_value));
1610                                 strncpy(p_value, p, size);
1611                                 for (idx = 0; idx < size; idx++) {
1612                                         if (p_value[idx] == '-') {
1613                                                 time_info[idx] = ':';
1614                                         } else if (p_value[idx] != '\0') {
1615                                                 time_info[idx] = p_value[idx];
1616                                         } else {
1617                                                 media_svc_error("strcpy error");
1618                                                 break;
1619                                         }
1620                                 }
1621                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
1622                         } else {
1623                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1624                         }
1625
1626                         if (ret != MS_MEDIA_ERR_NONE) {
1627                                 media_svc_error("strcpy error");
1628                         } else {
1629                                 /* This is same as datetaken */
1630 #if 0
1631                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
1632 #else
1633                                 int datetaken_size = 19;
1634                                 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
1635 #endif
1636                                 if (ret != MS_MEDIA_ERR_NONE)
1637                                         media_svc_error("strcpy error");
1638
1639                                 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1640                                 if (content_info->timeline == 0) {
1641                                         content_info->timeline = content_info->modified_time;
1642                                 } else {
1643                                         media_svc_debug("Timeline : %ld", content_info->timeline);
1644                                 }
1645                         }
1646                         /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
1647                 } else {
1648                         SAFE_FREE(err_attr_name);
1649                 }
1650
1651                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1652                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1653                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1654                         if (ret != MS_MEDIA_ERR_NONE)
1655                                 media_svc_error("strcpy error");
1656                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1657                         /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1658                 } else {
1659                         /*media_svc_debug("composer - unknown"); */
1660                         SAFE_FREE(err_attr_name);
1661                 }
1662
1663                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1664                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1665                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1666                         if (ret != MS_MEDIA_ERR_NONE)
1667                                 media_svc_error("strcpy error");
1668                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1669                         /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1670                 } else {
1671                         /*media_svc_debug("copyright - unknown"); */
1672                         SAFE_FREE(err_attr_name);
1673                 }
1674
1675                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1676                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1677                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1678                         if (ret != MS_MEDIA_ERR_NONE)
1679                                 media_svc_error("strcpy error");
1680                 } else {
1681                         SAFE_FREE(err_attr_name);
1682                 }
1683
1684                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1685                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
1686                         int year = 0;
1687                         if ((p != NULL) && (sscanf(p, "%d", &year))) {
1688                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1689                                 if (ret != MS_MEDIA_ERR_NONE)
1690                                         media_svc_error("strcpy error");
1691                         } else {
1692                                 media_svc_debug("Wrong Year Information [%s]", p);
1693                         }
1694                 } else {
1695                         SAFE_FREE(err_attr_name);
1696                 }
1697
1698                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1699                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1700                         content_info->media_meta.rating = atoi(p);
1701                 } else {
1702                         SAFE_FREE(err_attr_name);
1703                         content_info->media_meta.rating = 0;
1704                 }
1705
1706                 /*Initialize album_id to 0. below code will set the album_id*/
1707                 content_info->album_id = album_id;
1708                 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1709
1710                 if (ret != MS_MEDIA_ERR_NONE) {
1711                         if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1712                                 media_svc_debug("album does not exist. So start to make album art");
1713                                 extract_thumbnail = TRUE;
1714                                 append_album = TRUE;
1715                         } else {
1716                                 extract_thumbnail = TRUE;
1717                                 append_album = FALSE;
1718                         }
1719                 } else {
1720                         content_info->album_id = album_id;
1721                         append_album = FALSE;
1722
1723                         if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1724                             (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1725
1726                                 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1727                                 extract_thumbnail = TRUE;
1728                         } else {
1729                                 media_svc_debug("album already exists. don't need to make album art");
1730                                 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1731                                 media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, content_info);
1732                                 extract_thumbnail = TRUE;
1733                         }
1734                 }
1735
1736                 if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
1737                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1738                         if (mmf_error != MM_ERROR_NONE) {
1739                                 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1740                                 SAFE_FREE(err_attr_name);
1741                         } else {
1742                                 /*media_svc_debug("artwork size1 [%d]", size); */
1743                         }
1744
1745                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1746                         if (mmf_error != MM_ERROR_NONE) {
1747                                 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1748                                 SAFE_FREE(err_attr_name);
1749                         } else {
1750                                 /*media_svc_debug("artwork size2 [%d]", size); */
1751                         }
1752                         if (image != NULL && size > 0) {
1753                                 int ret = MS_MEDIA_ERR_NONE;
1754                                 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1755                                 int artwork_mime_size = -1;
1756
1757                                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1758                                 if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
1759                                         ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1760                                         if (ret != MS_MEDIA_ERR_NONE) {
1761                                                 media_svc_error("Fail to Get Thumbnail Path");
1762                                         }
1763                                 } else {
1764                                         SAFE_FREE(err_attr_name);
1765                                 }
1766
1767                                 if (strlen(thumb_path) > 0) {
1768                                         ret = _media_svc_save_image(image, size, thumb_path, uid);
1769                                         if (ret != MS_MEDIA_ERR_NONE) {
1770                                                 media_svc_error("Fail to Save Thumbnail Image");
1771                                         } else {
1772                                                 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1773                                                 if (ret != MS_MEDIA_ERR_NONE)
1774                                                         media_svc_error("strcpy error");
1775                                         }
1776                                 }
1777                         }
1778                 }
1779
1780                 if (append_album == TRUE) {
1781                         if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1782                             (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1783                                 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1784                         else
1785                                 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1786
1787                         content_info->album_id = album_id;
1788                 }
1789
1790                 if (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1791                         double longitude = 0.0;
1792                         double latitude = 0.0;
1793                         double altitude = 0.0;
1794
1795                         __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1796                         content_info->media_meta.longitude = longitude;
1797                         content_info->media_meta.latitude = latitude;
1798                         content_info->media_meta.altitude = altitude;
1799
1800                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1801                         if (mmf_error != MM_ERROR_NONE) {
1802                                 cdis_value = 0;
1803                                 SAFE_FREE(err_attr_name);
1804                         }
1805
1806                         media_svc_debug("CDIS : %d", cdis_value);
1807                 }
1808
1809                 mmf_error = mm_file_destroy_tag_attrs(tag);
1810                 if (mmf_error != MM_ERROR_NONE) {
1811                         media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1812                 }
1813         }       else {
1814                 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1815                 char *title = NULL;
1816                 media_svc_error("no tag information");
1817
1818                 title = _media_svc_get_title_from_filepath(content_info->path);
1819                 if (title) {
1820                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1821                         if (ret != MS_MEDIA_ERR_NONE)
1822                                 media_svc_error("strcpy error");
1823                         SAFE_FREE(title);
1824                 } else {
1825                         media_svc_error("Can't extract title");
1826                 }
1827
1828                 content_info->album_id = album_id;
1829         }
1830
1831         /*Get Content attribute ===========*/
1832         if (cdis_value == 1) {
1833                 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1834         } else {
1835                 mmf_error = mm_file_create_content_attrs(&content, content_info->path);
1836         }
1837
1838         if (mmf_error == MM_ERROR_NONE) {
1839                 /*Common attribute*/
1840                 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1841                 if (mmf_error != MM_ERROR_NONE) {
1842                         SAFE_FREE(err_attr_name);
1843                         media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1844                 } else {
1845                         /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1846                 }
1847
1848                 /*Sound/Music attribute*/
1849                 if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1850
1851                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1852                         if (mmf_error != MM_ERROR_NONE) {
1853                                 SAFE_FREE(err_attr_name);
1854                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1855                         } else {
1856                                 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1857                         }
1858
1859                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1860                         if (mmf_error != MM_ERROR_NONE) {
1861                                 SAFE_FREE(err_attr_name);
1862                                 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1863                         } else {
1864                                 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1865                         }
1866
1867                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1868                         if (mmf_error != MM_ERROR_NONE) {
1869                                 SAFE_FREE(err_attr_name);
1870                                 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1871                         } else {
1872                                 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1873                         }
1874
1875                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1876                         if (mmf_error != MM_ERROR_NONE) {
1877                                 SAFE_FREE(err_attr_name);
1878                                 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1879                         } else {
1880                                 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1881                         }
1882                 } else if (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)    {       /*Video attribute*/
1883                         int audio_bitrate = 0;
1884                         int video_bitrate = 0;
1885
1886                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1887                         if (mmf_error != MM_ERROR_NONE) {
1888                                 SAFE_FREE(err_attr_name);
1889                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1890                         } else {
1891                                 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1892                         }
1893
1894                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1895                         if (mmf_error != MM_ERROR_NONE) {
1896                                 SAFE_FREE(err_attr_name);
1897                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1898                         } else {
1899                                 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1900                         }
1901
1902                         content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1903
1904                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1905                         if (mmf_error != MM_ERROR_NONE) {
1906                                 SAFE_FREE(err_attr_name);
1907                                 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1908                         } else {
1909                                 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1910                         }
1911
1912                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1913                         if (mmf_error != MM_ERROR_NONE) {
1914                                 SAFE_FREE(err_attr_name);
1915                                 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1916                         } else {
1917                                 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1918                         }
1919
1920                 } else {
1921                         media_svc_error("Not support type");
1922                         mmf_error = mm_file_destroy_content_attrs(content);
1923                         if (mmf_error != MM_ERROR_NONE) {
1924                                 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1925                         }
1926                         return MS_MEDIA_ERR_INVALID_PARAMETER;
1927                 }
1928
1929                 mmf_error = mm_file_destroy_content_attrs(content);
1930                 if (mmf_error != MM_ERROR_NONE) {
1931                         media_svc_error("fail to free content attr - err(%x)", mmf_error);
1932                 }
1933         } else {
1934                 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1935         }
1936
1937         return MS_MEDIA_ERR_NONE;
1938 }
1939
1940 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1941 {
1942         media_svc_retm_if(content_info == NULL, "content info is NULL");
1943
1944         /* Delete media_svc_content_info_s */
1945         SAFE_FREE(content_info->media_uuid);
1946         SAFE_FREE(content_info->path);
1947         SAFE_FREE(content_info->file_name);
1948         SAFE_FREE(content_info->mime_type);
1949         SAFE_FREE(content_info->folder_uuid);
1950         SAFE_FREE(content_info->thumbnail_path);
1951
1952         /* Delete media_svc_content_meta_s */
1953         SAFE_FREE(content_info->media_meta.title);
1954         SAFE_FREE(content_info->media_meta.album);
1955         SAFE_FREE(content_info->media_meta.artist);
1956         SAFE_FREE(content_info->media_meta.album_artist);
1957         SAFE_FREE(content_info->media_meta.genre);
1958         SAFE_FREE(content_info->media_meta.composer);
1959         SAFE_FREE(content_info->media_meta.year);
1960         SAFE_FREE(content_info->media_meta.recorded_date);
1961         SAFE_FREE(content_info->media_meta.copyright);
1962         SAFE_FREE(content_info->media_meta.track_num);
1963         SAFE_FREE(content_info->media_meta.description);
1964         SAFE_FREE(content_info->media_meta.datetaken);
1965         SAFE_FREE(content_info->media_meta.exposure_time);
1966         SAFE_FREE(content_info->media_meta.model);
1967         SAFE_FREE(content_info->media_meta.weather);
1968
1969         SAFE_FREE(content_info->media_meta.title_pinyin);
1970         SAFE_FREE(content_info->media_meta.album_pinyin);
1971         SAFE_FREE(content_info->media_meta.artist_pinyin);
1972         SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1973         SAFE_FREE(content_info->media_meta.genre_pinyin);
1974         SAFE_FREE(content_info->media_meta.composer_pinyin);
1975         SAFE_FREE(content_info->media_meta.copyright_pinyin);
1976         SAFE_FREE(content_info->media_meta.description_pinyin);
1977
1978         return;
1979 }
1980
1981 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
1982 {
1983         if (STRING_VALID(path)) {
1984                 if (strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0) {
1985                         *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
1986                 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
1987                         *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
1988                 } else {
1989                         media_svc_error("Invalid Path");
1990                         return MS_MEDIA_ERR_INVALID_PARAMETER;
1991                 }
1992         } else {
1993                 media_svc_error("INVALID parameter");
1994                 return MS_MEDIA_ERR_INVALID_PARAMETER;
1995         }
1996
1997         return MS_MEDIA_ERR_NONE;
1998 }
1999
2000 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2001 {
2002         char *result, *sr;
2003         size_t i, count = 0;
2004         size_t oldlen = strlen(olds);
2005         if (oldlen < 1) return s;
2006         size_t newlen = strlen(news);
2007
2008         if (newlen != oldlen) {
2009                 for (i = 0; s[i] != '\0';) {
2010                         if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2011                         else i++;
2012                 }
2013         } else i = strlen(s);
2014
2015
2016         result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2017         if (result == NULL) return NULL;
2018
2019         sr = result;
2020         while (*s) {
2021                 if (memcmp(s, olds, oldlen) == 0) {
2022                         memcpy(sr, news, newlen);
2023                         sr += newlen;
2024                         s  += oldlen;
2025                 } else *sr++ = *s++;
2026         }
2027
2028         *sr = '\0';
2029
2030         return result;
2031 }
2032
2033 bool _media_svc_is_drm_file(const char *path)
2034 {
2035         return FALSE;
2036 }
2037
2038 int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
2039 {
2040         int ret = MS_MEDIA_ERR_NONE;
2041
2042         ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2043
2044         if (ret != MS_MEDIA_ERR_NONE) {
2045                 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2046                 ret = MS_MEDIA_ERR_INTERNAL;
2047         } else {
2048                 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2049         }
2050
2051         return ret;
2052 }
2053
2054 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2055 {
2056         int ret = MS_MEDIA_ERR_NONE;
2057         int size = 0;
2058         pinyin_name_s *pinyinname = NULL;
2059         *pinyin_str = NULL;
2060
2061         if (!STRING_VALID(src_str)) {
2062                 media_svc_debug("String is invalid");
2063                 return ret;
2064         }
2065
2066         ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2067         if (ret == MS_MEDIA_ERR_NONE) {
2068                 if (STRING_VALID(pinyinname[0].pinyin_name))
2069                         *pinyin_str = strdup(pinyinname[0].pinyin_name);
2070                 else
2071                         *pinyin_str = strdup(src_str);  /*Return Original Non China Character */
2072         }
2073
2074         _media_svc_pinyin_free(pinyinname, size);
2075
2076         return ret;
2077 }
2078
2079 bool _media_svc_check_pinyin_support(void)
2080 {
2081         /*Check CSC*/
2082         return TRUE;
2083 }
2084
2085 int _media_svc_request_extract_all_thumbs(uid_t uid)
2086 {
2087         int ret = MS_MEDIA_ERR_NONE;
2088
2089         ret = thumbnail_request_extract_all_thumbs(uid);
2090
2091         if (ret != MS_MEDIA_ERR_NONE) {
2092                 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2093                 ret = MS_MEDIA_ERR_INTERNAL;
2094         } else {
2095                 media_svc_sec_debug("thumbnail_request_extract_all_thumbs");
2096         }
2097
2098         return ret;
2099 }