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