142 Commits

Author SHA1 Message Date
Gleb Smirnoff
f9a78d598e Support for pluggable event modules, stage 1. Take out select() loop and associated code into a separate module select.c. Detailed list of changes down below.
The idea is taken from the nginx web server, but much simplified and
almost no copypaste left. This will allow minidlna to use different
event dispatcher APIs, which would be defined at compile time.

My personal goal is to convert minidlna to kqueue(2) on FreeBSD. This
would later allow for kqueue based directory change notification, which
won't conflict with select(2) like the current patch does.
Other platforms will also benefit from the pluggability of the event
system, Linux can switch to epoll(2) or at least to poll(2).

Detailed list of changes:

* event.h [New]
  Our internal API to unify different event dispatch systems.
* select.c [New]
  Much simplified version of nginx's ngx_select_module.c.
* minidlna.c
  - Split out listen socket event processing into separate function
    ProcessListen(), which matches event_process_t type.
  - Create and initialize struct event for the monitor socket, SSDP
    socket, HTTP socket and beacon socket.
  - Simplify and make more precise timeout calculation using
    helper timeval functions from utils.c. Treat gettimeofday() error
    as a fatal event.
  - Rip out all stuff related to select(2). Just call event_module.process().
* upnpevents.c
  - Embed struct event into upnp_event_notify.
  - Merge upnp_event_create_notify() with upnp_event_notify_connect().
    Start connecting immediately after socket creation. Garbage collect
    now useless ECreated state.
  - Make upnp_event_process_notify() of event_process_t type, and use it
    as process callback for upnp_event_notify event.
  - Looks like we always create upnp_event_notify with existing subscriber,
    and never clear it later. Remove checks for obj->sub and assert that it
    is never NULL. Simplifies things.
  - When switching obj state, add/del it to event dispatcher accrodingly.
  - Garbage collect upnpevents_selectfds().
  - Garbage collect select(2) related stuff from upnpevents_processfds().
    Rename function to upnpevents_gc(), since the remaining functionality
    is garbage collecting, not file descriptor processing.
    Actually, this can be simplified even more. We can safely close sockets
    and free objects immediately, eliminating need for upnpevents_gc(). But
    this change would be beyond scope of this commit.
* upnphttp.c, upnphttp.h
  Embed struct event into struct upnphttp. Adjust Process_upnphttp() to match
  event_process_t type. Add/del to event dispatcher once creating/closing a
  socket.
* minissdp.c, minissdp.h
  Make ProcessSSDPRequest() of event_process_t type.
* getifaddr.c, getifaddr.h
  Make ProcessMonitorEvent() of event_process_t type.
2018-01-16 16:53:08 -08:00
Justin Maggard
3e9ca13fa3 upnpsoap: Add forced alphasort capability
Add the ability to force title modification for clients that do their own
alphanumeric sorting.  Adding a '!' to the beginning of the
force_sort_criteria value will enable this behavior.

It is implemented by prepending all titles with a zero-padded number, and
possibly season and episode (or disc and track) numbers if they aren't
already in the title.
2018-01-11 11:12:22 -08:00
Justin Maggard
8bdba2f40d options: Add enable_subtitles config option
Enable generic subtitle support by default for unknown clients.  Set the
new enable_subtitles option to false to revert to the old behavior.
2018-01-11 11:11:42 -08:00
Justin Maggard
ad5d6413a7 If no group is specified, use the user's primary group 2017-10-06 16:05:01 -07:00
david reid
7a27ce3077 Add the ability to set the group to run as. 2017-08-25 17:45:20 -07:00
Justin Maggard
50b1a2e289 scanner: Clean up non-destructive rescan
Fix several issues with the non-destructive rescan functionality.
Most of these issues also affected inotify scanning as well.  These
include annoying debug messages, adding album art for files that we
aren't supposed to be scanning anyway, incrementing the UpdateID when no
changes were made to the database, and other smaller issues.
2017-08-23 23:43:42 -07:00
Justin Maggard
4f926639b2 upnpsoap: Add additonal bookmark support
Add support for upnp:playbackCount and upnp:lastPlaybackPosition tags.
These are used by Kodi to keep track of bookmark information as well as
determining whether to show the checkmark to indicate that the video
has been played.

