NEWS update
[paraslash.git] / server.h
1 /*
2  * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file server.h common server data structures */
8
9 #include "para.h"
10 #include "afh.h"
11
12 /** size of the selector_info and audio_file info strings of struct misc_meta_data */
13 #define MMD_INFO_SIZE 16384
14
15 /**
16  * defines one command of para_server
17  */
18 struct server_command {
19 /** the name of the command */
20         const char *name;
21 /** pointer to the function that handles the command */
22         int (*handler)(int, int, char **);
23 /** the privileges a user must have to execute this command */
24         unsigned int perms;
25 /** one-line description of the command */
26         const char *description;
27 /** summary of the command line options */
28         const char *usage;
29 /** the long help text */
30         const char *help;
31 };
32
33 /** holds the arguments for the para_server's sender command */
34 struct sender_command_data{
35 /** greater than 0 indicates that a sender cmd is already queued */
36         int cmd_num;
37 /** the number of the sender in question */
38         int sender_num;
39 /** used for the allow/deny/add/remove subcommands */
40         struct in_addr addr;
41 /** used for allow/deny */
42         int netmask;
43 /** the portnumber for add/remove */
44         int port;
45 };
46
47 /**
48  * used for parent-child communication
49  *
50  * There's only one struct of this type which lives in shared memory
51  * for communication between the server instances. Access to this
52  * area is serialized via mmd_lock() and mmd_unlock(). There are two
53  * reasons for a variable to be included here:
54  *
55  *      - At least one command (i.e. child of the server) must be able to
56  *      change its value.
57  *
58  * or
59  *
60  *      - The contents are listed in the stat command and have to be up to
61  *      date.
62  */
63 struct misc_meta_data {
64 /** information on the current audio file  */
65         struct audio_format_info afi;
66 /** the size of the current audio file in bytes */
67         size_t size;
68 /** the full path of the current audio file */
69         char filename[_POSIX_PATH_MAX];
70 /** the last modification file of the current audio file */
71         time_t mtime;
72 /** the number of the current audio format */
73         int audio_format;
74 /** the "old" status flags -- commands may only read them */
75         unsigned int vss_status_flags;
76 /** the new status flags -- commands may set them **/
77         unsigned int new_vss_status_flags;
78 /** the number of data chunks sent for the current audio file */
79         long unsigned chunks_sent;
80 /** set by the jmp/ff commands to the new position in chunks */
81         long unsigned repos_request;
82 /** the number of the chunk currently sent out*/
83         long unsigned current_chunk;
84 /** the milliseconds that have been skipped of the current audio file */
85         long offset;
86 /** the time para_server started to stream */
87         struct timeval stream_start;
88 /** the event counter
89  *
90  * commands may increase this to force a status update to be sent to all
91  * connected clients
92 */
93         unsigned int events;
94 /** the number of audio files already sent */
95         unsigned int num_played;
96 /** the number of executed commands */
97         unsigned int num_commands;
98 /** the number of connections para_server received so far */
99         unsigned int num_connects;
100 /** the number of connections currently active */
101         unsigned int active_connections;
102 /** the process id of para_server */
103         pid_t server_pid;
104 /** a string that gets filled in by the current audio file selector */
105         char selector_info[MMD_INFO_SIZE];
106 /** the number if the current audio file selector */
107         int selector_num;
108 /** commands set this to non-zero to change the current selector */
109         int selector_change;
110 /** used by the sender command */
111         struct sender_command_data sender_cmd_data;
112 };
113
114 extern struct server_args_info conf;
115
116 int handle_connect(int fd, struct sockaddr_in *addr);
117 void mmd_unlock(void);
118 void mmd_lock(void);