afh: Fix typo in comment.
[paraslash.git] / server.h
1 /*
2  * Copyright (C) 1997 Andre Noll <maan@tuebingen.mpg.de>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file server.h Common server data structures. */
8
9 /** Size of the selector_info and audio_file info strings of struct misc_meta_data. */
10 #define MMD_INFO_SIZE 16384
11
12 /** The maximum length of the host component in an URL */
13 #define MAX_HOSTLEN 256
14
15
16 /** Arguments for the sender command. */
17 struct sender_command_data {
18         /** Greater than zero indicates that a sender cmd is already queued. */
19         int cmd_num;
20         /** The number of the sender in question. */
21         int sender_num;
22         /** Used for the allow/deny/add/remove subcommands. */
23         char host[MAX_HOSTLEN];
24         /** Used for allow/deny. */
25         int netmask;
26         /** The port number for add/remove. */
27         int port;
28         /** Maximal slice size. */
29         uint16_t max_slice_bytes;
30         /** Number of data slices plus redundant slices. */
31         uint8_t slices_per_group;
32         /** Number of slices minus number of redundant slices. */
33         uint8_t data_slices_per_group;
34 };
35
36 /**
37  * Miscellaneous data for communication between server and command handlers.
38  *
39  * There's only one instance of this structure which lives in a shared memory
40  * area. Command handlers communicate with the server process through this
41  * area. Changes made by the command handlers stay after the command handler
42  * exits. Conversely, changes made by the server process propagate to the
43  * command handlers. Access to this area is serialized via mmd_lock() and
44  * mmd_unlock().
45  *
46  * There are two reasons for a variable to be included here: (a) at least one
47  * command handler changes its value, or (b) updates by the server must
48  * propagate to the stat command handlers.
49  */
50 struct misc_meta_data {
51         /** The "old" status flags -- commands may only read them. */
52         unsigned int vss_status_flags;
53         /** The new status flags -- commands may set them. */
54         unsigned int new_vss_status_flags;
55         /** The number of data chunks sent so far. */
56         long unsigned chunks_sent;
57         /** Set by the jmp/ff commands to the new position in chunks. */
58         long unsigned repos_request;
59         /** The number of the chunk currently being sent. */
60         long unsigned current_chunk;
61         /** The milliseconds that have been skipped of the current audio file. */
62         long offset;
63         /** The time para_server started to stream. */
64         struct timeval stream_start;
65         /**
66          * The event counter.
67          *
68          * Commands may increase this to force a status update to be sent to
69          * all connected stat clients.
70          */
71         unsigned int events;
72         /** The number of audio files already sent. */
73         unsigned int num_played;
74         /** The number of executed commands. */
75         unsigned int num_commands;
76         /** The number of connections para_server received so far. */
77         unsigned int num_connects;
78         /** The number of connections currently active. */
79         unsigned int active_connections;
80         /** The process id of the audio file selector. */
81         pid_t afs_pid;
82         /** This gets updated by afs and contains its current mode. */
83         char afs_mode_string[MAXLINE];
84         /** Used by the sender command. */
85         struct sender_command_data sender_cmd_data;
86         /** Describes the current audio file. */
87         struct audio_file_data afd;
88 };
89
90 extern struct lls_parse_result *server_lpr;
91
92 /**
93  * Get a reference to the supercommand of para_server.
94  *
95  * This is needed for parsing the command line and for the ENUM_STRING_VAL()
96  * macro below. The latter macro is used in command.c, so CMD_PTR() can not
97  * be made local to server.c.
98  */
99 #define CMD_PTR (lls_cmd(0, server_suite))
100
101 /** Get the parse result of an option to para_server. */
102 #define OPT_RESULT(_name) (lls_opt_result( \
103                 LSG_SERVER_PARA_SERVER_OPT_ ## _name, server_lpr))
104
105 /** How many times a server option was given. */
106 #define OPT_GIVEN(_name) (lls_opt_given(OPT_RESULT(_name)))
107
108 /** The (first) argument to a server option of type string. */
109 #define OPT_STRING_VAL(_name) (lls_string_val(0, OPT_RESULT(_name)))
110
111 /** The (first) argument to a server option of type uint32. */
112 #define OPT_UINT32_VAL(_name) (lls_uint32_val(0, OPT_RESULT(_name)))
113
114 /** The (first) argument to a server option of type int32. */
115 #define OPT_INT32_VAL(_name) (lls_int32_val(0, OPT_RESULT(_name)))
116
117 /** Get the string which corresponds to an enum constant. */
118 #define ENUM_STRING_VAL(_name) (lls_enum_string_val(OPT_UINT32_VAL(_name), \
119         lls_opt(LSG_SERVER_PARA_SERVER_OPT_ ## _name, CMD_PTR)))
120
121 __noreturn void handle_connect(int fd, const char *peername);
122 void parse_config_or_die(bool reload);
123 char *server_get_tasks(void);