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