1 /* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file send.h Sender-related defines and structures. */
6 * A little preprocessor fu helps to create the sender_subcommand enumeration
7 * below and the list of sender name strings without duplicating the commands.
9 #define SENDER_SUBCOMMANDS \
10 SENDER_SUBCOMMAND(add) /**< Add a target (udp only). */ \
11 SENDER_SUBCOMMAND(delete) /**< Delete a target (udp only). */ \
12 SENDER_SUBCOMMAND(allow) /**< Allow connections from given IP address(es). */ \
13 SENDER_SUBCOMMAND(deny) /**< Deny connections from given IP address(es). */ \
14 SENDER_SUBCOMMAND(on) /**< Activate the sender. */ \
15 SENDER_SUBCOMMAND(off) /**< Deactivate the sender. */ \
17 /** Concatenate "SENDER_" and the given arg and append a comma. */
18 #define SENDER_SUBCOMMAND(_name) SENDER_ ## _name,
21 * Each sender subcommand gets an SENDER_xxx identifier. The identifier is
22 * passed from the sender command handler to the server process via shared
25 enum sender_subcommand {
26 SENDER_SUBCOMMANDS /**< List of SENDER_xxx identifiers. */
27 NUM_SENDER_CMDS /**< Used as array size in struct \ref sender. */
30 #undef SENDER_SUBCOMMAND
33 * Redefine it to expand to the stringified name of the sender so that
34 * SENDER_SUBCOMMANDS above now expands to the comma-separated list of sender
35 * name strings. This is used in command.c to define and initialize an array of
38 #define SENDER_SUBCOMMAND(_name) #_name,
41 * Describes one supported sender of para_server.
43 * \sa \ref http_send.c \ref udp_send.c, \ref dccp_send.c.
46 /** The name of the sender. */
49 * Parse the command line options and initialize this sender (e.g.,
50 * initialize target or access control lists, listen on a network
55 * Return the help text of this sender.
57 * The result must be dynamically allocated and is freed by the caller.
61 * Return current status info about this sender.
63 * The result must be dynamically allocated and is freed by the caller.
65 char* (*status)(void);
69 * It gets called whenever para_server is playing and the current
70 * audio format handler indicates that another chunk of data should
71 * be sent now. The two parameters \a current_chunk and \a chunks_sent
72 * only differ if the stream was repositioned by the \a ff or \a jmp
73 * command. Of course, \a buf is a pointer to the chunk of data which
74 * should be sent, and \a len is the length of this buffer.
76 void (*send)(long unsigned current_chunk, long unsigned chunks_sent,
77 const char *buf, size_t len, const char *header_buf,
80 * Add file descriptors to fd_sets.
82 * The pre_select function of each supported sender is called just before
83 * para_server enters its main select loop. Each sender may watch its own
84 * file descriptors for reading or writing.
88 void (*pre_select)(struct sched *s);
90 * Handle the file descriptors which are ready for I/O.
92 * If the pre_select hook asked for one or more file descriptors to be
93 * watched, this is the hook to check the result and perform I/O on the
94 * descriptors which are ready for reading/writing.
96 void (*post_select)(struct sched *s);
98 * Terminate all connected clients.
100 * This is called e.g. if the stop command was executed. It should make
101 * the clients aware of the end-of-file condition.
103 void (*shutdown_clients)(void);
104 /** Dellocate all resources. Only called on exit. */
105 void (*shutdown)(void);
107 * Array of function pointers for the sender subcommands.
109 * Each sender may implement any subset of the sender commands by
110 * filling in the appropriate function pointer in the array. A \p NULL
111 * pointer means this command is not implemented by this sender.
113 int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
115 * Resolve target-specific URL string
117 * This method must be defined if the sender supports the add/delete
118 * subcommands. It interprets a string specifying a target URL in a
119 * sender-specific fashion (e.g. embedded FEC string). It can also
120 * fill in sender-specific defaults if necessary.
122 int (*resolve_target)(const char *, struct sender_command_data *);
125 /** NULL-terminated list, defined in \ref vss.c. */
126 extern const struct sender * const senders[];
127 /** Iterate over all senders. */
128 #define FOR_EACH_SENDER(_i) for ((_i) = 0; senders[(_i)]; (_i)++)
130 /** Describes one client, connected to a paraslash sender. */
131 struct sender_client {
132 /** The file descriptor of the client. */
134 /** The socket "name" of the client. */
136 /** The position of this client in the client list. */
137 struct list_head node;
138 /** Non-zero if audio file header has been sent. */
140 /** The list of pending chunks for this client. */
141 struct chunk_queue *cq;
142 /** Data specific to the particular sender. */
147 * Each paraslash sender may register arbitrary many clients to the virtual
148 * streaming system, possibly with varying fec parameters. In order to do so,
149 * it must allocate a \a fec_client_parms structure and pass it to \ref
150 * vss_add_fec_client.
152 * Clients are automatically removed from that list by the vss if an error
153 * occurs, or if the sender requests deletion of a client by calling \ref
154 * vss_del_fec_client().
157 /** FEC parameters requested by FEC clients. */
158 struct fec_client_parms {
159 /** Number of data slices plus redundant slices. */
160 uint8_t slices_per_group;
161 /** Number of slices minus number of redundant slices. */
162 uint8_t data_slices_per_group;
163 /** Whether the header must be sent periodically. */
164 bool need_periodic_header;
166 * Transport-layer initialisation for FEC support.
168 * This optional function serves (a) to make the transport layer
169 * ready to send FEC slices and (b) to determine the Maximum
170 * Packet Size (MPS) supported by the connection. The MPS value
171 * determines the largest payload size. This value is used to
172 * send FEC slices that are not larger than the path MTU, to avoid
173 * fragmentation and to maximize packet utilization. The user can
174 * alternatively specify a slice size of up to this value.
176 int (*init_fec)(struct sender_client *sc);
177 /** Push out FEC-encoded packets */
178 void (*send_fec)(struct sender_client *sc, char *buf, size_t len);
181 /** Describes the current status of one paraslash sender. */
182 struct sender_status {
183 /** Number of sockets to listen on, size of the two arrays below. */
184 unsigned num_listen_fds;
185 /** Derived from --http-listen-address and --dccp-listen-address. */
186 char **listen_addresses;
187 /** Default TCP/DCCP port number for addresses w/o port. */
189 /** The socket fd(s) this sender is listening on. */
191 /** The current number of simultaneous connections. */
193 /** The maximal number of simultaneous connections. */
195 /** Whether the access control list is a whitelist. */
197 /** The whitelist/blacklist. */
198 struct list_head acl;
199 /** The list of connected clients. */
200 struct list_head client_list;
203 /** Iterate over all listening addresses of the http/dccp sender. */
204 #define FOR_EACH_LISTEN_FD(_n, _ss) for (_n = 0; _n < (_ss)->num_listen_fds; _n++)
206 void shutdown_client(struct sender_client *sc, struct sender_status *ss);
207 void shutdown_clients(struct sender_status *ss);
208 void init_sender_status(struct sender_status *ss,
209 const struct lls_opt_result *acl_opt_result,
210 const struct lls_opt_result *listen_address_opt_result,
211 int default_port, int max_clients, int default_deny);
212 void free_sender_status(const struct sender_status *ss);
213 char *generic_sender_status(struct sender_status *ss, const char *name);
214 void generic_com_allow(struct sender_command_data *scd,
215 struct sender_status *ss);
216 void generic_com_deny(struct sender_command_data *scd,
217 struct sender_status *ss);
218 void generic_com_on(struct sender_status *ss, unsigned protocol);
219 void generic_acl_deplete(struct list_head *acl);
220 void generic_com_off(struct sender_status *ss);
221 char *generic_sender_help(void);
222 struct sender_client *accept_sender_client(struct sender_status *ss);
223 int send_queued_chunks(int fd, struct chunk_queue *cq);
224 int parse_fec_url(const char *arg, struct sender_command_data *scd);