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.
blob.c: Don't initialize table pointer in table->init(). This is a global variable which is guaranteed to be zeroed by the compiler.
blob: Constify name argument of blob_get_def_by_name(). This function does not modify the string, although the char pointer is used as the ->data pointer of an osl object, which is non-constant. We need to cast away the const qualifier to avoid a compiler warning, but that's still better than accepting only non-constant strings, as this means to put the cast into the callers.
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
blob: Avoid direct access to blob IDs. Some places of blob.c use read_u32() to get the blob ID from the osl object while others directly access the mapped memory through a uint32_t pointer. Besides alignment issues, this causes trouble on big endian machines. Make sure we always use the primitives from portable_io.h.
blob.c: Fix stale comment of stdin_command(). The arg_obj variable was removed last year in commit 02623a7cbff3 (server: Convert blob commands to lopsub).
blob.c: Trivial whitespace fixes.
Shorten copyright notice. The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
blob: Remove some unnecessary casts for arguments to read_u32(). Since read_u32() has been modified to receive a void * pointer, these casts are no longer needed.
doxygen: Don't refer to libosl functions. They are not part of the tree, and there is no dedicated man page for them.
server: Convert blob commands to lopsub. This converts all blob commands (ls, cat rm, mv) in one go to lopsub, making the patch rather large. The addblob commands are special in that we must pass not only the blob name given at the command line to the callback but also the blob data which was read from stdin. The command handler does not serialize the parse result like most other commands do, but constructs a query object containing name and data for the callback. Therefore the command handler does not call send_lls_callback_request() but send_callback_request(). We continue to follow this scheme. blob.c contains a few macros which expand to a set of functions, one for each type of bloc (mood, playlist, image, lyrics). These macros have to be adjusted to take another argument because we need the prefixes (e.g., lyr for lyrics) in both upper and lower case and there is no preprocessor toupper().
server: Convert non-afs commands to lopsub. Currently the server commands are divided into two group: those commands which are handled by the server process and those which communicate with the afs process. This commit converts the commands of the former group and the corresponding completers for para_client to the lopsub suite format while the afs commands will be converted in subsequent commits. After this change para_server needs to be linked with -llopsub. To this aim the options and help texts of of the server commands are transferred from server.cmd to the new server_cmd.suite.m4, enabling long-style options in the progress. Moreover, an introduction is added at the beginning of the list of server commands which describes how server commands are executed. Command permissions are now handled by making use of the aux_info feature of lopsub. To keep those commands working which do not have any permission bit set, we need to add a new identifier NO_PERMISSION_REQUIRED to enum server_command_permissions of user_list.h. The value of this identifier is zero of course. Naturally the bulk of the change takes place in command.c where all server commands are implemented. The command handlers are modified to take a pointer to a struct lls_parse result as an additional argument. A new helper, send_errctx(), is introduced to avoid code duplication. Since command.h now refers to a lopsub parse result, all files which include command.h, including those which implement only afs commands, need to include the system header lopsub.h. To keep afs commands working, some compatibility code in run_command() is added. This will go away after all commands have been converted. A couple of macros in command.h ease the handling of the long symbolic constants exposed by the generated lopsub header file. Although only the non-afs commands are converted, the change allows for a couple of cleanups: * The E_BAD_COMMAND error code is no longer needed and has been removed. * cmd_perms_itohuman() has become unused and is removed. * The server_cmds[] array is empty and can be removed, along with the loop in send_list_of_commands() which iterated over the array. The patch also adjusts tests t0004 and t0005 since the help output format changed slightly, breaking the expectations of these tests.
Merge branch 'refs/heads/t/invalid-ids' A single patch that was in misc for a while, and two follow up fixups that were detected after the branch was merged into next. * refs/heads/t/invalid-ids (cooking for two weeks): Makefile: Don't compile with -Wformat-signedness unconditionally. aft.c: Use correct format string for error output. touch: Refuse to set an invalid image or lyrics ID.
Fix signedness issues in format strings. Compiling with -Wformat-signedness (not enabled so far) causes many warnings because of format strings which specify an unsigned type but correspond to an argument of signed type, or vice versa. This commit fixes all these mismatches. For "%u", "%d", "%lu", "%ld" we let the format string match the type of the argument, but for "%x" we need to cast the argument to a suitable unsigned type. After this patch the tree compiles cleanly with -Wformat-signedness given. The warning will be enabled in a subsequent commit.
touch: Refuse to set an invalid image or lyrics ID. This makes the callback of the touch command fail the command if the given ID does not exist in the corresponding blob table. To this aim we call blob_get_name_by_id() to look up the ID. Since we are not interested in the name, the function now allows a NULL result pointer in which case it only checks whether the ID is valid. With this patch applied the attempt to set an invalid image or lyrics ID results in an error message like this: invalid image ID: 456565 remote: key not found in rbtree main: command failed
blob_get_name_by_id(): Treat id of dummy row as invalid. If the given id equals the id of the dummy row, the function currently returns an empty object. This is unfortunate, since blob table users should not know about the dummy row implementation detail. This patch makes the function return -E_DUMMY_ROW instead. In error.h, the E_DUMMY_ROW error code was defined in the section for mood.c because this file contains the only user of the error code. With another user in blob.c it seems appropriate to move it to the blob section instead.
Merge branch 'refs/heads/t/command_handler_cleanups' Cooking for about two months. * refs/heads/t/command_handler_cleanups: (39 commits) com_addatt(): Return negative on errors com_rm(): In force mode, don't complain if no paths matched. aft: Unify handling of hash and path duplicates. afs: Provide pbout para_buffer for each callback. afs: Make afs callbacks more flexible. afs: Rename callback_function to afs_callback. com_check(): Add attribute checking. Let afs_event() return int. playlist_check_callback(): Return negative on errors mood_check_callback(): Return negative on errors com_mvblob(): Return negative on errors com_addblob(): Return negative on errors com_rmblob(): Return negative on errors, cleanup com_catblob(): Return negative on errors com_lsblob(): Return negative on errors rmatt: Cleanup callback. com_rmatt(): Return negative on errors com_mvatt(): Return negative on errors com_lsatt(): Return negative on errors com_init(): Return negative on errors ...
Merge branch 'maint'
rmblob: Generate proper BLOB_REMOVE_EVENT. com_rmblob_callback() of blob.c is responsible for removing blobs from any of the four blob tables (images, lyrics, moods, playlists). After a blob has been removed, the function generates an AFS event to tell the other tables about the removal. However, the call to afs_event() passes the event identifier BLOB_RENAME rather than BLOB_REMOVE to the event handlers, which is clearly incorrect. Fortunately, this does not matter because the only event handler which cares about blob events is the one in mood.c, and this handler treats the two events identically. Nevertheless, it's is a bug that should be fixed. This bug was introduced eight years ago when event handling was introduced: commit 02d818d9 (Complete afs event handling).