Also add support for the UpdateObject command, which Kodi uses to
update the playbackCount and lastPlaybackPosition information.

This change requires a DB schema update, which should be done
automatically on the first run.

Inspired by SF user Karsten's patch #167.
2017-05-17 12:01:04 -07:00
Justin Maggard
49aa42d893 scanner: Add non-destructive update rescan
New functionality, based on Shrimpkin's patch #145 on SF.
2017-05-04 23:29:59 -07:00
Justin Maggard
0575299a87 tivo: Add Avahi support
TiVo Bolt doesn't support the old TiVo Beacon discovery mechanism, so
we need to support Bonjour discovery now.  Use Avahi if it's available.
2017-04-28 01:18:53 -07:00
Justin Maggard
1f46b53030 Remove obsolete PNPX support.
AFAICT this has been abandoned by Microsoft.
2016-04-21 14:38:45 -07:00
Justin Maggard
c4166b3e77 options: Add wide_links config option.
In some environments, it makes sense to validate that symlink destinations
remain inside user-defined media_dirs.  Make this behavior configurable.
2016-03-17 14:48:05 -07:00
Justin Maggard
520de165fb nls: Rework NLS init to work with non-en_US locales.
We shouldn't blindly set the LC_CTYPE to en_US.utf8, because the user may
not have it installed.  So if the user already has a utf8 locale defined,
just use it for LC_CTYPE.

Fixed: SF Bug #87 (Problem of accentuation)
2015-12-21 11:45:10 -08:00
Justin Maggard
c985eee9c7 inotify: Block signals in the inotify thread.
Otherwise, we may get invalid reads due to double-handling of signals.
2015-12-21 11:43:38 -08:00
Justin Maggard
d097d3c02d nls: Move init_nls() after log_init().
Otherwise the DPRINTF in minidlna.c:init_nls() will always fail to log.
Pointed out by Shrimpkin.
2015-11-16 09:57:07 -08:00
Justin Maggard
c160a8c8fd Fix a couple missed frees on exit.
There were harmless, but we should fix them for correctness.
2015-09-10 11:55:54 -07:00
Justin Maggard
98fbb5b98b Fix error message for bad user.
SF Patch #126 (Thanks Maxim).
2015-07-30 16:40:59 -07:00
Justin Maggard
e7ec55a2ad getifaddrs: Fix buffer overrun with >3 interfaces. 2015-07-30 16:25:48 -07:00
Justin Maggard
edbdd9acb4 ssdp: Fix service submit to MiniSSDPd.
SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port)
is called before lan_addr[0].str get a proper value.
Patch add call to reload_ifaces() in order to fix that
see miniupnp forum post http://miniupnp.tuxfamily.org/forum/viewtopic.php?t=1801

Thanks Thomas Bernard for this fix.
2015-07-29 23:44:45 -07:00
Justin Maggard
44810ab274 Stub out NLS function. 2014-07-11 18:16:33 -07:00
Justin Maggard
a01ffa1787 Fixes for client cache restructuring. 2014-06-17 18:38:36 -07:00
Justin Maggard
a46a8e5e89 process: associate open connections with clients 2014-06-09 18:48:49 -07:00
Justin Maggard
34cb08928c portability: add support for Illumos
This still won't work on older Solaris systems, but modern Illumos
at least should build and run now.
2014-05-14 17:53:25 -07:00
Justin Maggard
8e05f9b6f7 Allow the user to specify an arbitrary root container. 2014-04-29 16:12:42 -07:00
Justin Maggard
5676a17204 cleanup: remove unnecessary sbeacon set 2014-04-11 12:51:16 -07:00
Catalin Patulea
3a57744735 Add printf attribute to log_err/DPRINTF and fix a few warnings
Modified to not use %z for portability reasons.
2014-04-10 18:57:30 -07:00
Justin Maggard
435bd3d04d Use SERVER_NAME variable when checking for existing process. 2014-03-17 11:41:10 -07:00
Justin Maggard
cce9a012b3 config: add merge_media_dirs option
By default, if there are multiple media directories specified, there
will be entries for each one in the root directory container.  If
there is only one media directory specified, then just its contents
will be in the root container, to save one level of browsing.

