]> git.sesse.net Git - betaftpd/blob - ftpd.h
086df8a50780adc26c5ce6d2a8e0e98fa2abd94b
[betaftpd] / ftpd.h
1 /*  ftpd.h: Prototypes for BetaFTPD
2     Copyright (C) 1999-2000 Steinar H. Gunderson
3
4     This program is is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License, version 2 if the
6     License as published by the Free Software Foundation.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18 /*
19  * This is the port you want BetaFTPD to listen on. The standard
20  * FTP port is 21 -- if you really want to use BetaFTPD as your
21  * primary FTP server, change FTP_PORT.
22  */
23 #if WANT_NONROOT
24 #define FTP_PORT 12121
25 #else
26 #define FTP_PORT 21
27 #endif
28
29 /*
30  * This is the number of seconds an idle connection is allowed to
31  * remain idle (`idle' is defined as `no activity on the data socket',
32  * more or less) without getting shut down. This is not accurate,
33  * as such delays are only checked for every 60 seconds.
34  *
35  * The default (15 minutes) should be OK for most people.
36  */
37 #define TIMEOUT_SECS 900
38
39 /*
40  * This is the maximum block size you think you need. (This will most
41  * likely be the block size of your filesystem, and you're not likely
42  * to need a bigger number than this, unless your TCP stack likes
43  * big send()s better than small ones, and still manages to `interleave'
44  * the framents.) If this value is too small, your performance would be
45  * slightly worse, but it would still work. Try to keep it at a power of
46  * two -- most (read: all) FS block sizes _are_ powers of two. If you
47  * set it too high, it won't affect performance much -- you would just
48  * use a bit more memory.
49  */
50 #define MAX_BLOCK_SIZE 4096
51
52 #if HAVE_LINUX_SENDFILE && !HAVE_MMAP
53 #warning sendfile() without mmap() is not supported -- disabling sendfile()
54 #undef HAVE_LINUX_SENDFILE
55 #endif
56
57 #if WANT_DCACHE && !HAVE_MMAP
58 #warning directory cache requires use of mmap() -- disabling directory cache
59 #undef WANT_DCACHE
60 #endif
61
62 struct list_options {
63         int recursive;
64         int long_listing;
65         int classify;
66 };
67
68 /*
69  * General structure for the doubly linked lists (conn, ftran, dcache).
70  * This is used only by the generic linked list code (which inserts and
71  * removes elements from the lists).
72  */
73 struct list_element {
74         struct list_element *prev;
75         struct list_element *next;
76
77         /* structure specific data here */
78 };
79
80 /* doubly linked list of active connections */
81 struct conn {
82         struct conn *prev_conn;
83         struct conn *next_conn;
84
85         int sock;
86 #if WANT_STAT
87         struct sockaddr addr;
88 #endif
89         char recv_buf[256];
90 #if WANT_FULLSCREEN
91         char last_cmd[256];
92 #endif
93         char rename_from[256];
94
95         int buf_len;
96         int auth;
97
98         char username[17];
99
100         uid_t uid;
101         char root_dir[256];
102         char curr_dir[256];
103
104         struct ftran *transfer;
105
106         int rest_pos;
107 #if WANT_ASCII
108         int ascii_mode;
109 #endif
110
111         time_t last_transfer;
112 };
113
114 /* doubly linked list of file transfers */
115 struct ftran {
116         struct ftran *prev_ftran;
117         struct ftran *next_ftran;
118         struct conn *owner;
119
120         int state;              /*
121                                  * 0 = none, 1 = got PASV addr,
122                                  * 2 = waiting on PASV socket,  
123                                  * 3 = got PORT addr, 4 = waiting for
124                                  *     PORT connect, 
125                                  * 5 = transferring file (or waiting 
126                                  *     for PORT connect)
127                                  */
128         struct sockaddr_in sin;
129         int sock;
130         int dir_listing;
131 #if WANT_DCACHE
132         struct dcache *dir_cache;
133 #endif
134 #if WANT_ASCII
135         int ascii_mode;
136 #endif
137         char filename[256];
138         time_t tran_start;
139         long int size;
140
141         int local_file;
142         int block_size;
143
144 #if HAVE_MMAP
145         char *file_data;        /* mmap'ed */
146 #endif
147         long int pos;
148
149 #if WANT_UPLOAD
150         int upload;
151         int append;
152 #endif
153 };
154
155 void add_to_linked_list(struct list_element * const first,
156                         struct list_element * const elem);
157 void remove_from_linked_list(struct list_element * const elem);
158
159 struct conn *alloc_new_conn(const int sock);
160 struct ftran *alloc_new_ftran(const int sock, const struct conn * const c);
161 #if WANT_DCACHE
162 struct dcache *alloc_new_dcache();
163 #endif
164
165 int add_fd(const int fd, const int events);
166 void del_fd(const int fd);
167
168 void destroy_conn(struct conn * const c);
169 void destroy_ftran(struct ftran * const f);
170 #if WANT_DCACHE
171 void destroy_dcache(struct dcache * const d);
172 #endif
173
174 #if HAVE_POLL
175 int process_all_clients(const int num_ac);
176 int process_all_sendfiles(const int num_ac);
177 #else
178 int process_all_clients(const fd_set * const active_clients, const int num_ac);
179 int process_all_sendfiles(fd_set * const active_clients, const int num_ac);
180 #endif
181
182 int do_upload(struct ftran *f);
183 int do_download(struct ftran *f);
184 void write_xferlog(struct ftran *f);
185 int main(void);
186
187 RETSIGTYPE handle_alarm(int signum);
188
189 void accept_new_client(int * const server_sock);
190 void time_out_sockets();
191 #if WANT_DCACHE
192 void time_out_dcache();
193 #endif
194
195 void remove_bytes(struct conn * const c, const int i);
196 void numeric(struct conn * const c, const int numeric, const char * const format, ...);
197 void init_file_transfer(struct ftran * const f);
198 int create_server_socket();
199
200 #if !HAVE_POLL
201 void clear_bad_fds(int * const server_sock);
202 #endif
203
204 #if WANT_MESSAGE
205 void dump_file(struct conn * const c, const int num, const char * const filename);
206 void list_readmes(struct conn * const c);
207 #endif
208