paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Data Structures | Macros | Enumerations | Functions | Variables
send.h File Reference

Sender-related defines and structures. More...

Data Structures

struct  sender
 Describes one supported sender of para_server. More...
 
struct  sender_client
 Describes one client, connected to a paraslash sender. More...
 
struct  fec_client_parms
 Each paraslash sender may register arbitrary many clients to the virtual streaming system, possibly with varying fec parameters. More...
 
struct  sender_status
 Describes the current status of one paraslash sender. More...
 

Macros

#define SENDER_SUBCOMMANDS
 A little preprocessor fu helps to create the sender_subcommand enumeration below and the list of sender name strings without duplicating the commands. More...
 
#define SENDER_SUBCOMMAND(_name)   SENDER_ ## _name,
 Concatenate "SENDER_" and the given arg and append a comma. More...
 
#define SENDER_SUBCOMMAND(_name)   #_name,
 Concatenate "SENDER_" and the given arg and append a comma. More...
 
#define FOR_EACH_SENDER(_i)   for ((_i) = 0; senders[(_i)]; (_i)++)
 Iterate over all senders. More...
 
#define FOR_EACH_LISTEN_FD(_n, _ss)   for (_n = 0; _n < (_ss)->num_listen_fds; _n++)
 Iterate over all listening addresses of the http/dccp sender. More...
 

Enumerations

enum  sender_subcommand {
  SENDER_add, SENDER_delete, SENDER_allow, SENDER_deny,
  SENDER_on, SENDER_off, NUM_SENDER_CMDS
}
 Each sender subcommand gets an SENDER_xxx identifier. More...
 

Functions

void shutdown_client (struct sender_client *sc, struct sender_status *ss)
 Shut down a client connected to a paraslash sender. More...
 
void shutdown_clients (struct sender_status *ss)
 Shut down all clients connected to a paraslash sender. More...
 
void init_sender_status (struct sender_status *ss, const struct lls_opt_result *acl_opt_result, const struct lls_opt_result *listen_address_opt_result, int default_port, int max_clients, int default_deny)
 Initialize a struct sender status. More...
 
void free_sender_status (const struct sender_status *ss)
 Deallocate all resources allocated in init_sender_status(). More...
 
__malloc char * generic_sender_status (struct sender_status *ss, const char *name)
 Return a string containing the current status of a sender. More...
 
void generic_com_allow (struct sender_command_data *scd, struct sender_status *ss)
 Allow connections from the given range of IP addresses. More...
 
void generic_com_deny (struct sender_command_data *scd, struct sender_status *ss)
 Deny connections from the given range of IP addresses. More...
 
void generic_com_on (struct sender_status *ss, unsigned protocol)
 Activate a paraslash sender. More...
 
void generic_acl_deplete (struct list_head *acl)
 Empty the access control list of a sender. More...
 
void generic_com_off (struct sender_status *ss)
 Deactivate a paraslash sender. More...
 
__malloc char * generic_sender_help (void)
 Get the generic help text. More...
 
struct sender_clientaccept_sender_client (struct sender_status *ss)
 Accept a connection on the socket(s) this server is listening on. More...
 
int send_queued_chunks (int fd, struct chunk_queue *cq)
 Try to empty the chunk queue for this fd. More...
 
int parse_fec_url (const char *arg, struct sender_command_data *scd)
 Parse a FEC URL string. More...
 

Variables

const struct sender *const senders []
 NULL-terminated list, defined in vss.c. More...
 

Detailed Description

Sender-related defines and structures.

Macro Definition Documentation

◆ SENDER_SUBCOMMANDS

#define SENDER_SUBCOMMANDS
Value:
SENDER_SUBCOMMAND(delete) \
SENDER_SUBCOMMAND(allow) \
SENDER_SUBCOMMAND(deny) \
SENDER_SUBCOMMAND(on) \
SENDER_SUBCOMMAND(off)

A little preprocessor fu helps to create the sender_subcommand enumeration below and the list of sender name strings without duplicating the commands.

Deactivate the sender.

◆ SENDER_SUBCOMMAND [1/2]

#define SENDER_SUBCOMMAND (   _name)    SENDER_ ## _name,

Concatenate "SENDER_" and the given arg and append a comma.

Redefine it to expand to the stringified name of the sender so that SENDER_SUBCOMMANDS above now expands to the comma-separated list of sender name strings.

This is used in command.c to define and initialize an array of char pointers.

