Andre Noll [Tue, 13 Jan 2015 23:52:02 +0000 (00:52 +0100)]
command_util.bash: Kill make_proto().
It is always a bad idea to parse C code with a regex in a script. In
addition, it is completely unnecessary in this case.
This commit changes command_util.bash to define, in addition to the
old XXX_CMD_ARRAY, another preprocessor macro XXX__COMMAND_HANDLERS
containing the comma separated list of command handlers without
any type information instead of grepping the source files. A simple
typedef is used to declare all command handlers.
Avoiding all the grep/sed calls reduces the (warm cache) make dep
time by ~10%.
Andre Noll [Tue, 13 Jan 2015 22:53:28 +0000 (23:53 +0100)]
audiod: Clean up fd closing logic in command handlers.
audiod_command.c contains this comment:
/*
* command handlers don't close their fd on errors (ret < 0) so that
* its caller can send an error message. Otherwise (ret >= 0) it's up
* to each individual command to close the fd if necessary.
*/
This is a somewhat weird rule and this commit gets rid of it. Instead,
from now on the command handlers must not close their file descriptor
and handle_connect() closes it unconditionally.
The grab and stat commands need special treatment, which was the reason
for imposing the above rule. They need to keep the file descriptor open
to send the status items or the grabbed stream to the client. This
patch makes these two handlers create a copy of the descriptor with
dup(2). The new approach is simpler and less error-prone.
Andre Noll [Tue, 13 Jan 2015 23:00:41 +0000 (00:00 +0100)]
server: Remove command pointer from struct command_context.
Command handlers should not know about this implementation detail.
This commit also changes parse_sb_command() to not only parse the
command line but to actually run the command in case the caller has
sufficient permissions. The function is renamed to run_command()
to reflect this change.
We use the opportunity to clean up the allocation and freeing of
the command buffer and the argument vector. Both are now freed in
the same function they were allocated, which is considered good
programming practice.
Andre Noll [Tue, 13 Jan 2015 23:00:05 +0000 (00:00 +0100)]
server: Reduce scope of struct server_command.
This structure is only needed in command.c, so we can make it local
to this file. As structures defined in .c files are not included
in doxygen, the reference to struct server_command in server.h must
be removed.
Andre Noll [Mon, 30 Mar 2015 21:30:02 +0000 (21:30 +0000)]
client.m4: Adjust coding style of ggo options.
All other commands use one line per directive of each option, which
improves the readability of the ggo file. This commit changes the
.m4 file for the client options to match this style of specifying
the gengetopt options.
Andre Noll [Mon, 15 Dec 2014 19:20:44 +0000 (20:20 +0100)]
daemon: Improve daemon_log_welcome().
This function is used within para_server and para_audiod. Adding the
"para_" prefix in daemon_log_welcome() rather than its callers avoids
the duplication. Also rename the "whoami" parameter to "name" and add
documentation for it. Finally, the build date is not really important
in the log message, so simply remove it.
Andre Noll [Wed, 24 Dec 2014 02:55:52 +0000 (02:55 +0000)]
aft.c: Silence noisy warnings in com_add().
If the -a option to com_add() is not given, we ignore paths for which
guess_audio_format() returns negative. Currently the add command sends
a warning to the client for each skipped file, which may result in
very verbose output. This commit silences the warning.
Andre Noll [Sun, 10 May 2015 18:27:35 +0000 (20:27 +0200)]
Merge branch 'refs/heads/t/web-diet'
Was cooking in next for three weeks.
* web: Remove screenshots, license and credits page.
* web: Integrate Contact page into about.
* web: Make FEATURES the new homepage, rename it to "about".
* web: Shorten feature list
Andre Noll [Tue, 7 Oct 2014 14:02:07 +0000 (14:02 +0000)]
Allow to start server and audiod as daemon with no logfile.
Currently para_audiod and para_server won't start in the background
if no logfile is specified, so "-dL /dev/null" must be given to force
this. This is a bit tedious to type, so this commit makes "/dev/null"
the default.
To achive this, we can simply remove the gengetopt "dependon" statement
from daemon.m4. This works because if no logfile was given, log output
is written to stderr, which is redirected to /dev/null in case -d
was also given. We need to open /dev/null in read-write mode though,
but no other changes are required.
Andre Noll [Tue, 7 Apr 2015 18:34:05 +0000 (18:34 +0000)]
version.c: Update copyright year to range 2002-2015.
Although we don't update the year in each source file any more,
version.c contains the text that is printed with --version. So this
text should be up to date, and it should be a range. This commit
changes it from "2014" to "2002-2015".
2002 seems appropriate for the first year in the range since the
initial cvs commit was in 2002. Some code is older than that, but
that's probably not important.
Andre Noll [Tue, 7 Apr 2015 23:56:11 +0000 (23:56 +0000)]
touch, rm, cpsi, init: Fix initialization of para_buffer.
Three years ago, in commit 68cb0aef (Introduce
afs_max_size_handler_data and afs_max_size_handler()) the afs callbacks
were converted to pass a pointer to an afs_max_size_handler_data
structure to the dispatcher. This structure is defined as
struct afs_max_size_handler_data {
int fd;
uint8_t band;
};
However, we missed to convert the callbacks of the three commands
mentioned in the subject. All these commands except init pass
a pointer to an int as they did before commit 68cb0aef. Since
afs_max_size_handler_data stores one additional byte (the band
designator) after the file descriptor, the dispatcher will read one
byte past the allocated space.
This bug is benign because the max size handler is usually not called
for the affected commands, since they never have more than SHMMAX
bytes of output. For com_init() we even set the private_data pointer
to NULL, so the max size handler will never be called.
Andre Noll [Sat, 3 Jan 2015 02:50:12 +0000 (02:50 +0000)]
web: Remove screenshots, license and credits page.
The server and audiod log files provided little information and
were constantly outdated, so this patch removes them. The para_gui
screenshot is turned into a link in the feature list where para_gui
is mentioned. This gets rid of the screenshots page.
The paraslash license is mentioned on the main page, so we don't
need a dedicated page for it. The CREDITS file stays in the git repo
of course but we don't need a web page for this either. It's fairly
static anyway.
Andre Noll [Sat, 3 Jan 2015 02:23:18 +0000 (02:23 +0000)]
web: Make FEATURES the new homepage, rename it to "about".
This commit moves the FEATURES file to web/about.html.in, switching
the syntax from grutatxt to plain html. The new file is translated into
index.html while the old main page is now available as the "News" page.
Andre Noll [Sun, 19 Apr 2015 11:49:54 +0000 (13:49 +0200)]
Merge branch 't/lib_arg_with'
Was cooking in next for three weeks.
* t/lib_arg_with:
build: Fix curses detection.
build: Convert curses detection to new macros.
build: Convert libreadline detection to new macros.
build: Convert oss detection to new macros.
build: Convert libsamplerate detection to new macros.
build: Convert libao detection to new macros.
build: Convert alsa detection to new macros.
build: Convert flac detection to new macros.
build: Convert libid3tag detection to new macros.
build: Convert mad detection to new macros.
build: Convert faad detection to new macros.
build: Convert crypto detection/selection to new macros.
build: Convert opus detection to new macros.
build: Convert speex detection to new macros.
build: convert vorbis detection to new macros.
build: Convert ogg detection to new macros.
build: Reduce redundancy in configure.ac, convert osl detection.
Andre Noll [Wed, 18 Feb 2015 15:40:40 +0000 (16:40 +0100)]
gcrypt: Initialize key size of public ASN keys.
This bug could make applications acccept short keys. Not a serious
problem since (a) ASN keys are deprecated in favor of ssh keys and
(b) encrypting a 256 byte buffer fails anyways on short keys. Let's
fix it anyway.
Andre Noll [Sun, 4 Jan 2015 04:55:43 +0000 (04:55 +0000)]
audiod: Make struct slot_info local to audiod.c.
Thanks to the previous commit there is only one user of struct
slot_info left in audiod_command.c: decoder_flags(). Moving this
function to audiod.c allows to make the structure private to audiod.c,
along with the slot array and the MAX_STREAM_SLOTS and FOR_EACH_SLOT
macros.
Since audiod_command still needs the decoder flags for the stat command,
the function is made public and renamed to audiod_get_decoder_flags().
Andre Noll [Sun, 4 Jan 2015 04:39:15 +0000 (04:39 +0000)]
audiod: Move get_play_time_slot_num() to audiod.c.
audiod_status_dump() sends the play time string that corresponds
to the current slot to all connected stat clients. It first calls
the get_play_time_slot_num() helper to obtain the slot number, then
calls get_time_string(slot_num).
Currently the helper function is part of audiod_command.c, hence
we expose the slot_info structure to audiod_command.c. Moving the
helper from audiod_command.c to audiod.c is a first step to make this
structure local to audiod.c. It also allows to remove the slot_num
parameter from get_time_string().
Andre Noll [Fri, 2 Jan 2015 20:10:56 +0000 (20:10 +0000)]
alsa: Avoid alloca().
It is not in POSIX.1-2001, and its use is discouraged. Fortunately,
the alsa library provides also variants which call ordinary malloc(),
so use these instead.
Andre Noll [Mon, 19 Jan 2015 23:25:18 +0000 (00:25 +0100)]
audiod: Allow to specify usernames in --user-allow.
It's more convenient to specify usernames rather than the UIDs of
the users who may execute an audiod command. This patch allows to
do so. For backwards compatibility we still need to accept numerical
UIDs though.
On startup we first try to convert each given --user-allow argument
to a number and regard this number as a UID. Only if the conversion
fails, we translate the argument to a username with getpwnam().
In order to not perform this conversion on each command, we allocate
a UID whitelist at startup and populate it with the UIDs derived from
both types of --user allow arguments. A pointer to the whitelist is
passed as an additional argument to handle_connect().
The documentation is updated to reflect this change.
Andre Noll [Wed, 24 Dec 2014 03:07:48 +0000 (03:07 +0000)]
aft: Store resolved paths when adding files.
Currently the add command performs some sanity checks on the given
paths, but stores them unmodified in the audio file table if they
pass the checks. This commit removes the checks in favor of a call to
realpath(3) to get the canonicalized absolute pathname to be stored
in the audio file table.
The new code relies on POSIX.1-2008 semantics. That is, it calls
realpath() with second argument NULL to let the function allocate a
suitably sized buffer. This should not be a problem, since the old
POSIX.1-2001 version is broken by design, and all moderately recent
systems support the new semantics.
This change breaks t0004 which expects the ls -p command to print
the same paths that were used earlier to add audio files, which is
no longer true. We fix the test by simply running ls without the
-p option.
Andre Noll [Tue, 23 Dec 2014 12:52:03 +0000 (12:52 +0000)]
aft: Update mtime and file size on afhi changes.
If the current audio file is re-added to the osl database, for example
because meta tags have changed, file size and modification time change.
However, the paraslash stat command still shows the old values because
currently the virtual streaming system calls fstat(2) only once when
the audio file is opened and keeps reporting the resulting mtime and
file size values until the file is closed.
This commit introduces make_inode_status_items() which is called
from make_status_items() on AFSI_CHANGE and AFHI_CHANGE events for
the current audio file. The new function calls stat(2) on the path
obtained from the current aft row. We can't use fstat(2) since (a)
we don't have an open file descriptor any more and (b) this would
not work anyway if the original file was overwritten.
Due to the new helper, mmd->mtime can be removed. We must keep
mmd->size though, since we need the original file size for the call
to munmap().
Andre Noll [Mon, 22 Dec 2014 18:05:38 +0000 (18:05 +0000)]
aft: Update status items on afs events.
When a paraslash command changes the afs or afh info structures of the
current audio file, for example by re-adding the file with modified
meta tags, the stat output still reports the old values. With this
patch applied, the status items are updated immediately.
This is achieved by letting aft.c honor the AFSI_CHANGE and AFHI_CHANGE
events. If the audio file which triggered the event is the one
currently being streamed, the event handler recreates the status items.
We need two new global static variables in aft.c to track the row of
the audio file table which corresponds to the current file.
Andre Noll [Sun, 21 Dec 2014 15:24:18 +0000 (15:24 +0000)]
afs: Simplify open_next_audio_file().
This function of afs.c is called whenever the virtual streaming
system requests a new audio file. It determines the row of the audio
file table that corresponds to the audio file with highest score,
according to the current mood or playlist. The function passes this
information to open_and_update_audio_file() of aft.c which sets up
an afd structure to be passed back to the server process.
Letting open_and_update_audio_file() determine which file to
open is shorter, and it allows to get rid of two arguments to
open_and_update_audio_file().
Andre Noll [Mon, 2 Jun 2014 20:24:50 +0000 (22:24 +0200)]
build: convert vorbis detection to new macros.
Also introduces NEED_OGG_OBJECTS() and NEED_VORBIS_OBJECTS(). These
two macros are identical at the moment, but they will start to differ
when opus and speex will be converted.
Andre Noll [Sun, 20 Apr 2014 04:33:11 +0000 (04:33 +0000)]
build: Reduce redundancy in configure.ac, convert osl detection.
We've had a fair number of bugs in configure.ac due to the fact that
most parts of it were created by copy+paste from an existing part.
This commit is an attempt to reduce this redundancy by factoring out
the reappearing parts to common macros. This will also reduce the
number of lines of configure.ac considerably, although this first
patch naturally adds more lines than it removes.
This commit introduces four new macros in configure.ac:
* AC_ARG_WITH: handles --with-xxx-headers and --with-xxx-libs
options for configure. The generated options are identical
to the old ones, so there are no compatibility issues.
* LIB_SUBST_FLAGS: creates preprocessor defines and make
variables
* STASH_FLAGS: saves copies of the CPPFLAGS, LDFLAGS and
LIBS variables
* UNSTASH_FLAGS restores stashed values
Only libosl detection is converted to use the new macros. Subsequent
patches will convert other libraries.
Andre Noll [Tue, 10 Mar 2015 18:03:01 +0000 (19:03 +0100)]
Doxygen: Fix references on main page.
Newer doxygen versions render the main page incorrectly: the second
set of references is shown as a table, with no hyperlinks at all.
This commit should fix it.
Andre Noll [Sat, 14 Feb 2015 19:45:29 +0000 (20:45 +0100)]
gui: Fix config file reloading.
Without this, all key-map arguments found in the config file are
appended to the existing ones, duplicating these options in the help
output. Fix this by invalidating the key-map entry prior to the call
to gui_cmdline_parser_config_file().
Andre Noll [Sun, 8 Mar 2015 18:32:37 +0000 (19:32 +0100)]
Merge branch 'refs/heads/t/abtract_sockets'
Was cooking for almost one month and seems to work fine.
manual: Move /var/paraslash instructions to Troubleshooting.
Abstract sockets for server and audiod.
create_local_socket(): Avoid code duplication.
net.c: Combine remote_name() and __get_sock_name().
Remove socket address parameter of create_local_socket().
Andre Noll [Sat, 7 Feb 2015 14:14:43 +0000 (15:14 +0100)]
interactive.c does not depend on curses.h.
On systems where libreadline is installed but curses headers are not,
the build fails because interactive.c, which includes curses.h, is
attempted to be compiled. Fortunately, it is unnecessary to include
this header, so this commit removes the include directive. However,
we must include para.h before the readline headers because the latter
depend on stdio.h.
Andre Noll [Tue, 7 Oct 2014 19:56:01 +0000 (19:56 +0000)]
Improve signal init and shutdown.
Currently all users of the signal subsystem define their own
signal_task structure and initialize the ->fd field from the return
value of para_signal_init(). It is more natural to let the signal
subsystem perform the allocation and the initialization.
This commit renames para_signal_init() to signal_init_or_die() and
changes the function to allocate, initialize and return a signal
task structure (rather than only the file descriptor of the signal
pipe as para_signal_init() did). Similarly, para_signal_shutdown()
is renamed to signal_shutdown() and now takes a pointer to the
signal_task structure which was obtained in an earlier call to
signal_init_or_die(), and frees it. Conversion of all users is
straight forward.
The patch also adds a missing call to signal_shutdown() to audiod.c,
closing an fd leak.
Andre Noll [Mon, 12 Jan 2015 00:07:19 +0000 (01:07 +0100)]
Abstract sockets for server and audiod.
Currently para_server and para_audiod won't start if the socket
specials can not be created, for example because /var/paraslash does
not exist or has insufficient permissions.
The abstract namespace feature for local sockets allows to go
without socket specials, as implemented in this commit. The feature
is a non-portable Linux extension though, so a fallback to pathname
sockets is necessary for other operating systems and for backward
compatibility.
For para_server the situation is simple because the socket is created
by the afs process, and only command handlers are supposed to connect.
Since afs and the command handlers are part of the same executable
(para_server), there are no compatibility issues. Hence we simply
use an abstract socket on Linux and a pathname socket elsewhere.
For para_audiod things are more complicated because two executables
are involved: para_audioc and para_audiod. To allow older versions
of para_audioc to connect to recent versions of para_audiod, we let
audiod listen on one socket of either type. Startup fails only if
neither socket can be created.
As for the implementation, we make use of the fact that it makes
not much sense to call create_local_socket() with permission mode
equal to 0, and that there are no permission modes for abstract
sockets. With the patch applied, specifying the mode as zero instructs
create_local_socket() to create an abstract socket. In this case we
also use the given pathname but prepend a zero byte at the front of
the ->sun_path member of struct sockaddr_un to bind(2) the socket to
an address in the abstract namespace.
On the client side (connect_local_socket()) we first try to connect to
an abstract address and fall back to pathnames sockets on errors. This
change is transparent to the callers of connect_local_socket. Hence
para_audioc and afs command handlers need no modifications at all.
The patch also adds a section on abstract sockets to the user manual.
Andre Noll [Sun, 11 Jan 2015 23:40:22 +0000 (00:40 +0100)]
create_local_socket(): Avoid code duplication.
The two users of create_local_socket(), afs.c and audiod.c, both
call mark_fd_nonblocking() and listen(2) on the returned socket file
descriptor. This patch moves the code for this additional work to
create_local_socket(), simplifying the callers.
Andre Noll [Sun, 11 Jan 2015 22:21:13 +0000 (23:21 +0100)]
Remove socket address parameter of create_local_socket().
The two callers of create_local_socket() are not interested in
the sockaddr_un structure at all. So we may define the structure
in create_local_socket() rather than in each caller, and kill the
function parameter.
Andre Noll [Tue, 7 Oct 2014 19:16:16 +0000 (19:16 +0000)]
signal: Provide generic signal_pre_select().
Identical copies of this function exist in afs.c, gui.c, audiod.c and
server.c. This commit defines a generic version as an inline function
in signal.h and gets rid of the copies.
Andre Noll [Tue, 7 Oct 2014 19:50:25 +0000 (19:50 +0000)]
gui: Shutdown scheduler after schedule() returns.
This makes sure all resources allocated by the scheduler are released.
Since we exit anyway when schedule() returns, this is not a serious
memory leak. The fix helps to identify real leaks though.
Andre Noll [Fri, 23 Jan 2015 12:17:38 +0000 (13:17 +0100)]
Merge branch 'refs/heads/t/afh_improvements'
Was cooking for about a week.
mp3_afh: Detect both v1 and v2 tags.
ogg: Improve documentation of struct ogg_afh_callback_info.
ogg_afh: Add a comment about the three vorbis header packets.
afh_common.c: Avoid ifdefs.
afh loglevel adjustments.
wma: Rename comment_header.
afh: Fix fd leak.
afh: Unmap the audio file on errors.
Andre Noll [Mon, 19 Jan 2015 21:49:01 +0000 (22:49 +0100)]
build: Use curses_cppflags also for compiling gui.c.
The make pattern rule gui%.o does not match gui.o because there
must be at least one character to match the ‘%’. Consequently,
the curses cppflags are ignored for compiling gui.c.
Fix this by explicitly adding gui.o to the list of object files for
which $(curses_cppflags) must be added to CPPFLAGS.
This happens for example if the user is not allowed to connect to
para_audiod.
The problem is that the (non-positive) value -ret is passed to
para_strerror() as the error code rather than -ret2. This commit
fixes the bug. It was introduced one year ago in commit f840be8d
(gui: Introduce status_post_select()).
Andre Noll [Fri, 27 Dec 2013 03:14:57 +0000 (03:14 +0000)]
mp3_afh: Detect both v1 and v2 tags.
Currently the mp3 audio format handler first looks at id3v2 tags and
ignores any id3v1 tags if a version 2 tag is present. This patch makes
it look at both types of tags, and combine the result if necessary.
We use the opportunity to also get rid of the file descriptor mess
in mp3_get_id3(). It is completely unnecessary as lib3d3tag can make
a id3_t structure from a memory buffer. We simply pass (a part of)
the memory map of the audio file and are done.
The techinfo field of struct audio_format_handler_info is changed
to show which tag versions the various tags were extracted. Possible
values are none, v1, v2 and v1+v2.