"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scanner.c" between
minidlna-1.1.5.tar.gz and minidlna-1.2.0.tar.gz

About: ReadyMedia (formerly known as MiniDLNA) is a simple media server software, with the aim of being fully compliant with DLNA/UPnP-AV clients.

scanner.c  (minidlna-1.1.5):scanner.c  (minidlna-1.2.0)
/* MiniDLNA media server /* MiniDLNA media server
* Copyright (C) 2008-2009 Justin Maggard * Copyright (C) 2008-2017 Justin Maggard
* *
* This file is part of MiniDLNA. * This file is part of MiniDLNA.
* *
* MiniDLNA is free software; you can redistribute it and/or modify * MiniDLNA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* MiniDLNA is distributed in the hope that it will be useful, * MiniDLNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
skipping to change at line 49 skipping to change at line 49
#include "scanner_sqlite.h" #include "scanner_sqlite.h"
#include "upnpglobalvars.h" #include "upnpglobalvars.h"
#include "metadata.h" #include "metadata.h"
#include "playlist.h" #include "playlist.h"
#include "utils.h" #include "utils.h"
#include "sql.h" #include "sql.h"
#include "scanner.h" #include "scanner.h"
#include "albumart.h" #include "albumart.h"
#include "containers.h" #include "containers.h"
#include "log.h" #include "log.h"
#include "monitor.h"
#if SCANDIR_CONST #if SCANDIR_CONST
typedef const struct dirent scan_filter; typedef const struct dirent scan_filter;
#else #else
typedef struct dirent scan_filter; typedef struct dirent scan_filter;
#endif #endif
#ifndef AV_LOG_PANIC #ifndef AV_LOG_PANIC
#define AV_LOG_PANIC AV_LOG_FATAL #define AV_LOG_PANIC AV_LOG_FATAL
#endif #endif
skipping to change at line 97 skipping to change at line 98
int int
insert_container(const char *item, const char *rootParent, const char *refID, co nst char *class, insert_container(const char *item, const char *rootParent, const char *refID, co nst char *class,
const char *artist, const char *genre, const char *album_art, i nt64_t *objectID, int64_t *parentID) const char *artist, const char *genre, const char *album_art, i nt64_t *objectID, int64_t *parentID)
{ {
char *result; char *result;
char *base; char *base;
int ret = 0; int ret = 0;
result = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS o " result = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS o "
"left join DETAILS d on (o.DETAIL_ID = d. "left join DETAILS d on (o.DETAIL_ID = d.
ID)" ID)"
" where o.PARENT_ID = '%s'" " where o.PARENT_ID = '%s'"
" and o.NAME like '%q'" " and o.NAME like '%q'"
" and d.ARTIST %s %Q" " and d.ARTIST %s %Q"
" and o.CLASS = 'container.%s' limit 1", " and o.CLASS = 'container.%s' limit 1",
rootParent, item, artist?"like":"is", art rootParent, item, artist?"like":"is", art
ist, class); ist, class);
if( result ) if( result )
{ {
base = strrchr(result, '$'); base = strrchr(result, '$');
if( base ) if( base )
*parentID = strtoll(base+1, NULL, 16); *parentID = strtoll(base+1, NULL, 16);
else else
*parentID = 0; *parentID = 0;
*objectID = get_next_available_id("OBJECTS", result); *objectID = get_next_available_id("OBJECTS", result);
} }
else else
skipping to change at line 400 skipping to change at line 401
char class[] = "container.storageFolder"; char class[] = "container.storageFolder";
char *result, *p; char *result, *p;
static char last_found[256] = "-1"; static char last_found[256] = "-1";
if( strcmp(base, BROWSEDIR_ID) != 0 ) if( strcmp(base, BROWSEDIR_ID) != 0 )
{ {
int found = 0; int found = 0;
char id_buf[64], parent_buf[64], refID[64]; char id_buf[64], parent_buf[64], refID[64];
char *dir_buf, *dir; char *dir_buf, *dir;
dir_buf = strdup(path); dir_buf = strdup(path);
dir = dirname(dir_buf); dir = dirname(dir_buf);
snprintf(refID, sizeof(refID), "%s%s$%X", BROWSEDIR_ID, parentID, objectID); snprintf(refID, sizeof(refID), "%s%s$%X", BROWSEDIR_ID, parentID, objectID);
snprintf(id_buf, sizeof(id_buf), "%s%s$%X", base, parentID, objec tID); snprintf(id_buf, sizeof(id_buf), "%s%s$%X", base, parentID, objec tID);
snprintf(parent_buf, sizeof(parent_buf), "%s%s", base, parentID); snprintf(parent_buf, sizeof(parent_buf), "%s%s", base, parentID);
while( !found ) while( !found )
{ {
if( valid_cache && strcmp(id_buf, last_found) == 0 ) if( valid_cache && strcmp(id_buf, last_found) == 0 )
break; break;
if( sql_get_int_field(db, "SELECT count(*) from OBJECTS w here OBJECT_ID = '%s'", id_buf) > 0 ) if( sql_get_int_field(db, "SELECT count(*) from OBJECTS w here OBJECT_ID = '%s'", id_buf) > 0 )
{ {
skipping to change at line 469 skipping to change at line 470
if( (types & TYPE_IMAGES) && is_image(name) ) if( (types & TYPE_IMAGES) && is_image(name) )
{ {
if( is_album_art(name) ) if( is_album_art(name) )
return -1; return -1;
strcpy(base, IMAGE_DIR_ID); strcpy(base, IMAGE_DIR_ID);
strcpy(class, "item.imageItem.photo"); strcpy(class, "item.imageItem.photo");
detailID = GetImageMetadata(path, name); detailID = GetImageMetadata(path, name);
} }
else if( (types & TYPE_VIDEO) && is_video(name) ) else if( (types & TYPE_VIDEO) && is_video(name) )
{ {
orig_name = strdup(name); orig_name = strdup(name);
strcpy(base, VIDEO_DIR_ID); strcpy(base, VIDEO_DIR_ID);
strcpy(class, "item.videoItem"); strcpy(class, "item.videoItem");
detailID = GetVideoMetadata(path, name); detailID = GetVideoMetadata(path, name);
if( !detailID ) if( !detailID )
strcpy(name, orig_name); strcpy(name, orig_name);
} }
else if( is_playlist(name) ) else if( is_playlist(name) )
{ {
if( insert_playlist(path, name) == 0 ) if( insert_playlist(path, name) == 0 )
return 1; return 1;
skipping to change at line 597 skipping to change at line 598
if (!magic->name) if (!magic->name)
continue; continue;
if( sql_get_int_field(db, "SELECT 1 from OBJECTS where OBJECT_ID = '%s'", magic->objectid_match) == 0 ) if( sql_get_int_field(db, "SELECT 1 from OBJECTS where OBJECT_ID = '%s'", magic->objectid_match) == 0 )
{ {
char *parent = strdup(magic->objectid_match); char *parent = strdup(magic->objectid_match);
if (strrchr(parent, '$')) if (strrchr(parent, '$'))
*strrchr(parent, '$') = '\0'; *strrchr(parent, '$') = '\0';
ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PAREN T_ID, DETAIL_ID, CLASS, NAME)" ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PAREN T_ID, DETAIL_ID, CLASS, NAME)"
" values " " values "
"('%s', '%s', %lld, 'container.storage Folder', '%q')", "('%s', '%s', %lld, 'container.storage Folder', '%q')",
magic->objectid_match, parent, GetFold magic->objectid_match, parent,
erMetadata(magic->name, NULL, NULL, NULL, 0), magic->name); GetFolderMetadata(_(magic->name), NULL
, NULL, NULL, 0), _(magic->name));
free(parent); free(parent);
if( ret != SQLITE_OK ) if( ret != SQLITE_OK )
goto sql_failed; goto sql_failed;
} }
} }
sql_exec(db, "create INDEX IDX_OBJECTS_OBJECT_ID ON OBJECTS(OBJECT_ID);") ; sql_exec(db, "create INDEX IDX_OBJECTS_OBJECT_ID ON OBJECTS(OBJECT_ID);") ;
sql_exec(db, "create INDEX IDX_OBJECTS_PARENT_ID ON OBJECTS(PARENT_ID);") ; sql_exec(db, "create INDEX IDX_OBJECTS_PARENT_ID ON OBJECTS(PARENT_ID);") ;
sql_exec(db, "create INDEX IDX_OBJECTS_DETAIL_ID ON OBJECTS(DETAIL_ID);") ; sql_exec(db, "create INDEX IDX_OBJECTS_DETAIL_ID ON OBJECTS(DETAIL_ID);") ;
sql_exec(db, "create INDEX IDX_OBJECTS_CLASS ON OBJECTS(CLASS);"); sql_exec(db, "create INDEX IDX_OBJECTS_CLASS ON OBJECTS(CLASS);");
sql_exec(db, "create INDEX IDX_DETAILS_PATH ON DETAILS(PATH);"); sql_exec(db, "create INDEX IDX_DETAILS_PATH ON DETAILS(PATH);");
skipping to change at line 839 skipping to change at line 841
static void static void
_notify_stop(void) _notify_stop(void)
{ {
#ifdef READYNAS #ifdef READYNAS
if( access("/ramfs/.rescan_done", F_OK) == 0 ) if( access("/ramfs/.rescan_done", F_OK) == 0 )
system("/bin/sh /ramfs/.rescan_done"); system("/bin/sh /ramfs/.rescan_done");
unlink("/ramfs/.upnp-av_scan"); unlink("/ramfs/.upnp-av_scan");
#endif #endif
} }
/* rescan functions added by shrimpkin@sourceforge.net */
static int
cb_orphans(void *args, int argc, char **argv, char **azColName)
{
const char *path = argv[0];
const char *mime = argv[1];
/* If we can't access the path, remove it */
if (access(path, R_OK) != 0)
{
DPRINTF(E_DEBUG, L_SCANNER, "Removing %s [%s]\n", path, mime ? "f
ile" : "dir");
if (mime)
monitor_remove_file(path);
else
monitor_remove_directory(0, path);
}
return 0;
}
void
start_rescan(void)
{
struct media_dir_s *media_path;
char *esc_name = NULL;
char *zErrMsg;
const char *sql_files = "SELECT path, mime FROM details WHERE path NOT NU
LL AND mime IS NOT NULL;";
const char *sql_dir = "SELECT path, mime FROM details WHERE path NOT NULL
AND mime IS NULL;";
int ret;
DPRINTF(E_INFO, L_SCANNER, "Starting rescan\n");
/* Find and remove any dead directory links */
ret = sqlite3_exec(db, sql_dir, cb_orphans, NULL, &zErrMsg);
if (ret != SQLITE_OK)
{
DPRINTF(E_MAXDEBUG, L_SCANNER, "SQL error: %s\nBAD SQL: %s\n", zE
rrMsg, sql_dir);
sqlite3_free(zErrMsg);
}
/* Find and remove any dead file links */
ret = sqlite3_exec(db, sql_files, cb_orphans, NULL, &zErrMsg);
if (ret != SQLITE_OK)
{
DPRINTF(E_MAXDEBUG, L_SCANNER, "SQL error: %s\nBAD SQL: %s\n", zE
rrMsg, sql_files);
sqlite3_free(zErrMsg);
}
/* Rescan media_paths for new and/or modified files */
for (media_path = media_dirs; media_path != NULL; media_path = media_path
->next)
{
char path[MAXPATHLEN], buf[MAXPATHLEN];
strncpyt(path, media_path->path, sizeof(path));
strncpyt(buf, media_path->path, sizeof(buf));
esc_name = escape_tag(basename(buf), 1);
monitor_insert_directory(0, esc_name, path);
free(esc_name);
}
DPRINTF(E_INFO, L_SCANNER, "Rescan completed\n");
}
/* end rescan functions */
void void
start_scanner() start_scanner()
{ {
struct media_dir_s *media_path; struct media_dir_s *media_path;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
if (setpriority(PRIO_PROCESS, 0, 15) == -1) if (setpriority(PRIO_PROCESS, 0, 15) == -1)
DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread prio rity\n"); DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread prio rity\n");
_notify_start();
setlocale(LC_COLLATE, ""); setlocale(LC_COLLATE, "");
av_register_all(); av_register_all();
av_log_set_level(AV_LOG_PANIC); av_log_set_level(AV_LOG_PANIC);
if( rescan_db )
{
start_rescan();
return;
}
_notify_start();
for( media_path = media_dirs; media_path != NULL; media_path = media_path ->next ) for( media_path = media_dirs; media_path != NULL; media_path = media_path ->next )
{ {
int64_t id; int64_t id;
char *bname, *parent = NULL; char *bname, *parent = NULL;
char buf[8]; char buf[8];
strncpyt(path, media_path->path, sizeof(path)); strncpyt(path, media_path->path, sizeof(path));
bname = basename(path); bname = basename(path);
/* If there are multiple media locations, add a level to the Cont entDirectory */ /* If there are multiple media locations, add a level to the Cont entDirectory */
if( !GETFLAG(MERGE_MEDIA_DIRS_MASK) && media_dirs->next ) if( !GETFLAG(MERGE_MEDIA_DIRS_MASK) && media_dirs->next )
{ {
 End of changes. 9 change blocks. 
14 lines changed or deleted 89 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS