143 Commits

Author SHA1 Message Date
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
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
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
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
8a996b4b62 upnphttp: Kill strange HTTP request parsing
Avoid reading uninitialized memory on malicious HTTP requests.

Fixes: Bug #293 - upnphttp.c ProcessHttpQuery_upnphttp() Function HTTP Request Handling Remote DoS
2016-09-28 18:44:58 -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
8f7e760747 utils: Unescape "'" in .nfo files.
Kodi escapes apostrophes when exporting its database to .nfo files.

Fixes: Bug #271 (Handle &apos in .nfo files)
2015-08-03 00:20:45 -07:00
Justin Maggard
f85f5afe65 upnphttp: Fix inadvertently removed line from 8e201fe. 2015-08-02 23:51:07 -07:00
Justin Maggard
8e201fec7b upnphttp: Check for invalid Content-Length header. 2015-07-30 13:44:42 -07:00
Justin Maggard
30562d0b66 upnpttp: Implement PixelShape support.
TiVo uses this to get the aspect ratio correct on images.
2015-07-29 23:23:55 -07:00
Justin Maggard
3c4c35b49c upnpsoap: Use scaled thumbnails when rotation is needed
Embedded thumbnails may have an undesirable orientation, so
we should do our own scaling with inline rotation if the
thumbnail image needs to be rotated.
2014-12-11 17:03:35 -08:00
Justin Maggard
75a697a671 upnpttp: factor out basic header generation 2014-07-25 18:26:02 -07:00
Justin Maggard
b1cd1b5413 upnphttp: fix requests for the last byte of a file
Philips TV's apparently do this with MKV files (SF bug #180).
2014-07-18 12:27:39 -07:00
Justin Maggard
5b3c6a3645 upnphttp: declare a couple functions static 2014-07-18 12:26:30 -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
e9a653d6e8 clients: restructure client cache 2014-06-09 18:02:03 -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
08c21f39d1 http: fix error handling in the fallback read/write path 2014-04-18 15:46:00 -07:00
Justin Maggard
ffb8b35424 cleanup: avoid dereferencing NULL pointers 2014-04-11 12:43:59 -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
45cf9208fb Declare printf-like attributes for strcatf() and xasprintf()
Declare printf-like attributes for strcatf() and xasprintf(), and
clean up errors found by the compile after doing so.
2014-04-10 18:18:28 -07:00
Catalin Patulea
57c6510fe4 upnphttp: improve robustness against malformed (possibly malicious) requests 2014-04-10 18:10:55 -07:00
Catalin Patulea
01532b0490 upnphttp: check realloc return while receiving request body 2014-04-10 17:49:01 -07:00
Catalin Patulea
4a507cc84c upnphttp: limit receive headers size to 1 MB 2014-04-10 17:48:49 -07:00
Catalin Patulea
92b6061929 upnphttp: check realloc return while receiving headers 2014-04-10 17:48:33 -07:00
Justin Maggard
d492b43ef8 Fix various potential illegal access and memory leaks in error conditions. 2014-04-07 11:20:19 -07:00
Justin Maggard
9c8bc5d9c2 status: note when a media scan is in progress 2014-03-17 11:32:56 -07:00
Justin Maggard
e3a53fc8a3 clients: separate Samsung BDP and TV client types again
Advertising the DCM10 vendor-specific feature to Samsung Series
C and D (at least) players causes them to always browse ContainerID
1, no matter which section is chosen from their GUI.

Treat TVs and BDPs as separate client types with unique features.
2014-03-11 14:46:21 -07:00
Justin Maggard
372afa1ae6 cosmetic: whitespace cleanup 2014-03-03 13:28:31 -08:00
Justin Maggard
ea9a530a3a clients: keep generic device records
Now that we display connected clients in the status page,
it makes sense that we show all of them, instead of only
recognized device types.
2014-02-26 12:34:15 -08:00
Justin Maggard
a75bdadce1 Show client status on our basic presentation page. 2014-01-07 10:14:26 -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
0700cf9774 Fix up a few conformance issues with latest testing tools. 2013-10-22 19:05:22 -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
1c748c1d5a * Consolidate client detection code.
* Add forced sorting support for Panasonic devices.
2013-03-18 05:37:46 +00:00
Justin Maggard
2d0ae24009 * Do some additional SQL escaping. 2012-07-28 01:16:43 +00:00
Justin Maggard
5f14c68597 * Streamline some TiVo ifdefs. 2012-06-30 00:26:55 +00:00
Justin Maggard
61fbce18ba * Replace sqlite_int64 with int64_t in many places, to better allow for the possibility of other databases. (Thanks Douglas Carmichael) 2012-06-29 23:14:27 +00:00
Justin Maggard
ba162fc082 * Add flag to force downscaled thumbnails rather than using embedded ones.
* Add DirecTV client detection.
2012-05-31 18:37:22 +00:00
Justin Maggard
2383bd97fe * Improve error checking for UPnP events. 2012-05-10 22:34:05 +00:00
Justin Maggard
755c81fd34 * Forcibly tweak the model number for Xbox360 clients, or they might ignore us. 2012-04-04 18:24:21 +00:00
Justin Maggard
25c74a3962 * Fix a crash bug on some oddly-formed WAV files. 2012-03-08 18:11:01 +00:00
Justin Maggard
6b5e121f13 * Add DLNA.ORG_FLAGS support, and clean up transferMode support. 2012-02-14 18:43:35 +00:00
Justin Maggard
996b373f83 * Improve error checking for DLNA CTT compliance. 2012-02-13 23:03:42 +00:00
Justin Maggard
fe581c5e7f * Fix a couple errors in the rotation code. 2012-01-23 18:51:48 +00:00
Justin Maggard
c5bb5c84b3 * Add image rotation support during resize. (mostly useful for TiVo) 2012-01-22 00:33:55 +00:00
Justin Maggard
6820d05143 * Fix a potential segfault on requests for existing objects with no path. (Thanks Dominic) 2012-01-21 18:09:04 +00:00
Justin Maggard
08172a4ed2 * Enhance error checking in some additional places as required by the latest UPnP CTT. 2012-01-21 01:00:26 +00:00