"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "minidlna.c" between
minidlna-1.2.0.tar.gz and minidlna-1.2.1.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.

minidlna.c  (minidlna-1.2.0):minidlna.c  (minidlna-1.2.1)
skipping to change at line 258 skipping to change at line 258
struct passwd * pwent; struct passwd * pwent;
pwent = getpwuid(getuid()); pwent = getpwuid(getuid());
if (pwent) if (pwent)
logname = pwent->pw_name; logname = pwent->pw_name;
} }
#endif #endif
snprintf(buf+off, len-off, "%s", logname?logname:"Unknown"); snprintf(buf+off, len-off, "%s", logname?logname:"Unknown");
#endif #endif
} }
static time_t
_get_dbtime(void)
{
char path[PATH_MAX];
struct stat st;
snprintf(path, sizeof(path), "%s/files.db", db_path);
if (stat(path, &st) != 0)
return 0;
return st.st_mtime;
}
static int static int
open_db(sqlite3 **sq3) open_db(sqlite3 **sq3)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
int new_db = 0; int new_db = 0;
snprintf(path, sizeof(path), "%s/files.db", db_path); snprintf(path, sizeof(path), "%s/files.db", db_path);
if (access(path, F_OK) != 0) if (access(path, F_OK) != 0)
{ {
new_db = 1; new_db = 1;
skipping to change at line 298 skipping to change at line 310
char **result; char **result;
int i, rows = 0; int i, rows = 0;
int ret; int ret;
if (!new_db) if (!new_db)
{ {
/* Check if any new media dirs appeared */ /* Check if any new media dirs appeared */
media_path = media_dirs; media_path = media_dirs;
while (media_path) while (media_path)
{ {
ret = sql_get_int_field(db, "SELECT TIMESTAMP from DETAIL ret = sql_get_int_field(db, "SELECT TIMESTAMP as TYPE fro
S where PATH = %Q", media_path->path); m DETAILS where PATH = %Q",
media_path->path);
if (ret != media_path->types) if (ret != media_path->types)
{ {
ret = 1; ret = 1;
goto rescan; goto rescan;
} }
media_path = media_path->next; media_path = media_path->next;
} }
/* Check if any media dirs disappeared */ /* Check if any media dirs disappeared */
sql_get_table(db, "SELECT VALUE from SETTINGS where KEY = 'media_ dir'", &result, &rows, NULL); sql_get_table(db, "SELECT VALUE from SETTINGS where KEY = 'media_ dir'", &result, &rows, NULL);
for (i=1; i <= rows; i++) for (i=1; i <= rows; i++)
skipping to change at line 331 skipping to change at line 344
goto rescan; goto rescan;
} }
} }
sqlite3_free_table(result); sqlite3_free_table(result);
} }
ret = db_upgrade(db); ret = db_upgrade(db);
if (ret != 0) if (ret != 0)
{ {
rescan: rescan:
rescan_db = 0; CLEARFLAG(RESCAN_MASK);
if (ret < 0) if (ret < 0)
DPRINTF(E_WARN, L_GENERAL, "Creating new database at %s/f iles.db\n", db_path); DPRINTF(E_WARN, L_GENERAL, "Creating new database at %s/f iles.db\n", db_path);
else if (ret == 1) else if (ret == 1)
DPRINTF(E_WARN, L_GENERAL, "New media_dir detected; rebui lding...\n"); DPRINTF(E_WARN, L_GENERAL, "New media_dir detected; rebui lding...\n");
else if (ret == 2) else if (ret == 2)
DPRINTF(E_WARN, L_GENERAL, "Removed media_dir detected; r ebuilding...\n"); DPRINTF(E_WARN, L_GENERAL, "Removed media_dir detected; r ebuilding...\n");
else else
DPRINTF(E_WARN, L_GENERAL, "Database version mismatch (%d => %d); need to recreate...\n", DPRINTF(E_WARN, L_GENERAL, "Database version mismatch (%d => %d); need to recreate...\n",
ret, DB_VERSION); ret, DB_VERSION);
sqlite3_close(db); sqlite3_close(db);
snprintf(cmd, sizeof(cmd), "rm -rf %s/files.db %s/art_cache", db_ path, db_path); snprintf(cmd, sizeof(cmd), "rm -rf %s/files.db %s/art_cache", db_ path, db_path);
if (system(cmd) != 0) if (system(cmd) != 0)
DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cac he! Exiting...\n"); DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cac he! Exiting...\n");
open_db(&db); open_db(&db);
if (CreateDatabase() != 0) if (CreateDatabase() != 0)
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to create sqli te database! Exiting...\n"); DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to create sqli te database! Exiting...\n");
} }
if (ret || rescan_db) if (ret || GETFLAG(RESCAN_MASK))
{ {
#if USE_FORK #if USE_FORK
scanning = 1; SETFLAG(SCANNING_MASK);
sqlite3_close(db); sqlite3_close(db);
*scanner_pid = fork(); *scanner_pid = fork();
open_db(&db); open_db(&db);
if (*scanner_pid == 0) /* child (scanner) process */ if (*scanner_pid == 0) /* child (scanner) process */
{ {
start_scanner(); start_scanner();
sqlite3_close(db); sqlite3_close(db);
log_close(); log_close();
freeoptions(); freeoptions();
free(children); free(children);
skipping to change at line 596 skipping to change at line 609
if (*path == ',') if (*path == ',')
{ {
path++; path++;
break; break;
} }
else if (*path == 'A' || *path == 'a') else if (*path == 'A' || *path == 'a')
types |= TYPE_AUDIO; types |= TYPE_AUDIO;
else if (*path == 'V' || *path == 'v') else if (*path == 'V' || *path == 'v')
types |= TYPE_VIDEO; types |= TYPE_VIDEO;
else if (*path == 'P' || *path == 'p') else if (*path == 'P' || *path == 'p')
types |= TYPE_IMAGES; types |= TYPE_IMAGE;
else else
DPRINTF(E_FATAL, L_GENERAL, "Medi a directory entry not understood [%s]\n", DPRINTF(E_FATAL, L_GENERAL, "Medi a directory entry not understood [%s]\n",
ary_options[i].value); ary_options[i].value);
path++; path++;
} }
} }
path = realpath(path, buf); path = realpath(path, buf);
if (!path || access(path, F_OK) != 0) if (!path || access(path, F_OK) != 0)
{ {
DPRINTF(E_ERROR, L_GENERAL, "Media directory \"%s \" not accessible [%s]\n", DPRINTF(E_ERROR, L_GENERAL, "Media directory \"%s \" not accessible [%s]\n",
skipping to change at line 842 skipping to change at line 855
else else
DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]);
break; break;
case 'f': case 'f':
i++; /* discarding, the config file is already read */ i++; /* discarding, the config file is already read */
break; break;
case 'h': case 'h':
runtime_vars.port = -1; // triggers help display runtime_vars.port = -1; // triggers help display
break; break;
case 'r': case 'r':
rescan_db = 1; SETFLAG(RESCAN_MASK);
break; break;
case 'R': case 'R':
snprintf(buf, sizeof(buf), "rm -rf %s/files.db %s/art_cac he", db_path, db_path); snprintf(buf, sizeof(buf), "rm -rf %s/files.db %s/art_cac he", db_path, db_path);
if (system(buf) != 0) if (system(buf) != 0)
DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cache. EXITING\n"); DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cache. EXITING\n");
break; break;
case 'u': case 'u':
if (i+1 != argc) if (i+1 != argc)
{ {
i++; i++;
skipping to change at line 1015 skipping to change at line 1028
{ {
int ret, i; int ret, i;
int shttpl = -1; int shttpl = -1;
int smonitor = -1; int smonitor = -1;
LIST_HEAD(httplisthead, upnphttp) upnphttphead; LIST_HEAD(httplisthead, upnphttp) upnphttphead;
struct upnphttp * e = 0; struct upnphttp * e = 0;
struct upnphttp * next; struct upnphttp * next;
fd_set readset; /* for select() */ fd_set readset; /* for select() */
fd_set writeset; fd_set writeset;
struct timeval timeout, timeofday, lastnotifytime = {0, 0}; struct timeval timeout, timeofday, lastnotifytime = {0, 0};
time_t lastupdatetime = 0; time_t lastupdatetime = 0, lastdbtime = 0;
int max_fd = -1; int max_fd = -1;
int last_changecnt = 0; int last_changecnt = 0;
pid_t scanner_pid = 0; pid_t scanner_pid = 0;
pthread_t inotify_thread = 0; pthread_t inotify_thread = 0;
#ifdef TIVO_SUPPORT #ifdef TIVO_SUPPORT
uint8_t beacon_interval = 5; uint8_t beacon_interval = 5;
int sbeacon = -1; int sbeacon = -1;
struct sockaddr_in tivo_bcast; struct sockaddr_in tivo_bcast;
struct timeval lastbeacontime = {0, 0}; struct timeval lastbeacontime = {0, 0};
#endif #endif
skipping to change at line 1051 skipping to change at line 1064
LIST_INIT(&upnphttphead); LIST_INIT(&upnphttphead);
ret = open_db(NULL); ret = open_db(NULL);
if (ret == 0) if (ret == 0)
{ {
updateID = sql_get_int_field(db, "SELECT VALUE from SETTINGS wher e KEY = 'UPDATE_ID'"); updateID = sql_get_int_field(db, "SELECT VALUE from SETTINGS wher e KEY = 'UPDATE_ID'");
if (updateID == -1) if (updateID == -1)
ret = -1; ret = -1;
} }
check_db(db, ret, &scanner_pid); check_db(db, ret, &scanner_pid);
lastdbtime = _get_dbtime();
#ifdef HAVE_INOTIFY #ifdef HAVE_INOTIFY
if( GETFLAG(INOTIFY_MASK) ) if( GETFLAG(INOTIFY_MASK) )
{ {
if (!sqlite3_threadsafe() || sqlite3_libversion_number() < 300500 1) if (!sqlite3_threadsafe() || sqlite3_libversion_number() < 300500 1)
DPRINTF(E_ERROR, L_GENERAL, "SQLite library is not thread safe! " DPRINTF(E_ERROR, L_GENERAL, "SQLite library is not thread safe! "
"Inotify will be disabled.\n" ); "Inotify will be disabled.\n" );
else if (pthread_create(&inotify_thread, NULL, start_inotify, NUL L) != 0) else if (pthread_create(&inotify_thread, NULL, start_inotify, NUL L) != 0)
DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() fail ed for start_inotify. EXITING\n"); DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() fail ed for start_inotify. EXITING\n");
} }
#endif #endif
skipping to change at line 1168 skipping to change at line 1182
* then every minute or so thereafter. */ * then every minute or so thereafter. */
if (beacon_interval == 5 && (timeofday.tv _sec - startup_time) > 60) if (beacon_interval == 5 && (timeofday.tv _sec - startup_time) > 60)
beacon_interval = 60; beacon_interval = 60;
} }
else if (timeout.tv_sec > (lastbeacontime.tv_sec + beacon_interval + 1 - timeofday.tv_sec)) else if (timeout.tv_sec > (lastbeacontime.tv_sec + beacon_interval + 1 - timeofday.tv_sec))
timeout.tv_sec = lastbeacontime.tv_sec + beacon_interval - timeofday.tv_sec; timeout.tv_sec = lastbeacontime.tv_sec + beacon_interval - timeofday.tv_sec;
} }
#endif #endif
} }
if (scanning) if (GETFLAG(SCANNING_MASK))
{ {
if (!scanner_pid || kill(scanner_pid, 0) != 0) if (!scanner_pid || kill(scanner_pid, 0) != 0)
{ {
scanning = 0; CLEARFLAG(SCANNING_MASK);
updateID++; if (_get_dbtime() != lastdbtime)
updateID++;
} }
} }
/* select open sockets (SSDP, HTTP listen, and all HTTP soap sock ets) */ /* select open sockets (SSDP, HTTP listen, and all HTTP soap sock ets) */
FD_ZERO(&readset); FD_ZERO(&readset);
if (sssdp >= 0) if (sssdp >= 0)
{ {
FD_SET(sssdp, &readset); FD_SET(sssdp, &readset);
max_fd = MAX(max_fd, sssdp); max_fd = MAX(max_fd, sssdp);
skipping to change at line 1247 skipping to change at line 1262
} }
#endif #endif
if (smonitor >= 0 && FD_ISSET(smonitor, &readset)) if (smonitor >= 0 && FD_ISSET(smonitor, &readset))
{ {
ProcessMonitorEvent(smonitor); ProcessMonitorEvent(smonitor);
} }
/* increment SystemUpdateID if the content database has changed, /* increment SystemUpdateID if the content database has changed,
* and if there is an active HTTP connection, at most once every 2 seconds */ * and if there is an active HTTP connection, at most once every 2 seconds */
if (i && (timeofday.tv_sec >= (lastupdatetime + 2))) if (i && (timeofday.tv_sec >= (lastupdatetime + 2)))
{ {
if (scanning || sqlite3_total_changes(db) != last_changec if (GETFLAG(SCANNING_MASK))
nt) {
time_t dbtime = _get_dbtime();
if (dbtime != lastdbtime)
{
lastdbtime = dbtime;
last_changecnt = -1;
}
}
if (sqlite3_total_changes(db) != last_changecnt)
{ {
updateID++; updateID++;
last_changecnt = sqlite3_total_changes(db); last_changecnt = sqlite3_total_changes(db);
upnp_event_var_change_notify(EContentDirectory); upnp_event_var_change_notify(EContentDirectory);
lastupdatetime = timeofday.tv_sec; lastupdatetime = timeofday.tv_sec;
} }
} }
/* process active HTTP connections */ /* process active HTTP connections */
for (e = upnphttphead.lh_first; e != NULL; e = e->entries.le_next ) for (e = upnphttphead.lh_first; e != NULL; e = e->entries.le_next )
{ {
skipping to change at line 1311 skipping to change at line 1335
if(e->state >= 100) if(e->state >= 100)
{ {
LIST_REMOVE(e, entries); LIST_REMOVE(e, entries);
Delete_upnphttp(e); Delete_upnphttp(e);
} }
} }
} }
shutdown: shutdown:
/* kill the scanner */ /* kill the scanner */
if (scanning && scanner_pid) if (GETFLAG(SCANNING_MASK) && scanner_pid)
kill(scanner_pid, SIGKILL); kill(scanner_pid, SIGKILL);
/* close out open sockets */ /* close out open sockets */
while (upnphttphead.lh_first != NULL) while (upnphttphead.lh_first != NULL)
{ {
e = upnphttphead.lh_first; e = upnphttphead.lh_first;
LIST_REMOVE(e, entries); LIST_REMOVE(e, entries);
Delete_upnphttp(e); Delete_upnphttp(e);
} }
if (sssdp >= 0) if (sssdp >= 0)
skipping to change at line 1339 skipping to change at line 1363
if (smonitor >= 0) if (smonitor >= 0)
close(smonitor); close(smonitor);
for (i = 0; i < n_lan_addr; i++) for (i = 0; i < n_lan_addr; i++)
{ {
SendSSDPGoodbyes(lan_addr[i].snotify); SendSSDPGoodbyes(lan_addr[i].snotify);
close(lan_addr[i].snotify); close(lan_addr[i].snotify);
} }
if (inotify_thread) if (inotify_thread)
{
pthread_kill(inotify_thread, SIGCHLD);
pthread_join(inotify_thread, NULL); pthread_join(inotify_thread, NULL);
}
/* kill other child processes */ /* kill other child processes */
process_reap_children(); process_reap_children();
free(children); free(children);
sql_exec(db, "UPDATE SETTINGS set VALUE = '%u' where KEY = 'UPDATE_ID'", updateID); sql_exec(db, "UPDATE SETTINGS set VALUE = '%u' where KEY = 'UPDATE_ID'", updateID);
sqlite3_close(db); sqlite3_close(db);
upnpevents_removeSubscribers(); upnpevents_removeSubscribers();
 End of changes. 15 change blocks. 
14 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)