paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Data Structures | Macros | Typedefs | Functions
command.h File Reference

The structure of server and afs commands. More...

Data Structures

struct  command_context
 Per connection data available to command handlers. More...
 
struct  server_cmd_user_data
 The lopsub user data structure for server commands. More...
 

Macros

#define EXPORT_SERVER_CMD_HANDLER(_cmd)
 Define the user data structure for one command. More...
 
#define SERVER_CMD_CMD_PTR(_cmd)    (lls_cmd(LSG_SERVER_CMD_CMD_ ## _cmd, server_cmd_suite))
 Get the lopsub command pointer by command name. More...
 
#define SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)    (lls_opt_result(LSG_SERVER_CMD_ ## _cmd ## _OPT_ ## _opt, _lpr))
 Get the lopsub parse result of an option. More...
 
#define SERVER_CMD_OPT_GIVEN(_cmd, _opt, _lpr)    (lls_opt_given(SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
 How many times an option was given. More...
 
#define SERVER_CMD_UINT32_VAL(_cmd, _opt, _lpr)    (lls_uint32_val(0, SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
 Fetch the (first) argument given to an option of type uint32. More...
 

Typedefs

typedef int(* server_cmd_handler_t) (struct command_context *, struct lls_parse_result *)
 Prototype of a server command handler. More...
 

Functions

int send_sb (struct stream_cipher_context *scc, void *buf, size_t numbytes, int band, bool dont_free)
 Send a sideband packet through a blocking file descriptor. More...
 
__printf_3_4 int send_sb_va (struct stream_cipher_context *scc, int band, const char *fmt,...)
 Create a variable sized buffer and send it as a sideband packet. More...
 
int send_strerror (struct command_context *cc, int err)
 Send an error message to a client. More...
 
int send_errctx (struct command_context *cc, char *errctx)
 Send an error context to a client,. More...
 
int recv_sb (struct stream_cipher_context *scc, enum sb_designator expected_band, size_t max_size, struct iovec *result)
 Receive a sideband packet from a blocking file descriptor. More...
 

Detailed Description

The structure of server and afs commands.

Macro Definition Documentation

◆ EXPORT_SERVER_CMD_HANDLER

#define EXPORT_SERVER_CMD_HANDLER (   _cmd)
Value:
const struct server_cmd_user_data lsg_server_cmd_com_ ## _cmd ## _user_data = { \
.handler = com_ ## _cmd \
};

Define the user data structure for one command.

◆ SERVER_CMD_CMD_PTR

#define SERVER_CMD_CMD_PTR (   _cmd)     (lls_cmd(LSG_SERVER_CMD_CMD_ ## _cmd, server_cmd_suite))

Get the lopsub command pointer by command name.

◆ SERVER_CMD_OPT_RESULT

#define SERVER_CMD_OPT_RESULT (   _cmd,
  _opt,
  _lpr 
)     (lls_opt_result(LSG_SERVER_CMD_ ## _cmd ## _OPT_ ## _opt, _lpr))

Get the lopsub parse result of an option.

◆ SERVER_CMD_OPT_GIVEN

#define SERVER_CMD_OPT_GIVEN (   _cmd,
  _opt,
  _lpr 
)     (lls_opt_given(SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))

How many times an option was given.

◆ SERVER_CMD_UINT32_VAL

#define SERVER_CMD_UINT32_VAL (   _cmd,
  _opt,
  _lpr 
)     (lls_uint32_val(0, SERVER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))

Fetch the (first) argument given to an option of type uint32.

Typedef Documentation

◆ server_cmd_handler_t

typedef int(* server_cmd_handler_t) (struct command_context *, struct lls_parse_result *)

Prototype of a server command handler.

Function Documentation

◆ send_sb()

int send_sb ( struct stream_cipher_context scc,
void *  buf,
size_t  numbytes,
int  band,
bool  dont_free 
)

Send a sideband packet through a blocking file descriptor.

Parameters
sccfd and crypto keys.
bufThe buffer to send.
numbytesThe size of buf.
bandThe sideband designator of this packet.
dont_freeIf true, never deallocate buf.

The nonblock flag must be disabled for the file descriptor given by scc.

Stream cipher encryption is automatically activated if necessary via the sideband transformation, depending on the value of band.

Returns
Standard.
See also
send_sb_va().

References sb_buffer::band, stream_cipher_context::fd, sb_buffer::iov, sb_free(), sb_get_send_buffers(), sb_new_send(), sb_sent(), SBB_INIT, SBD_PROCEED, sc_trafo(), stream_cipher_context::send, and xwritev().

Referenced by send_sb_va().

◆ send_sb_va()

__printf_3_4 int send_sb_va ( struct stream_cipher_context scc,
int  band,
const char *  fmt,
  ... 
)

Create a variable sized buffer and send it as a sideband packet.

Parameters
sccPassed to send_sb.
bandSee send_sb.
fmtThe format string.
Returns
The return value of the underlying call to send_sb.

References sb_buffer::band, send_sb(), and xvasprintf().

Referenced by send_errctx(), and send_strerror().

◆ send_strerror()

int send_strerror ( struct command_context cc,
int  err 
)

Send an error message to a client.

Parameters
ccClient info.
errThe (positive) error code.
Returns
The return value of the underlying call to send_sb_va().

References para_strerror(), SBD_ERROR_LOG, command_context::scc, and send_sb_va().

◆ send_errctx()

int send_errctx ( struct command_context cc,
char *  errctx 
)

Send an error context to a client,.

Parameters
ccClient info.
errctxThe error context string.
Returns
The return value of the underlying call to send_sb_va().

This function frees the error context string after it was sent.

References SBD_ERROR_LOG, command_context::scc, and send_sb_va().

◆ recv_sb()

int recv_sb ( struct stream_cipher_context scc,
enum sb_designator  expected_band,
size_t  max_size,
struct iovec *  result 
)

Receive a sideband packet from a blocking file descriptor.

Parameters
sccfd and crypto keys.
expected_bandThe expected band designator.
max_sizePassed to sb_new_recv().
resultBody of the sideband packet is returned here.

If expected_band is not SBD_ANY, the band designator of the received sideband packet is compared to expected_band and a mismatch is considered an error.

Returns
Standard.

References sb_buffer::band, stream_cipher_context::fd, sb_buffer::iov, stream_cipher_context::recv, recv_bin_buffer(), sb_free(), sb_get_recv_buffer(), sb_new_recv(), sb_received(), SBD_ANY, SBD_PROCEED, and sc_trafo().

server_cmd_user_data
The lopsub user data structure for server commands.
Definition: command.h:23
server_cmd_user_data::handler
server_cmd_handler_t handler
Pointer to the command handler.
Definition: command.h:25