0077338bf47e1162ff121c51337705eca607c4f7
[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 #include "list.h"
23 #include <openssl/pem.h>
24
25 /** size of the selector_info and audio_file info strings of struct misc_meta_data */
26 #define MMD_INFO_SIZE 16384
27
28 /**
29 * permission flags that can be set individually for any server command
30 *
31 * - DB_READ: command reads from the database
32 * - DB_WRITE: command changes the contents of the database
33 * - AFS_READ: command reads information about the current audio stream
34 * - AFS_WRITE: command changes the current audio stream
35 */
36 enum {DB_READ = 1, DB_WRITE = 2, AFS_READ = 4, AFS_WRITE = 8};
37
38 /**
39 * data needed to authenticate the user
40 */
41 struct user{
42 /** the username */
43 char name[MAXLINE];
44 /** full path to the public RSA key */
45 char pubkey_file[_POSIX_PATH_MAX];
46 /** the privileges of this user */
47 unsigned int perms;
48 };
49
50 struct _user {
51 /** the position of this user in the list of users */
52 struct list_head node;
53 /** the username */
54 char *name;
55 /** the public RSA key */
56 RSA *rsa;
57 /** the privileges that this user has */
58 unsigned int perms;
59 };
60
61 /**
62 * defines one command of para_server
63 */
64 struct server_command {
65 /** the name of the command */
66 const char *name;
67 /** pointer to the function that handles the command */
68 int (*handler)(int, int, char **);
69 /** the privileges a user must have to execute this command */
70 unsigned int perms;
71 /** one-line description of the command */
72 const char *description;
73 /** summary of the command line options */
74 const char *synopsis;
75 /** the long help text */
76 const char *help;
77 };
78
79 /** holds the arguments for the para_server's sender command */
80 struct sender_command_data{
81 /** greater than 0 indicates that a sender cmd is already queued */
82 int cmd_num;
83 /** the number of the sender in question */
84 int sender_num;
85 /** used for the allow/deny/add/remove subcommands */
86 struct in_addr addr;
87 /** used for allow/deny */
88 int netmask;
89 /** the portnumber for add/remove */
90 int port;
91 };
92
93 /**
94 * used for parent-child communication
95 *
96 * There's only one struct of this type which lives in shared memory
97 * for communication between the server instances. Access to this
98 * area is serialized via mmd_lock() and mmd_unlock(). There are two
99 * reasons for a variable to be included here:
100 *
101 * - At least one command (i.e. child of the server) must be able to
102 * change its value.
103 *
104 * or
105 *
106 * - The contents are listed in the stat command and have to be up to
107 * date.
108 */
109 struct misc_meta_data{
110 /** the size of the current audio file in bytes */
111 long unsigned int size;
112 /** the full path of the current audio file */
113 char filename[_POSIX_PATH_MAX];
114 /** the last modification file of the current audio file */
115 time_t mtime;
116 /* the number of the current audio format */
117 int audio_format;
118 /** the "old" status flags -- commands may only read them */
119 unsigned int afs_status_flags;
120 /** the new status flags -- commands may set them **/
121 unsigned int new_afs_status_flags;
122 /** the number of data chunks sent for the current audio file */
123 long unsigned chunks_sent;
124 /** the number of chunks this audio file contains */
125 long unsigned chunks_total;
126 /** set by the jmp/ff commands to the new position in chunks */
127 long unsigned repos_request;
128 /** the number of the chunk currently sent out*/
129 long unsigned current_chunk;
130 /** the milliseconds that have been skipped of the current audio file */
131 long offset;
132 /** the length of the audio file in seconds */
133 int seconds_total;
134 /** the time para_server started to stream */
135 struct timeval stream_start;
136 /** a string that gets filled in by the audio format handler */
137 char audio_file_info[MMD_INFO_SIZE];
138 /** the event counter
139 *
140 * commands may increase this to force a status update to be sent to all
141 * connected clients
142 */
143 unsigned int events;
144 /** the number of audio files already sent */
145 unsigned int num_played;
146 /** the number of executed commands */
147 unsigned int num_commands;
148 /** the number of connections para_server received so far */
149 unsigned int num_connects;
150 /** the number of connections currently active */
151 unsigned int active_connections;
152 /** the process id of para_server */
153 pid_t server_pid;
154 /** a string that gets filled in by the current audio file selector */
155 char selector_info[MMD_INFO_SIZE];
156 /** the number if the current audio file selector */
157 int selector_num;
158 /** commands set this to non-zero to change the current selector */
159 int selector_change;
160 /** used by the sender command */
161 struct sender_command_data sender_cmd_data;
162 };
163
164 extern struct server_args_info conf;
165
166 int handle_connect(int fd, struct sockaddr_in *addr);
167 int _get_user(struct _user *user);
168 void mmd_unlock(void);
169 void mmd_lock(void);