Setting this option changes the default behavior so that multiple
media dirs will behave like a single media dir.
2014-03-12 11:40:49 -07:00
Justin Maggard
7c0739ad3f config: introduce strtobool() helper. 2014-03-12 11:32:09 -07:00
Justin Maggard
a606012d23 Fix Clang compiler warnings. 2014-03-07 12:42:40 -08:00
Justin Maggard
5cddc8fb4d print usage and bail if the user gives an unknown command line option 2014-03-03 16:04:46 -08:00
Justin Maggard
1a78a94f70 process: make max number of children (connections) configurable
At least some Panasonic clients try to open more than 5 simultaneous
connections to the server.  If we keep the default of 5 max children,
it results in choppy playback on those clients.

Make this setting configurable, and default to 50 max connections.
Our process is pretty lightweight, so 50 children should not be a
problem on most systems.
2014-03-03 13:32:20 -08:00
Justin Maggard
372afa1ae6 cosmetic: whitespace cleanup 2014-03-03 13:28:31 -08:00
Justin Maggard
6cef303fc1 try to ensure proper ownership of db_dir
If user has been set, try to ensure that db_dir is owned by that user.
If that fails, log an error.
2014-02-27 15:47:02 -08:00
Justin Maggard
fe7c26da2f ssdp: send a full byebye + alive set when a new interface comes online
If an interface comes online after startup, we really need to send a
complete byebye + alive set on that interface, but we don't want to do
it for other interfaces.  So do it as the interfaces come up, and
skip it for interfaces that existed before the reload.
2014-02-26 15:04:46 -08:00
Justin Maggard
a7c8ffb88d cosmetic: whitespace cleanup 2014-02-26 12:37:14 -08:00
Justin Maggard
3f4877cf2f Add a new force_sort_criteria option, to globally override the SortCriteria value sent by the client. 2014-01-07 11:30:15 -08:00
Justin Maggard
622b0b7411 Merge branch 'for-justin' of git://github.com/BenoitKnecht/minidlna 2013-11-01 17:57:00 -07:00
Justin Maggard
c96e6e2adb Skip the initial ssdp:alive packets when initially registering our network
interfaces during startup, so the byebye's can come first.
2013-10-22 18:50:09 -07:00
Benoît Knecht
3995cbdac4 Limit the number of simultanious children
Make sure minidlna cannot fork more than 5 children, to avoid becoming a
fork bomb.

Reported-by: Rinat Ibragimov <ibragimovrinat@mail.ru>
2013-06-20 19:31:34 +02:00
Justin Maggard
1c34c6c594 Update help output shown by "minidlna -h".
Reported-by: (and original version by) Benoît Knecht <benoit.knecht@fsfe.org>
2013-06-11 15:24:53 -07:00
Justin Maggard
62b6e235b1 Don't require a configured network interface to start up, and add network interface monitoring support on Linux. 2013-05-08 23:52:02 -07:00
Justin Maggard
1e4cf74436 * Enable all network interfaces by default if none were specified. 2013-04-30 21:09:30 +00:00
Justin Maggard
f06a93c17a * Store the media type in the TIMESTAMP column, so we can force a rescan if the user changes the media type configuration. 2013-01-02 21:00:52 +00:00
Justin Maggard
2521b3f238 * Force a rescan if a media_dir has been removed from the configuration. 2012-11-16 08:06:24 +00:00
Justin Maggard
1320eb4ea6 * Update coding style. 2012-11-16 08:01:05 +00:00
Justin Maggard
aee83a3ee6 * Improve how we clean up after ourselves during exit. 2012-11-16 07:40:40 +00:00
Justin Maggard
035fd35ffd * Fix up bad accesses found by valgrind. 2012-11-06 08:24:37 +00:00
Justin Maggard
2e120e83a0 * Add some logging and forking tweaks to work better with systemd. 2012-10-04 21:04:36 +00:00
Justin Maggard
584258c1f8 * Add support for limiting a media dir to multiple media types. 2012-10-03 07:26:00 +00:00
Justin Maggard
1de4ef8bc1 * Add configuration option to specify the user to run as. 2012-07-18 18:58:26 +00:00