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 add its own
84 * file descriptors to the \a rfds or the \a wfds set.
86 * If a file descriptor was added, \a max_fileno must be increased by
87 * this function, if necessary.
91 void (*pre_select)(int *max_fileno, fd_set *rfds, fd_set *wfds);
93 * Handle the file descriptors which are ready for I/O.
95 * If the pre_select hook added one ore more file descriptors to the
96 * read or write set, this is the hook to check the result and do any
97 * I/O on those descriptors which are ready for reading/writing.
99 void (*post_select)(fd_set *rfds, fd_set *wfds);
101 * Terminate all connected clients.
103 * This is called e.g. if the stop command was executed. It should make
104 * the clients aware of the end-of-file condition.
106 void (*shutdown_clients)(void);
107 /** Dellocate all resources. Only called on exit. */
108 void (*shutdown)(void);
110 * Array of function pointers for the sender subcommands.
112 * Each sender may implement any subset of the sender commands by
113 * filling in the appropriate function pointer in the array. A \p NULL
114 * pointer means this command is not implemented by this sender.
116 int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
118 * Resolve target-specific URL string
120 * This method must be defined if the sender supports the add/delete
121 * subcommands. It interprets a string specifying a target URL in a
122 * sender-specific fashion (e.g. embedded FEC string). It can also
123 * fill in sender-specific defaults if necessary.
125 int (*resolve_target)(const char *, struct sender_command_data *);
128 /** NULL-terminated list, defined in \ref vss.c. */
129 extern const struct sender * const senders[];
130 /** Iterate over all senders. */
131 #define FOR_EACH_SENDER(_i) for ((_i) = 0; senders[(_i)]; (_i)++)
133 /** Describes one client, connected to a paraslash sender. */
134 struct sender_client {
135 /** The file descriptor of the client. */
137 /** The socket "name" of the client. */
139 /** The position of this client in the client list. */
140 struct list_head node;
141 /** Non-zero if audio file header has been sent. */
143 /** The list of pending chunks for this client. */
144 struct chunk_queue *cq;
145 /** Data specific to the particular sender. */
150 * Each paraslash sender may register arbitrary many clients to the virtual
151 * streaming system, possibly with varying fec parameters. In order to do so,
152 * it must allocate a \a fec_client_parms structure and pass it to \ref
153 * vss_add_fec_client.
155 * Clients are automatically removed from that list by the vss if an error
156 * occurs, or if the sender requests deletion of a client by calling \ref
157 * vss_del_fec_client().
160 /** FEC parameters requested by FEC clients. */
161 struct fec_client_parms {
162 /** Number of data slices plus redundant slices. */
163 uint8_t slices_per_group;
164 /** Number of slices minus number of redundant slices. */
165 uint8_t data_slices_per_group;
166 /** Whether the header must be sent periodically. */
167 bool need_periodic_header;
169 * Transport-layer initialisation for FEC support.
171 * This optional function serves (a) to make the transport layer
172 * ready to send FEC slices and (b) to determine the Maximum
173 * Packet Size (MPS) supported by the connection. The MPS value
174 * determines the largest payload size. This value is used to
175 * send FEC slices that are not larger than the path MTU, to avoid
176 * fragmentation and to maximize packet utilization. The user can
177 * alternatively specify a slice size of up to this value.
179 int (*init_fec)(struct sender_client *sc);
180 /** Push out FEC-encoded packets */
181 void (*send_fec)(struct sender_client *sc, char *buf, size_t len);
184 /** Describes the current status of one paraslash sender. */
185 struct sender_status {
186 /** Number of sockets to listen on, size of the two arrays below. */
187 unsigned num_listen_fds;
188 /** Derived from --http-listen-address and --dccp-listen-address. */
189 char **listen_addresses;
190 /** Default TCP/DCCP port number for addresses w/o port. */
192 /** The socket fd(s) this sender is listening on. */
194 /** The current number of simultaneous connections. */
196 /** The maximal number of simultaneous connections. */
198 /** Whether the access control list is a whitelist. */
200 /** The whitelist/blacklist. */
201 struct list_head acl;
202 /** The list of connected clients. */
203 struct list_head client_list;
206 /** Iterate over all listening addresses of the http/dccp sender. */
207 #define FOR_EACH_LISTEN_FD(_n, _ss) for (_n = 0; _n < (_ss)->num_listen_fds; _n++)
209 void shutdown_client(struct sender_client *sc, struct sender_status *ss);
210 void shutdown_clients(struct sender_status *ss);
211 void init_sender_status(struct sender_status *ss,
212 const struct lls_opt_result *acl_opt_result,
213 const struct lls_opt_result *listen_address_opt_result,
214 int default_port, int max_clients, int default_deny);
215 void free_sender_status(const struct sender_status *ss);
216 char *generic_sender_status(struct sender_status *ss, const char *name);
217 void generic_com_allow(struct sender_command_data *scd,
218 struct sender_status *ss);
219 void generic_com_deny(struct sender_command_data *scd,
220 struct sender_status *ss);
221 void generic_com_on(struct sender_status *ss, unsigned protocol);
222 void generic_acl_deplete(struct list_head *acl);
223 void generic_com_off(struct sender_status *ss);
224 char *generic_sender_help(void);
225 struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds);
226 int send_queued_chunks(int fd, struct chunk_queue *cq);
227 int parse_fec_url(const char *arg, struct sender_command_data *scd);