◆ SENDER_SUBCOMMAND [2/2]

#define SENDER_SUBCOMMAND (   _name)    #_name,

Concatenate "SENDER_" and the given arg and append a comma.

Redefine it to expand to the stringified name of the sender so that SENDER_SUBCOMMANDS above now expands to the comma-separated list of sender name strings.

This is used in command.c to define and initialize an array of char pointers.

◆ FOR_EACH_SENDER

#define FOR_EACH_SENDER (   _i)    for ((_i) = 0; senders[(_i)]; (_i)++)

Iterate over all senders.

◆ FOR_EACH_LISTEN_FD

#define FOR_EACH_LISTEN_FD (   _n,
  _ss 
)    for (_n = 0; _n < (_ss)->num_listen_fds; _n++)

Iterate over all listening addresses of the http/dccp sender.

Enumeration Type Documentation

◆ sender_subcommand

Each sender subcommand gets an SENDER_xxx identifier.

The identifier is passed from the sender command handler to the server process via shared memory.

Enumerator
SENDER_add 

Add a target (udp only).

SENDER_delete 

Delete a target (udp only).

SENDER_allow 

Allow connections from given IP address(es).

SENDER_deny 

Deny connections from given IP address(es).

SENDER_on 

Activate the sender.

SENDER_off 

Deactivate the sender.

List of SENDER_xxx identifiers.

NUM_SENDER_CMDS 

Used as array size in struct sender.

Function Documentation

◆ shutdown_client()

void shutdown_client ( struct sender_client sc,
struct sender_status ss 
)

Shut down a client connected to a paraslash sender.

Parameters
scThe client to shut down.
ssThe sender whose clients are to be shut down.

Close the file descriptor given by sc, remove it from the close-on-fork list, destroy the chunk queue of this client, delete the client from the list of connected clients and free the sender_client struct.

See also
shutdown_clients().

References sender_client::cq, cq_destroy(), del_close_on_fork_list(), sender_client::fd, sender_client::name, PARA_INFO_LOG, and process_is_command_handler().

Referenced by shutdown_clients().

◆ shutdown_clients()

void shutdown_clients ( struct sender_status ss)

Shut down all clients connected to a paraslash sender.

Parameters
ssThe sender whose clients are to be shut down.

This just loops over all connected clients and calls shutdown_client() for each client.

References sender_status::client_list, list_for_each_entry_safe, sender_client::node, and shutdown_client().

Referenced by generic_com_off().

◆ init_sender_status()

void init_sender_status ( struct sender_status ss,
const struct lls_opt_result *  acl_opt_result,
const struct lls_opt_result *  listen_address_opt_result,
int  default_port,
int  max_clients,
int  default_deny 
)

Initialize a struct sender status.

Parameters
ssThe struct to initialize.
acl_opt_resultContains array of –{http|dccp}-access arguments.
listen_address_opt_resultWhere to listen on.
default_portUsed for addresses with no specified port.
max_clientsThe maximal number of simultaneous connections.
default_denyWhether a blacklist should be used for access control.

References alloc(), sender_status::default_port, FOR_EACH_LISTEN_FD, sender_status::listen_addresses, sender_status::listen_fds, sender_status::num_listen_fds, and para_strdup().

◆ free_sender_status()

void free_sender_status ( const struct sender_status ss)

Deallocate all resources allocated in init_sender_status().

Parameters
ssThe structure whose components should be freed.

This frees the dynamically allocated parts of the structure which was initialized by an earlier call to init_sender_status(). It does not call free(ss), though.

References FOR_EACH_LISTEN_FD, sender_status::listen_addresses, and sender_status::listen_fds.

◆ generic_sender_status()

__malloc char* generic_sender_status ( struct sender_status ss,
const char *  name 
)

◆ generic_com_allow()

void generic_com_allow ( struct sender_command_data scd,
struct sender_status ss 
)

Allow connections from the given range of IP addresses.

Parameters
scdContains the IP and the netmask.
ssThe sender.
See also
generic_com_deny().

References sender_status::acl, acl_allow(), sender_status::default_deny, sender_command_data::host, and sender_command_data::netmask.

◆ generic_com_deny()

void generic_com_deny ( struct sender_command_data scd,
struct sender_status ss 
)

Deny connections from the given range of IP addresses.

Parameters
scdsee generic_com_allow().
sssee generic_com_allow().
See also
generic_com_allow().

