Andre Noll [Sun, 22 Jul 2012 14:33:20 +0000 (16:33 +0200)]
Makefile: Clean up directory creation.
This combines all directory targets into a single target and executes
the contents of the new MKDIR_P variable (set to "mkdir -p") to create
the directory.
Andre Noll [Sun, 22 Jul 2012 14:11:11 +0000 (16:11 +0200)]
Move gengetopt input files to m4 directory.
This separates the gengetopt input directory from its output directory.
All gengetopt m4 file are moved to the new m4/gengetopt directory.
As a consequence of this cleanup, we may get rid of the .gitignore
file for the generated ggo files, which is a good thing as it was
hard to keep it up to date.
Andre Noll [Sun, 22 Jul 2012 13:15:52 +0000 (15:15 +0200)]
Treat all ggo files as m4 files.
Most input files for gengetopt are already generated from corresponding
m4 files. This renames the remaining ones, so that all .ggo files
are now generated and can be removed by the make clean variants.
Hence we do not need to track the set of generated ggo files any more.
Andre Noll [Tue, 14 Aug 2012 11:09:43 +0000 (13:09 +0200)]
signal: Improve documentation of para_signal_init().
para_signal_init() does not install any signal handlers, so this part of the
documentation is incorrect. The patch fixes this flaw, mentions which end of
the signal pipe is returned to the caller and improves the wording a bit.
Andre Noll [Mon, 23 Jul 2012 19:50:40 +0000 (21:50 +0200)]
server: Remove "foo" feature.
Oops, this feature was added only for testing feature negotiation
with multiple features and should have been deleted before 0.4.11 was
released. This was even mentioned in the commit message of e151dbb7,
which introduced the bogus "foo" feature..
Andre Noll [Tue, 24 Jul 2012 06:42:23 +0000 (08:42 +0200)]
com_init(): Send error message only for non-sideband connections.
If com_init() fails, this non-sideband error message is currently
sent also for sideband connections, which confuses the client. Send
it only for non-sideband connections.
Andre Noll [Mon, 23 Jul 2012 06:41:23 +0000 (08:41 +0200)]
fade: Fix command for switching moods.
It contained a newline, which was not a problem before the sideband
API was introduced. However, with sideband being the default, the
newline character is interpreted as part of the name of the mood or
playlist, causing the mood switch to fail.
The fix is simple: Just remove the trailing newline character.
Andre Noll [Sun, 8 Apr 2012 19:31:10 +0000 (21:31 +0200)]
btr_exec_up(): Also ask given node.
At the moment, the buffer tree walk starts at the parent of the given
node. Users of the btr API can not execute a command for a node unless
it has at least one child.
This unnecessary restriction is removed in this commit by letting
the tree walk start at the given node rather than its parent.
This actually simplifies the code a bit.
Andre Noll [Tue, 23 Aug 2011 19:04:02 +0000 (21:04 +0200)]
btr: Introduce btr_add_output_dont_free().
At the moment, all buffers which are fed to a buffer tree must be
allocated on the heap since the buffer tree code automatically frees
the buffer once its refcount dropped to zero.
The new afh receiver, however, mmaps the audio file and likes to feed
chunks of this memory map into the buffer tree. This is currently
impossible because such buffers must not be freed.
This patch adds the new public function btr_add_output_dont_free()
which works like btr_add_output() but sets the new dont_free bit
which prevents the buffer from being deallocated.
Also btr_inplace_ok() is changed to return "false" whenever there
exists a buffer in the input queue with the dont_free bit set.
Andre Noll [Mon, 9 Apr 2012 19:57:54 +0000 (21:57 +0200)]
btr: Remove btr_free_node().
This has turned out to be source for bugs. Deallocate everything
in btr_remove_node() hence making removing the node and freeing
its resources an atomic operation.
To avoid dangling pointers to freed btrn nodes, the argument of
btr_remove_node() is changed to to struct btr_node **btrnp.
Andre Noll [Mon, 9 Apr 2012 23:43:38 +0000 (01:43 +0200)]
command_util: Fix make dependencies for *_command_list.h.
The *_command_list.h files depend on the .c files listed in the SF
header line of the .cmd command file because command_util.sh gets
the declaration of the command handlers from these files.
Unfortunately, make does not know about these dependencies, so we
have to mention them in the Makefile as well.
Andre Noll [Sat, 7 Apr 2012 06:30:27 +0000 (08:30 +0200)]
Make (most) command handlers static.
Now that the array of commands for para_server and para_audiod are
read from a header file, the command handlers can be made static if
they are in the same file that defines the command array.
This patch makes all such handlers static and tweaks command_util.sh
to recognize also static functions.
Andre Noll [Thu, 28 Jun 2012 02:45:09 +0000 (04:45 +0200)]
command_util: Remove code for generating .c files.
Now that the *_command_list.c files are no longer needed we may remove
this mode from command_util.sh. This makes quite a few headers of
the .cmd files unused, so these can be removed as well.
Andre Noll [Thu, 28 Jun 2012 02:23:32 +0000 (04:23 +0200)]
command_util: Write array definition in header mode.
This modifies command_util.sh so that when it is called in header mode,
it also defines a macro for the array of all commands. command.c and
audiod_command.c are changed to use the new preprocessor macro.
This allows to get rid of the *command_list.c files completely. We may
hence remove these files from the various lists of errlist objects
in configure.ac. and from error.h. A subsequent patch will clean up
the parts that have become unused by this commit.
Andre Noll [Thu, 28 Jun 2012 01:08:00 +0000 (03:08 +0200)]
command_util: Output array members with backslashes.
This makes sure that the generated code for the definition of the
command array has backslashes at the end of each line. Currently
this does not matter because make_array_member() is only called when
generating C code where new lines don't matter.
However, ending each line with a backslash allows to use the same
output for a cpp #define which can go into the header file.
Andre Noll [Thu, 28 Jun 2012 00:51:28 +0000 (02:51 +0200)]
command_util: Avoid empty output lines.
Additional empty output lines do not matter for the generated C code or
the function declarations in the header files. However, a subsequent
commit changes command_util.sh to generate a preprocessor macro for
the header file, and there we can not afford empty lines unless they
end with a backslash to continue the line.
This patch makes sure that no superfluous newlines are printed in
the output.
Andre Noll [Fri, 1 Jun 2012 08:56:10 +0000 (10:56 +0200)]
wma: Remove exponent_sizes[] from struct private_wma_data.
This array is only used in compute_scale_factor_band_sizes(), and
even there we need only the current value. So it is enough to have
a single local variable in this function.
Andre Noll [Fri, 29 Jun 2012 14:28:11 +0000 (16:28 +0200)]
sideband: Fix use after free bug.
Commit 32ffc06c (Pass command exit status via sideband to client.)
made para_server's command handler send the exit status of the command
to the client as an RC4-encrypted sideband packet.
However, the encryption key has already been freed when this packet
is sent. This may result in client errors about invalid or unexpected
sideband designators, but these errors occurred rather infrequently,
which makes this bug hard to trigger. Presumably the freed memory is
usually not being reused since the command handler is going to dye
anyway after the packet is sent.
This patch fixes the bug by deferring to free the crypto keys until
the exit code has been sent.
Andre Noll [Tue, 26 Jun 2012 20:07:55 +0000 (22:07 +0200)]
Merge branch 't/decoder_fixes'
97dbfe wmadec: Only decode one superframe at a time.
d6e017 flacdec: Only process a single flac audio frame.
1e1968 flacdec_close(): Be liberal in what you accept.
3f96f9 oggdec: Fix EOF handling on repositioning.
c7e2f7 oggdec: Realloc buffer to save memory.
634e75 oggdec: Do not decode more than necessary.
These changes are well tested and there are no known problems.
Andre Noll [Wed, 13 Jun 2012 15:53:07 +0000 (17:53 +0200)]
alsa: Do not buffer more than 500ms.
In alsa_init() we set the buffer time to the maximum value supported
by the device. However, on some systems this time is more than 10
seconds, which is much too high.
This patch changes alsa_init() to use a buffer time of at most
0.5 seconds.
This is because clang can not prove that the "score" variable is
always initialized at this point. However, I can: The problematic
GET_NUM_DIGITS() statement is only executed if LS_FLAG_ADMISSIBLE_ONLY
is set in options->flags, but in this case "score" will be set by
get_score_and_aft_row() because this function only fails to do so if it
returns negative. In this case we return early from prepare_ls_row().
Let's make it easier for clang and initialize it anyway.
Andre Noll [Wed, 13 Jun 2012 14:38:10 +0000 (16:38 +0200)]
mood: Improve readability of get_item_score().
This function returns whether the given item matches, so make
it return bool rather than int. This improves readability of
compute_mood_score(), which calls get_item_score() three times,
quite a bit.
Andre Noll [Tue, 15 May 2012 21:19:29 +0000 (23:19 +0200)]
mood: Add score value only for admissible files.
mood.c:175:3: warning: Value stored to 'ret' is never read
ret = get_item_score(item, &afsi, &afhi, path, &item_score,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andre Noll [Tue, 15 May 2012 20:17:18 +0000 (22:17 +0200)]
client: Remove pointless assignment.
client.c:310:2: warning: Value stored to 'ret' is never read
ret = i9e_extract_completions(ci->word, sl, &cr->matches);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andre Noll [Tue, 15 May 2012 20:15:41 +0000 (22:15 +0200)]
gcrypt: Remove dead stores.
gcrypt.c:502:2: warning: Value stored to 'cp' is never read
cp += ret;
^ ~~~
gcrypt.c:577:2: warning: Value stored to 'cp' is never read
cp += ret;
^ ~~~
Andre Noll [Sat, 7 Apr 2012 01:02:33 +0000 (03:02 +0200)]
wmadec: Only decode one superframe at a time.
Similar to the previous commit for the flac decoder, this commit
removes the loop in wmadec_post_select(). This gives other tasks a
chance to run and simplifies the code.
Also, if the buffer was not filled completely, it is truncated to
the proper size to reduce memory usage of the decoder.
Andre Noll [Sat, 7 Apr 2012 01:02:02 +0000 (03:02 +0200)]
flacdec: Only process a single flac audio frame.
This removes the loop in flacdec_post_select() which makes the
flac decoder decode as much as possible, but may starve other
tasks. Removing the loop gives other tasks a chance to run, thereby
avoiding buffer underruns. It simplifies the code too.
Also, resetting the number of unconsumed input bytes to zero at
each scheduler iteration has always been a mistake, so remove it.
Andre Noll [Tue, 10 Apr 2012 05:38:20 +0000 (07:38 +0200)]
flacdec_close(): Be liberal in what you accept.
Functions like close() which terminate an instance of some subsystem
should always be idempotent, i.e. when calling such a function twice
with the same argument, the second call should be a noop.
However, flacdec_close() violates this rule because it dereferences
its private pointer unconditionally. This patch makes the function
idempotent.
Andre Noll [Sun, 3 Jun 2012 09:59:42 +0000 (11:59 +0200)]
oggdec: Fix EOF handling on repositioning.
If playback starts near the end of the file, it might happen that (a)
the read callback consumes all the remaining part in one go (so the
node status is BTR_EOF) and (b) the last ov_read() returned OV_HOLE.
(b) makes the decoder wait for more data which will never arrive due to
(a). Currently we error out without playing the last part of the file.
This patch makes ogg_post_select() return an error only if additionally
fn->min_iqs == 0, which indicates we did not hit OV_HOLE during the
last ov_read().
Andre Noll [Sun, 13 May 2012 19:54:46 +0000 (21:54 +0200)]
oggdec: Realloc buffer to save memory.
The ogg/vorbis decoder always allocates 32K buffers for the decoded
output data. If the buffer could not be filled completely due to
insufficient input data being available, the partially filled 32K
buffer is added to the output buffer tree.
This patch truncates (reallocates) the buffer if this has happened,
thereby reducing the memory footprint of the decoder.
Andre Noll [Sat, 7 Apr 2012 22:25:42 +0000 (00:25 +0200)]
audiod: Check pointers passed to btr_get_node_start().
If the receiver or writer buffer tree node pointer is NULL, we'll segfault due
to a a NULL pointer dereference in btr_get_node_start(). Although this might
not be triggerable, it does not hurt to be defensive here.
Andre Noll [Wed, 11 Apr 2012 21:16:00 +0000 (23:16 +0200)]
oggdec: Do not decode more than necessary.
Currently the ogg vorbis decoder decodes at least one buffer per
scheduler iteration and checks only then if its output queue is already
full. This is bad for several reasons, increased memory footprint is
one of them.
This patch adds an additional check at the beginning of
ogg_post_select() that causes the function to return early if the
output queue is full.
Andre Noll [Wed, 16 May 2012 13:21:10 +0000 (15:21 +0200)]
oss: Add proper error message on init.
If the device node of the sound device (/dev/dsp) does not exist,
we currently fail with a "no such file or directory" error message
without mentioning the name of the device. This adds a log message
which clarifies what went wrong.
Andre Noll [Sun, 26 Feb 2012 13:14:18 +0000 (14:14 +0100)]
Pass command exit status via sideband to client.
Currently the only way for the client side to tell whether a command
failed is to parse the command output. This patch changes command.c to
send an empty sideband packet at command termination. If the command
succeeded, the sideband designator is set to SBD_EXIT__SUCCESS,
otherwise it is SBD_EXIT__FAILURE.
The client checks for these sideband packets and terminates with
EXIT_FAILURE if it received the SBD_EXIT__FAILURE packet.
Andre Noll [Sat, 5 May 2012 10:11:54 +0000 (12:11 +0200)]
Send command output via sideband.
The next step towards sideband connections is to send the output of
each command as a sideband packet. To this aim, afs_cb_result_handler(),
pass_buffer_as_shm() and the callback_result_handler typedef are modified
to receive an additional "band" parameter.
For regular command output the value of this parameter is SBD_OUTPUT,
the sideband designator for normal output. The client code is patched
to add the contents of received SBD_OUTPUT sidband packets to the
buffer tree for the normal ouput.
However, log messages, which are only written to the log output
of the server at the moment, may also passed to the client via the
SBD_XXX_LOG designators, where XXX is the name of one of the usual
log levels for para_log().
The patch contains quite a few changes of the form
if (use_sideband)
do_new_stuff()
else
do_it_as_before()
which is a bit ugly, but we may remove the old method in 0.5.0,
which will support only sideband connections.
to send an error message to the client. This patch simplifies all
these places by introducing the public function send_strerror() which
takes a command context structure and an error code, and executes the
above statement. All places where this was open-coded are changed
to call the new function instead.
Andre Noll [Sat, 5 May 2012 09:04:23 +0000 (11:04 +0200)]
command.c: Improve get_status().
We know exactly the number of bytes in the result buffer. By returning
this information, the caller can use sc_send_bin_buffer() instead of
sc_send_buffer(), which safes one strlen() call.
Andre Noll [Thu, 5 Jan 2012 16:19:49 +0000 (17:19 +0100)]
Pass command via sideband.
This makes para_cclient pass the paraslash command and its arguments
as a sideband packet to para_server if possible.
For sideband connections the command and its arguments are stored as
NULL-terminated strings. This is better than separating by newlines
(as we do for non-sideband connections) because it allows for arguments
containing newlines.
Suitable helpers for creating and parsing a buffer of NULL-terminated
strings, are provided in client_common.c and command.c, respectively.
Andre Noll [Thu, 22 Dec 2011 22:24:54 +0000 (23:24 +0100)]
Use sideband also for "proceed" handshake.
This adds sideband-aware code for the next step of the connection
handshake. If sideband connections are supported at both ends,
the server side sends an empty sideband packet with designator
SBD_PROCEED if the client was authenticated successfully. When the
client receives this packet, it enters the CL_RECEIVED_PROCEED state,
just as with non-sideband connections.
Andre Noll [Wed, 4 Jan 2012 20:47:55 +0000 (21:47 +0100)]
Use sideband also for challenge response.
This changes server and client to exchange the challenge response
as a sideband packet if both ends support sideband connections. The
SBD_CHALLENGE_RESPONSE designator is used for this purpose. On the
client side the changes are less intrusive due to an additional
cleanup of the state handling.
During connection setup the client's idea of the state of
the connection is monitored in the ->status variable of struct
client_task. If the client is in the CL_SENT_AUTH state, it receives
the challenge and sends the hash of the decrypted challenge back to the
server. Either operation may fail, and it seems cleaner to separate
the two. So this patch adds the new state CL_RECEIVED_CHALLENGE. The
clients enters this state once it decrypted the received challenge.
Andre Noll [Sun, 18 Dec 2011 19:18:49 +0000 (20:18 +0100)]
Add sideband implementation.
This adds the new source files sideband.[ch] to the repository and
links the corresponding object file into para_server, para_audiod
and para_client.
The sideband API enables the command handlers of para_server to send a
multiplexed output stream. The client side (para_client or para_audiod)
demultiplex the received stream afterwards.
The design is as simple as it can be: Each data buffer is preceded
by a 5-byte header containing the length and the band designator,
a one-byte number which specifies the type of the data which follows.
The server-side and the client-side implement their own variant of the
send_sb() and recv_sb() functions for sending and receiving sideband
packets. Two implementations are necessary because the underlying
file descriptor is blocking on the server side (command handlers of
para_server) while it is non-blocking on the client side (para_client
and para_audiod).
The sideband API allows to optionally filter all data (including the
sideband header) through an arbitrary transformation. This patch adds
a suitable transformation as a new public function performs RC4 to
the crypto API.
To keep the patch within reasonable size, this commit does not contain
any users of the new sideband API yet. Subsequent commits will teach
the authentication handshake code and the command handlers to send
and receive data as sideband packets.
Andre Noll [Mon, 16 Jan 2012 21:14:41 +0000 (22:14 +0100)]
Introduce afs_max_size_handler_data and afs_max_size_handler().
Whenever the maximal size of a para buffer is reached, para_printf()
calls the specified max size handler. This handler takes, in addition
to the actual buffer and its size, a void * context pointer. Currently
all commands simply pass a pointer to the underlying file descriptor
here since this is the only context the handler needs to know about.
However, this is going to change since with sideband connections the
handler needs to know also the sideband designator.
To meet this future need, this patch introduces struct
afs_max_size_handler_data, which consists of the file descriptor only
at the moment, as well as a simple wrapper for pass_buffer_as_shm().
Andre Noll [Sun, 26 Feb 2012 11:53:43 +0000 (12:53 +0100)]
client: Improve error diagnostics.
If an error occurs in the post_select() method of the client task,
the scheduler removes this task from the task list and then returns
zero to indicate that the task list has become empty.
Currently, client.c looks only at the return value of schedule() and
therefore returns success in this case. This patch makes client.c
additionally check the task error state of the client task and
prints an error message if it was negative and different from an
EOF condition.
Andre Noll [Mon, 9 Apr 2012 19:07:23 +0000 (21:07 +0200)]
Client: Simplify signal handling.
There is no point in having a sighandler which just calls another one.
This patch makes i9e_signal_dispatch() the handler for SIGINT and
removes the pointless wrapper.