grab: use grab_client_cmdline_parser_string()
[paraslash.git] / server.h
1 /*
2 * Copyright (C) 1997-2006 Andre Noll <maan@systemlinux.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
17 */
18
19 /** \file server.h common server data structures */
20
21 #include "para.h"
22
23
24 /** size of the selector_info and audio_file info strings of struct misc_meta_data */
25 #define MMD_INFO_SIZE 16384
26
27 /**
28 * permission flags that can be set individually for any server command
29 *
30 * - DB_READ: command reads from the database
31 * - DB_WRITE: command changes the contents of the database
32 * - AFS_READ: command reads information about the current audio stream
33 * - AFS_WRITE: command changes the current audio stream
34 */
35 enum {DB_READ = 1, DB_WRITE = 2, AFS_READ = 4, AFS_WRITE = 8};
36
37 /**
38 * data needed to authenticate the user
39 */
40 struct user{
41 /** the username */
42 char name[MAXLINE];
43 /** full path to the public RSA key */
44 char pubkey_file[_POSIX_PATH_MAX];
45 /** the privileges of this user */
46 unsigned int perms;
47 };
48
49 /**
50 * defines one command of para_server
51 */
52 struct server_command {
53 /** the name of the command */
54 const char *name;
55 /** pointer to the function that handles the command */
56 int (*handler)(int, int, char **);
57 /** the privileges a user must have to execute this command */
58 unsigned int perms;
59 /** one-line description of the command */
60 const char *description;
61 /** summary of the command line options */
62 const char *synopsis;
63 /** the long help text */
64 const char *help;
65 };
66
67 /** holds the arguments for the para_server's sender command */
68 struct sender_command_data{
69 /** greater than 0 indicates that a sender cmd is already queued */
70 int cmd_num;
71 /** the number of the sender in question */
72 int sender_num;
73 /** used for the allow/deny/add/remove subcommands */
74 struct in_addr addr;
75 /** used for allow/deny */
76 int netmask;
77 /** the portnumber for add/remove */
78 int port;
79 };
80
81 /**
82 * used for parent-child communication
83 *
84 * There's only one struct of this type which lives in shared memory
85 * for communication between the server instances. Access to this
86 * area is serialized via mmd_lock() and mmd_unlock(). There are two
87 * reasons for a variable to be included here:
88 *
89 * - At least one command (i.e. child of the server) must be able to
90 * change its value.
91 *
92 * or
93 *
94 * - The contents are listed in the stat command and have to be up to
95 * date.
96 */
97 struct misc_meta_data{
98 /** the size of the current audio file in bytes */
99 long unsigned int size;
100 /** the full path of the current audio file */
101 char filename[_POSIX_PATH_MAX];
102 /** the last modification file of the current audio file */
103 time_t mtime;
104 /* the number of the current audio format */
105 int audio_format;
106 /** the "old" status flags -- commands may only read them */
107 unsigned int afs_status_flags;
108 /** the new status flags -- commands may set them **/
109 unsigned int new_afs_status_flags;
110 /** the number of data chunks sent for the current audio file */
111 long unsigned chunks_sent;
112 /** the number of chunks this audio file contains */
113 long unsigned chunks_total;
114 /** set by the jmp/ff commands to the new position in chunks */
115 long unsigned repos_request;
116 /** the number of the chunk currently sent out*/
117 long unsigned current_chunk;
118 /** the milliseconds that have been skipped of the current audio file */
119 long offset;
120 /** the length of the audio file in seconds */
121 int seconds_total;
122 /** the time para_server started to stream */
123 struct timeval stream_start;
124 /** a string that gets filled in by the audio format handler */
125 char audio_file_info[MMD_INFO_SIZE];
126 /** the event counter
127 *
128 * commands may increase this to force a status update to be sent to all
129 * connected clients
130 */
131 unsigned int events;
132 /** the number of audio files already sent */
133 unsigned int num_played;
134 /** the number of executed commands */
135 unsigned int num_commands;
136 /** the number of connections para_server received so far */
137 unsigned int num_connects;
138 /** the number of connections currently active */
139 unsigned int active_connections;
140 /** the process id of para_server */
141 pid_t server_pid;
142 /** a string that gets filled in by the current audio file selector */
143 char selector_info[MMD_INFO_SIZE];
144 /** the number if the current audio file selector */
145 int selector_num;
146 /** commands set this to non-zero to change the current selector */
147 int selector_change;
148 /** used by the sender command */
149 struct sender_command_data sender_cmd_data;
150 };
151
152
153 int handle_connect(int fd, struct sockaddr_in *addr);
154 void mmd_unlock(void);
155 void mmd_lock(void);