801 Commits

Author SHA1 Message Date
Gleb Smirnoff
f7604117c0 Fix more compilation mistakes from 338ee4bd7bb44 in TiVo. 2018-01-16 17:05:51 -08:00
Gleb Smirnoff
3e8da9bb1a Return back checking file for sparseness. Use lseek(SEEK_HOLE) if supported by the system, otherwise fallback to block check. This allows to workaround bugs with SMB client and not introduce new bugs for filesystems with compression and deduplication.
This has theoretical bug if our collection spans different
filesystems and some filesystems support holes, and some not.
If this ever encountered we should use pathconf(2) and cache
its result for directories.
2018-01-16 17:05:44 -08:00
Gleb Smirnoff
debb502ff3 Fix compilation mistakes from 338ee4bd7bb44 in TiVo. 2018-01-16 17:05:42 -08:00
Gleb Smirnoff
da30df3350 Remove C99 code. 2018-01-16 17:05:40 -08:00
Gleb Smirnoff
7428b8dede This file is derived from code by Bernard Spil. Fix copyright. 2018-01-16 17:04:32 -08:00
Gleb Smirnoff
1cb676f51d Add license and my copyright to monitor_kqueue.c. The file contains portions of code that were made either by William or by Stefan. Since I am unsure about that, put them both. To be clarified later. 2018-01-16 17:03:20 -08:00
Gleb Smirnoff
a4dc9a1996 Add nginx's and my copyright to the files that borrow ideas from nginx. 2018-01-16 17:03:00 -08:00
Gleb Smirnoff
4db229534b Initialize libav before enabling kqueue monitor, missed in b2613161329. 2018-01-16 17:02:13 -08:00
Gleb Smirnoff
d02866a084 Filled up event list isn't something warning. 2018-01-16 17:02:10 -08:00
Gleb Smirnoff
d6374fa4e2 Fix SQL queries that intended to match directories. Code originates from FreeBSD ports extra patch. Probably it was working on previous versions of SQLite, or on previous minidlna schema. 2018-01-16 17:02:05 -08:00
Gleb Smirnoff
4ba6f1fa27 Fix stupid logic typo, that prevented monitoring from working. 2018-01-16 17:02:03 -08:00
Gleb Smirnoff
42f0630198 Remove (st.st_blocks<<9 >= st.st_size) check. It may fail if a file system supports deduplication, compression and other features.
My guess the goal was to skip files with holes in them. Original commit
590f0761f4aba64c4a3b4c8f11543a929178da38, doesn't explain that. If that
is still necessary, better to add lseek(SEEK_DATA) check later.
2018-01-16 17:02:01 -08:00
Gleb Smirnoff
958da67592 Initialize libav before enabling kqueue monitor. 2018-01-16 17:01:59 -08:00
Gleb Smirnoff
dfdd81a09f Wrap struct event into struct watch. For now this is just code bloat. We might start monitoring files later. We also might want to create a tree/list of all watches if we ever need to search within them, like the inotify module does. 2018-01-16 17:01:55 -08:00
Gleb Smirnoff
5e320f2798 Add monitoring support via kqueue(2). Based on patch from FreeBSD ports, authored by wg@FreeBSD.org and se@FreeBSD.org. However, this version doesn't create any thread, it uses main event dispatcher.
Some effort was made to unify monitoring via kqueue and via inotify
APIs. Now both provide their implementation of add_watch() function.

