Merge topic branch t/ls-L into master A single patch which implements the new --limit option for the ls server command. The confict in aft.c was trivial to fix. * refs/heads/t/ls-L: server: Implement ls --limit.
Merge topic branch t/afs-ls-a into master A new feature for the ls command. Unfortunately, several bugs were found after the topic graduated to next, so the series contains a few fixup commits on top of the single patch which implements the feature. * refs/heads/t/afs-ls-a: afs: Really fix memory leak in mood_load(). afs: Fix memory leak in mood_load(). playlist: Fix error handling of playlist_load(). server: Fix NULL pointer dereference in com_ls(). Implement ls --admissible=m/foo.
server: Implement ls --limit. The new option is quite easy to implement. The patch actually removes more lines from aft.c than it adds, but this is just because the code which loops over all matching files was duplicated across the two branches of the clause which checks whether --reverse was given. The branches can easily be combined.
Implement ls --admissible=m/foo. Currently there can be only one score table at a time because the functions of score.c refer to the global score_table variable. To implement the new feature, we need to overcome this restriction so that the callback of the ls command can populate an independent score table to print its output without interfering with the score table that is currently active. This commit changes most functions of score.c to receive an additional table pointer argument. All current users of the score table pass a NULL pointer to instruct the functions to operate on the global score table as before. However, if the ls command is invoked with an optional mood argument to -a. the callback calls mood_load(), followed by mood_loop() and mood_unload(). The former returns an opaque handle which is then passed to the other two functions to instruct them to operate on the temporary score table instead of the global one. To make the feature work for playlists as well, analogous functionality is implemented in playlist.c. The new mop_loop() of aft.c performs the disambiguation in a similar way as the activate_mood_or_playlist() does. It is a bit simpler though, since the ls command does not have to deal with NULL arguments and does not need to fall back to the dummy mood.
fd: Simplify and move for_each_file_in_dir(). With only one user it can be static in aft.c. Modify the function so that it no longer changes the current working directory, remove para_opendir() because it is unused now, dedox the documentation and streamline it a bit.
aft: Always copy and compare full hash value. Although we switched to 32 byte hash function in paraslash-0.7.0, we kept comparing only the first 20 bytes to verify that the file has not changed. Also the ls output and the status items contained only the first 20 bytes of the hash value.
server: Don't save bogus chunk table for aac files. The audio file selector stores the chunk table of each audio file as an osl disk object. Since the aac audio format handler employs dynamic chunks, these on-disk chunk tables of aac files will never be consulted for streaming. They exist only for consistency with the other audio formats and should be empty. Due to a mis-computation of the chunk table size in the callback of the add command we happen to store the serialized lopsub parse result as the chunk table. This is a benign bug since it only affects the ls command, and only if -l=c is given to print the chunk table.
Merge branch 'maint' Two fixes for the chunk table output of the ls command. * maint: server: ls -l=c: Don't print chunk table in case of dynamic chunks. server: Fix ls -l=c.
server: ls -l=c: Don't print chunk table in case of dynamic chunks. The chunk table stored in the osl disk object of the paraslash database is useless for audio formats which support dynamic chunks (aac only). Omit this part of the ls output.
server: Fix ls -l=c. This classic copy+paste bug caused ls -l=c to work as if -l=m had been given. Introduced seven years ago in commit 7af252cbfe13 (server: Convert com_ls() to lopsub).
Introduce afs_error(). The callbacks of some afs commands employ the normal ->pbpout para buffer to send an error message to the client on failure. These messages are therefore tagged with the OUTPUT sideband designator just as regular command output. The receiving client writes such messages to stdout, so applications which call para_client have no other way than parsing the output to guess whether it is normal command output or an error message. This commit improves on this by providing a public helper in afs.c to format and send an error message that is tagged with the ERROR sideband designator and thus gets written to stderr on the client side. All afs callbacks which currently use ->pbout for error messages are converted to call the new helper.
afs: Replace ->init of afs tables by table operations. This is simpler, avoids the run-time initialization, and allows us to mark the instances of the operations structures constant. Improve the documentation a bit while at it.
Rename admissible_file_loop() -> score_loop(). The function simply iterates the entries of the score table. The new name is shorter, more to the point, and indicates that the function is implemented in score.c. Streamline the documentation while at it and swap the arguments, as the reversed order is more natural.
string: Introduce arr_alloc(). Change all callers of alloc() which pass a product of two integers as the allocation size to call the new function instead. This function aborts if the multiplication overflows. With arr_alloc() in place, alloc() reduces to a trivial wrapper which calls new arr_alloc() with the first argument equal to one.
string: Introduce arr_realloc() and check for integer overflow. Use __builtin_mul_overflow() for the check. This builtin was introduced in gcc-5, so we need to bump the lowest supported version. Re-implement para_realloc() as a trivial wrapper for arr_realloc() to simplify and to avoid duplicating the size check.
string: Rename para_malloc() -> alloc(). Just because it's shorter and matches the naming of the new allocators we are about to introduce. The bulk of this patch was created with sed -i 's/para_malloc/alloc/g' *.c *.h yy/mp.y
Remove para_dirname() and para_basename(). The former has only a single caller, the second only two, open-coding these is actually simpler and more performant because we no longer scan each path twice and avoid the temporary copy of the path.
com_ls(): Drop "audio file table syntax error" messsage. This error message is printed if ls is called with an invalid argument for the listing mode or sort order. That's not a syntax error, so use the standard EINVAL error code instead.
afs: Switch to sha256 and change default database path. This switches the hash column of the audio file table to use sha256 rather than sha1. Due to the preparations implemented in the previous patches this is a mechanical conversion that could have been performed by a script. The only non-trivial thing is the rename of the audio file table directory, which changes from "audio_files" to "audio-files" because this is the name the conversion script introduced in the previous commit picked.
Remove ->fd of struct audio file data. This structure contains information about the next audio file. It is stored in a shared memory area, and a reference to this area is sent through a pipe from the afs process to the server process. The file descriptor of the next audio file, however, must be passed via Unix socket magic (SCM_RIGHTS) and thus does not need to be part of the structure. Moreover, it's easier to define the afd structure in open_and_update_audio_file() of aft.c rather than in its caller, open_next_audio_file() of afs.c, because the caller only needs the fd of the audio file and the shared memory ID but not the audio file data structure itself. Expand the documentation of open_and_update_audio_file() a bit while at it.