Paraslash Audio Streaming | |
About News Download Documentation Development |
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_client * | accept_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... | |
Functions used by more than one paraslash sender.
#define MAX_CQ_BYTES 40000 |
Clients will be kicked if there are more than that many bytes pending.
void shutdown_client | ( | struct sender_client * | sc, |
struct sender_status * | ss | ||
) |
Shut down a client connected to a paraslash sender.
sc | The client to shut down. |
ss | The 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.
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().
void shutdown_clients | ( | struct sender_status * | ss | ) |
Shut down all clients connected to a paraslash sender.
ss | The 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().
int send_queued_chunks | ( | int | fd, |
struct chunk_queue * | cq | ||
) |
Try to empty the chunk queue for this fd.
fd | The file descriptor. |
cq | The list of queued chunks. |
References cq_dequeue(), cq_get(), cq_peek(), cq_update(), and xwrite().
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.
ss | The struct to initialize. |
acl_opt_result | Contains array of –{http|dccp}-access arguments. |
listen_address_opt_result | Where to listen on. |
default_port | Used for addresses with no specified port. |
max_clients | The maximal number of simultaneous connections. |
default_deny | Whether 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().
void free_sender_status | ( | const struct sender_status * | ss | ) |
Deallocate all resources allocated in init_sender_status().
ss | The 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.
__malloc char* generic_sender_status | ( | struct sender_status * | ss, |
const char * | name | ||
) |
Return a string containing the current status of a sender.
ss | The sender. |
name | Used for printing the header line. |
References sender_status::acl, acl_get_contents(), sender_status::client_list, sender_status::default_deny, sender_status::default_port, FOR_EACH_LISTEN_FD, format_url(), list_for_each_entry_safe, sender_status::listen_addresses, sender_status::listen_fds, make_message(), sender_status::max_clients, sender_client::name, sender_client::node, sender_status::num_clients, and stringify_port().
void generic_com_allow | ( | struct sender_command_data * | scd, |
struct sender_status * | ss | ||
) |
Allow connections from the given range of IP addresses.
scd | Contains the IP and the netmask. |
ss | The sender. |
References sender_status::acl, acl_allow(), sender_status::default_deny, sender_command_data::host, and sender_command_data::netmask.
void generic_acl_deplete | ( | struct list_head * | acl | ) |
Empty the access control list of a sender.
acl | The access control list of the sender. |
This is called from the ->shutdown methods of the http and the dccp sender.
References acl_allow().
void generic_com_deny | ( | struct sender_command_data * | scd, |
struct sender_status * | ss | ||
) |
Deny connections from the given range of IP addresses.
scd | see generic_com_allow(). |
ss | see generic_com_allow(). |
References sender_status::acl, acl_deny(), sender_status::default_deny, sender_command_data::host, and sender_command_data::netmask.
void generic_com_on | ( | struct sender_status * | ss, |
unsigned | protocol | ||
) |
Activate a paraslash sender.
ss | The sender to activate. |
protocol | layer4 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().
void generic_com_off | ( | struct sender_status * | ss | ) |
Deactivate a paraslash sender.
Shutdown all connected clients and stop listening on the TCP/DCCP socket.
ss | The sender to deactivate. |
References del_close_on_fork_list(), FOR_EACH_LISTEN_FD, sender_status::listen_fds, and shutdown_clients().
struct sender_client* accept_sender_client | ( | struct sender_status * | ss | ) |
Accept a connection on the socket(s) this server is listening on.
ss | The 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().
NULL
on errors.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().
__malloc char* generic_sender_help | ( | void | ) |
Get the generic help text.
References make_message().
int parse_fec_url | ( | const char * | arg, |
struct sender_command_data * | scd | ||
) |
Parse a FEC URL string.
arg | the URL string to parse. |
scd | The structure containing host, port and the FEC parameters. |
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.
References sender_command_data::data_slices_per_group, sender_command_data::max_slice_bytes, para_strdup(), and sender_command_data::slices_per_group.