/* SPDX-License-Identifier: GPL-2.0 */ /** \file server.h Common server data structures. */ /** * Flags for server commands and user permissions. * * For each command, zero or more of these flags are ored to define the command * permissions. A user is allowed to run the command if and only if all command * permission flags are set for the user in the server.users config file which * is read at server startup. */ enum server_command_permissions { NO_PERMISSION_REQUIRED = 0, /** None of the below. */ AFS_READ = 1, /** Read-only operation on the AFS database. */ AFS_WRITE = 2, /** Read-write operation on the AFS database. */ VSS_READ = 4, /** Read-only operation on the virtual streaming system. */ VSS_WRITE = 8 /** Read-write operation on the virtual streaming system. */ }; /** * Information stored about each user. Used during authentication. */ struct user { /** The position of this user in the list of users. */ struct list_head node; /** The username. */ char *name; /** The public key. */ struct asymmetric_key *pubkey; /** The privileges of this user. */ unsigned int perms; }; const struct user *user_list_lookup(const char *name); /** Arguments for the sender command. */ struct sender_command_data { /** Greater than zero indicates that a sender cmd is already queued. */ int cmd_num; /** The number of the sender in question. */ int sender_num; /** Used for the allow/deny/add/remove subcommands. */ char host[MAX_HOSTLEN]; /** Used for allow/deny. */ int netmask; /** The port number for add/remove. */ int port; /** Maximal slice size. */ uint16_t max_slice_bytes; /** Number of data slices plus redundant slices. */ uint8_t slices_per_group; /** Number of slices minus number of redundant slices. */ uint8_t data_slices_per_group; }; /** * Miscellaneous data for communication between server and command handlers. * * There is only one instance of this structure and this instance lives in * a shared memory area so that changes made by the command handlers are * visible by the server process and vice versa. Access to this area is * serialized by the \ref mmd_mutex. * * There are two reasons for a variable to be included here: (a) at least one * command handler changes its value, or (b) updates by the server must * propagate to the stat command handlers. */ struct misc_meta_data { /** The "old" status flags -- commands may only read them. */ unsigned int vss_status_flags; /** The new status flags -- commands may set them. */ unsigned int new_vss_status_flags; /** The number of data chunks sent so far. */ long unsigned chunks_sent; /** Set by the jmp/ff commands to the new position in chunks. */ long unsigned repos_request; /** The number of the chunk currently being sent. */ long unsigned current_chunk; /** The milliseconds that have been skipped of the current audio file. */ long offset; /** The time para_server started to stream. */ struct timeval stream_start; /** * The event counter. * * Commands may increase this to force a status update to be sent to * all connected stat clients. */ unsigned int events; /** The number of audio files already sent. */ unsigned int num_played; /** The number of executed commands. */ unsigned int num_commands; /** The number of connections para_server received so far. */ unsigned int num_connects; /** The number of connections currently active. */ unsigned int active_connections; /** This gets updated by afs and contains its current mode. */ char afs_mode_string[MAXLINE]; /** Used by the sender command. */ struct sender_command_data sender_cmd_data; /** Set by the ll command. */ int loglevel; /** Describes the current audio file. */ struct audio_file_data afd; }; extern pid_t afs_pid; extern struct lls_parse_result *server_lpr; extern struct timeval announce_tv; /** Get the parse result of an option to para_server. */ #define OPT_RESULT(_name) (lls_opt_result( \ LSG_SERVER_PARA_SERVER_OPT_ ## _name, server_lpr)) /** How many times a server option was given. */ #define OPT_GIVEN(_name) (lls_opt_given(OPT_RESULT(_name))) /** The (first) argument to a server option of type string. */ #define OPT_STRING_VAL(_name) (lls_string_val(0, OPT_RESULT(_name))) /** The (first) argument to a server option of type uint32. */ #define OPT_UINT32_VAL(_name) (lls_uint32_val(0, OPT_RESULT(_name))) /** The (first) argument to a server option of type int32. */ #define OPT_INT32_VAL(_name) (lls_int32_val(0, OPT_RESULT(_name))) int handle_connect(int fd, int afs_fd); void parse_config_or_die(bool reload); bool process_is_command_handler(void); void free_lpr(void); void del_close_on_fork_list(int fd); void add_close_on_fork_list(int fd); int parse_fec_url(const char *arg, struct sender_command_data *scd);