paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Macros | Functions
send_common.c File Reference

Functions used by more than one paraslash sender. More...

#include <netinet/in.h>
#include <sys/socket.h>
#include <regex.h>
#include <osl.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <netdb.h>
#include <lopsub.h>
#include "para.h"
#include "error.h"
#include "string.h"
#include "fd.h"
#include "net.h"
#include "list.h"
#include "afh.h"
#include "afs.h"
#include "server.h"
#include "acl.h"
#include "sched.h"
#include "send.h"
#include "close_on_fork.h"
#include "chunk_queue.h"
#include "vss.h"

Macros

#define MAX_CQ_BYTES   40000
 Clients will be kicked if there are more than that many bytes pending. 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...
 
int send_queued_chunks (int fd, struct chunk_queue *cq)
 Try to empty the chunk queue for this fd. 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_acl_deplete (struct list_head *acl)
 Empty the access control list of a sender. 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_com_off (struct sender_status *ss)
 Deactivate a paraslash sender. More...
 
struct sender_clientaccept_sender_client (struct sender_status *ss)
 Accept a connection on the socket(s) this server is listening on. More...
 
__malloc char * generic_sender_help (void)
 Get the generic help text. More...
 
int parse_fec_url (const char *arg, struct sender_command_data *scd)
 Parse a FEC URL string. More...
 

Detailed Description

Functions used by more than one paraslash sender.

Macro Definition Documentation

◆ MAX_CQ_BYTES

#define MAX_CQ_BYTES   40000

Clients will be kicked if there are more than that many bytes pending.

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().

◆ 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().

◆ 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_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_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_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().

◆ 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().

◆ 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().

◆ 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.