Paraslash Audio Streaming | |
About News Download Documentation Development |
Paraslash's audio file selector. More...
#include <netinet/in.h>
#include <sys/socket.h>
#include <regex.h>
#include <signal.h>
#include <fnmatch.h>
#include <osl.h>
#include <lopsub.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <netdb.h>
#include "server.lsg.h"
#include "server_cmd.lsg.h"
#include "para.h"
#include "error.h"
#include "crypt.h"
#include "string.h"
#include "afh.h"
#include "afs.h"
#include "net.h"
#include "server.h"
#include "daemon.h"
#include "ipc.h"
#include "list.h"
#include "sched.h"
#include "fd.h"
#include "sideband.h"
#include "command.h"
Macros | |
#define | NUM_AFS_TABLES ARRAY_SIZE(afs_tables) |
Used to loop over the afs tables. More... | |
#define | AFS_CLIENT_TIMEOUT 3 |
Shutdown connection if query has not arrived until this many seconds. More... | |
Functions | |
int | send_callback_request (afs_callback *f, struct osl_object *query, callback_result_handler *result_handler, void *private_result_data) |
Ask the afs process to call a given function. More... | |
int | send_lls_callback_request (afs_callback *f, const struct lls_command *const cmd, struct lls_parse_result *lpr, void *private_result_data) |
Wrapper for send_callback_request() which passes a lopsub parse result. More... | |
int | for_each_matching_row (struct pattern_match_data *pmd) |
Execute the given function for each matching row. More... | |
int | string_compare (const struct osl_object *obj1, const struct osl_object *obj2) |
Compare two osl objects of string type. More... | |
int | afs_cb_result_handler (struct osl_object *result, uint8_t band, void *private) |
Result handler for sending data to the para_client process. More... | |
int | pass_buffer_as_shm (int fd, uint8_t band, const char *buf, size_t size) |
Send data as shared memory to a file descriptor. More... | |
__printf_2_3 void | afs_error (const struct afs_callback_arg *aca, const char *fmt,...) |
Format and send an error message to the command handler. More... | |
__noreturn void | afs_init (int socket_fd) |
Initialize the audio file selector process. More... | |
__must_check int | afs_event (enum afs_events event, struct para_buffer *pb, void *data) |
The afs event dispatcher. More... | |
__a_const int | images_event_handler (__a_unused enum afs_events event, __a_unused struct para_buffer *pb, __a_unused void *data) |
Dummy event handler for the images table. More... | |
__a_const int | lyrics_event_handler (__a_unused enum afs_events event, __a_unused struct para_buffer *pb, __a_unused void *data) |
Dummy event handler for the lyrics table. More... | |
Variables | |
int | mmd_mutex |
The mutex protecting the shared memory area containing the mmd struct. More... | |
struct misc_meta_data * | mmd |
Pointer to shared memory area for communication between para_server and its children. More... | |
uint32_t | afs_socket_cookie |
A random number used to "authenticate" the afs connection. More... | |
const struct server_cmd_user_data | lsg_server_cmd_com_select_user_data = { .handler = com_select } |
const struct server_cmd_user_data | lsg_server_cmd_com_init_user_data = { .handler = com_init } |
const struct server_cmd_user_data | lsg_server_cmd_com_check_user_data = { .handler = com_check } |
Paraslash's audio file selector.
#define NUM_AFS_TABLES ARRAY_SIZE(afs_tables) |
Used to loop over the afs tables.
#define AFS_CLIENT_TIMEOUT 3 |
Shutdown connection if query has not arrived until this many seconds.
int send_callback_request | ( | afs_callback * | f, |
struct osl_object * | query, | ||
callback_result_handler * | result_handler, | ||
void * | private_result_data | ||
) |
Ask the afs process to call a given function.
f | The function to be called. |
query | Pointer to arbitrary data for the callback. |
result_handler | Called for each shm area sent by the callback. |
private_result_data | Passed verbatim to result_handler. |
This function creates a socket for communication with the afs process and a shared memory area (sma) to which the buffer pointed to by query is copied. It then notifies the afs process that the callback function f should be executed by sending the shared memory identifier (shmid) to the socket.
If the callback produces a result, it sends any number of shared memory identifiers back via the socket. For each such identifier received, result_handler is called. The contents of the sma identified by the received shmid are passed to that function as an osl object. The private_result_data pointer is passed as the second argument to result_handler.
References afs_socket_cookie, ATTACH_RW, connect_local_socket(), OPT_STRING_VAL, recv_bin_buffer(), shm_attach(), shm_detach(), shm_new(), and write_all().
Referenced by send_afs_status().
int send_lls_callback_request | ( | afs_callback * | f, |
const struct lls_command *const | cmd, | ||
struct lls_parse_result * | lpr, | ||
void * | private_result_data | ||
) |
Wrapper for send_callback_request() which passes a lopsub parse result.
f | The callback function. |
cmd | Needed for (de-)serialization. |
lpr | Must match cmd. |
private_result_data | Passed to send_callback_request(). |
This function serializes the parse result given by the lpr pointer into a buffer. The buffer is sent as the query to the afs process with the callback mechanism.
int for_each_matching_row | ( | struct pattern_match_data * | pmd | ) |
Execute the given function for each matching row.
pmd | Describes what to match and how. |
References pattern_match_data::loop_col_num, osl(), pattern_match_data::pm_flags, PM_REVERSE_LOOP, and pattern_match_data::table.
int string_compare | ( | const struct osl_object * | obj1, |
const struct osl_object * | obj2 | ||
) |
Compare two osl objects of string type.
obj1 | Pointer to the first object. |
obj2 | Pointer to the second object. |
In any case, only MIN
(obj1->size, obj2->size) characters of each string are taken into account.
References PARA_MIN.
int afs_cb_result_handler | ( | struct osl_object * | result, |
uint8_t | band, | ||
void * | private | ||
) |
Result handler for sending data to the para_client process.
result | The data to be sent. |
band | The band designator. |
private | Pointer to the command context. |
References SBD_CRIT_LOG, SBD_DEBUG_LOG, SBD_EMERG_LOG, SBD_ERROR_LOG, SBD_INFO_LOG, SBD_NOTICE_LOG, SBD_OUTPUT, and SBD_WARNING_LOG.
int pass_buffer_as_shm | ( | int | fd, |
uint8_t | band, | ||
const char * | buf, | ||
size_t | size | ||
) |
Send data as shared memory to a file descriptor.
fd | File descriptor to send the shmid to. |
band | The band designator for this data. |
buf | The buffer holding the data to be sent. |
size | The size of buf. |
This function creates a shared memory area large enough to hold the content given by buf and size and sends the identifier of this area to the file descriptor fd.
It is called by the AFS max_size handler as well as directly by the AFS command callbacks to send command output to the command handlers.
NULL
or size is zero. Negative on errors, and positive on success. References ATTACH_RW, PARA_ERROR_LOG, SBD_OUTPUT, shm_attach(), shm_destroy(), shm_detach(), shm_new(), and write_all().
Referenced by afs_error(), and afs_max_size_handler().
__printf_2_3 void afs_error | ( | const struct afs_callback_arg * | aca, |
const char * | fmt, | ||
... | |||
) |
Format and send an error message to the command handler.
To pass an error message from the callback of an afs command to the client, this function should be called. It formats the message into a buffer which is passed as a shared memory area to the command handler from where it propagates to the client.
The message will be tagged with the ERROR_LOG sideband designator so that the client writes it to its stderr stream rather than to stdout as with aca->pbout. In analogy to the default Unix semantics of stderr, the message is sent without buffering.
If sending the error message fails, an error is logged on the server side, but no other action is taken.
aca | Used to obtain the fd to send the shmid to. |
fmt | Usual format string. |
References afs_callback_arg::fd, PARA_ERROR_LOG, para_strerror(), pass_buffer_as_shm(), SBD_ERROR_LOG, and xvasprintf().
__noreturn void afs_init | ( | int | socket_fd | ) |
Initialize the audio file selector process.
socket_fd | File descriptor used for communication with the server. |
__must_check int afs_event | ( | enum afs_events | event, |
struct para_buffer * | pb, | ||
void * | data | ||
) |
The afs event dispatcher.
event | Type of the event. |
pb | May be NULL . |
data | Type depends on event. |
This function calls each table event handler, passing pb and data verbatim. It's up to the handlers to interpret the data pointer. If a handler returns negative, the loop is aborted.
References NUM_AFS_TABLES.
__a_const int images_event_handler | ( | __a_unused enum afs_events | event, |
__a_unused struct para_buffer * | pb, | ||
__a_unused void * | data | ||
) |
Dummy event handler for the images table.
event | Unused. |
pb | Unused. |
data | Unused. |
__a_const int lyrics_event_handler | ( | __a_unused enum afs_events | event, |
__a_unused struct para_buffer * | pb, | ||
__a_unused void * | data | ||
) |
Dummy event handler for the lyrics table.
event | Unused. |
pb | Unused. |
data | Unused. |
|
extern |
The mutex protecting the shared memory area containing the mmd struct.
|
extern |
|
extern |
A random number used to "authenticate" the afs connection.
para_server picks this number by random before it forks the afs process. The command handlers know this number as well and write it to the afs socket, together with the id of the shared memory area which contains the payload of the afs command. A local process has to know this number to abuse the afs service provided by the local socket.
Referenced by send_callback_request().
const struct server_cmd_user_data lsg_server_cmd_com_select_user_data = { .handler = com_select } |
const struct server_cmd_user_data lsg_server_cmd_com_init_user_data = { .handler = com_init } |
const struct server_cmd_user_data lsg_server_cmd_com_check_user_data = { .handler = com_check } |