1 /* Icecast
2  *
3  * This program is distributed under the GNU General Public License, version 2.
4  * A copy of this license is included with this source.
5  *
6  * Copyright 2000-2004, Jack Moffitt <jack@xiph.org>,
7  *                      Michael Smith <msmith@xiph.org>,
8  *                      oddsock <oddsock@xiph.org>,
9  *                      Karl Heyes <karl@xiph.org>
10  *                      and others (see AUTHORS for details).
11  * Copyright 2011,      Dave 'justdave' Miller <justdave@mozilla.com>.
12  * Copyright 2011-2014, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
13  */
14 
15 #ifndef __CFGFILE_H__
16 #define __CFGFILE_H__
17 
18 #define CONFIG_EINSANE -1
19 #define CONFIG_ENOROOT -2
20 #define CONFIG_EBADROOT -3
21 #define CONFIG_EPARSE -4
22 
23 #define MAX_YP_DIRECTORIES 25
24 
25 struct _mount_proxy;
26 
27 #include "thread/thread.h"
28 #include "avl/avl.h"
29 #include "auth.h"
30 #include "global.h"
31 #include "connection.h"
32 
33 #define XMLSTR(str) ((xmlChar *)(str))
34 
35 typedef enum _http_header_type {
36  /* static: headers are passed as is to the client. */
37  HTTP_HEADER_TYPE_STATIC
38 } http_header_type;
39 
40 typedef struct ice_config_http_header_tag {
41     /* type of this header. See http_header_type */
42     http_header_type type;
43 
44     /* name and value of the header */
45     char *name;
46     char *value;
47 
48     /* filters */
49     int status;
50 
51     /* link to the next list element */
52     struct ice_config_http_header_tag *next;
53 } ice_config_http_header_t;
54 
55 typedef struct ice_config_dir_tag {
56     char *host;
57     int touch_interval;
58     struct ice_config_dir_tag *next;
59 } ice_config_dir_t;
60 
61 typedef struct _config_options {
62     char *name;
63     char *value;
64     struct _config_options *next;
65 } config_options_t;
66 
67 typedef enum _mount_type {
68  MOUNT_TYPE_NORMAL,
69  MOUNT_TYPE_DEFAULT
70 } mount_type;
71 
72 typedef struct _mount_proxy {
73     char *mountname; /* The mountpoint this proxy is used for */
74 
75     mount_type mounttype; /* The type of the mount point */
76 
77     char *username; /* Username and password for this mountpoint. If unset, */
78     char *password; /* falls back to global source password */
79 
80     char *dumpfile; /* Filename to dump this stream to (will be appended). NULL
81                        to not dump. */
82     char *intro_filename;   /* Send contents of file to client before the stream */
83     int fallback_when_full; /* switch new listener to fallback source
84                                when max listeners reached */
85     int max_listeners; /* Max listeners for this mountpoint only. -1 to not
86                           limit here (i.e. only use the global limit) */
87     char *fallback_mount; /* Fallback mountname */
88 
89     int fallback_override; /* When this source arrives, do we steal back
90                               clients from the fallback? */
91     int no_mount; /* Do we permit direct requests of this mountpoint? (or only
92                      indirect, through fallbacks) */
93     int burst_size; /* amount to send to a new client if possible, -1 take
94                      * from global setting */
95     unsigned int queue_size_limit;
96     int hidden; /* Do we list this on the xsl pages */
97     unsigned int source_timeout;  /* source timeout in seconds */
98     char *charset;  /* character set if not utf8 */
99     int mp3_meta_interval; /* outgoing per-stream metadata interval */
100 
101     ice_config_http_header_t *http_headers; /* additional HTTP headers */
102 
103     char *auth_type; /* Authentication type */
104     struct auth_tag *auth;
105     char *cluster_password;
106     config_options_t *auth_options; /* Options for this type */
107     char *on_connect;
108     char *on_disconnect;
109     unsigned int max_listener_duration;
110 
111     char *stream_name;
112     char *stream_description;
113     char *stream_url;
114     char *stream_genre;
115     char *bitrate;
116     char *type;
117     char *subtype;
118     int yp_public;
119 
120     struct _mount_proxy *next;
121 } mount_proxy;
122 
123 typedef struct _aliases {
124     char *source;
125     char *destination;
126     int port;
127     char *bind_address;
128     struct _aliases *next;
129 } aliases;
130 
131 typedef struct _listener_t {
132     struct _listener_t *next;
133     int port;
134     int so_sndbuf;
135     char *bind_address;
136     int shoutcast_compat;
137     char *shoutcast_mount;
138     int ssl;
139 } listener_t;
140 
141 typedef struct ice_config_tag {
142     char *config_filename;
143 
144     char *location;
145     char *admin;
146 
147     int client_limit;
148     int source_limit;
149     unsigned int queue_size_limit;
150     int threadpool_size;
151     unsigned int burst_size;
152     int client_timeout;
153     int header_timeout;
154     int source_timeout;
155     int ice_login;
156     int fileserve;
157     int on_demand; /* global setting for all relays */
158 
159     char *shoutcast_mount;
160     char *source_password;
161     char *admin_username;
162     char *admin_password;
163     char *relay_username;
164     char *relay_password;
165 
166     int touch_interval;
167     ice_config_dir_t *dir_list;
168 
169     char *hostname;
170     int port;
171     char *mimetypes_fn;
172 
173     listener_t *listen_sock;
174     unsigned int listen_sock_count;
175 
176     char *master_server;
177     int master_server_port;
178     int master_update_interval;
179     char *master_username;
180     char *master_password;
181 
182     ice_config_http_header_t *http_headers;
183 
184     relay_server *relay;
185 
186     mount_proxy *mounts;
187 
188     char *server_id;
189     char *base_dir;
190     char *log_dir;
191     char *pidfile;
192     char *banfile;
193     char *allowfile;
194     char *cert_file;
195     char *cipher_list;
196     char *webroot_dir;
197     char *adminroot_dir;
198     aliases *aliases;
199 
200     char *access_log;
201     char *error_log;
202     char *playlist_log;
203     int loglevel;
204     int logsize;
205     int logarchive;
206 
207     int chroot;
208     int chuid;
209     char *user;
210     char *group;
211     char *yp_url[MAX_YP_DIRECTORIES];
212     int    yp_url_timeout[MAX_YP_DIRECTORIES];
213     int    yp_touch_interval[MAX_YP_DIRECTORIES];
214     int num_yp_directories;
215 } ice_config_t;
216 
217 typedef struct {
218     rwlock_t config_lock;
219     mutex_t relay_lock;
220 } ice_config_locks;
221 
222 void config_initialize(void);
223 void config_shutdown(void);
224 
225 int config_parse_file(const char *filename, ice_config_t *configuration);
226 int config_initial_parse_file(const char *filename);
227 int config_parse_cmdline(int arg, char **argv);
228 void config_set_config(ice_config_t *config);
229 listener_t *config_clear_listener (listener_t *listener);
230 void config_clear(ice_config_t *config);
231 mount_proxy *config_find_mount (ice_config_t *config, const char *mount, mount_type type);
232 listener_t *config_get_listen_sock (ice_config_t *config, connection_t *con);
233 
234 int config_rehash(void);
235 
236 ice_config_locks *config_locks(void);
237 
238 ice_config_t *config_get_config(void);
239 ice_config_t *config_grab_config(void);
240 void config_release_config(void);
241 
242 /* To be used ONLY in one-time startup code */
243 ice_config_t *config_get_config_unlocked(void);
244 
245 #endif  /* __CFGFILE_H__ */
246