4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
29 #include <libexif/exif-data.h>
30 #include <media-util.h>
31 #include <uuid/uuid.h>
32 #include <mm_util_magick.h>
33 #include <media-thumbnail.h>
34 #include "media-svc-util.h"
35 #include "media-svc-db-utils.h"
36 #include "media-svc-debug.h"
37 #include "media-svc-env.h"
38 #include "media-svc-album.h"
39 /*For ebook metadata */
41 #include <libxml/xmlmemory.h>
42 #include <libxml/parser.h>
43 #include <libxml/HTMLparser.h>
46 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
48 #define MUSIC_MIME_NUM 29
49 #define SOUND_MIME_NUM 2
50 #define MIME_LENGTH 50
51 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
52 #define IMAGE_PREFIX "image/"
53 #define IMAGE_PREFIX_LEN 6
54 #define AUDIO_PREFIX "audio/"
55 #define AUDIO_PREFIX_LEN 6
56 #define VIDEO_PREFIX "video/"
57 #define VIDEO_PREFIX_LEN 6
59 #define MEDIA_SVC_PDF_TAG_TAIL_LEN 12
60 #define MEDIA_SVC_PDF_BUF_SIZE 256
62 #define MEDIA_SVC_THUMB_WIDTH 320
63 #define MEDIA_SVC_THUMB_HEIGHT 240
65 #define PATH_PLUGIN_LIB PATH_LIBDIR"/libmedia-ebook-plugin.so"
67 enum Exif_Orientation {
79 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
80 /*known mime types of normal files*/
87 "x-mp3", /*alias of audio/mpeg*/
88 "x-mpeg", /*alias of audio/mpeg*/
90 "x-ogg", /*alias of audio/ogg*/
91 "vnd.ms-playready.media.pya:*.pya", /*playready*/
94 "x-m4a", /*alias of audio/mp4*/
95 /* below mimes are rare*/
105 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
106 "vorbis", /*alias of audio/x-vorbis+ogg*/
108 "x-mp2", /*alias of audio/mp2*/
109 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
110 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
114 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
115 "application/x-smaf",
119 static char *__media_info_generate_uuid(void)
122 char uuid_unparsed[37];
125 uuid_generate(uuid_value);
126 uuid_unparse(uuid_value, uuid_unparsed);
128 if (strlen(uuid_unparsed) < 36) {
129 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
133 return g_strdup(uuid_unparsed);
136 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, ExifTag tagtype)
139 ExifByteOrder mByteOrder;
141 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
143 entry = exif_data_get_entry(ed, tagtype);
144 media_svc_retv_if(!entry, MS_MEDIA_ERR_NONE);
147 case EXIF_TAG_ORIENTATION:
148 case EXIF_TAG_PIXEL_X_DIMENSION:
149 case EXIF_TAG_PIXEL_Y_DIMENSION:
150 media_svc_retvm_if(!i_value, MS_MEDIA_ERR_INVALID_PARAMETER, "i_value is NULL");
152 mByteOrder = exif_data_get_byte_order(ed);
153 short exif_value = exif_get_short(entry->data, mByteOrder);
154 *i_value = (int)exif_value;
157 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
159 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
160 buf[strlen(buf)] = '\0';
163 return MS_MEDIA_ERR_NONE;
166 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
172 media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
173 media_svc_retvm_if(!mime_type, MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is null");
174 media_svc_retvm_if(!media_type, MS_MEDIA_ERR_INVALID_PARAMETER, "media_type is null");
177 if (strncmp(mime_type, IMAGE_PREFIX, IMAGE_PREFIX_LEN) == 0) {
178 *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
179 return MS_MEDIA_ERR_NONE;
183 if (strncmp(mime_type, AUDIO_PREFIX, AUDIO_PREFIX_LEN) == 0) {
184 *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
186 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
187 if (strcmp(mime_type + AUDIO_PREFIX_LEN, music_mime_table[idx]) == 0) {
188 *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
193 /* audio/x-mpegurl : .m3u file (playlist file) */
194 if (strcmp(mime_type + AUDIO_PREFIX_LEN, "x-mpegurl") == 0)
195 *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
197 return MS_MEDIA_ERR_NONE;
201 if (strncmp(mime_type, VIDEO_PREFIX, VIDEO_PREFIX_LEN) == 0) {
202 *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
204 /*some video files don't have video stream. in this case it is categorize as music. */
205 if (strcmp(mime_type + VIDEO_PREFIX_LEN, "3gpp") == 0 ||
206 strcmp(mime_type + VIDEO_PREFIX_LEN, "mp4") == 0) {
207 if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
208 if (audio > 0 && video == 0)
209 *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
213 return MS_MEDIA_ERR_NONE;
217 *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
219 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
220 if (strcmp(mime_type, sound_mime_table[idx]) == 0) {
221 *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
222 return MS_MEDIA_ERR_NONE;
226 /*"asf" must check video stream and then categorize in directly. */
227 if (strcmp(mime_type, "application/vnd.ms-asf") == 0) {
228 if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
229 if (audio > 0 && video == 0)
230 *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
232 *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
235 return MS_MEDIA_ERR_NONE;
238 if (strcmp(mime_type, "application/epub+zip") == 0 || strcmp(mime_type, "application/pdf") == 0)
239 *media_type = MEDIA_SVC_MEDIA_TYPE_BOOK;
241 return MS_MEDIA_ERR_NONE;
244 static int __media_svc_get_mime_type(const char *path, char *mimetype)
246 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
248 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
249 media_svc_error("aul_get_mime_from_file fail");
250 return MS_MEDIA_ERR_INTERNAL;
253 return MS_MEDIA_ERR_NONE;
256 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
260 for (i = strlen(file_path); i >= 0; i--) {
261 if (file_path[i] == '.') {
262 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
266 if (file_path[i] == '/')
272 static int __media_svc_safe_atoi(char *buffer, int *si)
276 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
278 const long sl = strtol(buffer, &end, 10);
280 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
281 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
282 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
283 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
284 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
288 return MS_MEDIA_ERR_NONE;
291 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
293 int ret = MS_MEDIA_ERR_NONE;
295 char *thumb_path = NULL;
296 long bsize_kbytes = 0;
297 GError *error = NULL;
299 media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
300 media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
302 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
303 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
305 ret = statfs(thumb_path, &fs);
307 media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
309 bsize_kbytes = fs.f_bsize >> 10;
310 media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
312 if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
313 media_svc_error("g_file_set_contents faild:%s", error->message);
315 return MS_MEDIA_ERR_INTERNAL;
318 return MS_MEDIA_ERR_NONE;
321 static char *__media_svc_get_title_from_filepath(const char *path)
323 char *filename = NULL;
325 char *last_dot = NULL;
327 media_svc_retvm_if(!STRING_VALID(path), NULL, "Invalid path");
329 filename = g_path_get_basename(path);
331 last_dot = strrchr(filename, '.');
333 title = g_strndup(filename, last_dot - filename);
339 media_svc_debug("extract title is [%s]", title);
344 void _media_svc_remove_file(const char *path)
346 if (!STRING_VALID(path))
349 if (remove(path) != 0)
350 media_svc_stderror("fail to remove file result");
353 static int __media_svc_get_thumbnail_path(char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
355 int ret = MS_MEDIA_ERR_NONE;
356 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
357 g_autofree gchar *hash = NULL;
358 g_autofree gchar *thumb_dir = NULL;
360 ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
361 media_svc_retvm_if(!STRING_VALID(thumb_dir), ret, "ms_user_get_root_thumb_store_path failed");
362 media_svc_retvm_if(!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INTERNAL, "Not a directory");
364 memset(file_ext, 0, sizeof(file_ext));
365 if (!__media_svc_get_file_ext(pathname, file_ext))
366 media_svc_error("get file ext fail");
368 hash = g_compute_checksum_for_string(G_CHECKSUM_MD5, pathname, -1);
369 media_svc_retvm_if(!hash, MS_MEDIA_ERR_INTERNAL, "Failed to create hashname");
372 /* 'img_format' is mime-type */
373 if (!g_str_has_prefix(img_format, IMAGE_PREFIX) || strlen(img_format) == IMAGE_PREFIX_LEN) {
374 media_svc_error("Not proper img format");
375 return MS_MEDIA_ERR_INTERNAL;
378 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, img_format + IMAGE_PREFIX_LEN);
380 if (strcasecmp(file_ext, "PNG") == 0)
381 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
383 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
386 return MS_MEDIA_ERR_NONE;
389 int _media_svc_get_file_time(const char *full_path)
391 struct stat statbuf = { 0, };
393 if (stat(full_path, &statbuf) == -1) {
394 media_svc_stderror("stat fails.");
398 return statbuf.st_mtime;
401 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, const char *path, bool refresh)
403 int ret = MS_MEDIA_ERR_NONE;
404 char mime_type[256] = {0, };
405 media_svc_media_type_e media_type;
407 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
409 content_info->path = g_strdup(path);
410 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
413 memset(&st, 0, sizeof(struct stat));
414 if (stat(path, &st) == 0) {
415 content_info->modified_time = st.st_mtime;
416 content_info->timeline = content_info->modified_time;
417 content_info->size = st.st_size;
419 media_svc_stderror("stat failed");
422 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
424 media_svc_debug("refresh");
425 return MS_MEDIA_ERR_NONE;
428 content_info->storage_uuid = g_strdup(storage_id);
429 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
431 time(&content_info->added_time);
433 content_info->media_uuid = __media_info_generate_uuid();
434 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
436 content_info->file_name = g_path_get_basename(path);
437 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
439 ret = __media_svc_get_mime_type(path, mime_type);
440 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
442 media_svc_debug("mime [%s]", mime_type);
444 ret = __media_svc_get_media_type(path, mime_type, &media_type);
445 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
447 content_info->mime_type = g_strdup(mime_type);
448 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
450 media_svc_sec_debug("path[%s], media_type[%d]", path, media_type);
452 content_info->media_type = media_type;
454 return MS_MEDIA_ERR_NONE;
457 static char * __media_svc_get_title(MMHandleType tag, const char *path)
459 int ret = FILEINFO_ERROR_NONE;
465 ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
466 if (ret == FILEINFO_ERROR_NONE && size > 0) {
467 while(p && isspace(*p))
474 title = __media_svc_get_title_from_filepath(path);
478 media_svc_error("Can't extract title");
480 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
483 char * _media_svc_get_title_by_path(const char *path)
485 /* No MMHandleType in media-svc.c */
486 return __media_svc_get_title(NULL, path);
489 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
491 int orient_value = 0;
495 bool has_datetaken = false;
498 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
500 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
501 media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type [%d]", content_info->media_type);
502 media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
504 path = content_info->path;
505 content_info->media_meta.title = __media_svc_get_title(NULL, path);
507 /* Not used. But to preserved the behavior, set MEDIA_SVC_TAG_UNKNOWN. */
508 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
509 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
510 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
511 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
512 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
513 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
515 /* Load an ExifData object from an EXIF file */
516 ed = exif_data_new_from_file(path);
518 media_svc_sec_debug("There is no exif data in [ %s ]", path);
519 goto GET_WIDTH_HEIGHT;
522 memset(buf, 0x00, sizeof(buf));
523 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
524 if (strlen(buf) > 0) {
525 has_datetaken = true;
526 content_info->media_meta.datetaken = g_strdup(buf);
528 /* This is same as recorded_date */
529 content_info->media_meta.recorded_date = g_strdup(buf);
533 memset(buf, 0x00, sizeof(buf));
534 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
535 if (strlen(buf) > 0) {
536 has_datetaken = true;
537 content_info->media_meta.datetaken = g_strdup(buf);
539 /* This is same as recorded_date */
540 content_info->media_meta.recorded_date = g_strdup(buf);
544 if (content_info->media_meta.recorded_date == NULL)
545 content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
547 /* Get orientation value from exif. */
548 if (__media_svc_get_exif_info(ed, NULL, &orient_value, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
549 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
550 content_info->media_meta.orientation = orient_value;
553 /* Get width value from exif. */
554 if (__media_svc_get_exif_info(ed, NULL, &exif_width, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
556 content_info->media_meta.width = exif_width;
559 /* Get height value from exif. */
560 if (__media_svc_get_exif_info(ed, NULL, &exif_height, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
562 content_info->media_meta.height = exif_height;
570 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
571 /*Get image width, height*/
572 unsigned int img_width = 0;
573 unsigned int img_height = 0;
574 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
576 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
577 if (content_info->media_meta.width == 0)
578 content_info->media_meta.width = img_width;
580 if (content_info->media_meta.height == 0)
581 content_info->media_meta.height = img_height;
584 return MS_MEDIA_ERR_NONE;
587 static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
589 int ret = FILEINFO_ERROR_NONE;
593 ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
594 if (ret == FILEINFO_ERROR_NONE && size > 0)
597 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
600 int _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
602 MMHandleType tag = 0;
604 unsigned char *image = NULL;
605 unsigned int size = 0;
606 int mmf_error = FILEINFO_ERROR_NONE;
608 int ret = MS_MEDIA_ERR_NONE;
609 int convert_value = 0;
610 bool support_albumart = ms_user_thumb_support(uid, content_info->path);
612 /*Get Content Tag attribute ===========*/
613 if (support_albumart)
614 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
616 mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
618 if (mmf_error == FILEINFO_ERROR_NONE) {
619 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
620 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
621 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
622 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
623 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
624 content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
625 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
627 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
628 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
629 if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
630 /*Creation time format is 20130101 00:00:00 +0000. change it to 2013:01:01 00:00:00 +0000 like exif time format*/
631 char *p_value = g_strdelimit(g_strdup(p), "", ':');
632 content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value);
635 content_info->media_meta.recorded_date = g_strdup(p);
639 if (content_info->media_meta.recorded_date == NULL)
640 content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
642 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
643 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
644 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
645 content_info->media_meta.year = g_strdup(p);
648 if (!content_info->media_meta.year)
649 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
651 /*Do not extract artwork for the USB Storage content*/
652 if (support_albumart) {
653 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
654 if (mmf_error != FILEINFO_ERROR_NONE)
655 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
657 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
658 if (mmf_error != FILEINFO_ERROR_NONE)
659 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
661 if (image != NULL && size > 0) {
662 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
663 int artwork_mime_size = -1;
665 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
666 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
667 ret = __media_svc_get_thumbnail_path(thumb_path, content_info->path, p, uid);
668 if (ret != MS_MEDIA_ERR_NONE) {
669 media_svc_error("Fail to Get Thumbnail Path");
671 ret = __media_svc_save_image(image, size, thumb_path, uid);
672 if (ret != MS_MEDIA_ERR_NONE) {
673 media_svc_error("Fail to Save Image");
675 content_info->thumbnail_path = g_strdup(thumb_path);
682 /*Initialize album_id to 0. below code will set the album_id*/
683 content_info->album_id = album_id;
684 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
685 if (ret != MS_MEDIA_ERR_NONE) {
686 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
687 media_svc_debug("album does not exist. So start to make album art");
688 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
689 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
690 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
692 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
694 content_info->album_id = album_id;
697 content_info->album_id = album_id;
700 mmf_error = mm_file_destroy_tag_attrs(tag);
701 if (mmf_error != FILEINFO_ERROR_NONE)
702 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
704 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
705 content_info->album_id = album_id;
708 return MS_MEDIA_ERR_NONE;
711 int _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
713 int mmf_error = FILEINFO_ERROR_NONE;
714 MMHandleType tag = 0;
715 MMHandleType content = 0;
717 unsigned int size = 0;
719 mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
721 if (mmf_error == FILEINFO_ERROR_NONE) {
722 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
723 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
724 if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
725 /*Creation time format is 20130101 00:00:00 +0000. change it to 2013:01:01 00:00:00 +0000 like exif time format*/
726 char *p_value = g_strdelimit(g_strdup(p), "", ':');
727 content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value);
730 content_info->media_meta.recorded_date = g_strdup(p);
734 if (content_info->media_meta.recorded_date == NULL)
735 content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
736 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
738 mmf_error = mm_file_destroy_tag_attrs(tag);
739 if (mmf_error != FILEINFO_ERROR_NONE)
740 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
742 /*Get Content attribute ===========*/
743 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
744 media_svc_retvm_if(mmf_error != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_NONE, "mm_file_create_content_attrs failed");
746 mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width,
747 MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height,
750 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
751 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
752 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
753 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
754 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
755 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
756 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
757 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
758 content_info->album_id = 0;
760 return MS_MEDIA_ERR_NONE;
763 static gchar * __media_svc_get_zipfile_string(zip_t *z, const char *fname)
766 zip_int64_t index_num = 0;
767 zip_file_t *file = NULL;
768 zip_stat_t sb = {0, };
771 media_svc_retvm_if(!z, NULL, "z is NULL");
772 media_svc_retvm_if(!fname, NULL, "fname is NULL");
774 index_num = zip_name_locate(z, fname, ZIP_FL_NOCASE);
775 media_svc_retvm_if(index_num == -1, NULL, "fname is not exists [%s]", fname);
777 err = zip_stat_index(z, index_num, ZIP_STAT_SIZE, &sb);
778 media_svc_retvm_if(err == -1, NULL, "zip_stat_index failed");
780 file = zip_fopen_index(z, index_num, ZIP_FL_UNCHANGED);
781 media_svc_retvm_if(!file, NULL, "zip_fopen_index failed");
783 buf = g_malloc0(sb.size + 1);
785 err = zip_fread(file, buf, sb.size);
796 static xmlNodePtr __media_svc_find_node(xmlNodePtr node, const char *key)
798 xmlNodePtr tmp = NULL;
800 media_svc_retvm_if(!node, NULL, "node is NULL");
801 media_svc_retvm_if(!key, NULL, "key is NULL");
803 for (tmp = node->children; tmp; tmp = tmp->next) {
804 if (xmlIsBlankNode(tmp))
807 if (g_str_has_suffix((gchar *)tmp->name, key))
814 static char * __media_svc_remove_escape_c(const char *value)
820 media_svc_retv_if(!value, NULL);
824 for (i = 0; i < len; i++) {
825 if (value[i] != 10 && value[i] != 32) { // 10='\n' 32=' '
833 end = end - start + 1;
835 return g_strndup(value + start, end);
838 static char * __media_svc_find_and_get_value(xmlNodePtr node, const char *key)
840 xmlNodePtr tmp = NULL;
841 char *tmp_res = NULL;
844 media_svc_retvm_if(!node, NULL, "node is NULL");
845 media_svc_retvm_if(!key, NULL, "key is NULL");
847 for (tmp = node->children; tmp; tmp = tmp->next) {
848 if (xmlIsBlankNode(tmp))
852 tmp_res = __media_svc_find_and_get_value(tmp, key);
854 res = __media_svc_remove_escape_c(tmp_res);
860 if (g_str_has_suffix((gchar *)tmp->name, key))
861 return (char *)xmlNodeGetContent(tmp);
867 static gboolean __media_svc_get_epub_root_file(zip_t *z, char **opf_file)
870 gchar *tmp_buf = NULL;
871 xmlDocPtr doc = NULL;
872 xmlNodePtr node = NULL;
874 media_svc_retvm_if(!z, FALSE, "z is NULL");
875 media_svc_retvm_if(!opf_file, FALSE, "opf_file is NULL");
877 buf = __media_svc_get_zipfile_string(z, "META-INF/container.xml");
878 media_svc_retvm_if(!buf, FALSE, "buf is NULL");
880 tmp_buf = g_strrstr(buf, ">");
882 *(tmp_buf + 1) = '\0';
884 doc = xmlParseDoc((const xmlChar *)buf);
886 media_svc_retvm_if(!doc, FALSE, "doc is NULL");
888 node = xmlDocGetRootElement(doc);
889 node = __media_svc_find_node(node, "rootfiles");
890 node = __media_svc_find_node(node, "rootfile");
892 *opf_file = (char *)xmlGetProp(node, (const xmlChar *)"full-path");
893 media_svc_sec_debug("OPF [%s]", *opf_file);
899 static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_pdf, media_svc_content_info_s *content_info)
901 xmlDocPtr doc = NULL;
902 xmlNodePtr root = NULL;
904 media_svc_retvm_if(!buffer, FALSE, "buffer is NULL");
905 media_svc_retvm_if(!content_info, FALSE, "content_info is NULL");
907 doc = xmlParseDoc(buffer);
908 media_svc_retv_if(!doc, FALSE);
910 root = xmlDocGetRootElement(doc);
916 content_info->media_meta.title = __media_svc_find_and_get_value(root, "title");
917 if (is_pdf && !content_info->media_meta.title) {
922 content_info->media_meta.artist = __media_svc_find_and_get_value(root, "creator");
923 if (!content_info->media_meta.artist)
924 content_info->media_meta.artist = __media_svc_find_and_get_value(root, "author");
925 content_info->media_meta.genre = __media_svc_find_and_get_value(root, "subject");
926 content_info->media_meta.copyright = __media_svc_find_and_get_value(root, "publisher");
927 content_info->media_meta.recorded_date = __media_svc_find_and_get_value(root, "date");
934 static int __media_svc_get_epub_metadata(media_svc_content_info_s *content_info)
939 char *opf_path = NULL;
941 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
944 z = zip_open(content_info->path, ZIP_RDONLY, &err);
945 media_svc_retvm_if(err == -1, MS_MEDIA_ERR_INTERNAL, "zip_open failed");
947 //2. find and read opf file
948 if (!__media_svc_get_epub_root_file(z, &opf_path)) {
949 media_svc_error("__media_svc_get_epub_root_file failed");
951 return MS_MEDIA_ERR_INTERNAL;
955 buf = __media_svc_get_zipfile_string(z, opf_path);
958 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INTERNAL, "__media_svc_get_zipfile_string failed");
960 if (!__media_svc_get_xml_metadata((const xmlChar *)buf, FALSE, content_info))
961 media_svc_error("__media_svc_get_xml_metadata failed");
965 return MS_MEDIA_ERR_NONE;
968 static int __media_svc_get_pdf_metadata(media_svc_content_info_s *content_info)
974 int search_limit = 0;
975 char tmp[MEDIA_SVC_PDF_BUF_SIZE + 1] = {0, };
976 gchar *meta_buf = NULL;
979 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
980 media_svc_retvm_if(content_info->size < 256, MS_MEDIA_ERR_INTERNAL, "open failed");
982 fd = open(content_info->path, O_RDONLY);
983 media_svc_retvm_if(fd < 0, MS_MEDIA_ERR_INTERNAL, "open failed");
985 search_limit = content_info->size - MEDIA_SVC_PDF_TAG_TAIL_LEN;
987 while (cur_pos <= search_limit) {
988 if (lseek(fd, cur_pos, SEEK_SET) == -1)
991 memset(&tmp, 0x00, MEDIA_SVC_PDF_BUF_SIZE + 1);
993 if (read(fd, &tmp, MEDIA_SVC_PDF_BUF_SIZE) != MEDIA_SVC_PDF_BUF_SIZE) {
994 media_svc_error("read failed");
998 //1.Find <x:xmpmeta .. </x:xmpmeta> block
999 if (start_pos == 0 && (found = strstr(tmp, "<x:xmpmeta"))) {
1000 start_pos = cur_pos + (found - tmp);
1001 // media_svc_error("FIND START_POS[%d]", start_pos);
1006 if (start_pos != 0 && (found = strstr(tmp, "</x:xmpmeta>"))) {
1007 end_pos = cur_pos + (found - tmp) + MEDIA_SVC_PDF_TAG_TAIL_LEN;
1008 // media_svc_error("FIND END_POS[%d]", end_pos);
1012 //2.get metadata using xml parser
1013 if (start_pos && end_pos) {
1014 if (lseek(fd, start_pos, SEEK_SET) == -1)
1017 meta_buf = g_malloc0(end_pos - start_pos + 1);
1019 if (read(fd, meta_buf, end_pos - start_pos) == end_pos - start_pos) {
1020 if (__media_svc_get_xml_metadata((const xmlChar *)meta_buf, TRUE, content_info)) {
1038 return MS_MEDIA_ERR_NONE;
1041 int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info)
1043 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content info is NULL");
1045 if (g_str_has_suffix(content_info->mime_type, "epub+zip"))
1046 return __media_svc_get_epub_metadata(content_info);
1048 return __media_svc_get_pdf_metadata(content_info);
1051 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1053 media_svc_retm_if(!content_info, "content info is NULL");
1055 /* Delete media_svc_content_info_s */
1056 g_free(content_info->media_uuid);
1057 g_free(content_info->path);
1058 g_free(content_info->file_name);
1059 g_free(content_info->mime_type);
1060 g_free(content_info->thumbnail_path);
1061 g_free(content_info->storage_uuid);
1063 /* Delete media_svc_content_meta_s */
1064 g_free(content_info->media_meta.title);
1065 g_free(content_info->media_meta.album);
1066 g_free(content_info->media_meta.artist);
1067 g_free(content_info->media_meta.album_artist);
1068 g_free(content_info->media_meta.genre);
1069 g_free(content_info->media_meta.year);
1070 g_free(content_info->media_meta.recorded_date);
1071 g_free(content_info->media_meta.copyright);
1072 g_free(content_info->media_meta.track_num);
1073 g_free(content_info->media_meta.datetaken);
1076 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
1078 int ret = MS_MEDIA_ERR_NONE;
1080 media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
1081 media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
1082 media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
1084 if (!ms_user_thumb_support(uid, path)) {
1085 media_svc_sec_error("origin path(%s) is invalid", path);
1086 return MS_MEDIA_ERR_INVALID_PARAMETER;
1089 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1091 //1. make thumb path
1092 ret = __media_svc_get_thumbnail_path(thumb_path, path, NULL, uid);
1093 if (ret != MS_MEDIA_ERR_NONE) {
1094 media_svc_error("Failed to create thumbnail path[%d]", ret);
1095 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1100 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
1101 ret = create_image_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
1103 ret = create_video_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
1105 return (ret == THUMB_OK) ? MS_MEDIA_ERR_NONE : MS_MEDIA_ERR_INTERNAL;
1108 int _media_svc_get_media_type(const char *path, int *mediatype)
1110 int ret = MS_MEDIA_ERR_NONE;
1111 char mime_type[256] = {0};
1112 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1114 media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
1116 ret = __media_svc_get_mime_type(path, mime_type);
1117 if (ret == MS_MEDIA_ERR_NONE)
1118 __media_svc_get_media_type(path, mime_type, &media_type);
1120 media_svc_error("__media_svc_get_mime_type failed");
1122 *mediatype = media_type;
1127 bool _media_svc_is_keyword_included(const char *path, const char *keyword)
1130 void *handle = NULL;
1131 bool (*svc_search) (const char *, const char *);
1133 media_svc_retvm_if(!path, false, "Invalid path");
1134 media_svc_retvm_if(!keyword, false, "Invalid keyword");
1136 handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
1137 media_svc_retvm_if(!handle, false, "dlopen failed");
1139 if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
1140 svc_search = dlsym(handle, "media_svc_epub_is_keyword_included");
1142 svc_search = dlsym(handle, "media_svc_pdf_is_keyword_included");
1145 media_svc_error("dlsym failed - %s", dlerror());
1150 ret = svc_search(path, keyword);
1156 static int __media_svc_create_wordbook_db(const char *path, sqlite3 **handle)
1158 int ret = SQLITE_OK;
1159 sqlite3 *db_handle = NULL;
1162 ret = sqlite3_open_v2(path, &db_handle, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
1163 media_svc_retvm_if(ret != SQLITE_OK, ret, "sqlite3_open_v2 failed : %d", ret);
1165 ret = sqlite3_exec(db_handle, "PRAGMA journal_mode = OFF;", NULL, NULL, &err);
1166 if (ret != SQLITE_OK)
1169 ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS files(id integer primary key autoincrement, path text unique, validity integer default 1);", NULL, NULL, &err);
1170 if (ret != SQLITE_OK)
1173 ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS words(file_id integer, word text, frequency integer default 1, unique(file_id, word));", NULL, NULL, &err);
1174 if (ret != SQLITE_OK)
1177 ret = sqlite3_exec(db_handle, "CREATE TRIGGER IF NOT EXISTS TR_files_words DELETE ON files BEGIN DELETE FROM words WHERE file_id = old.id;END;", NULL, NULL, &err);
1178 if (ret != SQLITE_OK)
1181 *handle = db_handle;
1186 media_svc_error("sqlite3_exec failed : %s", err);
1187 SQLITE3_SAFE_FREE(err);
1188 sqlite3_close_v2(db_handle);
1193 static bool __media_svc_get_wordbook_handle(uid_t uid, sqlite3 **handle)
1195 int ret = SQLITE_OK;
1196 char *db_path = NULL;
1198 ms_user_get_wordbook_db_path(uid, &db_path);
1202 ret = sqlite3_open_v2(db_path, handle, SQLITE_OPEN_READWRITE, NULL);
1203 if (ret != SQLITE_OK) {
1204 ret = __media_svc_create_wordbook_db(db_path, handle);
1206 media_svc_retvm_if(ret != SQLITE_OK, false, "__media_svc_create_wordbook_db failed : %d", ret);
1208 ret = sqlite3_exec(*handle, "PRAGMA journal_mode = OFF;", NULL, NULL, NULL);
1209 if (ret != SQLITE_OK)
1210 media_svc_error("Failed to change journal mode [%d]", ret);
1216 static bool __media_svc_is_exist_in_wordbook(sqlite3 *db_handle, const char *path)
1218 int ret = SQLITE_OK;
1222 query = sqlite3_mprintf("UPDATE files SET validity=1 WHERE path = %Q", path);
1224 ret = sqlite3_exec(db_handle, query, NULL, NULL, &err);
1225 SQLITE3_SAFE_FREE(query);
1226 if (ret != SQLITE_OK) {
1227 media_svc_error("Query failed. [%s]", err);
1228 SQLITE3_SAFE_FREE(err);
1232 return sqlite3_changes(db_handle) > 0 ? true : false;
1235 static void __media_svc_insert_to_wordbook(sqlite3 *db_handle, const char *path)
1237 void *handle = NULL;
1238 void (*svc_update) (sqlite3 *, const char *);
1241 query = sqlite3_mprintf("INSERT INTO files(path) VALUES(%Q);", path);
1242 sqlite3_exec(db_handle, query, NULL, NULL, NULL);
1243 sqlite3_free(query);
1245 handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
1247 media_svc_error("dlopen failed");
1251 if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
1252 svc_update = dlsym(handle, "media_svc_epub_insert_to_db");
1254 svc_update = dlsym(handle, "media_svc_pdf_insert_to_db");
1257 media_svc_error("dlsym failed - %s", dlerror());
1262 svc_update(db_handle, path);
1266 void _media_svc_update_wordbook(const char *path, uid_t uid)
1268 sqlite3 *db_handle = NULL;
1271 media_svc_error("Invalid path");
1276 if (!__media_svc_get_wordbook_handle(uid, &db_handle))
1279 if (__media_svc_is_exist_in_wordbook(db_handle, path)) {
1280 sqlite3_close_v2(db_handle);
1284 // if no item, insert to db..
1285 __media_svc_insert_to_wordbook(db_handle, path);
1286 sqlite3_close_v2(db_handle);
1289 void _media_svc_clean_wordbook(uid_t uid)
1291 sqlite3 *db_handle = NULL;
1293 if (!__media_svc_get_wordbook_handle(uid, &db_handle))
1296 sqlite3_exec(db_handle, "DELETE FROM files where validity = 0;", NULL, NULL, NULL);
1297 sqlite3_exec(db_handle, "UPDATE files SET validity = 0;", NULL, NULL, NULL);
1298 sqlite3_close_v2(db_handle);
1301 bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list)
1303 int ret = SQLITE_OK;
1304 sqlite3 *handle = NULL;
1305 sqlite3_stmt *stmt = NULL;
1308 media_svc_retvm_if(!list, false, "list is NULL");
1309 media_svc_retvm_if(!keyword, false, "keyword is NULL");
1310 media_svc_retvm_if(!__media_svc_get_wordbook_handle(uid, &handle), false, "Failed to get handle");
1312 query = sqlite3_mprintf("SELECT files.path FROM files JOIN (SELECT file_id, sum(frequency) AS freq_sum FROM words WHERE word LIKE '%q%%' GROUP BY file_id ORDER BY freq_sum DESC) w ON files.id = w.file_id;", keyword);
1313 ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
1314 SQLITE3_SAFE_FREE(query);
1316 if (ret != SQLITE_OK) {
1317 media_svc_error("Query failed[%d]", ret);
1318 sqlite3_close_v2(handle);
1322 while (sqlite3_step(stmt) == SQLITE_ROW)
1323 *list = g_list_append(*list, g_strdup((char *)sqlite3_column_text(stmt, 0)));
1325 sqlite3_finalize(stmt);
1326 sqlite3_close_v2(handle);