"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "minidlna.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.

minidlna.c  (minidlna-1.1.5):minidlna.c  (minidlna-1.2.0)
skipping to change at line 93 skipping to change at line 93
#include "minidlnapath.h" #include "minidlnapath.h"
#include "getifaddr.h" #include "getifaddr.h"
#include "upnpsoap.h" #include "upnpsoap.h"
#include "options.h" #include "options.h"
#include "utils.h" #include "utils.h"
#include "minissdp.h" #include "minissdp.h"
#include "minidlnatypes.h" #include "minidlnatypes.h"
#include "process.h" #include "process.h"
#include "upnpevents.h" #include "upnpevents.h"
#include "scanner.h" #include "scanner.h"
#include "inotify.h" #include "monitor.h"
#include "log.h" #include "log.h"
#include "tivo_beacon.h" #include "tivo_beacon.h"
#include "tivo_utils.h" #include "tivo_utils.h"
#include "avahi.h"
#if SQLITE_VERSION_NUMBER < 3005001 #if SQLITE_VERSION_NUMBER < 3005001
# warning "Your SQLite3 library appears to be too old! Please use 3.5.1 or newe r." # warning "Your SQLite3 library appears to be too old! Please use 3.5.1 or newe r."
# define sqlite3_threadsafe() 0 # define sqlite3_threadsafe() 0
#endif #endif
/* OpenAndConfHTTPSocket() : /* OpenAndConfHTTPSocket() :
* setup the socket used to handle incoming HTTP connections. */ * setup the socket used to handle incoming HTTP connections. */
static int static int
OpenAndConfHTTPSocket(unsigned short port) OpenAndConfHTTPSocket(unsigned short port)
skipping to change at line 137 skipping to change at line 138
listenname.sin_port = htons(port); listenname.sin_port = htons(port);
listenname.sin_addr.s_addr = htonl(INADDR_ANY); listenname.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(s, (struct sockaddr *)&listenname, sizeof(struct sockaddr_in)) < 0) if (bind(s, (struct sockaddr *)&listenname, sizeof(struct sockaddr_in)) < 0)
{ {
DPRINTF(E_ERROR, L_GENERAL, "bind(http): %s\n", strerror(errno)); DPRINTF(E_ERROR, L_GENERAL, "bind(http): %s\n", strerror(errno));
close(s); close(s);
return -1; return -1;
} }
if (listen(s, 6) < 0) if (listen(s, 16) < 0)
{ {
DPRINTF(E_ERROR, L_GENERAL, "listen(http): %s\n", strerror(errno) ); DPRINTF(E_ERROR, L_GENERAL, "listen(http): %s\n", strerror(errno) );
close(s); close(s);
return -1; return -1;
} }
return s; return s;
} }
/* Handler for the SIGTERM signal (kill) /* Handler for the SIGTERM signal (kill)
skipping to change at line 241 skipping to change at line 242
char mac_str[13]; char mac_str[13];
if (getsyshwaddr(mac_str, sizeof(mac_str)) == 0) if (getsyshwaddr(mac_str, sizeof(mac_str)) == 0)
strcpy(serialnumber, mac_str); strcpy(serialnumber, mac_str);
else else
strcpy(serialnumber, "0"); strcpy(serialnumber, "0");
} }
break; break;
} }
} }
fclose(info); fclose(info);
#if PNPX
memcpy(pnpx_hwid+4, "01F2", 4);
if (strcmp(modelnumber, "NVX") == 0)
memcpy(pnpx_hwid+17, "0101", 4);
else if (strcmp(modelnumber, "Pro") == 0 ||
strcmp(modelnumber, "Pro 6") == 0 ||
strncmp(modelnumber, "Ultra 6", 7) == 0)
memcpy(pnpx_hwid+17, "0102", 4);
else if (strcmp(modelnumber, "Pro 2") == 0 ||
strncmp(modelnumber, "Ultra 2", 7) == 0)
memcpy(pnpx_hwid+17, "0103", 4);
else if (strcmp(modelnumber, "Pro 4") == 0 ||
strncmp(modelnumber, "Ultra 4", 7) == 0)
memcpy(pnpx_hwid+17, "0104", 4);
else if (strcmp(modelnumber+1, "100") == 0)
memcpy(pnpx_hwid+17, "0105", 4);
else if (strcmp(modelnumber+1, "200") == 0)
memcpy(pnpx_hwid+17, "0106", 4);
/* 0107 = Stora */
else if (strcmp(modelnumber, "Duo v2") == 0)
memcpy(pnpx_hwid+17, "0108", 4);
else if (strcmp(modelnumber, "NV+ v2") == 0)
memcpy(pnpx_hwid+17, "0109", 4);
#endif
#else #else
char * logname; char * logname;
logname = getenv("LOGNAME"); logname = getenv("LOGNAME");
#ifndef STATIC // Disable for static linking #ifndef STATIC // Disable for static linking
if (!logname) if (!logname)
{ {
struct passwd * pwent; struct passwd * pwent;
pwent = getpwuid(getuid()); pwent = getpwuid(getuid());
if (pwent) if (pwent)
logname = pwent->pw_name; logname = pwent->pw_name;
skipping to change at line 354 skipping to change at line 331
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;
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; resca nning...\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 escanning...\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 USE_FORK #if USE_FORK
scanning = 1; scanning = 1;
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();
skipping to change at line 471 skipping to change at line 452
static int strtobool(const char *str) static int strtobool(const char *str)
{ {
return ((strcasecmp(str, "yes") == 0) || return ((strcasecmp(str, "yes") == 0) ||
(strcasecmp(str, "true") == 0) || (strcasecmp(str, "true") == 0) ||
(atoi(str) == 1)); (atoi(str) == 1));
} }
static void init_nls(void) static void init_nls(void)
{ {
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
setlocale(LC_MESSAGES, ""); const char *messages, *ctype, *locale_dir;
setlocale(LC_CTYPE, "en_US.utf8");
DPRINTF(E_DEBUG, L_GENERAL, "Using locale dir %s\n", bindtextdomain("mini ctype = setlocale(LC_CTYPE, "");
dlna", getenv("TEXTDOMAINDIR"))); if (!ctype || !strcmp(ctype, "C"))
ctype = setlocale(LC_CTYPE, "en_US.utf8");
if (!ctype)
DPRINTF(E_WARN, L_GENERAL, "Unset locale\n");
else if (!strstr(ctype, "utf8") && !strstr(ctype, "UTF8") &&
!strstr(ctype, "utf-8") && !strstr(ctype, "UTF-8"))
DPRINTF(E_WARN, L_GENERAL, "Using unsupported non-utf8 locale '%s
'\n", ctype);
messages = setlocale(LC_MESSAGES, "");
if (!messages)
messages = "unset";
locale_dir = bindtextdomain("minidlna", getenv("TEXTDOMAINDIR"));
DPRINTF(E_DEBUG, L_GENERAL, "Using locale dir '%s' and locale langauge %s
/%s\n", locale_dir, messages, ctype);
textdomain("minidlna"); textdomain("minidlna");
#endif #endif
} }
/* init phase : /* init phase :
* 1) read configuration file * 1) read configuration file
* 2) read command line arguments * 2) read command line arguments
* 3) daemonize * 3) daemonize
* 4) check and write pid file * 4) check and write pid file
* 5) set startup time stamp * 5) set startup time stamp
skipping to change at line 741 skipping to change at line 734
case FORCE_SORT_CRITERIA: case FORCE_SORT_CRITERIA:
force_sort_criteria = ary_options[i].value; force_sort_criteria = ary_options[i].value;
break; break;
case MAX_CONNECTIONS: case MAX_CONNECTIONS:
runtime_vars.max_connections = atoi(ary_options[i].value) ; runtime_vars.max_connections = atoi(ary_options[i].value) ;
break; break;
case MERGE_MEDIA_DIRS: case MERGE_MEDIA_DIRS:
if (strtobool(ary_options[i].value)) if (strtobool(ary_options[i].value))
SETFLAG(MERGE_MEDIA_DIRS_MASK); SETFLAG(MERGE_MEDIA_DIRS_MASK);
break; break;
case WIDE_LINKS:
if (strtobool(ary_options[i].value))
SETFLAG(WIDE_LINKS_MASK);
break;
case TIVO_DISCOVERY:
if (strcasecmp(ary_options[i].value, "beacon") == 0)
CLEARFLAG(TIVO_BONJOUR_MASK);
break;
default: default:
DPRINTF(E_ERROR, L_GENERAL, "Unknown option in file %s\n" , DPRINTF(E_ERROR, L_GENERAL, "Unknown option in file %s\n" ,
optionsfile); optionsfile);
} }
} }
if (log_path[0] == '\0') if (log_path[0] == '\0')
{ {
if (db_path[0] == '\0') if (db_path[0] == '\0')
strncpyt(log_path, DEFAULT_LOG_PATH, PATH_MAX); strncpyt(log_path, DEFAULT_LOG_PATH, PATH_MAX);
else else
skipping to change at line 840 skipping to change at line 841
} }
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':
rescan_db = 1;
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++;
uid = strtoul(argv[i], &string, 0); uid = strtoul(argv[i], &string, 0);
skipping to change at line 886 skipping to change at line 890
} }
if (runtime_vars.port <= 0) if (runtime_vars.port <= 0)
{ {
printf("Usage:\n\t" printf("Usage:\n\t"
"%s [-d] [-v] [-f config_file] [-p port]\n" "%s [-d] [-v] [-f config_file] [-p port]\n"
"\t\t[-i network_interface] [-u uid_to_run_as]\n" "\t\t[-i network_interface] [-u uid_to_run_as]\n"
"\t\t[-t notify_interval] [-P pid_filename]\n" "\t\t[-t notify_interval] [-P pid_filename]\n"
"\t\t[-s serial] [-m model_number]\n" "\t\t[-s serial] [-m model_number]\n"
#ifdef __linux__ #ifdef __linux__
"\t\t[-w url] [-R] [-L] [-S] [-V] [-h]\n" "\t\t[-w url] [-r] [-R] [-L] [-S] [-V] [-h]\n"
#else #else
"\t\t[-w url] [-R] [-L] [-V] [-h]\n" "\t\t[-w url] [-r] [-R] [-L] [-V] [-h]\n"
#endif #endif
"\nNotes:\n\tNotify interval is in seconds. Default is 89 5 seconds.\n" "\nNotes:\n\tNotify interval is in seconds. Default is 89 5 seconds.\n"
"\tDefault pid file is %s.\n" "\tDefault pid file is %s.\n"
"\tWith -d minidlna will run in debug mode (not daemonize ).\n" "\tWith -d minidlna will run in debug mode (not daemonize ).\n"
"\t-w sets the presentation url. Default is http address on port 80\n" "\t-w sets the presentation url. Default is http address on port 80\n"
"\t-v enables verbose output\n" "\t-v enables verbose output\n"
"\t-h displays this text\n" "\t-h displays this text\n"
"\t-R forces a full rescan\n" "\t-r forces a rescan\n"
"\t-R forces a rebuild\n"
"\t-L do not create playlists\n" "\t-L do not create playlists\n"
#ifdef __linux__ #ifdef __linux__
"\t-S changes behaviour for systemd\n" "\t-S changes behaviour for systemd\n"
#endif #endif
"\t-V print the version number\n", "\t-V print the version number\n",
argv[0], pidfilename); argv[0], pidfilename);
return 1; return 1;
} }
if (verbose_flag) if (verbose_flag)
skipping to change at line 1024 skipping to change at line 1029
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
for (i = 0; i < L_MAX; i++) for (i = 0; i < L_MAX; i++)
log_level[i] = E_WARN; log_level[i] = E_WARN;
init_nls();
ret = init(argc, argv); ret = init(argc, argv);
if (ret != 0) if (ret != 0)
return 1; return 1;
init_nls();
DPRINTF(E_WARN, L_GENERAL, "Starting " SERVER_NAME " version " MINIDLNA_V ERSION ".\n"); DPRINTF(E_WARN, L_GENERAL, "Starting " SERVER_NAME " version " MINIDLNA_V ERSION ".\n");
if (sqlite3_libversion_number() < 3005001) if (sqlite3_libversion_number() < 3005001)
{ {
DPRINTF(E_WARN, L_GENERAL, "SQLite library is old. Please use ve rsion 3.5.1 or newer.\n"); DPRINTF(E_WARN, L_GENERAL, "SQLite library is old. Please use ve rsion 3.5.1 or newer.\n");
} }
LIST_INIT(&upnphttphead); LIST_INIT(&upnphttphead);
ret = open_db(NULL); ret = open_db(NULL);
skipping to change at line 1080 skipping to change at line 1085
DPRINTF(E_WARN, L_GENERAL, "HTTP listening on port %d\n", runtime_vars.po rt); DPRINTF(E_WARN, L_GENERAL, "HTTP listening on port %d\n", runtime_vars.po rt);
#ifdef TIVO_SUPPORT #ifdef TIVO_SUPPORT
if (GETFLAG(TIVO_MASK)) if (GETFLAG(TIVO_MASK))
{ {
DPRINTF(E_WARN, L_GENERAL, "TiVo support is enabled.\n"); DPRINTF(E_WARN, L_GENERAL, "TiVo support is enabled.\n");
/* Add TiVo-specific randomize function to sqlite */ /* Add TiVo-specific randomize function to sqlite */
ret = sqlite3_create_function(db, "tivorandom", 1, SQLITE_UTF8, N ULL, &TiVoRandomSeedFunc, NULL, NULL); ret = sqlite3_create_function(db, "tivorandom", 1, SQLITE_UTF8, N ULL, &TiVoRandomSeedFunc, NULL, NULL);
if (ret != SQLITE_OK) if (ret != SQLITE_OK)
DPRINTF(E_ERROR, L_TIVO, "ERROR: Failed to add sqlite ran domize function for TiVo!\n"); DPRINTF(E_ERROR, L_TIVO, "ERROR: Failed to add sqlite ran domize function for TiVo!\n");
/* open socket for sending Tivo notifications */ if (GETFLAG(TIVO_BONJOUR_MASK))
sbeacon = OpenAndConfTivoBeaconSocket(); {
if(sbeacon < 0) tivo_bonjour_register();
DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for s }
ending Tivo beacon notify " else
"messages. EXITING\n"); {
tivo_bcast.sin_family = AF_INET; /* open socket for sending Tivo notifications */
tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress()); sbeacon = OpenAndConfTivoBeaconSocket();
tivo_bcast.sin_port = htons(2190); if(sbeacon < 0)
DPRINTF(E_FATAL, L_GENERAL, "Failed to open socke
ts for sending Tivo beacon notify "
"messages. EXITING\n");
tivo_bcast.sin_family = AF_INET;
tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress());
tivo_bcast.sin_port = htons(2190);
}
} }
#endif #endif
reload_ifaces(0); reload_ifaces(0);
lastnotifytime.tv_sec = time(NULL) + runtime_vars.notify_interval; lastnotifytime.tv_sec = time(NULL) + runtime_vars.notify_interval;
/* main loop */ /* main loop */
while (!quitting) while (!quitting)
{ {
/* Check if we need to send SSDP NOTIFY messages and do it if /* Check if we need to send SSDP NOTIFY messages and do it if
skipping to change at line 1302 skipping to change at line 1314
Delete_upnphttp(e); Delete_upnphttp(e);
} }
} }
} }
shutdown: shutdown:
/* kill the scanner */ /* kill the scanner */
if (scanning && scanner_pid) if (scanning && scanner_pid)
kill(scanner_pid, SIGKILL); kill(scanner_pid, SIGKILL);
/* kill other child processes */
process_reap_children();
free(children);
/* 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)
close(sssdp); close(sssdp);
if (shttpl >= 0) if (shttpl >= 0)
skipping to change at line 1333 skipping to change at line 1341
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_join(inotify_thread, NULL); pthread_join(inotify_thread, NULL);
/* kill other child processes */
process_reap_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();
if (pidfilename && unlink(pidfilename) < 0) if (pidfilename && unlink(pidfilename) < 0)
DPRINTF(E_ERROR, L_GENERAL, "Failed to remove pidfile %s: %s\n", pidfilename, strerror(errno)); DPRINTF(E_ERROR, L_GENERAL, "Failed to remove pidfile %s: %s\n", pidfilename, strerror(errno));
log_close(); log_close();
freeoptions(); freeoptions();
 End of changes. 20 change blocks. 
50 lines changed or deleted 63 lines changed or added

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