I guess there are some logical bugs in vnode_process(). With this commit
it would be better provide code as is, and resolve bugs separately.
2018-01-16 17:01:43 -08:00
Gleb Smirnoff
184607cb56 Remove obsoleted useless flag. 2018-01-16 16:55:26 -08:00
Gleb Smirnoff
7ba9e52fc8 Add kqueue event module. Code inspired by nginx. There are a lot of room for optimization here, this is just first working version. 2018-01-16 16:55:23 -08:00
Gleb Smirnoff
aefe4dd0bf With current forking model of minidlna, we no longer need the event module in the child, so shut it down. While here, make any error from fork() a fatal error. 2018-01-16 16:53:14 -08:00
Gleb Smirnoff
33fb664fba Failure of event_module init is fatal. 2018-01-16 16:53:12 -08:00
Gleb Smirnoff
8fcb1258b4 Shut up compilation warning. 2018-01-16 16:53:10 -08:00
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
Gleb Smirnoff
04e243c85c Add handy functions for timeval manipulations. Obtained from FreeBSD. 2018-01-16 16:49:52 -08:00
Stefan Esser
63f725f8c9 Fix DEBUG build. 2018-01-16 16:49:49 -08:00
Gleb Smirnoff
8fb89dc6fa Remove reference to non-existent INSTALL file. 2018-01-16 16:49:43 -08:00
Justin Maggard
3990f61c57 monitor: Abort inotify directory scanning on quit
Add more interruption point in case we receive a quit signal while we're
scanning a large directory.
2018-01-12 13:57:58 -08:00
Justin Maggard
c2a9186c71 Increase MAX_LAN_ADDR to 8 2018-01-11 16:09:15 -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
c0e66e9997 metadata: Add episode season and number support
Add upnp:episodeSeason and upnp:episodeNumber support for video items.
The DISC and TRACK columns are multiplexed to store the data.
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
33fd018828 minissdp: Delay before answering ssdp:all requests
With some device combinations, our responses may be lost if we don't
delay for some time.
2018-01-08 18:04:57 -08:00
Justin Maggard
0d224a4607 upnpsoap: Add SEC namespace
Declare Samsung namespace where appropriate.
2018-01-03 23:01:46 -08:00
Justin Maggard
8b06ea863d minixml: Fix parsing error with extra whitespace
If there is extra whitespace, the iterator would not get moved properly
resulting in incomplete data.
2018-01-02 16:27:10 -08:00
Justin Maggard
2ad098fd69 Remove test code from last commit. 2017-11-29 23:52:57 -08:00
Justin Maggard
782e99873a upnphttp: Don't select an empty interface address
When determining which address to present to the client for a resource
URL, we should never use an empty string.
2017-11-29 23:31:36 -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
6819c6a186 Merge /u/jkrueger1/minidlna/ branch master into master
https://sourceforge.net/p/minidlna/git/merge-requests/16/
2017-08-26 00:40:41 +00:00
Justin Maggard
c760a338e0 Wrap up version 1.2.1. 2017-08-24 10:28:25 -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
9e534c56fd monitor: Support NFO file changes
Detect when a .nfo file changes, and rescan metadata for the associated
video file.
2017-08-22 15:30:10 -07:00
Justin Maggard
c8665bcf40 containers: Add Samsung DCM10 magic containers
Some Samsung clients (at least UE40ES8000) apparently cannot handle our
standard container IDs when we turn on the DCM10 feature. So they end up
requesting an empty ObjectID, which is invalid. If we blindly return our
root container, they still have problems browsing because they only use
one object from our returned results, so they don't get a full list of
browseable categories.

It has been confirmed that we can work around this by using the same
ObjectIDs that Samsung uses for our root containers in our
X_GetFeatureList response (A, V, and I). And fortunately it's trivial to
handle these renamed ObjectIDs using our magic container system.

Fixes: SF Bug #311 (Samsung TV built-in DLNA client broken since v1.1.5)
2017-08-22 12:28:42 -07:00
Justin Maggard
37346fb0a0 events: Limit subscriber count
Protect against DoS by limiting the number of subscribers we allow to a
total of 500, and immediately removing subscribers from our list if we
encounter an error communicating with them.
2017-08-22 12:20:38 -07:00
Justin Maggard
14d0110fb4 upnpsoap: Add extra thumnail res for Samsung video thumbnails
It's been reported that modern Samsung TVs (Series F?) won't show video
thumbnails unless they're listed as JPEG_SM. So add an extra entry for
that.
2017-07-28 18:14:52 -07:00
ynilu
914ac12302 ssdp: Fix UDP sendto bug
The size of the client address may be modified by recfrom.
So, the last parameter of sendto should be the modified size.
2017-07-28 17:47:51 -07:00
Justin Maggard
ca08f4540f metadata: Fix NFO parsing
The switch to dymanic allocation was botched. Fix it.
2017-07-28 17:28:15 -07:00
Justin Maggard
4df5400cb1 tivo: Fix Bonjour compatibility with Bolt
Bolt (Series6) seems to have a bug where it only reacts to
_tivo-videostream._tcp service types after a TiVo reboot, and ignores
_tivo-vidoes._tcp.  I have no idea what the difference is supposed to be
because it's undocumented, but either type works on both Roamio (Series5)
and Bolt, so hopefully it's safe for Series 3 and 4 also.
2017-07-26 16:00:20 -07:00
Vladislav Grishenko
b0cd672abf ssdp: fix M-SEARCH replies on non-linux OS and drop broadcast receiving due no read
On Darwin & *BSD binding to mcast address may force NITIFY packet send from
 this mcast address, not from primary interface address. Therefore subsequent
 NOTIFY packets might be ignored by some clients, including Samsung Smart TV
 and they will stop & disconnect after initial max-age timeout.

 SO_BROADCAST on notify packets is not needed, because there's no broadcasted
 M-SEARCH packets and notify socket queue is never read.
2017-05-25 17:38:36 -07:00
Justin Maggard
d9f033aa43 clients: add Movian detection and enable subtitles 2017-05-20 00:16:33 -07:00
Justin Maggard
c50936c347 Wrap up version 1.2.0. 2017-05-17 13:55:17 -07:00
Justin Maggard
46c692fc59 metadata: Reduce stack usage in nfo parsing
64KB is a bit much for a stack buffer.  Use dynamic allocation instead.
2017-05-17 13:55:13 -07:00