References sender_status::acl, acl_deny(), sender_status::default_deny, sender_command_data::host, and sender_command_data::netmask.

◆ generic_com_on()

void generic_com_on ( struct sender_status ss,
unsigned  protocol 
)

Activate a paraslash sender.

Parameters
ssThe sender to activate.
protocollayer4 type (IPPROTO_TCP or IPPROTO_DCCP).

This opens a passive socket of given layer4 type, sets the resulting file descriptor to nonblocking mode and adds it to the close on fork list.

Errors are logged but otherwise ignored.

References add_close_on_fork_list(), sender_status::default_port, FOR_EACH_LISTEN_FD, format_url(), sender_status::listen_addresses, sender_status::listen_fds, mark_fd_nonblocking(), PARA_ERROR_LOG, para_listen(), and para_strerror().

◆ generic_acl_deplete()

void generic_acl_deplete ( struct list_head acl)

Empty the access control list of a sender.

Parameters
aclThe access control list of the sender.

This is called from the ->shutdown methods of the http and the dccp sender.

References acl_allow().

◆ generic_com_off()

void generic_com_off ( struct sender_status ss)

Deactivate a paraslash sender.

Shutdown all connected clients and stop listening on the TCP/DCCP socket.

Parameters
ssThe sender to deactivate.
See also
del_close_on_fork_list(), shutdown_clients().

References del_close_on_fork_list(), FOR_EACH_LISTEN_FD, sender_status::listen_fds, and shutdown_clients().

◆ generic_sender_help()

__malloc char* generic_sender_help ( void  )

Get the generic help text.

Returns
A dynamically allocated string containing the help text for a paraslash sender.

References make_message().

◆ accept_sender_client()

struct sender_client* accept_sender_client ( struct sender_status ss)

Accept a connection on the socket(s) this server is listening on.

Parameters
ssThe sender whose listening fd is ready for reading.

This accepts incoming connections on any of the listening sockets of the server. If there is a connection pending, the function

 - Checks whether the maximal number of connections are exceeded.
 - Sets \a fd to nonblocking mode.
 - Checks the acl of the sender to find out whether connections
   are allowed from the IP of the connecting peer.
    - Increases the number of connections for this sender.
 - Creates and initializes a new chunk queue for queuing network
   packets that can not be sent immediately.
 - Allocates a new struct sender_client and fills in its \a fd, \a cq
   and \a name members.
 - Adds \a fd to the list of connected clients for this sender.
 - Adds \a fd to the list of file descriptors that should be closed
   in the child process when the server calls fork().
Returns
A pointer to the allocated sender_client structure on success, NULL on errors.
See also
para_accept(), mark_fd_nonblocking(), acl_check_access(), cq_new(), add_close_on_fork_list().

References sender_status::acl, acl_check_access(), sender_client::cq, cq_new(), sender_status::default_deny, sender_client::fd, FOR_EACH_LISTEN_FD, sender_status::listen_fds, mark_fd_nonblocking(), sender_status::max_clients, MAX_CQ_BYTES, sender_client::name, sender_status::num_clients, para_accept(), para_strdup(), remote_name(), and zalloc().

◆ send_queued_chunks()

int send_queued_chunks ( int  fd,
struct chunk_queue *  cq 
)

Try to empty the chunk queue for this fd.

Parameters
fdThe file descriptor.
cqThe list of queued chunks.
Returns
Negative on errors, zero if not everything was sent, one otherwise.

References cq_dequeue(), cq_get(), cq_peek(), cq_update(), and xwrite().

◆ parse_fec_url()

int parse_fec_url ( const char *  arg,
struct sender_command_data scd 
)

Parse a FEC URL string.

Parameters
argthe URL string to parse.
scdThe structure containing host, port and the FEC parameters.
Returns
Standard.

A FEC URL consists of an ordinary URL string according to RFC 3986, optionally followed by a slash and the three FEC parameters slice_size, data_slices_per_group and slices_per_group. The three FEC parameters are separated by colons.

See also
parse_url().

References sender_command_data::data_slices_per_group, sender_command_data::max_slice_bytes, para_strdup(), and sender_command_data::slices_per_group.

Variable Documentation

◆ senders

const struct sender* const senders[]
extern

NULL-terminated list, defined in vss.c.

Referenced by vss_shutdown().

SENDER_SUBCOMMAND
#define SENDER_SUBCOMMAND(_name)
Concatenate "SENDER_" and the given arg and append a comma.
Definition: send.h:39